コード例 #1
0
  @Override
  public void removeRepresentations() throws ResourceException {
    OpenAcdQueueGroup queueGroup;

    // get id then delete a single group
    String idString = (String) getRequest().getAttributes().get("id");

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

      m_openAcdContext.deleteQueueGroup(queueGroup);

      RestUtilities.setResponse(
          getResponse(), ResponseCode.SUCCESS_DELETED, "Deleted Queue Group", queueGroup.getId());

      return;
    }

    // no id string
    RestUtilities.setResponse(getResponse(), ResponseCode.ERROR_MISSING_INPUT, "ID value missing");
  }
コード例 #2
0
  private MetadataRestInfo addQueueGroups(
      List<OpenAcdQueueGroupRestInfoFull> queueGroupsRestInfo,
      List<OpenAcdQueueGroup> queueGroups) {
    List<OpenAcdSkillRestInfo> skillsRestInfo;
    List<OpenAcdAgentGroupRestInfo> agentGroupRestInfo;
    List<OpenAcdRecipeStepRestInfo> recipeStepRestInfo;
    // determine pagination
    PaginationInfo paginationInfo = RestUtilities.calculatePagination(m_form, queueGroups.size());

    // create list of group restinfos
    for (int index = paginationInfo.startIndex; index <= paginationInfo.endIndex; index++) {
      OpenAcdQueueGroup queueGroup = queueGroups.get(index);

      skillsRestInfo = createSkillsRestInfo(queueGroup.getSkills());
      agentGroupRestInfo = createAgentGroupsRestInfo(queueGroup);
      recipeStepRestInfo = createRecipeStepsRestInfo(queueGroup);

      OpenAcdQueueGroupRestInfoFull queueGroupRestInfo =
          new OpenAcdQueueGroupRestInfoFull(
              queueGroup, skillsRestInfo, agentGroupRestInfo, recipeStepRestInfo);
      queueGroupsRestInfo.add(queueGroupRestInfo);
    }

    // create metadata about agent groups
    MetadataRestInfo metadata = new MetadataRestInfo(paginationInfo);
    return metadata;
  }
コード例 #3
0
ファイル: BranchesResource.java プロジェクト: dwaseem/sipxecs
  @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);
  }
コード例 #4
0
  @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);
  }
コード例 #5
0
ファイル: BranchesResource.java プロジェクト: dwaseem/sipxecs
  @Override
  public void removeRepresentations() throws ResourceException {
    Branch branch;
    int idInt;

    // get id then delete single
    String idString = (String) getRequest().getAttributes().get("id");

    if (idString != null) {
      try {
        idInt = RestUtilities.getIntFromAttribute(idString);
        branch =
            m_branchManager.getBranch(
                idInt); // just obtain to make sure exists, use int id for actual delete
      } catch (Exception exception) {
        RestUtilities.setResponseError(
            getResponse(),
            RestUtilities.ResponseCode.ERROR_BAD_INPUT,
            "ID " + idString + " not found.");
        return;
      }

      List<Integer> branchIds = new ArrayList<Integer>();
      branchIds.add(idInt);
      m_branchManager.deleteBranches(branchIds);

      RestUtilities.setResponse(
          getResponse(),
          RestUtilities.ResponseCode.SUCCESS_DELETED,
          "Deleted Branch",
          branch.getId());

      return;
    }

    // no id string
    RestUtilities.setResponse(
        getResponse(), RestUtilities.ResponseCode.ERROR_MISSING_INPUT, "ID value missing");
  }
コード例 #6
0
ファイル: BranchesResource.java プロジェクト: dwaseem/sipxecs
  private MetadataRestInfo addBranches(
      List<BranchRestInfoFull> branchesRestInfo, List<Branch> branches) {
    BranchRestInfoFull branchRestInfo;

    // determine pagination
    PaginationInfo paginationInfo = RestUtilities.calculatePagination(m_form, branches.size());

    // create list of skill restinfos
    for (int index = paginationInfo.startIndex; index <= paginationInfo.endIndex; index++) {
      Branch branch = branches.get(index);

      branchRestInfo = new BranchRestInfoFull(branch);
      branchesRestInfo.add(branchRestInfo);
    }

    // create metadata about agent groups
    MetadataRestInfo metadata = new MetadataRestInfo(paginationInfo);
    return metadata;
  }
コード例 #7
0
  private void sortQueueGroups(List<OpenAcdQueueGroup> queueGroups) {
    // sort groups if requested
    SortInfo sortInfo = RestUtilities.calculateSorting(m_form);

    if (!sortInfo.sort) {
      return;
    }

    SortField sortField = SortField.toSortField(sortInfo.sortField);

    if (sortInfo.directionForward) {

      switch (sortField) {
        case NAME:
          Collections.sort(
              queueGroups,
              new Comparator() {

                public int compare(Object object1, Object object2) {
                  OpenAcdQueueGroup queueGroup1 = (OpenAcdQueueGroup) object1;
                  OpenAcdQueueGroup queueGroup2 = (OpenAcdQueueGroup) object2;
                  return RestUtilities.compareIgnoreCaseNullSafe(
                      queueGroup1.getName(), queueGroup2.getName());
                }
              });
          break;

        case DESCRIPTION:
          Collections.sort(
              queueGroups,
              new Comparator() {

                public int compare(Object object1, Object object2) {
                  OpenAcdQueueGroup queueGroup1 = (OpenAcdQueueGroup) object1;
                  OpenAcdQueueGroup queueGroup2 = (OpenAcdQueueGroup) object2;
                  return RestUtilities.compareIgnoreCaseNullSafe(
                      queueGroup1.getDescription(), queueGroup2.getDescription());
                }
              });
          break;
      }
    } else {
      // must be reverse
      switch (sortField) {
        case NAME:
          Collections.sort(
              queueGroups,
              new Comparator() {

                public int compare(Object object1, Object object2) {
                  OpenAcdQueueGroup queueGroup1 = (OpenAcdQueueGroup) object1;
                  OpenAcdQueueGroup queueGroup2 = (OpenAcdQueueGroup) object2;
                  return RestUtilities.compareIgnoreCaseNullSafe(
                      queueGroup2.getName(), queueGroup1.getName());
                }
              });
          break;

        case DESCRIPTION:
          Collections.sort(
              queueGroups,
              new Comparator() {

                public int compare(Object object1, Object object2) {
                  OpenAcdQueueGroup queueGroup1 = (OpenAcdQueueGroup) object1;
                  OpenAcdQueueGroup queueGroup2 = (OpenAcdQueueGroup) object2;
                  return RestUtilities.compareIgnoreCaseNullSafe(
                      queueGroup2.getDescription(), queueGroup1.getDescription());
                }
              });
          break;
      }
    }
  }
コード例 #8
0
  @Override
  public void storeRepresentation(Representation entity) throws ResourceException {
    // get group from body
    OpenAcdQueueGroupRepresentation representation = new OpenAcdQueueGroupRepresentation(entity);
    OpenAcdQueueGroupRestInfoFull queueGroupRestInfo = representation.getObject();
    OpenAcdQueueGroup queueGroup;

    // validate input for update or create
    ValidationInfo validationInfo = validate(queueGroupRestInfo);

    if (!validationInfo.valid) {
      RestUtilities.setResponseError(
          getResponse(), validationInfo.responseCode, validationInfo.message);
      return;
    }

    // if have id then update a single group
    String idString = (String) getRequest().getAttributes().get("id");

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

      // copy values over to existing group
      try {
        updateQueueGroup(queueGroup, queueGroupRestInfo);
        m_openAcdContext.saveQueueGroup(queueGroup);
      } catch (Exception exception) {
        RestUtilities.setResponseError(
            getResponse(),
            ResponseCode.ERROR_WRITE_FAILED,
            "Update Queue Group failed",
            exception.getLocalizedMessage());
        return;
      }

      RestUtilities.setResponse(
          getResponse(), ResponseCode.SUCCESS_UPDATED, "Updated Queue", queueGroup.getId());

      return;
    }

    // otherwise add new agent group
    try {
      queueGroup = createQueueGroup(queueGroupRestInfo);
      m_openAcdContext.saveQueueGroup(queueGroup);
    } catch (Exception exception) {
      RestUtilities.setResponseError(
          getResponse(),
          RestUtilities.ResponseCode.ERROR_WRITE_FAILED,
          "Create Queue Group failed",
          exception.getLocalizedMessage());
      return;
    }

    RestUtilities.setResponse(
        getResponse(),
        RestUtilities.ResponseCode.SUCCESS_CREATED,
        "Created Queue Group",
        queueGroup.getId());
  }
コード例 #9
0
ファイル: BranchesResource.java プロジェクト: dwaseem/sipxecs
  private void sortBranches(List<Branch> branches) {
    // sort if requested
    SortInfo sortInfo = RestUtilities.calculateSorting(m_form);

    if (!sortInfo.sort) {
      return;
    }

    SortField sortField = SortField.toSortField(sortInfo.sortField);

    if (sortInfo.directionForward) {

      switch (sortField) {
        case NAME:
          Collections.sort(
              branches,
              new Comparator() {

                public int compare(Object object1, Object object2) {
                  Branch branch1 = (Branch) object1;
                  Branch branch2 = (Branch) object2;
                  return branch1.getName().compareToIgnoreCase(branch2.getName());
                }
              });
          break;

        case DESCRIPTION:
          Collections.sort(
              branches,
              new Comparator() {

                public int compare(Object object1, Object object2) {
                  Branch branch1 = (Branch) object1;
                  Branch branch2 = (Branch) object2;
                  return branch1.getDescription().compareToIgnoreCase(branch2.getDescription());
                }
              });
          break;
      }
    } else {
      // must be reverse
      switch (sortField) {
        case NAME:
          Collections.sort(
              branches,
              new Comparator() {

                public int compare(Object object1, Object object2) {
                  Branch branch1 = (Branch) object1;
                  Branch branch2 = (Branch) object2;
                  return branch2.getName().compareToIgnoreCase(branch1.getName());
                }
              });
          break;

        case DESCRIPTION:
          Collections.sort(
              branches,
              new Comparator() {

                public int compare(Object object1, Object object2) {
                  Branch branch1 = (Branch) object1;
                  Branch branch2 = (Branch) object2;
                  return branch2.getDescription().compareToIgnoreCase(branch1.getDescription());
                }
              });
          break;
      }
    }
  }
コード例 #10
0
ファイル: BranchesResource.java プロジェクト: dwaseem/sipxecs
  @Override
  public void storeRepresentation(Representation entity) throws ResourceException {
    // get from request body
    BranchRepresentation representation = new BranchRepresentation(entity);
    BranchRestInfoFull branchRestInfo = representation.getObject();
    Branch branch = null;

    // validate input for update or create
    ValidationInfo validationInfo = validate(branchRestInfo);

    if (!validationInfo.valid) {
      RestUtilities.setResponseError(
          getResponse(), validationInfo.responseCode, validationInfo.message);
      return;
    }

    // if have id then update single
    String idString = (String) getRequest().getAttributes().get("id");

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

      // copy values over to existing
      try {
        updateBranch(branch, branchRestInfo);
        m_branchManager.saveBranch(branch);
      } catch (Exception exception) {
        RestUtilities.setResponseError(
            getResponse(),
            RestUtilities.ResponseCode.ERROR_WRITE_FAILED,
            "Update Branch failed",
            exception.getLocalizedMessage());
        return;
      }

      RestUtilities.setResponse(
          getResponse(),
          RestUtilities.ResponseCode.SUCCESS_UPDATED,
          "Updated Branch",
          branch.getId());

      return;
    }

    // otherwise add new
    try {
      branch = createBranch(branchRestInfo);
      m_branchManager.saveBranch(branch);
    } catch (Exception exception) {
      RestUtilities.setResponseError(
          getResponse(),
          RestUtilities.ResponseCode.ERROR_WRITE_FAILED,
          "Create Branch failed",
          exception.getLocalizedMessage());
      return;
    }

    RestUtilities.setResponse(
        getResponse(),
        RestUtilities.ResponseCode.SUCCESS_CREATED,
        "Created Branch",
        branch.getId());
  }