Search in sources :

Example 1 with InvitationNotFoundException

use of io.gravitee.rest.api.service.exceptions.InvitationNotFoundException 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 2 with InvitationNotFoundException

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

the class InvitationServiceImpl method update.

@Override
public InvitationEntity update(final UpdateInvitationEntity invitation) {
    try {
        final Optional<Invitation> invitationOptional = invitationRepository.findById(invitation.getId());
        if (invitationOptional.isPresent()) {
            final Invitation invitationToUpdate = invitationOptional.get();
            if (!invitationToUpdate.getReferenceId().equals(invitation.getReferenceId())) {
                throw new InvitationNotFoundException(invitation.getId());
            }
            invitationToUpdate.setApiRole(invitation.getApiRole());
            invitationToUpdate.setApplicationRole(invitation.getApplicationRole());
            invitationToUpdate.setUpdatedAt(new Date());
            return convert(invitationRepository.update(invitationToUpdate));
        } else {
            throw new InvitationNotFoundException(invitation.getId());
        }
    } catch (TechnicalException ex) {
        final String message = "An error occurs while trying to update invitation with email " + invitation.getEmail();
        LOGGER.error(message, ex);
        throw new TechnicalManagementException(message, ex);
    }
}
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) Date(java.util.Date) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Aggregations

TechnicalException (io.gravitee.repository.exceptions.TechnicalException)2 Invitation (io.gravitee.repository.management.model.Invitation)2 UuidString (io.gravitee.rest.api.service.common.UuidString)2 InvitationNotFoundException (io.gravitee.rest.api.service.exceptions.InvitationNotFoundException)2 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)2 Date (java.util.Date)1