Skip to content

Commit

Permalink
Integrate acceptance API with the service
Browse files Browse the repository at this point in the history
  • Loading branch information
ShanChathusanda93 committed Sep 3, 2023
1 parent c6d0c90 commit 34a16ab
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@
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;
Expand Down Expand Up @@ -109,6 +112,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,6 +205,22 @@ public boolean deleteInvitation(String invitationId) {
*/
public void acceptInvitation(AcceptanceRequestBody acceptanceRequestBody) {

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);
}
}
throw handleException(NOT_IMPLEMENTED, UserInvitationMgtConstants
.ErrorMessage.ERROR_CODE_NOT_IMPLEMENTED, null);
}
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.60
</org.wso2.carbon.identity.organization.management.version>

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

0 comments on commit 34a16ab

Please sign in to comment.