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

[Spring Cleanup] Remove Spring dependencies in the organization user invitation API #708

Open
wants to merge 2 commits into
base: feature-spring-cleanup
Choose a base branch
from
Open
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
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
~ Copyright (c) 2023-2024, WSO2 LLC. (http://www.wso2.com).
~
~ WSO2 LLC. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
Expand Down Expand Up @@ -56,11 +56,6 @@
<artifactId>javax.ws.rs-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2023-2024, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand All @@ -18,32 +18,30 @@

package org.wso2.carbon.identity.api.server.organization.user.invitation.management.common;

import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.organization.user.invitation.management.InvitationCoreService;

/**
* Holds the services which the shared user invitation management API component is using.
*/
public class UserInvitationMgtServiceHolder {

private static InvitationCoreService invitationCoreService;
private UserInvitationMgtServiceHolder() {

/**
* Get Invitation Core osgi service.
*
* @return InvitationCoreService.
*/
public static InvitationCoreService getInvitationCoreService() {
}

return invitationCoreService;
private static class InvitationCoreServiceHolder {
static final InvitationCoreService SERVICE = (InvitationCoreService) PrivilegedCarbonContext
.getThreadLocalCarbonContext().getOSGiService(InvitationCoreService.class, null);
}

/**
* Set Invitation Core osgi service.
* Get Invitation Core osgi service.
*
* @param invitationCoreService InvitationCoreService.
* @return InvitationCoreService.
*/
public static void setInvitationCoreService(InvitationCoreService invitationCoreService) {
public static InvitationCoreService getInvitationCoreService() {

UserInvitationMgtServiceHolder.invitationCoreService = invitationCoreService;
return InvitationCoreServiceHolder.SERVICE;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
~ Copyright (c) 2023-2024, WSO2 LLC. (http://www.wso2.com).
~
~ WSO2 LLC. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
Expand Down Expand Up @@ -34,16 +34,6 @@
<artifactId>javax.ws.rs-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2023-2024, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand All @@ -18,12 +18,12 @@

package org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1;

import org.springframework.beans.factory.annotation.Autowired;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.Multipart;
import java.io.InputStream;
import java.util.List;

import org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1.factories.GuestsApiServiceFactory;
import org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1.model.AcceptanceRequestBody;
import org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1.model.Error;
import org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1.model.IntrospectRequestBody;
Expand All @@ -45,8 +45,12 @@

public class GuestsApi {

@Autowired
private GuestsApiService delegate;
private final GuestsApiService delegate;

public GuestsApi() {

this.delegate = GuestsApiServiceFactory.getGuestsApi();
}

@Valid
@POST
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2023-2024, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand All @@ -21,12 +21,20 @@
import org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1.GuestsApiService;
import org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1.impl.GuestsApiServiceImpl;

/**
* This class is the factory class for GuestsApiService.
*/
public class GuestsApiServiceFactory {

private final static GuestsApiService service = new GuestsApiServiceImpl();
private final static GuestsApiService SERVICE = new GuestsApiServiceImpl();

/**
* Get GuestsApiService.
*
* @return GuestsApiService.
*/
public static GuestsApiService getGuestsApi()
{
return service;
return SERVICE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1.model.InvitationsListResponse;
import org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1.model.Property;
import org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1.model.RoleAssignmentResponse;
import org.wso2.carbon.identity.organization.user.invitation.management.InvitationCoreServiceImpl;
import org.wso2.carbon.identity.organization.user.invitation.management.InvitationCoreService;
import org.wso2.carbon.identity.organization.user.invitation.management.exception.UserInvitationMgtException;
import org.wso2.carbon.identity.organization.user.invitation.management.models.GroupAssignments;
import org.wso2.carbon.identity.organization.user.invitation.management.models.Invitation;
Expand Down Expand Up @@ -63,6 +63,13 @@
*/
public class GuestApiServiceCore {

private final InvitationCoreService invitationCoreService;

public GuestApiServiceCore(InvitationCoreService invitationCoreService) {

this.invitationCoreService = invitationCoreService;
}

private static List<RoleAssignmentResponse> buildRoleAssignmentResponse(Invitation invitationRecord) {

List<RoleAssignmentResponse> roleAssignmentResponseList = new ArrayList<>();
Expand Down Expand Up @@ -104,7 +111,6 @@ private static List<GroupAssignmentResponse> buildGroupAssignmentResponse(Invita
*/
public List<InvitationSuccessResponse> createInvitation(InvitationRequestBody invitationRequestBody) {

InvitationCoreServiceImpl invitationCoreService = new InvitationCoreServiceImpl();
InvitationDO invitation = new InvitationDO();
invitation.setUsernamesList(invitationRequestBody.getUsernames());
invitation.setUserDomain(invitationRequestBody.getUserDomain());
Expand Down Expand Up @@ -161,7 +167,6 @@ public InvitationsListResponse getInvitations(String filter, Integer limit, Inte
String sortBy) {

if (!isUnsupportedParamAvailable(limit, offset, sortOrder, sortBy)) {
InvitationCoreServiceImpl invitationCoreService = new InvitationCoreServiceImpl();
try {
return buildInvitationsListResponse(invitationCoreService.getInvitations(filter));
} catch (UserInvitationMgtException e) {
Expand Down Expand Up @@ -190,7 +195,6 @@ public InvitationsListResponse getInvitations(String filter, Integer limit, Inte
*/
public IntrospectSuccessResponse introspectInvitation(String confirmationCode) {

InvitationCoreServiceImpl invitationCoreService = new InvitationCoreServiceImpl();
try {
return buildValidateResponse(invitationCoreService.introspectInvitation(confirmationCode));
} catch (UserInvitationMgtException e) {
Expand All @@ -211,7 +215,6 @@ public IntrospectSuccessResponse introspectInvitation(String confirmationCode) {
*/
public boolean deleteInvitation(String invitationId) {

InvitationCoreServiceImpl invitationCoreService = new InvitationCoreServiceImpl();
try {
return invitationCoreService.deleteInvitation(invitationId);
} catch (UserInvitationMgtException e) {
Expand All @@ -233,7 +236,6 @@ public boolean deleteInvitation(String invitationId) {
*/
public void acceptInvitation(AcceptanceRequestBody acceptanceRequestBody) {

InvitationCoreServiceImpl invitationCoreService = new InvitationCoreServiceImpl();
try {
invitationCoreService.acceptInvitation(acceptanceRequestBody.getConfirmationCode());
} catch (UserInvitationMgtException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1.factories;

import org.wso2.carbon.identity.api.server.organization.user.invitation.management.common.UserInvitationMgtServiceHolder;
import org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1.core.GuestApiServiceCore;
import org.wso2.carbon.identity.organization.user.invitation.management.InvitationCoreService;

/**
* The factory class for GuestApiServiceCore.
*/
public class GuestApiServiceCoreFactory {

private static final GuestApiServiceCore SERVICE;

static {
InvitationCoreService invitationCoreService = UserInvitationMgtServiceHolder.getInvitationCoreService();

if (invitationCoreService == null) {
throw new IllegalStateException("InvitationCoreService is not available from OSGi context.");
}

SERVICE = new GuestApiServiceCore(invitationCoreService);
}

/**
* Get GuestApiServiceCore.
*
* @return GuestApiServiceCore.
*/
public static GuestApiServiceCore getGuestApiServiceCore() {

return SERVICE;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2023-2024, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand All @@ -18,9 +18,9 @@

package org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1.GuestsApiService;
import org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1.core.GuestApiServiceCore;
import org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1.factories.GuestApiServiceCoreFactory;
import org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1.model.AcceptanceRequestBody;
import org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1.model.IntrospectRequestBody;
import org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1.model.IntrospectSuccessResponse;
Expand All @@ -36,8 +36,16 @@
*/
public class GuestsApiServiceImpl implements GuestsApiService {

@Autowired
private GuestApiServiceCore guestApiServiceCore;
private final GuestApiServiceCore guestApiServiceCore;

public GuestsApiServiceImpl() {

try {
this.guestApiServiceCore = GuestApiServiceCoreFactory.getGuestApiServiceCore();
} catch (IllegalStateException e) {
throw new RuntimeException("Error occurred while initiating user invitation management services.", e);
}
}

@Override
public Response invitationAcceptPost(AcceptanceRequestBody acceptanceRequestBody) {
Expand Down
Loading