public String getAlias() { return boxStep.getInput().getAlias(); }
public String getAlias() { return boxStep.getInput().getAlias(); }
private static String getMostSimilarProperty(Box box, String search) { List<String> properties = new ArrayList<>(Arrays.asList(box.getAlias(), box.getName())); if (box.getIdentificationBarcode() != null) { properties.add(box.getIdentificationBarcode()); } return properties.stream().map(String::toLowerCase).filter(p -> p.indexOf(search) >= 0) .min(Comparator.comparingInt(p -> p.indexOf(search))).orElse(""); }
@Override public List<Box> getByPartialSearch(String search, boolean onlyMatchBeginning) { if (search == null) { throw new NullPointerException("No search String provided"); } Criteria criteria = currentSession().createCriteria(BoxImpl.class); criteria.add(Restrictions.or( Restrictions.like("identificationBarcode", search, onlyMatchBeginning ? MatchMode.START : MatchMode.ANYWHERE), Restrictions.like("name", search, onlyMatchBeginning ? MatchMode.START : MatchMode.ANYWHERE), Restrictions.like(FIELD_ALIAS, search, onlyMatchBeginning ? MatchMode.START : MatchMode.ANYWHERE))); @SuppressWarnings("unchecked") List<Box> results = criteria.list(); results.sort((Box b1, Box b2) -> { String p1 = getMostSimilarProperty(b1, search.toLowerCase()); String p2 = getMostSimilarProperty(b2, search.toLowerCase()); if (p1.indexOf(search.toLowerCase()) == p2.indexOf(search.toLowerCase())) { if (p1.length() == p2.length()) { return b1.getAlias().compareTo(b2.getAlias()); } return p1.length() - p2.length(); } return p1.indexOf(search.toLowerCase()) - p2.indexOf(search.toLowerCase()); }); return results; }
@Override public void processInput(BoxProgressStep step) { if (step.getInput().getFreeCount() >= 1) { boxStep = step; } else { error = String.format("Box '%s' is full", step.getInput().getAlias()); } }
private StorageLocation getFreezer(Box box) { if (box.getStorageLocation() == null) { throw new IllegalArgumentException(String.format("%s (%s) does not have a storage location", box.getAlias(), box.getName())); } StorageLocation location = box.getStorageLocation().getFreezerLocation(); if (location == null) { throw new IllegalArgumentException(String.format("Location %s does not have a parent freezer", box.getStorageLocation().getAlias())); } return location; }
@Override public void processInput(BoxProgressStep step) { if (isBoxBigEnough(step)) { boxStep = step; } else { error = String.format("Box '%s' does not have enough space for %d Aliquots (Box only has %d free spaces)", step.getInput().getAlias(), numAliquots, step.getInput().getFreeCount()); } }
/** * Add a changelog entry to record a Box added to or removed from a StorageLocation * * @param location the StorageLocation that box was added to or removed from * @param box the Box that was added or removed * @param addition true for addition; false for removal * @throws IOException */ private void addStorageChangeLog(StorageLocation location, Box box, boolean addition) throws IOException { if (location.getLocationUnit() != LocationUnit.FREEZER) { throw new IllegalArgumentException(String.format("%s is not a freezer", location.getAlias())); } String message = addition ? String.format("Added %s (%s) to %s", box.getAlias(), box.getName(), box.getStorageLocation().getFreezerDisplayLocation()) : (String.format("Removed %s (%s)", box.getAlias(), box.getName())); ChangeLog change = location.createChangeLog(message, "", authorizationManager.getCurrentUser()); changeLogService.create(change); }
@Override public void processInput(BoxPositionProgressStep step) { if (isLocationFree(step.getInput())) { boxPositionStep = step; } else if (!box.isValidPosition(step.getInput())) { error = String.format("The Box '%s' does not have a position '%s'", box.getAlias(), step.getInput()); } else if (!box.isFreePosition(step.getInput())) { error = String.format("The position '%s' is already occupied", step.getInput()); } }
@Override public void processInput(BoxPositionProgressStep step) { if (isLocationFree(step.getInput())) { boxPositionStep = step; occupiedLocations.add(getPosition()); } else if (!box.isValidPosition(step.getInput()) || !isColumnNonZero(step.getInput())) { error = String.format("The Box '%s' does not have a position '%s'", box.getAlias(), step.getInput()); } else if (!box.isFreePosition(step.getInput()) || occupiedLocations.contains(step.getInput())) { error = String.format("The position '%s' is already occupied", step.getInput()); } }
List<ValidationError> errors = new ArrayList<>(); if (isStringEmptyOrNull(box.getAlias())) { errors.add(new ValidationError("alias", "Alias cannot be blank")); } else if (beforeChange == null || !box.getAlias().equals(beforeChange.getAlias())) { Box existing = boxStore.getBoxByAlias(box.getAlias()); if (existing != null && existing.getId() != box.getId()) { errors.add(new ValidationError("alias", "There is already a box with this alias"));
@Override public void throwIfBoxPositionIsFilled(Boxable boxable) throws IOException { if (boxable.getBox() == null || boxable.getBoxPosition() == null) return; Box box = get(boxable.getBox().getId()); BoxPosition bp = box.getBoxPositions().get(boxable.getBoxPosition()); if (bp == null) return; if (!bp.getBoxableId().equals(new BoxableId(boxable.getEntityType(), boxable.getId()))) { throw new IllegalArgumentException("Box position '" + boxable.getBoxPosition() + "' in box '" + box.getAlias() + "' is not empty"); } }
public static String makeLocationLabel(Boxable boxable) { return makeLocationLabel(boxable.isDiscarded(), boxable.getLocationBarcode(), boxable.getBox() == null ? null : boxable.getBox().getAlias(), boxable.getBoxPosition(), boxable.getBox() == null ? null : boxable.getBox().getLocationBarcode()); }
private void applyChanges(Box from, Box to) throws IOException { to.setAlias(from.getAlias()); to.setDescription(from.getDescription()); to.setIdentificationBarcode(LimsUtils.nullifyStringIfBlank(from.getIdentificationBarcode())); to.setLocationBarcode(from.getLocationBarcode()); to.setUse(boxStore.getUseById(from.getUse().getId())); to.setStorageLocation(from.getStorageLocation()); }
public static BoxDto asDto(@Nonnull Box from, boolean includePositions) { BoxDto dto = new BoxDto(); dto.setId(from.getId()); dto.setName(from.getName()); dto.setAlias(from.getAlias()); dto.setDescription(from.getDescription()); dto.setIdentificationBarcode(from.getIdentificationBarcode()); dto.setLocationBarcode(from.getLocationBarcode()); if (from.getUse() != null) { dto.setUseId(from.getUse().getId()); dto.setUseAlias(from.getUse().getAlias()); } if (from.getSize() != null) { dto.setSizeId(from.getSize().getId()); dto.setRows(from.getSize().getRows()); dto.setCols(from.getSize().getColumns()); dto.setScannable(from.getSize().getScannable()); } if (includePositions) { dto.setItems(from.getBoxPositions().values().stream().map(Dtos::asDto).collect(Collectors.toList())); } if (from.getStorageLocation() != null) { dto.setStorageLocationId(from.getStorageLocation().getId()); dto.setStorageLocationBarcode(from.getStorageLocation().getIdentificationBarcode()); dto.setFreezerDisplayLocation(from.getStorageLocation().getFreezerDisplayLocation()); dto.setStorageDisplayLocation(from.getStorageLocation().getFullDisplayLocation()); } dto.setTubeCount(from.getTubeCount()); return dto; }
private long saveNewBox(Box box) throws IOException { authorizationManager.throwIfNotWritable(box); try { box.setName(generateTemporaryName()); box.setSecurityProfile(securityProfileStore.get(securityProfileStore.save(box.getSecurityProfile()))); box.setChangeDetails(authorizationManager.getCurrentUser()); box.setIdentificationBarcode(LimsUtils.nullifyStringIfBlank(box.getIdentificationBarcode())); validateChange(box, null); boxStore.save(box); if (autoGenerateIdBarcodes) { box.setIdentificationBarcode(box.getName() + "::" + box.getAlias()); } box.setName(namingScheme.generateNameFor(box)); validateNameOrThrow(box, namingScheme); if (box.getStorageLocation() != null) { addStorageChangeLog(getFreezer(box), box, true); } return boxStore.save(box); } catch (MisoNamingException e) { throw new IOException("Invalid name for box", e); } }
private void logStorageChange(Box box, Box original) throws IOException { if (original.getStorageLocation() == null && box.getStorageLocation() != null) { addStorageChangeLog(getFreezer(box), box, true); } else if (original.getStorageLocation() != null && box.getStorageLocation() == null) { addStorageChangeLog(getFreezer(original), box, false); } else if (original.getStorageLocation() != null && box.getStorageLocation() != null) { if (getFreezer(original).getId() != getFreezer(box).getId()) { addStorageChangeLog(getFreezer(original), box, false); addStorageChangeLog(getFreezer(box), box, true); } else if (original.getStorageLocation().getId() != box.getStorageLocation().getId()) { String message = String.format("Relocated %s (%s) from %s to %s", box.getAlias(), box.getName(), original.getStorageLocation().getFreezerDisplayLocation(), box.getStorageLocation().getFreezerDisplayLocation()); ChangeLog change = getFreezer(box).createChangeLog(message, "", authorizationManager.getCurrentUser()); changeLogService.create(change); } } }
public static BoxableView fromBoxable(Boxable boxable) { BoxableView v = new BoxableView(); v.setId(new BoxableId(boxable.getEntityType(), boxable.getId())); v.setName(boxable.getName()); v.setAlias(boxable.getAlias()); v.setIdentificationBarcode(boxable.getIdentificationBarcode()); v.setLocationBarcode(boxable.getLocationBarcode()); v.setVolume(boxable.getVolume()); v.setDiscarded(boxable.isDiscarded()); Box box = boxable.getBox(); if (box != null) { v.setBoxId(box.getId()); v.setBoxName(box.getName()); v.setBoxAlias(box.getAlias()); v.setBoxPosition(boxable.getBoxPosition()); v.setBoxLocationBarcode(box.getLocationBarcode()); } v.setPreMigrationId(boxable.getPreMigrationId()); return v; }
dto.setSampleBoxPositionLabel(BoxUtils.makeBoxPositionLabel(from.getSample().getBox().getAlias(), from.getSample().getBoxPosition()));
if (dilution.getBox() != null) { v.setBoxName(dilution.getBox().getName()); v.setBoxAlias(dilution.getBox().getAlias()); v.setBoxIdentificationBarcode(dilution.getBox().getIdentificationBarcode()); v.setBoxLocationBarcode(dilution.getBox().getLocationBarcode());