@Test void testDoImportIgnoreMetadata() { EmxImportJob emxImportJob = mock(EmxImportJob.class); when(emxImportJob.getMetadataAction()).thenReturn(MetadataAction.IGNORE); when(emxImportJob.getDataAction()).thenReturn(DataAction.ADD_UPDATE_EXISTING); ParsedMetaData parsedMetaData = mock(ParsedMetaData.class); when(parsedMetaData.getEntities()).thenReturn(ImmutableList.of()); when(emxImportJob.getParsedMetaData()).thenReturn(parsedMetaData); EntityImportReport entityImportReport = mock(EntityImportReport.class); when(emxImportJob.getEntityImportReport()).thenReturn(entityImportReport); PersistResult persistResult = mock(PersistResult.class); when(dataPersister.persist( any(), eq(DataPersister.MetadataMode.NONE), eq(DataPersister.DataMode.UPSERT))) .thenReturn(persistResult); when(persistResult.getNrPersistedEntitiesMap()).thenReturn(ImmutableMap.of()); importWriter.doImport(emxImportJob); verifyNoInteractions(metaDataService, permissionSystemService); }
@Transactional public EntityImportReport doImport(EmxImportJob job) { if (job.getMetadataAction() != MetadataAction.IGNORE) { importTags(job.parsedMetaData); importPackages(job.parsedMetaData); } GroupedEntityTypes groupedEntityTypes = groupEntityTypes(job.getParsedMetaData().getEntities()); validateEntityTypePermissions(groupedEntityTypes.getUpdatedEntityTypes()); PersistResult persistResult = dataPersister.persist( new EmxDataProvider(job, entityManager), toMetadataMode(job.getMetadataAction()), toDataMode(job.getDataAction())); if (job.getMetadataAction() != MetadataAction.IGNORE) { permissionSystemService.giveUserWriteMetaPermissions(groupedEntityTypes.getNewEntityTypes()); } persistResult .getNrPersistedEntitiesMap() .forEach( (key, value) -> job.getEntityImportReport().addEntityCount(key, Math.toIntExact(value))); groupedEntityTypes.getNewEntityTypes().stream() .map(EntityType::getId) .forEach(job.getEntityImportReport()::addNewEntity); return job.report; }
ImportWriter { @Transactional public EntityImportReport doImport(EmxImportJob job) { if (job.getMetadataAction() != MetadataAction.IGNORE) { importTags(job.parsedMetaData); importPackages(job.parsedMetaData); } GroupedEntityTypes groupedEntityTypes = groupEntityTypes(job.getParsedMetaData().getEntities()); validateEntityTypePermissions(groupedEntityTypes.getUpdatedEntityTypes()); PersistResult persistResult = dataPersister.persist( new EmxDataProvider(job, entityManager), toMetadataMode(job.getMetadataAction()), toDataMode(job.getDataAction())); if (job.getMetadataAction() != MetadataAction.IGNORE) { permissionSystemService.giveUserWriteMetaPermissions(groupedEntityTypes.getNewEntityTypes()); } persistResult .getNrPersistedEntitiesMap() .forEach( (key, value) -> job.getEntityImportReport().addEntityCount(key, Math.toIntExact(value))); groupedEntityTypes.getNewEntityTypes().stream() .map(EntityType::getId) .forEach(job.getEntityImportReport()::addNewEntity); return job.report; } }
ImportWriter { @Transactional public EntityImportReport doImport(EmxImportJob job) { if (job.getMetadataAction() != MetadataAction.IGNORE) { importTags(job.parsedMetaData); importPackages(job.parsedMetaData); } GroupedEntityTypes groupedEntityTypes = groupEntityTypes(job.getParsedMetaData().getEntities()); validateEntityTypePermissions(groupedEntityTypes.getUpdatedEntityTypes()); PersistResult persistResult = dataPersister.persist( new EmxDataProvider(job, entityManager), toMetadataMode(job.getMetadataAction()), toDataMode(job.getDataAction())); if (job.getMetadataAction() != MetadataAction.IGNORE) { permissionSystemService.giveUserWriteMetaPermissions(groupedEntityTypes.getNewEntityTypes()); } persistResult .getNrPersistedEntitiesMap() .forEach( (key, value) -> job.getEntityImportReport().addEntityCount(key, Math.toIntExact(value))); groupedEntityTypes.getNewEntityTypes().stream() .map(EntityType::getId) .forEach(job.getEntityImportReport()::addNewEntity); return job.report; } ImportWriter(
      MetaDataService metaDataService,
      PermissionSystemService permissionSystemService,
      UserPermissionEvaluator permissionService,
      EntityManager entityManager,
      DataPersister dataPersister); }
ImportWriter { @Transactional public EntityImportReport doImport(EmxImportJob job) { if (job.getMetadataAction() != MetadataAction.IGNORE) { importTags(job.parsedMetaData); importPackages(job.parsedMetaData); } GroupedEntityTypes groupedEntityTypes = groupEntityTypes(job.getParsedMetaData().getEntities()); validateEntityTypePermissions(groupedEntityTypes.getUpdatedEntityTypes()); PersistResult persistResult = dataPersister.persist( new EmxDataProvider(job, entityManager), toMetadataMode(job.getMetadataAction()), toDataMode(job.getDataAction())); if (job.getMetadataAction() != MetadataAction.IGNORE) { permissionSystemService.giveUserWriteMetaPermissions(groupedEntityTypes.getNewEntityTypes()); } persistResult .getNrPersistedEntitiesMap() .forEach( (key, value) -> job.getEntityImportReport().addEntityCount(key, Math.toIntExact(value))); groupedEntityTypes.getNewEntityTypes().stream() .map(EntityType::getId) .forEach(job.getEntityImportReport()::addNewEntity); return job.report; } ImportWriter(
      MetaDataService metaDataService,
      PermissionSystemService permissionSystemService,
      UserPermissionEvaluator permissionService,
      EntityManager entityManager,
      DataPersister dataPersister); @Transactional EntityImportReport doImport(EmxImportJob job); }
ImportWriter { @Transactional public EntityImportReport doImport(EmxImportJob job) { if (job.getMetadataAction() != MetadataAction.IGNORE) { importTags(job.parsedMetaData); importPackages(job.parsedMetaData); } GroupedEntityTypes groupedEntityTypes = groupEntityTypes(job.getParsedMetaData().getEntities()); validateEntityTypePermissions(groupedEntityTypes.getUpdatedEntityTypes()); PersistResult persistResult = dataPersister.persist( new EmxDataProvider(job, entityManager), toMetadataMode(job.getMetadataAction()), toDataMode(job.getDataAction())); if (job.getMetadataAction() != MetadataAction.IGNORE) { permissionSystemService.giveUserWriteMetaPermissions(groupedEntityTypes.getNewEntityTypes()); } persistResult .getNrPersistedEntitiesMap() .forEach( (key, value) -> job.getEntityImportReport().addEntityCount(key, Math.toIntExact(value))); groupedEntityTypes.getNewEntityTypes().stream() .map(EntityType::getId) .forEach(job.getEntityImportReport()::addNewEntity); return job.report; } ImportWriter(
      MetaDataService metaDataService,
      PermissionSystemService permissionSystemService,
      UserPermissionEvaluator permissionService,
      EntityManager entityManager,
      DataPersister dataPersister); @Transactional EntityImportReport doImport(EmxImportJob job);  }