Skip to content

Commit

Permalink
remove spring dependency from rule.metadata component
Browse files Browse the repository at this point in the history
  • Loading branch information
lashinijay committed Jan 11, 2025
1 parent 029069c commit 05b15d6
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 102 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2024-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
Expand All @@ -18,22 +18,25 @@

package org.wso2.carbon.identity.api.server.rule.metadata.common;

import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.rule.metadata.service.RuleMetadataService;

/**
* Service holder class for Rule Metadata Service.
*/
public class RuleMetadataServiceHolder {

private static RuleMetadataService ruleMetadataService;
public RuleMetadataServiceHolder() {}

public static RuleMetadataService getRuleMetadataService() {
private static class ServerRuleMetadataServiceHolder {

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

public static void setRuleMetadataService(RuleMetadataService ruleMetadataService) {
public static RuleMetadataService getRuleMetadataService() {

RuleMetadataServiceHolder.ruleMetadataService = ruleMetadataService;
return ServerRuleMetadataServiceHolder.SERVICE;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

package org.wso2.carbon.identity.api.server.rule.metadata.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.rule.metadata.v1.factories.RulesApiServiceFactory;
import org.wso2.carbon.identity.api.server.rule.metadata.v1.model.Error;
import org.wso2.carbon.identity.api.server.rule.metadata.v1.model.FieldDefinition;
import org.wso2.carbon.identity.api.server.rule.metadata.v1.RulesApiService;
Expand All @@ -40,9 +40,12 @@

public class RulesApi {

@Autowired
private RulesApiService delegate;
private final RulesApiService delegate;

public RulesApi() {

this.delegate = RulesApiServiceFactory.getRulesApi();
}
@Valid
@GET
@Path("/metadata")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@

public class RulesApiServiceFactory {

private final static RulesApiService service = new RulesApiServiceImpl();
private final static RulesApiService SERVICE = new RulesApiServiceImpl();

public static RulesApiService getRulesApi()
{
return service;
return SERVICE;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2024-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
Expand All @@ -19,7 +19,6 @@
package org.wso2.carbon.identity.api.server.rule.metadata.v1.core;

import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.identity.api.server.rule.metadata.common.RuleMetadataServiceHolder;
import org.wso2.carbon.identity.api.server.rule.metadata.v1.model.Field;
import org.wso2.carbon.identity.api.server.rule.metadata.v1.model.Link;
import org.wso2.carbon.identity.api.server.rule.metadata.v1.util.RuleMetadataAPIErrorBuilder;
Expand All @@ -32,6 +31,7 @@
import org.wso2.carbon.identity.rule.metadata.model.OptionsReferenceValue;
import org.wso2.carbon.identity.rule.metadata.model.OptionsValue;
import org.wso2.carbon.identity.rule.metadata.model.Value;
import org.wso2.carbon.identity.rule.metadata.service.RuleMetadataService;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -41,6 +41,12 @@
*/
public class ServerRuleMetadataService {

private final RuleMetadataService ruleMetadataService;

public ServerRuleMetadataService(RuleMetadataService ruleMetadataService) {

this.ruleMetadataService = ruleMetadataService;
}
/**
* Get the expression metadata for the given flow.
* @param flow Flow type
Expand All @@ -52,8 +58,7 @@ public List<org.wso2.carbon.identity.api.server.rule.metadata.v1.model.FieldDefi
try {
FlowType flowType = FlowType.valueOfFlowAlias(flow);

List<FieldDefinition> fieldDefinitions =
RuleMetadataServiceHolder.getRuleMetadataService().getExpressionMeta(flowType,
List<FieldDefinition> fieldDefinitions = ruleMetadataService.getExpressionMeta(flowType,
CarbonContext.getThreadLocalCarbonContext().getTenantDomain());

List<org.wso2.carbon.identity.api.server.rule.metadata.v1.model.FieldDefinition>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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.rule.metadata.v1.factories;

import org.wso2.carbon.identity.api.server.rule.metadata.common.RuleMetadataServiceHolder;
import org.wso2.carbon.identity.api.server.rule.metadata.v1.core.ServerRuleMetadataService;
import org.wso2.carbon.identity.rule.metadata.service.RuleMetadataService;

public class ServerRuleMetadataServiceFactory {

private static final ServerRuleMetadataService SERVICE;

static {
RuleMetadataService ruleMetadataService = RuleMetadataServiceHolder.getRuleMetadataService();
if (ruleMetadataService == null) {
throw new IllegalStateException("RuleMetadataService not available from OSGI context.");
}
SERVICE = new ServerRuleMetadataService(ruleMetadataService);
}

public static ServerRuleMetadataService getServerRuleMetadataService() {

return SERVICE;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2024-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
Expand All @@ -18,9 +18,9 @@

package org.wso2.carbon.identity.api.server.rule.metadata.v1.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.wso2.carbon.identity.api.server.rule.metadata.v1.RulesApiService;
import org.wso2.carbon.identity.api.server.rule.metadata.v1.core.ServerRuleMetadataService;
import org.wso2.carbon.identity.api.server.rule.metadata.v1.factories.ServerRuleMetadataServiceFactory;

import javax.ws.rs.core.Response;

Expand All @@ -29,8 +29,16 @@
*/
public class RulesApiServiceImpl implements RulesApiService {

@Autowired
private ServerRuleMetadataService serverRuleMetadataService;
private final ServerRuleMetadataService serverRuleMetadataService;

public RulesApiServiceImpl() {

try {
this.serverRuleMetadataService = ServerRuleMetadataServiceFactory.getServerRuleMetadataService();
} catch (IllegalStateException e) {
throw new RuntimeException("Error occurred while initiating serverRuleMetadataService.", e);
}
}

@Override
public Response getExpressionMeta(String flow) {
Expand Down

This file was deleted.

0 comments on commit 05b15d6

Please sign in to comment.