OicrSampleAliasGenerator implements NameGenerator<Sample> { @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)) { continue; } if (isTissueSample(parent)) { if (isTissueSample(detailed)) { 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"); }  void setSiblingNumberGenerator(SiblingNumberGenerator siblingNumberGenerator); void setSampleNumberPerProjectService(SampleNumberPerProjectService sampleNumberPerProjectService); @Override String generate(Sample sample);  }
@Test public void generateForIdentityTest() throws Exception { Sample identity = makeIdentity(); Mockito.when(sampleNumberPerProjectService.nextNumber(Mockito.any(), Mockito.anyString())).thenReturn("0123"); assertEquals("PROJ_0123", sut.generate(identity)); }
@Test public void generateForTissueTest() throws Exception { assertEquals("PROJ_0001_nn_n_nn_1-1", sut.generate(makeMinimalTissue())); assertEquals("PROJ_0001_Bn_P_32_2-3", sut.generate(makeFullTissue())); }
@Test public void generateForTissueFromTissueTest() throws Exception { assertEquals("PROJ_0001_Bn_O_nn_1-1", sut.generate(makeTissueFromTissue())); }
@Test public void generateForTissueProcessingTest() throws Exception { assertEquals("PROJ_0001_nn_n_nn_1-1_LCM02", sut.generate(makeLcmTube())); }
@Test public void generateForStockFromTissueTest() throws Exception { assertEquals("PROJ_0001_nn_n_nn_1-1_D_S4", sut.generate(makeStockFromTissue())); }
@Test public void generateForStockFromProcessingTest() throws Exception { assertEquals("PROJ_0001_nn_n_nn_1-1_D_S4", sut.generate(makeStockFromProcessing())); }
@Test public void generateForStockFromStockTest() throws Exception { assertEquals("PROJ_0001_nn_n_nn_1-1_D_S6", sut.generate(makeStockFromStock())); }
@Test public void generateForAliquotFromStockTest() throws Exception { assertEquals("PROJ_0001_nn_n_nn_1-1_R_12", sut.generate(makeAliquotFromStock())); }
@Test public void generateForAliquotFromAliquotTest() throws Exception { assertEquals("PROJ_0001_nn_n_nn_1-1_MR_2", sut.generate(makeAliquotFromAliquot())); }