Search in sources :

Example 76 with TechnicalManagementException

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

the class LogsServiceImpl method findByApi.

@Override
public SearchLogResponse findByApi(String api, LogQuery query) {
    try {
        TabularResponse response = logRepository.query(QueryBuilders.tabular().page(query.getPage()).size(query.getSize()).query(query.getQuery()).timeRange(DateRangeBuilder.between(query.getFrom(), query.getTo()), IntervalBuilder.interval(query.getInterval())).root("api", api).build());
        SearchLogResponse<ApiRequestItem> logResponse = new SearchLogResponse<>(response.getSize());
        // Transform repository logs
        logResponse.setLogs(response.getLogs().stream().map(this::toApiRequestItem).collect(Collectors.toList()));
        // Add metadata (only if they are results)
        if (response.getSize() > 0) {
            Map<String, Map<String, String>> metadata = new HashMap<>();
            logResponse.getLogs().forEach(logItem -> {
                String application = logItem.getApplication();
                String plan = logItem.getPlan();
                if (application != null) {
                    metadata.computeIfAbsent(application, getApplicationMetadata(application));
                }
                if (plan != null) {
                    metadata.computeIfAbsent(plan, getPlanMetadata(plan));
                }
            });
            logResponse.setMetadata(metadata);
        }
        return logResponse;
    } catch (AnalyticsException ae) {
        logger.error("Unable to retrieve logs: ", ae);
        throw new TechnicalManagementException("Unable to retrieve logs", ae);
    }
}
Also used : TabularResponse(io.gravitee.repository.analytics.query.tabular.TabularResponse) HashMap(java.util.HashMap) AnalyticsException(io.gravitee.repository.analytics.AnalyticsException) HashMap(java.util.HashMap) Map(java.util.Map) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 77 with TechnicalManagementException

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

the class MetadataServiceImpl method findDefaultByKey.

@Override
public MetadataEntity findDefaultByKey(final String key) {
    try {
        LOGGER.debug("Find default metadata by key");
        final Optional<Metadata> optMetadata = metadataRepository.findById(key, DEFAUT_REFERENCE_ID, MetadataReferenceType.DEFAULT);
        if (optMetadata.isPresent()) {
            return convert(optMetadata.get());
        } else {
            return null;
        }
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurred while trying to find default metadata by key", ex);
        throw new TechnicalManagementException("An error occurred while trying to find default metadata by key", ex);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Metadata(io.gravitee.repository.management.model.Metadata) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 78 with TechnicalManagementException

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

the class PageServiceImpl method findMaxPortalPageOrder.

@Override
public int findMaxPortalPageOrder() {
    try {
        logger.debug("Find Max Order Portal Page");
        final Integer maxPageOrder = pageRepository.findMaxPortalPageOrder();
        return maxPageOrder == null ? 0 : maxPageOrder;
    } catch (TechnicalException ex) {
        logger.error("An error occured when searching max order portal page", ex);
        throw new TechnicalManagementException("An error occured when searching max order portal ", ex);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 79 with TechnicalManagementException

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

the class PageServiceImpl method findMaxApiPageOrderByApi.

@Override
public int findMaxApiPageOrderByApi(String apiName) {
    try {
        logger.debug("Find Max Order Page for api name : {}", apiName);
        final Integer maxPageOrder = pageRepository.findMaxApiPageOrderByApiId(apiName);
        return maxPageOrder == null ? 0 : maxPageOrder;
    } catch (TechnicalException ex) {
        logger.error("An error occured when searching max order page for api name [{}]", apiName, ex);
        throw new TechnicalManagementException("An error occured when searching max order page for api name " + apiName, ex);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 80 with TechnicalManagementException

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

the class TagServiceImpl method delete.

@Override
public void delete(final String tagId) {
    try {
        Optional<Tag> tagOptional = tagRepository.findById(tagId);
        if (tagOptional.isPresent()) {
            tagRepository.delete(tagId);
            // delete all reference on APIs
            apiService.deleteTagFromAPIs(tagId);
            auditService.createPortalAuditLog(Collections.singletonMap(TAG, tagId), TAG_DELETED, new Date(), null, tagOptional.get());
        }
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to delete tag {}", tagId, ex);
        throw new TechnicalManagementException("An error occurs while trying to delete tag " + tagId, ex);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Tag(io.gravitee.repository.management.model.Tag) 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