Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate acceptance API with the service #482

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ public enum ErrorMessage {
ERROR_CODE_INVALID_FILTER("60009",
"Invalid filter.",
"Provided filter %s is not valid."),
ERROR_CODE_INVALID_APPLICATION("60009",
"Invalid application provided.",
"One of the provided applications with roles are not valid."),
ERROR_CODE_INVALID_CONFIRMATION_CODE_FOR_ACCEPTANCE("60010",
"Invalid confirmation code.",
"Could not accept the invitation since the confirmation code %s is not valid."),
ERROR_CODE_INVALID_USER("60011",
"Invalid user provided.",
"Invalid user is provided."),
ERROR_CODE_EXISTING_USER("60012",
"Authenticated user exist.",
"The authenticated user is already available in the organization."),

// Server errors.
ERROR_CODE_CREATE_INVITATION("65001",
Expand All @@ -78,6 +90,9 @@ public enum ErrorMessage {
ERROR_CODE_DELETE_INVITATION("65004",
"Unable to delete the invitation.",
"Could not delete the invitation with the id %s."),
ERROR_CODE_ACCEPT_INVITATION("65005",
"Unable to accept the invitation.",
"Could not accept the invitation with the confirmation code %s."),
ERROR_CODE_NOT_IMPLEMENTED("65100",
"Not Implemented.",
"Method is not implemented.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_INVALID_CONFIRMATION_CODE;
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_INVALID_FILTER;
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_INVALID_INVITATION_ID;
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_INVALID_USER;
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_MULTIPLE_INVITATIONS_FOR_USER;
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_STORE_ROLES_APP_ID_INVALID;
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_UNSUPPORTED_FILTER_ATTRIBUTE;
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_UNSUPPORTED_FILTER_ATTRIBUTE_VALUE;
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_USER_ALREADY_EXISTS;
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_USER_NOT_FOUND;
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
import static javax.ws.rs.core.Response.Status.NOT_IMPLEMENTED;

/**
* Service class for the User Invitation Management APIs.
Expand Down Expand Up @@ -109,6 +111,9 @@ public InvitationSuccessResponse createInvitation(InvitationRequestBody invitati
} else if (ERROR_CODE_ACTIVE_INVITATION_EXISTS.getCode().equals(e.getErrorCode())) {
throw handleException(BAD_REQUEST, UserInvitationMgtConstants.ErrorMessage
.ERROR_CODE_ACTIVE_INVITATION_AVAILABLE, invitation.getUsername());
} else if (ERROR_CODE_STORE_ROLES_APP_ID_INVALID.getCode().equals(e.getErrorCode())) {
throw handleException(BAD_REQUEST, UserInvitationMgtConstants.ErrorMessage
.ERROR_CODE_INVALID_APPLICATION, StringUtils.EMPTY);
}
throw handleException(Response.Status.INTERNAL_SERVER_ERROR,
UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_CREATE_INVITATION,
Expand Down Expand Up @@ -199,8 +204,24 @@ public boolean deleteInvitation(String invitationId) {
*/
public void acceptInvitation(AcceptanceRequestBody acceptanceRequestBody) {

throw handleException(NOT_IMPLEMENTED, UserInvitationMgtConstants
.ErrorMessage.ERROR_CODE_NOT_IMPLEMENTED, null);
InvitationCoreServiceImpl invitationCoreService = new InvitationCoreServiceImpl();
try {
invitationCoreService.acceptInvitation(acceptanceRequestBody.getConfirmationCode());
} catch (UserInvitationMgtException e) {
if (ERROR_CODE_INVALID_CONFIRMATION_CODE.getCode().equals(e.getErrorCode())) {
throw handleException(BAD_REQUEST, UserInvitationMgtConstants.ErrorMessage
.ERROR_CODE_INVALID_CONFIRMATION_CODE_FOR_ACCEPTANCE, acceptanceRequestBody
.getConfirmationCode());
} else if (ERROR_CODE_INVALID_USER.getCode().equals(e.getErrorCode())) {
throw handleException(BAD_REQUEST, UserInvitationMgtConstants.ErrorMessage
.ERROR_CODE_INVALID_USER, StringUtils.EMPTY);
} else if (ERROR_CODE_USER_ALREADY_EXISTS.getCode().equals(e.getErrorCode())) {
throw handleException(BAD_REQUEST, UserInvitationMgtConstants.ErrorMessage
.ERROR_CODE_EXISTING_USER, StringUtils.EMPTY);
}
ShanChathusanda93 marked this conversation as resolved.
Show resolved Hide resolved
throw handleException(INTERNAL_SERVER_ERROR, UserInvitationMgtConstants.ErrorMessage
.ERROR_CODE_ACCEPT_INVITATION, acceptanceRequestBody.getConfirmationCode());
}
}

private APIError handleException(Response.Status status, UserInvitationMgtConstants.ErrorMessage error,
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@
</org.wso2.carbon.identity.organization.management.core.version.range>

<!-- Organization management service Version -->
<org.wso2.carbon.identity.organization.management.version>1.3.54
<org.wso2.carbon.identity.organization.management.version>1.3.61
</org.wso2.carbon.identity.organization.management.version>

<!-- Unit test versions -->
Expand Down
Loading