Search in sources :

Example 6 with Dictionary

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

the class DictionaryServiceImpl method stop.

@Override
public DictionaryEntity stop(String id) {
    try {
        LOGGER.debug("Stop 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.STOPPED);
        dictionary = dictionaryRepository.update(dictionary);
        Map<String, String> properties = new HashMap<>();
        properties.put(Event.EventProperties.DICTIONARY_ID.getValue(), id);
        // And create event
        eventService.create(EventType.STOP_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 7 with Dictionary

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

the class DictionaryServiceImpl method undeploy.

@Override
public DictionaryEntity undeploy(String id) {
    try {
        LOGGER.debug("Undeploy 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 = dictionaryRepository.update(dictionary);
        Map<String, String> properties = new HashMap<>();
        properties.put(Event.EventProperties.DICTIONARY_ID.getValue(), id);
        // And create event
        eventService.create(EventType.UNPUBLISH_DICTIONARY, mapper.writeValueAsString(dictionary), properties);
        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 8 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(NewDictionaryEntity newDictionaryEntity) {
    Dictionary dictionary = new Dictionary();
    dictionary.setId(IdGenerator.generate(newDictionaryEntity.getName()));
    dictionary.setName(newDictionaryEntity.getName());
    dictionary.setDescription(newDictionaryEntity.getDescription());
    final io.gravitee.rest.api.model.configuration.dictionary.DictionaryType type = newDictionaryEntity.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.MANUAL) {
        dictionary.setProperties(newDictionaryEntity.getProperties());
    } else {
        dictionary.setProvider(convert(newDictionaryEntity.getProvider()));
        dictionary.setTrigger(convert(newDictionaryEntity.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)

Example 9 with Dictionary

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

the class DictionaryServiceImpl method delete.

@Override
public void delete(String id) {
    try {
        LOGGER.debug("Delete dictionary: {}", id);
        Optional<Dictionary> dictionary = dictionaryRepository.findById(id);
        if (!dictionary.isPresent()) {
            throw new DictionaryNotFoundException(id);
        }
        // Force un-deployment
        if (dictionary.get().getType() == DictionaryType.MANUAL) {
            undeploy(id);
        }
        this.stop(id);
        dictionaryRepository.delete(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 10 with Dictionary

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

the class DictionaryServiceImpl method create.

@Override
public DictionaryEntity create(NewDictionaryEntity newDictionaryEntity) {
    try {
        LOGGER.debug("Create dictionary {}", newDictionaryEntity);
        Optional<Dictionary> optDictionary = dictionaryRepository.findById(IdGenerator.generate(newDictionaryEntity.getName()));
        if (optDictionary.isPresent()) {
            throw new DictionaryAlreadyExistsException(newDictionaryEntity.getName());
        }
        Dictionary dictionary = convert(newDictionaryEntity);
        dictionary.setEnvironmentId(GraviteeContext.getCurrentEnvironment());
        // Set date fields
        dictionary.setCreatedAt(new Date());
        dictionary.setState(LifecycleState.STOPPED);
        dictionary.setUpdatedAt(dictionary.getCreatedAt());
        Dictionary createdDictionary = dictionaryRepository.create(dictionary);
        createAuditLog(Dictionary.AuditEvent.DICTIONARY_CREATED, dictionary.getCreatedAt(), null, dictionary);
        return convert(createdDictionary);
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to create dictionary {}", newDictionaryEntity, ex);
        throw new TechnicalManagementException("An error occurs while trying to create " + newDictionaryEntity, ex);
    }
}
Also used : Dictionary(io.gravitee.repository.management.model.Dictionary) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

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