@Test @Transactional(propagation = Propagation.REQUIRES_NEW) public void testGenerateUrl() throws IOException { Resource resource = context.getResource(CLASSPATH_TEMPLATES_FELIS_CATUS_VCF); FeatureIndexedFileRegistrationRequest request = new FeatureIndexedFileRegistrationRequest(); request.setReferenceId(referenceId); request.setName("testVcf1"); request.setPath(resource.getFile().getAbsolutePath()); VcfFile testVcf1 = vcfManager.registerVcfFile(request); Project testProject = new Project(); testProject.setName("testProject1"); testProject.setItems(Arrays.asList(new ProjectItem(testVcf1), new ProjectItem(new BiologicalDataItem(testReference.getBioDataItemId())))); projectManager.create(testProject); request.setName("testVcf2"); VcfFile testVcf2 = vcfManager.registerVcfFile(request); Project testProject2 = new Project(); testProject2.setName("testProject2"); testProject2.setItems(Arrays.asList(new ProjectItem(testVcf2), new ProjectItem(new BiologicalDataItem(testReference.getBioDataItemId())))); projectManager.create(testProject2); String url = biologicalDataItemManager.generateUrl(testProject.getName(), Collections.singletonList(testVcf1.getBioDataItemId().toString()), testChromosome.getName(), 1, TEST_CHROMOSOME_SIZE); Assert.assertNotNull(url); checkUrl(url, Collections.singletonList(testVcf1.getName())); Assert.assertEquals(url, biologicalDataItemManager.generateUrl(testProject.getId().toString(), Collections.singletonList(testVcf1.getName()), testChromosome.getName(), 1, TEST_CHROMOSOME_SIZE)); url = biologicalDataItemManager.generateUrl(testProject2.getName(), Collections.singletonList(testVcf2.getBioDataItemId().toString()), testChromosome.getName(), 1, TEST_CHROMOSOME_SIZE); Assert.assertNotNull(url); checkUrl(url, Collections.singletonList(testVcf2.getName())); Assert.assertEquals(url, biologicalDataItemManager.generateUrl(testProject2.getId().toString(), Collections.singletonList(testVcf2.getName()), testChromosome.getName(), 1, TEST_CHROMOSOME_SIZE)); String chrUrl = biologicalDataItemManager.generateUrl(testProject.getId().toString(), Collections.singletonList(testVcf1.getBioDataItemId().toString()), testChromosome.getName(), null, null); Assert.assertNotNull(chrUrl); checkChrUrl(chrUrl, Collections.singletonList(testVcf1.getName())); String shortUrl = biologicalDataItemManager.generateUrl(testProject2.getName(), Collections.singletonList(testVcf2.getBioDataItemId().toString()), null, null, null); Assert.assertNotNull(shortUrl); checkShortUrl(shortUrl, Arrays.asList(testVcf2.getName())); url = biologicalDataItemManager.generateUrl(testProject.getName(), Collections.singletonList(testVcf1.getBioDataItemId().toString()), Utils.changeChromosomeName(testChromosome.getName()), 1, TEST_CHROMOSOME_SIZE); Assert.assertNotNull(url); }
@Transactional(propagation = Propagation.REQUIRED) public String generateUrl(String dataset, List<String> ids, String chromosomeName, Integer startIndex, Integer endIndex) throws JsonProcessingException { Project project; if (NumberUtils.isDigits(dataset)) { project = projectManager.load(Long.parseLong(dataset)); } else { project = projectManager.load(dataset); } Assert.notNull(project, getMessage(MessagesConstants.ERROR_PROJECT_NOT_FOUND, dataset)); List<String> bioItemNames = new ArrayList<>(); List<Long> bioItemIds = new ArrayList<>(); for (String id : ids) { if (NumberUtils.isDigits(id)) { bioItemIds.add(Long.parseLong(id)); } else { bioItemNames.add(id); } } List<BiologicalDataItem> itemsByNames = biologicalDataItemDao.loadFilesByNamesStrict(bioItemNames); if (itemsByNames.size() != bioItemNames.size()) { throw new IllegalArgumentException(getMessage( MessagesConstants.ERROR_BIO_NAME_NOT_FOUND, bioItemNames.stream() .filter(n -> itemsByNames.stream().noneMatch(i -> i.getName().equals(n))) .collect(Collectors.joining(", "))) ); } List<BiologicalDataItem> itemsByIds = biologicalDataItemDao.loadBiologicalDataItemsByIds(bioItemIds); if (itemsByIds.size() != bioItemIds.size()) { throw new IllegalArgumentException(getMessage( MessagesConstants.ERROR_BIO_ID_NOT_FOUND, bioItemIds.stream() .filter(id -> itemsByIds.stream().noneMatch(i -> i.getId().equals(id))) .map(Object::toString) .collect(Collectors.joining(", "))) ); } List<BiologicalDataItem> items = new ArrayList<>(itemsByNames.size() + itemsByIds.size()); items.addAll(itemsByNames); items.addAll(itemsByIds); List<Long> references = project.getItems().stream() .filter(item -> item.getBioDataItem().getFormat() == BiologicalDataItemFormat.REFERENCE) .map(item -> item.getBioDataItem().getId()).collect(Collectors.toList()); Assert.notNull(references); Assert.isTrue(!references.isEmpty()); Long referenceId = references.get(0); List<Long> itemIds = new ArrayList<>(items.size()); for (BiologicalDataItem item : items) { if (FeatureFile.class.isAssignableFrom(item.getClass())) { FeatureFile file = (FeatureFile) item; Assert.isTrue(project.getItems().stream() .anyMatch(i -> i.getBioDataItem().getId().equals(item.getId())), getMessage(MessagesConstants.ERROR_PROJECT_FILE_NOT_FOUND, item.getName(), project.getName())); Assert.isTrue(referenceId.equals(file.getReferenceId()), "Specified files have different references"); } itemIds.add(BiologicalDataItem.getBioDataItemId(item)); } Reference reference = referenceGenomeManager.load(referenceId); return makeUrl(items, project, reference, chromosomeName, startIndex, endIndex); }
BiologicalDataItemManager { @Transactional(propagation = Propagation.REQUIRED) public String generateUrl(String dataset, List<String> ids, String chromosomeName, Integer startIndex, Integer endIndex) throws JsonProcessingException { Project project; if (NumberUtils.isDigits(dataset)) { project = projectManager.load(Long.parseLong(dataset)); } else { project = projectManager.load(dataset); } Assert.notNull(project, getMessage(MessagesConstants.ERROR_PROJECT_NOT_FOUND, dataset)); List<String> bioItemNames = new ArrayList<>(); List<Long> bioItemIds = new ArrayList<>(); for (String id : ids) { if (NumberUtils.isDigits(id)) { bioItemIds.add(Long.parseLong(id)); } else { bioItemNames.add(id); } } List<BiologicalDataItem> itemsByNames = biologicalDataItemDao.loadFilesByNamesStrict(bioItemNames); if (itemsByNames.size() != bioItemNames.size()) { throw new IllegalArgumentException(getMessage( MessagesConstants.ERROR_BIO_NAME_NOT_FOUND, bioItemNames.stream() .filter(n -> itemsByNames.stream().noneMatch(i -> i.getName().equals(n))) .collect(Collectors.joining(", "))) ); } List<BiologicalDataItem> itemsByIds = biologicalDataItemDao.loadBiologicalDataItemsByIds(bioItemIds); if (itemsByIds.size() != bioItemIds.size()) { throw new IllegalArgumentException(getMessage( MessagesConstants.ERROR_BIO_ID_NOT_FOUND, bioItemIds.stream() .filter(id -> itemsByIds.stream().noneMatch(i -> i.getId().equals(id))) .map(Object::toString) .collect(Collectors.joining(", "))) ); } List<BiologicalDataItem> items = new ArrayList<>(itemsByNames.size() + itemsByIds.size()); items.addAll(itemsByNames); items.addAll(itemsByIds); List<Long> references = project.getItems().stream() .filter(item -> item.getBioDataItem().getFormat() == BiologicalDataItemFormat.REFERENCE) .map(item -> item.getBioDataItem().getId()).collect(Collectors.toList()); Assert.notNull(references); Assert.isTrue(!references.isEmpty()); Long referenceId = references.get(0); List<Long> itemIds = new ArrayList<>(items.size()); for (BiologicalDataItem item : items) { if (FeatureFile.class.isAssignableFrom(item.getClass())) { FeatureFile file = (FeatureFile) item; Assert.isTrue(project.getItems().stream() .anyMatch(i -> i.getBioDataItem().getId().equals(item.getId())), getMessage(MessagesConstants.ERROR_PROJECT_FILE_NOT_FOUND, item.getName(), project.getName())); Assert.isTrue(referenceId.equals(file.getReferenceId()), "Specified files have different references"); } itemIds.add(BiologicalDataItem.getBioDataItemId(item)); } Reference reference = referenceGenomeManager.load(referenceId); return makeUrl(items, project, reference, chromosomeName, startIndex, endIndex); } }
BiologicalDataItemManager { @Transactional(propagation = Propagation.REQUIRED) public String generateUrl(String dataset, List<String> ids, String chromosomeName, Integer startIndex, Integer endIndex) throws JsonProcessingException { Project project; if (NumberUtils.isDigits(dataset)) { project = projectManager.load(Long.parseLong(dataset)); } else { project = projectManager.load(dataset); } Assert.notNull(project, getMessage(MessagesConstants.ERROR_PROJECT_NOT_FOUND, dataset)); List<String> bioItemNames = new ArrayList<>(); List<Long> bioItemIds = new ArrayList<>(); for (String id : ids) { if (NumberUtils.isDigits(id)) { bioItemIds.add(Long.parseLong(id)); } else { bioItemNames.add(id); } } List<BiologicalDataItem> itemsByNames = biologicalDataItemDao.loadFilesByNamesStrict(bioItemNames); if (itemsByNames.size() != bioItemNames.size()) { throw new IllegalArgumentException(getMessage( MessagesConstants.ERROR_BIO_NAME_NOT_FOUND, bioItemNames.stream() .filter(n -> itemsByNames.stream().noneMatch(i -> i.getName().equals(n))) .collect(Collectors.joining(", "))) ); } List<BiologicalDataItem> itemsByIds = biologicalDataItemDao.loadBiologicalDataItemsByIds(bioItemIds); if (itemsByIds.size() != bioItemIds.size()) { throw new IllegalArgumentException(getMessage( MessagesConstants.ERROR_BIO_ID_NOT_FOUND, bioItemIds.stream() .filter(id -> itemsByIds.stream().noneMatch(i -> i.getId().equals(id))) .map(Object::toString) .collect(Collectors.joining(", "))) ); } List<BiologicalDataItem> items = new ArrayList<>(itemsByNames.size() + itemsByIds.size()); items.addAll(itemsByNames); items.addAll(itemsByIds); List<Long> references = project.getItems().stream() .filter(item -> item.getBioDataItem().getFormat() == BiologicalDataItemFormat.REFERENCE) .map(item -> item.getBioDataItem().getId()).collect(Collectors.toList()); Assert.notNull(references); Assert.isTrue(!references.isEmpty()); Long referenceId = references.get(0); List<Long> itemIds = new ArrayList<>(items.size()); for (BiologicalDataItem item : items) { if (FeatureFile.class.isAssignableFrom(item.getClass())) { FeatureFile file = (FeatureFile) item; Assert.isTrue(project.getItems().stream() .anyMatch(i -> i.getBioDataItem().getId().equals(item.getId())), getMessage(MessagesConstants.ERROR_PROJECT_FILE_NOT_FOUND, item.getName(), project.getName())); Assert.isTrue(referenceId.equals(file.getReferenceId()), "Specified files have different references"); } itemIds.add(BiologicalDataItem.getBioDataItemId(item)); } Reference reference = referenceGenomeManager.load(referenceId); return makeUrl(items, project, reference, chromosomeName, startIndex, endIndex); }  }
BiologicalDataItemManager { @Transactional(propagation = Propagation.REQUIRED) public String generateUrl(String dataset, List<String> ids, String chromosomeName, Integer startIndex, Integer endIndex) throws JsonProcessingException { Project project; if (NumberUtils.isDigits(dataset)) { project = projectManager.load(Long.parseLong(dataset)); } else { project = projectManager.load(dataset); } Assert.notNull(project, getMessage(MessagesConstants.ERROR_PROJECT_NOT_FOUND, dataset)); List<String> bioItemNames = new ArrayList<>(); List<Long> bioItemIds = new ArrayList<>(); for (String id : ids) { if (NumberUtils.isDigits(id)) { bioItemIds.add(Long.parseLong(id)); } else { bioItemNames.add(id); } } List<BiologicalDataItem> itemsByNames = biologicalDataItemDao.loadFilesByNamesStrict(bioItemNames); if (itemsByNames.size() != bioItemNames.size()) { throw new IllegalArgumentException(getMessage( MessagesConstants.ERROR_BIO_NAME_NOT_FOUND, bioItemNames.stream() .filter(n -> itemsByNames.stream().noneMatch(i -> i.getName().equals(n))) .collect(Collectors.joining(", "))) ); } List<BiologicalDataItem> itemsByIds = biologicalDataItemDao.loadBiologicalDataItemsByIds(bioItemIds); if (itemsByIds.size() != bioItemIds.size()) { throw new IllegalArgumentException(getMessage( MessagesConstants.ERROR_BIO_ID_NOT_FOUND, bioItemIds.stream() .filter(id -> itemsByIds.stream().noneMatch(i -> i.getId().equals(id))) .map(Object::toString) .collect(Collectors.joining(", "))) ); } List<BiologicalDataItem> items = new ArrayList<>(itemsByNames.size() + itemsByIds.size()); items.addAll(itemsByNames); items.addAll(itemsByIds); List<Long> references = project.getItems().stream() .filter(item -> item.getBioDataItem().getFormat() == BiologicalDataItemFormat.REFERENCE) .map(item -> item.getBioDataItem().getId()).collect(Collectors.toList()); Assert.notNull(references); Assert.isTrue(!references.isEmpty()); Long referenceId = references.get(0); List<Long> itemIds = new ArrayList<>(items.size()); for (BiologicalDataItem item : items) { if (FeatureFile.class.isAssignableFrom(item.getClass())) { FeatureFile file = (FeatureFile) item; Assert.isTrue(project.getItems().stream() .anyMatch(i -> i.getBioDataItem().getId().equals(item.getId())), getMessage(MessagesConstants.ERROR_PROJECT_FILE_NOT_FOUND, item.getName(), project.getName())); Assert.isTrue(referenceId.equals(file.getReferenceId()), "Specified files have different references"); } itemIds.add(BiologicalDataItem.getBioDataItemId(item)); } Reference reference = referenceGenomeManager.load(referenceId); return makeUrl(items, project, reference, chromosomeName, startIndex, endIndex); }  @Transactional(propagation = Propagation.REQUIRED) void createBiologicalDataItem(BiologicalDataItem item); @Transactional(propagation = Propagation.REQUIRED) void deleteBiologicalDataItem(long id); @Transactional(propagation = Propagation.REQUIRED) String generateUrl(String dataset, List<String> ids, String chromosomeName,
            Integer startIndex, Integer endIndex); }
BiologicalDataItemManager { @Transactional(propagation = Propagation.REQUIRED) public String generateUrl(String dataset, List<String> ids, String chromosomeName, Integer startIndex, Integer endIndex) throws JsonProcessingException { Project project; if (NumberUtils.isDigits(dataset)) { project = projectManager.load(Long.parseLong(dataset)); } else { project = projectManager.load(dataset); } Assert.notNull(project, getMessage(MessagesConstants.ERROR_PROJECT_NOT_FOUND, dataset)); List<String> bioItemNames = new ArrayList<>(); List<Long> bioItemIds = new ArrayList<>(); for (String id : ids) { if (NumberUtils.isDigits(id)) { bioItemIds.add(Long.parseLong(id)); } else { bioItemNames.add(id); } } List<BiologicalDataItem> itemsByNames = biologicalDataItemDao.loadFilesByNamesStrict(bioItemNames); if (itemsByNames.size() != bioItemNames.size()) { throw new IllegalArgumentException(getMessage( MessagesConstants.ERROR_BIO_NAME_NOT_FOUND, bioItemNames.stream() .filter(n -> itemsByNames.stream().noneMatch(i -> i.getName().equals(n))) .collect(Collectors.joining(", "))) ); } List<BiologicalDataItem> itemsByIds = biologicalDataItemDao.loadBiologicalDataItemsByIds(bioItemIds); if (itemsByIds.size() != bioItemIds.size()) { throw new IllegalArgumentException(getMessage( MessagesConstants.ERROR_BIO_ID_NOT_FOUND, bioItemIds.stream() .filter(id -> itemsByIds.stream().noneMatch(i -> i.getId().equals(id))) .map(Object::toString) .collect(Collectors.joining(", "))) ); } List<BiologicalDataItem> items = new ArrayList<>(itemsByNames.size() + itemsByIds.size()); items.addAll(itemsByNames); items.addAll(itemsByIds); List<Long> references = project.getItems().stream() .filter(item -> item.getBioDataItem().getFormat() == BiologicalDataItemFormat.REFERENCE) .map(item -> item.getBioDataItem().getId()).collect(Collectors.toList()); Assert.notNull(references); Assert.isTrue(!references.isEmpty()); Long referenceId = references.get(0); List<Long> itemIds = new ArrayList<>(items.size()); for (BiologicalDataItem item : items) { if (FeatureFile.class.isAssignableFrom(item.getClass())) { FeatureFile file = (FeatureFile) item; Assert.isTrue(project.getItems().stream() .anyMatch(i -> i.getBioDataItem().getId().equals(item.getId())), getMessage(MessagesConstants.ERROR_PROJECT_FILE_NOT_FOUND, item.getName(), project.getName())); Assert.isTrue(referenceId.equals(file.getReferenceId()), "Specified files have different references"); } itemIds.add(BiologicalDataItem.getBioDataItemId(item)); } Reference reference = referenceGenomeManager.load(referenceId); return makeUrl(items, project, reference, chromosomeName, startIndex, endIndex); }  @Transactional(propagation = Propagation.REQUIRED) void createBiologicalDataItem(BiologicalDataItem item); @Transactional(propagation = Propagation.REQUIRED) void deleteBiologicalDataItem(long id); @Transactional(propagation = Propagation.REQUIRED) String generateUrl(String dataset, List<String> ids, String chromosomeName,
            Integer startIndex, Integer endIndex);  }