@SuppressWarnings("unchecked") @Test void removeNonExistingSystemEntities() { when(dataService.getMeta()).thenReturn(metaDataService); Package systemPackage = mock(Package.class); when(systemPackage.getId()).thenReturn(PACKAGE_SYSTEM); EntityType refRemovedMeta = when(mock(EntityType.class).getId()).thenReturn("refRemoved").getMock(); when(refRemovedMeta.getPackage()).thenReturn(systemPackage); EntityType removedMeta = when(mock(EntityType.class).getId()).thenReturn("removed").getMock(); when(removedMeta.getPackage()).thenReturn(systemPackage); EntityType refEntityType = when(mock(EntityType.class).getId()).thenReturn("refEntity").getMock(); when(refEntityType.getPackage()).thenReturn(systemPackage); EntityType entityType = when(mock(EntityType.class).getId()).thenReturn("entity").getMock(); when(entityType.getPackage()).thenReturn(systemPackage); doReturn(true).when(systemEntityTypeRegistry).hasSystemEntityType("entity"); doReturn(true).when(systemEntityTypeRegistry).hasSystemEntityType("refEntity"); 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(asList(refEntityType, entityType, refRemovedMeta, removedMeta)); return null; }) .when(repository) .forEachBatched(any(Fetch.class), any(), eq(1000)); systemEntityTypePersister.removeNonExistingSystemEntityTypes(); verify(metaDataService).deleteEntityTypes(asList("refRemoved", "removed")); }
void removeNonExistingSystemEntityTypes() { List<String> removedSystemEntityIds = new ArrayList<>(); dataService .getRepository(ENTITY_TYPE_META_DATA, EntityType.class) .forEachBatched( new Fetch().field(ID).field(PACKAGE), entityTypes -> entityTypes.stream() .filter(EntityTypeUtils::isSystemEntity) .filter(this::isNotExists) .map(EntityType::getId) .forEach(removedSystemEntityIds::add), 1000); dataService.getMeta().deleteEntityTypes(removedSystemEntityIds); removedSystemEntityIds.forEach( entityTypeId -> mutableAclClassService.deleteAclClass(EntityIdentityUtils.toType(entityTypeId))); }
SystemEntityTypePersister { void removeNonExistingSystemEntityTypes() { List<String> removedSystemEntityIds = new ArrayList<>(); dataService .getRepository(ENTITY_TYPE_META_DATA, EntityType.class) .forEachBatched( new Fetch().field(ID).field(PACKAGE), entityTypes -> entityTypes.stream() .filter(EntityTypeUtils::isSystemEntity) .filter(this::isNotExists) .map(EntityType::getId) .forEach(removedSystemEntityIds::add), 1000); dataService.getMeta().deleteEntityTypes(removedSystemEntityIds); removedSystemEntityIds.forEach( entityTypeId -> mutableAclClassService.deleteAclClass(EntityIdentityUtils.toType(entityTypeId))); } }
SystemEntityTypePersister { void removeNonExistingSystemEntityTypes() { List<String> removedSystemEntityIds = new ArrayList<>(); dataService .getRepository(ENTITY_TYPE_META_DATA, EntityType.class) .forEachBatched( new Fetch().field(ID).field(PACKAGE), entityTypes -> entityTypes.stream() .filter(EntityTypeUtils::isSystemEntity) .filter(this::isNotExists) .map(EntityType::getId) .forEach(removedSystemEntityIds::add), 1000); dataService.getMeta().deleteEntityTypes(removedSystemEntityIds); removedSystemEntityIds.forEach( entityTypeId -> mutableAclClassService.deleteAclClass(EntityIdentityUtils.toType(entityTypeId))); } SystemEntityTypePersister(
      DataService dataService,
      SystemEntityTypeRegistry systemEntityTypeRegistry,
      EntityTypeDependencyResolver entityTypeDependencyResolver,
      SystemPackageRegistry systemPackageRegistry,
      MutableAclClassService mutableAclClassService); }
SystemEntityTypePersister { void removeNonExistingSystemEntityTypes() { List<String> removedSystemEntityIds = new ArrayList<>(); dataService .getRepository(ENTITY_TYPE_META_DATA, EntityType.class) .forEachBatched( new Fetch().field(ID).field(PACKAGE), entityTypes -> entityTypes.stream() .filter(EntityTypeUtils::isSystemEntity) .filter(this::isNotExists) .map(EntityType::getId) .forEach(removedSystemEntityIds::add), 1000); dataService.getMeta().deleteEntityTypes(removedSystemEntityIds); removedSystemEntityIds.forEach( entityTypeId -> mutableAclClassService.deleteAclClass(EntityIdentityUtils.toType(entityTypeId))); } SystemEntityTypePersister(
      DataService dataService,
      SystemEntityTypeRegistry systemEntityTypeRegistry,
      EntityTypeDependencyResolver entityTypeDependencyResolver,
      SystemPackageRegistry systemPackageRegistry,
      MutableAclClassService mutableAclClassService); void persist(); }
SystemEntityTypePersister { void removeNonExistingSystemEntityTypes() { List<String> removedSystemEntityIds = new ArrayList<>(); dataService .getRepository(ENTITY_TYPE_META_DATA, EntityType.class) .forEachBatched( new Fetch().field(ID).field(PACKAGE), entityTypes -> entityTypes.stream() .filter(EntityTypeUtils::isSystemEntity) .filter(this::isNotExists) .map(EntityType::getId) .forEach(removedSystemEntityIds::add), 1000); dataService.getMeta().deleteEntityTypes(removedSystemEntityIds); removedSystemEntityIds.forEach( entityTypeId -> mutableAclClassService.deleteAclClass(EntityIdentityUtils.toType(entityTypeId))); } SystemEntityTypePersister(
      DataService dataService,
      SystemEntityTypeRegistry systemEntityTypeRegistry,
      EntityTypeDependencyResolver entityTypeDependencyResolver,
      SystemPackageRegistry systemPackageRegistry,
      MutableAclClassService mutableAclClassService); void persist();  }