use of io.gravitee.repository.management.model.Tenant in project gravitee-management-rest-api by gravitee-io.
the class TenantServiceImpl method convert.
private Tenant convert(final UpdateTenantEntity tenantEntity) {
final Tenant tenant = new Tenant();
tenant.setId(tenantEntity.getId());
tenant.setName(tenantEntity.getName());
tenant.setDescription(tenantEntity.getDescription());
return tenant;
}
use of io.gravitee.repository.management.model.Tenant in project gravitee-management-rest-api by gravitee-io.
the class TenantServiceImpl method create.
@Override
public List<TenantEntity> create(final List<NewTenantEntity> tenantEntities) {
// First we prevent the duplicate tenant name
final List<String> tenantNames = tenantEntities.stream().map(NewTenantEntity::getName).collect(Collectors.toList());
final Optional<TenantEntity> optionalTenant = findAll().stream().filter(tenant -> tenantNames.contains(tenant.getName())).findAny();
if (optionalTenant.isPresent()) {
throw new DuplicateTenantNameException(optionalTenant.get().getName());
}
final List<TenantEntity> savedTenants = new ArrayList<>(tenantEntities.size());
tenantEntities.forEach(tenantEntity -> {
try {
Tenant tenant = convert(tenantEntity);
savedTenants.add(convert(tenantRepository.create(tenant)));
auditService.createPortalAuditLog(Collections.singletonMap(TENANT, tenant.getId()), TENANT_CREATED, new Date(), null, tenant);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to create tenant {}", tenantEntity.getName(), ex);
throw new TechnicalManagementException("An error occurs while trying to create tenant " + tenantEntity.getName(), ex);
}
});
return savedTenants;
}
use of io.gravitee.repository.management.model.Tenant in project gravitee-management-rest-api by gravitee-io.
the class TenantServiceImpl method convert.
private Tenant convert(final NewTenantEntity tenantEntity) {
final Tenant tenant = new Tenant();
tenant.setId(IdGenerator.generate(tenantEntity.getName()));
tenant.setName(tenantEntity.getName());
tenant.setDescription(tenantEntity.getDescription());
return tenant;
}
use of io.gravitee.repository.management.model.Tenant in project gravitee-management-rest-api by gravitee-io.
the class TenantServiceImpl method update.
@Override
public List<TenantEntity> update(final List<UpdateTenantEntity> tenantEntities) {
final List<TenantEntity> savedTenants = new ArrayList<>(tenantEntities.size());
tenantEntities.forEach(tenantEntity -> {
try {
Tenant tenant = convert(tenantEntity);
Optional<Tenant> tenantOptional = tenantRepository.findById(tenant.getId());
if (tenantOptional.isPresent()) {
savedTenants.add(convert(tenantRepository.update(tenant)));
auditService.createPortalAuditLog(Collections.singletonMap(TENANT, tenant.getId()), TENANT_UPDATED, new Date(), tenantOptional.get(), tenant);
}
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to update tenant {}", tenantEntity.getName(), ex);
throw new TechnicalManagementException("An error occurs while trying to update tenant " + tenantEntity.getName(), ex);
}
});
return savedTenants;
}
use of io.gravitee.repository.management.model.Tenant in project gravitee-management-rest-api by gravitee-io.
the class TenantServiceImpl method findById.
@Override
public TenantEntity findById(String tenantId) {
try {
LOGGER.debug("Find tenant by ID: {}", tenantId);
Optional<Tenant> optTenant = tenantRepository.findById(tenantId);
if (!optTenant.isPresent()) {
throw new TenantNotFoundException(tenantId);
}
return convert(optTenant.get());
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to find tenant by ID", ex);
throw new TechnicalManagementException("An error occurs while trying to find tenant by ID", ex);
}
}
Aggregations