@SuppressWarnings("unchecked") @Test void persistSystemPackageNoChange() { RepositoryCollection defaultRepoCollection = mock(RepositoryCollection.class); when(metaDataService.getDefaultBackend()).thenReturn(defaultRepoCollection); when(dataService.getMeta()).thenReturn(metaDataService); when(systemEntityTypeRegistry.getSystemEntityTypes()).thenAnswer(invocation -> Stream.empty()); Repository<EntityType> repository = mock(Repository.class); when(dataService.getRepository(ENTITY_TYPE_META_DATA, EntityType.class)).thenReturn(repository); doAnswer( invocation -> { ((Consumer<List<Entity>>) invocation.getArgument(1)).accept(emptyList()); return null; }) .when(repository) .forEachBatched(any(Fetch.class), any(), eq(1000)); String packageId0 = "packageId0"; String packageName0 = "packageName0"; SystemPackage package0 = when(mock(SystemPackage.class).getId()).thenReturn(packageName0).getMock(); when(package0.getId()).thenReturn(packageId0); String packageId1 = "packageId1"; String packageName1 = "packageName1"; SystemPackage package1 = when(mock(SystemPackage.class).getId()).thenReturn(packageName1).getMock(); when(package1.getId()).thenReturn(packageId1); when(systemPackageRegistry.getSystemPackages()).thenReturn(Stream.of(package0, package1)); doAnswer(invocation -> Stream.of(package0, package1)) .when(dataService) .findAll(PACKAGE, Package.class); systemEntityTypePersister.persist(); @SuppressWarnings("unchecked") ArgumentCaptor<Stream<Package>> captor = ArgumentCaptor.forClass(Stream.class); verify(metaDataService).upsertPackages(captor.capture()); assertEquals(newArrayList(package0, package1), captor.getValue().collect(toList())); }
public void persist() { persistMetadataMetadata(); List<Package> systemPackages = systemPackageRegistry.getSystemPackages().collect(toList()); injectExistingPackageIdentifiers(systemPackages); dataService.getMeta().upsertPackages(systemPackages.stream()); List<SystemEntityType> metaEntityMetaSet = systemEntityTypeRegistry.getSystemEntityTypes().collect(toList()); injectExistingEntityTypeAttributeIdentifiers(metaEntityMetaSet); metaEntityMetaSet.forEach( systemEntityType -> { String aclClass = EntityIdentityUtils.toType(systemEntityType); if (systemEntityType.isRowLevelSecured() && !mutableAclClassService.hasAclClass(aclClass)) { mutableAclClassService.createAclClass( aclClass, EntityIdentityUtils.toIdType(systemEntityType)); } else if (!systemEntityType.isRowLevelSecured() && mutableAclClassService.hasAclClass(aclClass)) { mutableAclClassService.deleteAclClass(aclClass); } }); dataService.getMeta().upsertEntityTypes(new ArrayList<>(metaEntityMetaSet)); removeNonExistingSystemEntityTypes(); removeNonExistingSystemPackages(); }
SystemEntityTypePersister { public void persist() { persistMetadataMetadata(); List<Package> systemPackages = systemPackageRegistry.getSystemPackages().collect(toList()); injectExistingPackageIdentifiers(systemPackages); dataService.getMeta().upsertPackages(systemPackages.stream()); List<SystemEntityType> metaEntityMetaSet = systemEntityTypeRegistry.getSystemEntityTypes().collect(toList()); injectExistingEntityTypeAttributeIdentifiers(metaEntityMetaSet); metaEntityMetaSet.forEach( systemEntityType -> { String aclClass = EntityIdentityUtils.toType(systemEntityType); if (systemEntityType.isRowLevelSecured() && !mutableAclClassService.hasAclClass(aclClass)) { mutableAclClassService.createAclClass( aclClass, EntityIdentityUtils.toIdType(systemEntityType)); } else if (!systemEntityType.isRowLevelSecured() && mutableAclClassService.hasAclClass(aclClass)) { mutableAclClassService.deleteAclClass(aclClass); } }); dataService.getMeta().upsertEntityTypes(new ArrayList<>(metaEntityMetaSet)); removeNonExistingSystemEntityTypes(); removeNonExistingSystemPackages(); } }
SystemEntityTypePersister { public void persist() { persistMetadataMetadata(); List<Package> systemPackages = systemPackageRegistry.getSystemPackages().collect(toList()); injectExistingPackageIdentifiers(systemPackages); dataService.getMeta().upsertPackages(systemPackages.stream()); List<SystemEntityType> metaEntityMetaSet = systemEntityTypeRegistry.getSystemEntityTypes().collect(toList()); injectExistingEntityTypeAttributeIdentifiers(metaEntityMetaSet); metaEntityMetaSet.forEach( systemEntityType -> { String aclClass = EntityIdentityUtils.toType(systemEntityType); if (systemEntityType.isRowLevelSecured() && !mutableAclClassService.hasAclClass(aclClass)) { mutableAclClassService.createAclClass( aclClass, EntityIdentityUtils.toIdType(systemEntityType)); } else if (!systemEntityType.isRowLevelSecured() && mutableAclClassService.hasAclClass(aclClass)) { mutableAclClassService.deleteAclClass(aclClass); } }); dataService.getMeta().upsertEntityTypes(new ArrayList<>(metaEntityMetaSet)); removeNonExistingSystemEntityTypes(); removeNonExistingSystemPackages(); } SystemEntityTypePersister(
      DataService dataService,
      SystemEntityTypeRegistry systemEntityTypeRegistry,
      EntityTypeDependencyResolver entityTypeDependencyResolver,
      SystemPackageRegistry systemPackageRegistry,
      MutableAclClassService mutableAclClassService); }
SystemEntityTypePersister { public void persist() { persistMetadataMetadata(); List<Package> systemPackages = systemPackageRegistry.getSystemPackages().collect(toList()); injectExistingPackageIdentifiers(systemPackages); dataService.getMeta().upsertPackages(systemPackages.stream()); List<SystemEntityType> metaEntityMetaSet = systemEntityTypeRegistry.getSystemEntityTypes().collect(toList()); injectExistingEntityTypeAttributeIdentifiers(metaEntityMetaSet); metaEntityMetaSet.forEach( systemEntityType -> { String aclClass = EntityIdentityUtils.toType(systemEntityType); if (systemEntityType.isRowLevelSecured() && !mutableAclClassService.hasAclClass(aclClass)) { mutableAclClassService.createAclClass( aclClass, EntityIdentityUtils.toIdType(systemEntityType)); } else if (!systemEntityType.isRowLevelSecured() && mutableAclClassService.hasAclClass(aclClass)) { mutableAclClassService.deleteAclClass(aclClass); } }); dataService.getMeta().upsertEntityTypes(new ArrayList<>(metaEntityMetaSet)); removeNonExistingSystemEntityTypes(); removeNonExistingSystemPackages(); } SystemEntityTypePersister(
      DataService dataService,
      SystemEntityTypeRegistry systemEntityTypeRegistry,
      EntityTypeDependencyResolver entityTypeDependencyResolver,
      SystemPackageRegistry systemPackageRegistry,
      MutableAclClassService mutableAclClassService); void persist(); }
SystemEntityTypePersister { public void persist() { persistMetadataMetadata(); List<Package> systemPackages = systemPackageRegistry.getSystemPackages().collect(toList()); injectExistingPackageIdentifiers(systemPackages); dataService.getMeta().upsertPackages(systemPackages.stream()); List<SystemEntityType> metaEntityMetaSet = systemEntityTypeRegistry.getSystemEntityTypes().collect(toList()); injectExistingEntityTypeAttributeIdentifiers(metaEntityMetaSet); metaEntityMetaSet.forEach( systemEntityType -> { String aclClass = EntityIdentityUtils.toType(systemEntityType); if (systemEntityType.isRowLevelSecured() && !mutableAclClassService.hasAclClass(aclClass)) { mutableAclClassService.createAclClass( aclClass, EntityIdentityUtils.toIdType(systemEntityType)); } else if (!systemEntityType.isRowLevelSecured() && mutableAclClassService.hasAclClass(aclClass)) { mutableAclClassService.deleteAclClass(aclClass); } }); dataService.getMeta().upsertEntityTypes(new ArrayList<>(metaEntityMetaSet)); removeNonExistingSystemEntityTypes(); removeNonExistingSystemPackages(); } SystemEntityTypePersister(
      DataService dataService,
      SystemEntityTypeRegistry systemEntityTypeRegistry,
      EntityTypeDependencyResolver entityTypeDependencyResolver,
      SystemPackageRegistry systemPackageRegistry,
      MutableAclClassService mutableAclClassService); void persist();  }