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 extension management API #695

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,18 +1,20 @@
<?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).
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ 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.
~ 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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
Expand Down Expand Up @@ -45,11 +47,6 @@
</build>

<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>org.wso2.carbon.identity.extension.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 @@ -18,46 +18,28 @@

package org.wso2.carbon.identity.api.server.extension.management.common;

import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.extension.mgt.ExtensionManager;

/**
* Extension management service holder.
*/
public class ExtensionManagementServiceHolder {

private static ExtensionManagementServiceHolder instance = new ExtensionManagementServiceHolder();

private ExtensionManager extensionManager;

private ExtensionManagementServiceHolder() {}

/**
* Get instance of ExtensionManagementServiceHolder.
*
* @return ExtensionManagementServiceHolder.
*/
public static ExtensionManagementServiceHolder getInstance() {

return instance;
private static class ExtensionManagerHolder {
static final ExtensionManager SERVICE = (ExtensionManager) PrivilegedCarbonContext
.getThreadLocalCarbonContext().getOSGiService(ExtensionManager.class, null);
}

/**
* Get ExtensionManager osgi service.
*
* @return ApplicationManagementService
*/
public ExtensionManager getExtensionManager() {

return ExtensionManagementServiceHolder.getInstance().extensionManager;
}

/**
* Set ExtensionManager osgi service.
*
* @param extensionManager ExtensionManager.
* @return ExtensionManager
*/
public void setExtensionManager(ExtensionManager extensionManager) {
public static ExtensionManager getExtensionManager() {

ExtensionManagementServiceHolder.getInstance().extensionManager = extensionManager;
return ExtensionManagerHolder.SERVICE;
}
}

This file was deleted.

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 Down Expand Up @@ -100,7 +100,7 @@ private static ErrorResponse.Builder getErrorBuilder(ExtensionMgtConstants.Error
*/
public static void validateExtensionType(String extensionType) {

if (!ArrayUtils.contains(ExtensionManagementServiceHolder.getInstance().getExtensionManager()
if (!ArrayUtils.contains(ExtensionManagementServiceHolder.getExtensionManager()
.getExtensionTypes(), extensionType)) {
throw handleClientException(Response.Status.BAD_REQUEST, ExtensionMgtConstants.ErrorMessage
.ERROR_CODE_INVALID_EXTENSION_TYPE, extensionType);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
<?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).
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ 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.
~ 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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -103,11 +106,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
@@ -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.extension.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.extension.management.v1.factories.ExtensionsApiServiceFactory;
import org.wso2.carbon.identity.api.server.extension.management.v1.model.Error;
import org.wso2.carbon.identity.api.server.extension.management.v1.model.ExtensionListItem;
import org.wso2.carbon.identity.api.server.extension.management.v1.model.ExtensionResponseModel;
Expand All @@ -42,8 +42,12 @@

public class ExtensionsApi {

@Autowired
private ExtensionsApiService delegate;
private final ExtensionsApiService delegate;

public ExtensionsApi() {

this.delegate = ExtensionsApiServiceFactory.getExtensionsApi();
}

@Valid
@GET
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.extension.management.v1.ExtensionsApiService;
import org.wso2.carbon.identity.api.server.extension.management.v1.impl.ExtensionsApiServiceImpl;

/**
* Extensions Api Service Factory.
*/
public class ExtensionsApiServiceFactory {

private final static ExtensionsApiService service = new ExtensionsApiServiceImpl();
private final static ExtensionsApiService SERVICE = new ExtensionsApiServiceImpl();

/**
* Get Extensions Api Service.
*
* @return ExtensionsApiService
*/
public static ExtensionsApiService getExtensionsApi()
{
return service;
return SERVICE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class ExtensionsApiServiceImpl implements ExtensionsApiService {
@Override
public Response listExtensions() {

List<ExtensionInfo> extensionInfoList = ExtensionManagementServiceHolder.getInstance().getExtensionManager()
List<ExtensionInfo> extensionInfoList = ExtensionManagementServiceHolder.getExtensionManager()
.getExtensions();
return Response.ok().entity(extensionInfoList.stream().map(new
ExtensionListItemBuilder()).collect(Collectors.toList())).build();
Expand All @@ -66,7 +66,7 @@ public Response listExtensionsByType(String extensionType) {
// TODO: Add pagination support.
validateExtensionType(extensionType);
try {
List<ExtensionInfo> extensionInfoList = ExtensionManagementServiceHolder.getInstance().getExtensionManager()
List<ExtensionInfo> extensionInfoList = ExtensionManagementServiceHolder.getExtensionManager()
.getExtensionsByType(extensionType);
return Response.ok().entity(extensionInfoList.stream().map(new
ExtensionListItemBuilder()).collect(Collectors.toList())).build();
Expand All @@ -88,7 +88,7 @@ public Response getExtensionInfoById(String extensionType, String extensionId) {

validateExtensionType(extensionType);
try {
ExtensionInfo extensionInfo = ExtensionManagementServiceHolder.getInstance().getExtensionManager()
ExtensionInfo extensionInfo = ExtensionManagementServiceHolder.getExtensionManager()
.getExtensionByTypeAndId(extensionType, extensionId);
if (extensionInfo == null) {
throw ExtensionMgtUtils.handleClientException(Response.Status.NOT_FOUND,
Expand All @@ -113,7 +113,7 @@ public Response getTemplateById(String extensionType, String extensionId) {

validateExtensionType(extensionType);
try {
JSONObject template = ExtensionManagementServiceHolder.getInstance().getExtensionManager()
JSONObject template = ExtensionManagementServiceHolder.getExtensionManager()
.getExtensionTemplate(extensionType, extensionId);
if (template == null) {
throw ExtensionMgtUtils.handleClientException(Response.Status.NOT_FOUND,
Expand All @@ -138,7 +138,7 @@ public Response getMetadataById(String extensionType, String extensionId) {

validateExtensionType(extensionType);
try {
JSONObject metadata = ExtensionManagementServiceHolder.getInstance().getExtensionManager()
JSONObject metadata = ExtensionManagementServiceHolder.getExtensionManager()
.getExtensionMetadata(extensionType, extensionId);
if (metadata == null) {
throw ExtensionMgtUtils.handleClientException(Response.Status.NOT_FOUND,
Expand Down

This file was deleted.