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);
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations