Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

Commit

Permalink
adjust behavior to accommodate data peculiarities
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmartino committed May 29, 2020
1 parent d01de2f commit 0ffd3c4
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,37 @@ public User update(User system, User stored) {
* @return the updated object - null if the Grant does not need to be updated
*/
public Grant update(Grant system, Grant stored) {
//adjust the system view of co-pis by merging in the stored view of pi and co-pis
for( URI uri : stored.getCoPis() ) {
if ( !system.getCoPis().contains(uri) ) {
system.getCoPis().add(uri);
}
}

//need to be careful, system pi might be null if there is no record for it
//this is to finalize the version of the co-pi list we want to compare between
//system and stored
URI storedPi = stored.getPi();
if ( system.getPi() != null ) {
if (!system.getPi().equals(storedPi)) {
// stored.setPi( system.getPi() );
if (!system.getCoPis().contains(storedPi)) {
system.getCoPis().add(storedPi);
}
system.getCoPis().remove(system.getPi());
}
} else { //system view is null, do not trigger update based on this field
system.setPi( storedPi );
}

//now system view has all available info we want in this grant - look for update trigger
if (grantNeedsUpdate(system, stored)) {
return updateGrant(system, stored);
}
return null;
}

/**
/**0p
* Compare two Funder objects
*
* @param system the version of the Funder as seen in the COEUS system pull
Expand All @@ -103,7 +127,7 @@ private boolean funderNeedsUpdate(Funder system, Funder stored) {
* @return the Funder object which represents the Pass object, with any new information from COEUS merged in
*/
private Funder updateFunder (Funder system, Funder stored) {
stored.setLocalKey(system.getLocalKey());
//stored.setLocalKey(system.getLocalKey());
if (system.getName() != null) { stored.setName(system.getName()); }
if (system.getPolicy() != null) { stored.setPolicy(system.getPolicy()); }
return stored;
Expand Down Expand Up @@ -173,34 +197,18 @@ private boolean grantNeedsUpdate(Grant system, Grant stored) {
}

/**
* Update a Pass Grant object with new information from COEUS
* Update a Pass Grant object with new information from COEUS - only updatable fields are considered.
* the PASS version is authoritative for the rest
*
* @param system the version of the Grant as seen in the COEUS system pull
* @param stored the version of the Grant as read from Pass
* @return the Grant object which represents the Pass object, with any new information from COEUS merged in
*/
private Grant updateGrant(Grant system, Grant stored) {
stored.setAwardStatus(system.getAwardStatus());

//adjust the system view of co-pis by merging in the stored view
for( URI uri : stored.getCoPis() ) {
if ( !system.getCoPis().contains(uri) ) {
system.getCoPis().add(uri);
}
}
URI storedPi = stored.getPi();
if ( !system.getPi().equals( storedPi )) {
if ( !system.getCoPis().contains( storedPi )) {
system.getCoPis().add ( storedPi );
}
}
system.getCoPis().remove(system.getPi());

stored.setPi( system.getPi() );
stored.setPi(system.getPi());
stored.setCoPis( system.getCoPis() );
if ( system.getEndDate().isAfter(stored.getEndDate())) {
stored.setEndDate(system.getEndDate());
}
stored.setEndDate(system.getEndDate());
return stored;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,30 @@ public class CoeusPassInitEntityUtil extends CoeusPassEntityUtil {

@Override
public Grant update(Grant system, Grant stored) {
//adjust the system view of co-pis by merging in the stored view of pi and co-pis
for( URI uri : stored.getCoPis() ) {
if ( !system.getCoPis().contains(uri) ) {
system.getCoPis().add(uri);
}
}

//need to be careful, system pi might be null if there is no record for it
//this is to finalize the version of the co-pi list we want to compare between
//system and stored
URI storedPi = stored.getPi();
if ( system.getPi() != null ) {
if (!system.getPi().equals(storedPi)) {
// stored.setPi( system.getPi() );
if (!system.getCoPis().contains(storedPi)) {
system.getCoPis().add(storedPi);
}
system.getCoPis().remove(system.getPi());
}
} else { //system view is null, do not trigger update based on this field
system.setPi( storedPi );
}

//now system view has all available info we want in this grant - look for update trigger
if (this.grantNeedsUpdate(system, stored)) {
return this.updateGrant(system, stored);
}
Expand Down Expand Up @@ -57,23 +81,9 @@ private Grant updateGrant(Grant system, Grant stored) {
stored.setProjectName(system.getProjectName());
stored.setPrimaryFunder(system.getPrimaryFunder());
stored.setDirectFunder(system.getDirectFunder());

//adjust the system view of co-pis by merging in the stored view
for( URI uri : stored.getCoPis() ) {
if ( !system.getCoPis().contains(uri) ) {
system.getCoPis().add(uri);
}
}
URI storedPi = stored.getPi();
if ( !system.getPi().equals( storedPi )) {
if ( !system.getCoPis().contains( storedPi )) {
system.getCoPis().add ( storedPi );
}
}
system.getCoPis().remove(system.getPi());

stored.setPi( system.getPi() );
stored.setPi( system.getPi());
stored.setCoPis( system.getCoPis() );

//since this is essentially an initial pull, we can just take the system values
stored.setAwardDate(system.getAwardDate());
stored.setStartDate(system.getStartDate());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private void updateGrants(Collection<Map<String, String>> results) {
}
}

//now do things which may depend on the date
//now do things which may depend on the date - award date is the only one that changes
DateTime awardDate = createJodaDateTime(rowMap.getOrDefault(C_GRANT_AWARD_DATE, null));
DateTime startDate = createJodaDateTime(rowMap.getOrDefault(C_GRANT_START_DATE, null));
DateTime endDate = createJodaDateTime(rowMap.getOrDefault(C_GRANT_END_DATE, null));
Expand All @@ -180,19 +180,23 @@ private void updateGrants(Collection<Map<String, String>> results) {
//in case they are needed to update a stored grant record.
//these values will not override existing stored values unless the PassEntityUtil implementation
//allows it.
if (startDate != null && (grant.getStartDate() == null || startDate.isBefore(grant.getStartDate()))) {
//we mostly have awardDate, but will use start date as a fallback if not
if ( (awardDate != null && (grant.getAwardDate() == null || awardDate.isBefore(grant.getAwardDate()))) ||
awardDate == null && (startDate != null && (grant.getStartDate() == null || startDate.isBefore(grant.getStartDate())))) {
grant.setProjectName(rowMap.get(C_GRANT_PROJECT_NAME));
grant.setAwardNumber(rowMap.get(C_GRANT_AWARD_NUMBER));
grant.setDirectFunder(funderMap.get(directFunderLocalKey));
grant.setPrimaryFunder(funderMap.get(primaryFunderLocalKey));
grant.setAwardDate(awardDate);
grant.setStartDate(startDate);
grant.setAwardDate(awardDate);
}

//set values that should match the latest iteration of the grant
//use !isBefore in case more than one PI is specified, need to process more than one
if (endDate != null && (grant.getEndDate() == null || !endDate.isBefore(grant.getEndDate()))) {
grant.setEndDate(endDate);
//we mostly have awardDate, but will use end date as a fallback if not
if ( (awardDate != null && (grant.getAwardDate() == null || !awardDate.isBefore(grant.getAwardDate()))) ||
awardDate == null && ( endDate != null && (grant.getEndDate() == null || !endDate.isBefore(grant.getEndDate()))) ){
grant.setEndDate( endDate);
//status should be the latest one
String status = rowMap.getOrDefault(C_GRANT_AWARD_STATUS, null);
if (status != null) {
Expand All @@ -214,12 +218,12 @@ private void updateGrants(Collection<Map<String, String>> results) {
if ( abbreviatedRole.equals("P") ) {
URI userId=userMap.get(employeeId);
URI oldPiId=grant.getPi();
grant.setPi(userId);
grant.getCoPis().remove(userId);
if ( oldPiId == null ) {
grant.setPi(userId);
statistics.addPi();
} else {
if ( !oldPiId.equals(userId) ) {
grant.setPi(userId);
if ( !grant.getCoPis().contains(oldPiId) ) {
grant.getCoPis().add(oldPiId);
statistics.addCoPi();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public class JhuPassUpdaterIT {
String[] grantLocalKey = { "10000001", "10000001","10000001" }; //all the same, different from other ITs tho
String[] grantProjectName = {"Stupendous Research Project I", "Stupendous Research Project II", "Stupendous Research Project III" };
String[] grantAwardDate = { "01/01/1999", "01/01/2001", "01/01/2003" };
String[] grantStartDate = { "07/01/2000", "07/01/2002", "07/01/2004" };
String[] grantEndDate = { "06/30/2002", "06/30/2004", "06/30/2006"};
String[] grantStartDate = { "07/01/2000", "07/01/2000", "07/01/2000" }; //these appear to ge the same for all awards
String[] grantEndDate = { "06/30/2004", "06/30/2004", "06/30/2004"};//these seem to be the same for all awards
String[] grantUpdateTimestamp = { "2006-03-11 00:00:00.0","2010-04-05 00:00:00.0", "2015-11-11 00:00:00.0" };
String[] userEmployeeId= { "31000000", "31000001", "31000002"};
String[] userInstitutionalId = {"arecko1", "sclass1", "jgunn1" };
Expand Down

0 comments on commit 0ffd3c4

Please sign in to comment.