This commit is contained in:
2024-03-25 23:12:10 +05:00
parent dd0a3f17ea
commit ba933a0712
18 changed files with 194 additions and 2951 deletions

View File

@ -56,6 +56,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
@ -105,10 +109,13 @@ public class DBMSRecords implements ServletContextAware {
}
//Документация по @RequestBody http://javastudy.ru/spring-mvc/json-xml/ application/xml
@RequestMapping(value = "/monitoring/records.php",method = {RequestMethod.POST,RequestMethod.GET},produces = "text/plain; charset=utf-8")
@RequestMapping(value = "/api/dbms/records.xyz",method = {RequestMethod.POST,RequestMethod.GET}) //,produces = "text/plain; charset=utf-8"
@ResponseBody
public Object ajaxTamer(@ModelAttribute User user,@RequestBody(required = false) byte[] reqData,@RequestParam(required=false,name="lng") String language_id) {
public ResponseEntity<String> ajaxTamer(@ModelAttribute User user, @RequestBody(required = false) byte[] reqData, @RequestParam(required=false,name="lng") String language_id) {
final HttpHeaders httpHeaders= new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
if(language_id!=null && !language_id.equals(""))
user.language_id=language_id;
logger.info("user.id="+user.id+" user.name="+user.name+" user.language_id="+user.language_id+" user.country_id="+user.country_id);
@ -116,7 +123,7 @@ public class DBMSRecords implements ServletContextAware {
boolean error=false;
String result=sendError(1,"Request not processed!");
if(reqData==null)
return result;
return new ResponseEntity<String>(result, httpHeaders, HttpStatus.OK);
//response.setCharacterEncoding("UTF-8");
@ -198,7 +205,7 @@ public class DBMSRecords implements ServletContextAware {
} catch (Exception ex) {
logger.info(ex.getMessage());
//return "<metadata fn=\"-1\"><![CDATA[Parsing request error!]]></metadata>";
return sendError(1,"Parsing request error!");
return new ResponseEntity<String>(sendError(1,"Parsing request error!"), httpHeaders, HttpStatus.OK);
}
if (doc != null) {
@ -427,6 +434,7 @@ public class DBMSRecords implements ServletContextAware {
}
result=getText(conn,xml,user);
httpHeaders.setContentType(MediaType.APPLICATION_XML);
} else if (fn != null && fn.equals("1")) {
String typename = "";
@ -511,7 +519,8 @@ public class DBMSRecords implements ServletContextAware {
sql_query = Tools.replaceAll(sql_query,"${" + vn + "}", getSQLValue(vt, val));
}
sql_query = Tools.replaceAll(sql_query,"${_user_id}", (String) user.id); //Set current user id in sql query.
if(user.id==null) sql_query = Tools.replaceAll(sql_query,"${_user_id}", "null");
else sql_query = Tools.replaceAll(sql_query,"${_user_id}", (String) user.id);
logger.info("sql_query22 = " + sql_query);
@ -528,7 +537,8 @@ public class DBMSRecords implements ServletContextAware {
String xmlstring = "<metadata fn=\"1\"><type n=\"" + typename + "\" id=\"" + obj_id + "\"></type></metadata>";
result=xmlstring;
logger.info("xmlstring = " + xmlstring);
httpHeaders.setContentType(MediaType.APPLICATION_XML);
//logger.info("xmlstring = " + xmlstring);
}
stt.close();
rs.close();
@ -624,7 +634,8 @@ public class DBMSRecords implements ServletContextAware {
}
sql_query=Tools.replaceAll(sql_query,"${" + vn + "}", getSQLValue(vt, val));
}
sql_query = Tools.replaceAll(sql_query,"${_user_id}", (String) user.id); //Set current user id in sql query.
if(user.id==null) sql_query = Tools.replaceAll(sql_query,"${_user_id}", "null");
else sql_query = Tools.replaceAll(sql_query,"${_user_id}", (String) user.id);
logger.info("sql_query = " + sql_query);
@ -642,7 +653,8 @@ public class DBMSRecords implements ServletContextAware {
String xmlstring = "<metadata fn=\"2\"><type n=\"" + typename + "\" id=\"" + obj_id + "\"></type></metadata>";
result=xmlstring;
logger.info("xmlstring = " + xmlstring);
httpHeaders.setContentType(MediaType.APPLICATION_XML);
//logger.info("xmlstring = " + xmlstring);
}
rs.close();
stt.close();
@ -715,7 +727,8 @@ public class DBMSRecords implements ServletContextAware {
} */
sql_query = Tools.replaceAll(sql_query,"${id}", getSQLValue("string", obj_id)); //string а не i4 так как некоторые таблицы с uuid
sql_query = Tools.replaceAll(sql_query,"${_user_id}", (String) user.id); //Set current user id in sql query.
if(user.id==null) sql_query = Tools.replaceAll(sql_query,"${_user_id}", "null");
else sql_query = Tools.replaceAll(sql_query,"${_user_id}", (String) user.id);
//logger.info("sql_query = " + sql_query);
@ -732,6 +745,7 @@ public class DBMSRecords implements ServletContextAware {
String xmlstring = "<metadata fn=\"3\"><type n=\"" + typename + "\" id=\"" + obj_id + "\"></type></metadata>";
result=xmlstring;
httpHeaders.setContentType(MediaType.APPLICATION_XML);
//logger.info("xmlstring = " + xmlstring);
}
rs.close();
@ -830,7 +844,8 @@ public class DBMSRecords implements ServletContextAware {
}
nextnode = nextnode.getNextSibling();
}
sql_query = Tools.replaceAll(sql_query,"${_user_id}", (String) user.id); //Set current user id in sql query.
if(user.id==null) sql_query = Tools.replaceAll(sql_query,"${_user_id}", "null");
else sql_query = Tools.replaceAll(sql_query,"${_user_id}", (String) user.id);
//logger.info("sql_query = " + sql_query);
@ -930,8 +945,8 @@ public class DBMSRecords implements ServletContextAware {
xmlstring += "</type></metadata>\n";
result=xmlstring;*/
JSONObject json = new JSONObject();
json.put("errorCode",0);
json.put("errorMessage","");
json.put("error_code",0);
json.put("error_message","");
json.put("fn",fn);
json.put("n",typename);
json.put("pc",pagecount);
@ -1010,6 +1025,7 @@ public class DBMSRecords implements ServletContextAware {
String sql_query = "";
String typename = "";
String idname = "";
String id = "";
Node nTypeR = null;
if (doc != null) {
@ -1024,7 +1040,8 @@ public class DBMSRecords implements ServletContextAware {
if (nodeList.getLength() > 0) {
nTypeR = nodeList.item(0);
typename = "" + nTypeR.getAttributes().getNamedItem("n").getNodeValue();
idname = "" + nTypeR.getAttributes().getNamedItem("id").getNodeValue();
idname = "" + nTypeR.getAttributes().getNamedItem("ObjectID").getNodeValue();
id = "" + nTypeR.getAttributes().getNamedItem("id").getNodeValue();
}
}
@ -1044,8 +1061,9 @@ public class DBMSRecords implements ServletContextAware {
logger.info(ex.getMessage());
}
sql_query = Tools.replaceAll(sql_query,"${id}", getSQLValue("string", idname)); //Set current record id into sql query.
sql_query = Tools.replaceAll(sql_query,"${_user_id}", (String) user.id); //Set current user id into sql query.
sql_query = Tools.replaceAll(sql_query,"${"+idname+"}", getSQLValue("string", id));
if(user.id==null) sql_query = Tools.replaceAll(sql_query,"${_user_id}", "null");
else sql_query = Tools.replaceAll(sql_query,"${_user_id}", (String) user.id);
//logger.info("sql_query = " + sql_query);
@ -1058,7 +1076,7 @@ public class DBMSRecords implements ServletContextAware {
if (rs != null) {
//Выбираем данные и строим XML для отправки клиенту
String xmlstring = "";
xmlstring += "<metadata fn=\"" + fn + "\"><type n=\"" + typename + "\" id=\"" + idname + "\"><properties>\n";
xmlstring += "<metadata fn=\"" + fn + "\"><type n=\"" + typename + "\" id=\"" + id + "\"><properties>\n";
NodeList nodeList=null;
try {
nodeList = (NodeList) xpath.compile("properties/prop").evaluate(nTypeS, XPathConstants.NODESET);
@ -1085,6 +1103,7 @@ public class DBMSRecords implements ServletContextAware {
xmlstring += "</properties></type></metadata>\n";
result=xmlstring;
httpHeaders.setContentType(MediaType.APPLICATION_XML);
//logger.info("xmlstring = " + xmlstring);
}
rs.close();
@ -1193,7 +1212,8 @@ public class DBMSRecords implements ServletContextAware {
nextnode = nextnode.getNextSibling();
}
sql_query = Tools.replaceAll(sql_query,"${_user_id}", (String) user.id); //Set current user id in sql query.
if(user.id==null) sql_query = Tools.replaceAll(sql_query,"${_user_id}", "null");
else sql_query = Tools.replaceAll(sql_query,"${_user_id}", (String) user.id);
//logger.info("sql_query = " + sql_query);
@ -1220,6 +1240,7 @@ public class DBMSRecords implements ServletContextAware {
xmlstring += "</type></metadata>\n";
result=xmlstring;
httpHeaders.setContentType(MediaType.APPLICATION_XML);
//logger.info("xmlstring = " + xmlstring);
}
rs.close();
@ -1566,7 +1587,7 @@ public class DBMSRecords implements ServletContextAware {
}
result=xmlstring;
//logger.info("xmlstring = " + xmlstring);
httpHeaders.setContentType(MediaType.APPLICATION_XML);
} else if (fn != null && fn.equals("8")) {
//Select information about the current user
@ -1695,7 +1716,8 @@ public class DBMSRecords implements ServletContextAware {
}
nextnode = nextnode.getNextSibling();
}
sql_query = Tools.replaceAll(sql_query,"${_user_id}", (String) user.id); //Set current user id in sql query.
if(user.id==null) sql_query = Tools.replaceAll(sql_query,"${_user_id}", "null");
else sql_query = Tools.replaceAll(sql_query,"${_user_id}", (String) user.id);
//logger.info("sql_query2 = " + sql_query);
@ -1890,14 +1912,10 @@ public class DBMSRecords implements ServletContextAware {
result=sendError(1,"Unknown function \"" + fn + "\" !");
error=true;
}
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
try { if(conn!=null) conn.close(); } catch (SQLException e) { throw new RuntimeException(e); }
//return body content
return result;
return new ResponseEntity<String>(result, httpHeaders, HttpStatus.OK);
}
@Override
@ -2064,7 +2082,7 @@ public class DBMSRecords implements ServletContextAware {
}
}
if(conn!=null){try{conn.close();}catch(SQLException ex){}}
try { if(conn!=null) conn.close(); } catch (SQLException e) { throw new RuntimeException(e); }
if(file!=null) {
response.setContentType("application/octet-stream");