Search in sources :

Example 46 with TechnicalManagementException

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

the class ApiKeyServiceImpl method findBySubscription.

@Override
public Set<ApiKeyEntity> findBySubscription(String subscription) {
    try {
        LOGGER.debug("Find API Keys for subscription {}", subscription);
        SubscriptionEntity subscriptionEntity = subscriptionService.findById(subscription);
        Set<ApiKey> keys = apiKeyRepository.findBySubscription(subscriptionEntity.getId());
        return keys.stream().map(ApiKeyServiceImpl::convert).collect(Collectors.toSet());
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while finding API keys for subscription {}", subscription, ex);
        throw new TechnicalManagementException(String.format("An error occurs while finding API keys for subscription %s", subscription), ex);
    }
}
Also used : ApiKey(io.gravitee.repository.management.model.ApiKey) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 47 with TechnicalManagementException

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

the class ApiKeyServiceImpl method findByKey.

@Override
public ApiKeyEntity findByKey(String apiKey) {
    try {
        LOGGER.debug("Find an API Key by key: {}", apiKey);
        Optional<ApiKey> optApiKey = apiKeyRepository.findById(apiKey);
        if (optApiKey.isPresent()) {
            return convert(optApiKey.get());
        }
        throw new ApiKeyNotFoundException();
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to find an API Key by key {}", apiKey, ex);
        throw new TechnicalManagementException(String.format("An error occurs while trying to find an API Key by key: %s", apiKey), ex);
    }
}
Also used : ApiKey(io.gravitee.repository.management.model.ApiKey) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) ApiKeyNotFoundException(io.gravitee.management.service.exceptions.ApiKeyNotFoundException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 48 with TechnicalManagementException

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

the class PageServiceImpl method createPortalPage.

@Override
public PageEntity createPortalPage(NewPageEntity newPageEntity) {
    try {
        logger.debug("Create portal page {}", newPageEntity);
        String id = UUID.toString(UUID.random());
        Optional<Page> checkPage = pageRepository.findById(id);
        if (checkPage.isPresent()) {
            throw new PageAlreadyExistsException(id);
        }
        Page page = convert(newPageEntity);
        if (page.getSource() != null) {
            String fetchedContent = this.getContentFromFetcher(page.getSource());
            if (fetchedContent != null && !fetchedContent.isEmpty()) {
                page.setContent(fetchedContent);
            }
        }
        page.setId(id);
        // Set date fields
        page.setCreatedAt(new Date());
        page.setUpdatedAt(page.getCreatedAt());
        Page createdPage = pageRepository.create(page);
        // only one homepage is allowed
        onlyOneHomepage(page);
        createAuditLog(null, PAGE_CREATED, page.getCreatedAt(), null, page);
        return convert(createdPage);
    } catch (TechnicalException | FetcherException ex) {
        logger.error("An error occurs while trying to create {}", newPageEntity, ex);
        throw new TechnicalManagementException("An error occurs while trying create " + newPageEntity, ex);
    }
}
Also used : PageAlreadyExistsException(io.gravitee.management.service.exceptions.PageAlreadyExistsException) FetcherException(io.gravitee.fetcher.api.FetcherException) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 49 with TechnicalManagementException

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

the class ParameterServiceImpl method update.

@Override
public Parameter update(final String key, final String value) {
    try {
        final Optional<Parameter> optionalParameter = parameterRepository.findById(key);
        if (!optionalParameter.isPresent()) {
            throw new ParameterNotFoundException(key);
        }
        final Parameter parameter = new Parameter();
        parameter.setKey(key);
        parameter.setValue(value);
        final Parameter updatedParameter = parameterRepository.update(parameter);
        auditService.createPortalAuditLog(singletonMap(PARAMETER, updatedParameter.getKey()), PARAMETER_UPDATED, new Date(), optionalParameter.get(), updatedParameter);
        return updatedParameter;
    } catch (final TechnicalException ex) {
        final String message = "An error occurs while trying to update parameter for key/value: " + key + '/' + value;
        LOGGER.error(message, ex);
        throw new TechnicalManagementException(message, ex);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Parameter(io.gravitee.repository.management.model.Parameter) ParameterNotFoundException(io.gravitee.management.service.exceptions.ParameterNotFoundException) Date(java.util.Date) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 50 with TechnicalManagementException

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

the class ParameterServiceImpl method create.

@Override
public Parameter create(final String key, final String value) {
    try {
        final Optional<Parameter> optionalParameter = parameterRepository.findById(key);
        if (optionalParameter.isPresent()) {
            throw new ParameterAlreadyExistsException(key);
        }
        final Parameter parameter = new Parameter();
        parameter.setKey(key);
        parameter.setValue(value);
        final Parameter savedParameter = parameterRepository.create(parameter);
        auditService.createPortalAuditLog(singletonMap(PARAMETER, savedParameter.getKey()), PARAMETER_CREATED, new Date(), null, savedParameter);
        return savedParameter;
    } catch (final TechnicalException ex) {
        final String message = "An error occurs while trying to create parameter for key/value: " + key + '/' + value;
        LOGGER.error(message, ex);
        throw new TechnicalManagementException(message, ex);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Parameter(io.gravitee.repository.management.model.Parameter) ParameterAlreadyExistsException(io.gravitee.management.service.exceptions.ParameterAlreadyExistsException) Date(java.util.Date) 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