Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix retrieval of deleted records, add offset for deleted #325

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading