-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced object[] with map for query resullt
Signed-off-by: Piyush7034 <[email protected]>
- Loading branch information
1 parent
324bafa
commit 5374bc8
Showing
5 changed files
with
51 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ | |
</scm> | ||
<developers> | ||
<developer> | ||
<name>Mosip</name> | ||
<name>MOSIP</name> | ||
<email>[email protected]</email> | ||
<organization>io.mosip</organization> | ||
<organizationUrl>https://www.mosip.io</organizationUrl> | ||
|
@@ -46,16 +46,9 @@ | |
<git-commit-id-plugin.version>3.0.1</git-commit-id-plugin.version> | ||
<maven.jacoco.version>0.8.11</maven.jacoco.version> | ||
<maven-javadoc-plugin.version>3.6.3</maven-javadoc-plugin.version> | ||
<kernel-keymanager-service.version>1.3.0-beta.1</kernel-keymanager-service.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>3.8.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
|
@@ -68,27 +61,16 @@ | |
<version>0.10.0-SNAPSHOT</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.mosip.kernel</groupId> | ||
<artifactId>kernel-keymanager-service</artifactId> | ||
<version>${kernel-keymanager-service.version}</version> | ||
<scope>provided</scope> | ||
<classifier>lib</classifier> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-sleuth</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>org.springframework.security</groupId> | ||
<artifactId>spring-security-test</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<version>5.11.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-test</artifactId> | ||
<version>6.1.4</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
|
4 changes: 3 additions & 1 deletion
4
.../io/mosip/certify/postgresdataprovider/integration/repository/DataProviderRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package io.mosip.certify.postgresdataprovider.integration.repository; | ||
|
||
|
||
import java.util.Map; | ||
|
||
public interface DataProviderRepository { | ||
Object[] fetchDataFromIdentifier(String id, String queryString); | ||
Map<String, Object> fetchQueryResult(String id, String queryString); | ||
} |
29 changes: 23 additions & 6 deletions
29
...mosip/certify/postgresdataprovider/integration/repository/DataProviderRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,37 @@ | ||
package io.mosip.certify.postgresdataprovider.integration.repository; | ||
|
||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.PersistenceContext; | ||
import jakarta.persistence.Query; | ||
import jakarta.persistence.*; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
|
||
@Repository(value = "dataProviderRepository") | ||
public class DataProviderRepositoryImpl implements DataProviderRepository { | ||
@PersistenceContext | ||
private EntityManager entityManager; | ||
|
||
@Override | ||
public Object[] fetchDataFromIdentifier(String id, String queryString) { | ||
Query query = entityManager.createNativeQuery(queryString); | ||
public Map<String, Object> fetchQueryResult(String id, String queryString) { | ||
Query query = entityManager.createNativeQuery(queryString, Tuple.class); | ||
query.setParameter("id", id); | ||
return (Object[]) query.getSingleResult(); | ||
List<Tuple> list = query.getResultList(); | ||
List<Map<String, Object>> result = convertTuplesToMap(list); | ||
return result.getFirst(); | ||
} | ||
|
||
public static List<Map<String, Object>> convertTuplesToMap(List<Tuple> tuples) { | ||
List<Map<String, Object>> result = new ArrayList<>(); | ||
for (Tuple single : tuples) { | ||
Map<String, Object> tempMap = new HashMap<>(); | ||
for (TupleElement<?> key : single.getElements()) { | ||
tempMap.put(key.getAlias(), single.get(key)); | ||
} | ||
result.add(tempMap); | ||
} | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,14 +28,11 @@ public class PostgresDataProviderPluginTest { | |
|
||
@Before | ||
public void setup() { | ||
LinkedHashMap<String, LinkedHashMap<String, String>> scopeMapping = new LinkedHashMap<>(); | ||
LinkedHashMap<String, String> queryMap = new LinkedHashMap<>(); | ||
queryMap.put("query", "testQuery"); | ||
queryMap.put("fields","individualId,name,dateOfBirth,phoneNumber,email,landArea"); | ||
scopeMapping.put("test_vc_ldp", queryMap); | ||
ReflectionTestUtils.setField(postgresDataProviderPlugin, "scopeToQueryMapping", scopeMapping); | ||
Object[] obj = new Object[]{"1234567", "John Doe", "01/01/1980", "012345", "[email protected]", 100.24}; | ||
Mockito.when(dataProviderRepository.fetchDataFromIdentifier("1234567", "testQuery")).thenReturn(obj); | ||
LinkedHashMap<String, String> scopeQueryMapping = new LinkedHashMap<>(); | ||
scopeQueryMapping.put("test_vc_ldp", "test_query"); | ||
ReflectionTestUtils.setField(postgresDataProviderPlugin, "scopeQueryMapping", scopeQueryMapping); | ||
Map<String, Object> queryResult = Map.of("id","1234567", "name", "John Doe", "dateOfBirth", "01/01/1980", "phoneNumber", "012345", "email", "[email protected]", "landArea", 100.24); | ||
Mockito.when(dataProviderRepository.fetchQueryResult("1234567", "test_query")).thenReturn(queryResult); | ||
} | ||
|
||
@Test | ||
|
@@ -59,7 +56,7 @@ public void fetchJsonDataWithInValidIndividualId_thenFail() throws DataProviderE | |
try { | ||
postgresDataProviderPlugin.fetchData(Map.of("sub", "12345678", "client_id", "CLIENT_ID", "scope", "test_vc_ldp")); | ||
} catch (DataProviderExchangeException e) { | ||
Assert.assertEquals("ERROR_FETCHING_IDENTITY_DATA", e.getMessage()); | ||
Assert.assertEquals("ERROR_FETCHING_DATA_RECORD_FROM_TABLE", e.getMessage()); | ||
} | ||
} | ||
|
||
|
@@ -68,7 +65,7 @@ public void fetchJsonDataWithInValidScope_thenFail() throws DataProviderExchange | |
try { | ||
postgresDataProviderPlugin.fetchData(Map.of("sub", "1234567", "client_id", "CLIENT_ID", "scope", "sample_vc_ldp")); | ||
} catch (DataProviderExchangeException e) { | ||
Assert.assertEquals("ERROR_FETCHING_IDENTITY_DATA", e.getMessage()); | ||
Assert.assertEquals("ERROR_FETCHING_DATA_RECORD_FROM_TABLE", e.getMessage()); | ||
} | ||
} | ||
} |