コード例 #1
0
  /**
   * Overrides the execute method of Action class. Adds / Updates the data in the database.
   *
   * @param mapping ActionMapping
   * @param form ActionForm
   * @param request HttpServletRequest
   * @param response HttpServletResponse
   * @return ActionForward
   * @throws Exception Exception
   */
  public ActionForward executeSecureAction(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    LOGGER.info("in execute method");
    BaseAddEditAction addEditAction;
    AbstractActionForm abstractForm = (AbstractActionForm) form;
    ActionForward actionfwd;
    try {
      if (!isTokenValid(request)) {
        actionfwd = mapping.findForward(Constants.FAILURE);
        ActionErrors actionErrors = new ActionErrors();
        ActionError actionError =
            new ActionError("errors.item", "Invalid request for add/edit operation");
        actionErrors.add(ActionErrors.GLOBAL_ERROR, actionError);
        saveErrors(request, actionErrors);
      } else {
        resetToken(request);
        if (abstractForm.isAddOperation()) {
          addEditAction = new CommonAddAction();
        } else {
          addEditAction = new CommonEdtAction();
        }
        actionfwd = addEditAction.executeXSS(mapping, abstractForm, request, response);
      }
    } catch (ApplicationException applicationException) {
      LOGGER.error("Common Add/Edit failed.." + applicationException.getCustomizedMsg());

      ActionErrors actionErrors = new ActionErrors();
      ActionError actionError =
          new ActionError("errors.item", applicationException.getCustomizedMsg());
      actionErrors.add(ActionErrors.GLOBAL_ERROR, actionError);
      saveErrors(request, actionErrors);

      actionfwd = mapping.findForward(Constants.FAILURE);
    }
    return actionfwd;
  }
コード例 #2
0
  /**
   * Overriding the parent class's method to validate the enumerated attribute values
   *
   * @param obj : obj
   * @param dao : dao
   * @param operation : operation
   * @throws BizLogicException : BizLogicException
   * @return boolean
   */
  @Override
  protected boolean validate(Object obj, DAO dao, String operation) throws BizLogicException {
    try {
      final StorageContainer container = (StorageContainer) obj;
      final Map similarContainerMap = container.getSimilarContainerMap();
      final String containerPrefixKey = "simCont:";
      final String parentContainerId = "_parentContainerId";
      final List positionsToBeAllocatedList = new ArrayList();
      final List usedPositionsList = new ArrayList();

      for (int i = 1; i <= container.getNoOfContainers().intValue(); i++) {
        StorageContainerUtil.prepareContainerMap(
            dao,
            similarContainerMap,
            containerPrefixKey,
            positionsToBeAllocatedList,
            usedPositionsList,
            i,
            parentContainerId);
      }
      /*for (int i = 0; i < positionsToBeAllocatedList.size(); i++)
      {
      	StorageContainerUtil.allocatePositionToSingleContainerOrSpecimen(
      			positionsToBeAllocatedList.get(i), similarContainerMap, usedPositionsList,
      			containerPrefixKey, parentContainerId);
      }*/
      if (container.getNoOfContainers().intValue() > 1 && similarContainerMap.size() > 0) {
        for (int i = 1; i <= container.getNoOfContainers().intValue(); i++) {
          final int checkedButtonStatus =
              Integer.parseInt((String) similarContainerMap.get("checkedButton"));
          final String siteId = (String) similarContainerMap.get("simCont:" + i + "_siteId");
          if (checkedButtonStatus == 2 || siteId == null) {
            final String parentContId =
                (String) similarContainerMap.get("simCont:" + i + "_parentContainerId");
            final String positionDimensionOne =
                (String) similarContainerMap.get("simCont:" + i + "_positionDimensionOne");
            final String positionDimensionTwo =
                (String) similarContainerMap.get("simCont:" + i + "_positionDimensionTwo");
            if (parentContId.equals("-1")
                || positionDimensionOne.equals("-1")
                || positionDimensionTwo.equals("-1")) {

              throw this.getBizLogicException(
                  null,
                  "errors.item.required",
                  ApplicationProperties.getValue("similarcontainers.location"));
            }
          } else {
            if (siteId.equals("-1")) {
              throw this.getBizLogicException(
                  null,
                  "errors.item.required",
                  ApplicationProperties.getValue("storageContainer.site"));
            }
          }
        }
      }
    } catch (final ApplicationException exp) {
      this.logger.error(exp.getMessage(), exp);
      exp.printStackTrace();
      throw this.getBizLogicException(exp, exp.getErrorKeyName(), exp.getMsgValues());
    }
    return true;
  }