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 configuration API #705

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 All @@ -16,6 +16,7 @@
~ 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 @@ -47,11 +48,6 @@
<artifactId>org.wso2.carbon.identity.organization.config.service</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

</project>
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,14 +18,20 @@

package org.wso2.carbon.identity.api.server.organization.configs.common;

import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.organization.config.service.OrganizationConfigManager;

/**
* Service holder class for organization configuration management.
*/
public class OrganizationConfigsServiceHolder {

private static OrganizationConfigManager organizationConfigManager;
public OrganizationConfigsServiceHolder() {}

private static class OrganizationConfigManagerHolder {
static final OrganizationConfigManager SERVICE = (OrganizationConfigManager) PrivilegedCarbonContext
.getThreadLocalCarbonContext().getOSGiService(OrganizationConfigManager.class, null);
}

/**
* Get OrganizationConfigManager OSGi service.
Expand All @@ -34,16 +40,6 @@ public class OrganizationConfigsServiceHolder {
*/
public static OrganizationConfigManager getOrganizationConfigManager() {

return organizationConfigManager;
}

/**
* Set OrganizationConfigManager OSGi service.
*
* @param organizationConfigManager OrganizationConfigManager.
*/
public static void setOrganizationConfigManager(OrganizationConfigManager organizationConfigManager) {

OrganizationConfigsServiceHolder.organizationConfigManager = organizationConfigManager;
return OrganizationConfigManagerHolder.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 All @@ -16,6 +16,7 @@
~ 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 @@ -105,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,15 +18,14 @@

package org.wso2.carbon.identity.api.server.organization.configs.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.configs.v1.factories.OrganizationConfigsApiServiceFactory;
import org.wso2.carbon.identity.api.server.organization.configs.v1.model.Config;
import org.wso2.carbon.identity.api.server.organization.configs.v1.model.Error;
import org.wso2.carbon.identity.api.server.organization.configs.v1.OrganizationConfigsApiService;

import javax.validation.Valid;
import javax.ws.rs.*;
Expand All @@ -40,8 +39,12 @@

public class OrganizationConfigsApi {

@Autowired
private OrganizationConfigsApiService delegate;
private final OrganizationConfigsApiService delegate;

public OrganizationConfigsApi() {

this.delegate = OrganizationConfigsApiServiceFactory.getOrganizationConfigsApi();
}

@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.configs.v1.OrganizationConfigsApiService;
import org.wso2.carbon.identity.api.server.organization.configs.v1.impl.OrganizationConfigsApiServiceImpl;

/**
* Factory class for OrganizationConfigsApiService.
*/
public class OrganizationConfigsApiServiceFactory {

private final static OrganizationConfigsApiService service = new OrganizationConfigsApiServiceImpl();
private final static OrganizationConfigsApiService SERVICE = new OrganizationConfigsApiServiceImpl();

/**
* Get OrganizationConfigsApiService.
*
* @return OrganizationConfigsApiService.
*/
public static OrganizationConfigsApiService getOrganizationConfigsApi()
{
return service;
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 @@ -22,9 +22,9 @@
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.identity.api.server.common.error.APIError;
import org.wso2.carbon.identity.api.server.common.error.ErrorResponse;
import org.wso2.carbon.identity.api.server.organization.configs.common.OrganizationConfigsServiceHolder;
import org.wso2.carbon.identity.api.server.organization.configs.v1.model.Config;
import org.wso2.carbon.identity.api.server.organization.configs.v1.model.Properties;
import org.wso2.carbon.identity.organization.config.service.OrganizationConfigManager;
import org.wso2.carbon.identity.organization.config.service.exception.OrganizationConfigClientException;
import org.wso2.carbon.identity.organization.config.service.exception.OrganizationConfigException;
import org.wso2.carbon.identity.organization.config.service.model.ConfigProperty;
Expand All @@ -43,8 +43,14 @@
*/
public class OrganizationConfigsService {

private final OrganizationConfigManager organizationConfigManager;
private static final Log LOG = LogFactory.getLog(OrganizationConfigsService.class);

public OrganizationConfigsService(OrganizationConfigManager organizationConfigManager) {

this.organizationConfigManager = organizationConfigManager;
}

/**
* Add the organization discovery configuration in the primary organization.
*
Expand All @@ -56,8 +62,7 @@ public void addDiscoveryConfiguration(Config config) {
.map(property -> new ConfigProperty(property.getKey(), property.getValue()))
.collect(Collectors.toList());
try {
OrganizationConfigsServiceHolder.getOrganizationConfigManager().addDiscoveryConfiguration
(new DiscoveryConfig(configProperties));
organizationConfigManager.addDiscoveryConfiguration(new DiscoveryConfig(configProperties));
} catch (OrganizationConfigException e) {
throw handleException(e);
}
Expand All @@ -71,8 +76,7 @@ public void addDiscoveryConfiguration(Config config) {
public Config getDiscoveryConfiguration() {

try {
DiscoveryConfig discoveryConfig = OrganizationConfigsServiceHolder.getOrganizationConfigManager()
.getDiscoveryConfiguration();
DiscoveryConfig discoveryConfig = organizationConfigManager.getDiscoveryConfiguration();

List<Properties> properties = discoveryConfig.getConfigProperties().stream()
.map(configProperty -> {
Expand All @@ -95,7 +99,7 @@ public Config getDiscoveryConfiguration() {
public void deleteDiscoveryConfiguration() {

try {
OrganizationConfigsServiceHolder.getOrganizationConfigManager().deleteDiscoveryConfiguration();
organizationConfigManager.deleteDiscoveryConfiguration();
} catch (OrganizationConfigException e) {
throw handleException(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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.configs.v1.factories;

import org.wso2.carbon.identity.api.server.organization.configs.common.OrganizationConfigsServiceHolder;
import org.wso2.carbon.identity.api.server.organization.configs.v1.core.OrganizationConfigsService;
import org.wso2.carbon.identity.organization.config.service.OrganizationConfigManager;

/**
* Factory class for OrganizationConfigsService.
*/
public class OrganizationConfigsServiceFactory {

private static final OrganizationConfigsService SERVICE;

static {
OrganizationConfigManager organizationConfigManager = OrganizationConfigsServiceHolder
.getOrganizationConfigManager();

if (organizationConfigManager == null) {
throw new IllegalStateException("OrganizationConfigManager service is not available from OSGi context.");
}

SERVICE = new OrganizationConfigsService(organizationConfigManager);
}

/**
* Get OrganizationConfigsService.
*
* @return OrganizationConfigsService.
*/
public static OrganizationConfigsService getOrganizationConfigsService() {

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.configs.v1.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.wso2.carbon.identity.api.server.organization.configs.v1.OrganizationConfigsApiService;
import org.wso2.carbon.identity.api.server.organization.configs.v1.core.OrganizationConfigsService;
import org.wso2.carbon.identity.api.server.organization.configs.v1.factories.OrganizationConfigsServiceFactory;
import org.wso2.carbon.identity.api.server.organization.configs.v1.model.Config;

import javax.ws.rs.core.Response;
Expand All @@ -30,8 +30,15 @@
*/
public class OrganizationConfigsApiServiceImpl implements OrganizationConfigsApiService {

@Autowired
private OrganizationConfigsService organizationConfigsService;
private final OrganizationConfigsService organizationConfigsService;

public OrganizationConfigsApiServiceImpl() {
try {
this.organizationConfigsService = OrganizationConfigsServiceFactory.getOrganizationConfigsService();
} catch (IllegalStateException e) {
throw new RuntimeException("Error occurred while initiating organization configuration service.", e);
}
}

@Override
public Response createDiscoveryConfig(Config config) {
Expand Down
Loading