@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");
  }
Esempio n. 2
0
  @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");
  }
  @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());
  }
Esempio n. 4
0
  @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());
  }