Search in sources :

Example 81 with TechnicalManagementException

use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.

the class TagServiceImpl method update.

@Override
public List<TagEntity> update(final List<UpdateTagEntity> tagEntities) {
    final List<TagEntity> savedTags = new ArrayList<>(tagEntities.size());
    tagEntities.forEach(tagEntity -> {
        try {
            Tag tag = convert(tagEntity);
            Optional<Tag> tagOptional = tagRepository.findById(tag.getId());
            if (tagOptional.isPresent()) {
                savedTags.add(convert(tagRepository.update(tag)));
                auditService.createPortalAuditLog(Collections.singletonMap(TAG, tag.getId()), TAG_UPDATED, new Date(), tagOptional.get(), tag);
            }
        } catch (TechnicalException ex) {
            LOGGER.error("An error occurs while trying to update tag {}", tagEntity.getName(), ex);
            throw new TechnicalManagementException("An error occurs while trying to update tag " + tagEntity.getName(), ex);
        }
    });
    return savedTags;
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) NewTagEntity(io.gravitee.management.model.NewTagEntity) TagEntity(io.gravitee.management.model.TagEntity) UpdateTagEntity(io.gravitee.management.model.UpdateTagEntity) Tag(io.gravitee.repository.management.model.Tag) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 82 with TechnicalManagementException

use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.

the class TaskServiceImpl method convert.

private TaskEntity convert(SubscriptionEntity subscription) {
    TaskEntity taskEntity = new TaskEntity();
    try {
        taskEntity.setType(TaskType.SUBSCRIPTION_APPROVAL);
        taskEntity.setCreatedAt(subscription.getCreatedAt());
        taskEntity.setData(subscription);
    } catch (Exception e) {
        LOGGER.error("Error converting subscription {} to a Task", subscription.getId());
        throw new TechnicalManagementException("Error converting subscription " + subscription.getId() + " to a Task", e);
    }
    return taskEntity;
}
Also used : UnauthorizedAccessException(io.gravitee.management.service.exceptions.UnauthorizedAccessException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 83 with TechnicalManagementException

use of io.gravitee.management.service.exceptions.TechnicalManagementException 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;
}
Also used : Tenant(io.gravitee.repository.management.model.Tenant) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) TenantEntity(io.gravitee.management.model.TenantEntity) NewTenantEntity(io.gravitee.management.model.NewTenantEntity) UpdateTenantEntity(io.gravitee.management.model.UpdateTenantEntity) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 84 with TechnicalManagementException

use of io.gravitee.management.service.exceptions.TechnicalManagementException 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);
    }
}
Also used : Tenant(io.gravitee.repository.management.model.Tenant) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) TenantNotFoundException(io.gravitee.management.service.exceptions.TenantNotFoundException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 85 with TechnicalManagementException

use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.

the class TenantServiceImpl method delete.

@Override
public void delete(final String tenantId) {
    try {
        Optional<Tenant> tenantOptional = tenantRepository.findById(tenantId);
        if (tenantOptional.isPresent()) {
            tenantRepository.delete(tenantId);
            auditService.createPortalAuditLog(Collections.singletonMap(TENANT, tenantId), TENANT_DELETED, new Date(), null, tenantOptional.get());
            tenantRepository.delete(tenantId);
        }
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to delete tenant {}", tenantId, ex);
        throw new TechnicalManagementException("An error occurs while trying to delete tenant " + tenantId, ex);
    }
}
Also used : Tenant(io.gravitee.repository.management.model.Tenant) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Aggregations

TechnicalManagementException (io.gravitee.management.service.exceptions.TechnicalManagementException)90 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)83 Logger (org.slf4j.Logger)17 LoggerFactory (org.slf4j.LoggerFactory)17 Autowired (org.springframework.beans.factory.annotation.Autowired)17 Component (org.springframework.stereotype.Component)17 Collectors (java.util.stream.Collectors)13 java.util (java.util)11 Date (java.util.Date)11 AuditService (io.gravitee.management.service.AuditService)10 IdGenerator (io.gravitee.common.utils.IdGenerator)9 io.gravitee.management.model (io.gravitee.management.model)9 User (io.gravitee.repository.management.model.User)9 ApiRatingUnavailableException (io.gravitee.management.service.exceptions.ApiRatingUnavailableException)8 UserNotFoundException (io.gravitee.management.service.exceptions.UserNotFoundException)8 Metadata (io.gravitee.repository.management.model.Metadata)8 Rating (io.gravitee.repository.management.model.Rating)8 DuplicateMetadataNameException (io.gravitee.management.service.exceptions.DuplicateMetadataNameException)7 ApiService (io.gravitee.management.service.ApiService)6 MetadataService (io.gravitee.management.service.MetadataService)6