Skip to content

Commit

Permalink
fix retrieval of deleted records, add offset for deleted
Browse files Browse the repository at this point in the history
records #EA-3896
  • Loading branch information
GordeaS authored and GordeaS committed Jul 29, 2024
1 parent f40cfd1 commit a7ee0d0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ public class EntityManagementConfiguration implements InitializingBean {
@Value("${zoho.sync.register.deprecated: false}")
private boolean registerDeprecated;

@Value("${zoho.sync.delete.offset.days: 10}")
private int zohoSyncDeleteOffsetDays;

@Value("${europeana.item.data.endpoint:'http://data.europeana.eu/item'}")
private String itemDataEndpoint;

Expand Down Expand Up @@ -486,5 +489,9 @@ public String getRoleVocabularyFilename() {
public Map<String, ZohoLabelUriMapping> getCountryIdMappings() {
return countryIdMappings;
}

public int getZohoSyncDeleteOffsetDays() {
return zohoSyncDeleteOffsetDays;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,16 @@ public ZohoSyncReport synchronizeModifiedZohoOrganizations() throws EntityUpdate
public ZohoSyncReport synchronizeZohoOrganizations(@NonNull OffsetDateTime modifiedSince)
throws EntityUpdateException {

OffsetDateTime deletedSince = modifiedSince.minusDays(emConfiguration.getZohoSyncDeleteOffsetDays());
if (logger.isInfoEnabled()) {
logger.info("Synchronizing organizations updated after date: {}", modifiedSince);
logger.info("Synchronizing organizations updated after date: {}, and delete after date :{}", modifiedSince, deletedSince);
}

ZohoSyncReport zohoSyncReport = new ZohoSyncReport(new Date());
// synchronize updated
// synchronize updated in Zoho
synchronizeZohoOrganizations(modifiedSince, zohoSyncReport);
// synchronize deleted in zoho
synchronizeDeletedZohoOrganizations(modifiedSince, zohoSyncReport);
synchronizeDeletedZohoOrganizations(deletedSince, zohoSyncReport);

logger.info("Zoho update operations completed successfully:\n {}", zohoSyncReport);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ europeana.searchapi.urlPrefix=https://<api_endpoint>/record/v2/search.json?wskey
#enable/disable generation of entity ids for organizations (should be enabled only in productive environment)
#zoho.generate.organization.europeanaid=false

#offset (days before last sync) for fetching deleted organizations
#zoho.sync.delete.offset.days=0

#configuration files for zoho country and role mappings
#zoho.country.mapping=zoho_country_mapping.json
#zoho.role.mapping=zoho_role_mapping.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.zoho.api.authenticator.store.TokenStore;
import com.zoho.crm.api.HeaderMap;
import com.zoho.crm.api.Initializer;
import com.zoho.crm.api.Param;
import com.zoho.crm.api.ParameterMap;
import com.zoho.crm.api.SDKConfig;
import com.zoho.crm.api.UserSignature;
Expand Down Expand Up @@ -296,6 +297,9 @@ public List<DeletedRecord> getZohoDeletedRecordOrganizations(OffsetDateTime modi
paramInstance.add(GetDeletedRecordsParam.TYPE, "all"); // all, recycle, permanent
paramInstance.add(GetDeletedRecordsParam.PAGE, 1);
paramInstance.add(GetDeletedRecordsParam.PER_PAGE, pageSize);
Param<String> scopeParam = new Param<String>("scope", "com.zoho.crm.api.Record.GetDeletedRecordsParam");
paramInstance.add(scopeParam, "ZohoCRM.modules.ALL");

HeaderMap headersMap = new HeaderMap();
if (modifiedSince != null) {
headersMap.add(GetRecordsHeader.IF_MODIFIED_SINCE, modifiedSince);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ private static List<String> getAllSameAs(Record zohoRecord) {
* @return the name of the owner
*/
public static String getOwnerName(Record recordOrganization) {
return ((User) recordOrganization.getKeyValue(ZohoConstants.ZOHO_OWNER_FIELD)).getName();
Object keyValue = recordOrganization.getKeyValue(ZohoConstants.ZOHO_OWNER_FIELD);
return ((User) keyValue).getName();
}

/**
Expand Down

0 comments on commit a7ee0d0

Please sign in to comment.