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);
}
}
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;
}
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);
}
}
Aggregations