@Test public void testGetByNameForWorkspaceAndLoadDefaultsIfNecessaryWhenNotFound() { Blueprint blueprint1 = getBlueprint("One", DEFAULT); Blueprint blueprint2 = getBlueprint("Two", DEFAULT); when(blueprintRepository.findAllByNotDeletedInWorkspace(1L)).thenReturn(Set.of(blueprint1)); when(blueprintRepository.findAllByWorkspaceIdAndStatusIn(anyLong(), any())).thenReturn(Set.of(blueprint1)); when(blueprintLoaderService.isAddingDefaultBlueprintsNecessaryForTheUser(any())).thenReturn(true); when(blueprintLoaderService.loadBlueprintsForTheWorkspace(any(), any(), any())).thenReturn(Set.of(blueprint1, blueprint2)); try { underTest.getByNameForWorkspaceAndLoadDefaultsIfNecessary("Three", getWorkspace()); } catch (NotFoundException e) { assertThat(e.getMessage(), containsString("Three")); } verify(blueprintRepository).findAllByNotDeletedInWorkspace(1L); verify(blueprintRepository).findAllByWorkspaceIdAndStatusIn(anyLong(), any()); verify(blueprintLoaderService).isAddingDefaultBlueprintsNecessaryForTheUser(any()); verify(blueprintLoaderService).loadBlueprintsForTheWorkspace(any(), any(), any()); }
public Blueprint getByNameForWorkspaceAndLoadDefaultsIfNecessary(String name, Workspace workspace) { Set<Blueprint> blueprints = blueprintRepository.findAllByNotDeletedInWorkspace(workspace.getId()); Optional<Blueprint> blueprint = filterBlueprintsByName(name, blueprints); if (blueprint.isPresent()) { return blueprint.get(); } else { Set<Blueprint> updatedDefaultBlueprints = updateDefaultBlueprintCollection(workspace); blueprint = filterBlueprintsByName(name, updatedDefaultBlueprints); if (blueprint.isPresent()) { return blueprint.get(); } } throw new NotFoundException(String.format("No cluster template found with name '%s'", name)); }
BlueprintService extends AbstractWorkspaceAwareResourceService<Blueprint> implements ResourceBasedCrnProvider { public Blueprint getByNameForWorkspaceAndLoadDefaultsIfNecessary(String name, Workspace workspace) { Set<Blueprint> blueprints = blueprintRepository.findAllByNotDeletedInWorkspace(workspace.getId()); Optional<Blueprint> blueprint = filterBlueprintsByName(name, blueprints); if (blueprint.isPresent()) { return blueprint.get(); } else { Set<Blueprint> updatedDefaultBlueprints = updateDefaultBlueprintCollection(workspace); blueprint = filterBlueprintsByName(name, updatedDefaultBlueprints); if (blueprint.isPresent()) { return blueprint.get(); } } throw new NotFoundException(String.format("No cluster template found with name '%s'", name)); } }
BlueprintService extends AbstractWorkspaceAwareResourceService<Blueprint> implements ResourceBasedCrnProvider { public Blueprint getByNameForWorkspaceAndLoadDefaultsIfNecessary(String name, Workspace workspace) { Set<Blueprint> blueprints = blueprintRepository.findAllByNotDeletedInWorkspace(workspace.getId()); Optional<Blueprint> blueprint = filterBlueprintsByName(name, blueprints); if (blueprint.isPresent()) { return blueprint.get(); } else { Set<Blueprint> updatedDefaultBlueprints = updateDefaultBlueprintCollection(workspace); blueprint = filterBlueprintsByName(name, updatedDefaultBlueprints); if (blueprint.isPresent()) { return blueprint.get(); } } throw new NotFoundException(String.format("No cluster template found with name '%s'", name)); }  }
BlueprintService extends AbstractWorkspaceAwareResourceService<Blueprint> implements ResourceBasedCrnProvider { public Blueprint getByNameForWorkspaceAndLoadDefaultsIfNecessary(String name, Workspace workspace) { Set<Blueprint> blueprints = blueprintRepository.findAllByNotDeletedInWorkspace(workspace.getId()); Optional<Blueprint> blueprint = filterBlueprintsByName(name, blueprints); if (blueprint.isPresent()) { return blueprint.get(); } else { Set<Blueprint> updatedDefaultBlueprints = updateDefaultBlueprintCollection(workspace); blueprint = filterBlueprintsByName(name, updatedDefaultBlueprints); if (blueprint.isPresent()) { return blueprint.get(); } } throw new NotFoundException(String.format("No cluster template found with name '%s'", name)); }  Blueprint get(Long id); Blueprint createForLoggedInUser(Blueprint blueprint, Long workspaceId, String accountId, String creator); Blueprint deleteByWorkspace(NameOrCrn nameOrCrn, Long workspaceId); Blueprint getByWorkspace(@NotNull NameOrCrn nameOrCrn, Long workspaceId); void decorateWithCrn(Blueprint bp, String accountId, String creator); PlatformRecommendation getRecommendation(Long workspaceId, String blueprintName, String credentialName,
            String region, String platformVariant, String availabilityZone, CdpResourceType cdpResourceType); PlatformRecommendation getRecommendationByCredentialCrn(Long workspaceId, String blueprintName, String credentialCrn,
            String region, String platformVariant, String availabilityZone, CdpResourceType cdpResourceType); AutoscaleRecommendation getAutoscaleRecommendation(Long workspaceId, String blueprintName); ScaleRecommendation getScaleRecommendation(Long workspaceId, String blueprintName); @Override Set<Blueprint> findAllByWorkspace(Workspace workspace); @Override Set<Blueprint> findAllByWorkspaceId(Long workspaceId); Set<BlueprintView> getAllAvailableViewInWorkspaceAndFilterBySdxReady(Long workspaceId, Boolean withSdx); Set<Blueprint> getAllAvailableInWorkspace(Workspace workspace); Blueprint getByNameForWorkspaceAndLoadDefaultsIfNecessary(String name, Workspace workspace); void updateDefaultBlueprintCollection(Long workspaceId); boolean isDatalakeBlueprint(Blueprint blueprint); boolean isClouderaManagerTemplate(Blueprint blueprint); String getBlueprintVariant(Blueprint blueprint); @Override Blueprint getByNameForWorkspace(String name, Workspace workspace); @Override Blueprint delete(Blueprint blueprint); @Override WorkspaceResourceRepository<Blueprint, Long> repository(); Map<String, String> queryCustomParametersMap(String name, Long workspaceId); Set<ConfigQueryEntry> queryFileSystemParameters(String blueprintName, String clusterName,
            String baseLocation, String fileSystemType, String accountName, boolean attachedCluster,
            boolean secure, Long workspaceId); @Override String getResourceCrnByResourceName(String resourceName); @Override List<String> getResourceCrnsInAccount(); @Override List<String> getResourceCrnListByResourceNameList(List<String> resourceNames); Blueprint getByResourceCrn(String resourceCrn); @Override AuthorizationResourceType getResourceType(); BlueprintStatusView getStatusViewByResourceCrn(String resourceCrn); }
BlueprintService extends AbstractWorkspaceAwareResourceService<Blueprint> implements ResourceBasedCrnProvider { public Blueprint getByNameForWorkspaceAndLoadDefaultsIfNecessary(String name, Workspace workspace) { Set<Blueprint> blueprints = blueprintRepository.findAllByNotDeletedInWorkspace(workspace.getId()); Optional<Blueprint> blueprint = filterBlueprintsByName(name, blueprints); if (blueprint.isPresent()) { return blueprint.get(); } else { Set<Blueprint> updatedDefaultBlueprints = updateDefaultBlueprintCollection(workspace); blueprint = filterBlueprintsByName(name, updatedDefaultBlueprints); if (blueprint.isPresent()) { return blueprint.get(); } } throw new NotFoundException(String.format("No cluster template found with name '%s'", name)); }  Blueprint get(Long id); Blueprint createForLoggedInUser(Blueprint blueprint, Long workspaceId, String accountId, String creator); Blueprint deleteByWorkspace(NameOrCrn nameOrCrn, Long workspaceId); Blueprint getByWorkspace(@NotNull NameOrCrn nameOrCrn, Long workspaceId); void decorateWithCrn(Blueprint bp, String accountId, String creator); PlatformRecommendation getRecommendation(Long workspaceId, String blueprintName, String credentialName,
            String region, String platformVariant, String availabilityZone, CdpResourceType cdpResourceType); PlatformRecommendation getRecommendationByCredentialCrn(Long workspaceId, String blueprintName, String credentialCrn,
            String region, String platformVariant, String availabilityZone, CdpResourceType cdpResourceType); AutoscaleRecommendation getAutoscaleRecommendation(Long workspaceId, String blueprintName); ScaleRecommendation getScaleRecommendation(Long workspaceId, String blueprintName); @Override Set<Blueprint> findAllByWorkspace(Workspace workspace); @Override Set<Blueprint> findAllByWorkspaceId(Long workspaceId); Set<BlueprintView> getAllAvailableViewInWorkspaceAndFilterBySdxReady(Long workspaceId, Boolean withSdx); Set<Blueprint> getAllAvailableInWorkspace(Workspace workspace); Blueprint getByNameForWorkspaceAndLoadDefaultsIfNecessary(String name, Workspace workspace); void updateDefaultBlueprintCollection(Long workspaceId); boolean isDatalakeBlueprint(Blueprint blueprint); boolean isClouderaManagerTemplate(Blueprint blueprint); String getBlueprintVariant(Blueprint blueprint); @Override Blueprint getByNameForWorkspace(String name, Workspace workspace); @Override Blueprint delete(Blueprint blueprint); @Override WorkspaceResourceRepository<Blueprint, Long> repository(); Map<String, String> queryCustomParametersMap(String name, Long workspaceId); Set<ConfigQueryEntry> queryFileSystemParameters(String blueprintName, String clusterName,
            String baseLocation, String fileSystemType, String accountName, boolean attachedCluster,
            boolean secure, Long workspaceId); @Override String getResourceCrnByResourceName(String resourceName); @Override List<String> getResourceCrnsInAccount(); @Override List<String> getResourceCrnListByResourceNameList(List<String> resourceNames); Blueprint getByResourceCrn(String resourceCrn); @Override AuthorizationResourceType getResourceType(); BlueprintStatusView getStatusViewByResourceCrn(String resourceCrn);  }