Выборку метаданных вынес в отдельную функцию
This commit is contained in:
@ -11,20 +11,21 @@ issuer:
|
|||||||
|
|
||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
name: dbms
|
name: org_ccalm_dbms
|
||||||
datasource:
|
datasource:
|
||||||
url: jdbc:postgresql://91.201.214.156:5432/CCALM
|
url: jdbc:postgresql://91.201.214.156:5432/CCALM?ApplicationName=org_ccalm_dbms&ssl=true&sslmode=require&connectTimeout=10000&socketTimeout=10000
|
||||||
username: postgres
|
username: postgres
|
||||||
password: PasSecrKey1
|
password: 309A86FF65A78FB428F4E38DFE35F730
|
||||||
driver-class-name: org.postgresql.Driver
|
driver-class-name: org.postgresql.Driver
|
||||||
hikari:
|
hikari:
|
||||||
maximum-pool-size: 10
|
maximum-pool-size: 10
|
||||||
minimum-idle: 5
|
minimum-idle: 5
|
||||||
max-lifetime: 1700000
|
max-lifetime: 600000
|
||||||
idle-timeout: 600000
|
idle-timeout: 300000
|
||||||
connection-timeout: 30000
|
connection-timeout: 30000
|
||||||
connection-test-query: SELECT now()
|
connection-test-query: SELECT 1
|
||||||
validation-timeout: 60000
|
validation-timeout: 5000
|
||||||
|
validation-interval: 60000
|
||||||
redis:
|
redis:
|
||||||
host: 127.0.0.1
|
host: 127.0.0.1
|
||||||
port: 6379
|
port: 6379
|
||||||
@ -51,8 +52,8 @@ url:
|
|||||||
reset: http://127.0.0.1:8088/reset
|
reset: http://127.0.0.1:8088/reset
|
||||||
main: http://127.0.0.1:8088/
|
main: http://127.0.0.1:8088/
|
||||||
|
|
||||||
logging:
|
#logging:
|
||||||
level:
|
# level:
|
||||||
com:
|
# com:
|
||||||
zaxxer:
|
# zaxxer:
|
||||||
hikari: DEBUG
|
# hikari: DEBUG
|
||||||
|
|||||||
@ -19,14 +19,11 @@ import java.security.NoSuchAlgorithmException;
|
|||||||
import java.security.PublicKey;
|
import java.security.PublicKey;
|
||||||
import java.security.spec.InvalidKeySpecException;
|
import java.security.spec.InvalidKeySpecException;
|
||||||
import java.security.spec.X509EncodedKeySpec;
|
import java.security.spec.X509EncodedKeySpec;
|
||||||
import java.sql.Connection;
|
import java.sql.*;
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Statement;
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
//import java.util.Iterator;
|
//import java.util.Iterator;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.zip.CRC32;
|
import java.util.zip.CRC32;
|
||||||
import java.util.zip.Checksum;
|
import java.util.zip.Checksum;
|
||||||
|
|
||||||
@ -55,6 +52,7 @@ import javax.xml.xpath.XPathFactory;
|
|||||||
//import org.apache.commons.fileupload.FileItem;
|
//import org.apache.commons.fileupload.FileItem;
|
||||||
//import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
//import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
||||||
//import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
//import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||||
|
import models.MetadataNameModel;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.MarkerManager;
|
import org.apache.logging.log4j.MarkerManager;
|
||||||
@ -68,6 +66,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.core.io.FileSystemResource;
|
import org.springframework.core.io.FileSystemResource;
|
||||||
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
@ -142,11 +141,137 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Вместо fn="0"
|
||||||
|
@RequestMapping(value = "/metadata",method = {RequestMethod.POST,RequestMethod.GET}) //,produces = "text/plain; charset=utf-8"
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseEntity<String> getMetadata(
|
||||||
|
@RequestBody(required = false) byte[] reqData,
|
||||||
|
@CookieValue(value = "jwt_a", defaultValue = "") String jwt_a,
|
||||||
|
@CookieValue(value = "lng", defaultValue = "1") String language_id
|
||||||
|
) {
|
||||||
|
final HttpHeaders httpHeaders= new HttpHeaders();
|
||||||
|
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
String result=sendError(10000,"Request_not_processed",null);
|
||||||
|
|
||||||
|
if (jwt_a.equals("") || Tools.countOccurrences(jwt_a, '.') != 2) {
|
||||||
|
result = sendError(10000, "You_are_not_logged_in",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 user = new User();
|
||||||
|
user.id = claims.getBody().get("user_id").toString();
|
||||||
|
user.language_id = language_id;
|
||||||
|
|
||||||
|
result=sendError(10000,"Request not processed!",null);
|
||||||
|
if(reqData==null)
|
||||||
|
return new ResponseEntity<String>(result, httpHeaders, HttpStatus.OK);
|
||||||
|
InputStream body = new ByteArrayInputStream(reqData);
|
||||||
|
|
||||||
|
Document doc = null;
|
||||||
|
Element reqNode = null;
|
||||||
|
try {
|
||||||
|
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
||||||
|
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
||||||
|
doc = dBuilder.parse(body);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
logger.info(ex.getMessage());
|
||||||
|
return new ResponseEntity<String>(sendError(10000,"Parsing request error!",null), httpHeaders, HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (doc != null) {
|
||||||
|
reqNode = doc.getDocumentElement();
|
||||||
|
//fn = reqNode.getAttribute("fn"); //Номер функции
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get XML node from database and parse to DOM
|
||||||
|
javax.xml.xpath.XPathFactory xPathfactory = javax.xml.xpath.XPathFactory.newInstance();
|
||||||
|
XPath xpath = xPathfactory.newXPath();
|
||||||
|
XPathExpression expr=null;
|
||||||
|
|
||||||
|
String name = "";
|
||||||
|
//if (fn != null && fn.equals("0")) //Send metadata to client
|
||||||
|
if (doc != null) {
|
||||||
|
xPathfactory = XPathFactory.newInstance();
|
||||||
|
xpath = xPathfactory.newXPath();
|
||||||
|
try {
|
||||||
|
expr = xpath.compile("//metadata/type/@n");
|
||||||
|
name = "" + expr.evaluate(doc, XPathConstants.STRING);
|
||||||
|
} catch (XPathExpressionException ex) {
|
||||||
|
logger.info(ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String xml = "";
|
||||||
|
|
||||||
|
//Get XML node from database and parse to DOM
|
||||||
|
doc = parseString(getTypeStrNode2(name));
|
||||||
|
|
||||||
|
if (doc != null) {
|
||||||
|
doc.getDocumentElement().normalize(); //Del or concat text node
|
||||||
|
|
||||||
|
xml += "<metadata fn=\"0\">";
|
||||||
|
|
||||||
|
//Delete all child "sql-query" nodes.
|
||||||
|
XPathExpression exp=null;
|
||||||
|
NodeList nl=null;
|
||||||
|
try {
|
||||||
|
exp = xpath.compile("//sql-query");
|
||||||
|
nl = (NodeList) exp.evaluate(doc, XPathConstants.NODESET);
|
||||||
|
} catch (XPathExpressionException ex) {
|
||||||
|
logger.info(ex.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j = 0; j < nl.getLength(); j++) {
|
||||||
|
nl.item(j).getParentNode().removeChild(nl.item(j));
|
||||||
|
}
|
||||||
|
// XML Node Serialisation
|
||||||
|
DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation();
|
||||||
|
LSSerializer lsSerializer = domImplementation.createLSSerializer();
|
||||||
|
lsSerializer.getDomConfig().setParameter("xml-declaration", false);
|
||||||
|
|
||||||
|
//Set attributes to define access level (insert,update,selete,select).
|
||||||
|
String allow;
|
||||||
|
|
||||||
|
allow = getAccess(user.id,"Select_" + name);
|
||||||
|
doc.getDocumentElement().setAttribute("sel", allow);
|
||||||
|
|
||||||
|
allow = getAccess(user.id,"Insert_" + name);
|
||||||
|
doc.getDocumentElement().setAttribute("ins", allow);
|
||||||
|
|
||||||
|
allow = getAccess(user.id,"Update_" + name);
|
||||||
|
doc.getDocumentElement().setAttribute("upd", allow);
|
||||||
|
|
||||||
|
allow = getAccess(user.id,"Delete_" + name);
|
||||||
|
doc.getDocumentElement().setAttribute("del", allow);
|
||||||
|
|
||||||
|
xml += lsSerializer.writeToString(doc.getDocumentElement());
|
||||||
|
xml += "</metadata>";
|
||||||
|
} else {
|
||||||
|
xml += "<metadata fn=\"0\"></metadata>";
|
||||||
|
}
|
||||||
|
|
||||||
|
result=trts2(xml,user);
|
||||||
|
httpHeaders.setContentType(MediaType.APPLICATION_XML);
|
||||||
|
|
||||||
|
return new ResponseEntity<String>(result, httpHeaders, HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
//Документация по @RequestBody http://javastudy.ru/spring-mvc/json-xml/ application/xml
|
//Документация по @RequestBody http://javastudy.ru/spring-mvc/json-xml/ application/xml
|
||||||
//Обычно мантирую в: /api/dbms/v09/
|
//Обычно мантирую в: /api/dbms/v09/
|
||||||
@RequestMapping(value = "/dbms",method = {RequestMethod.POST,RequestMethod.GET}) //,produces = "text/plain; charset=utf-8"
|
@RequestMapping(value = "/dbms",method = {RequestMethod.POST,RequestMethod.GET}) //,produces = "text/plain; charset=utf-8"
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public ResponseEntity<String> ajaxRecords(
|
public ResponseEntity<String> ajaxRecords(
|
||||||
@ModelAttribute User user,
|
@ModelAttribute User user,
|
||||||
@RequestBody(required = false) byte[] reqData,
|
@RequestBody(required = false) byte[] reqData,
|
||||||
@CookieValue(value = "jwt_a", defaultValue = "") String jwt_a,
|
@CookieValue(value = "jwt_a", defaultValue = "") String jwt_a,
|
||||||
@ -154,7 +279,6 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
) {
|
) {
|
||||||
final HttpHeaders httpHeaders= new HttpHeaders();
|
final HttpHeaders httpHeaders= new HttpHeaders();
|
||||||
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
|
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
|
||||||
String result=sendError(10000,"Request_not_processed",null);
|
String result=sendError(10000,"Request_not_processed",null);
|
||||||
|
|
||||||
if(user.id==null || user.id.equals("null")) { //
|
if(user.id==null || user.id.equals("null")) { //
|
||||||
@ -177,12 +301,12 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(language_id!=null && !language_id.equals(""))
|
if(language_id!=null && !language_id.equals(""))
|
||||||
user.language_id=language_id;
|
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);
|
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;
|
boolean error=false;
|
||||||
result=sendError(10000,"Request not processed!",null);
|
result=sendError(10000,"Request not processed!",null);
|
||||||
if(reqData==null)
|
if(reqData==null)
|
||||||
return new ResponseEntity<String>(result, httpHeaders, HttpStatus.OK);
|
return new ResponseEntity<String>(result, httpHeaders, HttpStatus.OK);
|
||||||
|
|
||||||
@ -252,13 +376,13 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
Marker marker = MarkerManager.getMarker(uuid);
|
Marker marker = MarkerManager.getMarker(uuid);
|
||||||
logger.info(marker,"Connect is OK!");
|
logger.info(marker,"Connect is OK!");
|
||||||
} else {
|
} else {
|
||||||
error=true;
|
error=true;
|
||||||
result=sendError(10000,"An error occurred while connecting to the database!",null);
|
result=sendError(10000,"An error occurred while connecting to the database!",null);
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.info(ex.getMessage());
|
||||||
error=true;
|
error=true;
|
||||||
result=sendError(10000,"An error occurred while connecting to the database!",null);
|
result=sendError(10000,"An error occurred while connecting to the database!",null);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -523,17 +647,17 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
{
|
{
|
||||||
String srcPath = data_dir;//context.getInitParameter("file-upload");
|
String srcPath = data_dir;//context.getInitParameter("file-upload");
|
||||||
String destPath = nodeList.item(0).getAttributes().getNamedItem("path").getNodeValue();
|
String destPath = nodeList.item(0).getAttributes().getNamedItem("path").getNodeValue();
|
||||||
File srcFile = new File(srcPath+val); //Upload folder
|
File srcFile = new File(srcPath+val); //Upload folder
|
||||||
if(srcFile.isFile())
|
if(srcFile.isFile())
|
||||||
{
|
{
|
||||||
File destFile = new File(destPath+val); //Foldef from metadata.xml
|
File destFile = new File(destPath+val); //Foldef from metadata.xml
|
||||||
try {
|
try {
|
||||||
FileUtils.copyFile(srcFile, destFile);
|
FileUtils.copyFile(srcFile, destFile);
|
||||||
FileUtils.forceDelete(srcFile);
|
FileUtils.forceDelete(srcFile);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.info(ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -637,18 +761,18 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
{
|
{
|
||||||
String srcPath = data_dir;//context.getInitParameter("file-upload");
|
String srcPath = data_dir;//context.getInitParameter("file-upload");
|
||||||
String destPath = nodeList.item(0).getAttributes().getNamedItem("path").getNodeValue();
|
String destPath = nodeList.item(0).getAttributes().getNamedItem("path").getNodeValue();
|
||||||
File srcFile = new File(srcPath+val); //Upload folder
|
File srcFile = new File(srcPath+val); //Upload folder
|
||||||
if(srcFile.isFile())
|
if(srcFile.isFile())
|
||||||
{
|
{
|
||||||
File destFile = new File(destPath+val); //Foldef from metadata.xml
|
File destFile = new File(destPath+val); //Foldef from metadata.xml
|
||||||
try {
|
try {
|
||||||
FileUtils.copyFile(srcFile, destFile);
|
FileUtils.copyFile(srcFile, destFile);
|
||||||
FileUtils.forceDelete(srcFile);
|
FileUtils.forceDelete(srcFile);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.info(ex.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sql_query=Tools.replaceAll(sql_query,"${" + vn + "}", DBTools.getSQLValue(vt, val));
|
sql_query=Tools.replaceAll(sql_query,"${" + vn + "}", DBTools.getSQLValue(vt, val));
|
||||||
@ -1528,72 +1652,72 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!error) {
|
if(!error) {
|
||||||
String newPass = getRandomString(8);
|
String newPass = getRandomString(8);
|
||||||
sql_query = "select * from main.p__Users_1(4,${country_id},${surname},${name},${company},${position},${phone},${email},${password});";
|
sql_query = "select * from main.p__Users_1(4,${country_id},${surname},${name},${company},${position},${phone},${email},${password});";
|
||||||
|
|
||||||
val = DBTools.getSQLValue("i4", country_id);
|
val = DBTools.getSQLValue("i4", country_id);
|
||||||
sql_query = Tools.replaceAll(sql_query,"${country_id}", val);
|
sql_query = Tools.replaceAll(sql_query,"${country_id}", val);
|
||||||
val = DBTools.getSQLValue("string", lastname);
|
val = DBTools.getSQLValue("string", lastname);
|
||||||
sql_query = Tools.replaceAll(sql_query,"${surname}", val);
|
sql_query = Tools.replaceAll(sql_query,"${surname}", val);
|
||||||
val = DBTools.getSQLValue("string", firstname);
|
val = DBTools.getSQLValue("string", firstname);
|
||||||
sql_query = Tools.replaceAll(sql_query,"${name}", val);
|
sql_query = Tools.replaceAll(sql_query,"${name}", val);
|
||||||
val = DBTools.getSQLValue("string", company);
|
val = DBTools.getSQLValue("string", company);
|
||||||
sql_query = Tools.replaceAll(sql_query,"${company}", val);
|
sql_query = Tools.replaceAll(sql_query,"${company}", val);
|
||||||
val = DBTools.getSQLValue("string", position);
|
val = DBTools.getSQLValue("string", position);
|
||||||
sql_query = Tools.replaceAll(sql_query,"${position}", val);
|
sql_query = Tools.replaceAll(sql_query,"${position}", val);
|
||||||
val = DBTools.getSQLValue("string", phone);
|
val = DBTools.getSQLValue("string", phone);
|
||||||
sql_query = Tools.replaceAll(sql_query,"${phone}", val);
|
sql_query = Tools.replaceAll(sql_query,"${phone}", val);
|
||||||
val = DBTools.getSQLValue("string", email);
|
val = DBTools.getSQLValue("string", email);
|
||||||
sql_query = Tools.replaceAll(sql_query,"${email}", val);
|
sql_query = Tools.replaceAll(sql_query,"${email}", val);
|
||||||
val = DBTools.getSQLValue("string", newPass);
|
val = DBTools.getSQLValue("string", newPass);
|
||||||
sql_query = Tools.replaceAll(sql_query,"${password}", val);
|
sql_query = Tools.replaceAll(sql_query,"${password}", val);
|
||||||
|
|
||||||
//logger.info("sql_query = " + sql_query);
|
//logger.info("sql_query = " + sql_query);
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Statement stt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
Statement stt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||||
ResultSet rs = stt.executeQuery(sql_query);
|
ResultSet rs = stt.executeQuery(sql_query);
|
||||||
if (rs != null) {
|
if (rs != null) {
|
||||||
try {
|
try {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
xmlstring = "<metadata fn=\"7\"><cmd><![CDATA[4]]></cmd><![CDATA[1]]></metadata>";
|
xmlstring = "<metadata fn=\"7\"><cmd><![CDATA[4]]></cmd><![CDATA[1]]></metadata>";
|
||||||
|
|
||||||
//Отправляем пароль на Email
|
//Отправляем пароль на Email
|
||||||
String recipient = email;
|
String recipient = email;
|
||||||
String subject = "Password for new user on http://www.ccalm.org";
|
String subject = "Password for new user on http://www.ccalm.org";
|
||||||
String content = "Login is: "+ email.toLowerCase()+"\n<br> Password: <b>" + newPass+"</b>";
|
String content = "Login is: "+ email.toLowerCase()+"\n<br> Password: <b>" + newPass+"</b>";
|
||||||
content += "<br><br>Sincerely, the administration of ccalm.org.";
|
content += "<br><br>Sincerely, the administration of ccalm.org.";
|
||||||
|
|
||||||
|
//String answer = "";
|
||||||
|
try {
|
||||||
|
EmailUtility.sendEmail(mail_host, mail_port, mail_login, mail_password, recipient, subject, content);
|
||||||
|
//answer = "New password was sent successfully on \"" + recipient + "\".\nIf there is no email then check the spam folder.";
|
||||||
|
} catch (Exception ex) {
|
||||||
|
logger.info(ex.getMessage());
|
||||||
|
//answer = "There were an error: " + ex.getMessage();
|
||||||
|
} finally {
|
||||||
|
//request.setAttribute("Message", resultMessage);
|
||||||
|
//context.getRequestDispatcher("/Result.jsp").forward(request, response);
|
||||||
|
}
|
||||||
|
|
||||||
//String answer = "";
|
|
||||||
try {
|
|
||||||
EmailUtility.sendEmail(mail_host, mail_port, mail_login, mail_password, recipient, subject, content);
|
|
||||||
//answer = "New password was sent successfully on \"" + recipient + "\".\nIf there is no email then check the spam folder.";
|
|
||||||
} catch (Exception ex) {
|
|
||||||
logger.info(ex.getMessage());
|
|
||||||
//answer = "There were an error: " + ex.getMessage();
|
|
||||||
} finally {
|
|
||||||
//request.setAttribute("Message", resultMessage);
|
|
||||||
//context.getRequestDispatcher("/Result.jsp").forward(request, response);
|
|
||||||
}
|
}
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
logger.info(ex.getMessage());
|
||||||
}
|
}
|
||||||
} catch (SQLException ex) {
|
|
||||||
logger.info(ex.getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
rs.close();
|
||||||
rs.close();
|
stt.close();
|
||||||
stt.close();
|
rs=null;
|
||||||
rs=null;
|
stt=null;
|
||||||
stt=null;
|
} catch (SQLException ex) {
|
||||||
} catch (SQLException ex) {
|
logger.info(ex.getMessage());
|
||||||
logger.info(ex.getMessage());
|
|
||||||
//xmlstring = "<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "]]></metadata>";
|
//xmlstring = "<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "]]></metadata>";
|
||||||
xmlstring=sendError(10000,"Error: " + ex.getMessage(),null);
|
xmlstring=sendError(10000,"Error: " + ex.getMessage(),null);
|
||||||
error=true;
|
error=true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
result=xmlstring;
|
result=xmlstring;
|
||||||
httpHeaders.setContentType(MediaType.APPLICATION_XML);
|
httpHeaders.setContentType(MediaType.APPLICATION_XML);
|
||||||
@ -1923,7 +2047,7 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
try { if(conn!=null) conn.close(); } catch (SQLException e) { throw new RuntimeException(e); }
|
try { if(conn!=null) conn.close(); } catch (SQLException e) { throw new RuntimeException(e); }
|
||||||
//return body content
|
//return body content
|
||||||
return new ResponseEntity<String>(result, httpHeaders, HttpStatus.OK);
|
return new ResponseEntity<String>(result, httpHeaders, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Example request: http://localhost:8080/CCALM/download?t=FrmLocust&f=image_name1&i=1298
|
* Example request: http://localhost:8080/CCALM/download?t=FrmLocust&f=image_name1&i=1298
|
||||||
@ -1942,7 +2066,7 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
db_login = env.getProperty("spring.datasource.username");
|
db_login = env.getProperty("spring.datasource.username");
|
||||||
db_password = env.getProperty("spring.datasource.password");
|
db_password = env.getProperty("spring.datasource.password");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
logger.error("Error load application.properties",e);
|
logger.error("Error load application.properties",e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2044,8 +2168,8 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
|
|
||||||
if(file!=null) {
|
if(file!=null) {
|
||||||
response.setContentType("application/octet-stream");
|
response.setContentType("application/octet-stream");
|
||||||
response.setHeader("Content-Disposition", "attachment; filename="+afterFirst(filename,"_"));
|
response.setHeader("Content-Disposition", "attachment; filename="+afterFirst(filename,"_"));
|
||||||
response.setHeader("Cache-Control", "no-cache");
|
response.setHeader("Cache-Control", "no-cache");
|
||||||
return new FileSystemResource(file);
|
return new FileSystemResource(file);
|
||||||
}else {
|
}else {
|
||||||
response.setContentType("text/html");
|
response.setContentType("text/html");
|
||||||
@ -2087,25 +2211,25 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
//Calc CRC32
|
//Calc CRC32
|
||||||
long crc32=0;
|
long crc32=0;
|
||||||
FileInputStream fin = new FileInputStream(data_dir + fileName);
|
FileInputStream fin = new FileInputStream(data_dir + fileName);
|
||||||
Checksum sum_control = new CRC32();
|
Checksum sum_control = new CRC32();
|
||||||
for (int b = fin.read(); b != -1; b = fin.read()) {
|
for (int b = fin.read(); b != -1; b = fin.read()) {
|
||||||
sum_control.update(b);
|
sum_control.update(b);
|
||||||
}
|
}
|
||||||
crc32 = sum_control.getValue();
|
crc32 = sum_control.getValue();
|
||||||
fin.close();
|
fin.close();
|
||||||
|
|
||||||
//To be rename file, add CRC32 in begin.
|
//To be rename file, add CRC32 in begin.
|
||||||
File srcFile = new File(data_dir + fileName);
|
File srcFile = new File(data_dir + fileName);
|
||||||
File destFile = new File(data_dir + Long.toHexString(crc32) +"_"+ fileName);
|
File destFile = new File(data_dir + Long.toHexString(crc32) +"_"+ fileName);
|
||||||
FileUtils.copyFile(srcFile, destFile);
|
FileUtils.copyFile(srcFile, destFile);
|
||||||
FileUtils.forceDelete(srcFile);
|
FileUtils.forceDelete(srcFile);
|
||||||
|
|
||||||
//logger.info("Uploaded Filename: " + Long.toHexString(crc32) +"_"+ fileName);
|
//logger.info("Uploaded Filename: " + Long.toHexString(crc32) +"_"+ fileName);
|
||||||
result+="ok=" + Long.toHexString(crc32) +"_"+ fileName + "\n";
|
result+="ok=" + Long.toHexString(crc32) +"_"+ fileName + "\n";
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.info(ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//This code put into iframe
|
//This code put into iframe
|
||||||
@ -2132,9 +2256,9 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Send generated report to the client for downloading
|
//Send generated report to the client for downloading
|
||||||
@RequestMapping(value = "/reports",method = RequestMethod.GET, produces = "application/octet-stream")
|
@RequestMapping(value = "/reports",method = RequestMethod.GET, produces = "application/octet-stream")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public FileSystemResource sendReport(HttpServletResponse response,@RequestParam(required=true,name="file") String fileName) {
|
public FileSystemResource sendReport(HttpServletResponse response,@RequestParam(required=true,name="file") String fileName) {
|
||||||
|
|
||||||
String data_dir = "";
|
String data_dir = "";
|
||||||
try {
|
try {
|
||||||
@ -2144,21 +2268,21 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
logger.error("Error load application.properties",e);
|
logger.error("Error load application.properties",e);
|
||||||
}
|
}
|
||||||
|
|
||||||
File file = new File(data_dir + "temp" + File.separator + fileName);
|
File file = new File(data_dir + "temp" + File.separator + fileName);
|
||||||
if(file.exists())
|
if(file.exists())
|
||||||
{
|
{
|
||||||
//logger.info("Send report: " + fileName);
|
//logger.info("Send report: " + fileName);
|
||||||
|
|
||||||
//response.setContentType("application/octet-stream"); //Commented because it is specified in the function declaration.
|
//response.setContentType("application/octet-stream"); //Commented because it is specified in the function declaration.
|
||||||
response.setHeader("Content-Disposition","attachment; filename="+fileName);
|
response.setHeader("Content-Disposition","attachment; filename="+fileName);
|
||||||
response.setContentLength((int) file.length());
|
response.setContentLength((int) file.length());
|
||||||
return new FileSystemResource(file);
|
return new FileSystemResource(file);
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
logger.info("File not found: " + fileName);
|
logger.info("File not found: " + fileName);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String nodeToString(Node node) {
|
private String nodeToString(Node node) {
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
@ -2266,8 +2390,32 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
public String trt2(String key,User user)
|
||||||
|
{
|
||||||
|
String result="";
|
||||||
|
JSONObject json = null;
|
||||||
|
try {
|
||||||
|
String sql="select translation from main._translations where identifier=:identifier and language_id=:language_id";
|
||||||
|
MapSqlParameterSource parameters = new MapSqlParameterSource();
|
||||||
|
parameters.addValue("identifier", key);
|
||||||
|
parameters.addValue("language_id", Integer.valueOf(user.language_id), Types.INTEGER);
|
||||||
|
List<String> ret = jdbcTemplate.query(sql, parameters, new DBTools.JsonRowMapper());
|
||||||
|
for (int i = 0; i < ret.size(); i++) {
|
||||||
|
json = new JSONObject(ret.get(i));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}catch (DataAccessException ex){
|
||||||
|
String uuid = UUID.randomUUID().toString();
|
||||||
|
logger.error(uuid,ex);
|
||||||
|
}
|
||||||
|
if(json!=null) {
|
||||||
|
result=json.getString("translation");
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
//Translate text by patterns
|
//Translate text by patterns (новая функция ниже)
|
||||||
|
//TODO потом удалить
|
||||||
public String trts(Connection conn,String text,User user) {
|
public String trts(Connection conn,String text,User user) {
|
||||||
int pos1 = 0;
|
int pos1 = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
@ -2282,6 +2430,20 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
}
|
}
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
public String trts2(String text,User user) {
|
||||||
|
int pos1 = 0;
|
||||||
|
while (true) {
|
||||||
|
pos1 = text.indexOf("trt('", pos1);
|
||||||
|
if (pos1 == -1)
|
||||||
|
break;
|
||||||
|
int pos2 = text.indexOf("')", pos1);
|
||||||
|
if (pos2 == -1)
|
||||||
|
break;
|
||||||
|
|
||||||
|
text = text.substring(0, pos1) + trt2(text.substring(pos1 + 5, pos2),user) + text.substring(pos2 + 2);
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
public static String afterFirst(String str, String ch)
|
public static String afterFirst(String str, String ch)
|
||||||
{
|
{
|
||||||
@ -2291,15 +2453,16 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
return str.substring(i+ch.length());
|
return str.substring(i+ch.length());
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
//Получить узел метаданных из базы данных
|
//Получить узел метаданных из базы данных (новая функция ниже)
|
||||||
|
//TODO потом удалить
|
||||||
public String getTypeStrNode(Connection conn,String typeName)
|
public String getTypeStrNode(Connection conn,String typeName)
|
||||||
{
|
{
|
||||||
String result="";
|
String result="";
|
||||||
String sql="select xml from main._metadata where name='"+typeName+"';";
|
String sql="select xml from main._metadata where name='"+typeName+"';";
|
||||||
try {
|
try {
|
||||||
Statement st = conn.createStatement();
|
Statement st = conn.createStatement();
|
||||||
ResultSet rs=null;
|
ResultSet rs=null;
|
||||||
try {
|
try {
|
||||||
rs = st.executeQuery(sql);
|
rs = st.executeQuery(sql);
|
||||||
@ -2307,14 +2470,14 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if(rs!=null)
|
if(rs!=null)
|
||||||
{
|
{
|
||||||
if(rs.next())
|
if(rs.next())
|
||||||
{
|
{
|
||||||
result=rs.getString(1);
|
result=rs.getString(1);
|
||||||
}
|
}
|
||||||
rs.close();
|
rs.close();
|
||||||
}
|
}
|
||||||
st.close();
|
st.close();
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
@ -2324,6 +2487,47 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
//Получить узел метаданных из базы данных (новая функция ниже)
|
||||||
|
public String getTypeStrNode2(String typeName)
|
||||||
|
{
|
||||||
|
String result="";
|
||||||
|
try {
|
||||||
|
String sql="select xml from main._metadata where name=:name";
|
||||||
|
MapSqlParameterSource parameters = new MapSqlParameterSource();
|
||||||
|
parameters.addValue("name", typeName);
|
||||||
|
List<String> ret = jdbcTemplate.query(sql, parameters, new DBTools.JsonRowMapper());
|
||||||
|
for (int i = 0; i < ret.size(); i++) {
|
||||||
|
JSONObject json = new JSONObject(ret.get(i));
|
||||||
|
result = json.getString("xml");
|
||||||
|
}
|
||||||
|
}catch (DataAccessException ex){
|
||||||
|
String uuid = UUID.randomUUID().toString();
|
||||||
|
logger.error(uuid,ex);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAccess(String user_id,String name)
|
||||||
|
{
|
||||||
|
String allow="1";
|
||||||
|
try {
|
||||||
|
String sql = "select main.get_Access(:user_id,:name) as acc;";
|
||||||
|
MapSqlParameterSource parameters = new MapSqlParameterSource();
|
||||||
|
parameters.addValue("user_id", Integer.parseInt(user_id), Types.INTEGER);
|
||||||
|
parameters.addValue("name", name);
|
||||||
|
List<String> ret = jdbcTemplate.query(sql, parameters, new DBTools.JsonRowMapper());
|
||||||
|
for (int i = 0; i < ret.size(); i++) {
|
||||||
|
if ((new JSONObject(ret.get(i))).getBoolean("acc"))
|
||||||
|
allow = "1";
|
||||||
|
else
|
||||||
|
allow = "0";
|
||||||
|
}
|
||||||
|
}catch (DataAccessException ex){
|
||||||
|
String uuid = UUID.randomUUID().toString();
|
||||||
|
logger.error(uuid,ex);
|
||||||
|
}
|
||||||
|
return allow;
|
||||||
|
}
|
||||||
|
|
||||||
//Пропарсить сткоку в DOM
|
//Пропарсить сткоку в DOM
|
||||||
public Document parseString(String xml)
|
public Document parseString(String xml)
|
||||||
|
|||||||
15
src/main/java/models/MetadataNameModel.java
Normal file
15
src/main/java/models/MetadataNameModel.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package models;
|
||||||
|
|
||||||
|
//import jakarta.persistence.Column;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
public class MetadataNameModel {
|
||||||
|
@JsonProperty("metadata_name")
|
||||||
|
private String metadata_name;
|
||||||
|
public String getMetadataName() {
|
||||||
|
return metadata_name;
|
||||||
|
}
|
||||||
|
public void setMetadataName(String metadata_name) {
|
||||||
|
this.metadata_name = metadata_name;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -25,7 +25,8 @@
|
|||||||
</encoder>
|
</encoder>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<root level="info">
|
<!--root level="info"-->
|
||||||
|
<root level="warn">
|
||||||
<appender-ref ref="FILE" />
|
<appender-ref ref="FILE" />
|
||||||
<appender-ref ref="CONSOLE" />
|
<appender-ref ref="CONSOLE" />
|
||||||
</root>
|
</root>
|
||||||
|
|||||||
Reference in New Issue
Block a user