예제 #1
0
  public static ExpressionVariables getDefaultXPathVariables(
      UserType user, ShadowType shadow, ResourceType resource) {

    ExpressionVariables variables = new ExpressionVariables();
    if (user != null) {
      variables.addVariableDefinition(ExpressionConstants.VAR_USER, user.asPrismObject());
    }

    if (shadow != null) {
      variables.addVariableDefinition(ExpressionConstants.VAR_ACCOUNT, shadow.asPrismObject());
    }

    if (resource != null) {
      variables.addVariableDefinition(ExpressionConstants.VAR_RESOURCE, resource.asPrismObject());
    }

    return variables;
  }
 protected void assertUserJack(
     PrismObject<UserType> user,
     String name,
     String fullName,
     String givenName,
     String familyName,
     String locality) {
   assertUser(user, USER_JACK_OID, name, fullName, givenName, familyName, locality);
   UserType userType = user.asObjectable();
   PrismAsserts.assertEqualsPolyString(
       "Wrong jack honorificPrefix", "Cpt.", userType.getHonorificPrefix());
   PrismAsserts.assertEqualsPolyString(
       "Wrong jack honorificSuffix", "PhD.", userType.getHonorificSuffix());
   assertEquals(
       "Wrong jack emailAddress", "*****@*****.**", userType.getEmailAddress());
   assertEquals("Wrong jack telephoneNumber", "555-1234", userType.getTelephoneNumber());
   assertEquals("Wrong jack employeeNumber", "emp1234", userType.getEmployeeNumber());
   assertEquals("Wrong jack employeeType", "CAPTAIN", userType.getEmployeeType().get(0));
   if (locality == null) {
     assertNull("Locality sneaked to user jack", userType.getLocality());
   } else {
     PrismAsserts.assertEqualsPolyString("Wrong jack locality", locality, userType.getLocality());
   }
 }
예제 #3
0
  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());
  }
  private void repositorySelfTestUser(Task task, OperationResult testResult) {
    OperationResult result = testResult.createSubresult(REPOSITORY_SELF_TEST_USER);

    PrismObject<UserType> user = getObjectDefinition(UserType.class).instantiate();
    UserType userType = user.asObjectable();

    String name = generateRandomName();
    PolyStringType namePolyStringType = toPolyStringType(name);
    userType.setName(namePolyStringType);
    result.addContext("name", name);
    userType.setDescription(SelfTestData.POLICIJA);
    userType.setFullName(toPolyStringType(USER_FULL_NAME));
    userType.setGivenName(toPolyStringType(USER_GIVEN_NAME));
    userType.setFamilyName(toPolyStringType(USER_FAMILY_NAME));
    userType.setTitle(toPolyStringType(INSANE_NATIONAL_STRING));
    userType.getEmployeeType().add(USER_EMPLOYEE_TYPE[0]);
    userType.getEmployeeType().add(USER_EMPLOYEE_TYPE[1]);
    userType.getOrganization().add(toPolyStringType(USER_ORGANIZATION[0]));
    userType.getOrganization().add(toPolyStringType(USER_ORGANIZATION[1]));

    String oid;
    try {
      oid = repositoryService.addObject(user, null, result);
    } catch (ObjectAlreadyExistsException e) {
      result.recordFatalError(e);
      return;
    } catch (SchemaException e) {
      result.recordFatalError(e);
      return;
    } catch (RuntimeException e) {
      result.recordFatalError(e);
      return;
    }

    try {

      {
        OperationResult subresult = result.createSubresult(result.getOperation() + ".getObject");

        PrismObject<UserType> userRetrieved;
        try {
          userRetrieved = repositoryService.getObject(UserType.class, oid, null, subresult);
        } catch (ObjectNotFoundException e) {
          result.recordFatalError(e);
          return;
        } catch (SchemaException e) {
          result.recordFatalError(e);
          return;
        } catch (RuntimeException e) {
          result.recordFatalError(e);
          return;
        }

        if (LOGGER.isTraceEnabled()) {
          LOGGER.trace("Self-test:user getObject:\n{}", userRetrieved.debugDump());
        }

        checkUser(userRetrieved, name, subresult);

        subresult.recordSuccessIfUnknown();
      }

      {
        OperationResult subresult =
            result.createSubresult(result.getOperation() + ".searchObjects.fullName");
        try {

          ObjectQuery query = new ObjectQuery();
          ObjectFilter filter =
              EqualFilter.createEqual(
                  UserType.F_FULL_NAME,
                  UserType.class,
                  prismContext,
                  null,
                  toPolyString(USER_FULL_NAME));
          query.setFilter(filter);
          subresult.addParam("query", query);
          List<PrismObject<UserType>> foundObjects =
              repositoryService.searchObjects(UserType.class, query, null, subresult);
          if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Self-test:user searchObjects:\n{}", DebugUtil.debugDump(foundObjects));
          }
          assertSingleSearchResult("user", foundObjects, subresult);

          PrismObject<UserType> userRetrieved = foundObjects.iterator().next();
          checkUser(userRetrieved, name, subresult);

          subresult.recordSuccessIfUnknown();
        } catch (SchemaException e) {
          subresult.recordFatalError(e);
          return;
        } catch (RuntimeException e) {
          subresult.recordFatalError(e);
          return;
        }
      }

      // MID-1116
      {
        OperationResult subresult =
            result.createSubresult(result.getOperation() + ".searchObjects.employeeType");
        try {

          ObjectQuery query = new ObjectQuery();
          ObjectFilter filter =
              EqualFilter.createEqual(
                  UserType.F_EMPLOYEE_TYPE,
                  UserType.class,
                  prismContext,
                  null,
                  USER_EMPLOYEE_TYPE[0]);
          query.setFilter(filter);
          subresult.addParam("query", query);
          List<PrismObject<UserType>> foundObjects =
              repositoryService.searchObjects(UserType.class, query, null, subresult);
          if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Self-test:user searchObjects:\n{}", DebugUtil.debugDump(foundObjects));
          }
          assertSingleSearchResult("user", foundObjects, subresult);

          PrismObject<UserType> userRetrieved = foundObjects.iterator().next();
          checkUser(userRetrieved, name, subresult);

          subresult.recordSuccessIfUnknown();
        } catch (SchemaException e) {
          subresult.recordFatalError(e);
          return;
        } catch (RuntimeException e) {
          subresult.recordFatalError(e);
          return;
        }
      }

      // MID-1116
      {
        OperationResult subresult =
            result.createSubresult(result.getOperation() + ".searchObjects.organization");
        try {

          ObjectQuery query = new ObjectQuery();
          ObjectFilter filter =
              EqualFilter.createEqual(
                  UserType.F_ORGANIZATION,
                  UserType.class,
                  prismContext,
                  null,
                  toPolyString(USER_ORGANIZATION[1]));
          query.setFilter(filter);
          subresult.addParam("query", query);
          List<PrismObject<UserType>> foundObjects =
              repositoryService.searchObjects(UserType.class, query, null, subresult);
          if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Self-test:user searchObjects:\n{}", DebugUtil.debugDump(foundObjects));
          }
          assertSingleSearchResult("user", foundObjects, subresult);

          PrismObject<UserType> userRetrieved = foundObjects.iterator().next();
          checkUser(userRetrieved, name, subresult);

          subresult.recordSuccessIfUnknown();
        } catch (SchemaException e) {
          subresult.recordFatalError(e);
          return;
        } catch (RuntimeException e) {
          subresult.recordFatalError(e);
          return;
        }
      }

    } finally {

      try {
        repositoryService.deleteObject(UserType.class, oid, testResult);
      } catch (ObjectNotFoundException e) {
        result.recordFatalError(e);
        return;
      } catch (RuntimeException e) {
        result.recordFatalError(e);
        return;
      }

      result.computeStatus();
    }
  }