@Test void validateImportWithoutSamplesAlreadyExists() { String entityTypeId0 = "entity0"; List<String> entityTypeIds = singletonList(entityTypeId0); String attrName0 = "attr0"; Attribute attr0 = mock(Attribute.class); when(attr0.getName()).thenReturn(attrName0); EntityType entityType0 = mock(EntityType.class); when(entityType0.getAtomicAttributes()).thenReturn(singletonList(attr0)); @SuppressWarnings("unchecked") Repository<Entity> repo0 = mock(Repository.class); when(repo0.getEntityType()).thenReturn(entityType0); RepositoryCollection source = mock(RepositoryCollection.class); when(source.getEntityTypeIds()).thenReturn(entityTypeIds); when(source.getRepository(entityTypeId0)).thenReturn(repo0); when(dataService.hasRepository(entityTypeId0)).thenReturn(true); EntitiesValidationReport entitiesValidationReport = vcfImporterService.validateImport(source); assertFalse(entitiesValidationReport.valid()); assertEquals(emptyMap(), entitiesValidationReport.getFieldsAvailable()); assertEquals( singletonMap(entityTypeId0, singletonList(attrName0)), entitiesValidationReport.getFieldsImportable()); assertEquals(emptyMap(), entitiesValidationReport.getFieldsRequired()); assertEquals(emptyMap(), entitiesValidationReport.getFieldsUnknown()); assertEquals(emptyList(), entitiesValidationReport.getImportOrder()); assertEquals(emptyList(), entitiesValidationReport.getPackages()); assertEquals( singletonMap(entityTypeId0, FALSE), entitiesValidationReport.getSheetsImportable()); }
@Override public EntitiesValidationReport validateImport(RepositoryCollection source) { EntitiesValidationReport report = new EntitiesValidationReportImpl(); Iterator<String> it = source.getEntityTypeIds().iterator(); if (it.hasNext()) { String entityTypeId = it.next(); EntityType emd = source.getRepository(entityTypeId).getEntityType(); boolean entityExists = runAsSystem(() -> dataService.hasRepository(entityTypeId)); report.getSheetsImportable().put(entityTypeId, !entityExists); List<String> availableAttributeNames = Lists.newArrayList(); for (Attribute attr : emd.getAtomicAttributes()) { availableAttributeNames.add(attr.getName()); } report.getFieldsImportable().put(entityTypeId, availableAttributeNames); Attribute sampleAttribute = emd.getAttribute(VcfAttributes.SAMPLES); if (sampleAttribute != null) { String sampleEntityName = sampleAttribute.getRefEntity().getId(); boolean sampleEntityExists = runAsSystem(() -> dataService.hasRepository(sampleEntityName)); report.getSheetsImportable().put(sampleEntityName, !sampleEntityExists); List<String> availableSampleAttributeNames = Lists.newArrayList(); for (Attribute attr : sampleAttribute.getRefEntity().getAtomicAttributes()) { availableSampleAttributeNames.add(attr.getName()); } report.getFieldsImportable().put(sampleEntityName, availableSampleAttributeNames); } } return report; }
VcfImporterService implements ImportService { @Override public EntitiesValidationReport validateImport(RepositoryCollection source) { EntitiesValidationReport report = new EntitiesValidationReportImpl(); Iterator<String> it = source.getEntityTypeIds().iterator(); if (it.hasNext()) { String entityTypeId = it.next(); EntityType emd = source.getRepository(entityTypeId).getEntityType(); boolean entityExists = runAsSystem(() -> dataService.hasRepository(entityTypeId)); report.getSheetsImportable().put(entityTypeId, !entityExists); List<String> availableAttributeNames = Lists.newArrayList(); for (Attribute attr : emd.getAtomicAttributes()) { availableAttributeNames.add(attr.getName()); } report.getFieldsImportable().put(entityTypeId, availableAttributeNames); Attribute sampleAttribute = emd.getAttribute(VcfAttributes.SAMPLES); if (sampleAttribute != null) { String sampleEntityName = sampleAttribute.getRefEntity().getId(); boolean sampleEntityExists = runAsSystem(() -> dataService.hasRepository(sampleEntityName)); report.getSheetsImportable().put(sampleEntityName, !sampleEntityExists); List<String> availableSampleAttributeNames = Lists.newArrayList(); for (Attribute attr : sampleAttribute.getRefEntity().getAtomicAttributes()) { availableSampleAttributeNames.add(attr.getName()); } report.getFieldsImportable().put(sampleEntityName, availableSampleAttributeNames); } } return report; } }
VcfImporterService implements ImportService { @Override public EntitiesValidationReport validateImport(RepositoryCollection source) { EntitiesValidationReport report = new EntitiesValidationReportImpl(); Iterator<String> it = source.getEntityTypeIds().iterator(); if (it.hasNext()) { String entityTypeId = it.next(); EntityType emd = source.getRepository(entityTypeId).getEntityType(); boolean entityExists = runAsSystem(() -> dataService.hasRepository(entityTypeId)); report.getSheetsImportable().put(entityTypeId, !entityExists); List<String> availableAttributeNames = Lists.newArrayList(); for (Attribute attr : emd.getAtomicAttributes()) { availableAttributeNames.add(attr.getName()); } report.getFieldsImportable().put(entityTypeId, availableAttributeNames); Attribute sampleAttribute = emd.getAttribute(VcfAttributes.SAMPLES); if (sampleAttribute != null) { String sampleEntityName = sampleAttribute.getRefEntity().getId(); boolean sampleEntityExists = runAsSystem(() -> dataService.hasRepository(sampleEntityName)); report.getSheetsImportable().put(sampleEntityName, !sampleEntityExists); List<String> availableSampleAttributeNames = Lists.newArrayList(); for (Attribute attr : sampleAttribute.getRefEntity().getAtomicAttributes()) { availableSampleAttributeNames.add(attr.getName()); } report.getFieldsImportable().put(sampleEntityName, availableSampleAttributeNames); } } return report; } VcfImporterService(
      DataService dataService,
      PermissionSystemService permissionSystemService,
      MetaDataService metaDataService); }
VcfImporterService implements ImportService { @Override public EntitiesValidationReport validateImport(RepositoryCollection source) { EntitiesValidationReport report = new EntitiesValidationReportImpl(); Iterator<String> it = source.getEntityTypeIds().iterator(); if (it.hasNext()) { String entityTypeId = it.next(); EntityType emd = source.getRepository(entityTypeId).getEntityType(); boolean entityExists = runAsSystem(() -> dataService.hasRepository(entityTypeId)); report.getSheetsImportable().put(entityTypeId, !entityExists); List<String> availableAttributeNames = Lists.newArrayList(); for (Attribute attr : emd.getAtomicAttributes()) { availableAttributeNames.add(attr.getName()); } report.getFieldsImportable().put(entityTypeId, availableAttributeNames); Attribute sampleAttribute = emd.getAttribute(VcfAttributes.SAMPLES); if (sampleAttribute != null) { String sampleEntityName = sampleAttribute.getRefEntity().getId(); boolean sampleEntityExists = runAsSystem(() -> dataService.hasRepository(sampleEntityName)); report.getSheetsImportable().put(sampleEntityName, !sampleEntityExists); List<String> availableSampleAttributeNames = Lists.newArrayList(); for (Attribute attr : sampleAttribute.getRefEntity().getAtomicAttributes()) { availableSampleAttributeNames.add(attr.getName()); } report.getFieldsImportable().put(sampleEntityName, availableSampleAttributeNames); } } return report; } VcfImporterService(
      DataService dataService,
      PermissionSystemService permissionSystemService,
      MetaDataService metaDataService); @Transactional @Override EntityImportReport doImport(
      RepositoryCollection source,
      MetadataAction metadataAction,
      DataAction dataAction,
      @Nullable @CheckForNull String packageId); @Override EntitiesValidationReport validateImport(RepositoryCollection source); @Override boolean canImport(File file, RepositoryCollection source); @Override int getOrder(); @Override List<MetadataAction> getSupportedMetadataActions(); @Override List<DataAction> getSupportedDataActions(); @Override boolean getMustChangeEntityName(); @Override Set<String> getSupportedFileExtensions(); @Override Map<String, Boolean> determineImportableEntities(
      MetaDataService metaDataService,
      RepositoryCollection repositoryCollection,
      String defaultPackage); @Override MetadataAction getMetadataAction(RepositoryCollection source); }
VcfImporterService implements ImportService { @Override public EntitiesValidationReport validateImport(RepositoryCollection source) { EntitiesValidationReport report = new EntitiesValidationReportImpl(); Iterator<String> it = source.getEntityTypeIds().iterator(); if (it.hasNext()) { String entityTypeId = it.next(); EntityType emd = source.getRepository(entityTypeId).getEntityType(); boolean entityExists = runAsSystem(() -> dataService.hasRepository(entityTypeId)); report.getSheetsImportable().put(entityTypeId, !entityExists); List<String> availableAttributeNames = Lists.newArrayList(); for (Attribute attr : emd.getAtomicAttributes()) { availableAttributeNames.add(attr.getName()); } report.getFieldsImportable().put(entityTypeId, availableAttributeNames); Attribute sampleAttribute = emd.getAttribute(VcfAttributes.SAMPLES); if (sampleAttribute != null) { String sampleEntityName = sampleAttribute.getRefEntity().getId(); boolean sampleEntityExists = runAsSystem(() -> dataService.hasRepository(sampleEntityName)); report.getSheetsImportable().put(sampleEntityName, !sampleEntityExists); List<String> availableSampleAttributeNames = Lists.newArrayList(); for (Attribute attr : sampleAttribute.getRefEntity().getAtomicAttributes()) { availableSampleAttributeNames.add(attr.getName()); } report.getFieldsImportable().put(sampleEntityName, availableSampleAttributeNames); } } return report; } VcfImporterService(
      DataService dataService,
      PermissionSystemService permissionSystemService,
      MetaDataService metaDataService); @Transactional @Override EntityImportReport doImport(
      RepositoryCollection source,
      MetadataAction metadataAction,
      DataAction dataAction,
      @Nullable @CheckForNull String packageId); @Override EntitiesValidationReport validateImport(RepositoryCollection source); @Override boolean canImport(File file, RepositoryCollection source); @Override int getOrder(); @Override List<MetadataAction> getSupportedMetadataActions(); @Override List<DataAction> getSupportedDataActions(); @Override boolean getMustChangeEntityName(); @Override Set<String> getSupportedFileExtensions(); @Override Map<String, Boolean> determineImportableEntities(
      MetaDataService metaDataService,
      RepositoryCollection repositoryCollection,
      String defaultPackage); @Override MetadataAction getMetadataAction(RepositoryCollection source);  }