use of io.gravitee.rest.api.model.UpdateTenantEntity in project gravitee-management-rest-api by gravitee-io.
the class TenantServiceImpl method update.
@Override
public List<TenantEntity> update(final List<UpdateTenantEntity> tenantEntities, String referenceId, TenantReferenceType referenceType) {
final List<TenantEntity> savedTenants = new ArrayList<>(tenantEntities.size());
tenantEntities.forEach(tenantEntity -> {
try {
Tenant tenant = convert(tenantEntity);
Optional<Tenant> tenantOptional = tenantRepository.findByIdAndReference(tenant.getId(), referenceId, repoTenantReferenceType(referenceType));
if (tenantOptional.isPresent()) {
Tenant existingTenant = tenantOptional.get();
tenant.setReferenceId(existingTenant.getReferenceId());
tenant.setReferenceType(existingTenant.getReferenceType());
savedTenants.add(convert(tenantRepository.update(tenant)));
auditService.createEnvironmentAuditLog(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;
}
Aggregations