api.domino.domino-api.3.41.2.source-code.domino-rules.gdsl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of domino-api Show documentation
Show all versions of domino-api Show documentation
This artifact provides the API classes that are necessary to implement synchronization configuration Rules on the Memority IM platform.
import com.intellij.psi.PsiComment
import com.intellij.psi.PsiElement
import com.intellij.psi.tree.TokenSet
import com.intellij.testFramework.LightVirtualFile
import java.util.regex.Matcher
/**
* Domino rule DSL definition, for automagic autocompletion in "modern" IDEs (aka. IntelliJ).
* Usage:
*
* - Set the
toolkit.rule.flavor
maven property to toolkit,domino
* - OR start your groovy script with
//@ruleFlavor:toolkit,domino
*
*/
def globalContext = context(scope: scriptScope())
//noinspection GroovyAssignabilityCheck
contribute(globalContext) {
if (!ruleFlavor(psiClass, "domino")) {
return
}
// Contexts
property(name: "CTXT",
type: "com.memority.domino.shared.api.context.DominoContext",
doc: 'The parent context made available to all Domino rules.')
property(name: "SHADOW",
type: "com.memority.domino.shared.api.context.ShadowContext",
doc: 'The Shadow (application object) being worked on. For the provisioning outbound case better use ACCOUNT.')
property(name: "IDM_OBJECT",
type: "com.memority.citadel.shared.api.im.ApiObject",
doc: 'The IM object being worked on.')
property(name: "SYNC",
type: "com.memority.domino.shared.api.context.SynchronizationContext",
doc: 'Meaningful for the import inbound case only. Provides the sync situation')
property(name: "PROV",
type: "com.memority.domino.shared.api.context.ProvisioningContext",
doc: 'Meaningful for the provisioning outbound case only. Provides the application id.')
property(name: "ATTRIBUTE",
type: "com.memority.citadel.shared.api.context.AttributeContext",
doc: '''
The context of an individual attribute, when running while processing a single attribute. Note that
this attribute may be processed in the context of an IM object, in which case an accompanying OPERATION
context is also available.
Note: this context is immutable.
''')
property(name: "EXTERNAL",
type: "com.memority.citadel.shared.api.context.ExternalContext",
doc: 'Additional information sent by the API caller, that will be returned as is')
property(name: "SUBJECT",
type: "com.memority.citadel.shared.api.im.ApiObject",
doc: 'The authenticated principal, if any.')
property(name: "REQUESTER", type: "com.memority.citadel.shared.api.im.ApiObject",
doc: 'The current operation\'s requester')
// REST Connector context
property(name: "OBJECT", type: "com.memority.domino.shared.api.sync.Account",
doc: 'The provisioned account')
property(name: "ACCOUNT", type: "com.memority.domino.shared.api.sync.Account",
doc: 'The provisioned account')
property(name: "OBJECT_ID", type: "java.lang.String",
doc: 'The provisioned account\'s id')
property(name: "ACCOUNT_ID", type: "java.lang.String",
doc: 'The provisioned account\'s id')
property(name: "PATCH", type: "java.util.Map",
doc: 'The patch to be applied on the provisioned account when it is out-of-sync')
property(name: "SEARCH_PARAMS", type: "java.util.Map",
doc: 'The search parameters used to lookup an account')
property(name: "PAGE", type: "com.memority.domino.shared.api.PageRequest",
doc: 'Paging information enabling to keep track of the paged search state between consecutive search iterations.')
property(name: "ACTIVATION_SITUATION", type: "com.memority.domino.shared.api.sync.ActivationSituation",
doc: 'Set when an IDM object was either deleted, disabled, or unassigned from a provisioned application')
property(name: "LAST_EXEC_DATE", type: "java.time.Instant",
doc: 'The last time an inbound synchronization task or outbound provisioning task was executed.')
// APIs
property(name: "REST",
type: "com.memority.toolkit.rest.client.groovy.api.GroovyRestClient",
doc: 'Provides a {@link GroovyRestClient}')
property(name: "PARSER",
type: "com.memority.domino.shared.api.connector.rest.ResponseParserProvider",
doc: 'Provides a {@link ResponseParserProvider}')
property(name: "FIND",
type: "com.memority.citadel.shared.api.services.finder.ObjectFinderProvider",
doc: 'Provides an {@link ObjectFinder} for each Object Kind')
property(name: "MANAGE",
type: "com.memority.citadel.shared.api.services.manager.ObjectManager",
doc: 'Service to instantiate, save, patch and and delete managed objects.')
property(name: "API_REPORTING",
type: "com.memority.citadel.shared.api.services.reporting.ApiReportingManager",
doc: 'This service allows to execute operations on reporting collections')
property(name: "REF",
type: "com.memority.citadel.shared.api.services.reftable.ReferenceTableDataFinderProvider",
doc: '''
Provides access access to a given ReferenceTable's rows, using simple semantics.
It is the main entry point to reference table data through the Citadel API.
''')
property(name: "NOTIFY",
type: "com.memority.citadel.shared.api.services.notification.NotificationService",
doc: '''
Provides the ability to send notifications using the Citadel notification facility.
Usage:
notificationService.create()
.withType("some-notification-type)
.withNotifications(new HashSet<>(Arrays.asList("notif1", "notif2"))
.withActor("jdoe")
.role("some-role")
.name("John Doe")
.email("[email protected]")
.speaking("fr")
.end()
.withPayload(new HashMap
''')
}
/**
* Look for "magic" comments at the beginning of the script matching a given regex
* @param place the place to look at (typically the place
member available in contribute
closures
* @param re the regex to match
* @return a list of matchers for each matching comment
*/
static List findMagicComments(PsiElement place, String re) {
if (!place.containingFile.node) {
return []
}
def result = [] as List
loop:
for (def ast : place.containingFile.node.getChildren(TokenSet.ANY)) {
sw:
//noinspection GroovyFallthrough
switch (ast.elementType.toString()) {
case "new line":
case "WHITE_SPACE":
case "PACKAGE_DEFINITION":
case "IMPORT":
continue loop
case "line comment":
def magicComment = (ast as PsiComment).text
def matcher = magicComment =~ re
if (matcher.matches()) {
result << matcher
}
break sw
default:
break loop
}
}
return result
}
/**
* Checks that the enclosing groovy script has a given "rule flavor". It looks for, in order:
*
* - A
//@ruleFlavor:flavor1,flavor2,...
magic comment
* - The
toolkit.rule.flavor
Maven property
*
* @param place the place to look at (typically the place
member available in contribute
closures
* @param flavor the desired flavor
*/
static boolean ruleFlavor(PsiElement place, String flavor) {
def enabledFlavors = null
//check for magic comment
def magicCommentMatchers = findMagicComments(place, $///\s*@ruleFlavor\s*:\s*([\w,\s]+)\s*/$)
if (magicCommentMatchers) {
enabledFlavors = magicCommentMatchers.last().group(1)
}
//if no magic comment, check maven property
if (!enabledFlavors) {
def project = place.manager.project
def file = place.context.containingFile.originalFile.containingFile.virtualFile
//Groovy fragment: get original file
if (file instanceof LightVirtualFile && file.originalFile) {
file = file.originalFile
}
if (file) {
//noinspection GrUnresolvedAccess
def mavenProject = project
.getServiceByClassName("org.jetbrains.idea.maven.project.MavenProjectsManager")
.findContainingProject(file)
if (mavenProject) {
//noinspection GroovyAssignabilityCheck
enabledFlavors = (mavenProject.properties.getProperty("toolkit.rule.flavor") as String)
}
}
}
return enabledFlavors && enabledFlavors.split(",")
.collect { it.trim() }
.contains(flavor)
}