@SuppressWarnings("unchecked") @Test void addEntityTypesMappedByAttrs() { EntityType entityType0 = mock(EntityType.class); when(entityType0.getId()).thenReturn("entityType0"); when(entityType0.hasMappedByAttributes()).thenReturn(true); Attribute entity0Attr0 = mock(Attribute.class); when(entity0Attr0.getName()).thenReturn("entity0Attr0"); when(entity0Attr0.isMappedBy()).thenReturn(true); Attribute entity0Attr1 = mock(Attribute.class); when(entity0Attr1.getName()).thenReturn("entity0Attr1"); when(entity0Attr1.getIdentifier()).thenReturn("id01"); when(entity0Attr1.getTags()).thenReturn(emptyList()); when(entityType0.getOwnAllAttributes()).thenReturn(newArrayList(entity0Attr0, entity0Attr1)); when(entityType0.getOwnLookupAttributes()).thenReturn(emptyList()); EntityType entityType1 = mock(EntityType.class); when(entityType1.getId()).thenReturn("entityType1"); when(entityType1.hasMappedByAttributes()).thenReturn(false); Attribute entity1Attr0 = mock(Attribute.class); Attribute entity1Attr1 = mock(Attribute.class); when(entityType1.getOwnAllAttributes()).thenReturn(newArrayList(entity1Attr0, entity1Attr1)); when(dataService.findOneById(eq(ENTITY_TYPE_META_DATA), any(), eq(EntityType.class))) .thenReturn(null); when(entityTypeDependencyResolver.resolve(newArrayList(entityType0, entityType1))) .thenReturn(newArrayList(entityType1, entityType0)); metaDataServiceImpl.upsertEntityTypes(newArrayList(entityType0, entityType1)); InOrder inOrder = inOrder(dataService); inOrder.verify(dataService).add(ENTITY_TYPE_META_DATA, entityType1); ArgumentCaptor<Stream<Entity>> attrsCaptor1 = ArgumentCaptor.forClass(Stream.class); inOrder.verify(dataService).add(eq(ATTRIBUTE_META_DATA), attrsCaptor1.capture()); assertEquals( newArrayList(entity1Attr0, entity1Attr1), attrsCaptor1.getValue().collect(toList())); ArgumentCaptor<EntityType> entityCaptor0 = ArgumentCaptor.forClass(EntityType.class); inOrder.verify(dataService).add(eq(ENTITY_TYPE_META_DATA), entityCaptor0.capture()); assertEquals( singletonList(entity0Attr1), newArrayList(entityCaptor0.getValue().getOwnAllAttributes())); ArgumentCaptor<Stream<Entity>> attrsCaptor0 = ArgumentCaptor.forClass(Stream.class); inOrder.verify(dataService).add(eq(ATTRIBUTE_META_DATA), attrsCaptor0.capture()); assertEquals(singletonList(entity0Attr1), attrsCaptor0.getValue().collect(toList())); ArgumentCaptor<EntityType> entityCaptor0b = ArgumentCaptor.forClass(EntityType.class); inOrder.verify(dataService).update(eq(ENTITY_TYPE_META_DATA), entityCaptor0b.capture()); assertEquals(entityType0, entityCaptor0b.getValue()); ArgumentCaptor<Stream<Entity>> attrsCaptor0b = ArgumentCaptor.forClass(Stream.class); inOrder.verify(dataService).add(eq(ATTRIBUTE_META_DATA), attrsCaptor0b.capture()); assertEquals(singletonList(entity0Attr0), attrsCaptor0b.getValue().collect(toList())); }
@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);  }