/**
   * Assign two resources to a user. One of them is looney, the other is not. The result should be
   * that the account on the good resource is created.
   */
  private void testAssignTwoResoures(final String TEST_NAME, String badResourceOid)
      throws Exception {
    TestUtil.displayTestTile(this, TEST_NAME);

    // GIVEN
    Task task =
        taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.POSITIVE);

    ObjectDelta<UserType> userDelta =
        createAccountAssignmentUserDelta(USER_JACK_OID, badResourceOid, null, true);
    userDelta.addModification(createAccountAssignmentModification(RESOURCE_DUMMY_OID, null, true));
    display("input delta", userDelta);
    Collection<ObjectDelta<? extends ObjectType>> deltas =
        MiscSchemaUtil.createCollection(userDelta);

    // WHEN
    modelService.executeChanges(deltas, null, task, result);

    // THEN
    result.computeStatus();
    display("executeChanges result", result);

    // TODO: ugly hack, see MID-1248
    if ("test401AssignTwoResouresBroken".equals(TEST_NAME)) {
      assertEquals(
          "Expected partial error in result",
          OperationResultStatus.PARTIAL_ERROR,
          result.getStatus());
    }

    DummyAccount jackDummyAccount = dummyResource.getAccountByUsername(USER_JACK_USERNAME);
    assertNotNull("No jack dummy account", jackDummyAccount);
  }
  private void ownerChangePerformed(AjaxRequestTarget target, UserType user) {
    AccountOwnerChangeDto dto = ownerChangeModel.getObject();
    OperationResult result = new OperationResult(OPERATION_CHANGE_OWNER);
    try {
      Task task = createSimpleTask(OPERATION_CHANGE_OWNER);
      if (StringUtils.isNotEmpty(dto.getOldOwnerOid())) {
        ObjectDelta delta = new ObjectDelta(UserType.class, ChangeType.MODIFY, getPrismContext());
        delta.setOid(dto.getOldOwnerOid());
        PrismReferenceValue refValue = new PrismReferenceValue(dto.getAccountOid());
        refValue.setTargetType(dto.getAccountType());
        delta.addModification(
            ReferenceDelta.createModificationDelete(
                UserType.class, UserType.F_LINK_REF, getPrismContext(), refValue));
        getModelService()
            .executeChanges(WebMiscUtil.createDeltaCollection(delta), null, task, result);
      }

      if (user != null) {
        ObjectDelta delta = new ObjectDelta(UserType.class, ChangeType.MODIFY, getPrismContext());
        delta.setOid(user.getOid());
        PrismReferenceValue refValue = new PrismReferenceValue(dto.getAccountOid());
        refValue.setTargetType(dto.getAccountType());
        delta.addModification(
            ReferenceDelta.createModificationAdd(
                UserType.class, UserType.F_LINK_REF, getPrismContext(), refValue));

        getModelService()
            .executeChanges(WebMiscUtil.createDeltaCollection(delta), null, task, result);
      }
      result.recomputeStatus();
    } catch (Exception ex) {
      result.recordFatalError("Couldn't submit user.", ex);
      LoggingUtils.logException(LOGGER, "Couldn't submit user", ex);
    }

    showResult(result);
    target.add(getFeedbackPanel());
  }
Beispiel #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;
  }