Search in sources :

Example 81 with TechnicalManagementException

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);
    }
}
Also used : PluginNotFoundException(io.gravitee.rest.api.service.exceptions.PluginNotFoundException) IOException(java.io.IOException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) HashSet(java.util.HashSet)

Example 82 with TechnicalManagementException

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);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Message2RecipientNotFoundException(io.gravitee.rest.api.service.exceptions.Message2RecipientNotFoundException) Command(io.gravitee.repository.management.model.Command) Date(java.util.Date) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 83 with TechnicalManagementException

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);
    }
}
Also used : CustomUserField(io.gravitee.repository.management.model.CustomUserField) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) CustomUserFieldReferenceType(io.gravitee.repository.management.model.CustomUserFieldReferenceType) CustomUserFieldAlreadyExistException(io.gravitee.rest.api.service.exceptions.CustomUserFieldAlreadyExistException) Date(java.util.Date) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 84 with TechnicalManagementException

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);
    }
}
Also used : CustomUserField(io.gravitee.repository.management.model.CustomUserField) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) CustomUserFieldReferenceType(io.gravitee.repository.management.model.CustomUserFieldReferenceType) Date(java.util.Date) CustomUserFieldNotFoundException(io.gravitee.rest.api.service.exceptions.CustomUserFieldNotFoundException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 85 with TechnicalManagementException

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);
    }
}
Also used : CustomUserField(io.gravitee.repository.management.model.CustomUserField) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) CustomUserFieldReferenceType(io.gravitee.repository.management.model.CustomUserFieldReferenceType) 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