forked from avni-bahmni-integration/integration-service
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#000 - removing comments and unnecessary methods.
- Loading branch information
1 parent
e9f6ca7
commit bb87dcf
Showing
6 changed files
with
116 additions
and
171 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
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
83 changes: 83 additions & 0 deletions
83
lahi/src/main/java/org/avni_integration_service/lahi/service/BigQueryClient.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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package org.avni_integration_service.lahi.service; | ||
|
||
import com.google.cloud.bigquery.*; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonParser; | ||
import org.apache.log4j.Logger; | ||
import org.avni_integration_service.lahi.config.BigQueryConnector; | ||
import org.avni_integration_service.lahi.domain.StudentConstants; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.*; | ||
|
||
@Component | ||
public class BigQueryClient { | ||
public static final String RESULTS = "results"; | ||
private final BigQueryConnector bigQueryConnector; | ||
private static final Logger logger = Logger.getLogger(BigQueryClient.class); | ||
|
||
public BigQueryClient(BigQueryConnector bigQueryConnector) { | ||
this.bigQueryConnector = bigQueryConnector; | ||
} | ||
|
||
public TableResult queryWithPagination(String query, String date, int limit) { | ||
QueryJobConfiguration queryConfig = | ||
QueryJobConfiguration.newBuilder(query) | ||
.addNamedParameter("updated_at", QueryParameterValue.string(date)) | ||
.addNamedParameter("limit_count", QueryParameterValue.int64(limit)) | ||
.build(); | ||
return queryCall(queryConfig); | ||
} | ||
|
||
public TableResult queryCall(QueryJobConfiguration queryJobConfiguration) { | ||
try { | ||
JobId jobId = JobId.of(UUID.randomUUID().toString()); | ||
Job queryJob = bigQueryConnector.getBigQuery().create(JobInfo.newBuilder(queryJobConfiguration).setJobId(jobId).build()); | ||
queryJob = queryJob.waitFor(); | ||
|
||
if (queryJob == null) { | ||
logger.info("query job is null"); | ||
throw new RuntimeException("Job no longer exists"); | ||
} else if (queryJob.getStatus().getError() != null) { | ||
// You can also look at queryJob.getStatus().getExecutionErrors() for all | ||
// errors, not just the latest one. | ||
logger.info(queryJob.getStatus().getError().toString()); | ||
throw new RuntimeException(queryJob.getStatus().getError().toString()); | ||
} | ||
|
||
return queryJob.getQueryResults(); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public List<Map<String, Object>> filterData(TableResult response) { | ||
Schema schema = response.getSchema(); | ||
List<Map<String, Object>> list1 = new LinkedList<>(); | ||
for (FieldValueList row : response.iterateAll()) { | ||
Map<String, Object> resultMap = new HashMap<>(); | ||
for (int i = 0; i < schema.getFields().size(); i++) { | ||
Field field = schema.getFields().get(i); | ||
FieldValue fieldValue = row.get(i); | ||
String fieldName = field.getName(); | ||
if (fieldName.equals(RESULTS)) { | ||
getResultData(resultMap, fieldValue.getStringValue()); | ||
} | ||
resultMap.put(fieldName, fieldValue.getStringValue()); | ||
} | ||
list1.add(resultMap); | ||
} | ||
return list1; | ||
} | ||
|
||
public void getResultData(Map<String, Object> map, String result) { | ||
JsonObject jsonObject = new JsonParser().parse(result).getAsJsonObject(); | ||
StudentConstants.ResultFieldList.forEach(field -> { | ||
map.put(field, getDataFromJson(jsonObject, field)); | ||
}); | ||
} | ||
|
||
public String getDataFromJson(JsonObject jsonObject, String field) { | ||
return (jsonObject.has(field)) ? jsonObject.getAsJsonObject(field).get("input").getAsString() : null; | ||
} | ||
} |
95 changes: 0 additions & 95 deletions
95
lahi/src/main/java/org/avni_integration_service/lahi/service/DataExtractorService.java
This file was deleted.
Oops, something went wrong.
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