Skip to content

Commit

Permalink
Fixhack for user/org properties such as approverRef (MID-3201)
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Jun 22, 2016
1 parent a744e08 commit dcb1470
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 42 deletions.
Expand Up @@ -58,12 +58,18 @@ public class ObjectBrowserPanel<T extends ObjectType> extends BasePanel<T> imple
private PageBase parentPage;
private ObjectFilter queryFilter;

public ObjectBrowserPanel(String id, final Class<T> type, List<QName> supportedTypes, boolean multiselect,
/**
* @param defaultType specifies type of the object that will be selected by default
*/
public ObjectBrowserPanel(String id, final Class<T> defaultType, List<QName> supportedTypes, boolean multiselect,
PageBase parentPage) {
this(id, type, supportedTypes, multiselect, parentPage, null);
this(id, defaultType, supportedTypes, multiselect, parentPage, null);
}

public ObjectBrowserPanel(String id, final Class<T> type, List<QName> supportedTypes, boolean multiselect,
/**
* @param defaultType specifies type of the object that will be selected by default
*/
public ObjectBrowserPanel(String id, final Class<T> defaultType, List<QName> supportedTypes, boolean multiselect,
PageBase parentPage, ObjectFilter queryFilter) {
super(id);
this.parentPage = parentPage;
Expand All @@ -73,12 +79,12 @@ public ObjectBrowserPanel(String id, final Class<T> type, List<QName> supportedT

@Override
protected QName load() {
return compileTimeClassToQName(type);
return compileTimeClassToQName(defaultType);
}

};

initLayout(type, supportedTypes, multiselect);
initLayout(defaultType, supportedTypes, multiselect);
}

private void initLayout(Class<T> type, final List<QName> supportedTypes, final boolean multiselect) {
Expand Down
Expand Up @@ -100,19 +100,25 @@ public Class<O> getType() {
storageMap.put(PageServices.class, SessionStorage.KEY_SERVICES);
}

public ObjectListPanel(String id, Class<O> type, TableId tableId, Collection<SelectorOptions<GetOperationOptions>> options,
/**
* @param defaultType specifies type of the object that will be selected by default. It can be changed.
*/
public ObjectListPanel(String id, Class<O> defaultType, TableId tableId, Collection<SelectorOptions<GetOperationOptions>> options,
PageBase parentPage) {
super(id);
this.type = type;
this.type = defaultType;
this.parentPage = parentPage;
this.options = options;
this.tableId = tableId;
initLayout();
}

ObjectListPanel(String id, Class<O> type, boolean multiselect, PageBase parentPage) {
/**
* @param defaultType specifies type of the object that will be selected by default. It can be changed.
*/
ObjectListPanel(String id, Class<O> defaultType, boolean multiselect, PageBase parentPage) {
super(id);
this.type = type;
this.type = defaultType;
this.parentPage = parentPage;
this.multiselect = multiselect;
initLayout();
Expand Down
@@ -1,3 +1,18 @@
/*
* Copyright (c) 2010-2016 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.gui.api.component;

import java.util.List;
Expand All @@ -17,16 +32,22 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

public abstract class PopupObjectListPanel<T extends ObjectType> extends ObjectListPanel<T> {
private static final long serialVersionUID = 1L;

public PopupObjectListPanel(String id, Class<T> type, boolean multiselect, PageBase parentPage) {
super(id, type, multiselect, parentPage);
/**
* @param defaultType specifies type of the object that will be selected by default
*/
public PopupObjectListPanel(String id, Class<T> defaultType, boolean multiselect, PageBase parentPage) {
super(id, defaultType, multiselect, parentPage);

}

@Override
protected IColumn<SelectableBean<T>, String> createCheckboxColumn() {
if (isMultiselect()) {
return new CheckBoxHeaderColumn<SelectableBean<T>>() {
private static final long serialVersionUID = 1L;

@Override
protected void onUpdateRow(AjaxRequestTarget target, DataTable table, IModel<SelectableBean<T>> rowModel) {
super.onUpdateRow(target, table, rowModel);
Expand All @@ -48,6 +69,7 @@ protected IColumn<SelectableBean<T>, String> createNameColumn() {
if (!isMultiselect()) {
return new LinkColumn<SelectableBean<T>>(createStringResource("ObjectType.name"),
ObjectType.F_NAME.getLocalPart(), SelectableBean.F_VALUE + ".name") {
private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target, IModel<SelectableBean<T>> rowModel) {
Expand Down
Expand Up @@ -28,6 +28,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;

Expand Down Expand Up @@ -119,6 +120,7 @@
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.DisplayableValue;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SystemException;
Expand Down Expand Up @@ -296,6 +298,7 @@ public static boolean isAuthorized(Collection<String> actions) {
return false;
}

// TODO: move to util component
public static Integer safeLongToInteger(Long l) {
if (l == null) {
return null;
Expand All @@ -309,6 +312,7 @@ public static Integer safeLongToInteger(Long l) {
return (int) l.longValue();
}

// TODO: move to schema component
public static List<QName> createObjectTypeList() {
List<QName> types = new ArrayList<>(ObjectTypes.values().length);
for (ObjectTypes t : ObjectTypes.values()) {
Expand All @@ -317,6 +321,7 @@ public static List<QName> createObjectTypeList() {
return types;
}

// TODO: move to schema component
public static List<QName> createFocusTypeList() {
List<QName> focusTypeList = new ArrayList<>();

Expand All @@ -328,6 +333,7 @@ public static List<QName> createFocusTypeList() {
return focusTypeList;
}

// TODO: move to schema component
public static List<QName> createAbstractRoleTypeList() {
List<QName> focusTypeList = new ArrayList<>();

Expand All @@ -339,6 +345,7 @@ public static List<QName> createAbstractRoleTypeList() {
return focusTypeList;
}

// TODO: move to schema component
public static List<QName> createAssignableTypesList() {
List<QName> focusTypeList = new ArrayList<>();

Expand All @@ -349,6 +356,32 @@ public static List<QName> createAssignableTypesList() {

return focusTypeList;
}

/**
* Takes a collection of object types (classes) that may contain abstract types. Returns a collection
* that only contain concrete types.
* @param <O> common supertype for all the types in the collections
*
* TODO: move to schema component
*/
public static <O extends ObjectType> List<QName> resolveObjectTypesToQNames(Collection<Class<? extends O>> types, PrismContext prismContext) {
if (types == null) {
return null;
}
List<QName> concreteTypes = new ArrayList<>(types.size());
for (Class<? extends O> type: types) {
if (type == null || type.equals(ObjectType.class)) {
MiscUtil.addAllIfNotPresent(concreteTypes, WebComponentUtil.createObjectTypeList());
} else if (type.equals(FocusType.class)) {
MiscUtil.addAllIfNotPresent(concreteTypes, WebComponentUtil.createFocusTypeList());
} else if (type.equals(AbstractRoleType.class)) {
MiscUtil.addAllIfNotPresent(concreteTypes, WebComponentUtil.createAbstractRoleTypeList());
} else {
MiscUtil.addIfNotPresent(concreteTypes, WebComponentUtil.classToQName(prismContext, type));
}
}
return concreteTypes;
}

public static <T extends Enum> IModel<String> createLocalizedModelForEnum(T value, Component comp) {
String key = value != null ? value.getClass().getSimpleName() + "." + value.name() : "";
Expand Down Expand Up @@ -1673,5 +1706,6 @@ public static <O extends ObjectType> Class<? extends PageBase> getObjectDetailsP
} else {
throw new IllegalArgumentException("Cannot determine details page for "+type);
}
}
}

}
Expand Up @@ -16,6 +16,7 @@
package com.evolveum.midpoint.web.component.form;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.xml.namespace.QName;
Expand All @@ -42,12 +43,18 @@
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.page.admin.dto.ObjectViewDto;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AbstractRoleType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

public class ValueChoosePanel<T, C extends ObjectType> extends BasePanel<T> {
/**
*
* TODO: rename to ValueObjectChoicePanel, PrismValueObjectSelectorPanel or something better
*
* @param <T>
* @param <O> common superclass for all the options of objects that this panel should choose
*/
public class ValueChoosePanel<T, O extends ObjectType> extends BasePanel<T> {

private static final long serialVersionUID = 1L;

Expand All @@ -60,18 +67,18 @@ public class ValueChoosePanel<T, C extends ObjectType> extends BasePanel<T> {

protected static final String MODAL_ID_OBJECT_SELECTION_POPUP = "objectSelectionPopup";

private Class<C> type;
private Collection<Class<? extends O>> types;

public ValueChoosePanel(String id, IModel<T> value, List<PrismReferenceValue> values, boolean required, Class<C> type) {
public ValueChoosePanel(String id, IModel<T> value, List<PrismReferenceValue> values, boolean required, Collection<Class<? extends O>> types) {
super(id, value);
setOutputMarkupId(true);

this.type = type;
this.types = types;

initLayout(value, values, required, type);
initLayout(value, values, required, types);
}

private void initLayout(final IModel<T> value, final List<PrismReferenceValue> values, final boolean required, Class<C> type) {
private void initLayout(final IModel<T> value, final List<PrismReferenceValue> values, final boolean required, Collection<Class<? extends O>> types) {


WebMarkupContainer textWrapper = new WebMarkupContainer(ID_TEXT_WRAPPER);
Expand Down Expand Up @@ -170,23 +177,14 @@ public String getObject() {
}

protected void editValuePerformed(List<PrismReferenceValue> values, AjaxRequestTarget target) {
List<QName> supportedTypes = null;
if (type == null || type.equals(ObjectType.class)) {
supportedTypes = WebComponentUtil.createObjectTypeList();
} else if (type.equals(FocusType.class)) {
supportedTypes = WebComponentUtil.createFocusTypeList();
} else if (type.equals(AbstractRoleType.class)) {
supportedTypes = WebComponentUtil.createAbstractRoleTypeList();
} else {
supportedTypes = new ArrayList<>();
supportedTypes.add(WebComponentUtil.classToQName(getPageBase().getPrismContext(), type));
}
List<QName> supportedTypes = WebComponentUtil.resolveObjectTypesToQNames(types, getPageBase().getPrismContext());
ObjectFilter filter = createChooseQuery(values) == null ? null : createChooseQuery(values).getFilter();
ObjectBrowserPanel<C> objectBrowserPanel = new ObjectBrowserPanel<C>(getPageBase().getMainPopupBodyId(), type, supportedTypes, false, getPageBase(), filter) {
Class<O> defaultType = (Class<O>) types.iterator().next();
ObjectBrowserPanel<O> objectBrowserPanel = new ObjectBrowserPanel<O>(getPageBase().getMainPopupBodyId(), defaultType, supportedTypes, false, getPageBase(), filter) {
private static final long serialVersionUID = 1L;

@Override
protected void onSelectPerformed(AjaxRequestTarget target, C object) {
protected void onSelectPerformed(AjaxRequestTarget target, O object) {
getPageBase().hideMainPopup(target);
ValueChoosePanel.this.choosePerformed(target, object);
}
Expand All @@ -203,7 +201,7 @@ protected void onSelectPerformed(AjaxRequestTarget target, C object) {
* selected values array This is a temporary solution until we well be able
* to create "already-chosen" query
*/
protected void choosePerformed(AjaxRequestTarget target, C object) {
protected void choosePerformed(AjaxRequestTarget target, O object) {
choosePerformedHook(target, object);

if (isObjectUnique(object)) {
Expand All @@ -217,7 +215,7 @@ protected void choosePerformed(AjaxRequestTarget target, C object) {
}


protected boolean isObjectUnique(C object) {
protected boolean isObjectUnique(O object) {

PrismReferenceValue old = (PrismReferenceValue) getModelObject();
if (old == null || old.isEmpty()) {
Expand All @@ -235,7 +233,7 @@ protected boolean isObjectUnique(C object) {
* A custom code in form of hook that can be run on event of choosing new
* object with this chooser component
*/
protected void choosePerformedHook(AjaxRequestTarget target, C object) {
protected void choosePerformedHook(AjaxRequestTarget target, O object) {
}

}
Expand Up @@ -72,7 +72,7 @@ public PrismPropertyPanel(String id, final IModel<IW> model, Form form, PageBase

setOutputMarkupId(true);
add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;

@Override
public boolean isVisible() {
Expand Down
Expand Up @@ -677,13 +677,24 @@ public void checkInputValue(AutoCompleteTextField input, AjaxRequestTarget targe
prismContext = pageBase.getPrismContext();
}
QName targetTypeName = ((PrismReferenceDefinition) item.getDefinition()).getTargetTypeName();
Class typeFromName = null;
Class targetClass = null;
if (targetTypeName != null && prismContext != null) {
typeFromName = prismContext.getSchemaRegistry().determineCompileTimeClass(targetTypeName);
targetClass = prismContext.getSchemaRegistry().determineCompileTimeClass(targetTypeName);
}
final Class typeClass = typeFromName != null ? typeFromName : (item.getDefinition().getTypeClassIfKnown() != null ? item.getDefinition().getTypeClassIfKnown() : FocusType.class);
panel = new ValueChoosePanel(id,
new PropertyModel<>(valueWrapperModel, "value"), item.getValues(), false, typeClass);
final Class typeClass = targetClass != null ? targetClass :
(item.getDefinition().getTypeClassIfKnown() != null ? item.getDefinition().getTypeClassIfKnown() : FocusType.class);
Collection typeClasses = new ArrayList();

// HACK HACK MID-3201 MID-3231
if (isUserOrgItem(item, typeClass)) {
typeClasses.add(UserType.class);
typeClasses.add(OrgType.class);
} else {
typeClasses.add(typeClass);
}

panel = new ValueChoosePanel(id,
new PropertyModel<>(valueWrapperModel, "value"), item.getValues(), false, typeClasses);

} else if (item instanceof PrismContainer<?>) {
AssociationWrapper itemWrapper = (AssociationWrapper) valueWrapperModel.getObject().getItem();
Expand Down Expand Up @@ -731,7 +742,13 @@ public void checkInputValue(AutoCompleteTextField input, AjaxRequestTarget targe
return panel;
}

private List<String> prepareAutoCompleteList(String input, PrismObject<LookupTableType> lookupTable){
private boolean isUserOrgItem(Item item, Class referenceType) {
return (referenceType == ObjectType.class || referenceType == FocusType.class) &&
(AbstractRoleType.F_APPROVER_REF.equals(item.getElementName()) ||
AbstractRoleType.F_OWNER_REF.equals(item.getElementName()));
}

private List<String> prepareAutoCompleteList(String input, PrismObject<LookupTableType> lookupTable){
List<String> values = new ArrayList<>();

if(lookupTable == null){
Expand Down

0 comments on commit dcb1470

Please sign in to comment.