Esempio n. 1
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);
  }
  @Override
  public Representation represent(Variant variant) throws ResourceException {
    // process request for single
    int idInt;
    OpenAcdQueueGroupRestInfoFull queueGroupRestInfo = null;
    String idString = (String) getRequest().getAttributes().get("id");

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

      try {
        queueGroupRestInfo = createQueueGroupRestInfo(idInt);
      } catch (Exception exception) {
        return RestUtilities.getResponseError(
            getResponse(),
            ResponseCode.ERROR_READ_FAILED,
            "Read Queue Group failed",
            exception.getLocalizedMessage());
      }

      return new OpenAcdQueueGroupRepresentation(variant.getMediaType(), queueGroupRestInfo);
    }

    // if not single, process request for all
    List<OpenAcdQueueGroup> queueGroups = m_openAcdContext.getQueueGroups();
    List<OpenAcdQueueGroupRestInfoFull> queueGroupsRestInfo =
        new ArrayList<OpenAcdQueueGroupRestInfoFull>();
    MetadataRestInfo metadataRestInfo;

    // sort if specified
    sortQueueGroups(queueGroups);

    // set requested based on pagination and get resulting metadata
    metadataRestInfo = addQueueGroups(queueGroupsRestInfo, queueGroups);

    // create final restinfo
    OpenAcdQueueGroupsBundleRestInfo queueGroupsBundleRestInfo =
        new OpenAcdQueueGroupsBundleRestInfo(queueGroupsRestInfo, metadataRestInfo);

    return new OpenAcdQueueGroupsRepresentation(variant.getMediaType(), queueGroupsBundleRestInfo);
  }