Skip to content

Commit

Permalink
Moving things here and there in an attempt to fix association editor.…
Browse files Browse the repository at this point in the history
… Work in progress.
  • Loading branch information
semancik committed Dec 14, 2015
1 parent 16908de commit d21228d
Show file tree
Hide file tree
Showing 26 changed files with 634 additions and 270 deletions.
Expand Up @@ -18,7 +18,7 @@

import com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition;
import com.evolveum.midpoint.prism.PrismPropertyDefinition;
import com.evolveum.midpoint.web.component.util.BasePanel;
import com.evolveum.midpoint.web.component.util.BaseDeprecatedPanel;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
Expand All @@ -33,7 +33,7 @@
/**
* @author lazyman
*/
public class ACAttributePanel extends BasePanel<ACAttributeDto> {
public class ACAttributePanel extends BaseDeprecatedPanel<ACAttributeDto> {

private static final String ID_ATTRIBUTE_LABEL = "attributeLabel";
private static final String ID_VALUES = "values";
Expand Down
Expand Up @@ -19,7 +19,7 @@
import com.evolveum.midpoint.web.component.data.ObjectDataProvider;
import com.evolveum.midpoint.web.component.data.TablePanel;
import com.evolveum.midpoint.web.component.data.column.LinkColumn;
import com.evolveum.midpoint.web.component.util.BasePanel;
import com.evolveum.midpoint.web.component.util.BaseDeprecatedPanel;
import com.evolveum.midpoint.web.component.util.SelectableBean;
import com.evolveum.midpoint.web.page.PageBase;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
Expand All @@ -34,7 +34,7 @@
/**
* @author lazyman
*/
public class ResourceListPanel extends BasePanel {
public class ResourceListPanel extends BaseDeprecatedPanel {

public ResourceListPanel(String id) {
super(id, null);
Expand Down
Expand Up @@ -29,6 +29,7 @@
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.AjaxButton;
import com.evolveum.midpoint.web.component.util.BasePageAwarePanel;
import com.evolveum.midpoint.web.component.util.BaseSimplePanel;
import com.evolveum.midpoint.web.component.util.LoadableModel;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
Expand All @@ -40,6 +41,7 @@
import com.evolveum.midpoint.web.security.SecurityUtils;
import com.evolveum.midpoint.web.util.WebMiscUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Page;
import org.apache.wicket.ajax.AjaxRequestTarget;
Expand Down Expand Up @@ -103,7 +105,7 @@ public UserMenuPanel(String id) {

@Override
protected PasswordQuestionsDto load() {
return loadModel();
return loadModel(null);
}
};
isPasswordModelLoaded = true;
Expand All @@ -122,7 +124,7 @@ protected List<SecurityQuestionDefinitionType> load() {
@Override
protected void initLayout() {
if (userModel != null && userModel.getObject() == null){
loadModel();
loadModel(null);
}
WebMarkupContainer iconBox = new WebMarkupContainer(ID_ICON_BOX);
add(iconBox);
Expand All @@ -142,7 +144,7 @@ public AbstractResource getObject() {
@Override
public boolean isVisible(){
if (userModel != null && userModel.getObject() == null){
loadModel();
loadModel(null);
}
return jpegPhoto != null;
}
Expand All @@ -154,7 +156,7 @@ public boolean isVisible(){
@Override
public boolean isVisible(){
if (userModel != null && userModel.getObject() == null){
loadModel();
loadModel(null);
}
return jpegPhoto == null;

Expand Down Expand Up @@ -191,7 +193,7 @@ public AbstractResource getObject() {
@Override
public boolean isVisible(){
if (userModel != null && userModel.getObject() == null){
loadModel();
loadModel(null);
}
return jpegPhoto != null;
}
Expand All @@ -203,7 +205,7 @@ public boolean isVisible(){
@Override
public boolean isVisible(){
if (userModel != null && userModel.getObject() == null){
loadModel();
loadModel(null);
}
return jpegPhoto == null;
}
Expand Down Expand Up @@ -237,18 +239,14 @@ public void onClick(AjaxRequestTarget target) {
};
add(editPasswordQ);

if (!isUserModelLoaded) {
loadModel();

}
if (!isPasswordModelLoaded ){
passwordQuestionsDtoIModel = new LoadableModel<PasswordQuestionsDto>(false) {

private static final long serialVersionUID = 1L;

@Override
protected PasswordQuestionsDto load() {
return loadModel();
return loadModel(null);
}
};
isPasswordModelLoaded = true;
Expand Down Expand Up @@ -287,21 +285,30 @@ private String getShortUserName() {
return principal.toString();
}

private PasswordQuestionsDto loadModel() {
private PasswordQuestionsDto loadModel(PageBase parentPage) {
LOGGER.trace("Loading user for Security Question Page.");

PasswordQuestionsDto dto =new PasswordQuestionsDto();
OperationResult result = new OperationResult(OPERATION_LOAD_USER);
try{


if (parentPage == null) {
parentPage = ((PageBase)getPage());
}

try {

String userOid = SecurityUtils.getPrincipalUser().getOid();
Task task = ((PageBase)getPage()).createSimpleTask(OPERATION_LOAD_USER);
MidPointPrincipal principal = SecurityUtils.getPrincipalUser();
if (principal == null) {
result.recordNotApplicableIfUnknown();
return null;
}
String userOid = principal.getOid();
Task task = parentPage.createSimpleTask(OPERATION_LOAD_USER);
OperationResult subResult = result.createSubresult(OPERATION_LOAD_USER);

Collection options = SelectorOptions.createCollection(UserType.F_JPEG_PHOTO,
GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE));
PrismObject<UserType> user = ((PageBase)getPage()).getModelService().getObject(UserType.class, userOid, options, task, subResult);
PrismObject<UserType> user = parentPage.getModelService().getObject(UserType.class, userOid, options, task, subResult);
userModel.setObject(user);
jpegPhoto = user == null ? null :
(user.asObjectable() == null ? null : user.asObjectable().getJpegPhoto());
Expand Down
Expand Up @@ -22,14 +22,19 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.schema.constants.SchemaConstants;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;

Expand All @@ -40,6 +45,7 @@
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SystemException;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
Expand All @@ -54,6 +60,7 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationCapabilityType;
Expand All @@ -73,7 +80,7 @@ public class ContainerWrapper<T extends PrismContainer> implements ItemWrapper,
private static final String CREATE_PROPERTIES = DOT_CLASS + "createProperties";

private String displayName;
private ObjectWrapper<? extends ObjectType> object;
private ObjectWrapper<? extends ObjectType> objectWrapper;
private T container;
private ContainerStatus status;

Expand All @@ -87,23 +94,35 @@ public class ContainerWrapper<T extends PrismContainer> implements ItemWrapper,
private OperationResult result;

private PrismContainerDefinition containerDefinition;

public ContainerWrapper(ObjectWrapper object, T container, ContainerStatus status, ItemPath path,
public ContainerWrapper(ObjectWrapper objectWrapper, T container, ContainerStatus status, ItemPath path,
PageBase pageBase) {
this(objectWrapper, container, status, path, true, pageBase);
}

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(status, "Container status must not be null.");
Validate.notNull(pageBase, "pageBase must not be null.");

this.object = object;
this.objectWrapper = objectWrapper;
this.container = container;
this.status = status;
this.path = path;
main = path == null;
readonly = object.isReadonly(); // [pm] this is quite questionable
showInheritedObjectAttributes = object.isShowInheritedObjectAttributes();
readonly = objectWrapper.isReadonly(); // [pm] this is quite questionable
showInheritedObjectAttributes = objectWrapper.isShowInheritedObjectAttributes();
// have to be after setting "main" property
containerDefinition = getItemDefinition();
properties = createProperties(pageBase);
if (createProperties) {
// HACK HACK HACK, the container wrapper should not parse itself. This code should not be here.
// Constructor should NOT parse the object
// the createProperties parameter is here to avoid looping when parsing associations
properties = createProperties(pageBase);
} else {
properties = new ArrayList<>();
}
}

public void revive(PrismContext prismContext) throws SchemaException {
Expand All @@ -123,9 +142,9 @@ public void revive(PrismContext prismContext) throws SchemaException {
@Override
public PrismContainerDefinition getItemDefinition() {
if (main) {
return object.getDefinition();
return objectWrapper.getDefinition();
} else {
return object.getDefinition().findContainerDefinition(path);
return objectWrapper.getDefinition().findContainerDefinition(path);
}
}

Expand All @@ -138,7 +157,7 @@ void clearResult() {
}

ObjectWrapper getObject() {
return object;
return objectWrapper;
}

ContainerStatus getStatus() {
Expand Down Expand Up @@ -180,15 +199,15 @@ private List<ItemWrapper> createProperties(PageBase pageBase) {

if (ShadowType.F_ATTRIBUTES.equals(name)) {
try {
definition = object.getRefinedAttributeDefinition();
definition = objectWrapper.getRefinedAttributeDefinition();

if (definition == null) {
PrismReference resourceRef = parent.findReference(ShadowType.F_RESOURCE_REF);
PrismObject<ResourceType> resource = resourceRef.getValue().getObject();

definition = pageBase
.getModelInteractionService()
.getEditObjectClassDefinition((PrismObject<ShadowType>) object.getObject(), resource,
.getEditObjectClassDefinition((PrismObject<ShadowType>) objectWrapper.getObject(), resource,
AuthorizationPhaseType.REQUEST)
.toResourceAttributeContainerDefinition();

Expand Down Expand Up @@ -266,12 +285,31 @@ private List<ItemWrapper> createProperties(PageBase pageBase) {
}

} else if (isShadowAssociation()) {
if (object.getAssociations() != null) {
for (PrismProperty property : object.getAssociations()) {
// TODO: fix this -> for now, read only is supported..
PropertyWrapper propertyWrapper = new PropertyWrapper(this, property, false,
ValueStatus.NOT_CHANGED);
properties.add(propertyWrapper);
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();
PrismContainer<ShadowAssociationType> fractionalContainer = assocMap.get(assocName);
if (fractionalContainer == null) {
fractionalContainer = new PrismContainer<>(ShadowType.F_ASSOCIATION, ShadowAssociationType.class, cval.getPrismContext());
fractionalContainer.setDefinition(cval.getParent().getDefinition());
// HACK: set the name of the association as the element name so wrapper.getName() will return correct data.
fractionalContainer.setElementName(assocName);
assocMap.put(assocName, fractionalContainer);
}
try {
fractionalContainer.add(cval.clone());
} catch (SchemaException e) {
// Should not happen
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.
PropertyWrapper assocWrapper = new PropertyWrapper(this, assocEntry.getValue(), this.isReadonly(), ValueStatus.NOT_CHANGED);
properties.add(assocWrapper);
}
}

Expand Down Expand Up @@ -311,7 +349,7 @@ private List<ItemWrapper> createProperties(PageBase pageBase) {
// decision is based on parent object status, not this
// container's one (because container can be added also
// to an existing object)
if (object.getStatus() == ContainerStatus.MODIFYING) {
if (objectWrapper.getStatus() == ContainerStatus.MODIFYING) {

propertyIsReadOnly = !def.canModify();
} else {
Expand All @@ -336,7 +374,7 @@ private List<ItemWrapper> createProperties(PageBase pageBase) {
// decision is based on parent object status, not this
// container's one (because container can be added also
// to an existing object)
if (object.getStatus() == ContainerStatus.MODIFYING) {
if (objectWrapper.getStatus() == ContainerStatus.MODIFYING) {

propertyIsReadOnly = !def.canModify();
} else {
Expand Down Expand Up @@ -487,7 +525,7 @@ boolean isItemVisible(ItemWrapper item) {

// we decide not according to status of this container, but according to
// the status of the whole object
if (object.getStatus() == ContainerStatus.ADDING) {
if (objectWrapper.getStatus() == ContainerStatus.ADDING) {
return def.canAdd();
}

Expand All @@ -506,8 +544,13 @@ boolean isItemVisible(ItemWrapper item) {
private boolean showEmpty(ItemWrapper item) {
ObjectWrapper object = getObject();
List<ValueWrapper> values = item.getValues();
boolean isEmpty = values.isEmpty();
if (values.size() == 1) {
boolean isEmpty;
if (values == null) {
isEmpty = true;
} else {
isEmpty = values.isEmpty();
}
if (!isEmpty && values.size() == 1) {
ValueWrapper value = values.get(0);
if (ValueStatus.ADDED.equals(value.getStatus())) {
isEmpty = true;
Expand All @@ -529,6 +572,11 @@ public void setDisplayName(String name) {
this.displayName = name;
}

@Override
public QName getName() {
return getItem().getElementName();
}

public boolean isMain() {
return main;
}
Expand Down
Expand Up @@ -18,6 +18,8 @@

import java.util.List;

import javax.xml.namespace.QName;

import com.evolveum.midpoint.prism.Item;
import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.Revivable;
Expand All @@ -28,6 +30,8 @@
*/
public interface ItemWrapper extends Revivable, DebugDumpable {

QName getName();

String getDisplayName();

void setDisplayName(String name);
Expand Down

0 comments on commit d21228d

Please sign in to comment.