Skip to content

Commit

Permalink
fixing create, modify for focus forms..
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Oct 5, 2017
1 parent 776dd7d commit 1b2b4da
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 62 deletions.
Expand Up @@ -151,21 +151,24 @@ protected <T extends ObjectType> void addSelectedAssignmentsPerformed(AjaxReques
target.add(getPageBase().getFeedbackPanel());
return;
}
ContainerWrapperFactory factory = new ContainerWrapperFactory(getPageBase());

for (T object : assignmentsList){
ObjectReferenceType ort = new ObjectReferenceType();
ort.setOid(object.getOid());
ort.setRelation(SchemaConstants.ORG_DEFAULT);
ort.setType(WebComponentUtil.classToQName(getPageBase().getPrismContext(), object.getClass()));


PrismContainerValue<AssignmentType> newAssignment = getModelObject().getItem().createNewValue();
newAssignment.asContainerable().setTargetRef(ort);


ContainerValueWrapper<AssignmentType> valueWrapper = factory.createContainerValueWrapper(getModelObject(), newAssignment,
ValueStatus.ADDED, new ItemPath(FocusType.F_ASSIGNMENT));
getModelObject().getValues().add(valueWrapper);
PrismContainerValue<AssignmentType> newAssignment = getModelObject().getItem().createNewValue();
ObjectReferenceType ref = ObjectTypeUtil.createObjectRef(object, relation);
AssignmentType assignmentType = newAssignment.asContainerable();
if (ResourceType.class.equals(object.getClass())) {
ConstructionType constructionType = new ConstructionType();
constructionType.setResourceRef(ref);
assignmentType.setConstruction(constructionType);
} else {
assignmentType.setTargetRef(ref);
}
ContainerValueWrapper<AssignmentType> newAssignmentValueWrapper = createNewAssignmentContainerValueWrapper(newAssignment);
// getModelObject().getValues().add(newAssignmentValueWrapper);

// ContainerValueWrapper<AssignmentType> valueWrapper = factory.createContainerValueWrapper(getModelObject(), newAssignment.asPrismContainerValue(),
// ValueStatus.ADDED, new ItemPath(FocusType.F_ASSIGNMENT));
// getModelObject().getValues().add(valueWrapper);
}

refreshTable(target);
Expand Down
Expand Up @@ -48,6 +48,7 @@
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.prism.query.ObjectPaging;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.security.api.AuthorizationConstants;
import com.evolveum.midpoint.web.component.AjaxButton;
import com.evolveum.midpoint.web.component.AjaxIconButton;
Expand All @@ -67,6 +68,7 @@
import com.evolveum.midpoint.web.session.UserProfileStorage.TableId;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;

import javax.xml.datatype.XMLGregorianCalendar;

Expand Down Expand Up @@ -276,6 +278,7 @@ public void onClick(AjaxRequestTarget target, IModel<ContainerValueWrapper<Assig
@Override
public void populateItem(Item<ICellPopulator<ContainerValueWrapper<AssignmentType>>> item, String componentId,
final IModel<ContainerValueWrapper<AssignmentType>> rowModel) {

List<ItemWrapper> assignmentItems = rowModel.getObject().getItems();//ContainerValue().findContainer(AssignmentType.F_ACTIVATION);
ItemWrapper activationItem = null;
for (ItemWrapper wrapper : assignmentItems){
Expand Down Expand Up @@ -324,7 +327,7 @@ public void populateItem(Item<ICellPopulator<ContainerValueWrapper<AssignmentTyp
protected abstract List<IColumn<ContainerValueWrapper<AssignmentType>, String>> initColumns();

protected abstract void newAssignmentClickPerformed(AjaxRequestTarget target);

protected void initCustomLayout(WebMarkupContainer assignmentsContainer) {

}
Expand All @@ -350,7 +353,7 @@ public boolean isVisible() {

@Override
public List<ContainerValueWrapper<AssignmentType>> getObject() {
return getAssignmentListProvider().getSelectedData();
return getModelObject().getValues().stream().filter(v -> v.isSelected()).collect(Collectors.toList());
}
};

Expand Down Expand Up @@ -378,10 +381,11 @@ protected void populateItem(ListItem<ContainerValueWrapper<AssignmentType>> item
private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget ajaxRequestTarget) {
public void onClick(AjaxRequestTarget target) {
assignmentDetailsVisible = false;
getSelectedAssignments().stream().forEach(a -> a.setSelected(false));
ajaxRequestTarget.add(AssignmentPanel.this);
refreshTable(target);
target.add(AssignmentPanel.this);
}
};
details.add(doneButton);
Expand Down Expand Up @@ -486,13 +490,23 @@ protected void deleteAssignmentPerformed(AjaxRequestTarget target, List<Containe
if (toDelete == null){
return;
}
for (ContainerValueWrapper<AssignmentType> assignmentContainerWrapper : getModelObject().getValues()){
if (toDelete.contains(assignmentContainerWrapper)){
assignmentContainerWrapper.setStatus(ValueStatus.DELETED);
}
}
toDelete.forEach(value -> value.setStatus(ValueStatus.DELETED));
// for (ContainerValueWrapper<AssignmentType> assignmentContainerWrapper : getModelObject().getValues()){
// if (toDelete.contains(assignmentContainerWrapper)){
// assignmentContainerWrapper.setStatus(ValueStatus.DELETED);
// }
// }
refreshTable(target);
}

protected ContainerValueWrapper<AssignmentType> createNewAssignmentContainerValueWrapper(PrismContainerValue<AssignmentType> newAssignment) {
ContainerWrapperFactory factory = new ContainerWrapperFactory(getPageBase());
ContainerValueWrapper<AssignmentType> valueWrapper = factory.createContainerValueWrapper(getModelObject(), newAssignment,
ValueStatus.ADDED, new ItemPath(FocusType.F_ASSIGNMENT));
valueWrapper.setShowEmpty(true, false);
getModelObject().getValues().add(valueWrapper);
return valueWrapper;
}

protected WebMarkupContainer getAssignmentContainer() {
return (WebMarkupContainer) get(ID_ASSIGNMENTS);
Expand Down
Expand Up @@ -16,9 +16,11 @@
package com.evolveum.midpoint.web.component.assignment;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.prism.PrismContainer;
import com.evolveum.midpoint.prism.PrismContainerValue;
import com.evolveum.midpoint.prism.query.ObjectFilter;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
Expand Down Expand Up @@ -146,17 +148,11 @@ private AssignmentsTabStorage getPolicyRulesTabStorage(){

@Override
protected void newAssignmentClickPerformed(AjaxRequestTarget target) {
ContainerWrapperFactory factory = new ContainerWrapperFactory(getPageBase());

PrismContainerValue<AssignmentType> newAssignment = getModelObject().getItem().createNewValue();
newAssignment.asContainerable().setPolicyRule(new PolicyRuleType());


ContainerValueWrapper<AssignmentType> valueWrapper = factory.createContainerValueWrapper(getModelObject(), newAssignment,
ValueStatus.ADDED, new ItemPath(FocusType.F_ASSIGNMENT));
getModelObject().getValues().add(valueWrapper);

refreshTable(target);
ContainerValueWrapper<AssignmentType> newAssignmentWrapper = createNewAssignmentContainerValueWrapper(newAssignment);
assignmentDetailsPerformed(target, Arrays.asList(newAssignmentWrapper));
// refreshTable(target);

}

@Override
Expand Down
Expand Up @@ -81,6 +81,7 @@ public void onClick(AjaxRequestTarget ajaxRequestTarget) {
}
};
menuItemButton.setOutputMarkupId(true);
menuItemButton.setOutputMarkupPlaceholderTag(true);
menuItemButton.add(new AttributeAppender("class", "dropdown-toggle " + getAdditionalButtonClass()));
menuItemButton.add(new AttributeAppender("style", getMenuItemButtonStyle()));
menuItemContainer.add(menuItemButton);
Expand Down
Expand Up @@ -25,6 +25,7 @@
import com.evolveum.midpoint.web.component.assignment.AssignmentsUtil;
import com.evolveum.midpoint.web.component.form.Form;
import com.evolveum.midpoint.web.component.prism.*;
import com.evolveum.midpoint.web.model.ContainerWrapperFromObjectWrapperModel;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.apache.wicket.Component;
Expand Down Expand Up @@ -66,6 +67,7 @@ private void initLayout() {
assignments.setOutputMarkupId(true);
add(assignments);

new ContainerWrapperFromObjectWrapperModel<>(getObjectWrapperModel(), new ItemPath(FocusType.F_ASSIGNMENT));
AbstractRoleAssignmentPanel panel = new AbstractRoleAssignmentPanel(ID_ASSIGNMENTS_PANEL, Model.of(assignmentsContainerWrapper));

// new AbstractReadOnlyModel<ContainerWrapper<AssignmentType>>() {
Expand Down
Expand Up @@ -132,8 +132,8 @@ protected void populateItem(final ListItem<FocusSubwrapperDto<ShadowType>> item)
shadowPanel = new PrismPanel<F>(ID_SHADOW,
new ContainerWrapperListFromObjectWrapperModel(objectWrapperModel,
Arrays.asList(new ItemPath(ShadowType.F_ATTRIBUTES),
SchemaConstants.PATH_ACTIVATION, SchemaConstants.PATH_PASSWORD,
new ItemPath(ShadowType.F_ASSOCIATION))), packageRef,
SchemaConstants.PATH_ACTIVATION, SchemaConstants.PATH_PASSWORD
/*,new ItemPath(ShadowType.F_ASSOCIATION ) */)), packageRef,
getMainForm(), null, getPageBase());
} else {
shadowPanel = new SimpleErrorPanel<ShadowType>(ID_SHADOW, item.getModel()) {
Expand Down
Expand Up @@ -195,12 +195,22 @@ static String getDisplayNameFromItem(Item item) {
}

public boolean hasChanged() {
for (ItemWrapper item : getItems()) {
if (item.hasChanged()) {

switch (getStatus()) {
case DELETED :
return true;
}
case ADDED:
case NOT_CHANGED:
for (ItemWrapper item : getItems()) {
if (item.hasChanged()) {
return true;
}
}
}




return false;
}

Expand Down Expand Up @@ -372,7 +382,7 @@ public PrismContainerValue<C> createContainerValueAddDelta() throws SchemaExcept
try {
newValue.addAllReplaceExisting((Collection) getUpdatedContainerValueItems(containerValue.getPrismContext()));
} catch (TunnelException e) {
throw new SchemaException();
throw new SchemaException(e.getMessage(), e);
}

return newValue;
Expand Down Expand Up @@ -413,7 +423,7 @@ public Collection<Item> getUpdatedContainerValueItems(PrismContext prismContext)

}
} catch (SchemaException ex) {
throw new TunnelException("Cannot create add delta for container value: " + containerValue);
throw new TunnelException("Cannot create add delta for container value: " + containerValue, ex);
}
});
return updatedItems;
Expand Down
Expand Up @@ -357,29 +357,37 @@ public void setStripe(boolean isStripe) {
// Does not make much sense, but it is given by the interface
}

public PrismContainer createContainerAddDelta() throws SchemaException {
public PrismContainer<C> createContainerAddDelta() throws SchemaException {

PrismContainer containerAdd = container.clone();
PrismContainer<C> containerAdd = container.clone();

for (ContainerValueWrapper<C> itemWrapper : getValues()) {
if (!itemWrapper.hasChanged()) {
continue;
}

PrismContainerValue<C> newContainerValue = itemWrapper.createContainerValueAddDelta();

if (newContainerValue == null) {
continue;
}

if (itemWrapper.isMain()) {
containerAdd.setValue(itemWrapper.createContainerValueAddDelta());
containerAdd.setValue(newContainerValue);
continue;
}
containerAdd.add(itemWrapper.createContainerValueAddDelta());

if (containerAdd.isSingleValue()) {
containerAdd.replace(newContainerValue);
} else {
containerAdd.add(newContainerValue);
}
}
return containerAdd;
}

public <O extends ObjectType> void collectModifications(ObjectDelta<O> delta) throws SchemaException {

if (!hasChanged()) {
return;
}

for (ContainerValueWrapper<C> itemWrapper : getValues()) {
if (!itemWrapper.hasChanged()) {
continue;
Expand All @@ -398,7 +406,7 @@ public <O extends ObjectType> void collectModifications(ObjectDelta<O> delta) th
itemWrapper.collectModifications(delta);
break;
case DELETED:
delta.addModificationDeleteContainer(itemWrapper.getPath(), itemWrapper.getContainerValue().clone());
delta.addModificationDeleteContainer(getPath(), itemWrapper.getContainerValue().clone());
break;
}
}
Expand Down
Expand Up @@ -116,7 +116,7 @@ private <C extends Containerable> List<ContainerValueWrapper<C>> createContainer
List<ContainerValueWrapper<C>> containerValueWrappers = new ArrayList<>();
PrismContainer<C> container = cWrapper.getItem();

if (container.getValues().isEmpty()) {
if (container.getValues().isEmpty() && !(new ItemPath(FocusType.F_ASSIGNMENT)).equivalent(container.getPath())) {
PrismContainerValue<C> pcv = container.createNewValue();
ContainerValueWrapper<C> containerValueWrapper = createContainerValueWrapper(cWrapper, pcv, ValueStatus.ADDED, cWrapper.getPath());

Expand All @@ -125,7 +125,7 @@ private <C extends Containerable> List<ContainerValueWrapper<C>> createContainer
}

container.getValues().forEach(pcv -> {
ContainerValueWrapper<C> containerValueWrapper = createContainerValueWrapper(cWrapper, pcv, ValueStatus.NOT_CHANGED, pcv.getPath());
ContainerValueWrapper<C> containerValueWrapper = createContainerValueWrapper(cWrapper, pcv, cWrapper.getStatus() == ContainerStatus.ADDING ? ValueStatus.ADDED : ValueStatus.NOT_CHANGED, pcv.getPath());
containerValueWrappers.add(containerValueWrapper);
});

Expand Down Expand Up @@ -249,7 +249,7 @@ private <T, C extends Containerable> PropertyWrapper<T> createPropertyWrapper(
// }
return new PropertyWrapper(cWrapper, newProperty, propertyIsReadOnly, ValueStatus.ADDED, cWrapper.getPath().append(newProperty.getPath()));
}
return new PropertyWrapper(cWrapper, property, propertyIsReadOnly, ValueStatus.NOT_CHANGED, property.getPath());
return new PropertyWrapper(cWrapper, property, propertyIsReadOnly, cWrapper.getStatus() == ValueStatus.ADDED ? ValueStatus.ADDED: ValueStatus.NOT_CHANGED, property.getPath());
}

private <C extends Containerable> ReferenceWrapper createReferenceWrapper(PrismReferenceDefinition def, ContainerValueWrapper<C> cWrapper, boolean onlyEmpty) {
Expand All @@ -276,7 +276,7 @@ private <C extends Containerable> ReferenceWrapper createReferenceWrapper(PrismR
}

return new ReferenceWrapper(cWrapper, reference, propertyIsReadOnly,
ValueStatus.NOT_CHANGED, reference.getPath());
cWrapper.getStatus() == ValueStatus.ADDED ? ValueStatus.ADDED: ValueStatus.NOT_CHANGED, reference.getPath());

}

Expand Down Expand Up @@ -307,7 +307,7 @@ private <C extends Containerable> ContainerWrapper<C> createContainerWrapper(Pri
}
return createContainerWrapper(newContainer, ContainerStatus.ADDING, cWrapper.getPath().append(newContainer.getPath()));
}
return createContainerWrapper(container, ContainerStatus.MODIFYING, container.getPath());
return createContainerWrapper(container, cWrapper.getStatus() == ValueStatus.ADDED ? ContainerStatus.ADDING: ContainerStatus.MODIFYING, container.getPath());
}

private <C extends Containerable> ContainerWrapper<C> createPolicyConstraintsContainer(PrismContainer<C> policyConstraintsContainer, PrismContainerDefinition<C> def, ContainerValueWrapper<C> parentContainer) {
Expand Down
Expand Up @@ -343,8 +343,8 @@ public ObjectDelta<O> getObjectDelta() throws SchemaException {

for (ContainerWrapper containerWrapper : getContainers()) {
containerWrapper.collectModifications(delta);
containerWrapper.collectDeleteDelta(delta, object.getPrismContext());
containerWrapper.collectAddDelta(delta, object.getPrismContext());
// containerWrapper.collectDeleteDelta(delta, object.getPrismContext());
// containerWrapper.collectAddDelta(delta, object.getPrismContext());
}
// returning container to previous order
Collections.sort(containers, new ItemWrapperComparator());
Expand Down
Expand Up @@ -52,7 +52,8 @@ private List<ValueWrapper> createValues() {
List<ValueWrapper> values = new ArrayList<ValueWrapper>();

for (PrismReferenceValue prismValue : item.getValues()) {
values.add(new ValueWrapper(this, prismValue, prismValue, ValueStatus.NOT_CHANGED));

values.add(new ValueWrapper(this, prismValue, ValueStatus.NOT_CHANGED));
}

int minOccurs = getItemDefinition().getMinOccurs();
Expand Down

0 comments on commit 1b2b4da

Please sign in to comment.