Skip to content

Commit

Permalink
Resource Wizard, Schema Handling step update - save functionality com…
Browse files Browse the repository at this point in the history
…pleted + many minor improvements and small fixes made along the way.
  • Loading branch information
Erik Suta committed Sep 4, 2014
1 parent afd128d commit 5a29629
Show file tree
Hide file tree
Showing 19 changed files with 404 additions and 106 deletions.
Expand Up @@ -16,14 +16,17 @@

package com.evolveum.midpoint.web.component.form.multivalue;

import com.evolveum.midpoint.web.component.AjaxSubmitButton;
import com.evolveum.midpoint.web.component.util.LoadableModel;
import com.evolveum.midpoint.web.component.util.SimplePanel;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
Expand Down Expand Up @@ -98,10 +101,10 @@ protected void onUpdate(AjaxRequestTarget target) {}
}

private void initButtons(WebMarkupContainer buttonGroup, final ListItem<T> item) {
AjaxLink edit = new AjaxLink(ID_EDIT) {
AjaxSubmitLink edit = new AjaxSubmitLink(ID_EDIT) {

@Override
public void onClick(AjaxRequestTarget target) {
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
editPerformed(target, item.getModelObject());
}
};
Expand Down
Expand Up @@ -18,9 +18,12 @@


import com.evolveum.midpoint.common.refinery.RefinedResourceSchema;
import com.evolveum.midpoint.model.api.ModelService;
import com.evolveum.midpoint.prism.Definition;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.schema.processor.ResourceSchema;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
Expand All @@ -35,12 +38,12 @@
import com.evolveum.midpoint.web.component.wizard.resource.dto.SchemaHandlingDto;
import com.evolveum.midpoint.web.session.UserProfileStorage;
import com.evolveum.midpoint.web.util.WebMiscUtil;
import com.evolveum.midpoint.web.util.WebModelUtils;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
import org.apache.wicket.behavior.AttributeAppender;
Expand Down Expand Up @@ -71,6 +74,7 @@ public class SchemaHandlingStep extends WizardStep {

private static final String DOT_CLASS = SchemaHandlingStep.class.getName() + ".";
private static final String OPERATION_LOAD_OBJECT_CLASS_LIST = DOT_CLASS + "loadObjectClassList";
private static final String OPERATION_SAVE_SCHEMA_HANDLING = DOT_CLASS + "saveSchemaHandling";

private static final String ID_ROWS = "tableRows";
private static final String ID_ROW_OBJECT_TYPE = "objectTypeRow";
Expand Down Expand Up @@ -341,10 +345,10 @@ protected String load() {
SchemaHandlingDto.F_SELECTED + "._default"));
editor.add(editorDefault);

AjaxLink editorDependency = new AjaxLink(ID_EDITOR_BUTTON_DEPENDENCY) {
AjaxSubmitLink editorDependency = new AjaxSubmitLink(ID_EDITOR_BUTTON_DEPENDENCY) {

@Override
public void onClick(AjaxRequestTarget target) {
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
dependencyEditPerformed(target);
}
};
Expand Down Expand Up @@ -377,11 +381,6 @@ protected Iterator<String> getChoices(String input) {
return choices.iterator();
}
};
editorObjectClass.add(new AjaxFormComponentUpdatingBehavior("onchange") {

@Override
protected void onUpdate(AjaxRequestTarget target) {}
});
editorObjectClass.add(createObjectClassValidator());
editor.add(editorObjectClass);

Expand Down Expand Up @@ -471,56 +470,53 @@ protected boolean buttonsDisabled(){
};
editor.add(editorAssociations);



DropDownChoice editorAssignmentPolicyRef = new DropDownChoice<>(ID_EDITOR_ASSIGNMENT_POLICY,
new PropertyModel<AssignmentPolicyEnforcementType>(model, SchemaHandlingDto.F_SELECTED + ".assignmentPolicyEnforcement"),
WebMiscUtil.createReadonlyModelFromEnum(AssignmentPolicyEnforcementType.class),
new EnumChoiceRenderer<AssignmentPolicyEnforcementType>(this));
editor.add(editorAssignmentPolicyRef);

AjaxLink editorIteration = new AjaxLink(ID_EDITOR_BUTTON_ITERATION) {
AjaxSubmitLink editorIteration = new AjaxSubmitLink(ID_EDITOR_BUTTON_ITERATION) {

@Override
public void onClick(AjaxRequestTarget target) {
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
iterationEditPerformed(target);
}
};
addDisabledClassModifier(editorIteration);
editor.add(editorIteration);

AjaxLink editorProtected = new AjaxLink(ID_EDITOR_BUTTON_PROTECTED) {
AjaxSubmitLink editorProtected = new AjaxSubmitLink(ID_EDITOR_BUTTON_PROTECTED) {

@Override
public void onClick(AjaxRequestTarget target) {
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
protectedEditPerformed(target);
}
};
addDisabledClassModifier(editorProtected);
editor.add(editorProtected);

AjaxLink editorActivation = new AjaxLink(ID_EDITOR_BUTTON_ACTIVATION) {
AjaxSubmitLink editorActivation = new AjaxSubmitLink(ID_EDITOR_BUTTON_ACTIVATION) {

@Override
public void onClick(AjaxRequestTarget target) {
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
activationEditPerformed(target);
}
};
addDisabledClassModifier(editorActivation);
editor.add(editorActivation);

AjaxLink editorCredentials = new AjaxLink(ID_EDITOR_BUTTON_CREDENTIALS) {
AjaxSubmitLink editorCredentials = new AjaxSubmitLink(ID_EDITOR_BUTTON_CREDENTIALS) {

@Override
public void onClick(AjaxRequestTarget target) {
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
credentialsEditPerformed(target);
}
};
addDisabledClassModifier(editorCredentials);
editor.add(editorCredentials);
}


private IValidator<String> createObjectClassValidator(){
return new IValidator<String>() {

Expand Down Expand Up @@ -630,7 +626,8 @@ private void editAttributePerformed(AjaxRequestTarget target, ResourceAttributeD
target.add(getThirdRowContainer());
} else {
warn(getString("SchemaHandlingStep.message.selectObjectClassAttr"));
target.add(getPageBase().getFeedbackPanel());
getThirdRowContainer().replaceWith(new WebMarkupContainer(ID_THIRD_ROW_CONTAINER));
target.add(getPageBase().getFeedbackPanel(), getThirdRowContainer());
}
}

Expand All @@ -643,13 +640,46 @@ private void editAssociationPerformed(AjaxRequestTarget target, ResourceObjectAs
target.add(getThirdRowContainer());
} else {
warn(getString("SchemaHandlingStep.message.selectObjectClassAss"));
target.add(getPageBase().getFeedbackPanel());
getThirdRowContainer().replaceWith(new WebMarkupContainer(ID_THIRD_ROW_CONTAINER));
target.add(getPageBase().getFeedbackPanel(), getThirdRowContainer());
}
}

@Override
public void applyState() {
// TODO - implement
savePerformed();
}

private void savePerformed(){
PrismObject<ResourceType> oldResource;
PrismObject<ResourceType> newResource = resourceModel.getObject();
OperationResult result = new OperationResult(OPERATION_SAVE_SCHEMA_HANDLING);
ModelService modelService = getPageBase().getModelService();
ObjectDelta delta = null;

try{
oldResource = WebModelUtils.loadObject(ResourceType.class, newResource.getOid(), result, getPageBase());
if(oldResource != null){
delta = oldResource.diff(newResource);

if(LOGGER.isTraceEnabled()){
LOGGER.trace(delta.debugDump());
}

Collection<ObjectDelta<? extends ObjectType>> deltas = WebMiscUtil.createDeltaCollection(delta);
modelService.executeChanges(deltas, null, getPageBase().createSimpleTask(OPERATION_SAVE_SCHEMA_HANDLING), result);
}

} catch (Exception e){
LoggingUtils.logException(LOGGER, "Couldn't save schema handling", e);
result.recordFatalError(getString("SchemaHandlingStep.message.saveError", e));
} finally {
result.computeStatusIfUnknown();
}

if(WebMiscUtil.showResultInPage(result)){
getPageBase().showResult(result);
}
}

private void editObjectTypePerformed(AjaxRequestTarget target, ResourceObjectTypeDefinitionTypeDto objectType){
Expand Down
Expand Up @@ -43,4 +43,5 @@ AssignmentPolicyEnforcementType.RELATIVE=Relative
SchemaHandlingStep.message.errorLoadingObjectTypeList=Couldn't load object class list from resource. Error:
SchemaHandlingStep.message.validationError=Inserted objectClass value: '{0}' is not valid. Please provide valid objectClass value.
SchemaHandlingStep.message.selectObjectClassAttr=Please provide 'Object class' attribute before creating resource attribute.
SchemaHandlingStep.message.selectObjectClassAss=Please provide 'Object class' attribute before creating resource association.
SchemaHandlingStep.message.selectObjectClassAss=Please provide 'Object class' attribute before creating resource association.
SchemaHandlingStep.message.saveError=Couldn't save schema handling, {0}
Expand Up @@ -166,11 +166,18 @@ protected void editPerformed(AjaxRequestTarget target, MappingType object){
mappingEditPerformed(target, object);
}
};
inbound.setOutputMarkupId(true);
add(inbound);
}

private void initModals(){
ModalWindow mappingEditor = new MappingEditorDialog(ID_MODAL_MAPPING, null);
ModalWindow mappingEditor = new MappingEditorDialog(ID_MODAL_MAPPING, null){

@Override
public void updateComponents(AjaxRequestTarget target){
target.add(ResourceActivationEditor.this);
}
};
add(mappingEditor);
}

Expand Down
Expand Up @@ -25,6 +25,7 @@
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.component.AjaxSubmitButton;
import com.evolveum.midpoint.web.component.form.multivalue.MultiValueTextEditPanel;
import com.evolveum.midpoint.web.component.form.multivalue.MultiValueTextPanel;
import com.evolveum.midpoint.web.component.util.SimplePanel;
Expand Down Expand Up @@ -295,16 +296,18 @@ public String getIdValue(QName object, int index) {

TextField outboundLabel = new TextField<>(ID_OUTBOUND_LABEL,
new PropertyModel<String>(getModel(), "outbound.name"));
outboundLabel.setOutputMarkupId(true);
outboundLabel.setEnabled(false);
add(outboundLabel);

AjaxLink outbound = new AjaxLink(ID_BUTTON_OUTBOUND) {
AjaxSubmitButton outbound = new AjaxSubmitButton(ID_BUTTON_OUTBOUND) {

@Override
public void onClick(AjaxRequestTarget target) {
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
outboundEditPerformed(target);
}
};
outbound.setOutputMarkupId(true);
add(outbound);

MultiValueTextEditPanel inbound = new MultiValueTextEditPanel<MappingType>(ID_INBOUND,
Expand Down Expand Up @@ -337,6 +340,7 @@ protected void editPerformed(AjaxRequestTarget target, MappingType object){
mappingEditPerformed(target, object);
}
};
inbound.setOutputMarkupId(true);
add(inbound);

initModals();
Expand All @@ -347,7 +351,15 @@ private void initModals(){
new PropertyModel<List<PropertyLimitationsType>>(getModel(), "limitations"));
add(limitationsEditor);

ModalWindow mappingEditor = new MappingEditorDialog(ID_MODAL_MAPPING, null);
ModalWindow mappingEditor = new MappingEditorDialog(ID_MODAL_MAPPING, null){

@Override
public void updateComponents(AjaxRequestTarget target){
target.add(ResourceAssociationEditor.this.get(ID_INBOUND), ResourceAssociationEditor.this.get(ID_OUTBOUND_LABEL),
ResourceAssociationEditor.this.get(ID_BUTTON_OUTBOUND));
}

};
add(mappingEditor);
}

Expand Down
Expand Up @@ -37,6 +37,7 @@
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.*;
Expand Down Expand Up @@ -220,15 +221,17 @@ public String getIdValue(QName object, int index) {
TextField outboundLabel = new TextField<>(ID_OUTBOUND_LABEL,
new PropertyModel<String>(getModel(), "outbound.name"));
outboundLabel.setEnabled(false);
outboundLabel.setOutputMarkupId(true);
add(outboundLabel);

AjaxLink outbound = new AjaxLink(ID_BUTTON_OUTBOUND) {
AjaxSubmitLink outbound = new AjaxSubmitLink(ID_BUTTON_OUTBOUND) {

@Override
public void onClick(AjaxRequestTarget target) {
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
outboundEditPerformed(target);
}
};
outbound.setOutputMarkupId(true);
add(outbound);

MultiValueTextEditPanel inbound = new MultiValueTextEditPanel<MappingType>(ID_INBOUND,
Expand Down Expand Up @@ -261,6 +264,7 @@ protected void editPerformed(AjaxRequestTarget target, MappingType object){
mappingEditPerformed(target, object);
}
};
inbound.setOutputMarkupId(true);
add(inbound);

initModals();
Expand All @@ -271,7 +275,14 @@ private void initModals(){
new PropertyModel<List<PropertyLimitationsType>>(getModel(), "limitations"));
add(limitationsEditor);

ModalWindow mappingEditor = new MappingEditorDialog(ID_MODAL_MAPPING, null);
ModalWindow mappingEditor = new MappingEditorDialog(ID_MODAL_MAPPING, null){

@Override
public void updateComponents(AjaxRequestTarget target) {
target.add(ResourceAttributeEditor.this.get(ID_INBOUND), ResourceAttributeEditor.this.get(ID_OUTBOUND_LABEL),
ResourceAttributeEditor.this.get(ID_BUTTON_OUTBOUND));
}
};
add(mappingEditor);
}

Expand Down

0 comments on commit 5a29629

Please sign in to comment.