Пример #1
0
  private PrismValue clone(PrismValue value) {
    if (value == null) {
      return null;
    }
    PrismValue cloned = value.clone();
    cloned.setOriginType(OriginType.USER_ACTION);
    if (value instanceof PrismPropertyValue) {
      PrismPropertyValue ppValue = (PrismPropertyValue) value;
      if (ppValue.getValue() instanceof ProtectedStringType) {
        ((PrismPropertyValue) cloned).setValue(((ProtectedStringType) ppValue.getValue()).clone());
      }
      if (ppValue.getValue() instanceof PolyString) {
        PolyString poly = (PolyString) ppValue.getValue();
        if (StringUtils.isEmpty(poly.getOrig())) {
          return null;
        }
        ((PrismPropertyValue) cloned).setValue(new PolyString(poly.getOrig(), poly.getNorm()));
      }
    } else if (value instanceof PrismReferenceValue) {
      if (cloned == null) {
        return null;
      }
      if (cloned.isEmpty()) {
        return null;
      }
    }

    return cloned;
  }
Пример #2
0
 // 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;
 }
Пример #3
0
 private void assertAttributesFetched(List<PrismValue> data) {
   for (PrismValue value : data) {
     if (((PrismObjectValue<ShadowType>) value).asObjectable().getAttributes().getAny().size()
         <= 2) {
       throw new AssertionError("There are no attributes present in " + value.debugDump());
     }
   }
 }
Пример #4
0
 public RootXNode serializeItemValueAsRoot(PrismValue value, QName elementName)
     throws SchemaException {
   Validate.notNull(value, "Item value to be serialized cannot be null");
   Validate.notNull(value.getParent(), "Item value to be serialized must have a parent");
   Validate.notNull(elementName, "Element name cannot be null");
   return serializeItemValueAsRootInternal(value, elementName);
 }
  @Override
  public T getValue() {

    if (actualValue != null) {
      return actualValue;
    }

    if (valueForStorageWhenNotEncoded != null) {
      actualValue = valueForStorageWhenNotEncoded;
      return actualValue;
    }

    if (valueForStorageWhenEncoded != null) {
      if (prismContext == null) {
        throw new IllegalStateException(
            "PrismContext not set for SerializationSafeContainer holding "
                + StringUtils.abbreviate(valueForStorageWhenEncoded, MAX_WIDTH));
      }

      if (encodingScheme == EncodingScheme.PRISM) {
        try {
          PrismValue prismValue =
              prismContext.parserFor(valueForStorageWhenEncoded).xml().parseItemValue();
          actualValue = prismValue != null ? prismValue.getRealValue() : null;
        } catch (SchemaException e) {
          throw new SystemException(
              "Couldn't deserialize value from JAXB: "
                  + StringUtils.abbreviate(valueForStorageWhenEncoded, MAX_WIDTH),
              e);
        }
        return actualValue;
      } else {
        throw new IllegalStateException("Unexpected encoding scheme " + encodingScheme);
      }
    }

    return null;
  }
Пример #6
0
 // 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);
 }
Пример #7
0
  @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);
  }
Пример #8
0
  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;
      }
    }
  }