@Test public void setLocationByLocation() { RegionWrapper location = new RegionWrapper("r3", "Somewhere else", 1.2, 1.3, Collections.emptySet()); environmentServiceUnderTest.setLocation(environment, location, EnvironmentTestData.getCloudRegions()); assertEquals("Somewhere else", environment.getLocationDisplayName()); }
public void setLocation(Environment environment, RegionWrapper regionWrapper, CloudRegions cloudRegions) { if (regionWrapper != null) { LOGGER.debug("Setting location for environment. Location: '{}'.", regionWrapper); Optional<Entry<com.sequenceiq.cloudbreak.cloud.model.Region, Coordinate>> coordinate = cloudRegions.getCoordinates().entrySet() .stream() .filter(e -> e.getKey().getRegionName().equals(regionWrapper.getName()) || e.getValue().getDisplayName().equals(regionWrapper.getName()) || e.getValue().getKey().equals(regionWrapper.getName())) .findFirst(); if (coordinate.isPresent()) { environment.setLocation(coordinate.get().getValue().getKey()); environment.setLocationDisplayName(coordinate.get().getValue().getDisplayName()); environment.setLatitude(coordinate.get().getValue().getLatitude()); environment.setLongitude(coordinate.get().getValue().getLongitude()); } else if (regionWrapper.getLatitude() != null && regionWrapper.getLongitude() != null) { environment.setLocation(regionWrapper.getName()); environment.setLocationDisplayName(regionWrapper.getDisplayName()); environment.setLatitude(regionWrapper.getLatitude()); environment.setLongitude(regionWrapper.getLongitude()); } else { throw new BadRequestException(String.format("No location found with name %s in the location list. The supported locations are: [%s]", regionWrapper.getName(), cloudRegions.locationNames())); } } }
EnvironmentService extends AbstractAccountAwareResourceService<Environment> implements ResourceIdProvider, ResourceBasedCrnProvider { public void setLocation(Environment environment, RegionWrapper regionWrapper, CloudRegions cloudRegions) { if (regionWrapper != null) { LOGGER.debug("Setting location for environment. Location: '{}'.", regionWrapper); Optional<Entry<com.sequenceiq.cloudbreak.cloud.model.Region, Coordinate>> coordinate = cloudRegions.getCoordinates().entrySet() .stream() .filter(e -> e.getKey().getRegionName().equals(regionWrapper.getName()) || e.getValue().getDisplayName().equals(regionWrapper.getName()) || e.getValue().getKey().equals(regionWrapper.getName())) .findFirst(); if (coordinate.isPresent()) { environment.setLocation(coordinate.get().getValue().getKey()); environment.setLocationDisplayName(coordinate.get().getValue().getDisplayName()); environment.setLatitude(coordinate.get().getValue().getLatitude()); environment.setLongitude(coordinate.get().getValue().getLongitude()); } else if (regionWrapper.getLatitude() != null && regionWrapper.getLongitude() != null) { environment.setLocation(regionWrapper.getName()); environment.setLocationDisplayName(regionWrapper.getDisplayName()); environment.setLatitude(regionWrapper.getLatitude()); environment.setLongitude(regionWrapper.getLongitude()); } else { throw new BadRequestException(String.format("No location found with name %s in the location list. The supported locations are: [%s]", regionWrapper.getName(), cloudRegions.locationNames())); } } } }
EnvironmentService extends AbstractAccountAwareResourceService<Environment> implements ResourceIdProvider, ResourceBasedCrnProvider { public void setLocation(Environment environment, RegionWrapper regionWrapper, CloudRegions cloudRegions) { if (regionWrapper != null) { LOGGER.debug("Setting location for environment. Location: '{}'.", regionWrapper); Optional<Entry<com.sequenceiq.cloudbreak.cloud.model.Region, Coordinate>> coordinate = cloudRegions.getCoordinates().entrySet() .stream() .filter(e -> e.getKey().getRegionName().equals(regionWrapper.getName()) || e.getValue().getDisplayName().equals(regionWrapper.getName()) || e.getValue().getKey().equals(regionWrapper.getName())) .findFirst(); if (coordinate.isPresent()) { environment.setLocation(coordinate.get().getValue().getKey()); environment.setLocationDisplayName(coordinate.get().getValue().getDisplayName()); environment.setLatitude(coordinate.get().getValue().getLatitude()); environment.setLongitude(coordinate.get().getValue().getLongitude()); } else if (regionWrapper.getLatitude() != null && regionWrapper.getLongitude() != null) { environment.setLocation(regionWrapper.getName()); environment.setLocationDisplayName(regionWrapper.getDisplayName()); environment.setLatitude(regionWrapper.getLatitude()); environment.setLongitude(regionWrapper.getLongitude()); } else { throw new BadRequestException(String.format("No location found with name %s in the location list. The supported locations are: [%s]", regionWrapper.getName(), cloudRegions.locationNames())); } } } EnvironmentService(
            EnvironmentValidatorService validatorService,
            EnvironmentRepository environmentRepository,
            PlatformParameterService platformParameterService,
            EnvironmentDtoConverter environmentDtoConverter,
            DelegatingCliEnvironmentRequestConverter delegatingCliEnvironmentRequestConverter,
            GrpcUmsClient grpcUmsClient,
            TransactionService transactionService); }
EnvironmentService extends AbstractAccountAwareResourceService<Environment> implements ResourceIdProvider, ResourceBasedCrnProvider { public void setLocation(Environment environment, RegionWrapper regionWrapper, CloudRegions cloudRegions) { if (regionWrapper != null) { LOGGER.debug("Setting location for environment. Location: '{}'.", regionWrapper); Optional<Entry<com.sequenceiq.cloudbreak.cloud.model.Region, Coordinate>> coordinate = cloudRegions.getCoordinates().entrySet() .stream() .filter(e -> e.getKey().getRegionName().equals(regionWrapper.getName()) || e.getValue().getDisplayName().equals(regionWrapper.getName()) || e.getValue().getKey().equals(regionWrapper.getName())) .findFirst(); if (coordinate.isPresent()) { environment.setLocation(coordinate.get().getValue().getKey()); environment.setLocationDisplayName(coordinate.get().getValue().getDisplayName()); environment.setLatitude(coordinate.get().getValue().getLatitude()); environment.setLongitude(coordinate.get().getValue().getLongitude()); } else if (regionWrapper.getLatitude() != null && regionWrapper.getLongitude() != null) { environment.setLocation(regionWrapper.getName()); environment.setLocationDisplayName(regionWrapper.getDisplayName()); environment.setLatitude(regionWrapper.getLatitude()); environment.setLongitude(regionWrapper.getLongitude()); } else { throw new BadRequestException(String.format("No location found with name %s in the location list. The supported locations are: [%s]", regionWrapper.getName(), cloudRegions.locationNames())); } } } EnvironmentService(
            EnvironmentValidatorService validatorService,
            EnvironmentRepository environmentRepository,
            PlatformParameterService platformParameterService,
            EnvironmentDtoConverter environmentDtoConverter,
            DelegatingCliEnvironmentRequestConverter delegatingCliEnvironmentRequestConverter,
            GrpcUmsClient grpcUmsClient,
            TransactionService transactionService); Environment save(Environment environment); Environment saveWithOwnerRoleAssignment(Environment environment); EnvironmentDto getEnvironmentDto(Environment environment); EnvironmentDto getByNameAndAccountId(String environmentName, String accountId); EnvironmentDto getByCrnAndAccountId(String crn, String accountId); List<EnvironmentDto> listByAccountId(String accountId); void setRegions(Environment environment, Set<String> requestedRegions, CloudRegions cloudRegions); CloudRegions getRegionsByEnvironment(Environment environment); Environment findEnvironmentByIdOrThrow(Long id); Optional<Environment> findEnvironmentById(Long id); Optional<EnvironmentDto> findById(Long id); void setLocation(Environment environment, RegionWrapper regionWrapper, CloudRegions cloudRegions); List<EnvironmentDto> findAllByIdInAndStatusIn(Collection<Long> resourceIds, Collection<EnvironmentStatus> environmentStatuses); List<EnvironmentDto> findAllByStatusIn(Collection<EnvironmentStatus> environmentStatuses); Object getCreateEnvironmentForCli(EnvironmentRequest environmentRequest, String cloudPlatform); Object getCreateEnvironmentForCli(EnvironmentDto environmentDto); void setAdminGroupName(Environment environment, String adminGroupName); Collection<Environment> findByResourceCrnInAndAccountIdAndArchivedIsFalse(Collection<String> crns, String accountId); Collection<Environment> findByNameInAndAccountIdAndArchivedIsFalse(Collection<String> environmentNames, String accountId); String getCrnByNameAndAccountId(String environmentName, String accountId); @Override Long getResourceIdByResourceCrn(String resourceCrn); @Override Long getResourceIdByResourceName(String resourceName); @Override String getResourceCrnByResourceName(String resourceName); @Override List<String> getResourceCrnListByResourceNameList(List<String> resourceNames); @Override List<String> getResourceCrnsInAccount(); @Override AuthorizationResourceType getResourceType(); List<String> findNameWithAccountIdAndParentEnvIdAndArchivedIsFalse(String accountId, Long parentEnvironmentId); List<Environment> findAllByAccountIdAndParentEnvIdAndArchivedIsFalse(String accountId, Long parentEnvironmentId); void assignEnvironmentAdminRole(String userCrn, String environmentCrn); List<Environment> findAllForAutoSync(); }
EnvironmentService extends AbstractAccountAwareResourceService<Environment> implements ResourceIdProvider, ResourceBasedCrnProvider { public void setLocation(Environment environment, RegionWrapper regionWrapper, CloudRegions cloudRegions) { if (regionWrapper != null) { LOGGER.debug("Setting location for environment. Location: '{}'.", regionWrapper); Optional<Entry<com.sequenceiq.cloudbreak.cloud.model.Region, Coordinate>> coordinate = cloudRegions.getCoordinates().entrySet() .stream() .filter(e -> e.getKey().getRegionName().equals(regionWrapper.getName()) || e.getValue().getDisplayName().equals(regionWrapper.getName()) || e.getValue().getKey().equals(regionWrapper.getName())) .findFirst(); if (coordinate.isPresent()) { environment.setLocation(coordinate.get().getValue().getKey()); environment.setLocationDisplayName(coordinate.get().getValue().getDisplayName()); environment.setLatitude(coordinate.get().getValue().getLatitude()); environment.setLongitude(coordinate.get().getValue().getLongitude()); } else if (regionWrapper.getLatitude() != null && regionWrapper.getLongitude() != null) { environment.setLocation(regionWrapper.getName()); environment.setLocationDisplayName(regionWrapper.getDisplayName()); environment.setLatitude(regionWrapper.getLatitude()); environment.setLongitude(regionWrapper.getLongitude()); } else { throw new BadRequestException(String.format("No location found with name %s in the location list. The supported locations are: [%s]", regionWrapper.getName(), cloudRegions.locationNames())); } } } EnvironmentService(
            EnvironmentValidatorService validatorService,
            EnvironmentRepository environmentRepository,
            PlatformParameterService platformParameterService,
            EnvironmentDtoConverter environmentDtoConverter,
            DelegatingCliEnvironmentRequestConverter delegatingCliEnvironmentRequestConverter,
            GrpcUmsClient grpcUmsClient,
            TransactionService transactionService); Environment save(Environment environment); Environment saveWithOwnerRoleAssignment(Environment environment); EnvironmentDto getEnvironmentDto(Environment environment); EnvironmentDto getByNameAndAccountId(String environmentName, String accountId); EnvironmentDto getByCrnAndAccountId(String crn, String accountId); List<EnvironmentDto> listByAccountId(String accountId); void setRegions(Environment environment, Set<String> requestedRegions, CloudRegions cloudRegions); CloudRegions getRegionsByEnvironment(Environment environment); Environment findEnvironmentByIdOrThrow(Long id); Optional<Environment> findEnvironmentById(Long id); Optional<EnvironmentDto> findById(Long id); void setLocation(Environment environment, RegionWrapper regionWrapper, CloudRegions cloudRegions); List<EnvironmentDto> findAllByIdInAndStatusIn(Collection<Long> resourceIds, Collection<EnvironmentStatus> environmentStatuses); List<EnvironmentDto> findAllByStatusIn(Collection<EnvironmentStatus> environmentStatuses); Object getCreateEnvironmentForCli(EnvironmentRequest environmentRequest, String cloudPlatform); Object getCreateEnvironmentForCli(EnvironmentDto environmentDto); void setAdminGroupName(Environment environment, String adminGroupName); Collection<Environment> findByResourceCrnInAndAccountIdAndArchivedIsFalse(Collection<String> crns, String accountId); Collection<Environment> findByNameInAndAccountIdAndArchivedIsFalse(Collection<String> environmentNames, String accountId); String getCrnByNameAndAccountId(String environmentName, String accountId); @Override Long getResourceIdByResourceCrn(String resourceCrn); @Override Long getResourceIdByResourceName(String resourceName); @Override String getResourceCrnByResourceName(String resourceName); @Override List<String> getResourceCrnListByResourceNameList(List<String> resourceNames); @Override List<String> getResourceCrnsInAccount(); @Override AuthorizationResourceType getResourceType(); List<String> findNameWithAccountIdAndParentEnvIdAndArchivedIsFalse(String accountId, Long parentEnvironmentId); List<Environment> findAllByAccountIdAndParentEnvIdAndArchivedIsFalse(String accountId, Long parentEnvironmentId); void assignEnvironmentAdminRole(String userCrn, String environmentCrn); List<Environment> findAllForAutoSync();  }