Search in sources :

Example 51 with TechnicalManagementException

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

the class InstallationServiceImpl method setAdditionalInformation.

@Override
public InstallationEntity setAdditionalInformation(Map<String, String> additionalInformation) {
    try {
        final Optional<Installation> optInstallation = this.installationRepository.find();
        if (optInstallation.isPresent()) {
            Installation installation = optInstallation.get();
            installation.setAdditionalInformation(additionalInformation);
            installation.setUpdatedAt(new Date());
            return convert(this.installationRepository.update(installation));
        }
    } catch (final Exception ex) {
        LOGGER.error("Error while updating installation : {}", ex.getMessage());
        throw new TechnicalManagementException("Error while updating installation", ex);
    }
    throw new InstallationNotFoundException("");
}
Also used : Installation(io.gravitee.repository.management.model.Installation) InstallationNotFoundException(io.gravitee.rest.api.service.exceptions.InstallationNotFoundException) Date(java.util.Date) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) InstallationNotFoundException(io.gravitee.rest.api.service.exceptions.InstallationNotFoundException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 52 with TechnicalManagementException

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

the class InvitationServiceImpl method create.

@Override
public InvitationEntity create(final NewInvitationEntity invitation) {
    final List<InvitationEntity> invitations = findByReference(invitation.getReferenceType(), invitation.getReferenceId());
    if (invitations.stream().map(InvitationEntity::getEmail).anyMatch(invitation.getEmail()::equals)) {
        throw new InvitationEmailAlreadyExistsException(invitation.getEmail());
    }
    try {
        // First check if user exists
        final Optional<UserEntity> existingUser = userService.findByEmail(invitation.getEmail());
        if (existingUser.isPresent()) {
            final UserEntity user = existingUser.get();
            Set<String> groupUsers = membershipService.getMembershipsByReference(MembershipReferenceType.GROUP, invitation.getReferenceId()).stream().map(MembershipEntity::getMemberId).collect(Collectors.toSet());
            final GroupEntity group = groupService.findById(invitation.getReferenceId());
            if (groupUsers.contains(user.getId())) {
                throw new MemberEmailAlreadyExistsException(invitation.getEmail());
            }
            // override permission if not allowed
            final boolean hasPermission = permissionService.hasPermission(RolePermission.ENVIRONMENT_GROUP, GraviteeContext.getCurrentEnvironment(), CREATE, UPDATE, DELETE);
            if (!hasPermission && group.isLockApiRole()) {
                invitation.setApiRole(null);
            }
            if (!hasPermission && group.isLockApplicationRole()) {
                invitation.setApplicationRole(null);
            }
            addMember(invitation.getReferenceType().name(), invitation.getReferenceId(), user.getId(), invitation.getApiRole(), invitation.getApplicationRole());
            return null;
        } else {
            sendGroupInvitationEmail(invitation);
            final Invitation createdInvitation = invitationRepository.create(convert(invitation));
            return convert(createdInvitation);
        }
    } catch (TechnicalException ex) {
        final String message = "An error occurs while trying to create invitation for email " + invitation.getEmail();
        LOGGER.error(message, ex);
        throw new TechnicalManagementException(message, ex);
    }
}
Also used : InvitationEmailAlreadyExistsException(io.gravitee.rest.api.service.exceptions.InvitationEmailAlreadyExistsException) MemberEmailAlreadyExistsException(io.gravitee.rest.api.service.exceptions.MemberEmailAlreadyExistsException) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Invitation(io.gravitee.repository.management.model.Invitation) UuidString(io.gravitee.rest.api.service.common.UuidString) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 53 with TechnicalManagementException

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

the class InvitationServiceImpl method delete.

@Override
public void delete(final String invitationId, final String referenceId) {
    try {
        final Optional<Invitation> optionalInvitation = invitationRepository.findById(invitationId);
        if (!optionalInvitation.isPresent() || !optionalInvitation.get().getReferenceId().equals(referenceId)) {
            throw new InvitationNotFoundException(invitationId);
        }
        invitationRepository.delete(invitationId);
    } catch (TechnicalException te) {
        final String msg = "An error occurs while trying to delete the invitation " + invitationId;
        LOGGER.error(msg, te);
        throw new TechnicalManagementException(msg, te);
    }
}
Also used : InvitationNotFoundException(io.gravitee.rest.api.service.exceptions.InvitationNotFoundException) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Invitation(io.gravitee.repository.management.model.Invitation) UuidString(io.gravitee.rest.api.service.common.UuidString) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 54 with TechnicalManagementException

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

the class PortalNotificationServiceImpl method create.

private void create(List<NewPortalNotificationEntity> notificationEntities) {
    final Date now = new Date();
    List<PortalNotification> notifications = notificationEntities.stream().map(this::convert).collect(Collectors.toList());
    notifications.forEach(n -> {
        n.setId(UuidString.generateRandom());
        n.setCreatedAt(now);
    });
    try {
        portalNotificationRepository.create(notifications);
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to create {}", notifications, ex);
        throw new TechnicalManagementException("An error occurs while trying create " + notifications, ex);
    }
}
Also used : PortalNotification(io.gravitee.repository.management.model.PortalNotification) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Date(java.util.Date) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 55 with TechnicalManagementException

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

the class QualityRuleServiceImpl method create.

@Override
public QualityRuleEntity create(NewQualityRuleEntity newEntity) {
    try {
        final QualityRule qualityRule = convert(newEntity);
        final QualityRule createdQualityRule = qualityRuleRepository.create(qualityRule);
        auditService.createEnvironmentAuditLog(Collections.singletonMap(QUALITY_RULE, createdQualityRule.getId()), QualityRule.AuditEvent.QUALITY_RULE_CREATED, qualityRule.getCreatedAt(), null, qualityRule);
        return convert(createdQualityRule);
    } catch (TechnicalException e) {
        LOGGER.error("An error occurs while trying to create a quality rule {}", newEntity, e);
        throw new TechnicalManagementException("An error occurs while trying to create a quality rule " + newEntity, e);
    }
}
Also used : QualityRule(io.gravitee.repository.management.model.QualityRule) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) 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