SampleServiceImpl extends WaspMessageHandlingServiceImpl implements SampleService { @Override public boolean isSampleNameUniqueWithinJob(Sample sampleIn, SampleType sampleType, Job job){ Assert.assertParameterNotNull(sampleIn, "Invalid sampleIn Provided"); Assert.assertParameterNotNull(sampleType, "Invalid sampleType Provided"); Assert.assertParameterNotNull(job, "Invalid sampleIn Provided"); List<Sample> samplesInThisJob = job.getSample(); for(Sample sample : samplesInThisJob){ if (sampleIn.getId() != null && sample.getId().intValue() == sampleIn.getId().intValue()) continue; if( sample.getSampleType().getIName().equals(sampleType.getIName()) && sampleIn.getName().equals(sample.getName()) ){ return false; } } return true; }  @Override @Autowired void setSampleDao(SampleDao sampleDao); @Override SampleDao getSampleDao(); void setWorkflowDao(WorkflowDao workflowDao); @Override @Autowired void setAuthenticationService(AuthenticationService authenticationService); @Override SampleSourceMetaDao getSampleSourceMetaDao(); @Override @Autowired void setSampleSourceMetaDao(SampleSourceMetaDao sampleSourceMetaDao); @Override SampleSubtypeDao getSampleSubtypeDao(); @Override @Autowired void setSampleSubtypeDao(SampleSubtypeDao sampleSubtypeDao); @Override SampleTypeDao getSampleTypeDao(); @Override @Autowired void setSampleTypeDao(SampleTypeDao sampleTypeDao); @Autowired @Override void setSampleMetaDao(SampleMetaDao sampleMetaDao); @Override SampleMetaDao getSampleMetaDao(); @Autowired @Override void setSampleDraftDao(SampleDraftDao sampleDraftDao); @Override SampleDraftDao getSampleDraftDao(); @Autowired @Override void setSampleDraftMetaDao(SampleDraftMetaDao sampleDraftMetaDao); @Override SampleDraftMetaDao getSampleDraftMetaDao(); @Override Sample getSampleByName(final String name); @Override List<Sample> getPlatformUnits(); @Override List<SampleSubtype> getSampleSubtypesForWorkflowByLoggedInUserRoles(Integer workflowId); @Override List<SampleSubtype> getSampleSubtypesForWorkflowByLoggedInUserRoles(Integer workflowId, String sampleTypeIName); @Override List<SampleSubtype> getSampleSubtypesForWorkflowByRole(Integer workflowId, String[] roles); @Override @Transactional("entityManager") void saveSampleWithAssociatedMeta(Sample sample); @Override List<SampleSubtype> getSampleSubtypesForWorkflowByRole(Integer workflowId, String[] roles, String sampleTypeIName); @Override boolean isSampleNameUniqueWithinJob(Sample sampleIn, SampleType sampleType, Job job); @Override ExitStatus getReceiveSampleStatus(final Sample sample); @Override ExitStatus getSampleQCStatus(final Sample sample); @Override ExitStatus getLibraryQCStatus(final Sample library); @Override boolean isSamplePassQC(final Sample sample); @Override boolean isLibraryPassQC(final Sample library); @Override Boolean isSampleReceivedOrWithdrawn(Sample sample); @Override Boolean isSampleAwaitingLibraryCreation(Sample sample); @Override void sortSamplesBySampleName(List<Sample> samples); @Override void sortSamplesBySampleId(List<Sample> samples); @Override String convertSampleReceivedStatusForWeb(ExitStatus internalStatus); @Override String convertSampleQCStatusForWeb(ExitStatus internalStatus); @Override WaspStatus convertSampleQCStatusFromWeb(String webStatus); @Override List<String> getReceiveSampleStatusOptionsForWeb(); @Override void initiateBatchJobForSample(Job job, Sample sample, String batchJobName); @Override void initiateBatchJobForLibrary(Job job, Sample library, String batchJobName); @Override void updateSampleReceiveStatus(final Sample sample, final WaspStatus status); @Override void updateQCStatus(final Sample sample, final WaspStatus status); @Override boolean isSubmittedSampleProcessedByFacility(final Sample sample); @Override List<Sample> getFacilityGeneratedLibraries(Sample sample); @Override Adaptor getLibraryAdaptor(Sample library); @Override List<Sample> getAvailablePlatformUnits(); @Override List<Sample> getAvailableAndCompatiblePlatformUnits(ResourceCategory resourceCategory); @Override List<Sample> getAvailableAndCompatiblePlatformUnits(Job job); @Override Integer getCellIndex(Sample cell); @Override Sample getPlatformUnitForCell(Sample cell); @Override Map<Integer, Sample> getIndexedCellsOnPlatformUnit(Sample platformUnit); @Override Integer getNumberOfIndexedCellsOnPlatformUnit(Sample platformUnit); @Override void addCellToPlatformUnit(Sample platformUnit, Sample cell, Integer index); @Override List<Sample> getLibrariesOnCell(Sample cell); @Override List<Sample> getLibrariesOnCellWithoutControls(Sample cell); @Override List<Sample> getControlLibrariesOnCell(Sample cell); @Override //DO NOT USE. this method calls setJobForLibraryOnCell(cell, library); which is not a good idea, as job is derived from library.getJob (not good if a sample is on two jobs) //USE addLibraryToCell(Sample cell, Sample library, Float libConcInCellPicoM, Job job in) instead (see below) void addLibraryToCell(Sample cell, Sample library, Float libConcInCellPicoM); @Override int getRequestedSampleCoverage(Sample sample); @Override List<Sample> getCellsForLibrary(Sample library); @Override SampleDraft cloneSampleDraft(final SampleDraft sampleDraft); @Override Run getCurrentRunForPlatformUnit(Sample platformUnit); @Override boolean isBiomolecule(Sample sample); @Override boolean isBiomolecule(SampleDraft sampleDraft); @Override boolean isLibrary(SampleDraft sampleDraft); @Override boolean isLibrary(Sample sample); @Override boolean isCellLibrary(SampleSource cellLibrary); @Override boolean isDnaOrRna(SampleDraft sampleDraft); @Override boolean isDnaOrRna(Sample sample); @Override boolean isBarcodeNameExisting(String barcodeName); @Override List<SampleSubtype> getSampleSubtypesBySampleTypeIName(String sampleTypeIName); @Override SampleSubtype getSampleSubtypeById(Integer sampleSubtypeId); @Override boolean isSampleSubtypeWithSpecificSampleType(SampleSubtype sampleSubtype, String sampleTypeIName); @Override Sample getSampleById(Integer sampleId); @Override boolean isSampleOfSpecificSampleType(Sample sample, String sampleTypeIName); @Override boolean isSampleOfSpecificSampleSubtype(Sample sample, String sampleSubtypeIName); @Override boolean isSampleInDatabase(Sample sample); @Override boolean isSampleIdInDatabase(Integer sampleId); @Override boolean isSampleIdValid(Sample sample); @Override boolean isPlatformUnit(Sample sample); @Override boolean isControlLibrary(Sample library); @Override Sample getPlatformUnit(Integer sampleId); SampleSubtype getSampleSubtypeConfirmedForPlatformunit(Integer sampleSubtypeId); @Override List<Integer> getNumberOfCellsListForThisTypeOfPlatformUnit(SampleSubtype sampleSubtype); @Override boolean isRequestedReductionInCellNumberProhibited(Sample platformUnitInDatabase, Integer numberOfCellsRequested); @Override void createUpdatePlatformUnit(Sample platformUnit, SampleSubtype sampleSubtype, String barcodeName, Integer numberOfCellsRequested, List<SampleMeta> sampleMetaList); @Override void deletePlatformUnit(Integer platformUnitId); @Override List<Resource> getAllMassivelyParallelSequencingMachines(); @SuppressWarnings({ "rawtypes", "unchecked" }) List<Resource> getSequencingMachinesCompatibleWithPU(Sample platformUnit); @Override Resource getSequencingMachineByResourceId(Integer resourceId); @Override boolean isPlatformUnitCompatibleWithSequencingMachine(Sample platformUnit, Resource sequencingMachineInstance); @Override void removeLibraryFromCellOfPlatformUnit(SampleSource cellLibraryLink); @Override void removeLibraryFromCellOfPlatformUnit(Sample cell, Sample library); @Override boolean isLibraryAwaitingPlatformUnitPlacement(Sample library); @Override List<Sample> getPlatformUnitsNotYetRun(); @Override boolean isPlatformUnitAwaitingSequenceRunPlacement(Sample platformUnit); @Override List<Sample> getRunningOrSuccessfullyRunPlatformUnits(); @Override void setPlatformUnitLockStatus(Sample platformunit, LockStatus lockStatus); @Override LockStatus getPlatformUnitLockStatus(Sample platformunit); @Override SampleSourceDao getSampleSourceDao(); @Autowired void setSampleSourceDao(SampleSourceDao sampleSourceDao); @Override void createFacilityLibraryFromMacro(Job job, SampleWrapper managedLibrary, List<SampleMeta> libraryMetaList); @Override void setSampleQCComment(Integer sampleId, String comment); @Override List<MetaMessage> getSampleQCComments(Integer sampleId); @Override void setCellLibraryQCComment(Integer sampleSourceId, String comment); @Override List<MetaMessage> getCellLibraryQCComments(Integer sampleSourceId); @Override void updateExistingSampleViaSampleWrapper(SampleWrapper sw, List<SampleMeta> sampleMetaList); boolean isCell(Sample cell); @Override void setLibraryOnCellConcentration(SampleSource cellLibrary, Float valueInPicoM); @Override void setLibraryOnCellConcentration(Sample cell, Sample library, Float valueInPicoM); @Override Float getConcentrationOfLibraryAddedToCell(Sample cell, Sample library); @Override void setJobForLibraryOnCell(SampleSource cellLibrary); @Override void setJobForLibraryOnCell(Sample cell, Sample library); @Override Job getJobOfLibraryOnCell(Sample cell, Sample library); @Override Job getJobOfLibraryOnCell(SampleSource cellLibrary); @Override Set<SampleSource> getCellLibrariesForJob(Job job); @Override SampleSource getCellLibrary(Sample cell, Sample library); @Override SampleSource getCellLibraryBySampleSourceId(Integer ssid); @Override Sample getCell(SampleSource cellLibrary); @Override Sample getLibrary(SampleSource cellLibrary); @Override List<Sample> getControlSamplesForAJobsSample(Job job, Sample sample); @Override boolean isCellSequencedSuccessfully(Sample cell); @Override void setCellSequencedSuccessfully(Sample cell, boolean success); @Override ExitStatus getCellLibraryPreprocessingStatus(SampleSource cellLibrary); @Override ExitStatus getCellLibraryAggregationAnalysisStatus(SampleSource cellLibrary); @Override boolean isCellLibraryAwaitingQC(SampleSource cellLibrary); @Override boolean isCellLibraryPassedQC(SampleSource cellLibrary); @Override void setCellLibraryPassedQC(SampleSource cellLibrary, boolean isPassedQC); @Override List<SampleSource> getCellLibrariesThatPassedQCForJob(Job job); @Override List<SampleSource> getCellLibrariesPassQCAndNoAggregateAnalysis(Job job); @Override void setJobByTestAndControlSamples(Sample testSample, Sample controlSample); @Override Job getJobByTestAndControlSamples(Sample testSample, Sample controlSample); @Override Job getJobBySamplePair(SampleSource samplePair); @Override Set<SampleSource> getSamplePairsByJob(Job job); @Override SampleSource getSamplePair(Sample testSample, Sample controlSample); @Override Sample getTestSample(SampleSource samplePair); @Override Sample getControlSample(SampleSource samplePair); @Override List<Sample> getControlSamplesByTestSample(Sample testSample); @Override void createTestControlSamplePairsByIds(Integer testSampleId, Integer controlSampleId, Job job); Map<SampleSource, ExitStatus> getCellLibrariesWithPreprocessingStatus(Job job); @Override void saveCellLibraryQCStatusAndComment(SampleSource cellLibrary, String qcStatus, String comment); @Override String getPlatformunitViewLink(Sample platformunit); @Override List<SampleSource> getCellLibrariesForCell(Sample cell); @Override List<SampleSource> getCellLibrariesForLibrary(Sample library); @Override List<SampleSource> getCellLibraries(); @Override List<Sample> getLibraries(); @Override String getNameOfOrganism(Sample sample); @Override String getNameOfOrganism(Sample sample, String defaultValue); @Override Integer getIdOfOrganism(Sample sample); @Override Set<Organism> getOrganismsPlusOther(); @Override List<Sample> getCellsForLibrary(Sample library, Job job); @Override void addLibraryToCell(Sample cell, Sample libraryToBeAddedToCell, Float libConcInCellPicoM, Job job); @Override void setJobForLibraryOnCell(SampleSource cellLibrary, Job job); @Override void enumerateSamplesForMPS(List<Sample> allSamples, List<Sample> submittedMacromolecules, List<Sample> submittedLibraries, List<Sample> facilityLibraries); @Override void validateSampleNameUniqueWithinJob(String sampleName, Integer sampleId, Job job, BindingResult result); @Override String getNameOfOrganismForAlignmentRequest(Sample sample, String defaultValue); @Override String getNameOfGenomeForAlignmentRequest(Sample sample, String defaultValue); @Override String getNameOfGenomeBuildForAlignmentRequest(Sample sample, String defaultValue); @Override void setLibraryOnCellMeta(SampleSource cellLibrary, String area, String metaValueName, String metaValue); @Transactional("entityManager") @Override Map<Sample, List<SampleSource>> associateUppermostSampleWithCellLibraries(List<SampleSource> cellLibraryList); @Transactional("entityManager") @Override boolean confirmSamplePairIsOfSameSpecies(Sample s1, Sample s2); @Transactional("entityManager") @Override List<Integer> convertCellLibraryListToIdList(List<SampleSource> cellLibraryList); @Transactional("entityManager") @Override void addControlLibraryToCell(Sample cell, Sample controlLibraryToBeAdded, Float libConcInCellPicoM); @Override void setReasonForNewLibraryComment(Integer sampleId, String comment); @Override List<MetaMessage> getReasonForNewLibraryComment(Integer sampleId); static final String LIBRARY_ON_CELL_AREA; static final String LIB_CONC; static final String JOB_ID; static final String SAMPLE_PAIR_AREA; }
@Test (groups = "unit-tests-service-objects") public void isSampleNameUniqueWithinJob() { SampleType sampleType = new SampleType(); sampleType.setIName("sample1"); Job job = new Job(); job.setJobId(1); Sample sample1 = new Sample(); sample1.setSampleId(1); sample1.setName("sample1"); sample1.setSampleType(sampleType); JobSample js1 = new JobSample(); js1.setJobSampleId(1); js1.setJob(job); js1.setSample(sample1); List<JobSample> jobSamples = new ArrayList<JobSample>(); jobSamples.add(js1); Sample sample2 = new Sample(); sample2.setSampleId(2); sample2.setName("sample1"); sample2.setSampleType(sampleType); JobSample js2 = new JobSample(); js2.setJobSampleId(2); js2.setJob(job); js2.setSample(sample2); jobSamples.add(js2); job.setJobSample(jobSamples); Assert.assertEquals(sampleServiceImpl.isSampleNameUniqueWithinJob(sample1, sampleType, job), false); }