Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:Evolveum/midpoint
- Loading branch information
Showing
36 changed files
with
1,814 additions
and
753 deletions.
There are no files selected for viewing
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
53 changes: 53 additions & 0 deletions
53
.../src/main/java/com/evolveum/midpoint/web/page/admin/configuration/PageExecuteMapping.html
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,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> |
215 changes: 215 additions & 0 deletions
215
.../src/main/java/com/evolveum/midpoint/web/page/admin/configuration/PageExecuteMapping.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,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); | ||
} | ||
|
||
|
||
} |
58 changes: 58 additions & 0 deletions
58
...c/main/java/com/evolveum/midpoint/web/page/admin/configuration/dto/ExecuteMappingDto.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,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; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...volveum/midpoint/web/page/admin/configuration/mapping-samples/FullName_Delta.map.xml.data
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,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> |
Oops, something went wrong.