-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial import sdk with schema visible, not working since plugin init…
…ialization needs schema classes which are not available during sdk doesn't load something
- Loading branch information
Showing
26 changed files
with
466 additions
and
269 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
midpoint-sdk-api/src/main/java/com/evolveum/midpoint/sdk/api/SdkComponent.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,13 @@ | ||
package com.evolveum.midpoint.sdk.api; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
public @interface SdkComponent { | ||
|
||
Class<?> type(); | ||
} |
73 changes: 73 additions & 0 deletions
73
midpoint-sdk-api/src/main/java/com/evolveum/midpoint/sdk/api/SdkContext.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,73 @@ | ||
package com.evolveum.midpoint.sdk.api; | ||
|
||
import com.evolveum.midpoint.prism.PrismContext; | ||
import com.evolveum.midpoint.sdk.api.lang.AuthorizationActionProvider; | ||
import com.evolveum.midpoint.sdk.api.lang.ExpressionVariablesProvider; | ||
import com.evolveum.midpoint.sdk.api.lang.TaskHandlerProvider; | ||
|
||
public class SdkContext { | ||
|
||
private PrismContext prismContext; | ||
|
||
private TaskHandlerProvider taskHandlerProvider; | ||
|
||
private AuthorizationActionProvider authorizationActionProvider; | ||
|
||
private ExpressionVariablesProvider expressionVariablesProvider; | ||
|
||
public PrismContext prismContext() { | ||
return prismContext; | ||
} | ||
|
||
public TaskHandlerProvider taskHandlerProvider() { | ||
return taskHandlerProvider; | ||
} | ||
|
||
public AuthorizationActionProvider authorizationActionProvider() { | ||
return authorizationActionProvider; | ||
} | ||
|
||
public ExpressionVariablesProvider expressionVariablesProvider() { | ||
return expressionVariablesProvider; | ||
} | ||
|
||
public static class Builder { | ||
|
||
private PrismContext prismContext; | ||
|
||
private TaskHandlerProvider taskHandlerProvider; | ||
|
||
private AuthorizationActionProvider authorizationActionProvider; | ||
|
||
private ExpressionVariablesProvider expressionVariablesProvider; | ||
|
||
public Builder prismContext(PrismContext prismContext) { | ||
this.prismContext = prismContext; | ||
return this; | ||
} | ||
|
||
public Builder taskHandlerProvider(TaskHandlerProvider taskHandlerProvider) { | ||
this.taskHandlerProvider = taskHandlerProvider; | ||
return this; | ||
} | ||
|
||
public Builder authorizationActionProvider(AuthorizationActionProvider authorizationActionProvider) { | ||
this.authorizationActionProvider = authorizationActionProvider; | ||
return this; | ||
} | ||
|
||
public Builder expressionVariablesProvider(ExpressionVariablesProvider expressionVariablesProvider) { | ||
this.expressionVariablesProvider = expressionVariablesProvider; | ||
return this; | ||
} | ||
|
||
public SdkContext build() { | ||
SdkContext sdkContext = new SdkContext(); | ||
sdkContext.prismContext = prismContext; | ||
sdkContext.taskHandlerProvider = taskHandlerProvider; | ||
sdkContext.authorizationActionProvider = authorizationActionProvider; | ||
sdkContext.expressionVariablesProvider = expressionVariablesProvider; | ||
return sdkContext; | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
midpoint-sdk-api/src/main/java/com/evolveum/midpoint/sdk/api/SdkContextFactory.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,6 @@ | ||
package com.evolveum.midpoint.sdk.api; | ||
|
||
public interface SdkContextFactory { | ||
|
||
SdkContext creatContext() throws SdkException; | ||
} |
12 changes: 12 additions & 0 deletions
12
midpoint-sdk-api/src/main/java/com/evolveum/midpoint/sdk/api/SdkException.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,12 @@ | ||
package com.evolveum.midpoint.sdk.api; | ||
|
||
public class SdkException extends Exception { | ||
|
||
public SdkException(String message) { | ||
super(message); | ||
} | ||
|
||
public SdkException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
midpoint-sdk-api/src/main/java/com/evolveum/midpoint/sdk/api/SdkFactory.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,102 @@ | ||
package com.evolveum.midpoint.sdk.api; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import io.github.classgraph.ClassGraph; | ||
import io.github.classgraph.ScanResult; | ||
import org.apache.commons.lang3.Validate; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.boot.loader.LaunchedURLClassLoader; | ||
import org.springframework.boot.loader.archive.Archive; | ||
import org.springframework.boot.loader.archive.JarFileArchive; | ||
|
||
import java.io.File; | ||
import java.lang.annotation.Annotation; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.util.*; | ||
|
||
public class SdkFactory { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(SdkFactory.class); | ||
|
||
private File sdkFile; | ||
|
||
public SdkFactory sdkFile(File sdkFile) { | ||
this.sdkFile = sdkFile; | ||
return this; | ||
} | ||
|
||
public SdkContext build() throws SdkException { | ||
Validate.notNull(sdkFile, "SDK jar file must be set"); | ||
|
||
if (!sdkFile.exists() || !sdkFile.canRead() || !sdkFile.isFile()) { | ||
throw new IllegalArgumentException("SDK jar file does not exist or is not readable"); | ||
} | ||
|
||
try { | ||
Archive archive = new JarFileArchive(sdkFile); | ||
|
||
List<URL> urls = new ArrayList<>(); | ||
urls.add(archive.getUrl()); | ||
|
||
Iterator<Archive> iterator = archive.getNestedArchives(null, (entry) -> { | ||
if (entry.isDirectory()) { | ||
return entry.getName().equals("BOOT-INF/classes/"); | ||
} | ||
return entry.getName().startsWith("BOOT-INF/lib/"); | ||
}); | ||
|
||
ImmutableList.copyOf(iterator).forEach(a -> { | ||
try { | ||
urls.add(a.getUrl()); | ||
} catch (MalformedURLException e) { | ||
e.printStackTrace(); // todo fix | ||
} | ||
}); | ||
|
||
LaunchedURLClassLoader classLoader = new LaunchedURLClassLoader( | ||
false, archive, urls.toArray(new URL[0]), Thread.currentThread().getContextClassLoader()); | ||
|
||
@SuppressWarnings("unchecked") | ||
Class<? extends SdkContextFactory> factoryClass = (Class<? extends SdkContextFactory>) | ||
scanClasses(classLoader, SdkComponent.class, "com.evolveum.midpoint.sdk") | ||
.stream() | ||
.filter(c -> Objects.equals(c.getAnnotation(SdkComponent.class).type(), SdkContextFactory.class)) | ||
.filter(c -> SdkContextFactory.class.isAssignableFrom(c)) | ||
.findFirst() | ||
.orElse(null); | ||
|
||
if (factoryClass == null) { | ||
throw new SdkException("Couldn't find SDK context factory class annotated with @SdkComponent"); | ||
} | ||
|
||
SdkContextFactory factory = factoryClass.getConstructor().newInstance(); | ||
return factory.creatContext(); | ||
} catch (Exception ex) { | ||
throw new SdkException("Couldn't build SDK context", ex); | ||
} | ||
} | ||
|
||
Collection<Class<?>> scanClasses( | ||
ClassLoader classLoader, Class<? extends Annotation> annotationClass, String... packageNames) { | ||
|
||
LOG.debug("Scanning classes for: {} with package scope: {}", annotationClass, packageNames); | ||
|
||
try (ScanResult scanResult = new ClassGraph() | ||
.overrideClassLoaders(classLoader) | ||
.acceptPackages(packageNames) | ||
.enableClassInfo() | ||
.enableAnnotationInfo() | ||
.scan()) { | ||
|
||
List<Class<?>> classes = scanResult | ||
.getClassesWithAnnotation(annotationClass) | ||
.loadClasses(); | ||
|
||
LOG.debug("Found {} classes with annotation {}", classes.size(), annotationClass.getName()); | ||
|
||
return classes; | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
midpoint-sdk-api/src/main/java/com/evolveum/midpoint/sdk/api/SdkInfo.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,8 @@ | ||
package com.evolveum.midpoint.sdk.api; | ||
|
||
public interface SdkInfo { | ||
|
||
String getVersion(); | ||
|
||
String getName(); | ||
} |
46 changes: 46 additions & 0 deletions
46
midpoint-sdk-api/src/main/java/com/evolveum/midpoint/sdk/api/lang/Action.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,46 @@ | ||
package com.evolveum.midpoint.sdk.api.lang; | ||
|
||
import javax.xml.namespace.QName; | ||
import java.util.Comparator; | ||
import java.util.Objects; | ||
|
||
public class Action implements Comparable<Action> { | ||
|
||
private QName name; | ||
|
||
private String source; | ||
|
||
public Action(QName name, String source) { | ||
this.name = name; | ||
this.source = source; | ||
} | ||
|
||
public QName name() { | ||
return name; | ||
} | ||
|
||
public String source() { | ||
return source; | ||
} | ||
|
||
@Override | ||
public int compareTo(Action o) { | ||
String q1 = name != null ? name.getLocalPart() : null; | ||
String q2 = o != null && o.name != null ? o.name.getLocalPart() : null; | ||
|
||
return Comparator.<String>naturalOrder().compare(q1, q2); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Action action = (Action) o; | ||
return Objects.equals(name, action.name) && Objects.equals(source, action.source); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(name, source); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...sdk-api/src/main/java/com/evolveum/midpoint/sdk/api/lang/AuthorizationActionProvider.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,8 @@ | ||
package com.evolveum.midpoint.sdk.api.lang; | ||
|
||
import java.util.Set; | ||
|
||
public interface AuthorizationActionProvider { | ||
|
||
Set<Action> getActions(); | ||
} |
10 changes: 10 additions & 0 deletions
10
...sdk-api/src/main/java/com/evolveum/midpoint/sdk/api/lang/ExpressionVariablesProvider.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,10 @@ | ||
package com.evolveum.midpoint.sdk.api.lang; | ||
|
||
import java.util.Map; | ||
|
||
public interface ExpressionVariablesProvider { | ||
|
||
// todo parameters describing the context of the expression evaluation | ||
// eg. type of the object being evaluated, type of the expression, place (template, policy rule, assingment target search, ...) | ||
Map<String, Variable> getVariables(); | ||
} |
8 changes: 8 additions & 0 deletions
8
midpoint-sdk-api/src/main/java/com/evolveum/midpoint/sdk/api/lang/TaskHandlerProvider.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,8 @@ | ||
package com.evolveum.midpoint.sdk.api.lang; | ||
|
||
import java.util.Set; | ||
|
||
public interface TaskHandlerProvider { | ||
|
||
Set<String> getTaskHandlerUris(); | ||
} |
43 changes: 43 additions & 0 deletions
43
midpoint-sdk-api/src/main/java/com/evolveum/midpoint/sdk/api/lang/Variable.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,43 @@ | ||
package com.evolveum.midpoint.sdk.api.lang; | ||
|
||
import java.util.Objects; | ||
|
||
public class Variable<T, I extends T> { | ||
|
||
private String name; | ||
|
||
private Class<T> type; | ||
|
||
private Class<I> implementation; | ||
|
||
public Variable(String name, Class<T> type, Class<I> implementation) { | ||
this.name = name; | ||
this.type = type; | ||
this.implementation = implementation; | ||
} | ||
|
||
public String name() { | ||
return name; | ||
} | ||
|
||
public Class<T> type() { | ||
return type; | ||
} | ||
|
||
public Class<I> implementation() { | ||
return implementation; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Variable<?, ?> variable = (Variable<?, ?>) o; | ||
return Objects.equals(name, variable.name) && Objects.equals(type, variable.type) && Objects.equals(implementation, variable.implementation); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(name, type, implementation); | ||
} | ||
} |
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
Oops, something went wrong.