Skip to content

Commit

Permalink
Association editor seems to be working
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Dec 15, 2015
1 parent df62717 commit 87be917
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 99 deletions.
Expand Up @@ -37,11 +37,16 @@ public AssociationWrapper(ContainerWrapper container, PrismContainer<ShadowAssoc

@Override
public ValueWrapper createAddedValue() {
ItemDefinition definition = getDefinition();

ValueWrapper wrapper = new ValueWrapper(this, new PrismContainerValue<ShadowAssociationType>(null), ValueStatus.ADDED);
PrismContainer<ShadowAssociationType> container = (PrismContainer<ShadowAssociationType>)getItem();
PrismContainerValue<ShadowAssociationType> cval = container.createNewValue();
ValueWrapper wrapper = new ValueWrapper(this, cval, ValueStatus.ADDED);

return wrapper;
}

@Override
protected String getDebugName() {
return "AssociationWrapper";
}

}
Expand Up @@ -31,6 +31,10 @@
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.common.refinery.CompositeRefinedObjectClassDefinition;
import com.evolveum.midpoint.common.refinery.RefinedAssociationDefinition;
import com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition;
import com.evolveum.midpoint.common.refinery.RefinedResourceSchema;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
Expand All @@ -44,6 +48,7 @@
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.PrettyPrinter;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SystemException;
import com.evolveum.midpoint.util.logging.LoggingUtils;
Expand Down Expand Up @@ -102,7 +107,7 @@ public ContainerWrapper(ObjectWrapper objectWrapper, T container, ContainerStatu

private ContainerWrapper(ObjectWrapper objectWrapper, T container, ContainerStatus status, ItemPath path,
boolean createProperties, PageBase pageBase) {
Validate.notNull(container, "Prism object must not be null.");
Validate.notNull(container, "container must not be null.");
Validate.notNull(status, "Container status must not be null.");
Validate.notNull(pageBase, "pageBase must not be null.");

Expand Down Expand Up @@ -285,8 +290,9 @@ private List<ItemWrapper> createProperties(PageBase pageBase) {
}

} else if (isShadowAssociation()) {
PrismContext prismContext = objectWrapper.getObject().getPrismContext();
Map<QName,PrismContainer<ShadowAssociationType>> assocMap = new HashMap<>();
if (objectWrapper.getAssociations() != null) {
Map<QName,PrismContainer<ShadowAssociationType>> assocMap = new HashMap<>();
for (PrismContainerValue<ShadowAssociationType> cval : objectWrapper.getAssociations()) {
ShadowAssociationType associationType = cval.asContainerable();
QName assocName = associationType.getName();
Expand All @@ -305,12 +311,43 @@ private List<ItemWrapper> createProperties(PageBase pageBase) {
throw new SystemException("Unexpected error: "+e.getMessage(),e);
}
}
}

for (Entry<QName,PrismContainer<ShadowAssociationType>> assocEntry: assocMap.entrySet()) {
// HACK HACK HACK, the container wrapper should not parse itself. This code should not be here.
AssociationWrapper assocWrapper = new AssociationWrapper(this, assocEntry.getValue(), this.isReadonly(), ValueStatus.NOT_CHANGED);
properties.add(assocWrapper);
}
PrismReference resourceRef = parent.findReference(ShadowType.F_RESOURCE_REF);
PrismObject<ResourceType> resource = resourceRef.getValue().getObject();

// HACK. The revive should not be here. Revive is no good. The next use of the resource will
// cause parsing of resource schema. We need some centralized place to maintain live cached copies
// of resources.
try {
resource.revive(prismContext);
} catch (SchemaException e) {
throw new SystemException(e.getMessage(), e);
}
RefinedResourceSchema refinedSchema;
CompositeRefinedObjectClassDefinition rOcDef;
try {
refinedSchema = RefinedResourceSchema.getRefinedSchema(resource);
rOcDef = refinedSchema.determineCompositeObjectClassDefinition(parent);
} catch (SchemaException e) {
throw new SystemException(e.getMessage(),e);
}
// Make sure even empty associations have their wrappers so they can be displayed and edited
for (RefinedAssociationDefinition assocDef: rOcDef.getAssociations()) {
QName name = assocDef.getName();
if (!assocMap.containsKey(name)) {
PrismContainer<ShadowAssociationType> fractionalContainer = new PrismContainer<>(ShadowType.F_ASSOCIATION, ShadowAssociationType.class, prismContext);
fractionalContainer.setDefinition(getItemDefinition());
// HACK: set the name of the association as the element name so wrapper.getName() will return correct data.
fractionalContainer.setElementName(name);
assocMap.put(name, fractionalContainer);
}
}

for (Entry<QName,PrismContainer<ShadowAssociationType>> assocEntry: assocMap.entrySet()) {
// HACK HACK HACK, the container wrapper should not parse itself. This code should not be here.
AssociationWrapper assocWrapper = new AssociationWrapper(this, assocEntry.getValue(), this.isReadonly(), ValueStatus.NOT_CHANGED);
properties.add(assocWrapper);
}

} else { // if not an assignment
Expand Down Expand Up @@ -542,21 +579,21 @@ boolean isItemVisible(ItemWrapper item) {
}

private boolean showEmpty(ItemWrapper item) {
ObjectWrapper object = getObject();
List<ValueWrapper> values = item.getValues();
ObjectWrapper objectWrapper = getObject();
List<ValueWrapper> valueWrappers = item.getValues();
boolean isEmpty;
if (values == null) {
if (valueWrappers == null) {
isEmpty = true;
} else {
isEmpty = values.isEmpty();
isEmpty = valueWrappers.isEmpty();
}
if (!isEmpty && values.size() == 1) {
ValueWrapper value = values.get(0);
if (!isEmpty && valueWrappers.size() == 1) {
ValueWrapper value = valueWrappers.get(0);
if (ValueStatus.ADDED.equals(value.getStatus())) {
isEmpty = true;
}
}
return object.isShowEmpty() || !isEmpty;
return objectWrapper.isShowEmpty() || !isEmpty;
}

@Override
Expand Down Expand Up @@ -614,15 +651,13 @@ public boolean hasChanged() {
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ContainerWrapper(");
builder.append(getDisplayNameFromItem(container));
builder.append(", ");
builder.append(" (");
builder.append(status);
builder.append("\n");
for (ItemWrapper wrapper : getItems()) {
builder.append("\t");
builder.append(wrapper.toString());
builder.append("\n");
}
builder.append(") ");
builder.append(getItems() == null ? null : getItems().size());
builder.append(" items)");
return builder.toString();
}

Expand Down Expand Up @@ -717,7 +752,7 @@ public String debugDump() {
public String debugDump(int indent) {
StringBuilder sb = new StringBuilder();
DebugUtil.indentDebugDump(sb, indent);
sb.append("ContainerWrapper(\n");
sb.append("ContainerWrapper: ").append(PrettyPrinter.prettyPrint(getName())).append("\n");
DebugUtil.debugDumpWithLabel(sb, "displayName", displayName, indent+1);
sb.append("\n");
DebugUtil.debugDumpWithLabel(sb, "status", status == null?null:status.toString(), indent+1);
Expand All @@ -734,12 +769,11 @@ public String debugDump(int indent) {
sb.append("\n");
DebugUtil.debugDumpWithLabel(sb, "container", container==null?null:container.toString(), indent+1);
sb.append("\n");
DebugUtil.debugDumpWithLabel(sb, "properties", properties, indent+1);
DebugUtil.debugDumpLabel(sb, "properties", indent+1);
sb.append("\n");
DebugUtil.debugDumpWithLabel(sb, "result", result, indent+1);
DebugUtil.debugDump(sb, properties, indent+2, false);
sb.append("\n");
DebugUtil.indentDebugDump(sb, indent);
sb.append(")");
DebugUtil.debugDumpWithLabel(sb, "result", result, indent+1);
return sb.toString();
}
}
Expand Up @@ -366,13 +366,11 @@ private List<ContainerWrapper> createContainers(PageBase pageBase) {
}

PrismContainer<ShadowAssociationType> associationContainer = object
.findContainer(ShadowType.F_ASSOCIATION);
if (associationContainer != null) {
container = new ContainerWrapper(this, associationContainer, ContainerStatus.MODIFYING,
new ItemPath(ShadowType.F_ASSOCIATION), pageBase);
addSubresult(container.getResult());
containers.add(container);
}
.findOrCreateContainer(ShadowType.F_ASSOCIATION);
container = new ContainerWrapper(this, associationContainer, ContainerStatus.MODIFYING,
new ItemPath(ShadowType.F_ASSOCIATION), pageBase);
addSubresult(container.getResult());
containers.add(container);
} else if (ResourceType.class.isAssignableFrom(clazz)) {
containers = createResourceContainers(pageBase);
} else if (ReportType.class.isAssignableFrom(clazz)) {
Expand Down Expand Up @@ -582,38 +580,23 @@ public ObjectDelta getObjectDelta() throws SchemaException {

for (ContainerWrapper containerWrapper : getContainers()) {
//create ContainerDelta for association container
//TODO create correct procession for association container data
//HACK HACK HACK create correct procession for association container data
//according to its structure
if (containerWrapper.getItemDefinition().getName().equals(ShadowType.F_ASSOCIATION)) {
ContainerDelta containerDelta = ContainerDelta.createDelta(ShadowType.F_ASSOCIATION, containerWrapper.getItemDefinition());
List<ItemWrapper> itemsList = (List<ItemWrapper>) containerWrapper.getItems();
//TODO how to get the correct item (instead of index)?
int index = 0;
for (ItemWrapper vals : itemsList) {
List<ValueWrapper> valuesList = (List<ValueWrapper>) itemsList.get(index).getValues();
if (vals instanceof PropertyWrapper) {
PropertyWrapper assocValue =(PropertyWrapper) vals;
if (assocValue.getStatus() == ValueStatus.DELETED) {
PrismContainer prismContainer = containerWrapper.getItem();
List<PrismContainerValue> containerValues = prismContainer.getValues();
for (PrismContainerValue containerValue : containerValues){
if (containerValues.indexOf(containerValue) == index){
containerDelta.addValueToDelete(containerValue.clone());
}
}
} else if (assocValue.getStatus().equals(ValueStatus.ADDED)){
PrismContainer prismContainer = containerWrapper.getItem();
List<PrismContainerValue> containerValues = prismContainer.getValues();
for (PrismContainerValue containerValue : containerValues){
if (containerValues.indexOf(containerValue) == index){
containerDelta.addValueToAdd(containerValue.clone());
}
}
ContainerDelta<ShadowAssociationType> associationDelta = ContainerDelta.createDelta(ShadowType.F_ASSOCIATION, containerWrapper.getItemDefinition());
List<AssociationWrapper> associationItemWrappers = (List<AssociationWrapper>) containerWrapper.getItems();
for (AssociationWrapper associationItemWrapper : associationItemWrappers) {
List<ValueWrapper> assocValueWrappers = associationItemWrapper.getValues();
for (ValueWrapper assocValueWrapper: assocValueWrappers) {
PrismContainerValue<ShadowAssociationType> assocValue = (PrismContainerValue<ShadowAssociationType>) assocValueWrapper.getValue();
if (assocValueWrapper.getStatus() == ValueStatus.DELETED) {
associationDelta.addValueToDelete(assocValue.clone());
} else if (assocValueWrapper.getStatus().equals(ValueStatus.ADDED)){
associationDelta.addValueToAdd(assocValue.clone());
}
}
index++;
}
delta.addModification(containerDelta);
delta.addModification(associationDelta);
} else {
if (!containerWrapper.hasChanged()) {
continue;
Expand Down Expand Up @@ -645,6 +628,8 @@ public ObjectDelta getObjectDelta() throws SchemaException {
// returning container to previous order
Collections.sort(containers, new ItemWrapperComparator());

// Make sure we have all the definitions
object.getPrismContext().adopt(delta);
return delta;
}

Expand Down Expand Up @@ -902,15 +887,13 @@ private void cleanupEmptyContainers(PrismContainer container) {
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ObjectWrapper(");
builder.append(ContainerWrapper.getDisplayNameFromItem(object));
builder.append(", ");
builder.append(" (");
builder.append(status);
builder.append("\n");
for (ContainerWrapper wrapper : getContainers()) {
builder.append("\t");
builder.append(wrapper.toString());
builder.append("\n");
}
builder.append(") ");
builder.append(getContainers() == null ? null : getContainers().size());
builder.append(" containers)");
return builder.toString();
}

Expand Down
Expand Up @@ -21,6 +21,7 @@
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.page.PageBase;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.behavior.AttributeAppender;
Expand Down Expand Up @@ -54,26 +55,33 @@ public PrismContainerPanel(String id, final IModel<ContainerWrapper> model, bool
this.showHeader = showHeader;
this.pageBase = pageBase;

LOGGER.trace("Creating container panel for {}", model.getObject());

add(new AttributeAppender("class", new Model<>("attributeComponent"), " "));
add(new VisibleEnableBehaviour() {

@Override
public boolean isVisible() {
ContainerWrapper<? extends PrismContainer> container = model.getObject();
PrismContainer prismContainer = container.getItem();
ContainerWrapper<? extends PrismContainer> containerWrapper = model.getObject();
PrismContainer prismContainer = containerWrapper.getItem();
if (prismContainer.getDefinition().isOperational()) {
return false;
}

// HACK HACK HACK
if (ShadowType.F_ASSOCIATION.equals(prismContainer.getElementName())) {
return true;
}

boolean isVisible = false;
for (ItemWrapper item : container.getItems()) {
if (container.isItemVisible(item)) {
for (ItemWrapper item : containerWrapper.getItems()) {
if (containerWrapper.isItemVisible(item)) {
isVisible = true;
break;
}
}

return !container.getItems().isEmpty() && isVisible;
return !containerWrapper.getItems().isEmpty() && isVisible;
}
});

Expand Down
Expand Up @@ -18,6 +18,8 @@

import com.evolveum.midpoint.prism.PrismPropertyValue;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem;
import com.evolveum.midpoint.web.component.menu.cog.InlineMenuItemAction;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
Expand Down Expand Up @@ -61,6 +63,8 @@ public class PrismObjectPanel<O extends ObjectType> extends Panel {

private static final String STRIPED_CLASS = "striped";
private static final String ID_HEADER = "header";

private static final Trace LOGGER = TraceManager.getTrace(PrismObjectPanel.class);

private boolean showHeader = true;
private PageBase pageBase;
Expand All @@ -69,6 +73,8 @@ public PrismObjectPanel(String id, IModel<ObjectWrapper<O>> model, ResourceRefer
super(id);
setOutputMarkupId(true);

LOGGER.trace("Creating object panel for {}", model.getObject());

this.pageBase = pageBase;
initLayout(model, image, form);
}
Expand Down
Expand Up @@ -62,6 +62,8 @@ public PrismPropertyPanel(String id, final IModel<ItemWrapper> model, Form form,
super(id);
this.pageBase = pageBase;

LOGGER.trace("Creating property panel for {}", model.getObject());

setOutputMarkupId(true);
add(new VisibleEnableBehaviour() {

Expand Down

0 comments on commit 87be917

Please sign in to comment.