@Test void testMoveResources() { String targetFolderId = "targetFolderId"; List<ResourceIdentifier> resources = asList( ResourceIdentifier.builder().setType(ResourceType.PACKAGE).setId("p0").build(), ResourceIdentifier.builder().setType(ResourceType.ENTITY_TYPE).setId("e0").build()); Package targetPackage = mock(Package.class); when(dataService.findOneById(PackageMetadata.PACKAGE, targetFolderId, Package.class)) .thenReturn(targetPackage); Package package0 = mock(Package.class); Stream<Package> packages = Stream.of(package0); @SuppressWarnings("unchecked") ArgumentCaptor<Stream<Object>> packageIdsCaptor = ArgumentCaptor.forClass(Stream.class); doReturn(packages) .when(dataService) .findAll(eq(PackageMetadata.PACKAGE), packageIdsCaptor.capture(), eq(Package.class)); EntityType entityType0 = mock(EntityType.class); Stream<EntityType> entityTypes = Stream.of(entityType0); @SuppressWarnings("unchecked") ArgumentCaptor<Stream<Object>> entityTypeIdsCaptor = ArgumentCaptor.forClass(Stream.class); doReturn(entityTypes) .when(dataService) .findAll( eq(EntityTypeMetadata.ENTITY_TYPE_META_DATA), entityTypeIdsCaptor.capture(), eq(EntityType.class)); navigatorServiceImpl.moveResources(resources, targetFolderId); assertEquals(singletonList("p0"), packageIdsCaptor.getValue().collect(toList())); verify(package0).setParent(targetPackage); @SuppressWarnings("unchecked") ArgumentCaptor<Stream<Package>> updatedPackagesCaptor = ArgumentCaptor.forClass(Stream.class); verify(dataService).update(eq(PackageMetadata.PACKAGE), updatedPackagesCaptor.capture()); assertEquals(singletonList(package0), updatedPackagesCaptor.getValue().collect(toList())); assertEquals(singletonList("e0"), entityTypeIdsCaptor.getValue().collect(toList())); verify(entityType0).setPackage(targetPackage); @SuppressWarnings("unchecked") ArgumentCaptor<Stream<EntityType>> updatedEntityTypesCaptor = ArgumentCaptor.forClass(Stream.class); verify(dataService) .update(eq(EntityTypeMetadata.ENTITY_TYPE_META_DATA), updatedEntityTypesCaptor.capture()); assertEquals(singletonList(entityType0), updatedEntityTypesCaptor.getValue().collect(toList())); }
@Transactional @Override public void moveResources( List<ResourceIdentifier> resources, @Nullable @CheckForNull String targetFolderId) { if (resources.isEmpty()) { return; } Package targetPackage = getPackage(targetFolderId); Map<ResourceType, List<ResourceIdentifier>> resourceMap = resources.stream().collect(groupingBy(ResourceIdentifier::getType)); resourceMap.forEach( (type, typeResources) -> { switch (type) { case PACKAGE: movePackages(typeResources, targetPackage); break; case ENTITY_TYPE: case ENTITY_TYPE_ABSTRACT: moveEntityTypes(typeResources, targetPackage); break; default: throw new UnexpectedEnumException(type); } }); }
NavigatorServiceImpl implements NavigatorService { @Transactional @Override public void moveResources( List<ResourceIdentifier> resources, @Nullable @CheckForNull String targetFolderId) { if (resources.isEmpty()) { return; } Package targetPackage = getPackage(targetFolderId); Map<ResourceType, List<ResourceIdentifier>> resourceMap = resources.stream().collect(groupingBy(ResourceIdentifier::getType)); resourceMap.forEach( (type, typeResources) -> { switch (type) { case PACKAGE: movePackages(typeResources, targetPackage); break; case ENTITY_TYPE: case ENTITY_TYPE_ABSTRACT: moveEntityTypes(typeResources, targetPackage); break; default: throw new UnexpectedEnumException(type); } }); } }
NavigatorServiceImpl implements NavigatorService { @Transactional @Override public void moveResources( List<ResourceIdentifier> resources, @Nullable @CheckForNull String targetFolderId) { if (resources.isEmpty()) { return; } Package targetPackage = getPackage(targetFolderId); Map<ResourceType, List<ResourceIdentifier>> resourceMap = resources.stream().collect(groupingBy(ResourceIdentifier::getType)); resourceMap.forEach( (type, typeResources) -> { switch (type) { case PACKAGE: movePackages(typeResources, targetPackage); break; case ENTITY_TYPE: case ENTITY_TYPE_ABSTRACT: moveEntityTypes(typeResources, targetPackage); break; default: throw new UnexpectedEnumException(type); } }); } NavigatorServiceImpl(
      DataService dataService,
      JobExecutor jobExecutor,
      ResourceDownloadJobExecutionFactory downloadJobExecutionFactory,
      ResourceCopyJobExecutionFactory copyJobExecutionFactory,
      ResourceDeleteJobExecutionFactory resourceDeleteJobExecutionFactory); }
NavigatorServiceImpl implements NavigatorService { @Transactional @Override public void moveResources( List<ResourceIdentifier> resources, @Nullable @CheckForNull String targetFolderId) { if (resources.isEmpty()) { return; } Package targetPackage = getPackage(targetFolderId); Map<ResourceType, List<ResourceIdentifier>> resourceMap = resources.stream().collect(groupingBy(ResourceIdentifier::getType)); resourceMap.forEach( (type, typeResources) -> { switch (type) { case PACKAGE: movePackages(typeResources, targetPackage); break; case ENTITY_TYPE: case ENTITY_TYPE_ABSTRACT: moveEntityTypes(typeResources, targetPackage); break; default: throw new UnexpectedEnumException(type); } }); } NavigatorServiceImpl(
      DataService dataService,
      JobExecutor jobExecutor,
      ResourceDownloadJobExecutionFactory downloadJobExecutionFactory,
      ResourceCopyJobExecutionFactory copyJobExecutionFactory,
      ResourceDeleteJobExecutionFactory resourceDeleteJobExecutionFactory); @Transactional(readOnly = true) @Override @Nullable @CheckForNull Folder getFolder(@Nullable @CheckForNull String folderId); @Transactional(readOnly = true) @Override List<Resource> getResources(@Nullable @CheckForNull String folderId); @Transactional(readOnly = true) @Override List<Resource> findResources(String query); @Transactional @Override void moveResources(
      List<ResourceIdentifier> resources, @Nullable @CheckForNull String targetFolderId); @Override JobExecution copyResources(
      List<ResourceIdentifier> resources, @Nullable @CheckForNull String targetFolderId); @Override JobExecution downloadResources(List<ResourceIdentifier> resources); @Transactional @Override JobExecution deleteResources(List<ResourceIdentifier> resources); @Transactional @Override void updateResource(Resource resource); }
NavigatorServiceImpl implements NavigatorService { @Transactional @Override public void moveResources( List<ResourceIdentifier> resources, @Nullable @CheckForNull String targetFolderId) { if (resources.isEmpty()) { return; } Package targetPackage = getPackage(targetFolderId); Map<ResourceType, List<ResourceIdentifier>> resourceMap = resources.stream().collect(groupingBy(ResourceIdentifier::getType)); resourceMap.forEach( (type, typeResources) -> { switch (type) { case PACKAGE: movePackages(typeResources, targetPackage); break; case ENTITY_TYPE: case ENTITY_TYPE_ABSTRACT: moveEntityTypes(typeResources, targetPackage); break; default: throw new UnexpectedEnumException(type); } }); } NavigatorServiceImpl(
      DataService dataService,
      JobExecutor jobExecutor,
      ResourceDownloadJobExecutionFactory downloadJobExecutionFactory,
      ResourceCopyJobExecutionFactory copyJobExecutionFactory,
      ResourceDeleteJobExecutionFactory resourceDeleteJobExecutionFactory); @Transactional(readOnly = true) @Override @Nullable @CheckForNull Folder getFolder(@Nullable @CheckForNull String folderId); @Transactional(readOnly = true) @Override List<Resource> getResources(@Nullable @CheckForNull String folderId); @Transactional(readOnly = true) @Override List<Resource> findResources(String query); @Transactional @Override void moveResources(
      List<ResourceIdentifier> resources, @Nullable @CheckForNull String targetFolderId); @Override JobExecution copyResources(
      List<ResourceIdentifier> resources, @Nullable @CheckForNull String targetFolderId); @Override JobExecution downloadResources(List<ResourceIdentifier> resources); @Transactional @Override JobExecution deleteResources(List<ResourceIdentifier> resources); @Transactional @Override void updateResource(Resource resource);  }