-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #415 from dhaura/DP-add-b2b-resource-resolver
Introduce Generic Organization Resource Resolver
- Loading branch information
Showing
20 changed files
with
2,561 additions
and
0 deletions.
There are no files selected for viewing
222 changes: 222 additions & 0 deletions
222
components/org.wso2.carbon.identity.organization.resource.hierarchy.traverse.service/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
~ 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. | ||
--> | ||
|
||
<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/maven-v4_0_0.xsd"> | ||
|
||
<parent> | ||
<groupId>org.wso2.carbon.identity.organization.management</groupId> | ||
<artifactId>identity-organization-management</artifactId> | ||
<version>1.4.58-SNAPSHOT</version> | ||
<relativePath>../../pom.xml</relativePath> | ||
</parent> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>org.wso2.carbon.identity.organization.resource.hierarchy.traverse.service</artifactId> | ||
<name>WSO2 - Organization Resource Hierarchy Traverse Service</name> | ||
<packaging>bundle</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.wso2.carbon</groupId> | ||
<artifactId>org.wso2.carbon.utils</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-collections.wso2</groupId> | ||
<artifactId>commons-collections</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.ops4j.pax.logging</groupId> | ||
<artifactId>pax-logging-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.wso2.carbon.identity.framework</groupId> | ||
<artifactId>org.wso2.carbon.identity.application.mgt</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.wso2.carbon.identity.organization.management.core</groupId> | ||
<artifactId>org.wso2.carbon.identity.organization.management.service</artifactId> | ||
</dependency> | ||
|
||
<!-- Test dependencies --> | ||
<dependency> | ||
<groupId>org.testng</groupId> | ||
<artifactId>testng</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jacoco</groupId> | ||
<artifactId>org.jacoco.agent</artifactId> | ||
<classifier>runtime</classifier> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-inline</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.felix</groupId> | ||
<artifactId>maven-bundle-plugin</artifactId> | ||
<extensions>true</extensions> | ||
<configuration> | ||
<instructions> | ||
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> | ||
<Bundle-Name>${project.artifactId}</Bundle-Name> | ||
<Private-Package> | ||
org.wso2.carbon.identity.organization.resource.hierarchy.traverse.service.constant, | ||
org.wso2.carbon.identity.organization.resource.hierarchy.traverse.service.internal, | ||
org.wso2.carbon.identity.organization.resource.hierarchy.traverse.service.util | ||
</Private-Package> | ||
<Import-Package> | ||
org.apache.commons.lang; version="${org.apache.commons.lang.imp.pkg.version.range}", | ||
org.apache.commons.logging; version="${org.apache.commons.logging.imp.pkg.version.range}", | ||
org.apache.commons.collections; version="${org.apache.commons.collections.imp.pkg.version.range}", | ||
|
||
org.osgi.framework; version="${osgi.framework.imp.pkg.version.range}", | ||
org.osgi.service.component; version="${osgi.service.component.imp.pkg.version.range}", | ||
|
||
org.wso2.carbon.identity.application.mgt; | ||
version="${carbon.identity.package.import.version.range}", | ||
org.wso2.carbon.identity.application.common; | ||
version="${carbon.identity.package.import.version.range}", | ||
|
||
org.wso2.carbon.identity.organization.management.service; | ||
version="${org.wso2.identity.organization.mgt.core.imp.pkg.version.range}", | ||
org.wso2.carbon.identity.organization.management.service.exception; | ||
version="${org.wso2.identity.organization.mgt.core.imp.pkg.version.range}", | ||
org.wso2.carbon.identity.organization.management.service.util; | ||
version="${org.wso2.identity.organization.mgt.core.imp.pkg.version.range}" | ||
</Import-Package> | ||
<Export-Package> | ||
!org.wso2.carbon.identity.organization.resource.hierarchy.traverse.service.constant, | ||
!org.wso2.carbon.identity.organization.resource.hierarchy.traverse.service.internal, | ||
!org.wso2.carbon.identity.organization.resource.hierarchy.traverse.service.util, | ||
org.wso2.carbon.identity.organization.resource.hierarchy.traverse.service, | ||
org.wso2.carbon.identity.organization.resource.hierarchy.traverse.service.exception, | ||
org.wso2.carbon.identity.organization.resource.hierarchy.traverse.service.strategy; | ||
version="${project.version}" | ||
</Export-Package> | ||
</instructions> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-checkstyle-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>${maven.surefire.plugin.version}</version> | ||
<configuration> | ||
<!--suppress UnresolvedMavenProperty --> | ||
<argLine> | ||
${argLine} | ||
--add-opens java.xml/jdk.xml.internal=ALL-UNNAMED | ||
--add-opens=java.base/jdk.internal.loader=ALL-UNNAMED | ||
</argLine> | ||
<suiteXmlFiles> | ||
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile> | ||
</suiteXmlFiles> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.jacoco</groupId> | ||
<artifactId>jacoco-maven-plugin</artifactId> | ||
<version>${jacoco.version}</version> | ||
<configuration> | ||
<excludes> | ||
<exclude>org/wso2/carbon/identity/organization/resource/hierarchy/traverse/service/constant/*.class</exclude> | ||
<exclude>org/wso2/carbon/identity/organization/resource/hierarchy/traverse/service/exception/*.class</exclude> | ||
<exclude>org/wso2/carbon/identity/organization/resource/hierarchy/traverse/service/internal/*.class</exclude> | ||
<exclude>org/wso2/carbon/identity/organization/resource/hierarchy/traverse/service/strategy/AggregationStrategy.class</exclude> | ||
<exclude>org/wso2/carbon/identity/organization/resource/hierarchy/traverse/service/OrgResourceResolverService.class</exclude> | ||
</excludes> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>default-prepare-agent</id> | ||
<goals> | ||
<goal>prepare-agent</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>default-prepare-agent-integration</id> | ||
<goals> | ||
<goal>prepare-agent-integration</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>default-report</id> | ||
<goals> | ||
<goal>report</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>default-report-integration</id> | ||
<goals> | ||
<goal>report-integration</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>default-check</id> | ||
<goals> | ||
<goal>check</goal> | ||
</goals> | ||
<configuration> | ||
<rules> | ||
<rule implementation="org.jacoco.maven.RuleConfiguration"> | ||
<element>BUNDLE</element> | ||
<limits> | ||
<limit implementation="org.jacoco.report.check.Limit"> | ||
<counter>COMPLEXITY</counter> | ||
<value>COVEREDRATIO</value> | ||
<minimum>0.60</minimum> | ||
</limit> | ||
</limits> | ||
</rule> | ||
</rules> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>com.github.spotbugs</groupId> | ||
<artifactId>spotbugs-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>8</source> | ||
<target>8</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
77 changes: 77 additions & 0 deletions
77
...identity/organization/resource/hierarchy/traverse/service/OrgResourceResolverService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* 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.organization.resource.hierarchy.traverse.service; | ||
|
||
import org.wso2.carbon.identity.organization.resource.hierarchy.traverse.service.exception.OrgResourceHierarchyTraverseException; | ||
import org.wso2.carbon.identity.organization.resource.hierarchy.traverse.service.strategy.AggregationStrategy; | ||
|
||
import java.util.Optional; | ||
import java.util.function.BiFunction; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* Provides a service interface to retrieve resources from an organization's hierarchy. | ||
* Supports traversal of both organization and application hierarchies using customizable | ||
* resource retrieval and aggregation strategies. | ||
* <p> | ||
* The service is designed for extensibility, allowing clients to define their own retrieval logic | ||
* and aggregation mechanisms via functional interfaces and strategy patterns. | ||
*/ | ||
public interface OrgResourceResolverService { | ||
|
||
/** | ||
* Retrieves resources by traversing the hierarchy of a given organization. | ||
* | ||
* @param organizationId The unique identifier of the organization. | ||
* @param resourceRetriever A function that defines how to fetch a resource for a given organization ID. | ||
* The function must return an {@link Optional<T>} containing the resource if found, | ||
* or an empty {@link Optional<T>} if not. | ||
* @param aggregationStrategy A strategy defining how to aggregate resources retrieved from | ||
* different levels of the hierarchy. | ||
* @param <T> The type of the resource being retrieved and aggregated. | ||
* @return An aggregated resource of type <T> obtained from the organization hierarchy. | ||
* @throws OrgResourceHierarchyTraverseException If any errors occur during resource retrieval | ||
* or aggregation. | ||
*/ | ||
<T> T getResourcesFromOrgHierarchy(String organizationId, | ||
Function<String, Optional<T>> resourceRetriever, | ||
AggregationStrategy<T> aggregationStrategy) | ||
throws OrgResourceHierarchyTraverseException; | ||
|
||
/** | ||
* Retrieves resources by traversing the hierarchy of a given organization and application. | ||
* | ||
* @param organizationId The unique identifier of the organization. | ||
* @param applicationId The unique identifier of the application within the organization. | ||
* @param resourceRetriever A bi-function that defines how to fetch a resource based on the | ||
* organization and application IDs. The function must return an | ||
* {@link Optional<T>} containing the resource if found, | ||
* or an empty {@link Optional<T>} if not. | ||
* @param aggregationStrategy A strategy defining how to aggregate resources retrieved from | ||
* different levels of the hierarchy. | ||
* @param <T> The type of the resource being retrieved and aggregated. | ||
* @return An aggregated resource of type <T> obtained from the organization and application hierarchy. | ||
* @throws OrgResourceHierarchyTraverseException If any errors occur during resource retrieval | ||
* or aggregation. | ||
*/ | ||
<T> T getResourcesFromOrgHierarchy(String organizationId, String applicationId, | ||
BiFunction<String, String, Optional<T>> resourceRetriever, | ||
AggregationStrategy<T> aggregationStrategy) | ||
throws OrgResourceHierarchyTraverseException; | ||
} |
Oops, something went wrong.