private boolean isAddButtonVisible() { ValueWrapper valueWrapper = model.getObject(); if (valueWrapper.isReadonly()) { return false; } ItemWrapper propertyWrapper = valueWrapper.getItem(); Item property = propertyWrapper.getItem(); ItemDefinition definition = property.getDefinition(); int max = definition.getMaxOccurs(); List<ValueWrapper> usableValues = getUsableValues(propertyWrapper); if (usableValues.indexOf(valueWrapper) != usableValues.size() - 1) { return false; } if (max == -1) { return true; } if (countNonDeletedValues(propertyWrapper) >= max) { return false; } return isAccessible(definition, propertyWrapper.getContainer().getObject().getStatus()); }
private <T> QName determineRerturnType( Class<T> type, ScriptExpressionEvaluatorType expressionType, ItemDefinition outputDefinition, ScriptExpressionReturnTypeType suggestedReturnType) throws ExpressionEvaluationException { if (expressionType.getReturnType() == ScriptExpressionReturnTypeType.LIST || suggestedReturnType == ScriptExpressionReturnTypeType.LIST) { return XPathConstants.NODESET; } if (expressionType.getReturnType() == ScriptExpressionReturnTypeType.SCALAR) { return toXPathReturnType(outputDefinition.getTypeName()); } if (suggestedReturnType == ScriptExpressionReturnTypeType.LIST) { return XPathConstants.NODESET; } if (suggestedReturnType == ScriptExpressionReturnTypeType.SCALAR) { return toXPathReturnType(outputDefinition.getTypeName()); } if (outputDefinition.isMultiValue()) { return XPathConstants.NODESET; } else { return toXPathReturnType(outputDefinition.getTypeName()); } }
public <IV extends PrismValue, ID extends ItemDefinition> XNode serializeItem( Item<IV, ID> item, SerializationContext ctx) throws SchemaException { ListXNode xlist = new ListXNode(); List<IV> values = item.getValues(); ItemDefinition definition = item.getDefinition(); for (IV val : values) { XNode xsubnode = serializeItemValue(val, definition, ctx); xlist.add(xsubnode); } boolean asList; if (definition != null) { asList = definition.isMultiValue(); } else { asList = values.size() > 1; } if (asList) { return xlist; } else { if (xlist.isEmpty()) { return null; } else { return xlist.iterator().next(); } } }
private boolean isAddButtonVisible() { Component inputPanel = this.get(ID_VALUE_CONTAINER).get(ID_INPUT); ValueWrapper valueWrapper = valueWrapperModel.getObject(); if (valueWrapper.isReadonly()) { return false; } ItemWrapper propertyWrapper = valueWrapper.getItem(); Item property = propertyWrapper.getItem(); ItemDefinition definition = property.getDefinition(); int max = definition.getMaxOccurs(); List<ValueWrapper> usableValues = getUsableValues(propertyWrapper); if (usableValues.indexOf(valueWrapper) != usableValues.size() - 1) { return false; } if (max == -1) { return true; } if (countNonDeletedValues(propertyWrapper) >= max) { return false; } if (propertyWrapper.getContainer() == null) { return true; // TODO } return isAccessible(definition, getContainerStatus(propertyWrapper)); }
private boolean isRemoveButtonVisible() { ValueWrapper valueWrapper = valueWrapperModel.getObject(); if (valueWrapper.isReadonly()) { return false; } Component inputPanel = this.get(ID_VALUE_CONTAINER).get(ID_INPUT); if (inputPanel instanceof ValueChoosePanel || inputPanel instanceof AssociationValueChoicePanel) { return true; } ItemWrapper propertyWrapper = valueWrapper.getItem(); ItemDefinition definition = propertyWrapper.getItem().getDefinition(); int min = definition.getMinOccurs(); int count = countNonDeletedValues(propertyWrapper); if (count <= 1 || count <= min) { return false; } if (propertyWrapper.getContainer() == null) { return true; // TODO } return isAccessible(definition, getContainerStatus(propertyWrapper)); }
// element name may be null (it is then derived from the definition, if the definition exists) private RootXNode serializeItemValueAsRootInternal(PrismValue value, QName elementName) throws SchemaException { ItemDefinition definition = value.getParent().getDefinition(); // the definition may be null here XNode valueNode = serializeItemValue(value, definition); if (elementName == null) { if (definition == null) { throw new IllegalStateException( "The name of element to be serialized couldn't be determined, as there's no definition"); } elementName = definition.getName(); } return new RootXNode(elementName, valueNode); }
// definition may be null private <V extends PrismValue> XNode serializeItemValue( PrismValue itemValue, ItemDefinition definition, SerializationContext ctx) throws SchemaException { XNode xnode; if (definition == null) { if (itemValue.getParent() != null) { definition = itemValue.getParent().getDefinition(); } } if (beanConverter.getPrismContext() == null) { throw new IllegalStateException("No prismContext in beanConverter!"); } if (definition == null && itemValue instanceof PrismPropertyValue) { return serializePropertyRawValue((PrismPropertyValue<?>) itemValue); } if (itemValue instanceof PrismReferenceValue) { xnode = serializeReferenceValue( (PrismReferenceValue) itemValue, (PrismReferenceDefinition) definition, ctx); } else if (itemValue instanceof PrismPropertyValue<?>) { xnode = serializePropertyValue( (PrismPropertyValue<?>) itemValue, (PrismPropertyDefinition) definition); } else if (itemValue instanceof PrismContainerValue<?>) { xnode = serializeContainerValue( (PrismContainerValue<?>) itemValue, (PrismContainerDefinition) definition, ctx); } else { throw new IllegalArgumentException("Unsupported value type " + itemValue.getClass()); } if (definition != null && definition.isDynamic()) { xnode.setExplicitTypeDeclaration(true); } return xnode; }
@Override public int hashCode() { int result = fullPath != null ? fullPath.hashCode() : 0; result = 31 * result + (definition != null ? definition.hashCode() : 0); result = 31 * result + (filter != null ? filter.hashCode() : 0); return result; }
private boolean isAccessible(ItemDefinition def, ContainerStatus status) { switch (status) { case ADDING: if (!def.canAdd()) { return false; } break; case MODIFYING: if (!def.canModify()) { return false; } break; } return true; }
@Override public String debugDump(int indent) { StringBuilder sb = new StringBuilder(); DebugUtil.indentDebugDump(sb, indent); sb.append(getDebugName()); sb.append(": ").append(PrettyPrinter.prettyPrint(getName())).append("\n"); DebugUtil.debugDumpWithLabel(sb, "displayName", displayName, indent + 1); sb.append("\n"); DebugUtil.debugDumpWithLabel( sb, "status", status == null ? null : status.toString(), indent + 1); sb.append("\n"); DebugUtil.debugDumpWithLabel(sb, "readonly", readonly, indent + 1); sb.append("\n"); DebugUtil.debugDumpWithLabel( sb, "itemDefinition", itemDefinition == null ? null : itemDefinition.toString(), indent + 1); sb.append("\n"); DebugUtil.debugDumpWithLabel( sb, "property", property == null ? null : property.toString(), indent + 1); sb.append("\n"); DebugUtil.debugDumpLabel(sb, "values", indent + 1); sb.append("\n"); DebugUtil.debugDump(sb, values, indent + 2, false); return sb.toString(); }
public static <T> String toRepo( ItemDefinition parentDefinition, QName itemName, T value, PrismContext prismContext) throws SchemaException, JAXBException { if (value == null) { return null; } if (value instanceof Objectable) { return prismContext.serializeObjectToString( ((Objectable) value).asPrismObject(), PrismContext.LANG_XML); } ItemDefinition definition = null; if (parentDefinition instanceof PrismContainerDefinition) { definition = ((PrismContainerDefinition) parentDefinition).findItemDefinition(itemName); if (definition == null) { definition = parentDefinition; } } else { definition = parentDefinition; } return ValueSerializationUtil.serializeValue( value, definition, itemName, parentDefinition.getName(), prismContext, PrismContext.LANG_XML); }
public void revive(PrismContext prismContext) throws SchemaException { if (property != null) { property.revive(prismContext); } if (itemDefinition != null) { itemDefinition.revive(prismContext); } }
private <C extends Containerable> void serializeContainerValue( MapXNode xmap, PrismContainerValue<C> containerVal, PrismContainerDefinition<C> containerDefinition, SerializationContext ctx) throws SchemaException { Long id = containerVal.getId(); if (id != null) { xmap.put(XNode.KEY_CONTAINER_ID, createPrimitiveXNodeAttr(id, DOMUtil.XSD_LONG)); } if (containerVal.getConcreteType() != null) { xmap.setTypeQName(containerVal.getConcreteType()); xmap.setExplicitTypeDeclaration(true); } Collection<QName> serializedItems = new ArrayList<>(); if (containerDefinition != null) { // We have to serialize in the definition order. Some data formats (XML) are // ordering-sensitive. We need to keep that ordering otherwise the resulting // document won't pass schema validation for (ItemDefinition itemDef : containerDefinition.getDefinitions()) { QName elementName = itemDef.getName(); Item<?, ?> item = containerVal.findItem(elementName); if (item != null) { XNode xsubnode = serializeItem(item, ctx); xmap.put(elementName, xsubnode); serializedItems.add(elementName); } } } // There are some cases when we do not have list of all elements in a container. // E.g. in run-time schema. Therefore we must also iterate over items and not just item // definitions. if (containerVal.getItems() != null) { for (Item<?, ?> item : containerVal.getItems()) { QName elementName = item.getElementName(); if (serializedItems.contains(elementName)) { continue; } XNode xsubnode = serializeItem(item, ctx); xmap.put(elementName, xsubnode); } } }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof ExistsFilter)) return false; ExistsFilter that = (ExistsFilter) o; if (fullPath != null ? !fullPath.equals(that.fullPath) : that.fullPath != null) return false; if (definition != null ? !definition.equals(that.definition) : that.definition != null) return false; return !(filter != null ? !filter.equals(that.filter) : that.filter != null); }
public ValueWrapper createAddedValue() { ItemDefinition definition = property.getDefinition(); ValueWrapper wrapper; if (SchemaConstants.T_POLY_STRING_TYPE.equals(definition.getTypeName())) { wrapper = new ValueWrapper( this, new PrismPropertyValue(new PolyString("")), new PrismPropertyValue(new PolyString("")), ValueStatus.ADDED); } else if (isUser() && isThisPropertyActivationEnabled()) { wrapper = new ValueWrapper( this, new PrismPropertyValue(null), new PrismPropertyValue(null), ValueStatus.ADDED); } else { wrapper = new ValueWrapper(this, new PrismPropertyValue(null), ValueStatus.ADDED); } return wrapper; }
boolean isItemVisible(ItemWrapper item) { ItemDefinition def = item.getItemDefinition(); if (def.isIgnored() || def.isOperational()) { return false; } if (def instanceof PrismPropertyDefinition && skipProperty((PrismPropertyDefinition) def)) { return false; } // we decide not according to status of this container, but according to // the status of the whole object if (objectWrapper.getStatus() == ContainerStatus.ADDING) { return def.canAdd(); } // otherwise, object.getStatus() is MODIFYING if (def.canModify()) { return showEmpty(item); } else { if (def.canRead()) { return showEmpty(item); } return false; } }
public static <T> String serializeValue( T value, ItemDefinition def, QName itemName, QName parentName, PrismContext prismContext, String language) throws SchemaException { // System.out.println("value serialization"); if (value == null) { return null; } XNodeSerializer serializer = prismContext.getXnodeProcessor().createSerializer(); if (value instanceof List) { List<T> values = (List<T>) value; if (values.isEmpty()) { return null; } if (def instanceof PrismPropertyDefinition) { PrismProperty prop = (PrismProperty) def.instantiate(itemName); for (T val : values) { PrismPropertyValue<T> pValue = new PrismPropertyValue<T>(val); prop.add(pValue); } XNode node = serializer.serializeItem(prop); if (node instanceof ListXNode) { ListXNode xList = (ListXNode) node; if (xList.size() == 1) { XNode sub = xList.iterator().next(); if (!(sub instanceof MapXNode)) { throw new IllegalArgumentException("must be a map"); } String s = prismContext.getParserDom().serializeToString(sub, parentName); // System.out.println("serialized: " + s); return s; } else { MapXNode xmap = new MapXNode(); xmap.put(itemName, xList); String s = prismContext.getParserDom().serializeToString(xmap, parentName); // System.out.println("serialized: " + s); return s; // throw new IllegalArgumentException("Check your data."); } // MapXNode xmap = xList.new MapXNode(); // xmap.put(def.getName(), xList); } String s = prismContext.getParserDom().serializeToString(node, def.getName()); // System.out.println("serialized: " + s); return s; } else if (def instanceof PrismContainerDefinition) { PrismContainer pc = (PrismContainer) def.instantiate(); for (T val : values) { // PrismContainerValue pcVal = new PrismContainerValue<Containerable>((Containerable) // val); PrismContainerValue pcVal = ((Containerable) val).asPrismContainerValue(); pc.add(pcVal.clone()); } XNode node = serializer.serializeItem(pc); if (node instanceof ListXNode) { ListXNode xList = (ListXNode) node; MapXNode xmap = new MapXNode(); xmap.put(def.getName(), xList); String s = prismContext.getParserDom().serializeToString(xmap, parentName); // System.out.println("serialized: " + s); return s; } String s = prismContext.getParserDom().serializeToString(node, def.getName()); // System.out.println("serialized: " + s); return s; } } PrismValue pVal = null; if (value instanceof Containerable) { pVal = ((Containerable) value).asPrismContainerValue(); } else if (value instanceof Referencable) { pVal = ((Referencable) value).asReferenceValue(); } else { pVal = new PrismPropertyValue<T>(value); } // Class clazz = prismContext.getSchemaRegistry().determineCompileTimeClass(itemName); // PrismContainerDefinition def = // prismContext.getSchemaRegistry().determineDefinitionFromClass(clazz); // // ItemDefinition def = // prismContext.getSchemaRegistry().findItemDefinitionByElementName(itemName); // QName itemName = null; if (def != null) { itemName = def.getName(); } XNode node = serializer.serializeItemValue(pVal, def); String s = prismContext.getParserDom().serializeToString(node, itemName); // System.out.println("serialized: " + s); return s; // throw new UnsupportedOperationException("need to be implemented"); }
@Override public <T, V extends PrismValue> List<V> evaluate( ScriptExpressionEvaluatorType expressionType, ExpressionVariables variables, ItemDefinition outputDefinition, ScriptExpressionReturnTypeType suggestedReturnType, ObjectResolver objectResolver, Collection<FunctionLibrary> functions, String contextDescription, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, ExpressionSyntaxException { String codeString = expressionType.getCode(); if (codeString == null) { throw new ExpressionEvaluationException("No script code in " + contextDescription); } Class<T> type = null; if (outputDefinition != null) { QName xsdReturnType = outputDefinition.getTypeName(); type = XsdTypeMapper.toJavaType(xsdReturnType); // may return null if unknown } if (type == null) { type = (Class<T>) Element .class; // actually, if outputDefinition is null, the return value is of no // interest for us } QName returnType = determineRerturnType(type, expressionType, outputDefinition, suggestedReturnType); Object evaluatedExpression = evaluate( returnType, codeString, variables, objectResolver, functions, contextDescription, result); List<V> propertyValues; boolean scalar = !outputDefinition.isMultiValue(); if (expressionType.getReturnType() != null) { scalar = isScalar(expressionType.getReturnType()); } else if (suggestedReturnType != null) { scalar = isScalar(suggestedReturnType); } if (scalar) { if (evaluatedExpression instanceof NodeList) { NodeList evaluatedExpressionNodeList = (NodeList) evaluatedExpression; if (evaluatedExpressionNodeList.getLength() > 1) { throw new ExpressionEvaluationException( "Expected scalar expression result but got a list result with " + evaluatedExpressionNodeList.getLength() + " elements in " + contextDescription); } if (evaluatedExpressionNodeList.getLength() == 0) { evaluatedExpression = null; } else { evaluatedExpression = evaluatedExpressionNodeList.item(0); } } propertyValues = new ArrayList<V>(1); V pval = convertScalar(type, returnType, evaluatedExpression, contextDescription); if (pval instanceof PrismPropertyValue && !isNothing(((PrismPropertyValue<T>) pval).getValue())) { propertyValues.add(pval); } } else { if (!(evaluatedExpression instanceof NodeList)) { throw new IllegalStateException( "The expression " + contextDescription + " resulted in " + evaluatedExpression.getClass().getName() + " while exprecting NodeList in " + contextDescription); } propertyValues = convertList(type, (NodeList) evaluatedExpression, contextDescription); } return (List<V>) PrismValue.cloneCollection(propertyValues); }
private List<ContainerWrapper> createContainerWrapper( PrismContainer parent, ItemPath path, PageBase pageBase) { PrismContainerDefinition definition = parent.getDefinition(); List<ContainerWrapper> wrappers = new ArrayList<ContainerWrapper>(); List<ItemPathSegment> segments = new ArrayList<ItemPathSegment>(); if (path != null) { segments.addAll(path.getSegments()); } ItemPath parentPath = new ItemPath(segments); for (ItemDefinition def : (Collection<ItemDefinition>) definition.getDefinitions()) { if (!(def instanceof PrismContainerDefinition)) { continue; } if (ObjectSpecificationType.COMPLEX_TYPE.equals(def.getTypeName())) { continue; // TEMPORARY FIX } if (TriggerType.COMPLEX_TYPE.equals(def.getTypeName())) { continue; // TEMPORARY FIX TODO: remove after getEditSchema // (authorization) will be fixed. } if (ApprovalSchemaType.COMPLEX_TYPE.equals(def.getTypeName())) { continue; } LOGGER.trace("ObjectWrapper.createContainerWrapper processing definition: {}", def); PrismContainerDefinition containerDef = (PrismContainerDefinition) def; if (!showAssignments && AssignmentType.COMPLEX_TYPE.equals(containerDef.getTypeName())) { continue; } if (!showInheritedObjectAttributes) { boolean result = INHERITED_OBJECT_SUBCONTAINERS.contains(containerDef.getName()); LOGGER.info("checking " + containerDef.getName() + ", result = " + result); if (result) { continue; } } ItemPath newPath = createPropertyPath(parentPath, containerDef.getName()); // [med] // The following code fails to work when parent is multivalued or // potentially multivalued. // Therefore (as a brutal hack), for multivalued parents we simply // skip it. if (parent.size() <= 1) { // the same check as in getValue() implementation boolean isMultiValued = parent.getDefinition() != null && !parent.getDefinition().isDynamic() && !parent.getDefinition().isSingleValue(); if (!isMultiValued) { PrismContainer prismContainer = parent.findContainer(def.getName()); ContainerWrapper container; if (prismContainer != null) { container = new ContainerWrapper( this, prismContainer, ContainerStatus.MODIFYING, newPath, pageBase); } else { prismContainer = containerDef.instantiate(); container = new ContainerWrapper( this, prismContainer, ContainerStatus.ADDING, newPath, pageBase); } addSubresult(container.getResult()); wrappers.add(container); if (!AssignmentType.COMPLEX_TYPE.equals(containerDef.getTypeName()) || !ShadowType.F_ASSOCIATION.equals(parent.getElementName())) { // do // not // show // internals // of // Assignments // (e.g. // activation) wrappers.addAll(createContainerWrapper(prismContainer, newPath, pageBase)); } } } } return wrappers; }
private ItemDelta computePropertyDeltas(PropertyWrapper propertyWrapper, ItemPath containerPath) { ItemDefinition itemDef = propertyWrapper.getItem().getDefinition(); ItemDelta pDelta = itemDef.createEmptyDelta(containerPath.subPath(itemDef.getName())); addItemDelta(propertyWrapper, pDelta, itemDef, containerPath); return pDelta; }
private void addItemDelta( ItemWrapper itemWrapper, ItemDelta pDelta, ItemDefinition propertyDef, ItemPath containerPath) { for (ValueWrapper valueWrapper : itemWrapper.getValues()) { valueWrapper.normalize(propertyDef.getPrismContext()); ValueStatus valueStatus = valueWrapper.getStatus(); if (!valueWrapper.hasValueChanged() && (ValueStatus.NOT_CHANGED.equals(valueStatus) || ValueStatus.ADDED.equals(valueStatus))) { continue; } // TODO: need to check if the resource has defined // capabilities // todo this is bad hack because now we have not tri-state // checkbox if (SchemaConstants.PATH_ACTIVATION.equivalent(containerPath)) { if (object.asObjectable() instanceof ShadowType && (((ShadowType) object.asObjectable()).getActivation() == null || ((ShadowType) object.asObjectable()).getActivation().getAdministrativeStatus() == null)) { if (!hasResourceCapability( ((ShadowType) object.asObjectable()).getResource(), ActivationCapabilityType.class)) { continue; } } } PrismValue newValCloned = clone(valueWrapper.getValue()); PrismValue oldValCloned = clone(valueWrapper.getOldValue()); switch (valueWrapper.getStatus()) { case ADDED: if (newValCloned != null) { if (SchemaConstants.PATH_PASSWORD.equivalent(containerPath)) { // password change will always look like // add, // therefore we push replace pDelta.setValuesToReplace(Arrays.asList(newValCloned)); } else if (propertyDef.isSingleValue()) { // values for single-valued properties // should be pushed via replace // in order to prevent problems e.g. with // summarizing deltas for // unreachable resources pDelta.setValueToReplace(newValCloned); } else { pDelta.addValueToAdd(newValCloned); } } break; case DELETED: if (newValCloned != null) { pDelta.addValueToDelete(newValCloned); } if (oldValCloned != null) { pDelta.addValueToDelete(oldValCloned); } break; case NOT_CHANGED: // this is modify... if (propertyDef.isSingleValue()) { // newValCloned.isEmpty() if (newValCloned != null && !newValCloned.isEmpty()) { pDelta.setValuesToReplace(Arrays.asList(newValCloned)); } else { if (oldValCloned != null) { pDelta.addValueToDelete(oldValCloned); } } } else { if (newValCloned != null && !newValCloned.isEmpty()) { pDelta.addValueToAdd(newValCloned); } if (oldValCloned != null) { pDelta.addValueToDelete(oldValCloned); } } break; } } }