Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Feb 23, 2015
2 parents 8f4dbb7 + 61a43e2 commit 51d4e07
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 18 deletions.
Expand Up @@ -302,7 +302,7 @@ protected MappingType createNewEmptyItem(){

@Override
protected void editPerformed(AjaxRequestTarget target, MappingType object){
mappingEditPerformed(target, object);
mappingEditPerformed(target, object, false);
}
};
add(outbound);
Expand All @@ -329,7 +329,7 @@ protected MappingType createNewEmptyItem(){

@Override
protected void editPerformed(AjaxRequestTarget target, MappingType object){
mappingEditPerformed(target, object);
mappingEditPerformed(target, object, true);
}
};
inbound.setOutputMarkupId(true);
Expand All @@ -347,9 +347,9 @@ public void updateComponents(AjaxRequestTarget target){
add(mappingEditor);
}

private void mappingEditPerformed(AjaxRequestTarget target, MappingType mapping){
private void mappingEditPerformed(AjaxRequestTarget target, MappingType mapping, boolean isInbound){
MappingEditorDialog window = (MappingEditorDialog) get(ID_MODAL_MAPPING);
window.updateModel(target, mapping);
window.updateModel(target, mapping, isInbound);
window.show(target);
}
}
Expand Up @@ -484,13 +484,13 @@ private void limitationsEditPerformed(AjaxRequestTarget target){

private void outboundEditPerformed(AjaxRequestTarget target){
MappingEditorDialog window = (MappingEditorDialog) get(ID_MODAL_OUTBOUND);
window.updateModel(target, new PropertyModel<MappingType>(getModel(), "outbound"));
window.updateModel(target, new PropertyModel<MappingType>(getModel(), "outbound"), false);
window.show(target);
}

private void inboundEditPerformed(AjaxRequestTarget target, MappingType mapping){
MappingEditorDialog window = (MappingEditorDialog) get(ID_MODAL_INBOUND);
window.updateModel(target, mapping);
window.updateModel(target, mapping, true);
window.show(target);
}
}
Expand Up @@ -434,13 +434,13 @@ private void limitationsEditPerformed(AjaxRequestTarget target){

private void outboundEditPerformed(AjaxRequestTarget target){
MappingEditorDialog window = (MappingEditorDialog) get(ID_MODAL_OUTBOUND);
window.updateModel(target, new PropertyModel<MappingType>(getModel(), "outbound"));
window.updateModel(target, new PropertyModel<MappingType>(getModel(), "outbound"), false);
window.show(target);
}

private void inboundEditPerformed(AjaxRequestTarget target, MappingType mapping){
MappingEditorDialog window = (MappingEditorDialog) get(ID_MODAL_INBOUND);
window.updateModel(target, mapping);
window.updateModel(target, mapping, true);
window.show(target);
}
}
Expand Up @@ -251,13 +251,13 @@ private List<ObjectReferenceType> createPasswordPolicyList(){

private void outboundEditPerformed(AjaxRequestTarget target){
MappingEditorDialog window = (MappingEditorDialog) get(ID_MODAL_OUTBOUND);
window.updateModel(target, new PropertyModel<MappingType>(getModel(), "password.outbound"));
window.updateModel(target, new PropertyModel<MappingType>(getModel(), "password.outbound"), false);
window.show(target);
}

private void inboundEditPerformed(AjaxRequestTarget target, MappingType mapping){
MappingEditorDialog window = (MappingEditorDialog) get(ID_MODAL_INBOUND);
window.updateModel(target, mapping);
window.updateModel(target, mapping, true);
window.show(target);
}
}
Expand Up @@ -66,6 +66,7 @@
</div>

<div class="form-group" wicket:id="target" />
<span class="text-danger" wicket:id="feedback"/>

<div class="form-group" wicket:id="expressionType" />
<div class="form-group" wicket:id="expressionLanguage" />
Expand Down
Expand Up @@ -50,6 +50,7 @@
import org.apache.wicket.markup.html.form.EnumChoiceRenderer;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.IChoiceRenderer;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.*;

import java.util.ArrayList;
Expand All @@ -67,6 +68,7 @@ public class MappingEditorDialog extends ModalWindow{
private static final String DOT_CLASS = MappingEditorDialog.class.getName() + ".";
private static final String OPERATION_LOAD_PASSWORD_POLICIES = DOT_CLASS + "createPasswordPolicyList";

private static final String ID_FEEDBACK = "feedback";
private static final String ID_MAIN_FORM = "mainForm";
private static final String ID_NAME = "name";
private static final String ID_DESCRIPTION = "description";
Expand Down Expand Up @@ -103,6 +105,7 @@ public class MappingEditorDialog extends ModalWindow{
private IModel<MappingTypeDto> model;
private Map<String, String> policyMap = new HashMap<>();
private IModel<MappingType> inputModel;
private boolean isInbound = false;

public MappingEditorDialog(String id, final IModel<MappingType> mapping){
super(id);
Expand Down Expand Up @@ -134,13 +137,15 @@ protected MappingTypeDto load() {
setContent(content);
}

public void updateModel(AjaxRequestTarget target, IModel<MappingType> mapping){
public void updateModel(AjaxRequestTarget target, IModel<MappingType> mapping, boolean isInbound){
this.isInbound = isInbound;
model.setObject(new MappingTypeDto(mapping.getObject(), getPageBase().getPrismContext()));
inputModel = mapping;
target.add(getContent());
}

public void updateModel(AjaxRequestTarget target, MappingType mapping){
public void updateModel(AjaxRequestTarget target, MappingType mapping, boolean isInbound){
this.isInbound = isInbound;
model.setObject(new MappingTypeDto(mapping, getPageBase().getPrismContext()));

if(inputModel != null){
Expand Down Expand Up @@ -286,9 +291,15 @@ public String getIdValue(String object, int index) {

//TODO - create some nice ItemPathType editor in near future
TextFormGroup target = new TextFormGroup(ID_TARGET, new PropertyModel<String>(model, MappingTypeDto.F_TARGET),
createStringResource("MappingEditorDialog.label.target"), "SchemaHandlingStep.mapping.tooltip.target", true, ID_LABEL_SIZE, ID_INPUT_SIZE, false);
createStringResource("MappingEditorDialog.label.target"), "SchemaHandlingStep.mapping.tooltip.target", true, ID_LABEL_SIZE, ID_INPUT_SIZE, isInbound);
target.setOutputMarkupId(true);
form.add(target);

FeedbackPanel feedback = new FeedbackPanel(ID_FEEDBACK);
feedback.setOutputMarkupId(true);
feedback.setOutputMarkupPlaceholderTag(true);
form.add(feedback);

DropDownFormGroup<ExpressionUtil.ExpressionEvaluatorType> expressionType = new DropDownFormGroup<ExpressionUtil.ExpressionEvaluatorType>(ID_EXPRESSION_TYPE,
new PropertyModel<ExpressionUtil.ExpressionEvaluatorType>(model, MappingTypeDto.F_EXPRESSION_TYPE),
WebMiscUtil.createReadonlyModelFromEnum(ExpressionUtil.ExpressionEvaluatorType.class),
Expand Down Expand Up @@ -537,6 +548,10 @@ private PageBase getPageBase(){
return (PageBase) getPage();
}

private FeedbackPanel getFeedback(){
return (FeedbackPanel) get(getContentId() + ":" + ID_MAIN_FORM + ":" + ID_FEEDBACK);
}

private List<ObjectReferenceType> createPasswordPolicyList(){
policyMap.clear();
OperationResult result = new OperationResult(OPERATION_LOAD_PASSWORD_POLICIES);
Expand Down Expand Up @@ -583,6 +598,14 @@ private void cancelPerformed(AjaxRequestTarget target){
}

private void savePerformed(AjaxRequestTarget target){
if(isInbound){
if(model.getObject().getTarget() == null || model.getObject().getTarget().isEmpty()){
warn(getString("MappingEditorDialog.message.warn.emptyTarget"));
target.add(getFeedback());
return;
}
}

try {
if(inputModel != null){
inputModel.setObject(model.getObject().prepareDtoToSave(getPageBase().getPrismContext()));
Expand Down
Expand Up @@ -53,4 +53,5 @@ Channel.import=Import
Channel.user=User
Channel.webService=Web Service

MappingEditorDialog.message.cantSave=Couldn't save mapping. Reason:
MappingEditorDialog.message.cantSave=Couldn't save mapping. Reason:
MappingEditorDialog.message.warn.emptyTarget=Inbound mapping requires 'target' field to be specified.
Expand Up @@ -17,6 +17,8 @@
package com.evolveum.midpoint.web.component.wizard.resource.dto;

import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.path.ItemPathSegment;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
Expand Down Expand Up @@ -166,6 +168,8 @@ public MappingType prepareDtoToSave(PrismContext prismContext) throws SchemaExce
MappingTargetDeclarationType mappingTarget = new MappingTargetDeclarationType();
mappingTarget.setPath(new ItemPathType(target));
mappingObject.setTarget(mappingTarget);
} else {
mappingObject.setTarget(null);
}

mappingObject.getSource().clear();
Expand Down Expand Up @@ -366,14 +370,38 @@ public static String createMappingLabel(MappingType mapping, Trace LOGGER, Prism
StringBuilder sb = new StringBuilder();
if(mapping.getName() != null && StringUtils.isNotEmpty(mapping.getName())){
sb.append(mapping.getName());
} else {
sb.append(nameNotSpecified);
return sb.toString();
}

if(!mapping.getSource().isEmpty()){
for(MappingSourceDeclarationType source: mapping.getSource()){
if(source.getPath() != null && source.getPath().getItemPath() != null
&& source.getPath().getItemPath().getSegments() != null){

List<ItemPathSegment> segments = source.getPath().getItemPath().getSegments();
sb.append(segments.get(segments.size() - 1));

sb.append(",");
}
}
}

sb.append("-");
sb.append(" (");
if(mapping.getExpression() != null && mapping.getExpression().getExpressionEvaluator() != null){
sb.append(" (");
sb.append(ExpressionUtil.getExpressionType(ExpressionUtil.loadExpression(mapping, context, LOGGER)));
sb.append(")");
}
sb.append(")");
sb.append("->");

if(mapping.getTarget() != null){
MappingTargetDeclarationType target = mapping.getTarget();
if(target.getPath() != null && target.getPath().getItemPath() != null
&& target.getPath().getItemPath().getSegments() != null){

List<ItemPathSegment> segments = target.getPath().getItemPath().getSegments();
sb.append(segments.get(segments.size() - 1));
}
}

return sb.toString();
Expand Down

0 comments on commit 51d4e07

Please sign in to comment.