Пример #1
0
  @Override
  public void removeRepresentations() throws ResourceException {
    IntParameterInfo parameterInfo;
    Branch branch;

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

      try {
        // do not need object to delete, but confirm existence for error message
        branch = m_branchManager.retrieveBranch(parameterInfo.getValue());
        if (branch == null) {
          RestUtilities.setResponseError(
              getResponse(), ERROR_OBJECT_NOT_FOUND, parameterInfo.getValue());
          return;
        }

        List<Integer> branchIds = new ArrayList<Integer>();
        branchIds.add(parameterInfo.getValue());
        m_branchManager.deleteBranches(branchIds);
      } catch (Exception exception) {
        RestUtilities.setResponseError(
            getResponse(),
            ERROR_DELETE_FAILED,
            parameterInfo.getValue(),
            exception.getLocalizedMessage());
        return;
      }

      RestUtilities.setResponse(getResponse(), SUCCESS_DELETED, parameterInfo.getValue());
      return;
    }

    // no id string
    RestUtilities.setResponse(getResponse(), ERROR_MISSING_ID);
  }
Пример #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");
  }