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);
}
}
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);
}
}
Aggregations