Skip to content

Commit

Permalink
Associations editable panel. not finished yet
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Dec 4, 2015
1 parent 8c6057e commit db8c5a3
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 55 deletions.
@@ -1,8 +1,11 @@
package com.evolveum.midpoint.web.component.form;

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

import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.web.page.admin.configuration.component.ObjectSelectionPage;
import com.evolveum.midpoint.web.util.WebMiscUtil;
import org.apache.wicket.Page;
Expand Down Expand Up @@ -55,14 +58,22 @@ public class ValueChoosePanel <T, C extends ObjectType> extends SimplePanel<T> {

private static final String CLASS_MULTI_VALUE = "multivalue-form";

public ValueChoosePanel(String id, IModel<T> value, List<PrismReferenceValue> values, boolean required, Class<C> type) {
super(id, value);
setOutputMarkupId(true);
private Collection<SelectorOptions<GetOperationOptions>> options = null;

initLayout(value, values, required, type);
public ValueChoosePanel(String id, IModel<T> value, List<PrismReferenceValue> values, boolean required, Class<C> type) {
this(id, value, values, required, type, null, null);
}

private void initLayout(final IModel<T> value, final List<PrismReferenceValue> values, final boolean required, Class<C> type) {
public ValueChoosePanel(String id, IModel<T> value, List<PrismReferenceValue> values, boolean required, Class<C> type,
ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options){
super(id, value);
setOutputMarkupId(true);
this.options = options;
initLayout(value, values, required, type, query);
}

private void initLayout(final IModel<T> value, final List<PrismReferenceValue> values,
final boolean required, Class<C> type, ObjectQuery query) {


WebMarkupContainer textWrapper = new WebMarkupContainer(ID_TEXT_WRAPPER);
Expand Down Expand Up @@ -92,7 +103,7 @@ public void onClick(AjaxRequestTarget target) {
textWrapper.add(edit);
add(textWrapper);

initDialog(type, values);
initDialog(type, values, query);

}

Expand All @@ -108,19 +119,19 @@ protected void replaceIfEmpty(Object object) {

}

protected void initDialog(final Class<C> type, List<PrismReferenceValue> values) {
protected void initDialog(final Class<C> type, List<PrismReferenceValue> values, ObjectQuery query) {

if (FocusType.class.equals(type)){
initUserOrgDialog();
} else {
initGenericDialog(type, values);
initGenericDialog(type, values, query);


}
}

// for ModalWindow treatment see comments in ChooseTypePanel
private void initGenericDialog(final Class<C> type, final List<PrismReferenceValue> values) {
private void initGenericDialog(final Class<C> type, final List<PrismReferenceValue> values, final ObjectQuery query) {
final ModalWindow dialog = new ModalWindow(MODAL_ID_OBJECT_SELECTION_POPUP);

ObjectSelectionPanel.Context context = new ObjectSelectionPanel.Context(this) {
Expand All @@ -135,14 +146,23 @@ public void chooseOperationPerformed(AjaxRequestTarget target, ObjectType object
getRealParent().choosePerformed(target, object);
}

@Override
public Collection<SelectorOptions<GetOperationOptions>> getDataProviderOptions(){
return options;
}

@Override
public ObjectQuery getDataProviderQuery() {
return getRealParent().createChooseQuery(values);
if (query != null){
return query;
} else {
return getRealParent().createChooseQuery(values);
}
}

@Override
public boolean isSearchEnabled() {
return true;
return false;
}

@Override
Expand Down
Expand Up @@ -29,10 +29,7 @@
import com.evolveum.midpoint.model.api.ScriptExecutionException;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.parser.QueryConvertor;
import com.evolveum.midpoint.prism.query.AndFilter;
import com.evolveum.midpoint.prism.query.EqualFilter;
import com.evolveum.midpoint.prism.query.ObjectFilter;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.query.*;
import com.evolveum.midpoint.schema.util.ObjectQueryUtil;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
Expand Down Expand Up @@ -414,45 +411,22 @@ private Panel createTypedInputComponent(String id) {
ContainerWrapper containerWrapper = itemWrapper.getContainer();
if(containerWrapper != null && containerWrapper.getPath() != null){
if(ShadowType.F_ASSOCIATION.getLocalPart().equals(containerWrapper.getPath().toString())){
Class typeFromName = null;
PrismContext prismContext = item.getPrismContext();
if (prismContext == null) {
prismContext = pageBase.getPrismContext();
}

PrismContainerValue assocContainer = (PrismContainerValue)item.getParent();
PrismProperty assocObjectClassItem = (PrismProperty)assocContainer.findItem(ShadowType.F_OBJECT_CLASS);
QName objectClassName = null;
if (assocObjectClassItem != null && assocObjectClassItem.getValues() != null
&& assocObjectClassItem.getValues().size() > 0) {
objectClassName = (QName)((PrismPropertyValue)assocObjectClassItem.getValues().get(0)).getValue();
}

PrismProperty objectClassItem = (PrismProperty)assocContainer.findItem(ShadowType.F_OBJECT_CLASS);
PrismProperty kindItem = (PrismProperty)assocContainer.findItem(ShadowType.F_KIND);
ShadowKindType shadowKindType = null;
if (kindItem != null){
shadowKindType = kindItem.getValues() != null && kindItem.getValues().size() > 0 ?
(ShadowKindType)((PrismPropertyValue)kindItem.getValues().get(0)).getValue() : null;
}

PrismProperty intentItem = (PrismProperty)assocContainer.findItem(ShadowType.F_INTENT);
String intentValue = "";
if (intentItem != null){
intentValue = intentItem.getValues() != null && intentItem.getValues().size() > 0 ?
(String)((PrismPropertyValue)intentItem.getValues().get(0)).getValue() : "";
}

List<PrismObject<ShadowType>> values = loadAssociationShadows(assocObjectClassItem, kindItem, intentItem);
PrismObject<ResourceType> resource = ((ShadowType)containerWrapper.getObject().getObject().asObjectable()).getResource().asPrismObject();
ObjectQuery query = getAssociationsSearchQuery(resource,
objectClassItem, kindItem, intentItem);
List<PrismObject<ShadowType>> values = loadAssociationShadows(query);

return new ValueChoosePanel(id,
new PropertyModel<>(model, "value"), values, false, ShadowType.class);
// return new TextDetailsPanel(id, new PropertyModel<String>(model, baseExpression)){
//
// @Override
// public String createAssociationTooltip(){
// return createAssociationTooltipText(property);
// }
// };
new PropertyModel<>(model, "value"), values, false, ShadowType.class, query, getAssociationsSearchOptions());
}
}

Expand Down Expand Up @@ -798,30 +772,38 @@ private void removeValue(AjaxRequestTarget target) {
target.add(parent.getParent());
}

private List<PrismObject<ShadowType>> loadAssociationShadows(PrismProperty objectClass, PrismProperty kind,
PrismProperty intent) {
private List<PrismObject<ShadowType>> loadAssociationShadows(ObjectQuery query) {
Task task = pageBase.createSimpleTask(OPERATION_LOAD_ASSOC_SHADOWS);
OperationResult result = new OperationResult(OPERATION_LOAD_ASSOC_SHADOWS);

List<PrismObject<ShadowType>> assocShadows = null;
try {
ObjectFilter andFilter = AndFilter.createAnd(EqualFilter.createEqual(new ItemPath(ShadowType.F_OBJECT_CLASS), objectClass),
EqualFilter.createEqual(new ItemPath(ShadowType.F_KIND), kind),
EqualFilter.createEqual(new ItemPath(ShadowType.F_INTENT), intent));
ObjectQuery objectQuery = ObjectQuery.createObjectQuery(andFilter);

objectQuery.setFilter(andFilter);
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createNoFetch());

assocShadows = pageBase.getModelService().searchObjects(ShadowType.class, new ObjectQuery(), null, task, result);
assocShadows = pageBase.getModelService().searchObjects(ShadowType.class, query, getAssociationsSearchOptions(), task, result);
} catch (Exception ex) {
LoggingUtils.logException(LOGGER, "Unable to load association shadow", ex);
result.recordFatalError("Unable to load association shadow", ex);
} finally {
result.computeStatus();
}

return assocShadows;
}

private ObjectQuery getAssociationsSearchQuery(PrismObject resource, PrismProperty objectClass, PrismProperty kind,
PrismProperty intent){
ObjectFilter andFilter = AndFilter.createAnd(
EqualFilter.createEqual(new ItemPath(ShadowType.F_OBJECT_CLASS), objectClass),
EqualFilter.createEqual(new ItemPath(ShadowType.F_KIND), kind),
EqualFilter.createEqual(new ItemPath(ShadowType.F_INTENT), intent),
RefFilter.createReferenceEqual(ShadowType.F_RESOURCE_REF, ShadowType.class, resource));
ObjectQuery query = ObjectQuery.createObjectQuery(andFilter);
return query;
}

private Collection<SelectorOptions<GetOperationOptions>> getAssociationsSearchOptions(){
Collection<SelectorOptions<GetOperationOptions>> options = new ArrayList<SelectorOptions<GetOperationOptions>>();
options.add(SelectorOptions.create(ItemPath.EMPTY_PATH, GetOperationOptions.createRaw()));
options.add(SelectorOptions.create(ItemPath.EMPTY_PATH, GetOperationOptions.createNoFetch()));
return options;
}
}
Expand Up @@ -22,6 +22,8 @@
import com.evolveum.midpoint.prism.query.AndFilter;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.query.SubstringFilter;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SelectorOptions;
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 @@ -57,6 +59,7 @@
import javax.xml.namespace.QName;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
Expand Down Expand Up @@ -137,6 +140,10 @@ protected WebMarkupContainer createExtraContentContainer(String extraContentId,
container.setOutputMarkupPlaceholderTag(true);
return container;
}

public Collection<SelectorOptions<GetOperationOptions>> getDataProviderOptions(){
return null;
}
}

public ObjectSelectionPanel(String id, Class<? extends ObjectType> type, ModalWindow modalWindow, Context context) {
Expand Down Expand Up @@ -195,6 +202,7 @@ protected void clearSearchPerformed(AjaxRequestTarget target) {
List<IColumn<SelectableBean<ObjectType>, String>> columns = initColumns();
ObjectDataProvider provider = new ObjectDataProvider(pageBase, this.objectType);
provider.setQuery(context.getDataProviderQuery());
provider.setOptions(context.getDataProviderOptions());
TablePanel table = new TablePanel<>(ID_TABLE, provider, columns);
table.setOutputMarkupId(true);
addOrReplace(table);
Expand Down

0 comments on commit db8c5a3

Please sign in to comment.