コード例 #1
0
  private void savePerformed(AjaxRequestTarget target) {
    ObjectViewDto dto = model.getObject();
    if (StringUtils.isEmpty(dto.getXml())) {
      error(getString("pageResourceEdit.message.emptyXml"));
      target.add(getFeedbackPanel());
      return;
    }

    Task task = createSimpleTask(OPERATION_SAVE_RESOURCE);
    OperationResult result = task.getResult();
    try {
      Holder<PrismObject<ResourceType>> objectHolder = new Holder<PrismObject<ResourceType>>(null);
      validateObject(dto.getXml(), objectHolder, false, result);

      if (result.isAcceptable()) {
        PrismObject<ResourceType> newResource = objectHolder.getValue();
        updateConnectorRef(newResource, task, result);

        if (!isEditing()) {
          // we're adding new resource
          ObjectDelta delta = ObjectDelta.createAddDelta(newResource);
          getModelService()
              .executeChanges(WebMiscUtil.createDeltaCollection(delta), null, task, result);
        } else {
          // we're editing existing resource
          PrismObject<ResourceType> oldResource = dto.getObject();
          ObjectDelta<ResourceType> delta = oldResource.diff(newResource);

          getModelService()
              .executeChanges(
                  WebMiscUtil.createDeltaCollection(delta),
                  ModelExecuteOptions.createRaw(),
                  task,
                  result);
        }

        result.computeStatus();
      }
    } catch (Exception ex) {
      LoggingUtils.logException(LOGGER, "Couldn't save resource", ex);
      result.recordFatalError("Couldn't save resource.", ex);
    }

    if (WebMiscUtil.isSuccessOrHandledError(result)) {
      showResultInSession(result);
      setResponsePage(PageResources.class);
    } else {
      showResult(result);
      target.add(getFeedbackPanel());
    }
  }
コード例 #2
0
  @Test
  public void testParseTaskRoundtrip() throws Exception {
    System.out.println("===[ testParseTaskRoundtrip ]===");

    // GIVEN
    PrismContext prismContext = PrismTestUtil.getPrismContext();

    PrismObject<TaskType> task = prismContext.parseObject(TASK_FILE);

    System.out.println("Parsed task:");
    System.out.println(task.debugDump());

    assertTask(task);

    // SERIALIZE

    String serializedTask = prismContext.serializeObjectToString(task, PrismContext.LANG_XML);

    System.out.println("serialized task:");
    System.out.println(serializedTask);

    // RE-PARSE

    PrismObject<TaskType> reparsedTask = prismContext.parseObject(serializedTask);

    System.out.println("Re-parsed task:");
    System.out.println(reparsedTask.debugDump());

    // Cannot assert here. It will cause parsing of some of the raw values and diff will fail
    assertTask(reparsedTask);

    ObjectDelta<TaskType> objectDelta = task.diff(reparsedTask);
    System.out.println("Delta:");
    System.out.println(objectDelta.debugDump());
    assertTrue("Delta is not empty", objectDelta.isEmpty());

    PrismAsserts.assertEquivalent("Task re-parsed equivalence", task, reparsedTask);
  }