Search in sources :

Example 66 with TechnicalManagementException

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

the class PageRevisionServiceImpl method create.

@Override
public PageRevisionEntity create(Page page) {
    try {
        logger.debug("Create page revision for page {}", page.getId());
        PageType type = PageType.valueOf(page.getType());
        if (!(type == PageType.MARKDOWN || type == PageType.SWAGGER || type == PageType.TRANSLATION)) {
            throw new TechnicalManagementException("Invalid page type for revision");
        }
        PageRevision revision = pageRevisionRepository.create(convert(page));
        return convert(revision);
    } catch (TechnicalException e) {
        logger.warn("An error occurs while trying to create a revision for page {}", page.getId(), e);
        throw new TechnicalManagementException("An error occurs while trying to create a page revision", e);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) PageRevision(io.gravitee.repository.management.model.PageRevision) PageType(io.gravitee.rest.api.model.PageType) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 67 with TechnicalManagementException

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

the class PageRevisionServiceImpl method findAll.

@Override
public io.gravitee.common.data.domain.Page<PageRevisionEntity> findAll(Pageable pageable) {
    logger.debug("get all page revisions with pageable {}", pageable);
    try {
        io.gravitee.common.data.domain.Page<PageRevision> revisions = pageRevisionRepository.findAll(pageable);
        List<PageRevisionEntity> revisionEntities = revisions.getContent().stream().map(this::convert).collect(Collectors.toList());
        return new io.gravitee.common.data.domain.Page<PageRevisionEntity>(revisionEntities, revisions.getPageNumber(), revisionEntities.size(), revisions.getTotalElements());
    } catch (TechnicalException e) {
        logger.warn("An error occurs while trying to get the page revisions {}", pageable, e);
        throw new TechnicalManagementException("An error occurs while trying to get all page revisions", e);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Page(io.gravitee.repository.management.model.Page) PageRevision(io.gravitee.repository.management.model.PageRevision) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) PageRevisionEntity(io.gravitee.rest.api.model.PageRevisionEntity)

Example 68 with TechnicalManagementException

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

the class ParameterServiceImpl method findAll.

@Override
public <T> List<T> findAll(final Key key, final Function<String, T> mapper, final Predicate<String> filter, final String referenceId, final io.gravitee.rest.api.model.parameters.ParameterReferenceType referenceType) {
    String refIdToUse = getEffectiveReferenceId(referenceId, referenceType);
    try {
        Optional<Parameter> optionalParameter = this.getSystemParameter(key);
        if (optionalParameter.isPresent()) {
            return splitValue(optionalParameter.get().getValue(), mapper, filter);
        }
        switch(referenceType) {
            case ENVIRONMENT:
                optionalParameter = this.getEnvParameter(key, refIdToUse);
                if (optionalParameter.isPresent()) {
                    return splitValue(optionalParameter.get().getValue(), mapper, filter);
                }
                // String organizationId = "DEFAULT";
                String organizationId = environmentService.findById(refIdToUse).getOrganizationId();
                optionalParameter = this.getOrgParameter(key, organizationId);
                if (optionalParameter.isPresent()) {
                    return splitValue(optionalParameter.get().getValue(), mapper, filter);
                }
            case ORGANIZATION:
                optionalParameter = this.getOrgParameter(key, refIdToUse);
                if (optionalParameter.isPresent()) {
                    return splitValue(optionalParameter.get().getValue(), mapper, filter);
                }
        }
        return splitValue(this.getDefaultParameterValue(key), mapper, filter);
    } catch (final TechnicalException ex) {
        final String message = "An error occurs while trying to find parameter values with key: " + key;
        LOGGER.error(message, ex);
        throw new TechnicalManagementException(message, ex);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Parameter(io.gravitee.repository.management.model.Parameter) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 69 with TechnicalManagementException

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

the class ParameterServiceImpl method save.

@Override
public Parameter save(final Key key, final String value, final String referenceId, final io.gravitee.rest.api.model.parameters.ParameterReferenceType referenceType) {
    String refIdToUse = getEffectiveReferenceId(referenceId, referenceType);
    try {
        Optional<Parameter> optionalParameter = parameterRepository.findById(key.key(), refIdToUse, ParameterReferenceType.valueOf(referenceType.name()));
        final boolean updateMode = optionalParameter.isPresent();
        final Parameter parameter = new Parameter();
        parameter.setKey(key.key());
        parameter.setReferenceId(refIdToUse);
        parameter.setReferenceType(ParameterReferenceType.valueOf(referenceType.name()));
        parameter.setValue(value);
        if (environment.containsProperty(key.key()) && key.isOverridable()) {
            parameter.setValue(toSemicolonSeparatedString(key, environment.getProperty(key.key())));
            return parameter;
        }
        if (updateMode) {
            if (value == null) {
                parameterRepository.delete(key.key(), refIdToUse, ParameterReferenceType.valueOf(referenceType.name()));
                return null;
            } else if (!value.equals(optionalParameter.get().getValue())) {
                final Parameter updatedParameter = parameterRepository.update(parameter);
                auditService.createEnvironmentAuditLog(singletonMap(PARAMETER, updatedParameter.getKey()), PARAMETER_UPDATED, new Date(), optionalParameter.get(), updatedParameter);
                eventManager.publishEvent(key, parameter);
                return updatedParameter;
            } else {
                return optionalParameter.get();
            }
        } else {
            if (value == null) {
                return null;
            }
            final Parameter savedParameter = parameterRepository.create(parameter);
            auditService.createEnvironmentAuditLog(singletonMap(PARAMETER, savedParameter.getKey()), PARAMETER_CREATED, new Date(), null, savedParameter);
            eventManager.publishEvent(key, parameter);
            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) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 70 with TechnicalManagementException

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

the class ParameterServiceImpl method findAll.

@Override
public <T> Map<String, List<T>> findAll(List<Key> keys, Function<String, T> mapper, Predicate<String> filter, final String referenceId, final io.gravitee.rest.api.model.parameters.ParameterReferenceType referenceType) {
    String refIdToUse = getEffectiveReferenceId(referenceId, referenceType);
    try {
        List<Key> keysToFind = new ArrayList<>(keys);
        Map<String, List<T>> result = new HashMap<>();
        // Get System parameters
        for (Key keyToFind : keys) {
            this.getSystemParameter(keyToFind).ifPresent(p -> {
                result.put(p.getKey(), splitValue(p.getValue(), mapper, filter));
                keysToFind.remove(keyToFind);
            });
        }
        if (!keysToFind.isEmpty()) {
            switch(referenceType) {
                case ENVIRONMENT:
                    this.getEnvParameters(keysToFind, refIdToUse).forEach(p -> {
                        result.put(p.getKey(), splitValue(p.getValue(), mapper, filter));
                        keysToFind.remove(Key.findByKey(p.getKey()));
                    });
                    if (!keysToFind.isEmpty()) {
                        // String organizationId = "DEFAULT";//environmentService.findById(referenceId).getOrganizationId();
                        String organizationId = environmentService.findById(refIdToUse).getOrganizationId();
                        this.getOrgParameters(keysToFind, organizationId).forEach(p -> {
                            result.put(p.getKey(), splitValue(p.getValue(), mapper, filter));
                            keysToFind.remove(Key.findByKey(p.getKey()));
                        });
                        if (!keysToFind.isEmpty()) {
                            keysToFind.forEach(k -> result.put(k.key(), splitValue(k.defaultValue(), mapper, filter)));
                        }
                    }
                    break;
                case ORGANIZATION:
                    this.getOrgParameters(keysToFind, refIdToUse).forEach(p -> {
                        result.put(p.getKey(), splitValue(p.getValue(), mapper, filter));
                        keysToFind.remove(Key.findByKey(p.getKey()));
                    });
                    if (!keysToFind.isEmpty()) {
                        keysToFind.forEach(k -> result.put(k.key(), splitValue(k.defaultValue(), mapper, filter)));
                    }
                    break;
                default:
                    keysToFind.forEach(k -> result.put(k.key(), splitValue(k.defaultValue(), mapper, filter)));
                    break;
            }
        }
        return result;
    } catch (final TechnicalException ex) {
        final String message = "An error occurs while trying to find parameter values with keys: " + keys;
        LOGGER.error(message, ex);
        throw new TechnicalManagementException(message, ex);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Collections.emptyList(java.util.Collections.emptyList) Collectors.toList(java.util.stream.Collectors.toList) Key(io.gravitee.rest.api.model.parameters.Key) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Aggregations

TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)149 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)120 UuidString (io.gravitee.rest.api.service.common.UuidString)26 Date (java.util.Date)23 Component (org.springframework.stereotype.Component)18 Logger (org.slf4j.Logger)17 LoggerFactory (org.slf4j.LoggerFactory)17 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)16 Collectors (java.util.stream.Collectors)13 Autowired (org.springframework.beans.factory.annotation.Autowired)13 IOException (java.io.IOException)12 JsonNode (com.fasterxml.jackson.databind.JsonNode)11 Rating (io.gravitee.repository.management.model.Rating)9 ApiRatingUnavailableException (io.gravitee.rest.api.service.exceptions.ApiRatingUnavailableException)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 Dictionary (io.gravitee.repository.management.model.Dictionary)8 AuditService (io.gravitee.rest.api.service.AuditService)8 java.util (java.util)8 Theme (io.gravitee.repository.management.model.Theme)6 List (java.util.List)6