예제 #1
0
 @Override
 public <T extends ObjectType> String addObject(
     PrismObject<T> object, RepoAddOptions options, OperationResult parentResult)
     throws ObjectAlreadyExistsException, SchemaException {
   String oid = repository.addObject(object, options, parentResult);
   Cache cache = getCache();
   // DON't cache the object here. The object may not have proper "JAXB" form, e.g. some pieces may
   // be
   // DOM element instead of JAXB elements. Not to cache it is safer and the performance loss
   // is acceptable.
   if (cache != null) {
     // Invalidate the cache entry if it happens to be there
     cache.removeObject(oid);
     cache.clearQueryResults(object.getCompileTimeClass());
   }
   return oid;
 }
  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();
    }
  }