Search in sources :

Example 86 with TechnicalManagementException

use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.

the class CustomUserFieldsServiceImpl method map.

private CustomUserFieldEntity map(CustomUserField record) {
    CustomUserFieldEntity result = new CustomUserFieldEntity();
    result.setKey(formatKeyValue(record.getKey()));
    result.setLabel(record.getLabel());
    result.setRequired(record.isRequired());
    if (record.getValues() != null) {
        switch(record.getFormat()) {
            case STRING:
                result.setValues(record.getValues());
                break;
            default:
                throw new TechnicalManagementException("Unable to read values of CustomUserField, format not supported");
        }
    }
    return result;
}
Also used : CustomUserFieldEntity(io.gravitee.rest.api.model.CustomUserFieldEntity) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 87 with TechnicalManagementException

use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.

the class CustomUserFieldsServiceImpl method delete.

@Override
public void delete(String key) {
    try {
        final String refId = GraviteeContext.getCurrentOrganization();
        final CustomUserFieldReferenceType refType = ORGANIZATION;
        LOGGER.debug("Delete custom user field [key={}, refId={}]", key, refId);
        Optional<CustomUserField> existingRecord = this.customUserFieldsRepository.findById(formatKeyValue(key), refId, refType);
        if (existingRecord.isPresent()) {
            customUserFieldsRepository.delete(formatKeyValue(key), refId, refType);
            createAuditLog(CUSTOM_USER_FIELD_DELETED, new Date(), existingRecord.get(), null);
            // remove all instance of this field from UserMetadata
            this.userMetadataService.deleteAllByCustomFieldId(existingRecord.get().getKey(), existingRecord.get().getReferenceId(), existingRecord.get().getReferenceType());
        }
    } 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) Date(java.util.Date) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 88 with TechnicalManagementException

use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.

the class EnvironmentServiceImpl method findById.

@Override
public EnvironmentEntity findById(String environmentId) {
    try {
        LOGGER.debug("Find environment by ID: {}", environmentId);
        Optional<Environment> optEnvironment = environmentRepository.findById(environmentId);
        if (!optEnvironment.isPresent()) {
            throw new EnvironmentNotFoundException(environmentId);
        }
        return convert(optEnvironment.get());
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to find environment by ID", ex);
        throw new TechnicalManagementException("An error occurs while trying to find environment by ID", ex);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) EnvironmentNotFoundException(io.gravitee.rest.api.service.exceptions.EnvironmentNotFoundException) Environment(io.gravitee.repository.management.model.Environment) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 89 with TechnicalManagementException

use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.

the class ApplicationAlertServiceImpl method updateTriggerNotification.

private void updateTriggerNotification(AlertTriggerEntity trigger, String body, String subject, List<String> recipients) {
    if (CollectionUtils.isEmpty(trigger.getNotifications())) {
        return;
    }
    trigger.getNotifications().stream().filter(n -> DEFAULT_EMAIL_NOTIFIER.equals(n.getType())).findFirst().ifPresent(notification -> {
        try {
            ObjectNode configuration = mapper.createObjectNode();
            JsonNode emailNode = mapper.readTree(notification.getConfiguration());
            configuration.put("to", recipients == null ? emailNode.path("to").asText() : String.join(",", recipients));
            configuration.put("from", emailNode.path("from").asText());
            configuration.put("subject", subject == null ? emailNode.path("subject").asText() : subject);
            configuration.put("body", body == null ? emailNode.path("body").asText() : body);
            notification.setConfiguration(mapper.writeValueAsString(configuration));
            alertService.update(convert(trigger));
        } catch (JsonProcessingException e) {
            LOGGER.error("An error occurs while trying to update Alert notification", e);
            throw new TechnicalManagementException("An error occurs while trying to update Alert notification");
        }
    });
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 90 with TechnicalManagementException

use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.

the class ApplicationAlertServiceImpl method addMemberToApplication.

@Override
public void addMemberToApplication(String applicationId, String email) {
    if (StringUtils.isEmpty(email)) {
        return;
    }
    // check existence of application
    applicationService.findById(applicationId);
    alertService.findByReference(AlertReferenceType.APPLICATION, applicationId).forEach(trigger -> {
        if (trigger.getNotifications() == null) {
            trigger.setNotifications(createNotification(trigger.getType()));
        }
        final Optional<Notification> notificationOpt = trigger.getNotifications().stream().filter(n -> DEFAULT_EMAIL_NOTIFIER.equals(n.getType())).findFirst();
        if (notificationOpt.isPresent()) {
            Notification notification = notificationOpt.get();
            try {
                ObjectNode configuration = mapper.createObjectNode();
                JsonNode emailNode = mapper.readTree(notification.getConfiguration());
                configuration.put("to", emailNode.path("to").asText() + "," + email);
                configuration.put("from", emailNode.path("from").asText());
                configuration.put("subject", emailNode.path("subject").asText());
                configuration.put("body", emailNode.path("body").asText());
                notification.setConfiguration(mapper.writeValueAsString(configuration));
            } catch (JsonProcessingException e) {
                LOGGER.error("An error occurs while trying to add a recipient to the Alert notification", e);
                throw new TechnicalManagementException("An error occurs while trying to add a recipient to the Alert notification");
            }
        } else {
            trigger.setNotifications(createNotification(trigger.getType(), singletonList(email)));
        }
        alertService.update(convert(trigger));
    });
}
Also used : AlertHook(io.gravitee.rest.api.service.notification.AlertHook) Arrays(java.util.Arrays) LoggerFactory(org.slf4j.LoggerFactory) HookScope(io.gravitee.rest.api.service.notification.HookScope) AlertTriggerRepository(io.gravitee.repository.management.api.AlertTriggerRepository) Collections.singletonList(java.util.Collections.singletonList) StringCondition(io.gravitee.alert.api.condition.StringCondition) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) ApplicationListItem(io.gravitee.rest.api.model.application.ApplicationListItem) UpdateAlertTriggerEntity(io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity) MembershipEntity(io.gravitee.rest.api.model.MembershipEntity) AlertStatusEntity(io.gravitee.rest.api.model.alert.AlertStatusEntity) Collections.emptyList(java.util.Collections.emptyList) MembershipService(io.gravitee.rest.api.service.MembershipService) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) NewAlertTriggerEntity(io.gravitee.rest.api.model.alert.NewAlertTriggerEntity) AlertService(io.gravitee.rest.api.service.AlertService) CollectionUtils(org.springframework.util.CollectionUtils) ApplicationService(io.gravitee.rest.api.service.ApplicationService) Optional(java.util.Optional) Filter(io.gravitee.alert.api.condition.Filter) NotificationTemplateEntity(io.gravitee.rest.api.model.notification.NotificationTemplateEntity) UserEntity(io.gravitee.rest.api.model.UserEntity) Trigger(io.gravitee.alert.api.trigger.Trigger) Async(org.springframework.scheduling.annotation.Async) ApplicationAlertEventType(io.gravitee.rest.api.model.alert.ApplicationAlertEventType) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ApplicationAlertService(io.gravitee.rest.api.service.ApplicationAlertService) ArrayList(java.util.ArrayList) ApplicationAlertMembershipEvent(io.gravitee.rest.api.model.alert.ApplicationAlertMembershipEvent) HashSet(java.util.HashSet) Value(org.springframework.beans.factory.annotation.Value) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) NotificationTemplateService(io.gravitee.rest.api.service.notification.NotificationTemplateService) UserService(io.gravitee.rest.api.service.UserService) Notification(io.gravitee.notifier.api.Notification) AlertReferenceType(io.gravitee.rest.api.model.alert.AlertReferenceType) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Event(io.gravitee.common.event.Event) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) AlertTriggerEntity(io.gravitee.rest.api.model.alert.AlertTriggerEntity) Dampening(io.gravitee.alert.api.trigger.Dampening) Consumer(java.util.function.Consumer) MembershipReferenceType(io.gravitee.rest.api.model.MembershipReferenceType) Component(org.springframework.stereotype.Component) NotificationTemplateEvent(io.gravitee.rest.api.model.notification.NotificationTemplateEvent) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) StringUtils(org.springframework.util.StringUtils) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Notification(io.gravitee.notifier.api.Notification) 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