33import java .math .BigInteger ;
44import java .util .ArrayList ;
55import java .util .List ;
6- import java .util .concurrent .CompletableFuture ;
76
8- import javax .annotation .Resource ;
97import javax .persistence .Query ;
108import javax .persistence .TypedQuery ;
119
12- import org .orcid .utils .panoply .PanoplyDeletedItem ;
13- import org .orcid .utils .panoply .PanoplyRedshiftClient ;
14- import org .slf4j .Logger ;
15- import org .slf4j .LoggerFactory ;
16- import org .apache .commons .logging .Log ;
1710import org .orcid .persistence .aop .UpdateProfileLastModified ;
1811import org .orcid .persistence .aop .UpdateProfileLastModifiedAndIndexingStatus ;
1912import org .orcid .persistence .dao .OrgAffiliationRelationDao ;
2013import org .orcid .persistence .jpa .entities .OrgAffiliationRelationEntity ;
21- import org .springframework .beans .factory .annotation .Value ;
2214import org .springframework .cache .annotation .Cacheable ;
2315import org .springframework .transaction .annotation .Transactional ;
2416
2517public class OrgAffiliationRelationDaoImpl extends GenericDaoImpl <OrgAffiliationRelationEntity , Long > implements OrgAffiliationRelationDao {
26-
27- private static final Logger LOG = LoggerFactory .getLogger (OrgAffiliationRelationDaoImpl .class );
28-
29- @ Value ("${org.orcid.persistence.panoply.cleanup.production:false}" )
30- private boolean enablePanoplyCleanupInProduction ;
31-
18+
3219 private static final String AFFILIATION_TYPE_DISTINCTION = "DISTINCTION" ;
3320
3421 private static final String AFFILIATION_TYPE_EDUCATION = "EDUCATION" ;
@@ -42,11 +29,6 @@ public class OrgAffiliationRelationDaoImpl extends GenericDaoImpl<OrgAffiliation
4229 private static final String AFFILIATION_TYPE_QUALIFICATION = "QUALIFICATION" ;
4330
4431 private static final String AFFILIATION_TYPE_SERVICE = "SERVICE" ;
45-
46- private static final String DW_PANOPLY_AFFILIATION_TABLE = "dw_org_affiliation_relation" ;
47-
48- @ Resource
49- private PanoplyRedshiftClient panoplyClient ;
5032
5133 public OrgAffiliationRelationDaoImpl () {
5234 super (OrgAffiliationRelationEntity .class );
@@ -69,34 +51,7 @@ public boolean removeOrgAffiliationRelation(String userOrcid, Long orgAffiliatio
6951 Query query = entityManager .createQuery ("delete from OrgAffiliationRelationEntity where orcid=:userOrcid and id=:orgAffiliationRelationId" );
7052 query .setParameter ("userOrcid" , userOrcid );
7153 query .setParameter ("orgAffiliationRelationId" , orgAffiliationRelationId );
72- if (query .executeUpdate () > 0 ) {
73- if (enablePanoplyCleanupInProduction ) {
74- PanoplyDeletedItem item = new PanoplyDeletedItem ();
75- item .setItemId (orgAffiliationRelationId );
76- item .setDwTable (DW_PANOPLY_AFFILIATION_TABLE );
77- storeDeletedItemInPanoply (item );
78- }
79- return true ;
80- }
81- return false ;
82- }
83-
84- private void storeDeletedItemInPanoply (PanoplyDeletedItem item ) {
85- //Store the deleted item in panoply Db without blocking
86- CompletableFuture .supplyAsync (() -> {
87- try {
88- panoplyClient .addPanoplyDeletedItem (item );
89- return true ;
90- } catch (Exception e ) {
91- LOG .error ("Cannot store deleted affiliation in panoply " , e );
92- return false ;
93- }
94- }).thenAccept (result -> {
95- if (! result ) {
96- LOG .error ("Async call to panoply for : " + item .toString () + " Stored: " + result );
97- }
98-
99- });
54+ return query .executeUpdate () > 0 ? true : false ;
10055 }
10156
10257 /**
@@ -241,14 +196,6 @@ public void removeOrgAffiliationByClientSourceId(String clientSourceId) {
241196 Query query = entityManager .createNativeQuery ("DELETE FROM org_affiliation_relation WHERE client_source_id=:clientSourceId" );
242197 query .setParameter ("clientSourceId" , clientSourceId );
243198 query .executeUpdate ();
244- if (query .executeUpdate () > 0 ) {
245- if (enablePanoplyCleanupInProduction ) {
246- PanoplyDeletedItem item = new PanoplyDeletedItem ();
247- item .setClientSourceId (clientSourceId );
248- item .setDwTable (DW_PANOPLY_AFFILIATION_TABLE );
249- storeDeletedItemInPanoply (item );
250- }
251- }
252199 }
253200
254201 @ Override
@@ -334,15 +281,6 @@ public void removeAllAffiliations(String orcid) {
334281 Query query = entityManager .createQuery ("delete from OrgAffiliationRelationEntity where orcid = :orcid" );
335282 query .setParameter ("orcid" , orcid );
336283 query .executeUpdate ();
337- if (query .executeUpdate () > 0 ) {
338- if (enablePanoplyCleanupInProduction ) {
339- PanoplyDeletedItem item = new PanoplyDeletedItem ();
340- item .setOrcid (orcid );
341- item .setDwTable (DW_PANOPLY_AFFILIATION_TABLE );
342- storeDeletedItemInPanoply (item );
343- }
344- }
345-
346284 }
347285
348286 @ Override
0 commit comments