Skip to content

Commit

Permalink
Added prismContext to ItemDelta and PrismContainerValue. Made prismCo…
Browse files Browse the repository at this point in the history
…ntext in Definition and ObjectDelta mandatory.

Added calls to revive at many places in GUI, trying to solve MID-1928 (missing prismContext).
  • Loading branch information
mederly committed Jul 10, 2014
1 parent 1fc146b commit 37cc834
Show file tree
Hide file tree
Showing 64 changed files with 510 additions and 285 deletions.
Expand Up @@ -445,7 +445,7 @@ public void handleAssignmentsWhenAdd(PrismObject<T> object, PrismContainerDefini

public ContainerDelta handleAssignmentDeltas(ObjectDelta<T> userDelta, PrismContainerDefinition def, QName assignmentPath)
throws SchemaException {
ContainerDelta assDelta = new ContainerDelta(new ItemPath(), assignmentPath, def);
ContainerDelta assDelta = new ContainerDelta(new ItemPath(), assignmentPath, def, def.getPrismContext()); // hoping that def contains a prism context!

//PrismObject<OrgType> org = (PrismObject<OrgType>)getModel().getObject().getAssignmentParent();
//PrismObjectDefinition orgDef = org.getDefinition();
Expand Down
Expand Up @@ -23,6 +23,7 @@
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.ResourceTypeUtil;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
Expand Down Expand Up @@ -88,7 +89,22 @@ public ContainerWrapper(ObjectWrapper object, T container, ContainerStatus statu
containerDefinition = getContainerDefinition();
properties = createProperties(pageBase);
}


public void revive(PrismContext prismContext) throws SchemaException {
if (container != null) {
container.revive(prismContext);
}
if (containerDefinition != null) {
containerDefinition.revive(prismContext);
}
if (properties != null) {
for (PropertyWrapper propertyWrapper : properties) {
propertyWrapper.revive(prismContext);
}
}
}


protected PrismContainerDefinition getContainerDefinition() {
if (main) {
return object.getDefinition();
Expand Down
Expand Up @@ -17,11 +17,12 @@
package com.evolveum.midpoint.web.component.prism;

import com.evolveum.midpoint.prism.Item;
import com.evolveum.midpoint.prism.Revivable;

/**
* @author lazyman
*/
public interface ItemWrapper {
public interface ItemWrapper extends Revivable {

String getDisplayName();

Expand Down
Expand Up @@ -55,7 +55,7 @@
/**
* @author lazyman
*/
public class ObjectWrapper implements Serializable {
public class ObjectWrapper implements Serializable, Revivable {

public static final String F_DISPLAY_NAME = "displayName";
public static final String F_SELECTED = "selected";
Expand Down Expand Up @@ -120,6 +120,20 @@ public void initializeContainers(PageBase pageBase) {
containers = createContainers(pageBase);
}

public void revive(PrismContext prismContext) throws SchemaException {
if (object != null) {
object.revive(prismContext);
}
if (oldDelta != null) {
oldDelta.revive(prismContext);
}
if (containers != null) {
for (ContainerWrapper containerWrapper : containers) {
containerWrapper.revive(prismContext);
}
}
}

public List<PrismProperty> getAssociations() {
return associations;
}
Expand Down Expand Up @@ -480,7 +494,7 @@ public ObjectDelta getObjectDelta() throws SchemaException {

ItemPath path = containerWrapper.getPath() != null ? containerWrapper.getPath()
: new ItemPath();
PropertyDelta pDelta = new PropertyDelta(path, propertyDef.getName(), propertyDef);
PropertyDelta pDelta = new PropertyDelta(path, propertyDef.getName(), propertyDef, propertyDef.getPrismContext()); // hoping the prismContext is there
for (ValueWrapper valueWrapper : propertyWrapper.getValues()) {
valueWrapper.normalize();
ValueStatus valueStatus = valueWrapper.getStatus();
Expand Down
Expand Up @@ -17,6 +17,7 @@
package com.evolveum.midpoint.web.component.prism;

import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.prism.PrismPropertyDefinition;
Expand All @@ -25,6 +26,7 @@
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.schema.SchemaConstantsGenerated;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType;

Expand Down Expand Up @@ -66,6 +68,15 @@ public PropertyWrapper(ContainerWrapper container, PrismProperty property, boole
}
}

public void revive(PrismContext prismContext) throws SchemaException {
if (property != null) {
property.revive(prismContext);
}
if (itemDefinition != null) {
itemDefinition.revive(prismContext);
}
}

protected PrismPropertyDefinition getItemDefinition() {
PrismPropertyDefinition propDef = container.getContainerDefinition().findPropertyDefinition(property.getDefinition().getName());
if (propDef == null) {
Expand Down Expand Up @@ -222,4 +233,5 @@ public boolean isReadonly() {
public void setReadonly(boolean readonly) {
this.readonly = readonly;
}

}
Expand Up @@ -16,6 +16,9 @@

package com.evolveum.midpoint.web.component.util;

import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.web.util.WebMiscUtil;
import org.apache.wicket.model.IModel;

public abstract class LoadableModel<T> implements IModel<T> {
Expand Down Expand Up @@ -101,4 +104,11 @@ protected void onLoad() {

protected void onDetach() {
}

public void revive(PrismContext prismContext) throws SchemaException {
if (isLoaded()) {
WebMiscUtil.reviveObject(object, prismContext);
}
}

}
Expand Up @@ -234,7 +234,9 @@ public Object getObject() {
@Override
public List<DecisionDto> getObject() {
List<DecisionDto> retval = new ArrayList<>();
ItemApprovalProcessState instanceState = (ItemApprovalProcessState) model.getObject().getInstanceState().getProcessSpecificState();
ProcessInstanceDto processInstanceDto = model.getObject();
processInstanceDto.reviveIfNeeded(ItemApprovalPanel.this);
ItemApprovalProcessState instanceState = (ItemApprovalProcessState) processInstanceDto.getInstanceState().getProcessSpecificState();
List<DecisionType> allDecisions = instanceState.getDecisions();
if (allDecisions != null) {
for (DecisionType decision : allDecisions) {
Expand Down
Expand Up @@ -264,10 +264,7 @@ public void savePerformed(AjaxRequestTarget target) {
try {

PrismObject<ObjectType> oldObject = dto.getObject();
if (oldObject.getPrismContext() == null) {
LOGGER.warn("No prism context in old object {}, adding it", oldObject);
oldObject.setPrismContext(getPrismContext());
}
oldObject.revive(getPrismContext());

Holder<PrismObject<ObjectType>> objectHolder = new Holder<PrismObject<ObjectType>>(null);
validateObject(editor.getModel().getObject(), objectHolder, validateSchema.getObject(), result);
Expand All @@ -279,7 +276,7 @@ public void savePerformed(AjaxRequestTarget target) {

if (delta.getPrismContext() == null) {
LOGGER.warn("No prism context in delta {} after diff, adding it", delta);
delta.setPrismContext(getPrismContext());
delta.revive(getPrismContext());
}

//quick fix for now (MID-1910), maybe it should be somewhere in model..
Expand Down
Expand Up @@ -198,8 +198,9 @@ private void savePerformed(AjaxRequestTarget target) {
LOGGER.debug("Saving account changes.");

OperationResult result = new OperationResult(OPERATION_SAVE_ACCOUNT);
ObjectWrapper wrapper = accountModel.getObject();
try {
WebMiscUtil.revive(accountModel, getPrismContext());
ObjectWrapper wrapper = accountModel.getObject();
ObjectDelta<ShadowType> delta = wrapper.getObjectDelta();
if (delta == null) {
return;
Expand Down
Expand Up @@ -294,6 +294,8 @@ protected void onSubmit(AjaxRequestTarget target, Form<?> form){
private void savePerformed(AjaxRequestTarget target){
OperationResult result = new OperationResult(OPERATION_SAVE_ROLE);
try {
WebMiscUtil.revive(model, getPrismContext());

ModelService modelService = getModelService();

PrismObject<RoleType> newRole = model.getObject();
Expand Down
Expand Up @@ -445,6 +445,7 @@ private boolean isOrgParent(OrgType unit, List<ObjectReferenceType> parentList){
private void savePerformed(AjaxRequestTarget target) {
OperationResult result = new OperationResult(SAVE_UNIT);
try {
reviveModels();
ObjectDelta delta = null;
if (!isEditing()) {
PrismObject<OrgType> newOrgUnit = buildUnitFromModel(null);
Expand Down Expand Up @@ -575,4 +576,10 @@ private List<OrgType> loadParentOrgUnits() {
return parentList;
}

private void reviveModels() throws SchemaException {
WebMiscUtil.revive(orgModel, getPrismContext());
WebMiscUtil.revive(parentOrgUnitsModel, getPrismContext());
}


}
Expand Up @@ -25,19 +25,13 @@
import com.evolveum.midpoint.prism.query.*;
import com.evolveum.midpoint.prism.schema.SchemaRegistry;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.ResultHandler;
import com.evolveum.midpoint.schema.RetrieveOption;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.ObjectResolver;
import com.evolveum.midpoint.schema.util.ShadowUtil;
import com.evolveum.midpoint.security.api.AuthorizationConstants;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.CommunicationException;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SecurityViolationException;
import com.evolveum.midpoint.util.exception.SystemException;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
Expand All @@ -46,7 +40,6 @@
import com.evolveum.midpoint.web.application.PageDescriptor;
import com.evolveum.midpoint.web.component.AjaxButton;
import com.evolveum.midpoint.web.component.AjaxSubmitButton;
import com.evolveum.midpoint.web.component.data.ObjectDataProvider;
import com.evolveum.midpoint.web.component.menu.cog.InlineMenu;
import com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem;
import com.evolveum.midpoint.web.component.menu.cog.InlineMenuItemAction;
Expand Down Expand Up @@ -1110,7 +1103,7 @@ private void removeResourceFromAccConstruction(AssignmentType assignment) {
}

private ReferenceDelta prepareUserAccountsDeltaForModify(PrismReferenceDefinition refDef) throws SchemaException {
ReferenceDelta refDelta = new ReferenceDelta(refDef);
ReferenceDelta refDelta = new ReferenceDelta(refDef, getPrismContext());

List<UserAccountDto> accounts = accountsModel.getObject();
for (UserAccountDto accDto : accounts) {
Expand Down Expand Up @@ -1151,7 +1144,7 @@ private ReferenceDelta prepareUserAccountsDeltaForModify(PrismReferenceDefinitio

private ContainerDelta handleAssignmentDeltas(ObjectDelta<UserType> userDelta, PrismContainerDefinition def)
throws SchemaException {
ContainerDelta assDelta = new ContainerDelta(new ItemPath(), UserType.F_ASSIGNMENT, def);
ContainerDelta assDelta = new ContainerDelta(new ItemPath(), UserType.F_ASSIGNMENT, def, getPrismContext());

PrismObject<UserType> user = userModel.getObject().getObject();
PrismObjectDefinition userDef = user.getDefinition();
Expand Down Expand Up @@ -1270,11 +1263,12 @@ private void savePerformed(AjaxRequestTarget target) {
// try {

try {
reviveModels();

delta = userWrapper.getObjectDelta();
if (userWrapper.getOldDelta() != null) {
delta = ObjectDelta.summarize(userWrapper.getOldDelta(), delta);
}
delta.setPrismContext(getPrismContext());
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("User delta computed from form:\n{}", new Object[]{delta.debugDump(3)});
}
Expand Down Expand Up @@ -1397,6 +1391,13 @@ private void savePerformed(AjaxRequestTarget target) {

}

private void reviveModels() throws SchemaException {
WebMiscUtil.revive(userModel, getPrismContext());
WebMiscUtil.revive(accountsModel, getPrismContext());
WebMiscUtil.revive(assignmentsModel, getPrismContext());
WebMiscUtil.revive(summaryUser, getPrismContext());
}

private boolean executeForceDelete(ObjectWrapper userWrapper, Task task, ModelExecuteOptions options,
OperationResult parentResult) {
if (executeOptionsModel.getObject().isForce()) {
Expand Down
Expand Up @@ -758,8 +758,9 @@ private void savePerformed(AjaxRequestTarget target, boolean decision) {

OperationResult result = new OperationResult(OPERATION_SAVE_WORK_ITEM);

ObjectWrapper rsWrapper = requestSpecificModel.getObject();
try {
reviveModels();
ObjectWrapper rsWrapper = requestSpecificModel.getObject();
PrismObject object = rsWrapper.getObject();
ObjectDelta delta = rsWrapper.getObjectDelta();
delta.applyTo(object);
Expand Down Expand Up @@ -828,4 +829,14 @@ private void releasePerformed(AjaxRequestTarget target) {
public PageBase reinitialize() {
return new PageWorkItem(parameters, getPreviousPage(), true);
}

private void reviveModels() throws SchemaException {
WebMiscUtil.revive(requesterModel, getPrismContext());
WebMiscUtil.revive(objectOldModel, getPrismContext());
WebMiscUtil.revive(objectNewModel, getPrismContext());
WebMiscUtil.revive(requestSpecificModel, getPrismContext());
WebMiscUtil.revive(trackingDataModel, getPrismContext());
WebMiscUtil.revive(additionalDataModel, getPrismContext());
}

}
Expand Up @@ -20,6 +20,7 @@
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.web.component.util.Selectable;
import com.evolveum.midpoint.web.component.wf.processes.itemApproval.ItemApprovalPanel;
import com.evolveum.midpoint.web.util.WebMiscUtil;
import com.evolveum.midpoint.wf.util.ApprovalUtils;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
Expand Down Expand Up @@ -125,4 +126,9 @@ public ProcessInstanceState getInstanceState() {
public String getShadowTaskOid() {
return processInstanceState.getShadowTaskOid();
}

public void reviveIfNeeded(ItemApprovalPanel component) {
WebMiscUtil.reviveIfNeeded(processInstance, component);
WebMiscUtil.reviveIfNeeded(processInstanceState, component);
}
}

0 comments on commit 37cc834

Please sign in to comment.