Search in sources :

Example 6 with Environment

use of io.gravitee.repository.management.model.Environment in project gravitee-management-rest-api by gravitee-io.

the class EnvironmentServiceImpl method findById.

@Override
public EnvironmentEntity findById(String environmentId) {
    try {
        LOGGER.debug("Find environment by ID: {}", environmentId);
        Optional<Environment> optEnvironment = environmentRepository.findById(environmentId);
        if (!optEnvironment.isPresent()) {
            throw new EnvironmentNotFoundException(environmentId);
        }
        return convert(optEnvironment.get());
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to find environment by ID", ex);
        throw new TechnicalManagementException("An error occurs while trying to find environment by ID", ex);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) EnvironmentNotFoundException(io.gravitee.rest.api.service.exceptions.EnvironmentNotFoundException) Environment(io.gravitee.repository.management.model.Environment) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 7 with Environment

use of io.gravitee.repository.management.model.Environment in project gravitee-management-rest-api by gravitee-io.

the class EnvironmentServiceImpl method convert.

private Environment convert(final UpdateEnvironmentEntity environmentEntity) {
    final Environment environment = new Environment();
    environment.setCockpitId(environmentEntity.getCockpitId());
    environment.setHrids(environmentEntity.getHrids());
    environment.setName(environmentEntity.getName());
    environment.setDescription(environmentEntity.getDescription());
    environment.setDomainRestrictions(environmentEntity.getDomainRestrictions());
    return environment;
}
Also used : Environment(io.gravitee.repository.management.model.Environment)

Example 8 with Environment

use of io.gravitee.repository.management.model.Environment in project gravitee-management-rest-api by gravitee-io.

the class EnvironmentServiceImpl method findByUserAndIdOrHrid.

@Override
public List<EnvironmentEntity> findByUserAndIdOrHrid(String userId, String idOrHrid) {
    try {
        LOGGER.debug("Find all environments by user");
        Stream<Environment> envStream = environmentRepository.findByOrganization(GraviteeContext.getCurrentOrganization()).stream();
        if (userId != null) {
            final List<String> stringStream = membershipService.getMembershipsByMemberAndReference(MembershipMemberType.USER, userId, MembershipReferenceType.ENVIRONMENT).stream().map(MembershipEntity::getReferenceId).collect(Collectors.toList());
            envStream = envStream.filter(env -> stringStream.contains(env.getId()));
        }
        if (!StringUtils.isEmpty(idOrHrid)) {
            envStream = envStream.filter(env -> idOrHrid.equals(env.getId()) || !CollectionUtils.isEmpty(env.getHrids()) && env.getHrids().contains(idOrHrid));
        }
        return envStream.map(this::convert).collect(Collectors.toList());
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to find all environments", ex);
        throw new TechnicalManagementException("An error occurs while trying to find all environments", ex);
    }
}
Also used : io.gravitee.rest.api.service(io.gravitee.rest.api.service) Logger(org.slf4j.Logger) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) GraviteeContext(io.gravitee.rest.api.service.common.GraviteeContext) Collectors(java.util.stream.Collectors) EnvironmentRepository(io.gravitee.repository.management.api.EnvironmentRepository) List(java.util.List) Component(org.springframework.stereotype.Component) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) Stream(java.util.stream.Stream) CollectionUtils(org.springframework.util.CollectionUtils) Environment(io.gravitee.repository.management.model.Environment) EnvironmentNotFoundException(io.gravitee.rest.api.service.exceptions.EnvironmentNotFoundException) io.gravitee.rest.api.model(io.gravitee.rest.api.model) Optional(java.util.Optional) StringUtils(org.springframework.util.StringUtils) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Environment(io.gravitee.repository.management.model.Environment) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Aggregations

Environment (io.gravitee.repository.management.model.Environment)8 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)6 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)4 EnvironmentRepository (io.gravitee.repository.management.api.EnvironmentRepository)3 List (java.util.List)3 Optional (java.util.Optional)3 EnvironmentEntity (io.gravitee.rest.api.model.EnvironmentEntity)2 UpdateEnvironmentEntity (io.gravitee.rest.api.model.UpdateEnvironmentEntity)2 BadOrganizationException (io.gravitee.rest.api.service.exceptions.BadOrganizationException)2 EnvironmentNotFoundException (io.gravitee.rest.api.service.exceptions.EnvironmentNotFoundException)2 OrganizationNotFoundException (io.gravitee.rest.api.service.exceptions.OrganizationNotFoundException)2 EnvironmentServiceImpl (io.gravitee.rest.api.service.impl.EnvironmentServiceImpl)2 Arrays (java.util.Arrays)2 Assert.assertNotNull (org.junit.Assert.assertNotNull)2 Test (org.junit.Test)2 RunWith (org.junit.runner.RunWith)2 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)2 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)2 InjectMocks (org.mockito.InjectMocks)2 Mock (org.mockito.Mock)2