private static boolean isSamePosition(RunPosition pos1, RunPosition pos2) { String pos1Alias = pos1.getPosition() == null ? null : pos1.getPosition().getAlias(); String pos2Alias = pos2.getPosition() == null ? null : pos2.getPosition().getAlias(); if (pos1Alias == null && pos2Alias == null) { return true; } if (pos1Alias == null) { return false; } return pos1Alias.equals(pos2Alias); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; RunPosition other = (RunPosition) obj; if (container == null) { if (other.container != null) return false; } else if (!container.equals(other.container)) return false; if (position == null) { if (other.position != null) return false; } else if (!position.equals(other.position)) return false; if (run == null) { if (other.run != null) return false; } else if (!run.equals(other.run)) return false; return true; }
private InstrumentPosition findPosition(long id, Instrument instrument) { return instrument.getInstrumentModel().getPositions().stream() .filter(p -> p.getId() == id) .findFirst().orElse(null); }
private List<InstrumentStatus> map(List<InstrumentPositionStatus> positions) { Map<Long, InstrumentStatus> statusByInstrumentId = new HashMap<>(); for (InstrumentPositionStatus position : positions) { if (!statusByInstrumentId.containsKey(position.getInstrument().getId())) { InstrumentStatus status = new InstrumentStatus(); status.setInstrument(position.getInstrument()); statusByInstrumentId.put(position.getInstrument().getId(), status); } InstrumentStatus existing = statusByInstrumentId.get(position.getInstrument().getId()); if (position.getPosition() == null) { InstrumentPosition nullPosition = new InstrumentPosition(); nullPosition.setAlias("n/a"); nullPosition.setInstrumentModel(position.getInstrument().getInstrumentModel()); position.setPosition(nullPosition); } if (existing.getPositions().containsKey(position.getPosition())) { // there are likely multiple runs with the same start date Run moreRecent = getMoreRecentRun(existing.getPositions().get(position.getPosition()), position.getRun()); existing.getPositions().put(position.getPosition(), moreRecent); } else { existing.getPositions().put(position.getPosition(), position.getRun()); } } return new ArrayList<>(statusByInstrumentId.values()); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((container == null) ? 0 : container.hashCode()); result = prime * result + ((position == null) ? 0 : position.hashCode()); result = prime * result + ((run == null) ? 0 : run.hashCode()); return result; }
@Override public Set<InstrumentPosition> getOutOfServicePositions() { if (isOutOfService()) { return getInstrumentModel().getPositions(); } return getInstrumentModel().getPositions().stream() .filter(pos -> getServiceRecords().stream().anyMatch(sr -> sr.isOutOfService() && sr.getEndTime() == null && sr.getStartTime() != null && sr.getStartTime().before(new Date()) && sr.getPosition().getAlias().equals(pos.getAlias()))) .collect(Collectors.toSet()); }
private void validateChange(ServiceRecord record, ServiceRecord beforeChange) { List<ValidationError> errors = new ArrayList<>(); if (record.getPosition() != null && findPosition(record.getPosition().getId(), record.getInstrument()) == null) { errors.add(new ValidationError("position", "Position must belong to the same instrument as this record")); } if (!errors.isEmpty()) { throw new ValidationException(errors); } }
from.getPositions().forEach((pos, run) -> { InstrumentPositionStatusDto posDto = new InstrumentPositionStatusDto(); posDto.setPosition(pos.getAlias()); posDto.setRun(run == null ? null : asDto(run)); posDto.setPools(run == null ? Collections.emptyList() ServiceRecord instrumentOutOfServiceRecord = from.getInstrument().getServiceRecords().stream() .filter(sr -> sr.isOutOfService() && sr.getStartTime() != null && sr.getEndTime() == null && (sr.getPosition() == null || sr.getPosition().getAlias().equals(pos.getAlias()))) .min(Comparator.comparing(ServiceRecord::getStartTime)) .orElse(null);
private void applyRecordChanges(ServiceRecord target, ServiceRecord source) { target.setTitle(source.getTitle()); target.setDetails(source.getDetails()); if (source.getPosition() == null) { target.setPosition(null); } else { target.setPosition(findPosition(source.getPosition().getId(), target.getInstrument())); } target.setServicedByName(source.getServicedByName()); target.setReferenceNumber(source.getReferenceNumber()); target.setServiceDate(source.getServiceDate()); target.setStartTime(source.getStartTime()); target.setOutOfService(source.isOutOfService()); target.setEndTime(source.getEndTime()); }
if (!isStringEmptyOrNull(positionName)) { position = target.getSequencer().getInstrumentModel().getPositions().stream() .filter(pos -> positionName.equals(pos.getAlias())) .findFirst().orElseThrow(() -> new IllegalArgumentException(String.format("Unknown position '%s' for platform '%s'", positionName, target.getSequencer().getInstrumentModel().getAlias())));