Skip to content

Commit

Permalink
Merge branch 'master' into gui-devel
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Suta committed Jul 11, 2014
2 parents fedee97 + f1cb0f6 commit 3767b27
Show file tree
Hide file tree
Showing 86 changed files with 1,610 additions and 491 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 @@ -34,7 +34,7 @@ public class DatePanel extends InputPanel {
public DatePanel(String id, IModel<XMLGregorianCalendar> model) {
super(id);

DateInput date = new DateInput(ID_INPUT, new XmlGregorianCalendarModel(model, true));
DateInput date = new DateInput(ID_INPUT, new XmlGregorianCalendarModel(model));
add(date);
}

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 @@ -31,15 +31,9 @@
public class XmlGregorianCalendarModel extends Model<Date> {

private IModel<XMLGregorianCalendar> model;
private boolean copyTime;

public XmlGregorianCalendarModel(IModel<XMLGregorianCalendar> model) {
this(model, true);
}

public XmlGregorianCalendarModel(IModel<XMLGregorianCalendar> model, boolean copyTime) {
this.model = model;
this.copyTime = copyTime;
}

@Override
Expand All @@ -56,27 +50,7 @@ public void setObject(Date object) {
if (object == null) {
model.setObject(null);
} else {
if (copyTime) {
Date d = getObject();
object = copyTime(d, object);
}
model.setObject(MiscUtil.asXMLGregorianCalendar(object));
}
}

private Date copyTime(Date from, Date to) {
if (from == null || to == null) {
return to;
}

Calendar calendar = Calendar.getInstance();
calendar.setTime(from);

to = DateUtils.setHours(to, calendar.get(Calendar.HOUR_OF_DAY));
to = DateUtils.setMinutes(to, calendar.get(Calendar.MINUTE));
to = DateUtils.setSeconds(to, calendar.get(Calendar.SECOND));
to = DateUtils.setMilliseconds(to, calendar.get(Calendar.MILLISECOND));

return to;
}
}
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,14 +198,21 @@ 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;
}
if (delta.getPrismContext() == null) {
getPrismContext().adopt(delta);
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Account delta computed from form:\n{}", new Object[]{delta.debugDump(3)});
}

if (delta == null || delta.isEmpty()) {
if (delta.isEmpty()) {
return;
}
WebMiscUtil.encryptCredentials(delta, true, getMidpointApplication());
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 @@ -759,8 +759,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 @@ -829,4 +830,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());
}

}

0 comments on commit 3767b27

Please sign in to comment.