public BoxPosition(Box box, String position, EntityType targetType, long targetId) { this(box, position, new BoxableId(targetType, targetId)); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; BoxPosition other = (BoxPosition) obj; if (box == null) { if (other.box != null) return false; } else if (!box.equals(other.box)) return false; if (boxableId == null) { if (other.boxableId != null) return false; } else if (!boxableId.equals(other.boxableId)) return false; if (position == null) { if (other.position != null) return false; } else if (!position.equals(other.position)) return false; return true; }
@Override public BoxableView getBoxableView(BoxableId id) throws IOException { List<BoxableView> results = queryBoxables(Restrictions.eq("id", id)); switch (results.size()) { case 0: return null; case 1: return results.get(0); default: throw new IllegalStateException(String.format("More than one Boxable found with ID %s %d", id.getTargetType(), id.getTargetId())); } }
@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"); } }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((box == null) ? 0 : box.hashCode()); result = prime * result + ((boxableId == null) ? 0 : boxableId.hashCode()); result = prime * result + ((position == null) ? 0 : position.hashCode()); return result; }
@Override public void updateBoxableLocation(Boxable boxable) throws IOException { BoxableId boxableId = new BoxableId(boxable.getEntityType(), boxable.getId()); Boxable managedOriginal = boxStore.getBoxable(boxableId); if (boxable.getBox() == null && managedOriginal.getBox() == null) { if (temp != null && temp.getBoxableId().equals(boxableId)) { return;
@Override public Boxable getBoxable(BoxableId id) { Class<?> clazz = id.getTargetType().getPersistClass(); return (Boxable) currentSession().get(clazz, id.getTargetId()); }
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; }
BoxPosition newPos = entry.getValue(); if (managedPos != null && newPos.getBoxableId().equals(managedPos.getBoxableId())) { for (Map.Entry<String, BoxPosition> entry : managed.getBoxPositions().entrySet()) { if (box.getBoxPositions().keySet().contains(entry.getKey()) && box.getBoxPositions().get(entry.getKey()).getBoxableId().equals(entry.getValue().getBoxableId())) { || !managed.getBoxPositions().get(pos).getBoxableId().equals(box.getBoxPositions().get(pos).getBoxableId())) { managed.getBoxPositions().put(pos, new BoxPosition(managed, pos, box.getBoxPositions().get(pos).getBoxableId()));
private static BoxableDto asDto(@Nonnull BoxPosition from) { BoxableDto dto = new BoxableDto(); dto.setCoordinates(from.getPosition()); dto.setEntityType(from.getBoxableId().getTargetType()); dto.setId(from.getBoxableId().getTargetId()); return dto; }
public static BoxableDto asDto(@Nonnull BoxableView from) { BoxableDto dto = new BoxableDto(); dto.setId(from.getId().getTargetId()); dto.setAlias(from.getAlias()); dto.setBoxAlias(from.getBoxAlias()); dto.setBoxPosition(BoxUtils.makeLocationLabel(from)); dto.setCoordinates(from.getBoxPosition()); dto.setDiscarded(from.isDiscarded()); dto.setIdentificationBarcode(from.getIdentificationBarcode()); dto.setName(from.getName()); dto.setVolume(from.getVolume()); dto.setEntityType(from.getId().getTargetType()); dto.setSampleClassId(from.getSampleClassId()); return dto; }