Skip to content

Commit

Permalink
Fixed formatting added the default props for panoply redshift bean
Browse files Browse the repository at this point in the history
  • Loading branch information
Camelia-Orcid committed Oct 11, 2024
1 parent c2218c9 commit 0e30e1c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@
import org.orcid.persistence.aop.UpdateProfileLastModifiedAndIndexingStatus;
import org.orcid.persistence.dao.OrgAffiliationRelationDao;
import org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.transaction.annotation.Transactional;

public class OrgAffiliationRelationDaoImpl extends GenericDaoImpl<OrgAffiliationRelationEntity, Long> 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";
Expand All @@ -42,11 +43,11 @@ public class OrgAffiliationRelationDaoImpl extends GenericDaoImpl<OrgAffiliation
private static final String AFFILIATION_TYPE_QUALIFICATION = "QUALIFICATION";

private static final String AFFILIATION_TYPE_SERVICE = "SERVICE";

private static final String DW_PANOPLY_AFFILIATION_TABLE = "dw_org_affiliation_relation";

@Resource
private PanoplyRedshiftClient panoplyClient;
private PanoplyRedshiftClient panoplyClient;

public OrgAffiliationRelationDaoImpl() {
super(OrgAffiliationRelationEntity.class);
Expand All @@ -69,20 +70,20 @@ public boolean removeOrgAffiliationRelation(String userOrcid, Long orgAffiliatio
Query query = entityManager.createQuery("delete from OrgAffiliationRelationEntity where orcid=:userOrcid and id=:orgAffiliationRelationId");
query.setParameter("userOrcid", userOrcid);
query.setParameter("orgAffiliationRelationId", orgAffiliationRelationId);
if(query.executeUpdate() > 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);
Expand All @@ -91,11 +92,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);
}

});
}

Expand Down Expand Up @@ -241,13 +242,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);
}
}
}
}

Expand Down Expand Up @@ -334,15 +335,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
Expand Down Expand Up @@ -447,8 +448,7 @@ public void revertUserOBODetails(List<BigInteger> ids) {
@SuppressWarnings("unchecked")
@Override
public List<BigInteger> 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();
}
Expand All @@ -461,14 +461,14 @@ public List<BigInteger> getIdsOfOrgAffiliationRelationsReferencingClientProfiles
query.setMaxResults(max);
return query.getResultList();
}

@Override
@UpdateProfileLastModifiedAndIndexingStatus
@Transactional
public void persist(OrgAffiliationRelationEntity affiliation) {
super.persist(affiliation);
}

@Override
@UpdateProfileLastModifiedAndIndexingStatus
@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,13 +460,13 @@

<!-- Panoply Redshift -->
<bean id="panoplyRedshiftDataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
<property name="driverClassName" value="\${org.orcid.core.utils.panoply.driver}" />
<property name="driverClassName" value="\${org.orcid.core.utils.panoply.driver:com.amazon.redshift.jdbc.Driver}" />
<property name="jdbcUrl" value="\${org.orcid.core.utils.panoply.jdbcUrl}" />
<property name="username" value="\${org.orcid.core.utils.panoply.username}" />
<property name="password" value="\${org.orcid.core.utils.panoply.password}" />
<property name="maximumPoolSize" value="\${org.orcid.core.utils.panoply.maxPoolSize}" />
<property name="idleTimeout" value="\${org.orcid.core.utils.panoply.idleConnectionTimeout}" />
<property name="connectionTimeout" value="\${org.orcid.core.utils.panoply.connectionTimeout}" />
<property name="maximumPoolSize" value="\${org.orcid.core.utils.panoply.maxPoolSize:5}" />
<property name="idleTimeout" value="\${org.orcid.core.utils.panoply.idleConnectionTimeout:3600}" />
<property name="connectionTimeout" value="\${org.orcid.core.utils.panoply.connectionTimeout:3600}" />
</bean>

<!-- Panoply JdbcTemplate Bean Definition -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '\'' + '}';
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;


import java.util.Date;

import javax.annotation.Resource;
Expand All @@ -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());
}

}

0 comments on commit 0e30e1c

Please sign in to comment.