protected void updateEntityFields(ActionContext actionContext, IGTEntity entity)
      throws GTClientException {
    ConnectionSetupResultAForm form = (ConnectionSetupResultAForm) actionContext.getActionForm();
    IGTConnectionSetupResultEntity result = (IGTConnectionSetupResultEntity) entity;
    IGTConnectionSetupParamEntity param =
        (IGTConnectionSetupParamEntity)
            result.getFieldValue(IGTConnectionSetupResultEntity.SETUP_PARAMETERS);

    Short status = form.getStatusShort();
    if (IGTConnectionSetupResultEntity.STATUS_FAILURE.equals(status)
        || IGTConnectionSetupResultEntity.STATUS_NOT_DONE.equals(status)) {
      param.setFieldValue(
          IGTConnectionSetupParamEntity.ORIGINAL_LOCATION, form.getOriginalLocation());
      param.setFieldValue(
          IGTConnectionSetupParamEntity.SERVICING_ROUTER, form.getServicingRouter());
      param.setFieldValue(
          IGTConnectionSetupParamEntity.SECURITY_PASSWORD, form.getSecurityPassword());
    } else if (IGTConnectionSetupResultEntity.STATUS_SUCCESS.equals(status)) {
      OperationContext opCon = OperationContext.getOperationContext(actionContext.getRequest());
      List gridMasterList = (List) opCon.getAttribute(GRIDMASTER_LIST);
      List routerList = (List) opCon.getAttribute(ROUTER_LIST);
      Collection gridMasterUids = StaticCtrlUtils.getUids(gridMasterList);
      Collection routerUids = StaticCtrlUtils.getUids(routerList);
      result.setFieldValue(IGTConnectionSetupResultEntity.AVAILABLE_GRIDMASTERS, gridMasterUids);
      result.setFieldValue(IGTConnectionSetupResultEntity.AVAILABLE_ROUTERS, routerUids);
    } else {
      throw new java.lang.IllegalStateException(
          "Illegal STATUS for connectionSetupResult:" + status);
    }
  }
  protected void prepLists(ActionContext actionContext, boolean reloaded) throws GTClientException {
    try {
      OperationContext opCon = OperationContext.getOperationContext(actionContext.getRequest());
      List gridMasterList = (List) opCon.getAttribute(GRIDMASTER_LIST);
      if (reloaded || (gridMasterList == null)) {
        IGTConnectionSetupResultEntity result =
            (IGTConnectionSetupResultEntity) getEntity(actionContext);
        gridMasterList =
            (List) result.getFieldEntities(IGTConnectionSetupResultEntity.AVAILABLE_GRIDMASTERS);
        List routerList =
            (List) result.getFieldEntities(IGTConnectionSetupResultEntity.AVAILABLE_ROUTERS);
        if (gridMasterList == null)
          throw new NullPointerException("gridMasterList is null"); // 20030422AH
        if (routerList == null) throw new NullPointerException("routerList is null"); // 20030422AH
        opCon.setAttribute(GRIDMASTER_LIST, gridMasterList);
        opCon.setAttribute(ROUTER_LIST, routerList);

        ConnectionSetupResultAForm form =
            (ConnectionSetupResultAForm) actionContext.getActionForm();
        String initRoutersOrder = StaticUtils.initialOrderString(routerList.size());
        String initMastersOrder = StaticUtils.initialOrderString(gridMasterList.size());
        form.setAvailableGridMastersOrder(initMastersOrder);
        form.setAvailableRoutersOrder(initRoutersOrder);
      }
    } catch (Throwable t) {
      throw new GTClientException(
          "Error prepping GridMaster and Router lists in OperationContext", t);
    }
  }
  protected void validateActionForm(
      ActionContext actionContext, IGTEntity entity, ActionForm form, ActionErrors actionErrors)
      throws GTClientException {
    ConnectionSetupResultAForm rForm = (ConnectionSetupResultAForm) form;
    IGTConnectionSetupResultEntity result = (IGTConnectionSetupResultEntity) entity;
    IGTConnectionSetupParamEntity param =
        (IGTConnectionSetupParamEntity)
            result.getFieldValue(IGTConnectionSetupResultEntity.SETUP_PARAMETERS);
    Short status = rForm.getStatusShort();
    if (IGTConnectionSetupResultEntity.STATUS_FAILURE.equals(status)
        || IGTConnectionSetupResultEntity.STATUS_NOT_DONE.equals(status)) {
      if (result.getSession().isNoSecurity()) { // 20031105AH
        rForm.setSecurityPassword(IGTSession.PCP_DEFAULT);
      }

      basicValidateString(
          actionErrors, IGTConnectionSetupParamEntity.CURRENT_LOCATION, rForm, param);
      basicValidateString(
          actionErrors, IGTConnectionSetupParamEntity.SERVICING_ROUTER, rForm, param);
      basicValidateString(
          actionErrors, IGTConnectionSetupParamEntity.SECURITY_PASSWORD, rForm, param);
    } else if (IGTConnectionSetupResultEntity.STATUS_SUCCESS.equals(status)) {
      // Only the order can be changed.
      // We leave uid validation to b-tier
    } else {
      actionErrors.add("status", new ActionError("connectionSetupResult.error.status.invalid"));
    }
  }
  protected void initialiseActionForm(ActionContext actionContext, IGTEntity entity)
      throws GTClientException {
    ConnectionSetupResultAForm form = (ConnectionSetupResultAForm) actionContext.getActionForm();
    IGTConnectionSetupResultEntity result = (IGTConnectionSetupResultEntity) entity;
    IGTConnectionSetupParamEntity param =
        (IGTConnectionSetupParamEntity)
            result.getFieldValue(IGTConnectionSetupResultEntity.SETUP_PARAMETERS);

    form.setCurrentLocation(param.getFieldString(IGTConnectionSetupParamEntity.CURRENT_LOCATION));
    form.setServicingRouter(param.getFieldString(IGTConnectionSetupParamEntity.SERVICING_ROUTER));
    form.setOriginalLocation(param.getFieldString(IGTConnectionSetupParamEntity.ORIGINAL_LOCATION));
    form.setOriginalServicingRouter(
        param.getFieldString(IGTConnectionSetupParamEntity.ORIGINAL_SERVICING_ROUTER));

    form.setStatus(result.getFieldString(IGTConnectionSetupResultEntity.STATUS));
    form.setFailureReason(result.getFieldString(IGTConnectionSetupResultEntity.FAILURE_REASON));

    prepLists(actionContext, false);
  }