Skip to content

Commit

Permalink
#78 | Add null checks on Address fields for Goonj entities synced fro…
Browse files Browse the repository at this point in the history
…m Salesforce
  • Loading branch information
himeshr committed Sep 11, 2023
1 parent 2828399 commit 4c7176c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public Subject subjectWithoutObservations() {
subject.setSubjectType("Demand");
Date demandDate = DateTimeUtil.offsetTimeZone(new Date(), DateTimeUtil.UTC, DateTimeUtil.IST);
subject.setRegistrationDate(demandDate);
subject.setAddress(MapUtil.getString(DemandStateField, response) +", "+MapUtil.getString(DemandDistrictField, response));
subject.setAddress(getAddress(DemandStateField, DemandDistrictField, response));
subject.setExternalId(MapUtil.getString(DemandIdField, response));
subject.setFirstName(MapUtil.getString(DemandNameField, response));
subject.setVoided(MapUtil.getBoolean(DemandIsVoidedField, response));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Subject subjectWithoutObservations() {
Date dispatchDate = DateTimeUtil.convertToDateFromGoonjDateString(MapUtil.getString(DispatchDateField, response));
// dispatchDate = DateTimeUtil.offsetTimeZone(dispatchDate, DateTimeUtil.UTC, DateTimeUtil.IST);
subject.setRegistrationDate(dispatchDate);
subject.setAddress(MapUtil.getString(DispatchStateField, response) +", "+MapUtil.getString(DispatchDistrictField, response));
subject.setAddress(getAddress(DispatchStateField, DispatchDistrictField, response));
subject.setExternalId(MapUtil.getString(DispatchStatusIdField, response));
subject.setFirstName(MapUtil.getString(DispatchNameField, response));
subject.setVoided(MapUtil.getBoolean(DispatchIsVoidedField, response));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
package org.avni_integration_service.goonj.domain;

import org.avni_integration_service.util.MapUtil;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Map;

public interface GoonjEntity {
List<String> getObservationFields();
Object getValue(String responseField);

default String getAddress(String stateField, String districtField, Map<String, Object> response) {
String state = MapUtil.getString(stateField, response);
String district = MapUtil.getString(districtField, response);
if(StringUtils.hasText(state) && StringUtils.hasText(district)) {
return state + ", " + district;
}
throw new RuntimeException("Invalid address value specified");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@JsonIgnoreProperties(ignoreUnknown = true)
public class Inventory implements GoonjEntity {

private static final String InventoryStateField = "CenterFieldOfficeState";
private static final String InventoryStateField = "CenterFieldOfficeState";
private static final String InventoryDistrictField = "CenterFieldOfficeDistrict";
private static final String InventoryLastModifiedBy = "LastModifiedBy";
private static final String InventoryNameField = "ImplementationInventoryName";
Expand Down Expand Up @@ -51,7 +51,7 @@ public Subject subjectWithoutObservations() {
subject.setSubjectType("Inventory Item");
Date InventoryDate = DateTimeUtil.offsetTimeZone(new Date(), DateTimeUtil.UTC, DateTimeUtil.IST);
subject.setRegistrationDate(InventoryDate);
subject.setAddress(MapUtil.getString(InventoryStateField, response) +", "+MapUtil.getString(InventoryDistrictField, response));
subject.setAddress(getAddress(InventoryStateField, InventoryDistrictField, response));
subject.setFirstName(MapUtil.getString(InventoryNameField, response));
subject.setExternalId(MapUtil.getString(InventoryIdField, response));
subject.setVoided(MapUtil.getBoolean(InventoryIsVoidedField, response));
Expand Down

0 comments on commit 4c7176c

Please sign in to comment.