Esempio n. 1
0
  @SuppressWarnings("rawtypes")
  public static <T> T getValueFromFilter(
      List<? extends ObjectFilter> conditions, QName propertyName) throws SchemaException {
    ItemPath propertyPath = new ItemPath(propertyName);
    for (ObjectFilter f : conditions) {
      if (f instanceof EqualFilter && propertyPath.equivalent(((EqualFilter) f).getFullPath())) {
        List<? extends PrismValue> values = ((EqualFilter) f).getValues();
        if (values.size() > 1) {
          throw new SchemaException(
              "More than one " + propertyName + " defined in the search query.");
        }
        if (values.size() < 1) {
          throw new SchemaException("Search query does not have specified " + propertyName + ".");
        }

        return (T) ((PrismPropertyValue) values.get(0)).getValue();
      }
      if (NaryLogicalFilter.class.isAssignableFrom(f.getClass())) {
        T value = getValueFromFilter(((NaryLogicalFilter) f).getConditions(), propertyName);
        if (value != null) {
          return value;
        }
      }
    }

    return null;
  }
Esempio n. 2
0
 @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;
 }
 @Override
 public String debugDump(int indent) {
   StringBuilder sb = new StringBuilder();
   DebugUtil.indentDebugDump(sb, indent);
   sb.append("ContainerWrapper: ").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, "main", main, indent + 1);
   sb.append("\n");
   DebugUtil.debugDumpWithLabel(sb, "readonly", readonly, indent + 1);
   sb.append("\n");
   DebugUtil.debugDumpWithLabel(
       sb, "showInheritedObjectAttributes", showInheritedObjectAttributes, indent + 1);
   sb.append("\n");
   DebugUtil.debugDumpWithLabel(sb, "path", path == null ? null : path.toString(), indent + 1);
   sb.append("\n");
   DebugUtil.debugDumpWithLabel(
       sb,
       "containerDefinition",
       containerDefinition == null ? null : containerDefinition.toString(),
       indent + 1);
   sb.append("\n");
   DebugUtil.debugDumpWithLabel(
       sb, "container", container == null ? null : container.toString(), indent + 1);
   sb.append("\n");
   DebugUtil.debugDumpLabel(sb, "properties", indent + 1);
   sb.append("\n");
   DebugUtil.debugDump(sb, properties, indent + 2, false);
   sb.append("\n");
   DebugUtil.debugDumpWithLabel(sb, "result", result, indent + 1);
   return sb.toString();
 }
Esempio n. 4
0
  private ItemPath createPropertyPath(ItemPath path, QName element) {
    List<ItemPathSegment> segments = new ArrayList<ItemPathSegment>();
    segments.addAll(path.getSegments());
    segments.add(new NameItemPathSegment(element));

    return new ItemPath(segments);
  }
Esempio n. 5
0
 private ReferenceDelta computeReferenceDeltas(
     ReferenceWrapper referenceWrapper, ItemPath containerPath) {
   PrismReferenceDefinition propertyDef = referenceWrapper.getItem().getDefinition();
   ReferenceDelta pDelta =
       new ReferenceDelta(
           containerPath, propertyDef.getName(), propertyDef, propertyDef.getPrismContext());
   addItemDelta(
       referenceWrapper, pDelta, propertyDef, containerPath.subPath(propertyDef.getName()));
   return pDelta;
 }
Esempio n. 6
0
  public PropertyWrapper(
      ContainerWrapper container, I property, boolean readonly, ValueStatus status) {
    Validate.notNull(property, "Property must not be null.");
    Validate.notNull(status, "Property status must not be null.");

    this.container = container;
    this.property = property;
    this.status = status;
    this.readonly = readonly;
    this.itemDefinition = getItemDefinition();

    ItemPath passwordPath =
        new ItemPath(SchemaConstantsGenerated.C_CREDENTIALS, CredentialsType.F_PASSWORD);
    if (passwordPath.equivalent(container.getPath())
        && PasswordType.F_VALUE.equals(property.getElementName())) {
      displayName = "prismPropertyPanel.name.credentials.password";
    }

    values = createValues();
  }
Esempio n. 7
0
  @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);
  }
Esempio n. 8
0
 @Override
 public void checkConsistence() {
   if (fullPath == null || fullPath.isEmpty()) {
     throw new IllegalArgumentException("Null or empty path in " + this);
   }
   if (definition == null) {
     throw new IllegalArgumentException("Null definition in " + this);
   }
   // null subfilter is legal. It means "ALL".
   if (filter != null) {
     filter.checkConsistence();
   }
 }
Esempio n. 9
0
  public ContainerWrapper findContainerWrapper(ItemPath path) {
    for (ContainerWrapper wrapper : getContainers()) {
      if (path != null) {
        if (path.equivalent(wrapper.getPath())) {
          return wrapper;
        }
      } else {
        if (wrapper.getPath() == null) {
          return wrapper;
        }
      }
    }

    return null;
  }
Esempio n. 10
0
  private DateValidator getActivationRangeValidator(Form form, ItemPath path) {
    DateValidator validator = null;
    List<DateValidator> validators = form.getBehaviors(DateValidator.class);
    if (validators != null) {
      for (DateValidator val : validators) {
        if (path.equivalent(val.getIdentifier())) {
          validator = val;
          break;
        }
      }
    }

    if (validator == null) {
      validator = new DateValidator();
      validator.setIdentifier(path);
      form.add(validator);
    }

    return validator;
  }
 public <ID extends ItemDefinition> ID findItemDefinition(ItemPath path, Class<ID> clazz) {
   while (!path.isEmpty() && !(path.first() instanceof NameItemPathSegment)) {
     path = path.rest();
   }
   if (path.isEmpty()) {
     throw new IllegalArgumentException(
         "Cannot resolve empty path on complex type definition " + this);
   }
   QName firstName = ((NameItemPathSegment) path.first()).getName();
   for (ItemDefinition def : getDefinitions()) {
     if (firstName != null && firstName.equals(def.getName())) {
       return (ID) def.findItemDefinition(path.rest(), clazz);
     }
   }
   return null;
 }
Esempio n. 12
0
  private ObjectDelta createAddingObjectDelta() throws SchemaException {
    PrismObject object = this.object.clone();

    List<ContainerWrapper> containers = getContainers();
    // sort containers by path size
    Collections.sort(containers, new PathSizeComparator());

    for (ContainerWrapper containerWrapper : getContainers()) {

      if (containerWrapper.getItemDefinition().getName().equals(ShadowType.F_ASSOCIATION)) {
        PrismContainer associationContainer =
            object.findOrCreateContainer(ShadowType.F_ASSOCIATION);
        List<AssociationWrapper> associationItemWrappers =
            (List<AssociationWrapper>) containerWrapper.getItems();
        for (AssociationWrapper associationItemWrapper : associationItemWrappers) {
          List<ValueWrapper> assocValueWrappers = associationItemWrapper.getValues();
          for (ValueWrapper assocValueWrapper : assocValueWrappers) {
            PrismContainerValue<ShadowAssociationType> assocValue =
                (PrismContainerValue<ShadowAssociationType>) assocValueWrapper.getValue();
            associationContainer.add(assocValue.clone());
          }
        }
        continue;
      }

      if (!containerWrapper.hasChanged()) {
        continue;
      }

      PrismContainer container = containerWrapper.getItem();
      ItemPath path = containerWrapper.getPath();
      if (containerWrapper.getPath() != null) {
        container = container.clone();
        if (path.size() > 1) {
          ItemPath parentPath = path.allExceptLast();
          PrismContainer parent = object.findOrCreateContainer(parentPath);
          parent.add(container);
        } else {
          PrismContainer existing = object.findContainer(container.getElementName());
          if (existing == null) {
            object.add(container);
          } else {
            continue;
          }
        }
      } else {
        container = object;
      }

      for (ItemWrapper propertyWrapper : (List<ItemWrapper>) containerWrapper.getItems()) {
        if (!propertyWrapper.hasChanged()) {
          continue;
        }

        Item property = propertyWrapper.getItem().clone();
        if (container.findProperty(property.getElementName()) != null) {
          continue;
        }
        for (ValueWrapper valueWrapper : propertyWrapper.getValues()) {
          valueWrapper.normalize(object.getPrismContext());
          if (!valueWrapper.hasValueChanged()
              || ValueStatus.DELETED.equals(valueWrapper.getStatus())) {
            continue;
          }

          if (property.hasRealValue(valueWrapper.getValue())) {
            continue;
          }

          PrismValue cloned = clone(valueWrapper.getValue());
          if (cloned != null) {
            property.add(cloned);
          }
        }

        if (!property.isEmpty()) {
          container.add(property);
        }
      }
    }

    // cleanup empty containers
    cleanupEmptyContainers(object);

    ObjectDelta delta = ObjectDelta.createAddDelta(object);

    // returning container to previous order
    Collections.sort(containers, new ItemWrapperComparator());

    if (InternalsConfig.consistencyChecks) {
      delta.checkConsistence(true, true, true, ConsistencyCheckScope.THOROUGH);
    }

    return delta;
  }
Esempio n. 13
0
 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;
 }
Esempio n. 14
0
  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;
  }