Skip to content

Commit

Permalink
Mapping playground: new sample for deriving DN from parent org names
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Aug 26, 2016
1 parent 13644f9 commit 8e0e996
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 68 deletions.
Expand Up @@ -17,7 +17,6 @@
package com.evolveum.midpoint.gui.api.page;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
Expand All @@ -34,7 +33,6 @@
import org.apache.commons.lang.Validate;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
import org.apache.wicket.MarkupContainer;
import org.apache.wicket.Page;
import org.apache.wicket.RestartResponseException;
import org.apache.wicket.RuntimeConfigurationType;
Expand Down Expand Up @@ -101,7 +99,6 @@
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.task.api.TaskCategory;
import com.evolveum.midpoint.task.api.TaskManager;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.Holder;
import com.evolveum.midpoint.util.Producer;
import com.evolveum.midpoint.util.exception.SchemaException;
Expand Down Expand Up @@ -1270,8 +1267,8 @@ public boolean isMenuActive(WebPage page) {
submenu.add(menu);

if (SystemConfigurationHolder.isExperimentalCodeEnabled()) {
menu = new MenuItem(createStringResource("PageAdmin.menu.top.configuration.executeMapping"),
PageExecuteMapping.class);
menu = new MenuItem(createStringResource("PageAdmin.menu.top.configuration.evaluateMapping"),
PageEvaluateMapping.class);
submenu.add(menu);
}

Expand Down
Expand Up @@ -23,25 +23,25 @@
<div class="container-fluid">
<div class="row">
<div class="col-lg-6 col-md-12">
<h3><wicket:message key="PageExecuteMapping.mapping"/></h3>
<h3><wicket:message key="PageEvaluateMapping.mapping"/></h3>
<textarea wicket:id="editorMapping" style="margin-bottom: 10px"></textarea>
<div class="form-group" style="margin-top: 10px">
<label for="mappingSample" class="small"><wicket:message key="PageExecuteMapping.chooseSample"/></label>
<label for="mappingSample" class="small"><wicket:message key="PageEvaluateMapping.chooseSample"/></label>
<select id="mappingSample" class="input-sm form-control" wicket:id="mappingSample"/>
</div>
<div class="main-button-bar" style="margin-top: 10px">
<a class="btn btn-primary" wicket:id="execute"/>
</div>
</div>
<div class="col-lg-6 col-md-12">
<h3><wicket:message key="PageExecuteMapping.request"/></h3>
<h3><wicket:message key="PageEvaluateMapping.request"/></h3>
<textarea wicket:id="editorRequest" style="margin-bottom: 10px"></textarea>
</div>
</div>

<div class="row">
<div class="col-md-12">
<h3><wicket:message key="PageExecuteMapping.result"/></h3>
<h3><wicket:message key="PageEvaluateMapping.result"/></h3>
<textarea wicket:id="resultText"></textarea>
</div>
</div>
Expand Down
Expand Up @@ -32,8 +32,8 @@
import com.evolveum.midpoint.web.component.AjaxSubmitButton;
import com.evolveum.midpoint.web.page.admin.configuration.dto.ExecuteMappingDto;
import com.evolveum.midpoint.web.util.StringResourceChoiceRenderer;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MappingExecutionRequestType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MappingExecutionResponseType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MappingEvaluationRequestType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MappingEvaluationResponseType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -55,19 +55,19 @@
/**
* @author mederly
*/
@PageDescriptor(url = "/admin/config/executeMapping", action = {
@PageDescriptor(url = "/admin/config/evaluateMapping", action = {
@AuthorizationAction(actionUri = PageAdminConfiguration.AUTH_CONFIGURATION_ALL,
label = PageAdminConfiguration.AUTH_CONFIGURATION_ALL_LABEL, description = PageAdminConfiguration.AUTH_CONFIGURATION_ALL_DESCRIPTION),
@AuthorizationAction(actionUri = AuthorizationConstants.AUTZ_UI_CONFIGURATION_EXECUTE_MAPPING_URL,
label = "PageExecuteMapping.auth.mapping.label", description = "PageExecuteMapping.auth.mapping.description")
@AuthorizationAction(actionUri = AuthorizationConstants.AUTZ_UI_CONFIGURATION_EVALUATE_MAPPING_URL,
label = "PageEvaluateMapping.auth.mapping.label", description = "PageEvaluateMapping.auth.mapping.description")
})
public class PageExecuteMapping extends PageAdminConfiguration {
public class PageEvaluateMapping extends PageAdminConfiguration {

private static final Trace LOGGER = TraceManager.getTrace(PageExecuteMapping.class);
private static final Trace LOGGER = TraceManager.getTrace(PageEvaluateMapping.class);

private static final String DOT_CLASS = PageExecuteMapping.class.getName() + ".";
private static final String DOT_CLASS = PageEvaluateMapping.class.getName() + ".";

private static final String OPERATION_EXECUTE_MAPPING = DOT_CLASS + "executeMapping";
private static final String OPERATION_EXECUTE_MAPPING = DOT_CLASS + "evaluateMapping";

private static final String ID_MAIN_FORM = "mainForm";
private static final String ID_EXECUTE = "execute";
Expand All @@ -81,12 +81,13 @@ public class PageExecuteMapping extends PageAdminConfiguration {
"FullName_NoDelta",
"FullName_Delta",
"FullName_Delta_Ref",
"FullName_Delta_Cond"
"FullName_Delta_Cond",
"OrgName"
);

private final NonEmptyModel<ExecuteMappingDto> model = new NonEmptyWrapperModel<>(new Model<>(new ExecuteMappingDto()));

public PageExecuteMapping() {
public PageEvaluateMapping() {
initLayout();
}

Expand All @@ -106,7 +107,7 @@ private void initLayout() {
editorRequest.setResizeToMaxHeight(false);
mainForm.add(editorRequest);

AjaxSubmitButton executeMapping = new AjaxSubmitButton(ID_EXECUTE, createStringResource("PageExecuteMapping.button.executeMapping")) {
AjaxSubmitButton evaluateMapping = new AjaxSubmitButton(ID_EXECUTE, createStringResource("PageEvaluateMapping.button.evaluateMapping")) {
@Override
protected void onError(AjaxRequestTarget target, Form<?> form) {
target.add(getFeedbackPanel());
Expand All @@ -117,7 +118,7 @@ protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
executeMappingPerformed(target);
}
};
mainForm.add(executeMapping);
mainForm.add(evaluateMapping);

final DropDownChoice<String> sampleChoice = new DropDownChoice<>(ID_MAPPING_SAMPLE,
Model.of(""),
Expand All @@ -127,7 +128,7 @@ public List<String> getObject() {
return SAMPLES;
}
},
new StringResourceChoiceRenderer("PageExecuteMapping.sample"));
new StringResourceChoiceRenderer("PageEvaluateMapping.sample"));
sampleChoice.setNullValid(true);
sampleChoice.add(new OnChangeAjaxBehavior() {
@Override
Expand All @@ -139,11 +140,11 @@ protected void onUpdate(AjaxRequestTarget target) {
model.getObject().setMapping(readResource(SAMPLES_DIR + "/" + sampleName + ".map.xml.data"));
model.getObject().setRequest(readResource(SAMPLES_DIR + "/" + sampleName + ".req.xml.data"));
model.getObject().setResultText("");
target.add(PageExecuteMapping.this);
target.add(PageEvaluateMapping.this);
}

private String readResource(String name) {
InputStream is = PageExecuteMapping.class.getResourceAsStream(name);
InputStream is = PageEvaluateMapping.class.getResourceAsStream(name);
if (is != null) {
try {
return IOUtils.toString(is, "UTF-8");
Expand Down Expand Up @@ -175,24 +176,24 @@ private void executeMappingPerformed(AjaxRequestTarget target) {

ExecuteMappingDto dto = model.getObject();
if (StringUtils.isBlank(dto.getMapping())) {
warn(getString("PageExecuteMapping.message.emptyString"));
warn(getString("PageEvaluateMapping.message.emptyString"));
target.add(getFeedbackPanel());
return;
}
try {
MappingExecutionRequestType request;
MappingEvaluationRequestType request;
if (StringUtils.isNotBlank(dto.getRequest())) {
request = getPrismContext().parseAtomicValue(dto.getRequest(), MappingExecutionRequestType.COMPLEX_TYPE, PrismContext.LANG_XML);
request = getPrismContext().parseAtomicValue(dto.getRequest(), MappingEvaluationRequestType.COMPLEX_TYPE, PrismContext.LANG_XML);
} else {
request = new MappingExecutionRequestType();
request = new MappingEvaluationRequestType();
}

if (StringUtils.isNotBlank(dto.getMapping())) {
request.setMapping((MappingType) getPrismContext()
.parseAtomicValue(dto.getMapping(), MappingType.COMPLEX_TYPE, PrismContext.LANG_XML));
}

MappingExecutionResponseType response = getModelDiagnosticService().executeMapping(request, task, result);
MappingEvaluationResponseType response = getModelDiagnosticService().evaluateMapping(request, task, result);
dto.setResultText(response.getResponse());

} catch (CommonException | RuntimeException e) {
Expand Down
@@ -0,0 +1,28 @@
<!-- This mapping derives a value from parent organization's name.
It is used here to demonstrate derivation of LDAP distinguished name
based on the name of parent organization (and its parent and its parent) -->
<mapping>
<source>
<path>parentOrgRef</path>
</source>
<source>
<path>name</path>
</source>
<expression>
<script>
<code>
org1 = parentOrgRef != null ? midpoint.getOrgByOid(parentOrgRef?.oid) : null
org2 = org1?.parentOrgRef ? midpoint.getOrgByOid(org1?.parentOrgRef.get(0).oid) : null
org3 = org2?.parentOrgRef ? midpoint.getOrgByOid(org2?.parentOrgRef.get(0).oid) : null

'uid=' + name +
(org1 ? ',ou=' + org1?.name : '') +
(org2 ? ',ou=' + org2?.name : '') +
(org3 ? ',ou=' + org3?.name : '') + ',dc=example,dc=com'
</code>
</script>
</expression>
<target>
<path>description</path>
</target>
</mapping>
@@ -0,0 +1,20 @@
<!-- Please replace OIDs in targetRef by real OIDs of org being unassigned and assigned -->
<mappingExecutionRequest>
<sourceContext>
<objectRef oid="00000000-0000-0000-0000-000000000002" type="UserType"/>
<delta>
<changeType>modify</changeType>
<objectType>UserType</objectType>
<itemDelta>
<modificationType>add</modificationType>
<path>parentOrgRef</path>
<value oid="73dd4b6f-088a-4bfb-b12d-5a9ce058c8a5" type="OrgType"/>
</itemDelta>
<itemDelta>
<modificationType>add</modificationType>
<path>parentOrgRef</path>
<value oid="d1bb0eaf-3cc0-4cfd-99ec-6c000c7349ba" type="OrgType"/>
</itemDelta>
</delta>
</sourceContext>
</mappingExecutionRequest>
25 changes: 13 additions & 12 deletions gui/admin-gui/src/main/resources/localization/Midpoint.properties
Expand Up @@ -969,7 +969,7 @@ PageAdmin.menu.top.configuration.about=About
PageAdmin.menu.top.configuration.basic=System
PageAdmin.menu.top.configuration.bulkActions=Bulk actions
PageAdmin.menu.top.configuration.repoQuery=Query playground
PageAdmin.menu.top.configuration.executeMapping=Mapping playground
PageAdmin.menu.top.configuration.evaluateMapping=Mapping playground
PageAdmin.menu.top.configuration=Configuration
PageAdmin.menu.top.configuration.configuration=Configuration
PageAdmin.menu.top.configuration.development=Development
Expand Down Expand Up @@ -3307,14 +3307,15 @@ operation.com.evolveum.midpoint.web.page.admin.configuration.PageRepositoryQuery
operation.com.evolveum.midpoint.web.page.admin.configuration.PageRepositoryQuery.executeQuery=Execute query (GUI)
operation.com.evolveum.midpoint.model.api.ModelDiagnosticService.executeRepositoryQuery=Execute repository query (Model diagnostic service)
operation.com.evolveum.midpoint.repo.api.RepositoryService.executeQueryDiagnostics=Execute query diagnostics (Repository)
PageExecuteMapping.title=Execute mapping
PageExecuteMapping.button.executeMapping=Execute mapping
PageExecuteMapping.message.emptyString=Please provide a mapping to execute.
PageExecuteMapping.result=Result
PageExecuteMapping.mapping=Mapping
PageExecuteMapping.request=Request
PageExecuteMapping.chooseSample=Or use a sample:
PageExecuteMapping.sample.FullName_NoDelta=Full name mapping (no change)
PageExecuteMapping.sample.FullName_Delta=Full name mapping (change in givenName)
PageExecuteMapping.sample.FullName_Delta_Ref=Full name mapping (change in givenName); source from repository
PageExecuteMapping.sample.FullName_Delta_Cond=Full name mapping with condition (change in givenName)
PageEvaluateMapping.title=Evaluate mapping
PageEvaluateMapping.button.evaluateMapping=Evaluate mapping
PageEvaluateMapping.message.emptyString=Please provide a mapping to execute.
PageEvaluateMapping.result=Result
PageEvaluateMapping.mapping=Mapping
PageEvaluateMapping.request=Request
PageEvaluateMapping.chooseSample=Or use a sample:
PageEvaluateMapping.sample.FullName_NoDelta=Full name mapping (no change)
PageEvaluateMapping.sample.FullName_Delta=Full name mapping (change in givenName)
PageEvaluateMapping.sample.FullName_Delta_Ref=Full name mapping (change in givenName); source from repository
PageEvaluateMapping.sample.FullName_Delta_Cond=Full name mapping with condition (change in givenName)
PageEvaluateMapping.sample.OrgName=Deriving attribute from parent org's name
Expand Up @@ -12050,14 +12050,14 @@
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="MappingExecutionRequestType">
<xsd:complexType name="MappingEvaluationRequestType">
<xsd:annotation>
<xsd:documentation>
TODO ... EXPERIMENTAL
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="sourceContext" type="c:MappingExecutionSourceContextType" minOccurs="0" >
<xsd:element name="sourceContext" type="c:MappingEvaluationSourceContextType" minOccurs="0" >
<xsd:annotation>
<xsd:documentation>
TODO
Expand All @@ -12071,14 +12071,14 @@
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="variable" type="c:MappingExecutionVariableType" minOccurs="0" maxOccurs="unbounded">
<xsd:element name="variable" type="c:MappingEvaluationVariableType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
TODO
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="options" type="c:MappingExecutionOptionsType" minOccurs="0" maxOccurs="unbounded">
<xsd:element name="options" type="c:MappingEvaluationOptionsType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
TODO
Expand All @@ -12094,9 +12094,9 @@
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="mappingExecutionRequest" type="tns:MappingExecutionRequestType"/>
<xsd:element name="MappingEvaluationRequest" type="tns:MappingEvaluationRequestType"/>

<xsd:complexType name="MappingExecutionSourceContextType">
<xsd:complexType name="MappingEvaluationSourceContextType">
<xsd:sequence>
<xsd:element name="name" type="xsd:string" minOccurs="0"/>
<xsd:choice>
Expand All @@ -12107,20 +12107,20 @@
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="MappingExecutionVariableType">
<xsd:complexType name="MappingEvaluationVariableType">
<xsd:sequence>
<xsd:element name="name" type="xsd:string" minOccurs="0"/>
<xsd:element ref="c:value" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="MappingExecutionOptionsType">
<xsd:complexType name="MappingEvaluationOptionsType">
<xsd:sequence>
<xsd:element name="now" type="xsd:dateTime" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="MappingExecutionResponseType">
<xsd:complexType name="MappingEvaluationResponseType">
<xsd:annotation>
<xsd:documentation>
TODO ... EXPERIMENTAL
Expand All @@ -12136,6 +12136,6 @@
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="mappingExecutionResponse" type="tns:MappingExecutionResponseType"/>
<xsd:element name="MappingEvaluationResponse" type="tns:MappingEvaluationResponseType"/>

</xsd:schema>
Expand Up @@ -24,8 +24,8 @@
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MappingExecutionRequestType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MappingExecutionResponseType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MappingEvaluationRequestType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MappingEvaluationResponseType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;

/**
Expand All @@ -45,7 +45,7 @@ public interface ModelDiagnosticService {
String REPOSITORY_SELF_TEST = CLASS_NAME_WITH_DOT + "repositorySelfTest";
String REPOSITORY_TEST_ORG_CLOSURE_CONSISTENCY = CLASS_NAME_WITH_DOT + "repositoryTestOrgClosureConsistency";
String EXECUTE_REPOSITORY_QUERY = CLASS_NAME_WITH_DOT + "executeRepositoryQuery";
String EXECUTE_MAPPING = CLASS_NAME_WITH_DOT + "executeMapping";
String EXECUTE_MAPPING = CLASS_NAME_WITH_DOT + "evaluateMapping";
String PROVISIONING_SELF_TEST = CLASS_NAME_WITH_DOT + "provisioningSelfTest";

/**
Expand Down Expand Up @@ -100,7 +100,7 @@ RepositoryQueryDiagResponse executeRepositoryQuery(RepositoryQueryDiagRequest re
*
* EXPERIMENTAL
*/
MappingExecutionResponseType executeMapping(MappingExecutionRequestType request, Task task, OperationResult parentResult)
MappingEvaluationResponseType evaluateMapping(MappingEvaluationRequestType request, Task task, OperationResult parentResult)
throws SchemaException, SecurityViolationException, ExpressionEvaluationException,
ObjectNotFoundException;
/**
Expand Down

0 comments on commit 8e0e996

Please sign in to comment.