Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Aug 24, 2016
2 parents 5de0578 + e604f09 commit ea0521c
Show file tree
Hide file tree
Showing 36 changed files with 1,814 additions and 753 deletions.
Expand Up @@ -28,6 +28,8 @@
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;

import com.evolveum.midpoint.common.SystemConfigurationHolder;
import com.evolveum.midpoint.web.page.admin.configuration.*;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
import org.apache.wicket.AttributeModifier;
Expand Down Expand Up @@ -128,15 +130,6 @@
import com.evolveum.midpoint.web.page.admin.certification.PageCertDecisions;
import com.evolveum.midpoint.web.page.admin.certification.PageCertDefinition;
import com.evolveum.midpoint.web.page.admin.certification.PageCertDefinitions;
import com.evolveum.midpoint.web.page.admin.configuration.PageAbout;
import com.evolveum.midpoint.web.page.admin.configuration.PageAccounts;
import com.evolveum.midpoint.web.page.admin.configuration.PageBulkAction;
import com.evolveum.midpoint.web.page.admin.configuration.PageDebugList;
import com.evolveum.midpoint.web.page.admin.configuration.PageDebugView;
import com.evolveum.midpoint.web.page.admin.configuration.PageImportObject;
import com.evolveum.midpoint.web.page.admin.configuration.PageInternals;
import com.evolveum.midpoint.web.page.admin.configuration.PageRepositoryQuery;
import com.evolveum.midpoint.web.page.admin.configuration.PageSystemConfiguration;
import com.evolveum.midpoint.web.page.admin.home.PageDashboard;
import com.evolveum.midpoint.web.page.admin.reports.PageCreatedReports;
import com.evolveum.midpoint.web.page.admin.reports.PageNewReport;
Expand Down Expand Up @@ -1276,6 +1269,12 @@ public boolean isMenuActive(WebPage page) {
PageRepositoryQuery.class);
submenu.add(menu);

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

menu = new MenuItem(createStringResource("PageAdmin.menu.top.configuration.about"), PageAbout.class);
submenu.add(menu);

Expand Down
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2016 Evolveum
~
~ Licensed 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.
-->

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org">
<body>
<wicket:extend>
<form wicket:id="mainForm" class="form-inline" role="form">

<div class="container-fluid">
<div class="row">
<div class="col-lg-6 col-md-12">
<h3><wicket:message key="PageExecuteMapping.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>
<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>
<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>
<textarea wicket:id="resultText"></textarea>
</div>
</div>
</div>
</form>

</wicket:extend>
</body>
</html>
@@ -0,0 +1,215 @@
/*
* Copyright (c) 2010-2016 Evolveum
*
* Licensed 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 com.evolveum.midpoint.web.page.admin.configuration;

import com.evolveum.midpoint.gui.api.model.NonEmptyModel;
import com.evolveum.midpoint.gui.api.model.NonEmptyWrapperModel;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.security.api.AuthorizationConstants;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.CommonException;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.application.AuthorizationAction;
import com.evolveum.midpoint.web.application.PageDescriptor;
import com.evolveum.midpoint.web.component.AceEditor;
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.MappingType;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Arrays;
import java.util.List;

/**
* @author mederly
*/
@PageDescriptor(url = "/admin/config/executeMapping", 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")
})
public class PageExecuteMapping extends PageAdminConfiguration {

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

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

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

private static final String ID_MAIN_FORM = "mainForm";
private static final String ID_EXECUTE = "execute";
private static final String ID_EDITOR_REQUEST = "editorRequest";
private static final String ID_EDITOR_MAPPING = "editorMapping";
private static final String ID_RESULT_TEXT = "resultText";
private static final String ID_MAPPING_SAMPLE = "mappingSample";

private static final String SAMPLES_DIR = "mapping-samples";
private static final List<String> SAMPLES = Arrays.asList(
"FullName_NoDelta",
"FullName_Delta",
"FullName_Delta_Ref",
"FullName_Delta_Cond"
);

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

public PageExecuteMapping() {
initLayout();
}

private void initLayout() {
Form mainForm = new Form(ID_MAIN_FORM);
add(mainForm);

AceEditor editorMapping = new AceEditor(
ID_EDITOR_MAPPING, new PropertyModel<String>(model, ExecuteMappingDto.F_MAPPING));
editorMapping.setHeight(400);
editorMapping.setResizeToMaxHeight(false);
mainForm.add(editorMapping);

AceEditor editorRequest = new AceEditor(
ID_EDITOR_REQUEST, new PropertyModel<String>(model, ExecuteMappingDto.F_REQUEST));
editorRequest.setHeight(430);
editorRequest.setResizeToMaxHeight(false);
mainForm.add(editorRequest);

AjaxSubmitButton executeMapping = new AjaxSubmitButton(ID_EXECUTE, createStringResource("PageExecuteMapping.button.executeMapping")) {
@Override
protected void onError(AjaxRequestTarget target, Form<?> form) {
target.add(getFeedbackPanel());
}

@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
executeMappingPerformed(target);
}
};
mainForm.add(executeMapping);

final DropDownChoice<String> sampleChoice = new DropDownChoice<>(ID_MAPPING_SAMPLE,
Model.of(""),
new AbstractReadOnlyModel<List<String>>() {
@Override
public List<String> getObject() {
return SAMPLES;
}
},
new StringResourceChoiceRenderer("PageExecuteMapping.sample"));
sampleChoice.setNullValid(true);
sampleChoice.add(new OnChangeAjaxBehavior() {
@Override
protected void onUpdate(AjaxRequestTarget target) {
String sampleName = sampleChoice.getModelObject();
if (StringUtils.isEmpty(sampleName)) {
return;
}
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);
}

private String readResource(String name) {
InputStream is = PageExecuteMapping.class.getResourceAsStream(name);
if (is != null) {
try {
return IOUtils.toString(is, "UTF-8");
} catch (IOException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't read sample from resource {}", e, name);
} finally {
IOUtils.closeQuietly(is);
}
} else {
LOGGER.warn("Resource {} containing sample couldn't be found", name);
}
return null;
}
});
mainForm.add(sampleChoice);

AceEditor resultText = new AceEditor(ID_RESULT_TEXT, new PropertyModel<String>(model, ExecuteMappingDto.F_RESULT_TEXT));
resultText.setReadonly(true);
resultText.setHeight(300);
resultText.setResizeToMaxHeight(false);
resultText.setMode(null);
mainForm.add(resultText);

}

private void executeMappingPerformed(AjaxRequestTarget target) {
Task task = createSimpleTask(OPERATION_EXECUTE_MAPPING);
OperationResult result = new OperationResult(OPERATION_EXECUTE_MAPPING);

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

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);
dto.setResultText(response.getResponse());

} catch (CommonException | RuntimeException e) {
result.recordFatalError("Couldn't execute mapping", e);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't execute mapping", e);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
pw.close();
dto.setResultText(sw.toString());
} finally {
result.computeStatus();
}

showResult(result);
target.add(this);
}


}
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2010-2016 Evolveum
*
* Licensed 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 com.evolveum.midpoint.web.page.admin.configuration.dto;

import javax.xml.namespace.QName;
import java.io.Serializable;

/**
* @author mederly
*/
public class ExecuteMappingDto implements Serializable {

public static final String F_MAPPING = "mapping";
public static final String F_REQUEST = "request";
public static final String F_RESULT_TEXT = "resultText";

private String mapping = "";
private String request = "";
private String resultText = "";

public String getMapping() {
return mapping;
}

public void setMapping(String mapping) {
this.mapping = mapping;
}

public String getRequest() {
return request;
}

public void setRequest(String request) {
this.request = request;
}

public String getResultText() {
return resultText;
}

public void setResultText(String resultText) {
this.resultText = resultText;
}
}
@@ -0,0 +1,19 @@
<mapping>
<strength>normal</strength>
<source>
<path>givenName</path>
</source>
<source>
<path>familyName</path>
</source>
<expression>
<script>
<code>
givenName + ' ' + familyName
</code>
</script>
</expression>
<target>
<path>fullName</path>
</target>
</mapping>

0 comments on commit ea0521c

Please sign in to comment.