diff --git a/orcid-persistence/src/main/java/org/orcid/persistence/dao/impl/OrgAffiliationRelationDaoImpl.java b/orcid-persistence/src/main/java/org/orcid/persistence/dao/impl/OrgAffiliationRelationDaoImpl.java index de1c3a5bf1f..bf849fbb405 100644 --- a/orcid-persistence/src/main/java/org/orcid/persistence/dao/impl/OrgAffiliationRelationDaoImpl.java +++ b/orcid-persistence/src/main/java/org/orcid/persistence/dao/impl/OrgAffiliationRelationDaoImpl.java @@ -13,7 +13,6 @@ import org.orcid.utils.panoply.PanoplyRedshiftClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.apache.commons.logging.Log; import org.orcid.persistence.aop.UpdateProfileLastModified; import org.orcid.persistence.aop.UpdateProfileLastModifiedAndIndexingStatus; import org.orcid.persistence.dao.OrgAffiliationRelationDao; @@ -23,12 +22,12 @@ import org.springframework.transaction.annotation.Transactional; public class OrgAffiliationRelationDaoImpl extends GenericDaoImpl implements OrgAffiliationRelationDao { - + private static final Logger LOG = LoggerFactory.getLogger(OrgAffiliationRelationDaoImpl.class); - + @Value("${org.orcid.persistence.panoply.cleanup.production:false}") - private boolean enablePanoplyCleanupInProduction; - + private boolean enablePanoplyCleanupInProduction; + private static final String AFFILIATION_TYPE_DISTINCTION = "DISTINCTION"; private static final String AFFILIATION_TYPE_EDUCATION = "EDUCATION"; @@ -42,11 +41,11 @@ public class OrgAffiliationRelationDaoImpl extends GenericDaoImpl 0) { - if(enablePanoplyCleanupInProduction) { + if (query.executeUpdate() > 0) { + if (enablePanoplyCleanupInProduction) { PanoplyDeletedItem item = new PanoplyDeletedItem(); item.setItemId(orgAffiliationRelationId); item.setDwTable(DW_PANOPLY_AFFILIATION_TABLE); storeDeletedItemInPanoply(item); - } + } return true; } - return false; + return false; } - + private void storeDeletedItemInPanoply(PanoplyDeletedItem item) { - //Store the deleted item in panoply Db without blocking + // Store the deleted item in panoply Db without blocking CompletableFuture.supplyAsync(() -> { try { panoplyClient.addPanoplyDeletedItem(item); @@ -91,11 +90,11 @@ private void storeDeletedItemInPanoply(PanoplyDeletedItem item) { LOG.error("Cannot store deleted affiliation in panoply ", e); return false; } - }).thenAccept(result -> { - if(! result) { - LOG.error("Async call to panoply for : " + item.toString() + " Stored: "+ result); + }).thenAccept(result -> { + if (!result) { + LOG.error("Async call to panoply for : " + item.toString() + " Stored: " + result); } - + }); } @@ -241,13 +240,13 @@ public void removeOrgAffiliationByClientSourceId(String clientSourceId) { Query query = entityManager.createNativeQuery("DELETE FROM org_affiliation_relation WHERE client_source_id=:clientSourceId"); query.setParameter("clientSourceId", clientSourceId); query.executeUpdate(); - if(query.executeUpdate() > 0) { - if(enablePanoplyCleanupInProduction) { + if (query.executeUpdate() > 0) { + if (enablePanoplyCleanupInProduction) { PanoplyDeletedItem item = new PanoplyDeletedItem(); item.setClientSourceId(clientSourceId); item.setDwTable(DW_PANOPLY_AFFILIATION_TABLE); storeDeletedItemInPanoply(item); - } + } } } @@ -334,15 +333,15 @@ public void removeAllAffiliations(String orcid) { Query query = entityManager.createQuery("delete from OrgAffiliationRelationEntity where orcid = :orcid"); query.setParameter("orcid", orcid); query.executeUpdate(); - if(query.executeUpdate() > 0) { - if(enablePanoplyCleanupInProduction) { + if (query.executeUpdate() > 0) { + if (enablePanoplyCleanupInProduction) { PanoplyDeletedItem item = new PanoplyDeletedItem(); item.setOrcid(orcid); item.setDwTable(DW_PANOPLY_AFFILIATION_TABLE); storeDeletedItemInPanoply(item); - } + } } - + } @Override @@ -447,8 +446,7 @@ public void revertUserOBODetails(List ids) { @SuppressWarnings("unchecked") @Override public List getIdsForUserOBORecords(int max) { - Query query = entityManager - .createNativeQuery("SELECT id FROM org_affiliation_relation WHERE assertion_origin_source_id IS NOT NULL"); + Query query = entityManager.createNativeQuery("SELECT id FROM org_affiliation_relation WHERE assertion_origin_source_id IS NOT NULL"); query.setMaxResults(max); return query.getResultList(); } @@ -461,14 +459,14 @@ public List getIdsOfOrgAffiliationRelationsReferencingClientProfiles query.setMaxResults(max); return query.getResultList(); } - + @Override @UpdateProfileLastModifiedAndIndexingStatus @Transactional public void persist(OrgAffiliationRelationEntity affiliation) { super.persist(affiliation); } - + @Override @UpdateProfileLastModifiedAndIndexingStatus @Transactional diff --git a/orcid-persistence/src/main/resources/orcid-persistence-context.xml b/orcid-persistence/src/main/resources/orcid-persistence-context.xml index 554d47b39a6..629b3b163c1 100644 --- a/orcid-persistence/src/main/resources/orcid-persistence-context.xml +++ b/orcid-persistence/src/main/resources/orcid-persistence-context.xml @@ -460,13 +460,13 @@ - + - - - + + + diff --git a/orcid-utils/src/main/java/org/orcid/utils/panoply/PanoplyDeletedItem.java b/orcid-utils/src/main/java/org/orcid/utils/panoply/PanoplyDeletedItem.java index 378b0185227..a39df453cde 100644 --- a/orcid-utils/src/main/java/org/orcid/utils/panoply/PanoplyDeletedItem.java +++ b/orcid-utils/src/main/java/org/orcid/utils/panoply/PanoplyDeletedItem.java @@ -6,50 +6,54 @@ public class PanoplyDeletedItem { private Long itemId; private String clientSourceId; private String orcid; - + public final String DW_ORG_AFFILIATION_RELATION = "dw_org_affiliation_relation"; public final String DW_WORK = "dw_work"; - + public Long getId() { return id; } + public void setId(Long id) { this.id = id; } + public String getDwTable() { return dwTable; } + public void setDwTable(String dwTable) { this.dwTable = dwTable; } + public Long getItemId() { return itemId; } + public void setItemId(Long itemId) { this.itemId = itemId; } + public String getClientSourceId() { return clientSourceId; } + public void setClientSourceId(String clientSourceId) { this.clientSourceId = clientSourceId; } + public String getOrcid() { return orcid; } + public void setOrcid(String orcid) { this.orcid = orcid; } - + @Override public String toString() { - return "PanoplyDeletedItem{" + - "id=" + id + - ", dwTable='" + dwTable + '\'' + - ", itemId='" + itemId + '\'' + - ", clientSourceId='" + clientSourceId + '\'' + - ", orcid='" + orcid + '\'' + - '}'; + return "PanoplyDeletedItem{" + "id=" + id + ", dwTable='" + dwTable + '\'' + ", itemId='" + itemId + '\'' + ", clientSourceId='" + clientSourceId + '\'' + + ", orcid='" + orcid + '\'' + '}'; } } diff --git a/orcid-utils/src/main/java/org/orcid/utils/panoply/PanoplyRedshiftClient.java b/orcid-utils/src/main/java/org/orcid/utils/panoply/PanoplyRedshiftClient.java index 3499593eb27..77c5db8ef16 100644 --- a/orcid-utils/src/main/java/org/orcid/utils/panoply/PanoplyRedshiftClient.java +++ b/orcid-utils/src/main/java/org/orcid/utils/panoply/PanoplyRedshiftClient.java @@ -8,7 +8,6 @@ import org.springframework.stereotype.Repository; import org.springframework.stereotype.Service; - import java.util.Date; import javax.annotation.Resource; @@ -21,16 +20,16 @@ public class PanoplyRedshiftClient { private static final Logger LOG = LoggerFactory.getLogger(PanoplyRedshiftClient.class); - + @Autowired @Qualifier("panoplyJdbcTemplate") private JdbcTemplate panoplyJdbcTemplate; - - + public int addPanoplyDeletedItem(PanoplyDeletedItem item) { - LOG.debug("Adding deleted item to panoply DB: " + item.toString()); + LOG.debug("Adding deleted item to panoply DB: " + item.toString()); String sql = "INSERT INTO dw_deleted_items (item_id, orcid, client_source_id, date_deleted, dw_table) VALUES (?, ?, ?, ?, ?)"; - return panoplyJdbcTemplate.update(sql, item.getItemId(), item.getOrcid(), item.getClientSourceId(), new java.sql.Timestamp(new Date().getTime()), item.getDwTable()); + return panoplyJdbcTemplate.update(sql, item.getItemId(), item.getOrcid(), item.getClientSourceId(), new java.sql.Timestamp(new Date().getTime()), + item.getDwTable()); } - + }