Skip to content

Commit

Permalink
fix for MID-5025 Role inducement association shadow ref error
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Feb 26, 2019
1 parent e3d7c1f commit 3967a5b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 27 deletions.
Expand Up @@ -48,6 +48,7 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.types_3.ItemPathType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
import org.apache.commons.collections.CollectionUtils;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.feedback.FeedbackMessage;
Expand Down Expand Up @@ -237,41 +238,40 @@ protected void executeCustomRemoveAction(AjaxRequestTarget target) {
ExpressionUtil.removeEvaluatorByName(ExpressionValuePanel.this.getModelObject(), SchemaConstantsGenerated.C_VALUE);
}

@Override
protected boolean isEnabledToEdit(){
Collection<RefinedAssociationDefinition> refinedAssociationDefinitions = getRefinedAssociationDefinitions();
return CollectionUtils.isNotEmpty(refinedAssociationDefinitions);
}

@Override
protected IModel<String> getPanelTitle(){
Collection<RefinedAssociationDefinition> refinedAssociationDefinitions = getRefinedAssociationDefinitions();
return CollectionUtils.isNotEmpty(refinedAssociationDefinitions) ? null : createStringResource("ExpressionValuePanel.associationDefenitionsNotDefined");
}

@Override
protected ObjectQuery getChooseQuery() {
ObjectQuery query = new ObjectQuery();

ExpressionType expression = ExpressionValuePanel.this.getModelObject();
if (expression == null || construction == null){
return new ObjectQuery();
}
PrismObject<ResourceType> resource = getResource();
if (resource == null){
if (expression == null || construction == null || resource == null){
return new ObjectQuery();
}

try {
RefinedResourceSchema refinedResourceSchema = RefinedResourceSchema.getRefinedSchema(resource);
RefinedObjectClassDefinition oc = refinedResourceSchema.getRefinedDefinition(construction.getKind(), construction.getIntent());
if (oc == null){
return new ObjectQuery();
}
Collection<RefinedAssociationDefinition> refinedAssociationDefinitions = oc.getAssociationDefinitions();

for (RefinedAssociationDefinition refinedAssociationDefinition : refinedAssociationDefinitions) {
S_FilterEntryOrEmpty atomicFilter = QueryBuilder.queryFor(ShadowType.class, pageBase.getPrismContext());
List<ObjectFilter> orFilterClauses = new ArrayList<>();
refinedAssociationDefinition.getIntents()
.forEach(intent -> orFilterClauses.add(atomicFilter.item(ShadowType.F_INTENT).eq(intent).buildFilter()));
OrFilter intentFilter = OrFilter.createOr(orFilterClauses);

AndFilter filter = (AndFilter) atomicFilter.item(ShadowType.F_KIND).eq(refinedAssociationDefinition.getKind()).and()
.item(ShadowType.F_RESOURCE_REF).ref(resource.getOid(), ResourceType.COMPLEX_TYPE).buildFilter();
filter.addCondition(intentFilter);
query.setFilter(filter);
}
} catch (SchemaException ex) {
LOGGER.error("Couldn't create query filter for ShadowType popup list: {}" , ex.getErrorTypeMessage());
Collection<RefinedAssociationDefinition> refinedAssociationDefinitions = getRefinedAssociationDefinitions();

for (RefinedAssociationDefinition refinedAssociationDefinition : refinedAssociationDefinitions) {
S_FilterEntryOrEmpty atomicFilter = QueryBuilder.queryFor(ShadowType.class, pageBase.getPrismContext());
List<ObjectFilter> orFilterClauses = new ArrayList<>();
refinedAssociationDefinition.getIntents()
.forEach(intent -> orFilterClauses.add(atomicFilter.item(ShadowType.F_INTENT).eq(intent).buildFilter()));
OrFilter intentFilter = OrFilter.createOr(orFilterClauses);

AndFilter filter = (AndFilter) atomicFilter.item(ShadowType.F_KIND).eq(refinedAssociationDefinition.getKind()).and()
.item(ShadowType.F_RESOURCE_REF).ref(resource.getOid(), ResourceType.COMPLEX_TYPE).buildFilter();
filter.addCondition(intentFilter);
query.setFilter(filter);
}
return query;
}
Expand All @@ -295,6 +295,27 @@ public void onClick(AjaxRequestTarget target) {
shadowRefValueContainer.add(removeButton);
}

private Collection<RefinedAssociationDefinition> getRefinedAssociationDefinitions(){
PrismObject<ResourceType> resource = getResource();
Collection<RefinedAssociationDefinition> refinedAssociationDefinitions = null;
if (resource == null){
return refinedAssociationDefinitions;
}

try {
RefinedResourceSchema refinedResourceSchema = RefinedResourceSchema.getRefinedSchema(resource);
RefinedObjectClassDefinition oc = refinedResourceSchema.getRefinedDefinition(construction.getKind(), construction.getIntent());
if (oc == null){
return refinedAssociationDefinitions;
}
refinedAssociationDefinitions = oc.getAssociationDefinitions();

} catch (SchemaException ex) {
LOGGER.error("Couldn't create query filter for ShadowType popup list: {}" , ex.getErrorTypeMessage());
}
return refinedAssociationDefinitions;
}

private void initAssociationTargetSearchExpressionPanel(){
WebMarkupContainer targetSearchContainer = new WebMarkupContainer(ID_ASSOCIATION_TARGET_SEARCH_CONTAINER);
targetSearchContainer.setOutputMarkupId(true);
Expand Down
Expand Up @@ -23,6 +23,7 @@
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.util.EnableBehaviour;
import com.evolveum.midpoint.web.page.admin.dto.ObjectViewDto;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
Expand Down Expand Up @@ -95,6 +96,7 @@ protected void initLayout() {
// return "";
// }
// });
name.add(AttributeAppender.append("title", getPanelTitle()));
name.setOutputMarkupId(true);


Expand All @@ -112,6 +114,8 @@ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
attributes.setChannel(new AjaxChannel("blocking", AjaxChannel.Type.ACTIVE));
}
};
choose.add(new EnableBehaviour(() -> isEnabledToEdit()));
choose.add(AttributeAppender.append("title", getPanelTitle()));
choose.setOutputMarkupId(true);

AjaxLink<String> remove = new AjaxLink<String>(ID_LINK_REMOVE) {
Expand Down Expand Up @@ -163,6 +167,14 @@ protected void executeCustomAction(AjaxRequestTarget target, T object) {

}

protected boolean isEnabledToEdit(){
return true;
}

protected IModel<String> getPanelTitle(){
return null;
}

private void changeOptionPerformed(AjaxRequestTarget target){
Class<T> type = getObjectTypeClass();
List<QName> supportedTypes = new ArrayList<>();
Expand Down
Expand Up @@ -4146,6 +4146,7 @@ ExpressionValuePanel.specifyExpression=Specify expression
ExpressionValuePanel.addValueButtonDefaultTitle=Add shadow reference value
ExpressionValuePanel.addValueButtonTargetSearchTitle=Add association target search
ExpressionValuePanel.addLiteralValueButton=Add literal value
ExpressionValuePanel.associationDefenitionsNotDefined=Association definitions are not defined for the current resource with selected kind/intent parameters.
ConstructionType.attribute=Attribute
ConstructionType.association=Association
operation.Recompute.ALL.members=Recompute all members
Expand Down

0 comments on commit 3967a5b

Please sign in to comment.