Skip to content

Commit

Permalink
Compare by association ID instead of equals
Browse files Browse the repository at this point in the history
  • Loading branch information
rpoet-jh committed Oct 9, 2023
1 parent 2edf834 commit a25827c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@
import java.time.ZonedDateTime;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.pass.support.client.PassClient;
Expand Down Expand Up @@ -313,6 +317,24 @@ private void updateGrants(Collection<Map<String, String>> results) {
}
}

/**
* Returns the Pass entity ID of passEntity. This method is null-safe.
* @param passEntity the passEntity
* @return the ID of passEntity or null if passEntity is null or the ID is null
*/
protected String getPassEntityId(PassEntity passEntity) {
return Optional.ofNullable(passEntity).map(PassEntity::getId).orElse(null);
}

/**
* Returns a Set of Pass entity ID of passEntities.
* @param passEntities the list of passEntities
* @return the Set of passEntity IDs
*/
protected Set<String> getPassEntityIds(List<? extends PassEntity> passEntities) {
return passEntities.stream().map(PassEntity::getId).collect(Collectors.toSet());
}

private void updateUsers(Collection<Map<String, String>> results) {

boolean modeChecked = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package org.eclipse.pass.support.grant.data;

import java.util.HashSet;

import org.eclipse.pass.support.client.model.Grant;
import org.eclipse.pass.support.client.model.User;

Expand Down Expand Up @@ -75,50 +73,59 @@ public Grant updateGrantIfNeeded(Grant system, Grant stored) {
*/

private boolean grantNeedsUpdate(Grant system, Grant stored) {
if (system.getAwardNumber() != null ? !system.getAwardNumber()
.equals(
stored.getAwardNumber()) : stored.getAwardNumber() != null) {
if (system.getAwardNumber() != null
? !system.getAwardNumber().equals(stored.getAwardNumber())
: stored.getAwardNumber() != null) {
return true;
}
if (system.getAwardStatus() != null ? !system.getAwardStatus()
.equals(
stored.getAwardStatus()) : stored.getAwardStatus() != null) {
if (system.getAwardStatus() != null
? !system.getAwardStatus().equals(stored.getAwardStatus())
: stored.getAwardStatus() != null) {
return true;
}
if (system.getLocalKey() != null ? !system.getLocalKey()
.equals(stored.getLocalKey()) : stored.getLocalKey() != null) {
if (system.getLocalKey() != null
? !system.getLocalKey().equals(stored.getLocalKey())
: stored.getLocalKey() != null) {
return true;
}
if (system.getProjectName() != null ? !system.getProjectName()
.equals(
stored.getProjectName()) : stored.getProjectName() != null) {
if (system.getProjectName() != null
? !system.getProjectName().equals(stored.getProjectName())
: stored.getProjectName() != null) {
return true;
}
if (system.getPrimaryFunder() != null ? !system.getPrimaryFunder().equals(
stored.getPrimaryFunder()) : stored.getPrimaryFunder() != null) {
if (system.getPrimaryFunder() != null
? !system.getPrimaryFunder().getId().equals(getPassEntityId(stored.getPrimaryFunder()))
: stored.getPrimaryFunder() != null) {
return true;
}
if (system.getDirectFunder() != null ? !system.getDirectFunder().equals(
stored.getDirectFunder()) : stored.getDirectFunder() != null) {
if (system.getDirectFunder() != null
? !system.getDirectFunder().getId().equals(getPassEntityId(stored.getDirectFunder()))
: stored.getDirectFunder() != null) {
return true;
}
if (system.getPi() != null ? !system.getPi().equals(stored.getPi()) : stored.getPi() != null) {
if (system.getPi() != null
? !system.getPi().getId().equals(getPassEntityId(stored.getPi()))
: stored.getPi() != null) {
return true;
}
if (system.getCoPis() != null ? !new HashSet(system.getCoPis()).equals(
new HashSet(stored.getCoPis())) : stored.getCoPis() != null) {
if (system.getCoPis() != null
? !getPassEntityIds(system.getCoPis()).equals(getPassEntityIds(stored.getCoPis()))
: stored.getCoPis() != null) {
return true;
}
if (system.getAwardDate() != null ? system.getAwardDate()
.isBefore(stored.getAwardDate()) : stored.getAwardDate() != null) {
if (system.getAwardDate() != null
? system.getAwardDate().isBefore(stored.getAwardDate())
: stored.getAwardDate() != null) {
return true;
}
if (system.getStartDate() != null ? system.getStartDate()
.isBefore(stored.getStartDate()) : stored.getStartDate() != null) {
if (system.getStartDate() != null
? system.getStartDate().isBefore(stored.getStartDate())
: stored.getStartDate() != null) {
return true;
}
if (system.getEndDate() != null ? system.getEndDate()
.isAfter(stored.getEndDate()) : stored.getEndDate() != null) {
if (system.getEndDate() != null
? system.getEndDate().isAfter(stored.getEndDate())
: stored.getEndDate() != null) {
return true;
}
return false;
Expand All @@ -132,7 +139,7 @@ private boolean grantNeedsUpdate(Grant system, Grant stored) {
* @return the Grant object which represents the Pass object, with any new information from COEUS merged in
*/
private Grant updateGrant(Grant system, Grant stored) {
differenceLogger.log(system, stored);
differenceLogger.log(stored, system);
stored.setAwardNumber(system.getAwardNumber());
stored.setAwardStatus(system.getAwardStatus());
stored.setLocalKey(system.getLocalKey());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,14 @@ private boolean funderNeedsUpdate(Funder system, Funder stored) {
if (system.getName() != null && !system.getName().equals(stored.getName())) {
return true;
}
if (system.getLocalKey() != null ? !system.getLocalKey()
.equals(stored.getLocalKey()) : stored.getLocalKey() != null) {
if (system.getLocalKey() != null
? !system.getLocalKey().equals(stored.getLocalKey())
: stored.getLocalKey() != null) {
return true;
}
if (system.getPolicy() != null ? !system.getPolicy().equals(stored.getPolicy()) : stored.getPolicy() != null) {
if (system.getPolicy() != null
? !system.getPolicy().getId().equals(getPassEntityId(stored.getPolicy()))
: stored.getPolicy() != null) {
return true;
}
return false;
Expand Down Expand Up @@ -244,20 +247,24 @@ private User updateUser(User system, User stored) {
* @return a boolean which asserts whether the two supplied Grants are "COEUS equal"
*/
private boolean grantNeedsUpdate(Grant system, Grant stored) {
if (system.getAwardStatus() != null ? !system.getAwardStatus()
.equals(
stored.getAwardStatus()) : stored.getAwardStatus() != null) {
if (system.getAwardStatus() != null
? !system.getAwardStatus().equals(stored.getAwardStatus())
: stored.getAwardStatus() != null) {
return true;
}
if (system.getPi() != null ? !system.getPi().equals(stored.getPi()) : stored.getPi() != null) {
if (system.getPi() != null
? !system.getPi().getId().equals(getPassEntityId(stored.getPi()))
: stored.getPi() != null) {
return true;
}
if (system.getCoPis() != null ? !new HashSet(system.getCoPis()).equals(
new HashSet(stored.getCoPis())) : stored.getCoPis() != null) {
if (system.getCoPis() != null
? !getPassEntityIds(system.getCoPis()).equals(getPassEntityIds(stored.getCoPis()))
: stored.getCoPis() != null) {
return true;
}
if (system.getEndDate() != null ? system.getEndDate()
.isAfter(stored.getEndDate()) : stored.getEndDate() != null) {
if (system.getEndDate() != null
? system.getEndDate().isAfter(stored.getEndDate())
: stored.getEndDate() != null) {
return true;
}
return false;
Expand Down

0 comments on commit a25827c

Please sign in to comment.