@SuppressWarnings("unchecked") @Test void updateEntityTypeCollection() { String entityTypeId = "entity"; String attrShared0Name = "attrSame"; String attrShared1Name = "attrUpdated"; String attrAddedName = "attrAdded"; String attrDeletedName = "attrDeleted"; Attribute attrShared0 = when(mock(Attribute.class).getName()).thenReturn(attrShared0Name).getMock(); when(attrShared0.getIdentifier()).thenReturn(attrShared0Name); when(attrShared0.getTags()).thenReturn(emptyList()); Attribute attrShared1 = when(mock(Attribute.class).getName()).thenReturn(attrShared1Name).getMock(); when(attrShared1.getIdentifier()).thenReturn(attrShared1Name); Attribute attrShared1Updated = when(mock(Attribute.class).getName()).thenReturn(attrShared1Name).getMock(); when(attrShared1Updated.getIdentifier()).thenReturn(attrShared1Name); when(attrShared1Updated.getLabel()).thenReturn("updated label"); Attribute attrAdded = when(mock(Attribute.class).getName()).thenReturn(attrAddedName).getMock(); when(attrAdded.getIdentifier()).thenReturn(attrAddedName); Attribute attrDeleted = when(mock(Attribute.class).getName()).thenReturn(attrDeletedName).getMock(); when(attrDeleted.getIdentifier()).thenReturn(attrDeletedName); EntityType existingEntityType = mock(EntityType.class); when(existingEntityType.getLabel()).thenReturn("label"); when(existingEntityType.getId()).thenReturn(entityTypeId); when(existingEntityType.getOwnAllAttributes()) .thenReturn(newArrayList(attrShared0, attrShared1, attrDeleted)); when(existingEntityType.getOwnMappedByAttributes()).thenAnswer(invocation -> Stream.empty()); EntityType entityType = mock(EntityType.class); when(entityType.getLabel()).thenReturn("new label"); when(entityType.getId()).thenReturn(entityTypeId); when(entityType.getOwnAllAttributes()) .thenReturn(newArrayList(attrShared0, attrShared1Updated, attrAdded)); when(entityType.getOwnMappedByAttributes()).thenAnswer(invocation -> Stream.empty()); when(entityTypeDependencyResolver.resolve(singletonList(entityType))) .thenReturn(singletonList(entityType)); when(dataService.findOneById(ENTITY_TYPE_META_DATA, entityTypeId, EntityType.class)) .thenReturn(existingEntityType); metaDataServiceImpl.upsertEntityTypes(singletonList(entityType)); ArgumentCaptor<Stream<Entity>> attrAddCaptor = ArgumentCaptor.forClass(Stream.class); verify(dataService).add(eq(ATTRIBUTE_META_DATA), attrAddCaptor.capture()); assertEquals(singletonList(attrAdded), attrAddCaptor.getValue().collect(toList())); ArgumentCaptor<Stream<Entity>> attrUpdateCaptor = ArgumentCaptor.forClass(Stream.class); verify(dataService).update(eq(ATTRIBUTE_META_DATA), attrUpdateCaptor.capture()); assertEquals(singletonList(attrShared1Updated), attrUpdateCaptor.getValue().collect(toList())); verify(dataService).update(ENTITY_TYPE_META_DATA, entityType); }
@Transactional @Override public void upsertEntityTypes(Collection<EntityType> entityTypes) { if (entityTypes.isEmpty()) { return; } List<EntityType> resolvedEntityTypes = entityTypeDependencyResolver.resolve(entityTypes); Map<String, EntityType> existingEntityTypeMap = getExistingEntityTypeMap(entityTypes); upsertEntityTypesSkipMappedByAttributes(resolvedEntityTypes, existingEntityTypeMap); addMappedByAttributes(resolvedEntityTypes, existingEntityTypeMap); }
MetaDataServiceImpl implements MetaDataService { @Transactional @Override public void upsertEntityTypes(Collection<EntityType> entityTypes) { if (entityTypes.isEmpty()) { return; } List<EntityType> resolvedEntityTypes = entityTypeDependencyResolver.resolve(entityTypes); Map<String, EntityType> existingEntityTypeMap = getExistingEntityTypeMap(entityTypes); upsertEntityTypesSkipMappedByAttributes(resolvedEntityTypes, existingEntityTypeMap); addMappedByAttributes(resolvedEntityTypes, existingEntityTypeMap); } }
MetaDataServiceImpl implements MetaDataService { @Transactional @Override public void upsertEntityTypes(Collection<EntityType> entityTypes) { if (entityTypes.isEmpty()) { return; } List<EntityType> resolvedEntityTypes = entityTypeDependencyResolver.resolve(entityTypes); Map<String, EntityType> existingEntityTypeMap = getExistingEntityTypeMap(entityTypes); upsertEntityTypesSkipMappedByAttributes(resolvedEntityTypes, existingEntityTypeMap); addMappedByAttributes(resolvedEntityTypes, existingEntityTypeMap); } MetaDataServiceImpl(
      DataService dataService,
      RepositoryCollectionRegistry repoCollectionRegistry,
      SystemEntityTypeRegistry systemEntityTypeRegistry,
      EntityTypeDependencyResolver entityTypeDependencyResolver,
      PackagePersister packagePersister); }
MetaDataServiceImpl implements MetaDataService { @Transactional @Override public void upsertEntityTypes(Collection<EntityType> entityTypes) { if (entityTypes.isEmpty()) { return; } List<EntityType> resolvedEntityTypes = entityTypeDependencyResolver.resolve(entityTypes); Map<String, EntityType> existingEntityTypeMap = getExistingEntityTypeMap(entityTypes); upsertEntityTypesSkipMappedByAttributes(resolvedEntityTypes, existingEntityTypeMap); addMappedByAttributes(resolvedEntityTypes, existingEntityTypeMap); } MetaDataServiceImpl(
      DataService dataService,
      RepositoryCollectionRegistry repoCollectionRegistry,
      SystemEntityTypeRegistry systemEntityTypeRegistry,
      EntityTypeDependencyResolver entityTypeDependencyResolver,
      PackagePersister packagePersister); @Override Optional<Repository<Entity>> getRepository(String entityTypeId); @SuppressWarnings("unchecked") @Override Optional<Repository<E>> getRepository(
      String entityTypeId, Class<E> entityClass); @Override Optional<Repository<Entity>> getRepository(EntityType entityType); @SuppressWarnings("unchecked") @Override Optional<Repository<E>> getRepository(
      EntityType entityType, Class<E> entityClass); @Override boolean hasRepository(String entityTypeId); @Transactional @Override Repository<Entity> createRepository(EntityType entityType); @Transactional @Override Repository<E> createRepository(
      EntityType entityType, Class<E> entityClass); @Override RepositoryCollection getDefaultBackend(); @Override RepositoryCollection getBackend(String backendName); @Transactional @Override void deleteEntityType(String entityTypeId); @Transactional @Override void deleteEntityTypes(Collection<String> entityTypeIds); @Transactional @Override void deleteAttributeById(Object id); @Override RepositoryCollection getBackend(EntityType entityType); @Transactional @Override void addEntityType(EntityType entityType); @Transactional @Override void updateEntityType(EntityType entityType); @Transactional @Override void upsertEntityTypes(Collection<EntityType> entityTypes); @Transactional @Override void addAttribute(Attribute attr); @Override boolean hasEntityType(String entityTypeId); @Override Optional<EntityType> getEntityType(String entityTypeId); @Transactional @Override void addPackage(Package aPackage); @Transactional @Override void upsertPackages(Stream<Package> packages); @Override Optional<Package> getPackage(String packageId); @Override List<Package> getPackages(); @Override List<Package> getRootPackages(); @Transactional @Override void upsertTags(Collection<Tag> tags); @Override Stream<EntityType> getEntityTypes(); @Override Stream<Repository<Entity>> getRepositories(); @Override @Nonnull Iterator<RepositoryCollection> iterator(); @Override Map<String, Boolean> determineImportableEntities(
      RepositoryCollection repositoryCollection); @Override boolean isEntityTypeCompatible(EntityType newEntityType); @Override boolean hasBackend(String backendName); @Override Stream<EntityType> getConcreteChildren(EntityType entityType); @Override Stream<Attribute> getReferringAttributes(String entityTypeId); }
MetaDataServiceImpl implements MetaDataService { @Transactional @Override public void upsertEntityTypes(Collection<EntityType> entityTypes) { if (entityTypes.isEmpty()) { return; } List<EntityType> resolvedEntityTypes = entityTypeDependencyResolver.resolve(entityTypes); Map<String, EntityType> existingEntityTypeMap = getExistingEntityTypeMap(entityTypes); upsertEntityTypesSkipMappedByAttributes(resolvedEntityTypes, existingEntityTypeMap); addMappedByAttributes(resolvedEntityTypes, existingEntityTypeMap); } MetaDataServiceImpl(
      DataService dataService,
      RepositoryCollectionRegistry repoCollectionRegistry,
      SystemEntityTypeRegistry systemEntityTypeRegistry,
      EntityTypeDependencyResolver entityTypeDependencyResolver,
      PackagePersister packagePersister); @Override Optional<Repository<Entity>> getRepository(String entityTypeId); @SuppressWarnings("unchecked") @Override Optional<Repository<E>> getRepository(
      String entityTypeId, Class<E> entityClass); @Override Optional<Repository<Entity>> getRepository(EntityType entityType); @SuppressWarnings("unchecked") @Override Optional<Repository<E>> getRepository(
      EntityType entityType, Class<E> entityClass); @Override boolean hasRepository(String entityTypeId); @Transactional @Override Repository<Entity> createRepository(EntityType entityType); @Transactional @Override Repository<E> createRepository(
      EntityType entityType, Class<E> entityClass); @Override RepositoryCollection getDefaultBackend(); @Override RepositoryCollection getBackend(String backendName); @Transactional @Override void deleteEntityType(String entityTypeId); @Transactional @Override void deleteEntityTypes(Collection<String> entityTypeIds); @Transactional @Override void deleteAttributeById(Object id); @Override RepositoryCollection getBackend(EntityType entityType); @Transactional @Override void addEntityType(EntityType entityType); @Transactional @Override void updateEntityType(EntityType entityType); @Transactional @Override void upsertEntityTypes(Collection<EntityType> entityTypes); @Transactional @Override void addAttribute(Attribute attr); @Override boolean hasEntityType(String entityTypeId); @Override Optional<EntityType> getEntityType(String entityTypeId); @Transactional @Override void addPackage(Package aPackage); @Transactional @Override void upsertPackages(Stream<Package> packages); @Override Optional<Package> getPackage(String packageId); @Override List<Package> getPackages(); @Override List<Package> getRootPackages(); @Transactional @Override void upsertTags(Collection<Tag> tags); @Override Stream<EntityType> getEntityTypes(); @Override Stream<Repository<Entity>> getRepositories(); @Override @Nonnull Iterator<RepositoryCollection> iterator(); @Override Map<String, Boolean> determineImportableEntities(
      RepositoryCollection repositoryCollection); @Override boolean isEntityTypeCompatible(EntityType newEntityType); @Override boolean hasBackend(String backendName); @Override Stream<EntityType> getConcreteChildren(EntityType entityType); @Override Stream<Attribute> getReferringAttributes(String entityTypeId);  }