public static <T extends DetailedSample> T getParent(Class<T> targetParentClass, DetailedSample start) { for (DetailedSample current = deproxify(start.getParent()); current != null; current = deproxify(current.getParent())) { if (targetParentClass.isInstance(current)) { return targetParentClass.cast(current); } } return null; }
/** * Finds the identity of a sample by climbing the hierarchy * * @param sample * @return identity attached to sample or null if no identity is attached * @throws IOException */ private SampleIdentity getIdentity(DetailedSample sample) throws IOException { if (sample.getParent() == null) { throw new IllegalArgumentException(ERR_MISSING_PARENT_ID); } SampleIdentity identity = LimsUtils.getParent(SampleIdentity.class, sample); return identity; }
@Override public Optional<DetailedSample> getEffectiveGroupIdSample() { for (DetailedSample sample = this; sample != null; sample = sample.getParent()) { String groupId = sample.getGroupId(); if (!LimsUtils.isStringEmptyOrNull(groupId)) return Optional.of(sample); } return Optional.empty(); }
private void setIdentity(DetailedSample descendant) throws IOException, MisoNamingException { if (descendant.getParent() == null) { throw new IllegalArgumentException(ERR_MISSING_PARENT_ID); } DetailedSample child = descendant; DetailedSample parent = descendant.getParent(); while (parent.getParent() != null) { child = parent; parent = child.getParent(); } if (!isIdentitySample(parent)) { throw new IllegalStateException("Missing Identity at root of hierarchy"); } if (descendant.getIdentityId() != null) { parent.setId(descendant.getIdentityId()); } SampleIdentity identity = findOrCreateIdentity(descendant, (SampleIdentity) parent); child.setParent(identity); }
private void validateHierarchy(DetailedSample sample) throws IOException { Set<SampleValidRelationship> sampleValidRelationships = sampleValidRelationshipService.getAll(); if (!isValidRelationship(sampleValidRelationships, sample.getParent(), sample)) { throw new IllegalArgumentException("Parent " + sample.getParent().getSampleClass().getAlias() + " not permitted to have a child of type " + sample.getSampleClass().getAlias()); } }
if (sample.getParent() == null) { throw new IllegalArgumentException(ERR_MISSING_PARENT_ID); DetailedSample tempParent = sample.getParent(); if (tempParent.getId() != Sample.UNSAVED_ID) { Sample parent = sampleStore.getSample(tempParent.getId()); return (DetailedSample) parent; } else { if (isTissueSample(tempParent) && isIdentitySample(tempParent.getParent())) { DetailedSample tissueParent = sampleStore.getMatchingGhostTissue((SampleTissue) tempParent); if (tissueParent != null) {
@Override public String generate(Sample sample) throws MisoNamingException, IOException { if (!LimsUtils.isDetailedSample(sample)) { throw new IllegalArgumentException("Can only generate an alias for detailed samples"); } DetailedSample detailed = (DetailedSample) sample; if (isIdentitySample(detailed)) { return generateIdentityAlias((SampleIdentity) detailed); } for (DetailedSample parent = detailed.getParent(); parent != null; parent = parent.getParent()) { if (isAliquotSample(parent)) { return addSiblingTag(parent.getAlias(), detailed); } if (isTissueSample(parent)) { if (isTissueSample(detailed)) { // tissues parented to tissues return generateTissueAlias((SampleTissue) detailed, LimsUtils.getParent(SampleIdentity.class, parent)); } else { return addSiblingTag(parent.getAlias(), detailed); } } if (isIdentitySample(parent)) { if (!isTissueSample(detailed)) throw new IllegalArgumentException("Missing parent tissue"); return generateTissueAlias((SampleTissue) detailed, (SampleIdentity) parent); } } throw new IllegalStateException("Unexpected conditions for alias generation"); }
@Override public void update(Sample sample) throws IOException { Sample managed = get(sample.getId()); managed.setChangeDetails(authorizationManager.getCurrentUser()); boolean validateAliasUniqueness = !managed.getAlias().equals(sample.getAlias()); authorizationManager.throwIfNotWritable(managed); maybeRemoveFromBox(sample); boxService.throwIfBoxPositionIsFilled(sample); validateChange(sample, managed); applyChanges(managed, sample); loadChildEntities(managed); if (isDetailedSample(managed)) { DetailedSample detailedUpdated = (DetailedSample) managed; if (detailedUpdated.getParent() != null) { detailedUpdated.setParent((DetailedSample) get(detailedUpdated.getParent().getId())); validateHierarchy(detailedUpdated); } } save(managed, validateAliasUniqueness); boxService.updateBoxableLocation(sample); }
if (detailed.getParent() == null) { throw new IllegalArgumentException(ERR_MISSING_PARENT_ID); if (detailed.getParent().getId() != SampleImpl.UNSAVED_ID) { detailed.setParent((DetailedSample) get(detailed.getParent().getId())); } else { try { setIdentity(detailed); if (!isIdentitySample(detailed.getParent())) { detailed.setParent(findOrCreateParent(detailed)); detailed.inheritPermissions(detailed.getParent() == null ? detailed.getProject() : detailed.getParent()); } else { sample.inheritPermissions(sample.getProject());
dto.setSubprojectPriority(from.getSubproject().getPriority()); if (from.getParent() != null) { dto.setParentId(from.getParent().getId()); dto.setParentAlias(from.getParent().getAlias()); dto.setParentTissueSampleClassId(from.getParent().getSampleClass().getId()); dto.setIdentityConsentLevel(getIdentityConsentLevelString(from));
if (!LimsUtils.isStringEmptyOrNull(from.getExternalNames()) && to.getParent() != null) { SampleIdentity identity = LimsUtils.getParent(SampleIdentity.class, to); if (identity == null) {