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 admin advisory management API #787

Merged
merged 2 commits into from
Jan 24, 2025
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 @@ -51,11 +51,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.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.admin.advisory.mgt</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 @@ -19,34 +19,26 @@
package org.wso2.carbon.identity.api.server.admin.advisory.management.common;

import org.wso2.carbon.admin.advisory.mgt.service.AdminAdvisoryManagementService;
import org.wso2.carbon.context.PrivilegedCarbonContext;

/**
* Service holder class for admin advisory management.
*/
public class AdminAdvisoryManagementServiceHolder {

private static AdminAdvisoryManagementService adminAdvisoryManagementService;
public AdminAdvisoryManagementServiceHolder() {}

/**
* Get admin advisory management service.
*/
public static AdminAdvisoryManagementService getAdminAdvisoryManagementService() {
private static class AdminAdvisoryServiceHolder {

return adminAdvisoryManagementService;
static final AdminAdvisoryManagementService SERVICE = (AdminAdvisoryManagementService) PrivilegedCarbonContext
.getThreadLocalCarbonContext().getOSGiService(AdminAdvisoryManagementService.class, null);
}

/**
* Set admin advisory management service.
*
* @param adminAdvisoryManagementService the admin advisory management service
* Get admin advisory management service.
*/
public static void setAdminAdvisoryManagementService
(AdminAdvisoryManagementService adminAdvisoryManagementService) {

AdminAdvisoryManagementServiceHolder.adminAdvisoryManagementService = adminAdvisoryManagementService;
}

private AdminAdvisoryManagementServiceHolder() {
public static AdminAdvisoryManagementService getAdminAdvisoryManagementService() {

return AdminAdvisoryServiceHolder.SERVICE;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,6 @@
<artifactId>cxf-rt-rs-service-description</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;

import org.wso2.carbon.identity.api.server.admin.advisory.management.v1.factories.AdminAdvisoryManagementApiServiceFactory;
import org.wso2.carbon.identity.api.server.admin.advisory.management.v1.model.AdminAdvisoryConfig;
import org.wso2.carbon.identity.api.server.admin.advisory.management.v1.model.Error;

Expand All @@ -44,8 +44,12 @@

public class AdminAdvisoryManagementApi {

@Autowired
private AdminAdvisoryManagementApiService delegate;
private final AdminAdvisoryManagementApiService delegate;

public AdminAdvisoryManagementApi() {

this.delegate = AdminAdvisoryManagementApiServiceFactory.getAdminAdvisoryManagementApi();
}

@Valid
@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@
*/
public class AdminAdvisoryManagementApiServiceFactory {

private static final AdminAdvisoryManagementApiService service = new AdminAdvisoryManagementApiServiceImpl();
private static final AdminAdvisoryManagementApiService SERVICE = new AdminAdvisoryManagementApiServiceImpl();

/**
* Get admin advisory management service.
*
* @return AdminAdvisoryManagementApiService
*/
public static AdminAdvisoryManagementApiService getAdminAdvisoryManagementApi() {
return service;

return SERVICE;
}

private AdminAdvisoryManagementApiServiceFactory() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.wso2.carbon.admin.advisory.mgt.exception.AdminAdvisoryMgtException;
import org.wso2.carbon.admin.advisory.mgt.service.AdminAdvisoryManagementService;
import org.wso2.carbon.identity.api.server.admin.advisory.management.common.AdminAdvisoryConstants;
import org.wso2.carbon.identity.api.server.admin.advisory.management.common.AdminAdvisoryManagementServiceHolder;
import org.wso2.carbon.identity.api.server.admin.advisory.management.v1.model.AdminAdvisoryConfig;
import org.wso2.carbon.identity.api.server.common.error.APIError;
import org.wso2.carbon.identity.api.server.common.error.ErrorResponse;
Expand All @@ -38,8 +37,14 @@
*/
public class ServerAdminAdvisoryManagementService {

private final AdminAdvisoryManagementService adminAdvisoryManagementService;
private static final Log LOG = LogFactory.getLog(ServerAdminAdvisoryManagementService.class);

public ServerAdminAdvisoryManagementService(AdminAdvisoryManagementService adminAdvisoryManagementService) {

this.adminAdvisoryManagementService = adminAdvisoryManagementService;
}

/**
* Get admin advisory configuration.
*
Expand All @@ -48,8 +53,6 @@ public class ServerAdminAdvisoryManagementService {
public AdminAdvisoryConfig getAdminAdvisoryConfig() {

try {
AdminAdvisoryManagementService adminAdvisoryManagementService = AdminAdvisoryManagementServiceHolder
.getAdminAdvisoryManagementService();
AdminAdvisoryBannerDTO adminAdvisoryBannerDTO = adminAdvisoryManagementService.getAdminAdvisoryConfig();

return buildAdminAdvisoryConfigResponse(adminAdvisoryBannerDTO);
Expand All @@ -70,8 +73,6 @@ public AdminAdvisoryConfig getAdminAdvisoryConfig() {
public void saveAdminAdvisoryConfig(AdminAdvisoryConfig adminAdvisoryConfig) {

try {
AdminAdvisoryManagementService adminAdvisoryManagementService = AdminAdvisoryManagementServiceHolder
.getAdminAdvisoryManagementService();
AdminAdvisoryBannerDTO modifiedAdminAdvisoryBannerDTO = createModifiedAdminAdvisoryBannerDTO(
adminAdvisoryManagementService.getAdminAdvisoryConfig(), adminAdvisoryConfig);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2025, 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.admin.advisory.management.v1.factories;

import org.wso2.carbon.admin.advisory.mgt.service.AdminAdvisoryManagementService;
import org.wso2.carbon.identity.api.server.admin.advisory.management.common.AdminAdvisoryManagementServiceHolder;
import org.wso2.carbon.identity.api.server.admin.advisory.management.v1.core.ServerAdminAdvisoryManagementService;

/**
* Service factory class for admin advisory management API.
*/
public class ServerAdminAdvisoryManagementServiceFactory {

private static final ServerAdminAdvisoryManagementService SERVICE;

static {
AdminAdvisoryManagementService adminAdvisoryManagementService = AdminAdvisoryManagementServiceHolder
.getAdminAdvisoryManagementService();

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

SERVICE = new ServerAdminAdvisoryManagementService(adminAdvisoryManagementService);
}

/**
* Get admin advisory management service.
*
* @return ServerAdminAdvisoryManagementService
*/
public static ServerAdminAdvisoryManagementService getServerAdminAdvisoryManagementService() {
lashinijay marked this conversation as resolved.
Show resolved Hide resolved

return SERVICE;
lashinijay marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

package org.wso2.carbon.identity.api.server.admin.advisory.management.v1.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.wso2.carbon.identity.api.server.admin.advisory.management.v1.AdminAdvisoryManagementApiService;
import org.wso2.carbon.identity.api.server.admin.advisory.management.v1.core.ServerAdminAdvisoryManagementService;
import org.wso2.carbon.identity.api.server.admin.advisory.management.v1.factories.ServerAdminAdvisoryManagementServiceFactory;
import org.wso2.carbon.identity.api.server.admin.advisory.management.v1.model.AdminAdvisoryConfig;

import javax.ws.rs.core.Response;
Expand All @@ -30,8 +30,17 @@
**/
public class AdminAdvisoryManagementApiServiceImpl implements AdminAdvisoryManagementApiService {

@Autowired
private ServerAdminAdvisoryManagementService adminAdvisoryManagementService;
private final ServerAdminAdvisoryManagementService adminAdvisoryManagementService;

public AdminAdvisoryManagementApiServiceImpl() {

try {
this.adminAdvisoryManagementService = ServerAdminAdvisoryManagementServiceFactory
.getServerAdminAdvisoryManagementService();
} catch (Exception e) {
throw new RuntimeException("Error occurred while initiating admin advisory management service.", e);
}
}

/**
* Endpoint to get the admin advisory banner configuration.
Expand Down

This file was deleted.

Loading