@Override public boolean isSaved() { return getId() != UNSAVED_ID; }
private void applyChanges(ArrayRun from, ArrayRun to) { to.setAlias(from.getAlias()); to.setDescription(from.getDescription()); to.setFilePath(from.getFilePath()); to.setArray(from.getArray()); to.setHealth(from.getHealth()); to.setStartDate(from.getStartDate()); to.setCompletionDate(from.getCompletionDate()); }
private void loadChildEntities(ArrayRun arrayRun) throws IOException { if (arrayRun.getInstrument() != null) { arrayRun.setInstrument(instrumentService.get(arrayRun.getInstrument().getId())); } if (arrayRun.getArray() != null) { Array array = arrayService.get(arrayRun.getArray().getId()); if (array == null) { // providing a way to detect "array not found" in validation arrayRun.getArray().setAlias(null); } else { arrayRun.setArray(array); } } }
public static ArrayRunDto asDto(@Nonnull ArrayRun from) { ArrayRunDto dto = new ArrayRunDto(); dto.setId(from.getId()); dto.setAlias(from.getAlias()); dto.setDescription(from.getDescription()); dto.setFilePath(from.getFilePath()); if (from.getInstrument() != null) { dto.setInstrumentId(from.getInstrument().getId()); dto.setInstrumentName(from.getInstrument().getName()); } if (from.getArray() != null) { dto.setArray(asDto(from.getArray())); } dto.setStatus(from.getHealth().getKey()); if (from.getStartDate() != null) { dto.setStartDate(formatDate(from.getStartDate())); } if (from.getCompletionDate() != null) { dto.setCompletionDate(formatDate(from.getCompletionDate())); } if (from.getLastModified() != null) { dto.setLastModified(formatDate(from.getLastModified())); } return dto; }
public static final ArrayRun to(@Nonnull ArrayRunDto from) { ArrayRun run = new ArrayRun(); if (from.getId() != null) { run.setId(from.getId()); } run.setAlias(from.getAlias()); run.setDescription(nullifyStringIfBlank(from.getDescription())); run.setFilePath(nullifyStringIfBlank(from.getFilePath())); run.setInstrument(new InstrumentImpl()); if (from.getInstrumentId() != null) { run.getInstrument().setId(from.getInstrumentId()); } if (from.getInstrumentName() != null) { run.getInstrument().setName(from.getInstrumentName()); } if (from.getArray() != null) { run.setArray(to(from.getArray())); } run.setHealth(HealthType.get(from.getStatus())); if (from.getStartDate() != null) { run.setStartDate(parseDate(from.getStartDate())); } if (from.getCompletionDate() != null) { run.setCompletionDate(parseDate(from.getCompletionDate())); } if (from.getLastModified() != null) { run.setLastModified(parseDate(from.getLastModified())); } return run; }
List<ValidationError> errors = new ArrayList<>(); if (arrayRun.getId() != ArrayRun.UNSAVED_ID && beforeChange == null) { errors.add(new ValidationError("Array Run not found")); if (isStringEmptyOrNull(arrayRun.getAlias())) { errors.add(new ValidationError("alias", "Alias cannot be blank")); if (arrayRun.getInstrument() == null) { errors.add(new ValidationError("instrument", "An instrument must be selected")); } else if (arrayRun.getInstrument().getInstrumentModel().getInstrumentType() != InstrumentType.ARRAY_SCANNER) { errors.add(new ValidationError("instrument", "Instrument must be an array scanner")); if (beforeChange == null || !arrayRun.getAlias().equals(beforeChange.getAlias())) { ArrayRun duplicateAlias = arrayRunStore.getByAlias(arrayRun.getAlias()); if (duplicateAlias != null) { errors.add(new ValidationError("alias", "There is already an array run with this alias")); if (arrayRun.getArray() != null && arrayRun.getArray().getAlias() == null) { errors.add(new ValidationError("array", "Array not found"));
private long update(ArrayRun arrayRun) throws IOException { ArrayRun managed = get(arrayRun.getId()); validateChange(arrayRun, managed); applyChanges(arrayRun, managed); managed.setChangeDetails(authorizationManager.getCurrentUser()); return arrayRunStore.save(managed); }
private void validateStatusAndCompletion(ArrayRun arrayRun, ArrayRun beforeChange, List<ValidationError> errors) throws IOException { if (arrayRun.getHealth() == null) { errors.add(new ValidationError("status", "A status must be selected")); } else if (arrayRun.getHealth().isDone()) { if (arrayRun.getCompletionDate() == null) { errors.add(new ValidationError(FIELD_COMPLETIONDATE, "Completion date must be entered for a completed run")); } else if (!authorizationManager.isAdminUser() && beforeChange != null && beforeChange.getCompletionDate() != null && !arrayRun.getCompletionDate().equals(beforeChange.getCompletionDate())) { errors.add(new ValidationError(FIELD_COMPLETIONDATE, "Only admin may change completion date of a completed run")); } } else if (arrayRun.getCompletionDate() != null) { errors.add(new ValidationError(FIELD_COMPLETIONDATE, "Cannot set completion date for incomplete run")); } }
private void validateStartDate(ArrayRun arrayRun, ArrayRun beforeChange, List<ValidationError> errors) throws IOException { if (arrayRun.getStartDate() == null) { errors.add(new ValidationError("startDate", "Start date cannot be blank")); } else if (!authorizationManager.isAdminUser() && beforeChange != null && beforeChange.getStartDate() != null && !arrayRun.getStartDate().equals(beforeChange.getStartDate())) { errors.add(new ValidationError("startDate", "Only admin may change start date")); } }
@Override public Long getId() { return arrayRun.getId(); }
@Override public long save(ArrayRun arrayRun) throws IOException { loadChildEntities(arrayRun); if (arrayRun.getId() == ArrayRun.UNSAVED_ID) { return create(arrayRun); } else { return update(arrayRun); } }