Ejemplo n.º 1
0
  @Test
  public void test320GetResourceNoJars() throws Exception {
    TestUtil.displayTestTile(this, "test320GetResourceNoJars");

    // GIVEN
    Task task =
        taskManager.createTaskInstance(
            TestModelServiceContract.class.getName() + ".test320GetResourceNoJars");
    OperationResult result = task.getResult();

    // WHEN
    PrismObject<ResourceType> resource =
        modelService.getObject(ResourceType.class, RESOURCE_DUMMY_NOJARS_OID, null, task, result);

    // THEN
    display("getObject resource", resource);
    result.computeStatus();
    display("getObject result", result);
    assertEquals(
        "Expected partial errror in result",
        OperationResultStatus.PARTIAL_ERROR,
        result.getStatus());

    OperationResultType fetchResult = resource.asObjectable().getFetchResult();
    display("resource.fetchResult", fetchResult);
    assertEquals(
        "Expected partial errror in fetchResult",
        OperationResultStatusType.PARTIAL_ERROR,
        fetchResult.getStatus());

    // TODO: better asserts
    assertNotNull("Null resource", resource);
  }
Ejemplo n.º 2
0
  @Test
  public void test221GetResourceNotFoundResolveConnector() throws Exception {
    final String TEST_NAME = "test221GetResourceNotFoundResolveConnector";
    TestUtil.displayTestTile(this, TEST_NAME);

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

    Collection<SelectorOptions<GetOperationOptions>> options =
        SelectorOptions.createCollection(
            ResourceType.F_CONNECTOR_REF, GetOperationOptions.createResolve());

    // WHEN
    PrismObject<ResourceType> resource =
        modelService.getObject(
            ResourceType.class, RESOURCE_CSVFILE_NOTFOUND_OID, options, task, result);

    // THEN
    display("getObject resource", resource);
    result.computeStatus();
    display("getObject result", result);
    assertEquals(
        "Expected partial errror in result",
        OperationResultStatus.PARTIAL_ERROR,
        result.getStatus());

    OperationResultType fetchResult = resource.asObjectable().getFetchResult();
    display("resource.fetchResult", fetchResult);
    assertEquals(
        "Expected partial errror in fetchResult",
        OperationResultStatusType.PARTIAL_ERROR,
        fetchResult.getStatus());

    // TODO: better asserts
    assertNotNull("Null resource", resource);

    assertNotNull("Connector was not resolved", resource.asObjectable().getConnector());
  }
Ejemplo n.º 3
0
  public static void copyResultFromJAXB(
      ItemDefinition parentDef,
      QName itemName,
      OperationResultType jaxb,
      OperationResult repo,
      PrismContext prismContext)
      throws DtoTranslationException {
    Validate.notNull(repo, "Repo object must not be null.");

    if (jaxb == null) {
      return;
    }

    repo.setStatus(getRepoEnumValue(jaxb.getStatus(), ROperationResultStatus.class));
    if (repo instanceof OperationResultFull) {
      try {
        ((OperationResultFull) repo)
            .setFullResult(RUtil.toRepo(parentDef, itemName, jaxb, prismContext));
      } catch (Exception ex) {
        throw new DtoTranslationException(ex.getMessage(), ex);
      }
    }
  }
Ejemplo n.º 4
0
  public static OperationResult createOperationResult(OperationResultType result) {
    if (result == null) {
      return null;
    }

    Map<String, Serializable> params = ParamsTypeUtil.fromParamsType(result.getParams());
    //		if (result.getParams() != null) {
    //			params = new HashMap<String, Serializable>();
    //			for (EntryType entry : result.getParams().getEntry()) {
    //				params.put(entry.getKey(), (Serializable) entry.getEntryValue());
    //			}
    //		}

    Map<String, Serializable> context = ParamsTypeUtil.fromParamsType(result.getContext());
    //		if (result.getContext() != null) {
    //			context = new HashMap<String, Serializable>();
    //			for (EntryType entry : result.getContext().getEntry()) {
    //				context.put(entry.getKey(), (Serializable) entry.getEntryValue());
    //			}
    //		}

    Map<String, Serializable> returns = ParamsTypeUtil.fromParamsType(result.getReturns());
    //		if (result.getReturns() != null) {
    //			returns = new HashMap<String, Serializable>();
    //			for (EntryType entry : result.getReturns().getEntry()) {
    //				returns.put(entry.getKey(), (Serializable) entry.getEntryValue());
    //			}
    //		}

    List<OperationResult> subresults = null;
    if (!result.getPartialResults().isEmpty()) {
      subresults = new ArrayList<OperationResult>();
      for (OperationResultType subResult : result.getPartialResults()) {
        subresults.add(createOperationResult(subResult));
      }
    }

    LocalizedMessageType message = result.getLocalizedMessage();
    String localizedMessage = message == null ? null : message.getKey();
    List<Serializable> localizedArguments =
        message == null
            ? null
            : (List<Serializable>) (List) message.getArgument(); // FIXME: brutal hack

    OperationResult opResult =
        new OperationResult(
            result.getOperation(),
            params,
            context,
            returns,
            OperationResultStatus.parseStatusType(result.getStatus()),
            result.getToken(),
            result.getMessageCode(),
            result.getMessage(),
            localizedMessage,
            localizedArguments,
            null,
            subresults);
    if (result.getCount() != null) {
      opResult.setCount(result.getCount());
    }
    return opResult;
  }
Ejemplo n.º 5
0
  private OperationResultType createOperationResultType(OperationResult opResult) {
    OperationResultType result = new OperationResultType();
    result.setToken(opResult.getToken());
    result.setStatus(OperationResultStatus.createStatusType(opResult.getStatus()));
    if (opResult.getCount() != 1) {
      result.setCount(opResult.getCount());
    }
    result.setOperation(opResult.getOperation());
    result.setMessage(opResult.getMessage());
    result.setMessageCode(opResult.getMessageCode());

    if (opResult.getCause() != null || !opResult.details.isEmpty()) {
      StringBuilder detailsb = new StringBuilder();

      // Record text messages in details (if present)
      if (!opResult.details.isEmpty()) {
        for (String line : opResult.details) {
          detailsb.append(line);
          detailsb.append("\n");
        }
      }

      // Record stack trace in details if a cause is present
      if (opResult.getCause() != null) {
        Throwable ex = opResult.getCause();
        detailsb.append(ex.getClass().getName());
        detailsb.append(": ");
        detailsb.append(ex.getMessage());
        detailsb.append("\n");
        StackTraceElement[] stackTrace = ex.getStackTrace();
        for (int i = 0; i < stackTrace.length; i++) {
          detailsb.append(stackTrace[i].toString());
          detailsb.append("\n");
        }
      }

      result.setDetails(detailsb.toString());
    }

    if (StringUtils.isNotEmpty(opResult.getLocalizationMessage())) {
      LocalizedMessageType message = new LocalizedMessageType();
      message.setKey(opResult.getLocalizationMessage());
      if (opResult.getLocalizationArguments() != null) {
        message.getArgument().addAll(opResult.getLocalizationArguments());
      }
      result.setLocalizedMessage(message);
    }

    //		Set<Entry<String, Serializable>> params = opResult.getParams();
    //		if (!params.isEmpty()) {
    ParamsType paramsType = ParamsTypeUtil.toParamsType(opResult.getParams());
    result.setParams(paramsType);

    //			for (Entry<String, Serializable> entry : params) {
    //				paramsType.getEntry().add(createEntryElement(entry.getKey(),entry.getValue()));
    //			}
    //		}

    //		Set<Entry<String, Serializable>> context = opResult.getContext().entrySet();
    //		if (!context.isEmpty()) {
    paramsType = ParamsTypeUtil.toParamsType(opResult.getContext());
    result.setContext(paramsType);

    //			for (Entry<String, Serializable> entry : context) {
    //				paramsType.getEntry().add(createEntryElement(entry.getKey(),entry.getValue()));
    //			}
    //		}

    //		Set<Entry<String, Serializable>> returns = opResult.getReturns().entrySet();
    //		if (!returns.isEmpty()) {
    paramsType = ParamsTypeUtil.toParamsType(opResult.getReturns());
    result.setReturns(paramsType);

    //			for (Entry<String, Serializable> entry : returns) {
    //				paramsType.getEntry().add(createEntryElement(entry.getKey(),entry.getValue()));
    //			}
    //		}

    for (OperationResult subResult : opResult.getSubresults()) {
      result.getPartialResults().add(opResult.createOperationResultType(subResult));
    }

    return result;
  }