use of uk.ac.bbsrc.tgac.miso.core.data.SampleClass in project miso-lims by miso-lims.
the class DefaultSampleClassService method loadChildEntities.
@Override
protected void loadChildEntities(SampleClass object) throws IOException {
Set<SampleValidRelationship> parents = new HashSet<>();
for (SampleValidRelationship svr : object.getParentRelationships()) {
SampleValidRelationship loaded = null;
if (svr.isSaved()) {
loaded = sampleValidRelationshipService.get(svr.getId());
if (loaded == null) {
throw new ValidationException(new ValidationError("No parent relationship found with ID: " + svr.getId()));
}
loaded.setArchived(svr.isArchived());
} else {
loaded = svr;
loaded.setChild(object);
SampleClass parent = loaded.getParent() == null ? null : get(loaded.getParent().getId());
if (parent == null) {
throw new ValidationException(String.format("Parent sample class not found%s%s", loaded.getParent() == null ? "" : " with ID: ", loaded.getParent() == null ? "" : loaded.getParent().getId()));
}
loaded.setParent(parent);
}
parents.add(loaded);
}
object.getParentRelationships().clear();
object.getParentRelationships().addAll(parents);
if (object.getDefaultSampleType() != null) {
object.setDefaultSampleType(sampleTypeService.getByName(object.getDefaultSampleType().getName()));
}
}
use of uk.ac.bbsrc.tgac.miso.core.data.SampleClass in project miso-lims by miso-lims.
the class DefaultSampleService method isValidRelationship.
public boolean isValidRelationship(Sample parent, Sample child) throws IOException {
if (parent == null && !isDetailedSample(child)) {
// Simple sample has no relationships.
return true;
}
if (!isDetailedSample(child) || !isDetailedSample(parent)) {
return false;
}
SampleClass parentClass = ((DetailedSample) parent).getSampleClass();
SampleClass childClass = ((DetailedSample) child).getSampleClass();
return sampleValidRelationshipService.getByClasses(parentClass, childClass) != null;
}
use of uk.ac.bbsrc.tgac.miso.core.data.SampleClass in project miso-lims by miso-lims.
the class DefaultSampleService method createParentIdentity.
private SampleIdentity createParentIdentity(DetailedSample sample, SampleIdentity identity) throws IOException, MisoNamingException, SQLException {
log.debug("Creating a new Identity to use as a parent.");
List<SampleClass> identityClasses = sampleClassService.listByCategory(SampleIdentity.CATEGORY_NAME);
if (identityClasses.size() != 1) {
throw new IllegalStateException("Found more or less than one SampleClass of category " + SampleIdentity.CATEGORY_NAME + ". Cannot choose which to use as root sample class.");
}
SampleClass rootSampleClass = identityClasses.get(0);
confirmExternalNameUniqueForProjectIfRequired(identity.getExternalName(), sample);
Sample identitySample = new IdentityBuilder().project(sample.getProject()).sampleType(sample.getSampleType()).scientificName(sample.getScientificName()).name(generateTemporaryName()).rootSampleClass(rootSampleClass).volume(BigDecimal.ZERO).externalName(identity.getExternalName()).donorSex(identity.getDonorSex()).consentLevel(identity.getConsentLevel()).build();
identitySample.setAlias(getNamingScheme(sample).generateSampleAlias(identitySample));
identitySample.setChangeDetails(authorizationManager.getCurrentUser());
return (SampleIdentity) save(identitySample, true);
}
use of uk.ac.bbsrc.tgac.miso.core.data.SampleClass in project miso-lims by miso-lims.
the class DefaultLibraryService method loadChildEntities.
/**
* Loads persisted objects into library fields. Should be called before saving libraries. Loads all member objects <b>except</b>
* <ul>
* <li>creator/lastModifier User objects</li>
* </ul>
*
* @param library the Library to load entities into. Must contain at least the IDs of objects to load (e.g. to load the persisted Sample
* into library.sample, library.sample.id must be set)
* @throws IOException
*/
private void loadChildEntities(Library library) throws IOException {
if (library.getSample() != null) {
library.setSample(sampleService.get(library.getSample().getId()));
}
if (library.getLibraryType() != null) {
library.setLibraryType(libraryTypeService.get(library.getLibraryType().getId()));
}
if (library.getLibrarySelectionType() != null) {
library.setLibrarySelectionType(librarySelectionService.get(library.getLibrarySelectionType().getId()));
}
if (library.getLibraryStrategyType() != null) {
library.setLibraryStrategyType(libraryStrategyService.get(library.getLibraryStrategyType().getId()));
}
loadChildEntity(library::setIndex1, library.getIndex1(), indexService, "index1Id");
loadChildEntity(library::setIndex2, library.getIndex2(), indexService, "index2Id");
if (library.getKitDescriptor() != null) {
library.setKitDescriptor(kitService.get(library.getKitDescriptor().getId()));
}
if (library.getSpikeIn() != null) {
library.setSpikeIn(librarySpikeInService.get(library.getSpikeIn().getId()));
}
if (library.getWorkstation() != null) {
library.setWorkstation(workstationService.get(library.getWorkstation().getId()));
}
if (library.getThermalCycler() != null) {
library.setThermalCycler(instrumentService.get(library.getThermalCycler().getId()));
}
loadChildEntity(library::setSop, library.getSop(), sopService, "sopId");
loadChildEntity(library::setDetailedQcStatus, library.getDetailedQcStatus(), detailedQcStatusService, "detailedQcStatusId");
if (isDetailedLibrary(library)) {
DetailedLibrary lai = (DetailedLibrary) library;
if (lai.getLibraryDesignCode() != null) {
lai.setLibraryDesignCode(libraryDesignCodeService.get(lai.getLibraryDesignCode().getId()));
}
if (lai.getLibraryDesign() != null) {
LibraryDesign design = libraryDesignService.get(lai.getLibraryDesign().getId());
lai.setLibraryDesign(design);
lai.setLibrarySelectionType(design.getLibrarySelectionType());
lai.setLibraryStrategyType(design.getLibraryStrategyType());
lai.setLibraryDesignCode(design.getLibraryDesignCode());
SampleClass sampleClass = ((DetailedSample) library.getSample()).getSampleClass();
if (sampleClass.getId() != design.getSampleClass().getId()) {
throw new IllegalArgumentException("Cannot use design " + design.getName() + " for a library from a sample of type " + sampleClass.getAlias());
}
}
}
}
use of uk.ac.bbsrc.tgac.miso.core.data.SampleClass in project miso-lims by miso-lims.
the class Dtos method toDetailedSample.
private static DetailedSample toDetailedSample(@Nonnull DetailedSampleDto from) {
DetailedSample to = null;
if (from.getClass() == SampleIdentityDto.class) {
to = toIdentitySample((SampleIdentityDto) from);
} else if (from.getClass() == SampleTissueDto.class) {
to = toTissueSample((SampleTissueDto) from);
} else if (from instanceof SampleTissueProcessingDto) {
to = toTissueProcessingSample((SampleTissueProcessingDto) from);
} else if (from instanceof SampleAliquotDto) {
to = toAliquotSample((SampleAliquotDto) from);
} else if (from instanceof SampleStockDto) {
to = toStockSample((SampleStockDto) from);
} else {
to = new DetailedSampleImpl();
}
if (from.getSubprojectId() != null) {
Subproject subproject = new SubprojectImpl();
subproject.setId(from.getSubprojectId());
to.setSubproject(subproject);
}
if (from.getSampleClassId() != null) {
SampleClass sampleClass = new SampleClassImpl();
sampleClass.setId(from.getSampleClassId());
to.setSampleClass(sampleClass);
}
to.setGroupId(nullifyStringIfBlank(from.getGroupId()));
to.setGroupDescription(nullifyStringIfBlank(from.getGroupDescription()));
to.setSynthetic(from.getSynthetic());
to.setCreationDate(LimsUtils.isStringEmptyOrNull(from.getCreationDate()) ? null : parseDate(from.getCreationDate()));
if (from.getIdentityId() != null) {
to.setIdentityId(from.getIdentityId());
}
to.setNonStandardAlias(from.getNonStandardAlias());
to.setParent(getParent(from));
setBigDecimal(to::setVolumeUsed, from.getVolumeUsed());
setBigDecimal(to::setNgUsed, from.getNgUsed());
return to;
}
Aggregations