Search in sources :

Example 1 with Dictionary

use of io.gravitee.repository.management.model.Dictionary 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 2 with Dictionary

use of io.gravitee.repository.management.model.Dictionary 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 3 with Dictionary

use of io.gravitee.repository.management.model.Dictionary 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 4 with Dictionary

use of io.gravitee.repository.management.model.Dictionary 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)

Example 5 with Dictionary

use of io.gravitee.repository.management.model.Dictionary in project gravitee-management-rest-api by gravitee-io.

the class DictionaryServiceImpl method convert.

private Dictionary convert(UpdateDictionaryEntity updateDictionaryEntity) {
    Dictionary dictionary = new Dictionary();
    dictionary.setName(updateDictionaryEntity.getName());
    dictionary.setDescription(updateDictionaryEntity.getDescription());
    dictionary.setProperties(updateDictionaryEntity.getProperties());
    final io.gravitee.rest.api.model.configuration.dictionary.DictionaryType type = updateDictionaryEntity.getType();
    if (type != null) {
        dictionary.setType(io.gravitee.repository.management.model.DictionaryType.valueOf(type.name()));
    }
    if (type == io.gravitee.rest.api.model.configuration.dictionary.DictionaryType.DYNAMIC) {
        dictionary.setProvider(convert(updateDictionaryEntity.getProvider()));
        dictionary.setTrigger(convert(updateDictionaryEntity.getTrigger()));
    }
    return dictionary;
}
Also used : Dictionary(io.gravitee.repository.management.model.Dictionary) io.gravitee.rest.api.model.configuration.dictionary(io.gravitee.rest.api.model.configuration.dictionary) io.gravitee.repository.management.model(io.gravitee.repository.management.model)

Aggregations

Dictionary (io.gravitee.repository.management.model.Dictionary)10 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)8 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)8 IOException (java.io.IOException)4 io.gravitee.repository.management.model (io.gravitee.repository.management.model)2 io.gravitee.rest.api.model.configuration.dictionary (io.gravitee.rest.api.model.configuration.dictionary)2