@@ -1365,27 +1365,15 @@ private static List<RelatedIdentifier> getSourceRi(List<RelatedIdentifier> list,
13651365 *
13661366 * @param em the EntityManager to control commits.
13671367 * @param md the Metadata to evaluate.
1368- * @return Updated DOECodeMetadata object.
1368+ * @return Updated and detached List<RelatedIdentifier> object.
13691369 */
1370- private static DOECodeMetadata createIndexableRi (EntityManager em , DOECodeMetadata md ) throws IOException {
1371- // need a detached copy of the RI data
1372- DOECodeMetadata alteredMd = new DOECodeMetadata ();
1373- BeanUtilsBean bean = new BeanUtilsBean ();
1374-
1375- try {
1376- bean .copyProperties (alteredMd , md );
1377- } catch (IllegalAccessException | InvocationTargetException ex ) {
1378- // log issue, swallow error
1379- String msg = "NonIndexable RI Removal Bean Error: " + ex .getMessage ();
1380- throw new IOException (msg );
1381- }
1382-
1370+ private static List <RelatedIdentifier > createIndexableRi (EntityManager em , DOECodeMetadata md ) throws IOException {
13831371 TypedQuery <MetadataSnapshot > querySnapshot = em .createNamedQuery ("MetadataSnapshot.findByDoiAndStatus" , MetadataSnapshot .class )
13841372 .setParameter ("status" , DOECodeMetadata .Status .Approved );
13851373
13861374 // get detached list of RI to check
13871375 List <RelatedIdentifier > riList = new ArrayList <>();
1388- riList .addAll (alteredMd .getRelatedIdentifiers ());
1376+ riList .addAll (md .getRelatedIdentifiers ());
13891377
13901378 // filter to targeted RI
13911379 List <RelatedIdentifier > filteredRiList = riList .stream ().filter (p -> p .getIdentifierType () == RelatedIdentifier .Type .DOI
@@ -1415,13 +1403,28 @@ private static DOECodeMetadata createIndexableRi(EntityManager em, DOECodeMetada
14151403 removalList .add (ri );
14161404 }
14171405
1418- // perform removals, as needed, and update
1406+ // perform removals, as needed
14191407 if (!removalList .isEmpty ()) {
14201408 riList .removeAll (removalList );
14211409 }
14221410
1423- // Add AWARD DOI to RI list, and then remove , for Indexing purposes.
1424- List <Award > awards = alteredMd .getAwardDois ();
1411+ return riList ;
1412+ }
1413+
1414+ /**
1415+ * Add indexable Award DOI RI from metadata.
1416+ *
1417+ * @param em the EntityManager to control commits.
1418+ * @param md the Metadata to evaluate.
1419+ * @return Updated and detached List<RelatedIdentifier> object.
1420+ */
1421+ private static List <RelatedIdentifier > createAwardRi (EntityManager em , DOECodeMetadata md ) throws IOException {
1422+ // get detached list of RI to check
1423+ List <RelatedIdentifier > riList = new ArrayList <>();
1424+ riList .addAll (md .getRelatedIdentifiers ());
1425+
1426+ // Add AWARD DOI to RI list for Indexing purposes.
1427+ List <Award > awards = md .getAwardDois ();
14251428 if (awards != null && !awards .isEmpty ()) {
14261429 for (Award award : awards ) {
14271430 RelatedIdentifier ri = new RelatedIdentifier ();
@@ -1430,14 +1433,9 @@ private static DOECodeMetadata createIndexableRi(EntityManager em, DOECodeMetada
14301433 ri .setIdentifierValue (award .toJson ());
14311434 riList .add (ri );
14321435 }
1433- alteredMd .setAwardDois (null );
14341436 }
14351437
1436- if (!removalList .isEmpty () || (awards != null && !awards .isEmpty ())) {
1437- alteredMd .setRelatedIdentifiers (riList );
1438- }
1439-
1440- return alteredMd ;
1438+ return riList ;
14411439 }
14421440
14431441 /**
@@ -1694,17 +1692,22 @@ private static void sendToIndex(EntityManager em, DOECodeMetadata md) {
16941692 .create ()
16951693 .setDefaultRequestConfig (rc )
16961694 .build ();
1695+
1696+ // backup info
1697+ List <RelatedIdentifier > originalRi = md .getRelatedIdentifiers ();
1698+
16971699 try {
16981700 // do not index DOE CODE New/Previous DOI related identifiers if Approved without a Release Date
1699- DOECodeMetadata indexableMd = createIndexableRi (em , md );
1701+ List <RelatedIdentifier > indexableRi = createIndexableRi (em , md );
1702+ md .setRelatedIdentifiers (indexableRi );
17001703
17011704 // construct a POST submission to the indexer service
17021705 HttpPost post = new HttpPost (INDEX_URL );
17031706 post .setHeader ("Content-Type" , "application/json" );
17041707 post .setHeader ("Accept" , "application/json" );
17051708 // add JSON String to index for later display/search
1706- ObjectNode node = (ObjectNode )index_mapper .valueToTree (indexableMd );
1707- node .put ("json" , indexableMd .toJson ().toString ());
1709+ ObjectNode node = (ObjectNode )index_mapper .valueToTree (md );
1710+ node .put ("json" , md .toJson ().toString ());
17081711 post .setEntity (new StringEntity (node .toString (), "UTF-8" ));
17091712
17101713 HttpResponse response = hc .execute (post );
@@ -1721,6 +1724,9 @@ private static void sendToIndex(EntityManager em, DOECodeMetadata md) {
17211724 } catch ( IOException e ) {
17221725 log .warn ("Index Close Error: " + e .getMessage ());
17231726 }
1727+
1728+ // restore manipulated lists from backup info
1729+ md .setRelatedIdentifiers (originalRi );
17241730 }
17251731 }
17261732
@@ -2561,8 +2567,18 @@ private void sendToOsti(EntityManager em, DOECodeMetadata md) throws IOException
25612567 // if configured, post this to OSTI
25622568 String publishing_host = context .getInitParameter ("publishing.host" );
25632569 if (null !=publishing_host ) {
2570+ // backup info
2571+ List <RelatedIdentifier > originalRi = md .getRelatedIdentifiers ();
2572+ List <Award > awardDois = md .getAwardDois ();
2573+
25642574 // do not index DOE CODE New/Previous DOI related identifiers if Approved without a Release Date
2565- DOECodeMetadata indexableMd = createIndexableRi (em , md );
2575+ List <RelatedIdentifier > indexableRi = createIndexableRi (em , md );
2576+ md .setRelatedIdentifiers (indexableRi );
2577+
2578+ // add award info to RI list for OSTI
2579+ List <RelatedIdentifier > awardRi = createAwardRi (em , md );
2580+ md .setRelatedIdentifiers (awardRi );
2581+ md .setAwardDois (null );
25662582
25672583 // set some reasonable default timeouts
25682584 // create an HTTP client to request through
@@ -2579,7 +2595,7 @@ private void sendToOsti(EntityManager em, DOECodeMetadata md) throws IOException
25792595 HttpPost post = new HttpPost (publishing_host + "/services/softwarecenter?action=api" );
25802596 post .setHeader ("Content-Type" , "application/json" );
25812597 post .setHeader ("Accept" , "application/json" );
2582- post .setEntity (new StringEntity (mapper .writeValueAsString (indexableMd ), "UTF-8" ));
2598+ post .setEntity (new StringEntity (mapper .writeValueAsString (md ), "UTF-8" ));
25832599
25842600 HttpResponse response = hc .execute (post );
25852601 String text = EntityUtils .toString (response .getEntity ());
@@ -2589,6 +2605,11 @@ private void sendToOsti(EntityManager em, DOECodeMetadata md) throws IOException
25892605 throw new IOException ("OSTI software publication error for " + md .getCodeId ());
25902606 }
25912607 }
2608+ finally {
2609+ // restore manipulated lists from backup info
2610+ md .setRelatedIdentifiers (originalRi );
2611+ md .setAwardDois (awardDois );
2612+ }
25922613 }
25932614 }
25942615
0 commit comments