@Override public long saveProject(Project project) throws IOException { ValidationResult shortNameValidation = namingScheme.validateProjectShortName(project.getShortName()); if (!shortNameValidation.isValid()) { throw new IOException("Cannot save project - invalid shortName: " + shortNameValidation.getMessage()); if (project.getId() == ProjectImpl.UNSAVED_ID) { resolveMembers(project.getSecurityProfile()); project.setName(generateTemporaryName()); projectStore.save(project); try { project.setName(namingScheme.generateNameFor(project)); } catch (MisoNamingException e) { throw new IOException("Cannot save Project - issue with naming scheme", e); Project original = projectStore.get(project.getId()); authorizationManager.throwIfNotWritable(original); original.setAlias(project.getAlias()); original.setDescription(project.getDescription()); original.setLastUpdated(new Date()); original.setProgress(project.getProgress()); original.setReferenceGenome(referenceGenomeDao.getReferenceGenome(project.getReferenceGenome().getId())); if (project.getDefaultTargetedSequencing() != null) { original.setDefaultTargetedSequencing(targetedSequencingStore.get(project.getDefaultTargetedSequencing().getId())); } else { original.setDefaultTargetedSequencing(null); original.setShortName(project.getShortName()); updateSecurityProfile(original.getSecurityProfile(), project.getSecurityProfile()); project = original;
public static ProjectDto asDto(@Nonnull Project from) { ProjectDto dto = new ProjectDto(); dto.setId(from.getId()); dto.setName(from.getName()); dto.setAlias(from.getAlias()); dto.setShortName(from.getShortName()); dto.setDescription(from.getDescription()); dto.setProgress(from.getProgress().getKey()); if (from.getReferenceGenome() != null) { dto.setDefaultSciName(from.getReferenceGenome().getDefaultSciName()); } return dto; }
@Override public long save(Project project) throws IOException { Date timestamp = new Date(); project.setLastUpdated(timestamp); if (project.getId() == ProjectImpl.UNSAVED_ID) { project.setCreationDate(timestamp); return (Long) currentSession().save(project); } else { currentSession().update(project); return project.getId(); } }
@Override public String getDeleteDescription() { Project p = getProject(); return (p.getShortName() == null ? p.getAlias() : p.getShortName()) + " " + getName() + " (" + getAlias() + ")"; }
v.setProjectAlias(proj.getAlias()); v.setProjectId(proj.getId()); v.setProjectName(proj.getName()); v.setProjectShortName(proj.getShortName());
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(getName()); sb.append(" : "); sb.append(getAlias()); sb.append(" : "); sb.append(getDescription()); sb.append(" : "); sb.append(getStudyType()); sb.append(" : "); if (getProject() != null) { sb.append(getProject().getAlias()); sb.append("(" + getProject().getName() + ")"); } return sb.toString(); }
@Override public Collection<Project> listAllProjectsByShortname() throws IOException { List<Project> sortedProjects = (ArrayList<Project>) projectStore.listAll(); /** * Uses String.compareTo to alphabetically sort Projects by shortname */ sortedProjects.sort((Project p1, Project p2) -> p1.getShortName().compareTo(p2.getShortName())); return authorizationManager.filterUnreadable(sortedProjects); }
@Override public long save(Study study) throws IOException { if (study.getId() == StudyImpl.UNSAVED_ID) { study.setChangeDetails(authorizationManager.getCurrentUser()); study.setStudyType(studyStore.getType(study.getStudyType().getId())); study.setProject(projectStore.get(study.getProject().getId())); study.setName(LimsUtils.generateTemporaryName()); study.setSecurityProfile(study.getProject().getSecurityProfile()); long id = studyStore.save(study); try { study.setName(namingScheme.generateNameFor(study)); LimsUtils.validateNameOrThrow(study, namingScheme); studyStore.save(study); } catch (MisoNamingException e) { throw new IOException(e); } return id; } else { Study original = studyStore.get(study.getId()); authorizationManager.throwIfNotWritable(original); original.setAccession(study.getAccession()); original.setAlias(study.getAlias()); original.setDescription(study.getDescription()); original.setChangeDetails(authorizationManager.getCurrentUser()); // project is immutable original.setStudyType(studyStore.getType(study.getStudyType().getId())); return studyStore.save(original); } }
@Override protected void populate(Element xml, Study s) { xml.setAttribute("alias", s.getAlias()); Element studyDescriptor = xml.getOwnerDocument().createElementNS(null, "DESCRIPTOR"); xml.appendChild(studyDescriptor); Element studyTitle = xml.getOwnerDocument().createElementNS(null, "STUDY_TITLE"); studyTitle.setTextContent(s.getAlias()); studyDescriptor.appendChild(studyTitle); Element studyType = xml.getOwnerDocument().createElementNS(null, "STUDY_TYPE"); studyType.setAttribute("existing_study_type", s.getStudyType().getName()); studyDescriptor.appendChild(studyType); Element centerProjectName = xml.getOwnerDocument().createElementNS(null, "CENTER_PROJECT_NAME"); centerProjectName.setTextContent(s.getProject().getAlias()); studyDescriptor.appendChild(centerProjectName); Element studyAbstract = xml.getOwnerDocument().createElementNS(null, "STUDY_ABSTRACT"); studyDescriptor.appendChild(studyAbstract); Element studyDescription = xml.getOwnerDocument().createElementNS(null, "STUDY_DESCRIPTION"); studyDescription.setTextContent(s.getDescription()); studyDescriptor.appendChild(studyDescription); }
/** * Returns true if another sample with same external name and project exists in database * * @param sample * @return boolean * @throws IOException */ private boolean isExternalNameDuplicatedInProject(Sample sample) throws IOException { SampleIdentity identity = (SampleIdentity) sample; return getIdentitiesByExternalNameOrAliasAndProject(identity.getExternalName(), identity.getProject().getId(), true).size() > 0; }
@Override public String getDeleteDescription() { Project p = getParentProject(); return (p.getShortName() == null ? p.getAlias() : p.getShortName()) + " - " + getAlias() + (getAlias().equals(getDescription()) ? "" : " (" + getDescription() + ")"); }
private String generateIdentityAlias(SampleIdentity identity) throws IOException { if (identity.getProject().getShortName() == null) { throw new NullPointerException("Project shortname required to generate Identity alias"); } String internalName = identity.getProject().getShortName() + "_"; String number = sampleNumberPerProjectService.nextNumber(identity.getProject(), internalName); internalName += number; return internalName; }
private SampleIdentity findOrCreateIdentity(DetailedSample descendant, SampleIdentity identity) throws IOException, MisoNamingException { if (identity.getId() != SampleImpl.UNSAVED_ID) { return (SampleIdentity) sampleStore.getSample(identity.getId()); } else { // If samples are being bulk received for the same new donor, they will all have a null parentId. // After the new donor's Identity is created, the following samples need to be parented to that now-existing Identity. Collection<SampleIdentity> newlyCreated = getIdentitiesByExternalNameOrAliasAndProject(identity.getExternalName(), descendant.getProject().getId(), true); if (newlyCreated.size() > 1) { throw new IllegalArgumentException( "IdentityId is required since there are multiple identities with external name " + identity.getExternalName() + " in project " + descendant.getProject().getId()); } else if (newlyCreated.size() == 1) { Sample parent = newlyCreated.iterator().next(); if (parent == null) throw new IllegalArgumentException("Parent sample does not exist"); else return (SampleIdentity) parent; } else { try { return createParentIdentity(descendant, identity); } catch (SQLException e) { throw new IOException(e); } } } }
if (isUniqueExternalNameWithinProjectRequired() && isExternalNameDuplicatedInProject(sample)) { throw new IllegalArgumentException("Sample with external name '" + ((SampleIdentity) sample).getExternalName() + "' already exists in project " + sample.getProject().getShortName());
/** * Adds any external names in the sample's attached identity to the identity stored in the database * * @param sample * @throws IOException */ private void addExternalNames(DetailedSample sample, SampleIdentity identityCopy) throws IOException { if (identityCopy == null || identityCopy.getExternalName() == null) return; SampleIdentity identity = (SampleIdentity) get(getIdentity(sample).getId()); Set<String> identityExternalNames = SampleIdentityImpl.getSetFromString(identity.getExternalName()); Set<String> tempExternalNames = SampleIdentityImpl.getSetFromString(identityCopy.getExternalName()); Set<String> lowerCaseIdentityExternalNames = identityExternalNames.stream().map(String::toLowerCase).collect(Collectors.toSet()); for (String name : tempExternalNames) { if (!lowerCaseIdentityExternalNames.contains(name.toLowerCase()) && !(isUniqueExternalNameWithinProjectRequired() && (identity.getProject() == null || getIdentitiesByExternalNameOrAliasAndProject(name, identity.getProject().getId(), true).size() > 0))) { identityExternalNames.add(name); } } if (identityExternalNames.size() > lowerCaseIdentityExternalNames.size()) { identity.setExternalName(String.join(",", identityExternalNames)); identity.setChangeDetails(authorizationManager.getCurrentUser()); sampleStore.update(identity); } }
@Override public Library getAdjacentLibrary(long libraryId, boolean before) throws IOException { AdjacencySelector selector = before ? BEFORE : AFTER; Library lib = get(libraryId); if (lib == null) throw new IOException("Library not found"); // get library siblings Criteria criteria = currentSession().createCriteria(LibraryImpl.class); criteria.createAlias("sample", "sample"); criteria.add(Restrictions.eq("sample.id", lib.getSample().getId())); criteria.add(selector.generateCriterion("id", libraryId)); criteria.addOrder(selector.getOrder("id")); criteria.setMaxResults(1); Library library = (Library) criteria.uniqueResult(); if (library != null) return library; // get library cousins criteria = currentSession().createCriteria(LibraryImpl.class); criteria.createAlias("sample", "sample"); criteria.createAlias("sample.project", "project"); criteria.add(Restrictions.eq("project.id", lib.getSample().getProject().getId())); criteria.add(selector.generateCriterion("id", lib.getId())); criteria.addOrder(selector.getOrder("sample.id")); criteria.addOrder(selector.getOrder("id")); criteria.setMaxResults(1); library = (Library) criteria.uniqueResult(); return library; }
@Override public Long create(SampleGroupId sampleGroup, Long projectId, Long subprojectId) throws IOException { authorizationManager.throwIfUnauthenticated(); User user = authorizationManager.getCurrentUser(); Project project = projectStore.get(projectId); Subproject subproject = subprojectId == null ? null : subprojectDAO.getSubproject(subprojectId); if (subproject != null && subproject.getParentProject().getId() != projectId) { throw new IllegalArgumentException("Subproject specified is not part of project."); } sampleGroup.setCreatedBy(user); sampleGroup.setUpdatedBy(user); sampleGroup.setProject(project); sampleGroup.setSubproject(subproject); return sampleGroupDao.addSampleGroup(sampleGroup); }
if (!isUniqueExternalNameWithinProjectRequired()) return; Collection<SampleIdentity> matches = getIdentitiesByExternalNameOrAliasAndProject(newExternalName, sample.getProject().getId(), true); if (!matches.isEmpty()) { for (SampleIdentity match : matches) {