Esempio n. 1
0
  @Override
  public Representation represent(Variant variant) throws ResourceException {
    IntParameterInfo parameterInfo;
    Branch branch;
    BranchRestInfoFull branchRestInfo;

    // if have id then get a single item
    parameterInfo = RestUtilities.getIntFromAttribute(getRequest(), REQUEST_ATTRIBUTE_ID);
    if (parameterInfo.getExists()) {
      if (!parameterInfo.getValid()) {
        return RestUtilities.getResponseError(
            getResponse(), ERROR_ID_INVALID, parameterInfo.getValueString());
      }

      try {
        branch = m_branchManager.retrieveBranch(parameterInfo.getValue());
        if (branch == null) {
          return RestUtilities.getResponseError(
              getResponse(), ERROR_OBJECT_NOT_FOUND, parameterInfo.getValue());
        }

        branchRestInfo = createBranchRestInfo(branch);
      } catch (Exception exception) {
        return RestUtilities.getResponseError(
            getResponse(),
            ERROR_READ_FAILED,
            parameterInfo.getValue(),
            exception.getLocalizedMessage());
      }

      return new BranchRepresentation(variant.getMediaType(), branchRestInfo);
    }

    // if not single, process request for list
    List<Branch> branches = m_branchManager.getBranches();
    List<BranchRestInfoFull> branchesRestInfo = new ArrayList<BranchRestInfoFull>();
    MetadataRestInfo metadataRestInfo;

    // sort if specified
    sortBranches(branches);

    // set requested agents groups and get resulting metadata
    metadataRestInfo = addBranches(branchesRestInfo, branches);

    // create final restinfo
    BranchesBundleRestInfo branchesBundleRestInfo =
        new BranchesBundleRestInfo(branchesRestInfo, metadataRestInfo);

    return new BranchesRepresentation(variant.getMediaType(), branchesBundleRestInfo);
  }
Esempio n. 2
0
  @Override
  public Representation represent(Variant variant) throws ResourceException {
    // process request for single
    int idInt;
    BranchRestInfoFull branchRestInfo = null;
    String idString = (String) getRequest().getAttributes().get("id");

    if (idString != null) {
      try {
        idInt = RestUtilities.getIntFromAttribute(idString);
      } catch (Exception exception) {
        return RestUtilities.getResponseError(
            getResponse(),
            RestUtilities.ResponseCode.ERROR_BAD_INPUT,
            "ID " + idString + " not found.");
      }

      try {
        branchRestInfo = createBranchRestInfo(idInt);
      } catch (Exception exception) {
        return RestUtilities.getResponseError(
            getResponse(),
            RestUtilities.ResponseCode.ERROR_READ_FAILED,
            "Read Skills failed",
            exception.getLocalizedMessage());
      }

      return new BranchRepresentation(variant.getMediaType(), branchRestInfo);
    }

    // if not single, process request for all
    List<Branch> branches = m_branchManager.getBranches();
    List<BranchRestInfoFull> branchesRestInfo = new ArrayList<BranchRestInfoFull>();
    MetadataRestInfo metadataRestInfo;

    // sort if specified
    sortBranches(branches);

    // set requested agents groups and get resulting metadata
    metadataRestInfo = addBranches(branchesRestInfo, branches);

    // create final restinfo
    BranchesBundleRestInfo branchesBundleRestInfo =
        new BranchesBundleRestInfo(branchesRestInfo, metadataRestInfo);

    return new BranchesRepresentation(variant.getMediaType(), branchesBundleRestInfo);
  }