Search in sources :

Example 1 with TechnicalManagementException

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

the class ListEnvironmentOperationHandler method handle.

@Override
public Single<BridgeReply> handle(BridgeCommand bridgeCommand) {
    BridgeMultiReply multiReply = new BridgeMultiReply();
    multiReply.setCommandId(bridgeCommand.getId());
    try {
        final List<EnvironmentEntity> managedEnvironments = this.environmentService.findByOrganization(bridgeCommand.getOrganizationId());
        multiReply.setCommandStatus(CommandStatus.SUCCEEDED);
        multiReply.setReplies(managedEnvironments.stream().map(environmentEntity -> {
            BridgeSimpleReply simpleReply = new BridgeSimpleReply();
            simpleReply.setCommandId(bridgeCommand.getId());
            simpleReply.setCommandStatus(CommandStatus.SUCCEEDED);
            simpleReply.setOrganizationId(environmentEntity.getOrganizationId());
            simpleReply.setEnvironmentId(environmentEntity.getId());
            simpleReply.setInstallationId(installationService.get().getId());
            try {
                simpleReply.setPayload(objectMapper.writeValueAsString(environmentEntity));
            } catch (JsonProcessingException e) {
                logger.warn("Problem while serializing environment {}", environmentEntity.getId());
                simpleReply.setMessage("Problem while serializing environment: " + environmentEntity.getId());
                simpleReply.setCommandStatus(CommandStatus.ERROR);
            }
            return simpleReply;
        }).collect(Collectors.toList()));
    } catch (TechnicalManagementException ex) {
        multiReply.setCommandStatus(CommandStatus.ERROR);
        multiReply.setMessage("No environment available for organization: " + bridgeCommand.getOrganizationId());
    }
    return Single.just(multiReply);
}
Also used : BridgeMultiReply(io.gravitee.cockpit.api.command.bridge.BridgeMultiReply) BridgeSimpleReply(io.gravitee.cockpit.api.command.bridge.BridgeSimpleReply) EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 2 with TechnicalManagementException

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

the class DictionaryServiceImpl method start.

@Override
public DictionaryEntity start(String id) {
    try {
        LOGGER.debug("Start dictionary {}", id);
        Optional<Dictionary> optDictionary = dictionaryRepository.findById(id);
        if (!optDictionary.isPresent()) {
            throw new DictionaryNotFoundException(id);
        }
        // add deployment date
        Dictionary dictionary = optDictionary.get();
        dictionary.setUpdatedAt(new Date());
        dictionary.setState(LifecycleState.STARTED);
        dictionary = dictionaryRepository.update(dictionary);
        Map<String, String> properties = new HashMap<>();
        properties.put(Event.EventProperties.DICTIONARY_ID.getValue(), id);
        // And create event
        eventService.create(EventType.START_DICTIONARY, null, properties);
        // Audit
        createAuditLog(Dictionary.AuditEvent.DICTIONARY_UPDATED, dictionary.getCreatedAt(), optDictionary.get(), dictionary);
        return convert(dictionary);
    } catch (Exception ex) {
        LOGGER.error("An error occurs while trying to undeploy dictionary {}", id, ex);
        throw new TechnicalManagementException("An error occurs while trying to undeploy " + id, ex);
    }
}
Also used : Dictionary(io.gravitee.repository.management.model.Dictionary) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) IOException(java.io.IOException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 3 with TechnicalManagementException

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

the class DictionaryServiceImpl method update.

@Override
public DictionaryEntity update(String id, UpdateDictionaryEntity updateDictionaryEntity) {
    try {
        LOGGER.debug("Update dictionary {}", updateDictionaryEntity);
        Optional<Dictionary> optDictionary = dictionaryRepository.findById(id);
        if (!optDictionary.isPresent()) {
            throw new DictionaryNotFoundException(updateDictionaryEntity.getName());
        }
        Dictionary dictionary = convert(updateDictionaryEntity);
        dictionary.setId(id);
        dictionary.setCreatedAt(optDictionary.get().getCreatedAt());
        dictionary.setEnvironmentId(optDictionary.get().getEnvironmentId());
        dictionary.setUpdatedAt(new Date());
        dictionary.setState(optDictionary.get().getState());
        Dictionary updatedDictionary = dictionaryRepository.update(dictionary);
        // Force a new start event if the dictionary is already started when updating.
        if (updatedDictionary.getState() == LifecycleState.STARTED) {
            Map<String, String> properties = new HashMap<>();
            properties.put(Event.EventProperties.DICTIONARY_ID.getValue(), id);
            eventService.create(EventType.START_DICTIONARY, null, properties);
        }
        // Audit
        createAuditLog(Dictionary.AuditEvent.DICTIONARY_UPDATED, dictionary.getCreatedAt(), optDictionary.get(), updatedDictionary);
        return convert(updatedDictionary);
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to update dictionary {}", updateDictionaryEntity, ex);
        throw new TechnicalManagementException("An error occurs while trying to update " + updateDictionaryEntity, ex);
    }
}
Also used : Dictionary(io.gravitee.repository.management.model.Dictionary) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 4 with TechnicalManagementException

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

the class DictionaryServiceImpl method findById.

@Override
public DictionaryEntity findById(String id) {
    try {
        LOGGER.debug("Find dictionary by ID: {}", id);
        Optional<Dictionary> dictionary = dictionaryRepository.findById(id);
        if (dictionary.isPresent()) {
            return convert(dictionary.get());
        }
        throw new DictionaryNotFoundException(id);
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to delete a dictionary using its ID {}", id, ex);
        throw new TechnicalManagementException("An error occurs while trying to delete a dictionary using its ID " + id, ex);
    }
}
Also used : Dictionary(io.gravitee.repository.management.model.Dictionary) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 5 with TechnicalManagementException

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

the class DictionaryServiceImpl method deploy.

@Override
public DictionaryEntity deploy(String id) {
    try {
        LOGGER.debug("Deploy dictionary {}", id);
        Optional<Dictionary> optDictionary = dictionaryRepository.findById(id);
        if (!optDictionary.isPresent()) {
            throw new DictionaryNotFoundException(id);
        }
        // add deployment date
        Dictionary dictionary = optDictionary.get();
        dictionary.setUpdatedAt(new Date());
        dictionary.setDeployedAt(dictionary.getUpdatedAt());
        dictionary = dictionaryRepository.update(dictionary);
        Map<String, String> properties = new HashMap<>();
        properties.put(Event.EventProperties.DICTIONARY_ID.getValue(), id);
        // And create event
        eventService.create(EventType.PUBLISH_DICTIONARY, mapper.writeValueAsString(dictionary), properties);
        return convert(dictionary);
    } catch (Exception ex) {
        LOGGER.error("An error occurs while trying to deploy dictionary {}", id, ex);
        throw new TechnicalManagementException("An error occurs while trying to deploy " + id, ex);
    }
}
Also used : Dictionary(io.gravitee.repository.management.model.Dictionary) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) IOException(java.io.IOException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) 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