Skip to content

Commit

Permalink
induced entitlement fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Jan 30, 2019
1 parent d1551b1 commit e1770fd
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 46 deletions.
Expand Up @@ -3046,7 +3046,7 @@ public static ExpressionType getAssociationExpression(ContainerValueWrapper<Assi
if (assignmentValueWrapper == null){
return null;
}
if (createIfNotExist && prismContext != null) {
if (createIfNotExist && prismContext == null) {
throw new IllegalArgumentException("createIfNotExist is set but prismContext is null");
}
ContainerWrapper<ConstructionType> construction = assignmentValueWrapper
Expand Down
Expand Up @@ -161,10 +161,12 @@ protected void removeValuePerformed(AjaxRequestTarget target, ListItem<ObjectRef
PrismContainerValue associationValue = ((ContainerValueWrapper) associationValueWrapper).getContainerValue();
ResourceObjectAssociationType assoc = (ResourceObjectAssociationType) associationValue.asContainerable();
if (assoc == null || assoc.getOutbound() == null || assoc.getOutbound().getExpression() == null ||
ExpressionUtil.getShadowRefValue(assoc.getOutbound().getExpression()) == null) {
ExpressionUtil.getShadowRefValue(assoc.getOutbound().getExpression(),
ConstructionAssociationPanel.this.getPageBase().getPrismContext()) == null) {
return;
}
List<ObjectReferenceType> shadowRefList = ExpressionUtil.getShadowRefValue(assoc.getOutbound().getExpression());
List<ObjectReferenceType> shadowRefList = ExpressionUtil.getShadowRefValue(assoc.getOutbound().getExpression(),
ConstructionAssociationPanel.this.getPageBase().getPrismContext());
shadowRefList.forEach(shadowRef -> {
if (shadowRef.equals(removedShadowRef)) {
((ContainerValueWrapper) associationValueWrapper).setStatus(ValueStatus.DELETED);
Expand Down Expand Up @@ -201,14 +203,16 @@ public List<ObjectReferenceType> load() {
PrismContainerValue associationValue = ((ContainerValueWrapper) associationValueWrapper).getContainerValue();
ResourceObjectAssociationType assoc = (ResourceObjectAssociationType) associationValue.asContainerable();
if (assoc == null || assoc.getOutbound() == null || assoc.getOutbound().getExpression() == null
|| (ExpressionUtil.getShadowRefValue(assoc.getOutbound().getExpression()) == null
|| (ExpressionUtil.getShadowRefValue(assoc.getOutbound().getExpression(),
ConstructionAssociationPanel.this.getPageBase().getPrismContext()) == null
&& !ValueStatus.ADDED.equals(((ContainerValueWrapper) associationValueWrapper).getStatus()))) {
return;
}
QName assocRef = ItemPathTypeUtil.asSingleNameOrFailNullSafe(assoc.getRef());
if ((defName != null && defName.equals(assocRef))
|| (assocRef == null && ValueStatus.ADDED.equals(((ContainerValueWrapper) associationValueWrapper).getStatus()))) {
shadowsList.addAll(ExpressionUtil.getShadowRefValue(assoc.getOutbound().getExpression()));
shadowsList.addAll(ExpressionUtil.getShadowRefValue(assoc.getOutbound().getExpression(),
ConstructionAssociationPanel.this.getPageBase().getPrismContext()));
}
});
return shadowsList;
Expand All @@ -226,16 +230,16 @@ private List<ObjectReferenceType> getAssociationsShadowRefs(boolean compareName,
PrismContainerValue associationValue = ((ContainerValueWrapper) associationValueWrapper).getContainerValue();
ResourceObjectAssociationType assoc = (ResourceObjectAssociationType) associationValue.asContainerable();
if (assoc == null || assoc.getOutbound() == null || assoc.getOutbound().getExpression() == null
|| ExpressionUtil.getShadowRefValue(assoc.getOutbound().getExpression()) == null) {
|| ExpressionUtil.getShadowRefValue(assoc.getOutbound().getExpression(), getPageBase().getPrismContext()) == null) {
return;
}
if (compareName) {
QName assocRef = ItemPathTypeUtil.asSingleNameOrFailNullSafe(assoc.getRef());
if (name != null && name.equals(assocRef)) {
shadowsList.addAll(ExpressionUtil.getShadowRefValue(assoc.getOutbound().getExpression()));
shadowsList.addAll(ExpressionUtil.getShadowRefValue(assoc.getOutbound().getExpression(), getPageBase().getPrismContext()));
}
} else {
shadowsList.addAll(ExpressionUtil.getShadowRefValue(assoc.getOutbound().getExpression()));
shadowsList.addAll(ExpressionUtil.getShadowRefValue(assoc.getOutbound().getExpression(), getPageBase().getPrismContext()));
}
});
return shadowsList;
Expand Down
Expand Up @@ -132,7 +132,8 @@ public void populateItem(Item<ICellPopulator<ContainerValueWrapper<AssignmentTyp
public void populateItem(Item<ICellPopulator<ContainerValueWrapper<AssignmentType>>> item, String componentId,
final IModel<ContainerValueWrapper<AssignmentType>> rowModel) {
List<ShadowType> shadowsList =
WebComponentUtil.loadReferencedObjectList(ExpressionUtil.getShadowRefValue(WebComponentUtil.getAssociationExpression(rowModel.getObject())),
WebComponentUtil.loadReferencedObjectList(ExpressionUtil.getShadowRefValue(WebComponentUtil.getAssociationExpression(rowModel.getObject()),
InducedEntitlementsPanel.this.getPageBase().getPrismContext()),
OPERATION_LOAD_SHADOW_OBJECT, InducedEntitlementsPanel.this.getPageBase());
MultiValueChoosePanel<ShadowType> valuesPanel = new MultiValueChoosePanel<ShadowType>(componentId,
Model.ofList(shadowsList), Arrays.asList(ShadowType.class), false){
Expand All @@ -157,7 +158,8 @@ protected void removePerformedHook(AjaxRequestTarget target, ShadowType shadow)
protected void choosePerformedHook(AjaxRequestTarget target, List<ShadowType> selectedList) {
ShadowType shadow = selectedList != null && selectedList.size() > 0 ? selectedList.get(0) : null;
if (shadow != null && StringUtils.isNotEmpty(shadow.getOid())){
ExpressionType expression = WebComponentUtil.getAssociationExpression(rowModel.getObject(), true, getPrismContext());
ExpressionType expression = WebComponentUtil.getAssociationExpression(rowModel.getObject(), true,
InducedEntitlementsPanel.this.getPageBase().getPrismContext());
ExpressionUtil.addShadowRefEvaluatorValue(expression, shadow.getOid(),
InducedEntitlementsPanel.this.getPageBase().getPrismContext());
}
Expand Down
Expand Up @@ -169,6 +169,9 @@ private static <O extends ObjectType> DisplayType getDisplayTypeForRowObject(IMo

private static <T extends ObjectType> String getIconColumnValue(IModel<SelectableBean<T>> rowModel){
T object = rowModel.getObject().getValue();
if (object == null){
return "";
}
Class<T> type = (Class<T>)rowModel.getObject().getValue().getClass();
if (object == null && !ShadowType.class.equals(type)){
return null;
Expand Down
Expand Up @@ -106,7 +106,7 @@ protected String getSpecialButtonClass(){

@Override
public boolean isVisible(){
boolean isShadowRefValueNull = ExpressionUtil.getShadowRefValue(getModelObject()) == null;
boolean isShadowRefValueNull = ExpressionUtil.getShadowRefValue(getModelObject(), pageBase.getPrismContext()) == null;

MapXNode associationTargetSearchNode = ExpressionUtil.getAssociationTargetSearchFilterValuesMap(getModelObject());
boolean isAssociationTargetSearchNull = associationTargetSearchNode == null || associationTargetSearchNode.isEmpty();
Expand Down Expand Up @@ -199,15 +199,16 @@ private void initValueExpressionPanel(){

@Override
public boolean isVisible(){
return ExpressionUtil.getShadowRefValue(getModelObject()) != null;
return ExpressionUtil.getShadowRefValue(getModelObject(), pageBase.getPrismContext()) != null;
}
});
add(shadowRefValueContainer);

shadowsListModel = new LoadableModel<List<ShadowType>>() {
@Override
protected List<ShadowType> load() {
return WebComponentUtil.loadReferencedObjectList(ExpressionUtil.getShadowRefValue(ExpressionValuePanel.this.getModelObject()),
return WebComponentUtil.loadReferencedObjectList(ExpressionUtil.getShadowRefValue(ExpressionValuePanel.this.getModelObject(),
pageBase.getPrismContext()),
OPERATION_LOAD_SHADOW, pageBase);
}
};
Expand Down
Expand Up @@ -106,7 +106,7 @@ public class ContainerValueWrapper<C extends Containerable> extends PrismWrapper
}

public PrismContainerDefinition<C> getDefinition() {
return containerValue.getParent().getDefinition();
return containerValue.getParent() != null ? containerValue.getParent().getDefinition() : null;
}

public void revive(PrismContext prismContext) throws SchemaException {
Expand Down
Expand Up @@ -156,28 +156,6 @@ public <C extends Containerable> ShadowAssociationWrapper createAssociationWrapp
itemPath = associationValue.getPath();
shadowAss.add(associationValue.findReference(ShadowAssociationType.F_SHADOW_REF).getValue().clone());
}
} else if (association.getDefinition().getCompileTimeClass().equals(ResourceObjectAssociationType.class)){
//for now Induced entitlements gui should support only targetRef expression value
//that is why no need to look for another expression types within association
ResourceObjectAssociationType resourceAssociation = (ResourceObjectAssociationType) associationValue.asContainerable();
if (resourceAssociation.getRef() == null) {
continue;
}
if (resourceAssociation.getRef().getItemPath().asSingleName().equals(refinedAssocationDefinition.getName())){
itemPath = associationValue.getPath();
MappingType outbound = ((ResourceObjectAssociationType)association.getRealValue()).getOutbound();
if (outbound == null){
continue;
}
ExpressionType expression = outbound.getExpression();
if (expression == null){
continue;
}
List<ObjectReferenceType> shadowRefList = ExpressionUtil.getShadowRefValue(expression);
if (shadowRefList != null && shadowRefList.size() > 0) {
shadowAss.add(shadowRefList.get(0).asReferenceValue().clone());
}
}
}
}

Expand Down
Expand Up @@ -57,11 +57,11 @@ public boolean hasChanged() {
return true;
case ADDED:
case NOT_CHANGED:
if (ExpressionUtil.areAllExpressionValuesEmpty(oldExpressionValue) && ExpressionUtil.areAllExpressionValuesEmpty(expression)) {
if (ExpressionUtil.areAllExpressionValuesEmpty(oldExpressionValue, prismContext) && ExpressionUtil.areAllExpressionValuesEmpty(expression, prismContext)) {
return false;
} else if (!ExpressionUtil.areAllExpressionValuesEmpty(oldExpressionValue) && ExpressionUtil.areAllExpressionValuesEmpty(expression)) {
} else if (!ExpressionUtil.areAllExpressionValuesEmpty(oldExpressionValue, prismContext) && ExpressionUtil.areAllExpressionValuesEmpty(expression, prismContext)) {
return true;
} else if (ExpressionUtil.areAllExpressionValuesEmpty(oldExpressionValue) && !ExpressionUtil.areAllExpressionValuesEmpty(expression)) {
} else if (ExpressionUtil.areAllExpressionValuesEmpty(oldExpressionValue, prismContext) && !ExpressionUtil.areAllExpressionValuesEmpty(expression, prismContext)) {
return true;
} else if (valueWrapper.hasValueChanged()) {
return true;
Expand Down
Expand Up @@ -251,8 +251,8 @@ public static boolean isEmpty(ExpressionType expression) {
return expression == null || expression.getExpressionEvaluator().isEmpty();
}

public static boolean isShadowRefNotEmpty(ExpressionType expression) {
List<ObjectReferenceType> shadowRefValueList = getShadowRefValue(expression);
public static boolean isShadowRefNotEmpty(ExpressionType expression, PrismContext prismContext) {
List<ObjectReferenceType> shadowRefValueList = getShadowRefValue(expression, prismContext);
return !isEmpty(expression) && shadowRefValueList != null && shadowRefValueList.size() > 0;
}

Expand All @@ -267,8 +267,8 @@ public static boolean isLiteralExpressionValueNotEmpty(ExpressionType expression
return values != null && values.size() > 0;
}

public static boolean areAllExpressionValuesEmpty(ExpressionType expression) throws SchemaException {
return !isShadowRefNotEmpty(expression) && !isLiteralExpressionValueNotEmpty(expression) && !isAssociationTargetSearchNotEmpty(expression);
public static boolean areAllExpressionValuesEmpty(ExpressionType expression, PrismContext prismContext) throws SchemaException {
return !isShadowRefNotEmpty(expression, prismContext) && !isLiteralExpressionValueNotEmpty(expression) && !isAssociationTargetSearchNotEmpty(expression);
}

public static void parseExpressionEvaluators(String xml, ExpressionType expressionObject, PrismContext context) throws SchemaException {
Expand Down Expand Up @@ -446,12 +446,12 @@ public static void updateAssociationTargetSearchValue(ExpressionType expression,
expression.getExpressionEvaluator().add(evaluator);
}

public static List<ObjectReferenceType> getShadowRefValue(ExpressionType expressionType) {
public static List<ObjectReferenceType> getShadowRefValue(ExpressionType expressionType, PrismContext prismContext) {
if (expressionType == null) {
return null;
}
List<ObjectReferenceType> shadowRefList = new ArrayList<>();
ListXNode shadowRefNodes = getShadowRefNodesList(expressionType, false, null);
ListXNode shadowRefNodes = getShadowRefNodesList(expressionType, false, prismContext);

if (shadowRefNodes != null) {
for (XNode shadowRefNode : shadowRefNodes.asList()) {
Expand Down Expand Up @@ -496,7 +496,7 @@ public static ListXNode getShadowRefNodesList(ExpressionType expression, boolean
if (((MapXNode) node).containsKey(SHADOW_REF_KEY)) {
if (((MapXNode) node).get(SHADOW_REF_KEY) instanceof ListXNode) {
shadowRefNodes = (ListXNode) ((MapXNode) node).get(SHADOW_REF_KEY);
} else if (createIfNotExist && ((MapXNode) node).get(SHADOW_REF_KEY) instanceof MapXNode) {
} else if (((MapXNode) node).get(SHADOW_REF_KEY) instanceof MapXNode) {
MapXNode shadowRef = (MapXNode) ((MapXNode) node).get(SHADOW_REF_KEY);
shadowRefNodes = prismContext.xnodeFactory().list(shadowRef);
prismContext.xnodeMutator().putToMapXNode((MapXNode) node, SHADOW_REF_KEY, shadowRefNodes);
Expand Down

0 comments on commit e1770fd

Please sign in to comment.