Esempio n. 1
0
  @Override
  public ResultDTO executeCommand(
      String screenName,
      String querynodeXpath,
      JSONObject jsonRecord,
      InputDTO inputDTO,
      ResultDTO resultDTO) {
    ResultDTO resDTO = new ResultDTO();
    try {
      Element rootXml = ScreenMapRepo.findMapXMLRoot(screenName);
      Element processorElm =
          (Element) rootXml.selectSingleNode("/root/screen/bl/" + querynodeXpath + " ");
      String methodName = processorElm.attributeValue("method");

      if ("testMethod1".equals(methodName)) {
        testMethod1();
        System.out.println(ServletActionContext.getContext().getSession());
        System.out.println(
            "Session var retreived:"
                + ServletActionContext.getContext().getSession().get("mysessionkey"));
      } else {
        System.out.println("ProgramSetup BL methodname is not defined");
      }

      List<String> errors = new ArrayList<String>();
      errors.add("business.logic.unimplemented");
      resDTO.setMessages(errors);
    } catch (FrontendException e) {
      resDTO.addError("error.accessxml");
    }
    return resDTO;
  }
Esempio n. 2
0
  public String save() throws Exception {

    String resultHtml = "";
    String formname = "";
    ResultDTO result = new ResultDTO();
    logger.debug("submitdata:" + submitdata);
    JSONObject jobj1 = JSONObject.fromObject(submitdata);
    InputDTO inputDTO = new InputDTO();
    inputDTO.setData((JSONObject) jobj1);
    ActionContext.getContext().getValueStack().getContext().put("inputDTO", inputDTO);
    ServletActionContext.getContext().getSession().put("mysessionkey", "MY session val");
    System.out.println(ServletActionContext.getContext().getSession().get("mysessionkey"));
    ResultDTO resDTO = null;

    try {
      FEValidator validator = new FEValidator();
      ResultDTO validatorDTO = validator.validate(screenName, jobj1);
      if (validatorDTO != null && validatorDTO.getErrors() != null) {
        if (validatorDTO.getErrors().size() > 0) {
          throw new ValidationException();
        }
      }
      CommandProcessor cmdpr = new CommandProcessor();
      resDTO = cmdpr.commandProcessor(jobj1, screenName);
      //			if(resDTO!=null && resDTO.getErrors() != null){
      //				if(resDTO.getErrors().size() >0){
      //					throw new ValidationException();
      //				}
      //			}
      JSONObject resObj = JSONObject.fromObject(resDTO);
      resultHtml = resObj.toString();
    } catch (ValidationException e) {
      throw new FrontendException("error.pagefailed", e);
    } catch (Exception e) {
      throw new Exception("error.global");
    }

    PageReturnType pg = null;
    try {
      pg = new ReturnCommandProcessor().getReturnType(screenName, jobj1, resDTO);
      screenName = pg.nextScreenName;
      resultPage = pg.resultPage;

      if ("ajax".equals(pg.resultName)) {
        inputStream = new StringBufferInputStream(resultHtml);
      }
    } catch (FrontendException e) {
      throw new FrontendException("error.nextpagenotfound");
    } catch (Exception e) {
      throw new Exception("error.global");
    }
    System.out.println("resultName = " + pg.resultName);
    System.out.println("screenName = " + pg.nextScreenName);
    System.out.println("resultPage = " + pg.resultPage);

    return pg.resultName;

    /*for (Iterator itr = jobj1.keys();itr.hasNext();) {
    	String name = (String) itr.next();
    	formname = name;
    	logger.debug(name);
    	JSONArray jobj = jobj1.getJSONArray(formname);
    	Gson gson = new Gson();
    	JsonElement jelm = gson.toJsonTree(submitdata);

    	for (int i = 0; i < jobj.size(); i++) {

    		if(jobj.getJSONObject(i).getString("txtstatus").equalsIgnoreCase("Modify")){

    				logger.debug("Going to Modify Block");
    				UpdateData upd = new UpdateData();
    				result =	upd.update(screenName,formname,jobj.getJSONObject(i));
    				if(result.getMessages().size() > 0)
    					resultHtml += "Records("+result.getMessages().size()+") Modified Successfully<br/>";
    				else
    					resultHtml += "Request failed "+ result.getErrors().size()+"\n";
    		}
    		if(jobj.getJSONObject(i).getString("txtstatus").equalsIgnoreCase("new")){
    				logger.debug("Going to Modify Block");
    				InsertData ins = new InsertData();
    				result = ins.insert(screenName,formname,jobj.getJSONObject(i));
    				if(result.getMessages().size() > 0)
    					resultHtml += "Records("+result.getMessages().size()+") Created Successfully<br/>";
    				else
    					resultHtml += "Request failed "+result.getErrors().size()+"\n";
    		}
    		if(jobj.getJSONObject(i).getString("txtstatus").equalsIgnoreCase("close")){
    				logger.debug("Going to Modify Block");
    				UpdateData upd = new UpdateData();
    				result = upd.update(screenName,formname,jobj.getJSONObject(i));
    				if(result.getMessages().size() > 0)
    					resultHtml += "Records("+result.getMessages().size()+") Closed Successfully<br/>";
    				else
    					resultHtml += "Request failed "+result.getErrors().size()+"\n";
    		}


    	}

    }*/
  }