@Test public void testGetByCrnsFound() { Set<String> crnSet = Set.of(SERVER_CRN.toString(), SERVER_2_CRN.toString()); Set<DatabaseServerConfig> serverSet = Set.of(server, server2); when(repository.findByResourceCrnIn(any())).thenReturn(serverSet); Set<DatabaseServerConfig> gottenSet = underTest.getByCrns(crnSet); assertEquals(serverSet, gottenSet); }
public Set<DatabaseServerConfig> getByCrns(Set<String> crns) { Set<Crn> parsedCrns = crns.stream() .map(Crn::safeFromString) .collect(Collectors.toSet()); Set<DatabaseServerConfig> resources = repository.findByResourceCrnIn(parsedCrns); Set<String> notFound = Sets.difference(crns, resources.stream().map(dsc -> dsc.getResourceCrn().toString()).collect(Collectors.toSet())); if (!notFound.isEmpty()) { throw new NotFoundException(String.format("No %s(s) found with crn(s) %s ", DatabaseServerConfig.class.getSimpleName(), String.join(", ", notFound))); } return resources; }
DatabaseServerConfigService extends AbstractArchivistService<DatabaseServerConfig> implements ResourceBasedCrnProvider { public Set<DatabaseServerConfig> getByCrns(Set<String> crns) { Set<Crn> parsedCrns = crns.stream() .map(Crn::safeFromString) .collect(Collectors.toSet()); Set<DatabaseServerConfig> resources = repository.findByResourceCrnIn(parsedCrns); Set<String> notFound = Sets.difference(crns, resources.stream().map(dsc -> dsc.getResourceCrn().toString()).collect(Collectors.toSet())); if (!notFound.isEmpty()) { throw new NotFoundException(String.format("No %s(s) found with crn(s) %s ", DatabaseServerConfig.class.getSimpleName(), String.join(", ", notFound))); } return resources; } }
DatabaseServerConfigService extends AbstractArchivistService<DatabaseServerConfig> implements ResourceBasedCrnProvider { public Set<DatabaseServerConfig> getByCrns(Set<String> crns) { Set<Crn> parsedCrns = crns.stream() .map(Crn::safeFromString) .collect(Collectors.toSet()); Set<DatabaseServerConfig> resources = repository.findByResourceCrnIn(parsedCrns); Set<String> notFound = Sets.difference(crns, resources.stream().map(dsc -> dsc.getResourceCrn().toString()).collect(Collectors.toSet())); if (!notFound.isEmpty()) { throw new NotFoundException(String.format("No %s(s) found with crn(s) %s ", DatabaseServerConfig.class.getSimpleName(), String.join(", ", notFound))); } return resources; }  }
DatabaseServerConfigService extends AbstractArchivistService<DatabaseServerConfig> implements ResourceBasedCrnProvider { public Set<DatabaseServerConfig> getByCrns(Set<String> crns) { Set<Crn> parsedCrns = crns.stream() .map(Crn::safeFromString) .collect(Collectors.toSet()); Set<DatabaseServerConfig> resources = repository.findByResourceCrnIn(parsedCrns); Set<String> notFound = Sets.difference(crns, resources.stream().map(dsc -> dsc.getResourceCrn().toString()).collect(Collectors.toSet())); if (!notFound.isEmpty()) { throw new NotFoundException(String.format("No %s(s) found with crn(s) %s ", DatabaseServerConfig.class.getSimpleName(), String.join(", ", notFound))); } return resources; }  Set<DatabaseServerConfig> findAll(Long workspaceId, String environmentCrn); DatabaseServerConfig create(DatabaseServerConfig resource, Long workspaceId, boolean test); DatabaseServerConfig update(DatabaseServerConfig resource); DatabaseServerConfig release(String resourceCrn); @Override DatabaseServerConfig delete(DatabaseServerConfig resource); DatabaseServerConfig getByName(Long workspaceId, String environmentCrn, String name); DatabaseServerConfig getByCrn(String resourceCrn); Optional<DatabaseServerConfig> getByCrn(Crn resourceCrn); Optional<DatabaseServerConfig> getByClusterCrn(String clusterCrn); DatabaseServerConfig deleteByCrn(String crn); @Override JpaRepository repository(); Set<DatabaseServerConfig> getByCrns(Set<String> crns); String testConnection(String crn); String testConnection(DatabaseServerConfig resource); String createDatabaseOnServer(String serverCrn, String databaseName, String databaseType, Optional<String> databaseDescription); @Override AuthorizationResourceType getResourceType(); @Override String getResourceCrnByResourceName(String resourceName); @Override List<String> getResourceCrnListByResourceNameList(List<String> resourceNames); @Override List<String> getResourceCrnsInAccount(); }
DatabaseServerConfigService extends AbstractArchivistService<DatabaseServerConfig> implements ResourceBasedCrnProvider { public Set<DatabaseServerConfig> getByCrns(Set<String> crns) { Set<Crn> parsedCrns = crns.stream() .map(Crn::safeFromString) .collect(Collectors.toSet()); Set<DatabaseServerConfig> resources = repository.findByResourceCrnIn(parsedCrns); Set<String> notFound = Sets.difference(crns, resources.stream().map(dsc -> dsc.getResourceCrn().toString()).collect(Collectors.toSet())); if (!notFound.isEmpty()) { throw new NotFoundException(String.format("No %s(s) found with crn(s) %s ", DatabaseServerConfig.class.getSimpleName(), String.join(", ", notFound))); } return resources; }  Set<DatabaseServerConfig> findAll(Long workspaceId, String environmentCrn); DatabaseServerConfig create(DatabaseServerConfig resource, Long workspaceId, boolean test); DatabaseServerConfig update(DatabaseServerConfig resource); DatabaseServerConfig release(String resourceCrn); @Override DatabaseServerConfig delete(DatabaseServerConfig resource); DatabaseServerConfig getByName(Long workspaceId, String environmentCrn, String name); DatabaseServerConfig getByCrn(String resourceCrn); Optional<DatabaseServerConfig> getByCrn(Crn resourceCrn); Optional<DatabaseServerConfig> getByClusterCrn(String clusterCrn); DatabaseServerConfig deleteByCrn(String crn); @Override JpaRepository repository(); Set<DatabaseServerConfig> getByCrns(Set<String> crns); String testConnection(String crn); String testConnection(DatabaseServerConfig resource); String createDatabaseOnServer(String serverCrn, String databaseName, String databaseType, Optional<String> databaseDescription); @Override AuthorizationResourceType getResourceType(); @Override String getResourceCrnByResourceName(String resourceName); @Override List<String> getResourceCrnListByResourceNameList(List<String> resourceNames); @Override List<String> getResourceCrnsInAccount();  }