예제 #1
0
  @Test
  public void testContainerValueDiffDesciptionNoPath() throws Exception {
    System.out.println("\n\n===[ testContainerValueDiffDesciptionNoPath ]===\n");

    // GIVEN
    PrismObjectDefinition<UserType> userDef = getUserTypeDefinition();
    PrismContainerDefinition<AssignmentType> assignmentContDef =
        userDef.findContainerDefinition(UserType.F_ASSIGNMENT);

    PrismContainer<AssignmentType> ass1 = assignmentContDef.instantiate();
    PrismContainerValue<AssignmentType> ass1cval = ass1.createNewValue();
    ass1cval.setPropertyRealValue(
        AssignmentType.F_DESCRIPTION, "blah blah", PrismTestUtil.getPrismContext());

    PrismContainer<AssignmentType> ass2 = assignmentContDef.instantiate();
    PrismContainerValue<AssignmentType> ass2cval = ass2.createNewValue();
    ass2cval.setPropertyRealValue(
        AssignmentType.F_DESCRIPTION,
        "chamalalia patlama paprtala",
        PrismTestUtil.getPrismContext());

    // WHEN
    Collection<? extends ItemDelta> modifications = ass1cval.diff(ass2cval);

    // THEN
    assertNotNull(modifications);
    System.out.println(DebugUtil.debugDump(modifications));
    assertEquals("Unexpected number of midifications", 1, modifications.size());
    PrismAsserts.assertPropertyReplace(
        modifications,
        new ItemPath(UserType.F_ASSIGNMENT, AssignmentType.F_DESCRIPTION),
        "chamalalia patlama paprtala");
    ItemDelta.checkConsistence(modifications);
  }
예제 #2
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;
      }
    }
  }
예제 #3
0
  public ObjectDelta getObjectDelta() throws SchemaException {
    if (ContainerStatus.ADDING.equals(getStatus())) {
      return createAddingObjectDelta();
    }

    ObjectDelta delta =
        new ObjectDelta(object.getCompileTimeClass(), ChangeType.MODIFY, object.getPrismContext());
    delta.setOid(object.getOid());

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

    for (ContainerWrapper containerWrapper : getContainers()) {
      // create ContainerDelta for association container
      // HACK HACK HACK create correct procession for association container data
      // according to its structure
      if (containerWrapper.getItemDefinition().getName().equals(ShadowType.F_ASSOCIATION)) {
        ContainerDelta<ShadowAssociationType> associationDelta =
            ContainerDelta.createDelta(
                ShadowType.F_ASSOCIATION, containerWrapper.getItemDefinition());
        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();
            if (assocValueWrapper.getStatus() == ValueStatus.DELETED) {
              associationDelta.addValueToDelete(assocValue.clone());
            } else if (assocValueWrapper.getStatus().equals(ValueStatus.ADDED)) {
              associationDelta.addValueToAdd(assocValue.clone());
            }
          }
        }
        delta.addModification(associationDelta);
      } else {
        if (!containerWrapper.hasChanged()) {
          continue;
        }

        for (ItemWrapper itemWrapper : (List<ItemWrapper>) containerWrapper.getItems()) {
          if (!itemWrapper.hasChanged()) {
            continue;
          }
          ItemPath containerPath =
              containerWrapper.getPath() != null ? containerWrapper.getPath() : new ItemPath();
          if (itemWrapper instanceof PropertyWrapper) {
            ItemDelta pDelta = computePropertyDeltas((PropertyWrapper) itemWrapper, containerPath);
            if (!pDelta.isEmpty()) {
              delta.addModification(pDelta);
            }
          }

          if (itemWrapper instanceof ReferenceWrapper) {
            ReferenceDelta pDelta =
                computeReferenceDeltas((ReferenceWrapper) itemWrapper, containerPath);
            if (!pDelta.isEmpty()) {
              delta.addModification(pDelta);
            }
          }
        }
      }
    }
    // returning container to previous order
    Collections.sort(containers, new ItemWrapperComparator());

    // Make sure we have all the definitions
    if (object.getPrismContext() != null) {
      object.getPrismContext().adopt(delta);
    }
    return delta;
  }