use of io.gravitee.management.model.TenantEntity in project gravitee-management-rest-api by gravitee-io.
the class TenantServiceImpl method convert.
private TenantEntity convert(final Tenant tenant) {
final TenantEntity tenantEntity = new TenantEntity();
tenantEntity.setId(tenant.getId());
tenantEntity.setName(tenant.getName());
tenantEntity.setDescription(tenant.getDescription());
return tenantEntity;
}
use of io.gravitee.management.model.TenantEntity 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.management.model.TenantEntity in project gravitee-management-rest-api by gravitee-io.
the class AnalyticsServiceImpl method getTenantMetadata.
private Map<String, String> getTenantMetadata(String tenant) {
Map<String, String> metadata = new HashMap<>();
try {
TenantEntity tenantEntity = tenantService.findById(tenant);
metadata.put("name", tenantEntity.getName());
} catch (TenantNotFoundException tnfe) {
metadata.put("deleted", "true");
}
return metadata;
}
use of io.gravitee.management.model.TenantEntity 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;
}
Aggregations