use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class AbstractPluginService method list.
/*
protected AbstractPluginService(ConfigurablePluginManager<T> pluginManager) {
this.pluginManager = pluginManager;
}
*/
protected Set<T> list() {
try {
logger.debug("List all plugins");
final Collection<T> plugins = pluginManager.findAll();
return new HashSet<>(plugins);
} catch (Exception ex) {
logger.error("An error occurs while trying to list all policies", ex);
throw new TechnicalManagementException("An error occurs while trying to list all policies", ex);
}
}
use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class CommandServiceImpl method send.
@Override
public void send(NewCommandEntity messageEntity) {
if (messageEntity.getTo() == null || messageEntity.getTo().isEmpty()) {
throw new Message2RecipientNotFoundException();
}
Command command = new Command();
command.setId(UuidString.generateRandom());
command.setEnvironmentId(GraviteeContext.getCurrentEnvironment());
command.setFrom(node.id());
command.setTo(messageEntity.getTo());
command.setTags(convert(messageEntity.getTags()));
long now = System.currentTimeMillis();
command.setCreatedAt(new Date(now));
command.setUpdatedAt(command.getCreatedAt());
command.setExpiredAt(new Date(now + (messageEntity.getTtlInSeconds() * 1000)));
if (messageEntity.getContent() != null) {
command.setContent(messageEntity.getContent());
}
try {
commandRepository.create(command);
} catch (TechnicalException ex) {
logger.error("An error occurs while trying to create {}", command, ex);
throw new TechnicalManagementException("An error occurs while trying create " + command, ex);
}
}
use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class CustomUserFieldsServiceImpl method create.
@Override
public CustomUserFieldEntity create(CustomUserFieldEntity newFieldEntity) {
try {
final String refId = GraviteeContext.getCurrentOrganization();
final CustomUserFieldReferenceType refType = ORGANIZATION;
LOGGER.debug("Create custom user field [key={}, refId={}]", newFieldEntity.getKey(), refId);
Optional<CustomUserField> existingRecord = this.customUserFieldsRepository.findById(formatKeyValue(newFieldEntity.getKey()), refId, refType);
if (existingRecord.isPresent()) {
throw new CustomUserFieldAlreadyExistException(newFieldEntity.getKey());
} else {
CustomUserField fieldToCreate = map(newFieldEntity);
fieldToCreate.setReferenceId(refId);
fieldToCreate.setReferenceType(refType);
final Date now = new Date();
fieldToCreate.setCreatedAt(now);
fieldToCreate.setUpdatedAt(now);
final CustomUserField recorded = customUserFieldsRepository.create(fieldToCreate);
createAuditLog(CUSTOM_USER_FIELD_CREATED, now, null, recorded);
return map(recorded);
}
} catch (TechnicalException e) {
LOGGER.error("An error occurs while trying to create CustomUserField", e);
throw new TechnicalManagementException("An error occurs while trying to create CustomUserField", e);
}
}
use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class CustomUserFieldsServiceImpl method update.
@Override
public CustomUserFieldEntity update(CustomUserFieldEntity updateFieldEntity) {
try {
final String refId = GraviteeContext.getCurrentOrganization();
final CustomUserFieldReferenceType refType = ORGANIZATION;
LOGGER.debug("Update custom user field [key={}, refId={}]", updateFieldEntity.getKey(), refId);
Optional<CustomUserField> existingRecord = this.customUserFieldsRepository.findById(formatKeyValue(updateFieldEntity.getKey()), refId, refType);
if (existingRecord.isPresent()) {
CustomUserField fieldToUpdate = map(updateFieldEntity);
fieldToUpdate.setKey(existingRecord.get().getKey());
fieldToUpdate.setReferenceId(existingRecord.get().getReferenceId());
fieldToUpdate.setReferenceType(existingRecord.get().getReferenceType());
fieldToUpdate.setCreatedAt(existingRecord.get().getCreatedAt());
final Date updatedAt = new Date();
fieldToUpdate.setUpdatedAt(updatedAt);
final CustomUserField updatedField = customUserFieldsRepository.update(fieldToUpdate);
createAuditLog(CUSTOM_USER_FIELD_UPDATED, updatedAt, existingRecord.get(), updatedField);
return map(updatedField);
} else {
throw new CustomUserFieldNotFoundException(updateFieldEntity.getKey());
}
} catch (TechnicalException e) {
LOGGER.error("An error occurs while trying to update CustomUserField", e);
throw new TechnicalManagementException("An error occurs while trying to update CustomUserField", e);
}
}
use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class CustomUserFieldsServiceImpl method listAllFields.
@Override
public List<CustomUserFieldEntity> listAllFields() {
try {
final String refId = GraviteeContext.getCurrentOrganization();
final CustomUserFieldReferenceType refType = ORGANIZATION;
LOGGER.debug("List all custom user fields [refId={}/refType={}]", refId, refType);
List<CustomUserField> records = this.customUserFieldsRepository.findByReferenceIdAndReferenceType(refId, refType);
return records.stream().map(this::map).collect(Collectors.toList());
} catch (TechnicalException e) {
LOGGER.error("An error occurs while trying to list all CustomUserField", e);
throw new TechnicalManagementException("An error occurs while trying to list all CustomUserField", e);
}
}
Aggregations