コード例 #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
  @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());
  }