Skip to content

Commit

Permalink
support for reconcile option in GUI and model..
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Jul 7, 2014
1 parent 6e9270f commit c163504
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 5 deletions.
Expand Up @@ -84,6 +84,8 @@
<div class="operatingFormBlock">
<span class="operatingFormText"><wicket:message key="pageUser.button.label.force"/></span>
<input wicket:id="forceCheck" type="checkbox"/>
<span class="operatingFormText"><wicket:message key="pageUser.button.label.reconcile"/></span>
<input wicket:id="reconcileCheck" type="checkbox"/>
</div>
</div>
</form>
Expand Down
Expand Up @@ -152,6 +152,7 @@ public class PageUser extends PageAdminUsers {
private static final String ID_USER_FORM = "userForm";
private static final String ID_ACCOUNTS_DELTAS = "accountsDeltas";
private static final String ID_FORCE_CHECK = "forceCheck";
private static final String ID_RECONCILE_CHECK = "reconcileCheck";

private static final Trace LOGGER = TraceManager.getTrace(PageUser.class);
private IModel<ObjectWrapper> userModel;
Expand All @@ -161,6 +162,7 @@ public class PageUser extends PageAdminUsers {
// used to add force flag to operations if necessary, will be moved to some
// "page dto"
private boolean forceAction;
private boolean reconcileAction;

// it should be sent from submit. If the user is on the preview page and
// than he wants to get back to the edit page, the object delta is set, so
Expand Down Expand Up @@ -824,6 +826,25 @@ public void detach() {
}
});
mainForm.add(forceCheck);

// todo move model object to some dto and use PropertyModel
CheckBox reconcileCheck = new CheckBox(ID_RECONCILE_CHECK, new IModel<Boolean>() {

@Override
public Boolean getObject() {
return reconcileAction;
}

@Override
public void setObject(Boolean value) {
reconcileAction = value;
}

@Override
public void detach() {
}
});
mainForm.add(reconcileCheck);
}

private void initAccountButton(Form mainForm) {
Expand Down Expand Up @@ -1329,6 +1350,7 @@ private void savePerformed(AjaxRequestTarget target) {
Task task = createSimpleTask(OPERATION_SEND_TO_SUBMIT);
ModelExecuteOptions options = new ModelExecuteOptions();
options.setForce(forceAction);
options.setReconcile(reconcileAction);
// try {

try {
Expand All @@ -1341,7 +1363,7 @@ private void savePerformed(AjaxRequestTarget target) {
LOGGER.trace("User delta computed from form:\n{}", new Object[] { delta.debugDump(3) });
}

LOGGER.debug("Using force flag: {}.", new Object[] { forceAction });
LOGGER.debug("Using force flag: {}, reconcile flag {}.", new Object[] { forceAction, reconcileAction });
} catch (Exception ex) {
result.recordFatalError(getString("pageUser.message.cantCreateUser"), ex);
LoggingUtils.logException(LOGGER, getString("pageUser.message.cantCreateUser"), ex);
Expand Down Expand Up @@ -1582,7 +1604,12 @@ private void previewSavePerformed(AjaxRequestTarget target) {
ObjectDelta delta = null;
ModelContext changes = null;
ModelExecuteOptions options = forceAction ? ModelExecuteOptions.createForce() : null;

if (options == null){
options = reconcileAction ? ModelExecuteOptions.createReconcile() : null;
} else{
options.setReconcile(reconcileAction);
}

try {
delta = userWrapper.getObjectDelta();
if (userWrapper.getOldDelta() != null) {
Expand All @@ -1604,14 +1631,14 @@ private void previewSavePerformed(AjaxRequestTarget target) {
prepareUserForAdd(user);
getPrismContext().adopt(user, UserType.class);
deltas.add(delta);
changes = getModelInteractionService().previewChanges(deltas, null, task, result);
changes = getModelInteractionService().previewChanges(deltas, options, task, result);
result.recordSuccess();
break;
case MODIFYING:
WebMiscUtil.encryptCredentials(delta, true, getMidpointApplication());
prepareUserDeltaForModify(delta);
deltas.add(delta);
changes = getModelInteractionService().previewChanges(deltas, null, task, result);
changes = getModelInteractionService().previewChanges(deltas, options, task, result);
result.recordSuccess();
break;
// support for add/delete containers (e.g. delete credentials)
Expand Down
Expand Up @@ -45,6 +45,7 @@ pageUser.button.label.role=Role
pageUser.button.label.resources=Resource
pageUser.button.label.assign=Assign
pageUser.button.label.force=Force
pageUser.button.label.reconcile=Reconcile

pageUser.message.cantCreateUser=Create user failed
pageUser.message.cantUpdateUser=Update user failed
Expand Down
Expand Up @@ -46,6 +46,11 @@ public class ModelExecuteOptions {
*/
Boolean crypt;

/**
* Option to reconcile user while executing changes.
*/
Boolean reconcile;

public Boolean getForce() {
return force;
}
Expand Down Expand Up @@ -118,5 +123,30 @@ public static ModelExecuteOptions createCrypt() {
opts.setCrypt(true);
return opts;
}

public Boolean getReconcile() {
return reconcile;
}

public void setReconcile(Boolean reconcile) {
this.reconcile = reconcile;
}

public static boolean isReconcile(ModelExecuteOptions options){
if (options == null){
return false;
}
if (options.reconcile == null){
return false;
}
return options.reconcile;
}

public static ModelExecuteOptions createReconcile(){
ModelExecuteOptions opts = new ModelExecuteOptions();
opts.setReconcile(true);
return opts;
}


}
Expand Up @@ -375,6 +375,7 @@ public void run() {
RewindException rewindException = null;
LensContext<?, ?> context = LensUtil.objectDeltasToContext(deltas, provisioning, prismContext, task, result);
context.setOptions(options);
context.setDoReconciliationForAllProjections(ModelExecuteOptions.isReconcile(options));
try {

clockwork.run(context, task, result);
Expand Down
Expand Up @@ -31,6 +31,7 @@
import com.evolveum.midpoint.common.refinery.RefinedResourceSchema;
import com.evolveum.midpoint.common.refinery.ResourceShadowDiscriminator;
import com.evolveum.midpoint.common.refinery.ShadowDiscriminatorObjectDelta;
import com.evolveum.midpoint.model.api.ModelExecuteOptions;
import com.evolveum.midpoint.model.api.PolicyViolationException;
import com.evolveum.midpoint.model.api.context.ModelContext;
import com.evolveum.midpoint.prism.Item;
Expand Down Expand Up @@ -230,7 +231,6 @@ public static <F extends ObjectType, P extends ObjectType> LensContext<F, P> obj
context.rot();

if (CompiletimeConfig.CONSISTENCY_CHECKS) context.checkConsistence();

return context;
}

Expand Down

0 comments on commit c163504

Please sign in to comment.