Commit 18bdfe40 by gechengyang

AA

parent e7d54cd1
......@@ -16,6 +16,7 @@ public class NoUiRequest {
private String mappingUrl;
private Map<String, ?> paramsMap = new HashMap<String, Object>();
private Map<String, ?> dataMap = new HashMap<String, Object>();
private Map<String, ?> saveDisplayMap = new HashMap<String, Object>();
public NoUiRequest(HttpServletRequest request, String mappingUrl, Map<String, ?> requestData) {
String tokenId = request.getHeader("token");
......@@ -28,10 +29,13 @@ public class NoUiRequest {
if (requestData != null) {
this.paramsMap = (Map<String, ?>) requestData.get(Constants.PARAMS);
this.dataMap = (Map<String, ?>) requestData.get(Constants.DATA);
this.saveDisplayMap = (Map<String, ?>) requestData.get(Constants.DISPLAY);
if (this.paramsMap == null)
this.paramsMap = new HashMap<String, Object>();
if (this.dataMap == null)
this.dataMap = new HashMap<String, Object>();
if (this.saveDisplayMap == null)
this.saveDisplayMap = new HashMap<String, Object>();
}
}
......@@ -91,4 +95,12 @@ public class NoUiRequest {
this.dataMap = dataMap;
}
public Map<String, ?> getSaveDisplayMap() {
return saveDisplayMap;
}
public void setSaveDisplayMap(Map<String, ?> saveDisplayMap) {
this.saveDisplayMap = saveDisplayMap;
}
}
......@@ -3,9 +3,13 @@ package org.sss.presentation.noui.common;
public class Constants {
public final static String PARAMS = "params";
public final static String DATA = "data";
public final static String DISPLAY = "display";
public final static String ENCODING = "UTF-8";
public final static String USERNAME = "username";
public final static String PASSWORD = "password";
public final static String DISPLAY_FILE_NAME = "fileName";
public final static String MAPPING_PRE = "_";
}
......@@ -19,10 +19,10 @@ public class NoUiContextManager {
public static String dbType = "hibernate";
public static String loginContextName = "cn.com.brilliance.eibs.auth.DatabaseLoginContext";
public static NoUiContext createNoUiContext(NoUiRequest request) {
public static NoUiContext createNoUiContext(NoUiRequest noUiRequest) {
NoUiContext noUiContext = new NoUiContext();
ILoginContext loginContext = null;
if (StringUtils.isEmpty(request.getToken())) {
if (StringUtils.isEmpty(noUiRequest.getToken())) {
try {
loginContext = (ILoginContext) Class.forName(loginContextName).newInstance();
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
......@@ -31,7 +31,7 @@ public class NoUiContextManager {
}
else
loginContext = new EmptyLoginContext(request.getUserId());
loginContext = new EmptyLoginContext(noUiRequest.getUserId());
loginContext.setContext(noUiContext);
noUiContext.setAuth(loginContext);
noUiContext.setSessionId(UUID.randomUUID().toString());
......@@ -42,7 +42,7 @@ public class NoUiContextManager {
} catch (Exception e) {
throw new NoUiException("Constructs NoUiContext error");
}
noUiContext.setGui(new NoUiPresentation(noUiContext));
noUiContext.setGui(new NoUiPresentation(noUiContext, noUiRequest));
noUiContext.setSession(session);
log.debug("Build context finished");
......
......@@ -2,6 +2,7 @@ package org.sss.presentation.noui.context;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
......@@ -13,6 +14,7 @@ import java.util.Map;
import log.Log;
import log.LogFactory;
import org.apache.commons.io.FileUtils;
import org.sss.common.impl.AbstractNullPresentation;
import org.sss.common.model.CodetableItem;
import org.sss.common.model.IAttribute;
......@@ -28,9 +30,13 @@ import org.sss.common.model.MessageType;
import org.sss.common.model.RowOpType;
import org.sss.common.model.ViewType;
import org.sss.exception.ContainerException;
import org.sss.presentation.noui.api.request.NoUiRequest;
import org.sss.presentation.noui.common.Constants;
import org.sss.presentation.noui.util.NoUiUtils;
import org.sss.util.ContainerUtils;
import com.google.gson.Gson;
public class NoUiPresentation extends AbstractNullPresentation {
private static final Log log = LogFactory.getLog(NoUiPresentation.class);
// public final Map<IModuleList<?>, List<RowOpItem>> tableRowMap = new
......@@ -51,6 +57,8 @@ public class NoUiPresentation extends AbstractNullPresentation {
// ArrayList<IAttribute<?>>();
private Map<String, Object> codetable = new HashMap<>();
private NoUiRequest noUiRequest;
private Map<String, Object> error = new HashMap<>();
private Map<String, Object> modifyMap = new HashMap<>();
......@@ -74,8 +82,9 @@ public class NoUiPresentation extends AbstractNullPresentation {
return isChain;
}
public NoUiPresentation(NoUiContext context) {
public NoUiPresentation(NoUiContext context, NoUiRequest noUiRequest) {
this.ctx = context;
this.noUiRequest = noUiRequest;
}
public synchronized void dispose() {
......@@ -452,6 +461,23 @@ public class NoUiPresentation extends AbstractNullPresentation {
return NoUiUtils.debugMode;
}
@Override
public void saveDisplay(IPanel[] panels, String fileName, String cssUrl) throws ContainerException {
saveDisplay(panels, fileName);
}
@Override
public void saveDisplay(IPanel[] panels, String fileName) throws ContainerException {
try {
Map<String, ?> map = noUiRequest.getSaveDisplayMap();
String data = new Gson().toJson(map);
FileUtils.write(new File(fileName), data, Constants.ENCODING);
} catch (IOException e) {
log.error("save dispaly error", e);
}
}
public Map<String, Object> getCodetable() {
return codetable;
}
......
......@@ -115,8 +115,9 @@ public class AbstractCommonController {
NoUiPresentationUtil.handleErrorReturnData(context, alias), NoUiPresentationUtil.handleCodeTableReturnData(context, alias));
} catch (Exception e) {
log.error("OnClick command error", e);
return ResultUtil.result(ErrorCodes.ERROR, "hander error", e.getMessage());
}
return ResultUtil.result(ErrorCodes.ERROR, "提交处理异常", null);
}
private IBaseObject baseObject(NoUiContext context, NoUiRequest noUiRequest, Alias alias) {
......
package org.sss.presentation.noui.controller;
import java.io.File;
import java.io.FileInputStream;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import log.Log;
import log.LogFactory;
import org.apache.commons.io.IOUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.sss.presentation.noui.api.response.ErrorCodes;
import org.sss.presentation.noui.api.response.ResultUtil;
import org.sss.presentation.noui.common.Constants;
import com.google.gson.Gson;
@Controller
public class ShowDisplayController {
private static final Log log = LogFactory.getLog(ShowDisplayController.class);
@ResponseBody
@RequestMapping(value = "/showDisplay", method = RequestMethod.POST)
public Object showDisplay(@RequestBody Map<String, Object> dataMap, HttpServletRequest request, HttpSession session) {
System.out.println(dataMap);
try {
String fileName = (String) dataMap.get(Constants.DISPLAY_FILE_NAME);
FileInputStream fis = new FileInputStream(new File(fileName));
String jsonData = IOUtils.toString(fis, Constants.ENCODING);
Map mapData = new Gson().fromJson(jsonData, Map.class);
return ResultUtil.result(ErrorCodes.SUCCESS, ErrorCodes.SUCCESS_INFO, mapData);
} catch (Exception e) {
log.error("showDisplay error", e);
return ResultUtil.result(ErrorCodes.ERROR, "showDisplay error", e.getMessage());
}
}
}
package org.sss.presentation.noui.api.servlet;
import java.util.HashMap;
import java.util.Map;
import com.google.gson.Gson;
public class GsonTest {
public static void main(String[] args) {
Map<String, String> map = new HashMap<String, String>();
map.put("username", "tst1");
map.put("password", "1");
Map<String, Object> map2 = new HashMap<String, Object>();
map2.put("data", map);
// System.out.println(JSON.toJSON(student));
System.out.println(new Gson().toJson(map2));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment