add postData to get data

This commit is contained in:
2024-12-08 15:24:40 +06:00
parent 91e8b21d39
commit ddcb146952
9 changed files with 585 additions and 393 deletions

View File

@ -1,4 +1,4 @@
package dbms; //package com.geovizor.monitoring; //Главная 2
package dbms; //package org.ccalm.monitoring; //Главная 2
import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
@ -12,6 +12,13 @@ import java.io.OutputStreamWriter;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.X509EncodedKeySpec;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
@ -49,23 +56,26 @@ import javax.xml.xpath.XPathFactory;
//import org.apache.commons.fileupload.disk.DiskFileItemFactory;
//import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.MarkerManager;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
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.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
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.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.ServletContextAware;
import org.springframework.web.multipart.MultipartFile;
import org.w3c.dom.CharacterData;
@ -79,25 +89,31 @@ import org.w3c.dom.ls.LSSerializer;
import org.xml.sax.InputSource;
import tctable.Tools;
import tools.DBTools;
import tools.EmailUtility;
import tools.Translation;
import tools.User;
@Controller
@SessionAttributes( { "user" }) //Сесионный объект
public class DBMSRecords implements ServletContextAware {
//private static final Logger logger = LoggerFactory.getLogger(Translation.class);
private static final Logger logger = LoggerFactory.getLogger(DBMSRecords.class);
private static final Logger logger = LogManager.getLogger(DBMSRecords.class);
private final NamedParameterJdbcTemplate jdbcTemplate;
private ServletContext context;
private Properties m_props=null;
private String m_props_loc="";
//If not created object "user", create him.
@ModelAttribute("user")
public User populatePerson() {
return new User("none");
@Value("${public.key}")
String key_a_txt="";
@Autowired
private Environment env;
@Autowired
public DBMSRecords(NamedParameterJdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
@Override
@ -105,27 +121,68 @@ public class DBMSRecords implements ServletContextAware {
this.context=servletContext;
}
public String sendError(int code, String message) {
public String sendError(int code, String message,String marker) {
JSONObject json = new JSONObject();
json.put("error_code",code);
json.put("error_message",message);
json.put("error_marker",marker);
return json.toString();
}
//Документация по @RequestBody http://javastudy.ru/spring-mvc/json-xml/ application/xml
@RequestMapping(value = "/api/dbms/v09/records.xyz",method = {RequestMethod.POST,RequestMethod.GET}) //,produces = "text/plain; charset=utf-8"
@ResponseBody
public ResponseEntity<String> ajaxRecords(@ModelAttribute User user, @RequestBody(required = false) byte[] reqData, @RequestParam(required=false,name="lng") String language_id) {
private PublicKey getPublicKey(){
try {
byte[] keyBytes = Base64.getDecoder().decode(key_a_txt);
X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PublicKey key = keyFactory.generatePublic(spec);
return key;
} catch (Exception e) {
logger.error(e);
}
return null;
}
//Документация по @RequestBody http://javastudy.ru/spring-mvc/json-xml/ application/xml
//Обычно мантирую в: /api/dbms/v09/
@RequestMapping(value = "/dbms",method = {RequestMethod.POST,RequestMethod.GET}) //,produces = "text/plain; charset=utf-8"
@ResponseBody
public ResponseEntity<String> ajaxRecords(
@ModelAttribute User user,
@RequestBody(required = false) byte[] reqData,
@CookieValue(value = "jwt_a", defaultValue = "") String jwt_a,
@RequestParam(required=false,name="lng") String language_id
) {
final HttpHeaders httpHeaders= new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
String result=sendError(10000,"Request_not_processed",null);
if(user.id==null || user.id.equals("null")) { //
if (jwt_a.equals("") || Tools.countOccurrences(jwt_a, '.') != 2) {
result = sendError(10000, "Please_send_a_valid_JWT_token",null);
return new ResponseEntity<String>(result, httpHeaders, HttpStatus.OK);
}
//Проверяю подпись токена
Jws<Claims> claims = null;
PublicKey key_a = getPublicKey(); //SecretKey key_a = new SecretKeySpec(Base64.getDecoder().decode(env.getProperty("access.key")), "HmacSHA256");
try {
claims = Jwts.parserBuilder()
.setSigningKey(key_a)
.build()
.parseClaimsJws(jwt_a);
} catch (Exception e) {
return new ResponseEntity<String>("JWT_token_verification_error", httpHeaders, HttpStatus.OK);
}
user.id = claims.getBody().get("user_id").toString();
}
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);
boolean error=false;
String result=sendError(1,"Request not processed!");
result=sendError(10000,"Request not processed!",null);
if(reqData==null)
return new ResponseEntity<String>(result, httpHeaders, HttpStatus.OK);
@ -141,20 +198,18 @@ public class DBMSRecords implements ServletContextAware {
String mail_port = "";
String mail_login = "";
String mail_password = "";
Properties prop = new Properties();
try {
prop.load(new FileInputStream("application.properties")); // load a properties file
db_url = prop.getProperty("spring.datasource.url");
db_login = prop.getProperty("spring.datasource.username");
db_password = prop.getProperty("spring.datasource.password");
data_dir = prop.getProperty("data.dir");
mail_host = prop.getProperty("mail.host");
mail_port = prop.getProperty("mail.port");
mail_login = prop.getProperty("mail.login");
mail_password = prop.getProperty("mail.password");
db_url = env.getProperty("spring.datasource.url");
db_login = env.getProperty("spring.datasource.username");
db_password = env.getProperty("spring.datasource.password");
data_dir = env.getProperty("data.dir");
mail_host = env.getProperty("mail.host");
mail_port = env.getProperty("mail.port");
mail_login = env.getProperty("mail.login");
mail_password = env.getProperty("mail.password");
} catch (Exception e) {
e.printStackTrace();
logger.error("Error load application.properties",e);
logger.error("Error load org_ccalm_main.properties",e);
}
String jspPath = context.getRealPath("/");
@ -176,7 +231,7 @@ public class DBMSRecords implements ServletContextAware {
} catch (Exception ex) {
logger.info(ex.getMessage());
//return "<metadata fn=\"-1\"><![CDATA[Parsing request error!]]></metadata>";
return new ResponseEntity<String>(sendError(1,"Parsing request error!"), httpHeaders, HttpStatus.OK);
return new ResponseEntity<String>(sendError(10000,"Parsing request error!",null), httpHeaders, HttpStatus.OK);
}
if (doc != null) {
@ -193,15 +248,17 @@ public class DBMSRecords implements ServletContextAware {
Class.forName("org.postgresql.Driver");
conn = DriverManager.getConnection(db_url, db_login, db_password);
if (conn != null) {
logger.info("Connect is OK!");
String uuid = UUID.randomUUID().toString();
Marker marker = MarkerManager.getMarker(uuid);
logger.info(marker,"Connect is OK!");
} else {
error=true;
result=sendError(1,"An error occurred while connecting to the database!");
result=sendError(10000,"An error occurred while connecting to the database!",null);
}
} catch (Exception ex) {
logger.info(ex.getMessage());
error=true;
result=sendError(1,"An error occurred while connecting to the database!");
result=sendError(10000,"An error occurred while connecting to the database!",null);
}
try {
@ -212,7 +269,7 @@ public class DBMSRecords implements ServletContextAware {
} catch (SQLException ex) {
logger.info(ex.getMessage());
error=true;
result=sendError(1,"An set TYPE_SCROLL_SENSITIVE!");
result=sendError(10000,"An set TYPE_SCROLL_SENSITIVE!",null);
}
//response.getWriter().append("fn="+fn);
@ -286,7 +343,7 @@ public class DBMSRecords implements ServletContextAware {
allow = "1";
try {
stt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
sql_query = "select main.p_getAccess(" + user.id + ", 'Select_" + name + "') as acc;";
sql_query = "select main.get_Access(" + user.id + ", 'Select_" + name + "') as acc;";
rs = stt.executeQuery(sql_query);
if (rs != null) {
try {
@ -302,7 +359,7 @@ public class DBMSRecords implements ServletContextAware {
}
} catch (SQLException ex) {
logger.info(ex.getMessage() + " SQL=" + sql_query);
result=sendError(1,"Error: " + ex.getMessage());
result=sendError(10000,"Error: " + ex.getMessage(),null);
error=true;
}finally {
if(rs!=null) try{rs.close();}catch(SQLException ex){}
@ -314,7 +371,7 @@ public class DBMSRecords implements ServletContextAware {
allow = "1";
try {
stt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = stt.executeQuery("select main.p_getAccess(" + user.id + ", 'Insert_" + name + "') as acc;");
rs = stt.executeQuery("select main.get_Access(" + user.id + ", 'Insert_" + name + "') as acc;");
if (rs != null) {
try {
if (rs.next())
@ -329,7 +386,7 @@ public class DBMSRecords implements ServletContextAware {
}
} catch (SQLException ex) {
logger.info(ex.getMessage());
result=sendError(1,"Error: " + ex.getMessage());
result=sendError(10000,"Error: " + ex.getMessage(),null);
error=true;
}finally {
if(rs!=null) try{rs.close();}catch(SQLException ex){}
@ -341,7 +398,7 @@ public class DBMSRecords implements ServletContextAware {
allow = "1";
try {
stt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = stt.executeQuery("select main.p_getAccess(" + user.id + ", 'Update_" + name + "') as acc;");
rs = stt.executeQuery("select main.get_Access(" + user.id + ", 'Update_" + name + "') as acc;");
if (rs != null) {
try {
if (rs.next())
@ -356,7 +413,7 @@ public class DBMSRecords implements ServletContextAware {
}
} catch (SQLException ex) {
logger.info(ex.getMessage());
result=sendError(1,"Error: " + ex.getMessage());
result=sendError(10000,"Error: " + ex.getMessage(),null);
error=true;
}finally {
if(rs!=null) try{rs.close();}catch(SQLException ex){}
@ -368,7 +425,7 @@ public class DBMSRecords implements ServletContextAware {
allow = "1";
try {
stt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = stt.executeQuery("select main.p_getAccess(" + user.id + ", 'Delete_" + name + "') as acc;");
rs = stt.executeQuery("select main.get_Access(" + user.id + ", 'Delete_" + name + "') as acc;");
if (rs != null) {
try {
if (rs.next())
@ -383,7 +440,7 @@ public class DBMSRecords implements ServletContextAware {
}
} catch (SQLException ex) {
logger.info(ex.getMessage());
result=sendError(1,"Error: " + ex.getMessage());
result=sendError(10000,"Error: " + ex.getMessage(),null);
error=true;
}finally {
if(rs!=null) try{rs.close();}catch(SQLException ex){}
@ -480,7 +537,7 @@ public class DBMSRecords implements ServletContextAware {
}
}
sql_query = Tools.replaceAll(sql_query,"${" + vn + "}", getSQLValue(vt, val));
sql_query = Tools.replaceAll(sql_query,"${" + vn + "}", DBTools.getSQLValue(vt, val));
}
if(user.id==null) sql_query = Tools.replaceAll(sql_query,"${_user_id}", "null");
@ -509,7 +566,7 @@ public class DBMSRecords implements ServletContextAware {
rs=null;
} catch (SQLException ex) {
logger.info(ex.getMessage());
result=sendError(1,"Error: " + ex.getMessage()+"\n\nSQL query: " + sql_query);
result=sendError(10000,"Error: " + ex.getMessage()+"\n\nSQL query: " + sql_query,null);
error=true;
}
}
@ -594,7 +651,7 @@ public class DBMSRecords implements ServletContextAware {
}
}
}
sql_query=Tools.replaceAll(sql_query,"${" + vn + "}", getSQLValue(vt, val));
sql_query=Tools.replaceAll(sql_query,"${" + vn + "}", DBTools.getSQLValue(vt, val));
}
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);
@ -621,7 +678,7 @@ public class DBMSRecords implements ServletContextAware {
stt.close();
} catch (SQLException ex) {
logger.info(ex.getMessage());
result=sendError(1,"Error: " + ex.getMessage()+"\n\nSQL query: " + sql_query);
result=sendError(10000,"Error: " + ex.getMessage()+"\n\nSQL query: " + sql_query,null);
error=true;
}
}
@ -683,10 +740,10 @@ public class DBMSRecords implements ServletContextAware {
vt=nodeList.item(0).getAttributes().getNamedItem("vt").getNodeValue();
}
sql_query=Tools.replaceAll(sql_query,"${"+vn+"}",getSQLValue(vt,val));
sql_query=Tools.replaceAll(sql_query,"${"+vn+"}",DBTools.getSQLValue(vt,val));
} */
sql_query = Tools.replaceAll(sql_query,"${id}", getSQLValue("string", obj_id)); //string а не i4 так как некоторые таблицы с uuid
sql_query = Tools.replaceAll(sql_query,"${id}", DBTools.getSQLValue("string", obj_id)); //string а не i4 так как некоторые таблицы с uuid
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);
@ -711,7 +768,7 @@ public class DBMSRecords implements ServletContextAware {
stt.close();
} catch (SQLException ex) {
logger.info(ex.getMessage());
result=sendError(1,"Error: " + ex.getMessage()+"\n\nSQL query: " + sql_query);
result=sendError(10000,"Error: " + ex.getMessage()+"\n\nSQL query: " + sql_query,null);
error=true;
}
@ -792,7 +849,7 @@ public class DBMSRecords implements ServletContextAware {
String vt = nextnode.getAttributes().getNamedItem("vt").getNodeValue();
String val = getCharacterDataFromElement((Element) nextnode);
val = getSQLValue(vt, val);
val = DBTools.getSQLValue(vt, val);
sql_query = Tools.replaceAll(sql_query,"${" + vn + "}", val);
} catch (Exception ex) {
@ -818,7 +875,7 @@ public class DBMSRecords implements ServletContextAware {
}
} catch (Exception ex) {
logger.info(ex.getMessage());
result=sendError(1,"Error: " + ex.getMessage()+"\n\nSQL query: " + sql_query);
result=sendError(10000,"Error: " + ex.getMessage()+"\n\nSQL query: " + sql_query,null);
error=true;
}
pagecount = (int) Math.ceil((double) pagecount / (double) rowspagecount);
@ -969,9 +1026,11 @@ public class DBMSRecords implements ServletContextAware {
stmt=null;
} catch (SQLException ex) {
logger.info(ex.getMessage());
String uuid = UUID.randomUUID().toString();
Marker marker = MarkerManager.getMarker(uuid);
logger.error(marker,ex.getMessage(),ex);
ex.printStackTrace();
result=sendError(1,"Error: " + ex.getMessage()+"\n\nSQL query: " + sql_query);
result=sendError(10000,trt(conn,"Error_executing_SQL_query",user),uuid);
error=true;
}
}
@ -1016,7 +1075,7 @@ public class DBMSRecords implements ServletContextAware {
logger.info(ex.getMessage());
}
sql_query = Tools.replaceAll(sql_query,"${"+idname+"}", getSQLValue("string", id));
sql_query = Tools.replaceAll(sql_query,"${"+idname+"}", DBTools.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);
@ -1066,7 +1125,7 @@ public class DBMSRecords implements ServletContextAware {
stt=null;
} catch (SQLException ex) {
logger.info(ex.getMessage());
result=sendError(1,"Error: " + ex.getMessage()+"\n\nSQL query: " + sql_query);
result=sendError(10000,"Error: " + ex.getMessage()+"\n\nSQL query: " + sql_query,null);
error=true;
}
}
@ -1154,7 +1213,7 @@ public class DBMSRecords implements ServletContextAware {
String vt = nextnode.getAttributes().getNamedItem("vt").getNodeValue();
String val = getCharacterDataFromElement((Element) nextnode);
val = getSQLValue(vt, val);
val = DBTools.getSQLValue(vt, val);
sql_query = Tools.replaceAll(sql_query,"${" + vn + "}", val);
} catch (Exception ex) {
@ -1201,14 +1260,14 @@ public class DBMSRecords implements ServletContextAware {
stt=null;
} catch (SQLException ex) {
logger.info(ex.getMessage());
result=sendError(1,"Error: " + ex.getMessage()+"\n\nSQL query: " + sql_query);
result=sendError(10000,"Error: " + ex.getMessage()+"\n\nSQL query: " + sql_query,null);
error=true;
}
} else {
result=sendError(1,"Could not find the requested node!");
result=sendError(10000,"Could not find the requested node!",null);
error=true;
}
}
@ -1273,7 +1332,7 @@ public class DBMSRecords implements ServletContextAware {
} catch (SQLException ex) {
logger.info(ex.getMessage());
//xmlstring = "<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "]]></metadata>";
xmlstring=sendError(1,"Error: " + ex.getMessage());
xmlstring=sendError(10000,"Error: " + ex.getMessage(),null);
error=true;
}
@ -1310,14 +1369,14 @@ public class DBMSRecords implements ServletContextAware {
} catch (SQLException ex) {
logger.info(ex.getMessage());
//xmlstring = "<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "]]></metadata>";
xmlstring=sendError(1,"Error: " + ex.getMessage());
xmlstring=sendError(10000,"Error: " + ex.getMessage(),null);
}
}
xmlstring = "<metadata fn=\"7\"><![CDATA[" + answer + "]]></metadata>";
} else {
//xmlstring = "<metadata fn=\"-1\"><![CDATA[This email address was not registered!]]></metadata>";
xmlstring=sendError(1,"This email address was not registered!");
xmlstring=sendError(10000,"This email address was not registered!",null);
}
} else if (cmd.equals("1")) //Logout
@ -1335,7 +1394,7 @@ public class DBMSRecords implements ServletContextAware {
} catch (SQLException ex) {
logger.info(ex.getMessage());
//xmlstring = "<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "\n\nSQL query: " + sql_query + "]]></metadata>";
xmlstring=sendError(1,"Error: " + ex.getMessage() + "\n\nSQL query: " + sql_query);
xmlstring=sendError(10000,"Error: " + ex.getMessage() + "\n\nSQL query: " + sql_query,null);
error=true;
}
@ -1379,17 +1438,17 @@ public class DBMSRecords implements ServletContextAware {
}
String val;
val = getSQLValue("i4", user_id);
val = DBTools.getSQLValue("i4", user_id);
sql_query = Tools.replaceAll(sql_query,"${user_id}", val);
val = getSQLValue("string", login);
val = DBTools.getSQLValue("string", login);
sql_query = Tools.replaceAll(sql_query,"${login}", val);
val = getSQLValue("string", password);
val = DBTools.getSQLValue("string", password);
sql_query = Tools.replaceAll(sql_query,"${password}", val);
val = getSQLValue("string", hash);
val = DBTools.getSQLValue("string", hash);
sql_query = Tools.replaceAll(sql_query,"${hash}", val);
val = getSQLValue("string", ""/*request.getSession().getId()*/);
val = DBTools.getSQLValue("string", ""/*request.getSession().getId()*/);
sql_query = Tools.replaceAll(sql_query,"${sessionid}", val);
val = getSQLValue("string", ""/*request.getRemoteAddr()*/);
val = DBTools.getSQLValue("string", ""/*request.getRemoteAddr()*/);
sql_query = Tools.replaceAll(sql_query,"${ip}", val);
//logger.info("sql_query = " + sql_query);
@ -1419,7 +1478,7 @@ public class DBMSRecords implements ServletContextAware {
}else
{
//xmlstring = "<metadata fn=\"-1\"><![CDATA["+trt(conn,"Error_in_login_or_password",user)+"]]></metadata>";
xmlstring=sendError(1,trt(conn,"Error_in_login_or_password",user));
xmlstring=sendError(10000,trt(conn,"Error_in_login_or_password",user),null);
}
}
rs.close();
@ -1429,7 +1488,7 @@ public class DBMSRecords implements ServletContextAware {
} catch (SQLException ex) {
logger.info(ex.getMessage());
//xmlstring = "<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "\n\nSQL query: " + sql_query + "]]></metadata>";
xmlstring=sendError(1,"Error: " + ex.getMessage() + "\n\nSQL query: " + sql_query);
xmlstring=sendError(10000,"Error: " + ex.getMessage() + "\n\nSQL query: " + sql_query,null);
error=true;
}
@ -1443,7 +1502,7 @@ public class DBMSRecords implements ServletContextAware {
//Check exists user by email email
sql_query = "select id from main._users where email=LOWER(TRIM(${email}))";
val = getSQLValue("string", email);
val = DBTools.getSQLValue("string", email);
sql_query = Tools.replaceAll(sql_query,"${email}", val);
try {
Statement stt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
@ -1452,7 +1511,7 @@ public class DBMSRecords implements ServletContextAware {
try {
if (rs.next()) {
//xmlstring = "<metadata fn=\"-1\"><![CDATA["+trt(conn,"E_mail_already_exists_in_the_database",user)+"]]></metadata>";
xmlstring=sendError(1,trt(conn,"E_mail_already_exists_in_the_database",user));
xmlstring=sendError(10000,trt(conn,"E_mail_already_exists_in_the_database",user),null);
error=true;
}
} catch (SQLException ex) {
@ -1464,7 +1523,7 @@ public class DBMSRecords implements ServletContextAware {
} catch (SQLException ex) {
logger.info(ex.getMessage());
//xmlstring = "<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "]]></metadata>";
xmlstring=sendError(1,"Error: " + ex.getMessage());
xmlstring=sendError(10000,"Error: " + ex.getMessage(),null);
error=true;
}
@ -1472,21 +1531,21 @@ public class DBMSRecords implements ServletContextAware {
String newPass = getRandomString(8);
sql_query = "select * from main.p__Users_1(4,${country_id},${surname},${name},${company},${position},${phone},${email},${password});";
val = getSQLValue("i4", country_id);
val = DBTools.getSQLValue("i4", country_id);
sql_query = Tools.replaceAll(sql_query,"${country_id}", val);
val = getSQLValue("string", lastname);
val = DBTools.getSQLValue("string", lastname);
sql_query = Tools.replaceAll(sql_query,"${surname}", val);
val = getSQLValue("string", firstname);
val = DBTools.getSQLValue("string", firstname);
sql_query = Tools.replaceAll(sql_query,"${name}", val);
val = getSQLValue("string", company);
val = DBTools.getSQLValue("string", company);
sql_query = Tools.replaceAll(sql_query,"${company}", val);
val = getSQLValue("string", position);
val = DBTools.getSQLValue("string", position);
sql_query = Tools.replaceAll(sql_query,"${position}", val);
val = getSQLValue("string", phone);
val = DBTools.getSQLValue("string", phone);
sql_query = Tools.replaceAll(sql_query,"${phone}", val);
val = getSQLValue("string", email);
val = DBTools.getSQLValue("string", email);
sql_query = Tools.replaceAll(sql_query,"${email}", val);
val = getSQLValue("string", newPass);
val = DBTools.getSQLValue("string", newPass);
sql_query = Tools.replaceAll(sql_query,"${password}", val);
//logger.info("sql_query = " + sql_query);
@ -1530,7 +1589,7 @@ public class DBMSRecords implements ServletContextAware {
} catch (SQLException ex) {
logger.info(ex.getMessage());
//xmlstring = "<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "]]></metadata>";
xmlstring=sendError(1,"Error: " + ex.getMessage());
xmlstring=sendError(10000,"Error: " + ex.getMessage(),null);
error=true;
}
}
@ -1561,7 +1620,7 @@ public class DBMSRecords implements ServletContextAware {
stt=null;
} catch (SQLException ex) {
logger.info(ex.getMessage());
result=sendError(1,"Error: " + ex.getMessage());
result=sendError(10000,"Error: " + ex.getMessage(),null);
error=true;
}
@ -1656,7 +1715,7 @@ public class DBMSRecords implements ServletContextAware {
String vt = nextnode.getAttributes().getNamedItem("vt").getNodeValue();
String val = getCharacterDataFromElement((Element) nextnode);
val = getSQLValue(vt, val);
val = DBTools.getSQLValue(vt, val);
sql_query = Tools.replaceAll(sql_query,"${" + vn + "}", val);
} catch (Exception ex) {
@ -1742,7 +1801,7 @@ public class DBMSRecords implements ServletContextAware {
}
} catch (IOException ex) {
logger.info(ex.getMessage());
result=sendError(1,"Error: " + ex.getMessage());
result=sendError(10000,"Error: " + ex.getMessage(),null);
error=true;
} finally {
try {
@ -1760,7 +1819,7 @@ public class DBMSRecords implements ServletContextAware {
stt=null;
} catch (SQLException ex) {
logger.info(ex.getMessage());
result=sendError(1,"Error: " + ex.getMessage() + "\n\nSQL query: " + sql_query);
result=sendError(10000,"Error: " + ex.getMessage() + "\n\nSQL query: " + sql_query,null);
error=true;
}
}
@ -1857,7 +1916,7 @@ public class DBMSRecords implements ServletContextAware {
*/
} else {
result=sendError(1,"Unknown function \"" + fn + "\" !");
result=sendError(10000,"Unknown function \"" + fn + "\" !",null);
error=true;
}
@ -1878,15 +1937,13 @@ public class DBMSRecords implements ServletContextAware {
String db_url="";
String db_login="";
String db_password="";
Properties prop = new Properties();
try {
prop.load(new FileInputStream("application.properties")); // load a properties file
db_url = prop.getProperty("spring.datasource.url");
db_login = prop.getProperty("spring.datasource.username");
db_password = prop.getProperty("spring.datasource.password");
db_url = env.getProperty("spring.datasource.url");
db_login = env.getProperty("spring.datasource.username");
db_password = env.getProperty("spring.datasource.password");
} catch (Exception e) {
e.printStackTrace();
logger.error("Error load application.properties",e);
logger.error("Error load org_ccalm_main.properties",e);
}
@ -1895,7 +1952,9 @@ public class DBMSRecords implements ServletContextAware {
Class.forName("org.postgresql.Driver");
conn = DriverManager.getConnection(db_url, db_login, db_password);
if (conn != null) {
logger.info("Connect is OK!");
String uuid = UUID.randomUUID().toString();
Marker marker = MarkerManager.getMarker(uuid);
logger.info(marker,"Connect is OK!");
} else {
logger.info("An error occurred while connecting to the database!");
}
@ -1994,7 +2053,6 @@ public class DBMSRecords implements ServletContextAware {
}
}
@RequestMapping(value = "/upload", method = { RequestMethod.GET, RequestMethod.POST })
@ResponseBody
public String uploadFile(HttpServletResponse response,@RequestParam(required=false,name="file") MultipartFile file) {
@ -2002,13 +2060,11 @@ public class DBMSRecords implements ServletContextAware {
String result="";
String data_dir = "";
Properties prop = new Properties();
try {
prop.load(new FileInputStream("application.properties")); // load a properties file
data_dir = prop.getProperty("data.dir");
data_dir = env.getProperty("data.dir");
} catch (Exception e) {
e.printStackTrace();
logger.error("Error load application.properties",e);
logger.error("Error load org_ccalm_main.properties",e);
}
@ -2081,13 +2137,11 @@ public class DBMSRecords implements ServletContextAware {
public FileSystemResource sendReport(HttpServletResponse response,@RequestParam(required=true,name="file") String fileName) {
String data_dir = "";
Properties prop = new Properties();
try {
prop.load(new FileInputStream("application.properties")); // load a properties file
data_dir = prop.getProperty("data.dir");
data_dir = env.getProperty("data.dir");
} catch (Exception e) {
e.printStackTrace();
logger.error("Error load application.properties",e);
logger.error("Error load org_ccalm_main.properties",e);
}
File file = new File(data_dir + "temp" + File.separator + fileName);
@ -2106,43 +2160,6 @@ public class DBMSRecords implements ServletContextAware {
}
}
String getSQLValue(String t, String v) {
//if($t=='object' && (strtoupper($v)!='NULL' && gettype($v)=='string')) $t='string'; //Если id шники uuid
if (t.equals("object") || t.equals("uid")) {
if (v.equals(""))
v = "NULL";
} else if (t.equals("i4") || t.equals("integer")) {
if (v.equals(""))
v = "NULL";
} else if (t.equals("f8")) {
if (v.equals(""))
v = "NULL";
v = Tools.replaceAll(v,",", "."); //The decimal part: point.
} else if (t.equals("f4")) {
if (v.equals(""))
v = "NULL";
v = Tools.replaceAll(v,",", "."); //The decimal part: point.
} else if (t.equals("b")) {
if (v.equals(""))
v = "NULL";
else if (v.equals("1"))
v = "true";
else if (v.equals("0"))
v = "false";
} else if (t.equals("string") || t.equals("text") || t.equals("dateTime") || t.equals("date")) {
if (v.equals("")) {
v = "NULL";
} else {
v = Tools.replaceAll(v,"'", "''");
v = "'" + v + "'";
}
} else {
v = "'" + v + "'";
}
return v;
}
private String nodeToString(Node node) {
StringWriter sw = new StringWriter();
try {