From 6fa5d9556e217e07f59d24ac6458d00f4b7c10a9 Mon Sep 17 00:00:00 2001 From: Joel Weiser Date: Wed, 10 Jul 2024 13:17:49 -0400 Subject: [PATCH 1/3] refactors Main class --- .../release/update_stable_ids/Main.java | 86 +++++++++++++------ 1 file changed, 58 insertions(+), 28 deletions(-) diff --git a/src/main/java/org/reactome/release/update_stable_ids/Main.java b/src/main/java/org/reactome/release/update_stable_ids/Main.java index ae5bebbf..97a84fad 100644 --- a/src/main/java/org/reactome/release/update_stable_ids/Main.java +++ b/src/main/java/org/reactome/release/update_stable_ids/Main.java @@ -1,6 +1,9 @@ package org.reactome.release.update_stable_ids; -import java.io.FileInputStream; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.sql.SQLException; import java.util.Properties; @@ -13,47 +16,74 @@ * Instances that have been changed have their 'identifierVersion' attribute incremented by 1 to reflect a change. * */ -public class Main -{ +public class Main { private static final Logger logger = LogManager.getLogger(); - public static void main( String[] args ) throws Exception - { + public static void main(String[] args) throws Exception { logger.info("Beginning UpdateStableIds step..."); - String pathToConfig = ""; + Properties props = getProperties(getPathToConfigFile(args)); + + MySQLAdaptor dbaSlice = getCurrentSliceDBA(props); + MySQLAdaptor dbaPrevSlice = getPreviousSliceDBA(props); + MySQLAdaptor dbaGkCentral = getCuratorDBA(props); + long personId = Long.parseLong(props.getProperty("personId")); + + StableIdentifierUpdater.updateStableIdentifiers(dbaSlice, dbaPrevSlice, dbaGkCentral, personId); + + logger.info("Finished UpdateStableIds step"); + } + + private static Properties getProperties(Path pathToConfigFile) throws IOException { + Properties props = new Properties(); + props.load(Files.newInputStream(pathToConfigFile)); + return props; + } + + private static Path getPathToConfigFile(String[] args) { + String pathToConfigFile; if (args.length > 0) { - pathToConfig = args[0]; + pathToConfigFile = args[0]; } else { - pathToConfig = "src/main/resources/config.properties"; + pathToConfigFile = "src/main/resources/config.properties"; } - //Sets up the various DB Adaptors needed. This includes the current and previous test_slice versions on the release server, - //as well as gk_central on the curation server. - Properties props = new Properties(); - props.load(new FileInputStream(pathToConfig)); - int port = Integer.valueOf(props.getProperty("release.database.port")); - int releaseNumber = Integer.valueOf(props.getProperty("releaseNumber")); - int prevReleaseNumber = releaseNumber - 1; + return Paths.get(pathToConfigFile); + } - MySQLAdaptor dbaSlice = createDatabaseAdaptor(props, "release.database.user", "release.database.password", "release.database.host","slice_current.name", "release.database.port"); - MySQLAdaptor dbaPrevSlice = createDatabaseAdaptor(props, "release.database.user", "release.database.password", "release.database.host","slice_previous.name", "release.database.port"); - MySQLAdaptor dbaGkCentral = createDatabaseAdaptor(props, "curator.database.user", "curator.database.password", "curator.database.host", "curator.database.name", "curator.database.port"); + private static MySQLAdaptor getCurrentSliceDBA(Properties props) throws SQLException { + String databaseNameProperty = "slice_current.name"; - long personId = Long.parseLong(props.getProperty("personId")); - StableIdentifierUpdater.updateStableIdentifiers(dbaSlice, dbaPrevSlice, dbaGkCentral, personId); + return getReleaseDBA(props, databaseNameProperty); + } - logger.info("Finished UpdateStableIds step"); + private static MySQLAdaptor getPreviousSliceDBA(Properties props) throws SQLException { + String databaseNameProperty = "slice_previous.name"; + + return getReleaseDBA(props, databaseNameProperty); } - private static MySQLAdaptor createDatabaseAdaptor(Properties props, String userProperty, String passwordProperty, String hostProperty, String databaseNameProperty, String portProperty) throws SQLException { - String userName = props.getProperty(userProperty); - String password = props.getProperty(passwordProperty); - String host = props.getProperty(hostProperty); - String databaseName = props.getProperty(databaseNameProperty); - int port = Integer.parseInt(props.getProperty(portProperty)); + private static MySQLAdaptor getReleaseDBA(Properties props, String databaseNameProperty) throws SQLException { + final String propertyPrefix = "release.database"; - logger.info("Creating DB adaptor for " + databaseName + " at " + host + " on port " + port + " for user " + userName); + return getDBA(props, propertyPrefix, databaseNameProperty); + } + + private static MySQLAdaptor getCuratorDBA(Properties props) throws SQLException { + final String propertyPrefix = "curator.database"; + final String databaseNameProperty = propertyPrefix + ".name"; + + return getDBA(props, propertyPrefix, databaseNameProperty); + } + + private static MySQLAdaptor getDBA(Properties props, String propertyPrefix, String databaseNameProperty) + throws SQLException { + + String userName = props.getProperty(propertyPrefix + ".user"); + String password = props.getProperty(propertyPrefix + ".password"); + String host = props.getProperty(propertyPrefix + ".host"); + String databaseName = props.getProperty(databaseNameProperty); + int port = Integer.parseInt(props.getProperty(propertyPrefix + ".port")); return new MySQLAdaptor(host, databaseName, userName, password, port); } From 6ab46e246747d125ecdbca1cf061ec439768a557 Mon Sep 17 00:00:00 2001 From: Joel Weiser Date: Thu, 11 Jul 2024 14:47:41 -0400 Subject: [PATCH 2/3] refactors StableIdentifierUpdater class --- .../release/update_stable_ids/Main.java | 3 +- .../StableIdentifierUpdater.java | 323 ++++++++++++------ .../StableIdentifierUpdaterTest.java | 12 +- 3 files changed, 220 insertions(+), 118 deletions(-) diff --git a/src/main/java/org/reactome/release/update_stable_ids/Main.java b/src/main/java/org/reactome/release/update_stable_ids/Main.java index 97a84fad..db841adc 100644 --- a/src/main/java/org/reactome/release/update_stable_ids/Main.java +++ b/src/main/java/org/reactome/release/update_stable_ids/Main.java @@ -29,7 +29,8 @@ public static void main(String[] args) throws Exception { MySQLAdaptor dbaGkCentral = getCuratorDBA(props); long personId = Long.parseLong(props.getProperty("personId")); - StableIdentifierUpdater.updateStableIdentifiers(dbaSlice, dbaPrevSlice, dbaGkCentral, personId); + StableIdentifierUpdater stableIdentifierUpdater = new StableIdentifierUpdater(); + stableIdentifierUpdater.update(dbaSlice, dbaPrevSlice, dbaGkCentral, personId); logger.info("Finished UpdateStableIds step"); } diff --git a/src/main/java/org/reactome/release/update_stable_ids/StableIdentifierUpdater.java b/src/main/java/org/reactome/release/update_stable_ids/StableIdentifierUpdater.java index 301ed414..6a7d762f 100644 --- a/src/main/java/org/reactome/release/update_stable_ids/StableIdentifierUpdater.java +++ b/src/main/java/org/reactome/release/update_stable_ids/StableIdentifierUpdater.java @@ -1,168 +1,265 @@ package org.reactome.release.update_stable_ids; -import static org.gk.model.ReactomeJavaConstants.*; - +import java.sql.SQLException; import java.util.*; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.gk.model.GKInstance; +import org.gk.model.ReactomeJavaConstants; import org.gk.persistence.MySQLAdaptor; -import org.gk.schema.InvalidAttributeException; +import org.gk.persistence.TransactionsNotSupportedException; import org.reactome.release.common.database.InstanceEditUtils; public class StableIdentifierUpdater { private static final Logger logger = LogManager.getLogger(); - @SuppressWarnings("unchecked") - public static void updateStableIdentifiers(MySQLAdaptor dbaSlice, MySQLAdaptor dbaPrevSlice, MySQLAdaptor dbaGkCentral, Long personId) throws Exception { + private MySQLAdaptor dbaSlice; + private MySQLAdaptor dbaPrevSlice; + private MySQLAdaptor dbaGKCentral; + private long personId; - logger.info("Generating InstanceEdits for " + dbaSlice.getDBName() + " and " + dbaGkCentral.getDBName()); - // Instance Edits for test_slice and gk_central - String creatorName = "org.reactome.release.updateStableIds"; - GKInstance sliceIE = InstanceEditUtils.createInstanceEdit(dbaSlice, personId, creatorName); - GKInstance gkCentralIE = InstanceEditUtils.createInstanceEdit(dbaGkCentral, personId, creatorName); + private GKInstance sliceInstanceEdit; + private GKInstance gkCentralInstanceEdit; - // At time of writing (December 2018), test_slice is a non-transactional database. This check has been put in place as a safety net in case that changes. - if (dbaSlice.supportsTransactions()) { - dbaSlice.startTransaction(); - } - dbaGkCentral.startTransaction(); + public StableIdentifierUpdater( + MySQLAdaptor dbaSlice, MySQLAdaptor dbaPrevSlice, MySQLAdaptor dbaGkCentral, long personId) { - //TODO: Perl wrapper will create a 'snapshot' of the previous slice -- once the wrapper is retired this needs to be done + this.dbaSlice = dbaSlice; + this.dbaPrevSlice = dbaPrevSlice; + this.dbaGKCentral = dbaGkCentral; + this.personId = personId; + } - logger.info("Fetching all Event and PhysicalEntity instances"); - // Get all Event and PhysicalEntity instances and combine them into one large List - Collection eventInstances = dbaSlice.fetchInstancesByClass(Event); - Collection physicalEntityInstances = dbaSlice.fetchInstancesByClass(PhysicalEntity); - List sliceInstances = new ArrayList(); - sliceInstances.addAll(eventInstances); - sliceInstances.addAll(physicalEntityInstances); + @SuppressWarnings("unchecked") + public void update() throws Exception { + startTransaction(); + //TODO: Perl wrapper will create a 'snapshot' of the previous slice -- once the wrapper is retired this needs to be done int incrementedCount = 0; int notIncrementedCount = 0; - logger.info("Total instances to check: " + sliceInstances.size()); + List sliceInstances = getSliceInstances(); + logger.info("Total instances to check: " + sliceInstances.size()); for (GKInstance sliceInstance : sliceInstances) { logger.info("Checking " + sliceInstance); - GKInstance gkCentralInstance = dbaGkCentral.fetchInstance(sliceInstance.getDBID()); - GKInstance prevSliceInstance = dbaPrevSlice.fetchInstance(sliceInstance.getDBID()); + GKInstance gkCentralInstance = getDbaGKCentral().fetchInstance(sliceInstance.getDBID()); + GKInstance prevSliceInstance = getDbaPrevSlice().fetchInstance(sliceInstance.getDBID()); // Check if instance is new and that it exists on gkCentral (they could be deleted) - if (prevSliceInstance != null && gkCentralInstance != null) { - - // Compare number of 'Modified' instances between slices - Collection sliceInstanceModified = sliceInstance.getAttributeValuesList(modified); - Collection prevSliceInstanceModified = prevSliceInstance.getAttributeValuesList(modified); - if (sliceInstanceModified.size() > prevSliceInstanceModified.size()) { - // Make sure StableIdentifier instance exists - if (sliceInstance.getAttributeValue(stableIdentifier) != null && gkCentralInstance.getAttributeValue(stableIdentifier) != null) { - logger.info("\tIncrementing " + sliceInstance.getAttributeValue(stableIdentifier)); - incrementStableIdentifier(sliceInstance, dbaSlice, sliceIE); - incrementStableIdentifier(gkCentralInstance, dbaGkCentral, gkCentralIE); - incrementedCount++; - } else if (sliceInstance.getAttributeValue(stableIdentifier) == null){ - logger.warn(sliceInstance + ": could not locate StableIdentifier instance"); - } else { - logger.warn(prevSliceInstance + ": Instance from previous slice did not have StableIdentifier instance"); - } - } else { - if (sliceInstanceModified.size() < prevSliceInstanceModified.size()) { - logger.fatal(sliceInstance + " in current release has less modification instances than previous release"); - throw new IllegalStateException("Found instance with less modification instances than in previous release -- terminating"); - } - notIncrementedCount++; + if (prevSliceInstance == null || gkCentralInstance == null) { + if (gkCentralInstance == null) { + logger.warn(sliceInstance + " -- Instance not found in gkCentral"); + } + continue; + } + + // Compare number of 'Modified' instances between slices + Collection sliceInstanceModified = sliceInstance.getAttributeValuesList(ReactomeJavaConstants.modified); + Collection prevSliceInstanceModified = prevSliceInstance.getAttributeValuesList(ReactomeJavaConstants.modified); + + if (sliceInstanceModified.size() < prevSliceInstanceModified.size()) { + String errorMessage = + sliceInstance + " in current release has less modification instances than previous release"; + logger.fatal(errorMessage); + throw new IllegalStateException(errorMessage); + } + + if (sliceInstanceModified.size() > prevSliceInstanceModified.size()) { + boolean incrementSuccessful = attemptIncrementOfStableId(sliceInstance, gkCentralInstance, prevSliceInstance); + if (incrementSuccessful) { + incrementedCount++; } - // Instances that have been updated already during the current release will have their 'releaseStatus' attribute equal to 'UPDATED'. - // This will make sure that StableIDs are only updated once per release. - try { - if (isUpdated(sliceInstance, prevSliceInstance, dbaPrevSlice)) { - logger.info("Checking if " + sliceInstance + " needs to be updated"); - String releaseStatusString = (String) sliceInstance.getAttributeValue(releaseStatus); - String updated = "UPDATED"; - - if (releaseStatusString == null || !releaseStatusString.equals(updated)) { - logger.info("Updating release status for " + sliceInstance); - sliceInstance.addAttributeValue(releaseStatus, updated); - sliceInstance.addAttributeValue(modified, sliceIE); - dbaSlice.updateInstanceAttribute(sliceInstance, releaseStatus); - dbaSlice.updateInstanceAttribute(sliceInstance, modified); - } else { - logger.info("StableIdentifer has already been updated during this release"); - } + } else { + notIncrementedCount++; + } + // Instances that have been updated already during the current release will have their 'releaseStatus' + // attribute equal to 'UPDATED'. + // This will make sure that StableIDs are only updated once per release. + try { + if (isUpdated(sliceInstance, prevSliceInstance)) { + logger.info("Checking if " + sliceInstance + " needs to be updated"); + String releaseStatusString = (String) sliceInstance.getAttributeValue(ReactomeJavaConstants.releaseStatus); + String updated = "UPDATED"; + + if (releaseStatusString == null || !releaseStatusString.equals(updated)) { + logger.info("Updating release status for " + sliceInstance); + sliceInstance.addAttributeValue(ReactomeJavaConstants.releaseStatus, updated); + sliceInstance.addAttributeValue(ReactomeJavaConstants.modified, getSliceInstanceEdit()); + getDbaSlice().updateInstanceAttribute(sliceInstance, ReactomeJavaConstants.releaseStatus); + getDbaSlice().updateInstanceAttribute(sliceInstance, ReactomeJavaConstants.modified); + } else { + logger.info("StableIdentifier has already been updated during this release"); } - } catch (Exception e) { - e.printStackTrace(); } - } else if (gkCentralInstance == null) { - logger.warn(sliceInstance + " -- Instance not found in gkCentral"); + } catch (Exception e) { + logger.error("Unable to check if {} was updated", sliceInstance, e); } } - // TODO: Update test_slice after gkCentral has been successfully updated - if (dbaSlice.supportsTransactions()) { - dbaSlice.commit(); - } - logger.info("Commiting all changes in " + dbaGkCentral.getDBName()); - dbaGkCentral.commit(); + commit(); + logger.info(incrementedCount + " Stable Identifiers were updated"); logger.info(notIncrementedCount + " were not updated"); logger.info("UpdateStableIdentifiers step has finished"); } + private GKInstance getSliceInstanceEdit() throws Exception { + if (this.sliceInstanceEdit == null) { + this.sliceInstanceEdit = getInstanceEdit(getDbaSlice()); + } + + return this.sliceInstanceEdit; + } + + private GKInstance getGkCentralInstanceEdit() throws Exception { + if (this.gkCentralInstanceEdit == null) { + this.gkCentralInstanceEdit = getInstanceEdit(getDbaGKCentral()); + } + + return this.gkCentralInstanceEdit; + } + + private GKInstance getInstanceEdit(MySQLAdaptor dbAdaptor) throws Exception { + final String creatorName = "org.reactome.release.updateStableIds"; + return InstanceEditUtils.createInstanceEdit(dbAdaptor, getPersonId(), creatorName); + } + + private List getSliceInstances() throws Exception { + logger.info("Fetching all Event and PhysicalEntity instances"); + // Get all Event and PhysicalEntity instances and combine them into one large List + List sliceInstances = new ArrayList<>(); + + Collection eventInstances = + getDbaSlice().fetchInstancesByClass(ReactomeJavaConstants.Event); + Collection physicalEntityInstances = + getDbaSlice().fetchInstancesByClass(ReactomeJavaConstants.PhysicalEntity); + sliceInstances.addAll(eventInstances); + sliceInstances.addAll(physicalEntityInstances); + return sliceInstances; + } + + private boolean attemptIncrementOfStableId(GKInstance sliceInstance, GKInstance gkCentralInstance, GKInstance prevSliceInstance) throws Exception { + // Make sure StableIdentifier instance exists + if (sliceInstance.getAttributeValue(ReactomeJavaConstants.stableIdentifier) != null && gkCentralInstance.getAttributeValue(ReactomeJavaConstants.stableIdentifier) != null) { + logger.info("\tIncrementing " + sliceInstance.getAttributeValue(ReactomeJavaConstants.stableIdentifier)); + incrementStableIdentifier(sliceInstance, getDbaSlice(), getSliceInstanceEdit()); + incrementStableIdentifier(gkCentralInstance, getDbaGKCentral(), getGkCentralInstanceEdit()); + return true; + } else if (sliceInstance.getAttributeValue(ReactomeJavaConstants.stableIdentifier) == null){ + logger.warn(sliceInstance + ": could not locate StableIdentifier instance"); + } else { + logger.warn(prevSliceInstance + ": Instance from previous slice did not have StableIdentifier instance"); + } + return false; + } + // Increments the identifierVersion attribute and updates the StableIdentifier displayName accordingly. // TODO: Integration Testing of increment function - private static void incrementStableIdentifier(GKInstance instance, MySQLAdaptor dba, GKInstance instanceEdit) throws InvalidAttributeException, Exception { - GKInstance stableIdentifierInst = (GKInstance) instance.getAttributeValue(stableIdentifier); - String id = (String) stableIdentifierInst.getAttributeValue(identifier); - int idVersion = Integer.valueOf((String) stableIdentifierInst.getAttributeValue(identifierVersion)); + private void incrementStableIdentifier(GKInstance instance, MySQLAdaptor dba, GKInstance instanceEdit) throws Exception { + GKInstance stableIdentifierInst = (GKInstance) instance.getAttributeValue(ReactomeJavaConstants.stableIdentifier); + String id = (String) stableIdentifierInst.getAttributeValue(ReactomeJavaConstants.identifier); + int idVersion = Integer.parseInt((String) stableIdentifierInst.getAttributeValue(ReactomeJavaConstants.identifierVersion)); int newIdentifierVersion = idVersion + 1; - stableIdentifierInst.addAttributeValue(identifierVersion, String.valueOf(newIdentifierVersion)); + stableIdentifierInst.addAttributeValue(ReactomeJavaConstants.identifierVersion, String.valueOf(newIdentifierVersion)); stableIdentifierInst.setDisplayName(id + "." + newIdentifierVersion); - Collection modifiedInstances = (Collection) stableIdentifierInst.getAttributeValuesList(modified); - stableIdentifierInst.addAttributeValue(modified, instanceEdit); - dba.updateInstanceAttribute(stableIdentifierInst, identifierVersion); - dba.updateInstanceAttribute(stableIdentifierInst, _displayName); - dba.updateInstanceAttribute(stableIdentifierInst, modified); + Collection modifiedInstances = (Collection) stableIdentifierInst.getAttributeValuesList(ReactomeJavaConstants.modified); + stableIdentifierInst.addAttributeValue(ReactomeJavaConstants.modified, instanceEdit); + dba.updateInstanceAttribute(stableIdentifierInst, ReactomeJavaConstants.identifierVersion); + dba.updateInstanceAttribute(stableIdentifierInst, ReactomeJavaConstants._displayName); + dba.updateInstanceAttribute(stableIdentifierInst, ReactomeJavaConstants.modified); } // Checks via the 'releaseStatus', 'revised', and 'reviewed' attributes if this instance has been updated since last release. // Also goes through any child 'hasEvent' instances and recursively checks as well. - private static boolean isUpdated(GKInstance sliceInstance, GKInstance prevSliceInstance, MySQLAdaptor dbaPrevSlice) throws InvalidAttributeException, Exception { + private boolean isUpdated(GKInstance sliceInstance, GKInstance prevSliceInstance) throws Exception { + if (!isEvent(sliceInstance)) { + return false; + } - if (sliceInstance.getSchemClass().isa(Event)) { - if (sliceInstance.getAttributeValue(releaseStatus) != null) { - return true; - } + return hasReleaseStatus(sliceInstance) || + (recentlyRevised(sliceInstance, prevSliceInstance) || recentlyReviewed(sliceInstance, prevSliceInstance)) || + (isPathway(sliceInstance) && anyChildEventInstancesUpdated(sliceInstance)); + } - Collection revisedInstances = sliceInstance.getAttributeValuesList(revised); - Collection prevRevisedInstances = prevSliceInstance.getAttributeValuesList(revised); + private void startTransaction() throws SQLException, TransactionsNotSupportedException { + // At time of writing (December 2018), test_slice is a non-transactional database. + // This check has been put in place as a safety net in case that changes. + if (getDbaSlice().supportsTransactions()) { + getDbaSlice().startTransaction(); + } + getDbaGKCentral().startTransaction(); + } - if (revisedInstances.size() > prevRevisedInstances.size()) { - return true; - } + private void commit() throws SQLException { + // TODO: Update test_slice after gkCentral has been successfully updated + if (getDbaSlice().supportsTransactions()) { + getDbaSlice().commit(); + } + logger.info("Commiting all changes in " + getDbaGKCentral().getDBName()); + getDbaGKCentral().commit(); + } - Collection reviewedInstances = sliceInstance.getAttributeValuesList(reviewed); - Collection prevReviewedInstances = prevSliceInstance.getAttributeValuesList(reviewed); - if (reviewedInstances.size() > prevReviewedInstances.size()) { - return true; - } + private boolean isEvent(GKInstance sliceInstance) { + return sliceInstance.getSchemClass().isa(ReactomeJavaConstants.Event); + } - if (sliceInstance.getSchemClass().isValidAttribute(hasEvent)) { - Collection eventInstances = sliceInstance.getAttributeValuesList(hasEvent); - for (GKInstance eventInst : eventInstances) { - GKInstance prevEventInst = dbaPrevSlice.fetchInstance(eventInst.getDBID()); - - try { - if (prevEventInst != null && isUpdated(eventInst, prevEventInst, dbaPrevSlice)) { - return true; - } - } catch (Exception e) { - e.printStackTrace(); - } + private boolean hasReleaseStatus(GKInstance sliceInstance) throws Exception { + return sliceInstance.getAttributeValue(ReactomeJavaConstants.releaseStatus) != null; + } + + private boolean recentlyRevised(GKInstance sliceInstance, GKInstance prevSliceInstance) throws Exception { + Collection revisedInstances = sliceInstance.getAttributeValuesList(ReactomeJavaConstants.revised); + Collection prevRevisedInstances = prevSliceInstance.getAttributeValuesList(ReactomeJavaConstants.revised); + + if (revisedInstances.size() > prevRevisedInstances.size()) { + return true; + } + return false; + } + + private boolean recentlyReviewed(GKInstance sliceInstance, GKInstance prevSliceInstance) throws Exception { + Collection reviewedInstances = sliceInstance.getAttributeValuesList(ReactomeJavaConstants.reviewed); + Collection prevReviewedInstances = prevSliceInstance.getAttributeValuesList(ReactomeJavaConstants.reviewed); + if (reviewedInstances.size() > prevReviewedInstances.size()) { + return true; + } + return false; + } + + private boolean isPathway(GKInstance sliceInstance) { + return sliceInstance.getSchemClass().isValidAttribute(ReactomeJavaConstants.hasEvent); + } + + private boolean anyChildEventInstancesUpdated(GKInstance sliceInstance) throws Exception { + Collection eventInstances = sliceInstance.getAttributeValuesList(ReactomeJavaConstants.hasEvent); + for (GKInstance eventInst : eventInstances) { + GKInstance prevEventInst = getDbaPrevSlice().fetchInstance(eventInst.getDBID()); + + try { + if (prevEventInst != null && isUpdated(eventInst, prevEventInst)) { + return true; } + } catch (Exception e) { + logger.error("Unable to check if {} is updated", eventInst, e); } } return false; } + + private MySQLAdaptor getDbaSlice() { + return this.dbaSlice; + } + + private MySQLAdaptor getDbaPrevSlice() { + return this.dbaPrevSlice; + } + + private MySQLAdaptor getDbaGKCentral() { + return this.dbaGKCentral; + } + + private long getPersonId() { + return this.personId; + } } diff --git a/src/test/java/org/reactome/release/update_stable_ids/StableIdentifierUpdaterTest.java b/src/test/java/org/reactome/release/update_stable_ids/StableIdentifierUpdaterTest.java index a28a1e09..1730e4e3 100644 --- a/src/test/java/org/reactome/release/update_stable_ids/StableIdentifierUpdaterTest.java +++ b/src/test/java/org/reactome/release/update_stable_ids/StableIdentifierUpdaterTest.java @@ -56,7 +56,7 @@ public void setUp() { } @Test - public void updateStableIdentifiersTest() throws Exception { + public void updateTest() throws Exception { PowerMockito.mockStatic(InstanceEditUtils.class); @@ -83,11 +83,13 @@ public void updateStableIdentifiersTest() throws Exception { Mockito.when(mockInstance.getAttributeValuesList("reviewed")).thenReturn(sliceList); Mockito.when(mockInstance2.getAttributeValuesList("reviewed")).thenReturn(sliceList2); - StableIdentifierUpdater.updateStableIdentifiers(mockSliceAdaptor, mockPrevSliceAdaptor, mockGkCentralAdaptor, 12345L); + StableIdentifierUpdater stableIdentifierUpdater = + new StableIdentifierUpdater(mockSliceAdaptor, mockPrevSliceAdaptor, mockGkCentralAdaptor, 12345L); + stableIdentifierUpdater.update(); } @Test - public void updateStableIdentifiersModifiedListsWithSameSizeTest() throws Exception { + public void updateModifiedListsWithSameSizeTest() throws Exception { PowerMockito.mockStatic(InstanceEditUtils.class); sliceList = Arrays.asList(mockInstance); @@ -105,6 +107,8 @@ public void updateStableIdentifiersModifiedListsWithSameSizeTest() throws Except Mockito.when(mockInstance.getSchemClass()).thenReturn(mockSchemaClass); Mockito.when(mockInstance.getSchemClass().isa("Event")).thenReturn(false); - StableIdentifierUpdater.updateStableIdentifiers(mockSliceAdaptor, mockPrevSliceAdaptor, mockGkCentralAdaptor, 12345L); + StableIdentifierUpdater stableIdentifierUpdater = + new StableIdentifierUpdater(mockSliceAdaptor, mockPrevSliceAdaptor, mockGkCentralAdaptor, 12345L); + stableIdentifierUpdater.update(); } } \ No newline at end of file From 76236cbc69b3bc87d3f1d7409af671a1cc0a4dd1 Mon Sep 17 00:00:00 2001 From: Joel Weiser Date: Fri, 30 Aug 2024 12:54:47 -0400 Subject: [PATCH 3/3] changes st id increment test to use update tracker instances --- .../StableIdentifierUpdater.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/reactome/release/update_stable_ids/StableIdentifierUpdater.java b/src/main/java/org/reactome/release/update_stable_ids/StableIdentifierUpdater.java index 6a7d762f..c840302b 100644 --- a/src/main/java/org/reactome/release/update_stable_ids/StableIdentifierUpdater.java +++ b/src/main/java/org/reactome/release/update_stable_ids/StableIdentifierUpdater.java @@ -54,18 +54,18 @@ public void update() throws Exception { continue; } - // Compare number of 'Modified' instances between slices - Collection sliceInstanceModified = sliceInstance.getAttributeValuesList(ReactomeJavaConstants.modified); - Collection prevSliceInstanceModified = prevSliceInstance.getAttributeValuesList(ReactomeJavaConstants.modified); + // Compare number of 'Update Tracker' instances between slices + Collection sliceInstanceUpdateTracker = getUpdateTrackerInstances(sliceInstance); + Collection prevSliceUpdateTracker = getUpdateTrackerInstances(prevSliceInstance); - if (sliceInstanceModified.size() < prevSliceInstanceModified.size()) { + if (sliceInstanceUpdateTracker.size() < prevSliceUpdateTracker.size()) { String errorMessage = - sliceInstance + " in current release has less modification instances than previous release"; + sliceInstance + " in current release has fewer update tracker instances than previous release"; logger.fatal(errorMessage); throw new IllegalStateException(errorMessage); } - if (sliceInstanceModified.size() > prevSliceInstanceModified.size()) { + if (sliceInstanceUpdateTracker.size() > prevSliceUpdateTracker.size()) { boolean incrementSuccessful = attemptIncrementOfStableId(sliceInstance, gkCentralInstance, prevSliceInstance); if (incrementSuccessful) { incrementedCount++; @@ -138,6 +138,11 @@ private List getSliceInstances() throws Exception { return sliceInstances; } + private List getUpdateTrackerInstances(GKInstance instance) throws Exception { + Collection updateTrackerInstances = instance.getReferers("updatedInstance"); + return updateTrackerInstances != null ? new ArrayList<>(updateTrackerInstances) : new ArrayList<>(); + } + private boolean attemptIncrementOfStableId(GKInstance sliceInstance, GKInstance gkCentralInstance, GKInstance prevSliceInstance) throws Exception { // Make sure StableIdentifier instance exists if (sliceInstance.getAttributeValue(ReactomeJavaConstants.stableIdentifier) != null && gkCentralInstance.getAttributeValue(ReactomeJavaConstants.stableIdentifier) != null) {