start
This commit is contained in:
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/mvnw text eol=lf
|
||||
*.cmd text eol=crlf
|
||||
33
.gitignore
vendored
Normal file
33
.gitignore
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
HELP.md
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
19
.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
19
.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
wrapperVersion=3.3.2
|
||||
distributionType=only-script
|
||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
|
||||
25
logs/org-ccalm-translation.2025-04-26.0.log
Normal file
25
logs/org-ccalm-translation.2025-04-26.0.log
Normal file
@ -0,0 +1,25 @@
|
||||
{"timestamp":"2025-04-26T14:07:41.049Z","thread":"[HikariPool-1 housekeeper]","level":"WARN","logger":"com.zaxxer.hikari.pool.PoolBase","message":"HikariPool-1 - Failed to validate connection org.postgresql.jdbc.PgConnection@2cac72bc (This connection has been closed.). Possibly consider using a shorter maxLifetime value."}
|
||||
{"timestamp":"2025-04-26T14:07:51.067Z","thread":"[HikariPool-1 housekeeper]","level":"WARN","logger":"com.zaxxer.hikari.pool.PoolBase","message":"HikariPool-1 - Failed to validate connection org.postgresql.jdbc.PgConnection@221bf29d (This connection has been closed.). Possibly consider using a shorter maxLifetime value."}
|
||||
{"timestamp":"2025-04-26T14:07:51.067Z","thread":"[HikariPool-1 housekeeper]","level":"WARN","logger":"com.zaxxer.hikari.pool.HikariPool","message":"HikariPool-1 - Thread starvation or clock leap detected (housekeeper delta=14h52m49s548ms905µs400ns)."}
|
||||
{"timestamp":"2025-04-26T14:08:01.079Z","thread":"[HikariPool-1 housekeeper]","level":"WARN","logger":"com.zaxxer.hikari.pool.PoolBase","message":"HikariPool-1 - Failed to validate connection org.postgresql.jdbc.PgConnection@685a9fed (This connection has been closed.). Possibly consider using a shorter maxLifetime value."}
|
||||
{"timestamp":"2025-04-26T14:08:11.104Z","thread":"[HikariPool-1 housekeeper]","level":"WARN","logger":"com.zaxxer.hikari.pool.PoolBase","message":"HikariPool-1 - Failed to validate connection org.postgresql.jdbc.PgConnection@25179dd8 (This connection has been closed.). Possibly consider using a shorter maxLifetime value."}
|
||||
{"timestamp":"2025-04-26T14:08:21.126Z","thread":"[HikariPool-1 housekeeper]","level":"WARN","logger":"com.zaxxer.hikari.pool.PoolBase","message":"HikariPool-1 - Failed to validate connection org.postgresql.jdbc.PgConnection@5f65ea29 (This connection has been closed.). Possibly consider using a shorter maxLifetime value."}
|
||||
{"timestamp":"2025-04-26T15:51:36.590Z","thread":"[HikariPool-1 housekeeper]","level":"WARN","logger":"com.zaxxer.hikari.pool.PoolBase","message":"HikariPool-1 - Failed to validate connection org.postgresql.jdbc.PgConnection@5b5aa211 (This connection has been closed.). Possibly consider using a shorter maxLifetime value."}
|
||||
{"timestamp":"2025-04-26T20:22:34.173Z","thread":"[main]","level":"WARN","logger":"o.s.b.t.j.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer","message":"
|
||||
|
||||
Found multiple occurrences of org.json.JSONObject on the class path:
|
||||
|
||||
jar:file:/C:/Users/irigm/.m2/repository/com/vaadin/external/google/android-json/0.0.20131108.vaadin1/android-json-0.0.20131108.vaadin1.jar!/org/json/JSONObject.class
|
||||
jar:file:/C:/Users/irigm/.m2/repository/org/json/json/20231013/json-20231013.jar!/org/json/JSONObject.class
|
||||
|
||||
You may wish to exclude one of them to ensure predictable runtime behavior
|
||||
"}
|
||||
{"timestamp":"2025-04-26T20:23:39.081Z","thread":"[main]","level":"WARN","logger":"o.s.b.t.j.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer","message":"
|
||||
|
||||
Found multiple occurrences of org.json.JSONObject on the class path:
|
||||
|
||||
jar:file:/C:/Users/irigm/.m2/repository/com/vaadin/external/google/android-json/0.0.20131108.vaadin1/android-json-0.0.20131108.vaadin1.jar!/org/json/JSONObject.class
|
||||
jar:file:/C:/Users/irigm/.m2/repository/org/json/json/20231013/json-20231013.jar!/org/json/JSONObject.class
|
||||
|
||||
You may wish to exclude one of them to ensure predictable runtime behavior
|
||||
"}
|
||||
10
logs/org-ccalm-translation.2025-04-27.0.log
Normal file
10
logs/org-ccalm-translation.2025-04-27.0.log
Normal file
@ -0,0 +1,10 @@
|
||||
{"timestamp":"2025-04-27T12:14:07.398Z","thread":"[HikariPool-1 housekeeper]","level":"WARN","logger":"com.zaxxer.hikari.pool.HikariPool","message":"HikariPool-1 - Thread starvation or clock leap detected (housekeeper delta=1m2s604ms762µs801ns)."}
|
||||
{"timestamp":"2025-04-27T12:21:20.749Z","thread":"[main]","level":"WARN","logger":"o.s.b.t.j.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer","message":"
|
||||
|
||||
Found multiple occurrences of org.json.JSONObject on the class path:
|
||||
|
||||
jar:file:/C:/Users/irigm/.m2/repository/com/vaadin/external/google/android-json/0.0.20131108.vaadin1/android-json-0.0.20131108.vaadin1.jar!/org/json/JSONObject.class
|
||||
jar:file:/C:/Users/irigm/.m2/repository/org/json/json/20231013/json-20231013.jar!/org/json/JSONObject.class
|
||||
|
||||
You may wish to exclude one of them to ensure predictable runtime behavior
|
||||
"}
|
||||
1863
logs/org-ccalm-translation.2025-05-03.0.log
Normal file
1863
logs/org-ccalm-translation.2025-05-03.0.log
Normal file
File diff suppressed because it is too large
Load Diff
70
logs/org-ccalm-translation.2025-05-04.0.log
Normal file
70
logs/org-ccalm-translation.2025-05-04.0.log
Normal file
@ -0,0 +1,70 @@
|
||||
{"timestamp":"2025-05-04T08:57:21.442Z","thread":"[https-jsse-nio-8085-exec-9]","level":"WARN","logger":"com.zaxxer.hikari.pool.PoolBase","message":"HikariPool-1 - Default transaction isolation level detection failed (An I/O error occurred while sending to the backend.)."}
|
||||
{"timestamp":"2025-05-04T08:57:21.445Z","thread":"[https-jsse-nio-8085-exec-9]","level":"ERROR","logger":"com.zaxxer.hikari.pool.HikariPool","message":"HikariPool-1 - Error thrown while acquiring connection from data source"}
|
||||
org.postgresql.util.PSQLException: This connection has been closed.
|
||||
at org.postgresql.jdbc.PgConnection.checkClosed(PgConnection.java:1009)
|
||||
at org.postgresql.jdbc.PgConnection.setTransactionIsolation(PgConnection.java:1071)
|
||||
at com.zaxxer.hikari.pool.PoolBase.setupConnection(PoolBase.java:415)
|
||||
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:365)
|
||||
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:202)
|
||||
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:461)
|
||||
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:550)
|
||||
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:98)
|
||||
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:111)
|
||||
at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:160)
|
||||
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:118)
|
||||
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:81)
|
||||
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:653)
|
||||
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:723)
|
||||
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:748)
|
||||
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:804)
|
||||
at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.query(NamedParameterJdbcTemplate.java:218)
|
||||
at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.query(NamedParameterJdbcTemplate.java:230)
|
||||
at org.ccalm.translation.MainController.translateAll(MainController.java:225)
|
||||
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
|
||||
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
|
||||
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:257)
|
||||
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:190)
|
||||
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:118)
|
||||
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:986)
|
||||
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:891)
|
||||
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
|
||||
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1088)
|
||||
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:978)
|
||||
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014)
|
||||
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:903)
|
||||
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:564)
|
||||
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:885)
|
||||
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:658)
|
||||
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:195)
|
||||
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
|
||||
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
|
||||
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
|
||||
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
|
||||
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
|
||||
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
|
||||
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
|
||||
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
|
||||
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
|
||||
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
|
||||
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
|
||||
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
|
||||
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
|
||||
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
|
||||
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
|
||||
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
|
||||
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167)
|
||||
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90)
|
||||
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:483)
|
||||
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:115)
|
||||
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93)
|
||||
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
|
||||
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344)
|
||||
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:397)
|
||||
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63)
|
||||
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:905)
|
||||
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1741)
|
||||
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
|
||||
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1190)
|
||||
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
|
||||
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63)
|
||||
at java.base/java.lang.Thread.run(Thread.java:1583)
|
||||
1
logs/org-ccalm-translation.2025-05-09.0.log
Normal file
1
logs/org-ccalm-translation.2025-05-09.0.log
Normal file
@ -0,0 +1 @@
|
||||
{"timestamp":"2025-05-09T18:25:14.971Z","thread":"[HikariPool-1 housekeeper]","level":"WARN","logger":"com.zaxxer.hikari.pool.PoolBase","message":"HikariPool-1 - Failed to validate connection org.postgresql.jdbc.PgConnection@26f52393 (This connection has been closed.). Possibly consider using a shorter maxLifetime value."}
|
||||
5180
logs/org-ccalm-translation.2025-05-10.0.log
Normal file
5180
logs/org-ccalm-translation.2025-05-10.0.log
Normal file
File diff suppressed because it is too large
Load Diff
24
logs/org-ccalm-translation.2025-05-11.0.log
Normal file
24
logs/org-ccalm-translation.2025-05-11.0.log
Normal file
@ -0,0 +1,24 @@
|
||||
{"timestamp":"2025-05-11T07:38:03.501Z","thread":"[HikariPool-1 housekeeper]","level":"WARN","logger":"com.zaxxer.hikari.pool.PoolBase","message":"HikariPool-1 - Failed to validate connection org.postgresql.jdbc.PgConnection@11637f58 (This connection has been closed.). Possibly consider using a shorter maxLifetime value."}
|
||||
{"timestamp":"2025-05-11T07:38:13.525Z","thread":"[HikariPool-1 housekeeper]","level":"WARN","logger":"com.zaxxer.hikari.pool.PoolBase","message":"HikariPool-1 - Failed to validate connection org.postgresql.jdbc.PgConnection@de191c2 (This connection has been closed.). Possibly consider using a shorter maxLifetime value."}
|
||||
{"timestamp":"2025-05-11T07:38:23.534Z","thread":"[HikariPool-1 housekeeper]","level":"WARN","logger":"com.zaxxer.hikari.pool.PoolBase","message":"HikariPool-1 - Failed to validate connection org.postgresql.jdbc.PgConnection@90a13ce (This connection has been closed.). Possibly consider using a shorter maxLifetime value."}
|
||||
{"timestamp":"2025-05-11T07:38:23.534Z","thread":"[HikariPool-1 housekeeper]","level":"WARN","logger":"com.zaxxer.hikari.pool.HikariPool","message":"HikariPool-1 - Thread starvation or clock leap detected (housekeeper delta=7h28m18s8ms907µs100ns)."}
|
||||
{"timestamp":"2025-05-11T07:38:33.565Z","thread":"[HikariPool-1 housekeeper]","level":"WARN","logger":"com.zaxxer.hikari.pool.PoolBase","message":"HikariPool-1 - Failed to validate connection org.postgresql.jdbc.PgConnection@67fd433a (This connection has been closed.). Possibly consider using a shorter maxLifetime value."}
|
||||
{"timestamp":"2025-05-11T07:38:43.589Z","thread":"[HikariPool-1 housekeeper]","level":"WARN","logger":"com.zaxxer.hikari.pool.PoolBase","message":"HikariPool-1 - Failed to validate connection org.postgresql.jdbc.PgConnection@7449fbe7 (This connection has been closed.). Possibly consider using a shorter maxLifetime value."}
|
||||
{"timestamp":"2025-05-11T15:25:25.068Z","thread":"[main]","level":"WARN","logger":"o.s.b.t.j.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer","message":"
|
||||
|
||||
Found multiple occurrences of org.json.JSONObject on the class path:
|
||||
|
||||
jar:file:/C:/Users/irigm/.m2/repository/com/vaadin/external/google/android-json/0.0.20131108.vaadin1/android-json-0.0.20131108.vaadin1.jar!/org/json/JSONObject.class
|
||||
jar:file:/C:/Users/irigm/.m2/repository/org/json/json/20231013/json-20231013.jar!/org/json/JSONObject.class
|
||||
|
||||
You may wish to exclude one of them to ensure predictable runtime behavior
|
||||
"}
|
||||
{"timestamp":"2025-05-11T15:27:08.699Z","thread":"[main]","level":"WARN","logger":"o.s.b.t.j.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer","message":"
|
||||
|
||||
Found multiple occurrences of org.json.JSONObject on the class path:
|
||||
|
||||
jar:file:/C:/Users/irigm/.m2/repository/com/vaadin/external/google/android-json/0.0.20131108.vaadin1/android-json-0.0.20131108.vaadin1.jar!/org/json/JSONObject.class
|
||||
jar:file:/C:/Users/irigm/.m2/repository/org/json/json/20231013/json-20231013.jar!/org/json/JSONObject.class
|
||||
|
||||
You may wish to exclude one of them to ensure predictable runtime behavior
|
||||
"}
|
||||
9
logs/org-ccalm-translation.2025-05-21.0.log
Normal file
9
logs/org-ccalm-translation.2025-05-21.0.log
Normal file
@ -0,0 +1,9 @@
|
||||
{"timestamp":"2025-05-21T21:44:14.312Z","thread":"[main]","level":"WARN","logger":"o.s.b.t.j.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer","message":"
|
||||
|
||||
Found multiple occurrences of org.json.JSONObject on the class path:
|
||||
|
||||
jar:file:/C:/Users/irigm/.m2/repository/com/vaadin/external/google/android-json/0.0.20131108.vaadin1/android-json-0.0.20131108.vaadin1.jar!/org/json/JSONObject.class
|
||||
jar:file:/C:/Users/irigm/.m2/repository/org/json/json/20231013/json-20231013.jar!/org/json/JSONObject.class
|
||||
|
||||
You may wish to exclude one of them to ensure predictable runtime behavior
|
||||
"}
|
||||
18
logs/org-ccalm-translation.log
Normal file
18
logs/org-ccalm-translation.log
Normal file
@ -0,0 +1,18 @@
|
||||
{"timestamp":"2025-05-26T07:28:01.360Z","thread":"[main]","level":"WARN","logger":"o.s.b.t.j.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer","message":"
|
||||
|
||||
Found multiple occurrences of org.json.JSONObject on the class path:
|
||||
|
||||
jar:file:/C:/Users/irigm/.m2/repository/com/vaadin/external/google/android-json/0.0.20131108.vaadin1/android-json-0.0.20131108.vaadin1.jar!/org/json/JSONObject.class
|
||||
jar:file:/C:/Users/irigm/.m2/repository/org/json/json/20231013/json-20231013.jar!/org/json/JSONObject.class
|
||||
|
||||
You may wish to exclude one of them to ensure predictable runtime behavior
|
||||
"}
|
||||
{"timestamp":"2025-05-26T07:29:12.172Z","thread":"[main]","level":"WARN","logger":"o.s.b.t.j.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer","message":"
|
||||
|
||||
Found multiple occurrences of org.json.JSONObject on the class path:
|
||||
|
||||
jar:file:/C:/Users/irigm/.m2/repository/com/vaadin/external/google/android-json/0.0.20131108.vaadin1/android-json-0.0.20131108.vaadin1.jar!/org/json/JSONObject.class
|
||||
jar:file:/C:/Users/irigm/.m2/repository/org/json/json/20231013/json-20231013.jar!/org/json/JSONObject.class
|
||||
|
||||
You may wish to exclude one of them to ensure predictable runtime behavior
|
||||
"}
|
||||
259
mvnw
vendored
Normal file
259
mvnw
vendored
Normal file
@ -0,0 +1,259 @@
|
||||
#!/bin/sh
|
||||
# ----------------------------------------------------------------------------
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Apache Maven Wrapper startup batch script, version 3.3.2
|
||||
#
|
||||
# Optional ENV vars
|
||||
# -----------------
|
||||
# JAVA_HOME - location of a JDK home dir, required when download maven via java source
|
||||
# MVNW_REPOURL - repo url base for downloading maven distribution
|
||||
# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
|
||||
# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
set -euf
|
||||
[ "${MVNW_VERBOSE-}" != debug ] || set -x
|
||||
|
||||
# OS specific support.
|
||||
native_path() { printf %s\\n "$1"; }
|
||||
case "$(uname)" in
|
||||
CYGWIN* | MINGW*)
|
||||
[ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")"
|
||||
native_path() { cygpath --path --windows "$1"; }
|
||||
;;
|
||||
esac
|
||||
|
||||
# set JAVACMD and JAVACCMD
|
||||
set_java_home() {
|
||||
# For Cygwin and MinGW, ensure paths are in Unix format before anything is touched
|
||||
if [ -n "${JAVA_HOME-}" ]; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ]; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
JAVACCMD="$JAVA_HOME/jre/sh/javac"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
JAVACCMD="$JAVA_HOME/bin/javac"
|
||||
|
||||
if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then
|
||||
echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2
|
||||
echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
else
|
||||
JAVACMD="$(
|
||||
'set' +e
|
||||
'unset' -f command 2>/dev/null
|
||||
'command' -v java
|
||||
)" || :
|
||||
JAVACCMD="$(
|
||||
'set' +e
|
||||
'unset' -f command 2>/dev/null
|
||||
'command' -v javac
|
||||
)" || :
|
||||
|
||||
if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then
|
||||
echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# hash string like Java String::hashCode
|
||||
hash_string() {
|
||||
str="${1:-}" h=0
|
||||
while [ -n "$str" ]; do
|
||||
char="${str%"${str#?}"}"
|
||||
h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296))
|
||||
str="${str#?}"
|
||||
done
|
||||
printf %x\\n $h
|
||||
}
|
||||
|
||||
verbose() { :; }
|
||||
[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; }
|
||||
|
||||
die() {
|
||||
printf %s\\n "$1" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
trim() {
|
||||
# MWRAPPER-139:
|
||||
# Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds.
|
||||
# Needed for removing poorly interpreted newline sequences when running in more
|
||||
# exotic environments such as mingw bash on Windows.
|
||||
printf "%s" "${1}" | tr -d '[:space:]'
|
||||
}
|
||||
|
||||
# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties
|
||||
while IFS="=" read -r key value; do
|
||||
case "${key-}" in
|
||||
distributionUrl) distributionUrl=$(trim "${value-}") ;;
|
||||
distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;;
|
||||
esac
|
||||
done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties"
|
||||
[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties"
|
||||
|
||||
case "${distributionUrl##*/}" in
|
||||
maven-mvnd-*bin.*)
|
||||
MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/
|
||||
case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in
|
||||
*AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;;
|
||||
:Darwin*x86_64) distributionPlatform=darwin-amd64 ;;
|
||||
:Darwin*arm64) distributionPlatform=darwin-aarch64 ;;
|
||||
:Linux*x86_64*) distributionPlatform=linux-amd64 ;;
|
||||
*)
|
||||
echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2
|
||||
distributionPlatform=linux-amd64
|
||||
;;
|
||||
esac
|
||||
distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip"
|
||||
;;
|
||||
maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;;
|
||||
*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;;
|
||||
esac
|
||||
|
||||
# apply MVNW_REPOURL and calculate MAVEN_HOME
|
||||
# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-<version>,maven-mvnd-<version>-<platform>}/<hash>
|
||||
[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}"
|
||||
distributionUrlName="${distributionUrl##*/}"
|
||||
distributionUrlNameMain="${distributionUrlName%.*}"
|
||||
distributionUrlNameMain="${distributionUrlNameMain%-bin}"
|
||||
MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}"
|
||||
MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")"
|
||||
|
||||
exec_maven() {
|
||||
unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || :
|
||||
exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD"
|
||||
}
|
||||
|
||||
if [ -d "$MAVEN_HOME" ]; then
|
||||
verbose "found existing MAVEN_HOME at $MAVEN_HOME"
|
||||
exec_maven "$@"
|
||||
fi
|
||||
|
||||
case "${distributionUrl-}" in
|
||||
*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;;
|
||||
*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;;
|
||||
esac
|
||||
|
||||
# prepare tmp dir
|
||||
if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then
|
||||
clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; }
|
||||
trap clean HUP INT TERM EXIT
|
||||
else
|
||||
die "cannot create temp dir"
|
||||
fi
|
||||
|
||||
mkdir -p -- "${MAVEN_HOME%/*}"
|
||||
|
||||
# Download and Install Apache Maven
|
||||
verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
|
||||
verbose "Downloading from: $distributionUrl"
|
||||
verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
|
||||
|
||||
# select .zip or .tar.gz
|
||||
if ! command -v unzip >/dev/null; then
|
||||
distributionUrl="${distributionUrl%.zip}.tar.gz"
|
||||
distributionUrlName="${distributionUrl##*/}"
|
||||
fi
|
||||
|
||||
# verbose opt
|
||||
__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR=''
|
||||
[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v
|
||||
|
||||
# normalize http auth
|
||||
case "${MVNW_PASSWORD:+has-password}" in
|
||||
'') MVNW_USERNAME='' MVNW_PASSWORD='' ;;
|
||||
has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;;
|
||||
esac
|
||||
|
||||
if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then
|
||||
verbose "Found wget ... using wget"
|
||||
wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl"
|
||||
elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then
|
||||
verbose "Found curl ... using curl"
|
||||
curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl"
|
||||
elif set_java_home; then
|
||||
verbose "Falling back to use Java to download"
|
||||
javaSource="$TMP_DOWNLOAD_DIR/Downloader.java"
|
||||
targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName"
|
||||
cat >"$javaSource" <<-END
|
||||
public class Downloader extends java.net.Authenticator
|
||||
{
|
||||
protected java.net.PasswordAuthentication getPasswordAuthentication()
|
||||
{
|
||||
return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() );
|
||||
}
|
||||
public static void main( String[] args ) throws Exception
|
||||
{
|
||||
setDefault( new Downloader() );
|
||||
java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() );
|
||||
}
|
||||
}
|
||||
END
|
||||
# For Cygwin/MinGW, switch paths to Windows format before running javac and java
|
||||
verbose " - Compiling Downloader.java ..."
|
||||
"$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java"
|
||||
verbose " - Running Downloader.java ..."
|
||||
"$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")"
|
||||
fi
|
||||
|
||||
# If specified, validate the SHA-256 sum of the Maven distribution zip file
|
||||
if [ -n "${distributionSha256Sum-}" ]; then
|
||||
distributionSha256Result=false
|
||||
if [ "$MVN_CMD" = mvnd.sh ]; then
|
||||
echo "Checksum validation is not supported for maven-mvnd." >&2
|
||||
echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
|
||||
exit 1
|
||||
elif command -v sha256sum >/dev/null; then
|
||||
if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then
|
||||
distributionSha256Result=true
|
||||
fi
|
||||
elif command -v shasum >/dev/null; then
|
||||
if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then
|
||||
distributionSha256Result=true
|
||||
fi
|
||||
else
|
||||
echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2
|
||||
echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ $distributionSha256Result = false ]; then
|
||||
echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2
|
||||
echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# unzip and move
|
||||
if command -v unzip >/dev/null; then
|
||||
unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip"
|
||||
else
|
||||
tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar"
|
||||
fi
|
||||
printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url"
|
||||
mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME"
|
||||
|
||||
clean || :
|
||||
exec_maven "$@"
|
||||
149
mvnw.cmd
vendored
Normal file
149
mvnw.cmd
vendored
Normal file
@ -0,0 +1,149 @@
|
||||
<# : batch portion
|
||||
@REM ----------------------------------------------------------------------------
|
||||
@REM Licensed to the Apache Software Foundation (ASF) under one
|
||||
@REM or more contributor license agreements. See the NOTICE file
|
||||
@REM distributed with this work for additional information
|
||||
@REM regarding copyright ownership. The ASF licenses this file
|
||||
@REM to you under the Apache License, Version 2.0 (the
|
||||
@REM "License"); you may not use this file except in compliance
|
||||
@REM with the License. You may obtain a copy of the License at
|
||||
@REM
|
||||
@REM http://www.apache.org/licenses/LICENSE-2.0
|
||||
@REM
|
||||
@REM Unless required by applicable law or agreed to in writing,
|
||||
@REM software distributed under the License is distributed on an
|
||||
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@REM KIND, either express or implied. See the License for the
|
||||
@REM specific language governing permissions and limitations
|
||||
@REM under the License.
|
||||
@REM ----------------------------------------------------------------------------
|
||||
|
||||
@REM ----------------------------------------------------------------------------
|
||||
@REM Apache Maven Wrapper startup batch script, version 3.3.2
|
||||
@REM
|
||||
@REM Optional ENV vars
|
||||
@REM MVNW_REPOURL - repo url base for downloading maven distribution
|
||||
@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
|
||||
@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output
|
||||
@REM ----------------------------------------------------------------------------
|
||||
|
||||
@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0)
|
||||
@SET __MVNW_CMD__=
|
||||
@SET __MVNW_ERROR__=
|
||||
@SET __MVNW_PSMODULEP_SAVE=%PSModulePath%
|
||||
@SET PSModulePath=
|
||||
@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @(
|
||||
IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B)
|
||||
)
|
||||
@SET PSModulePath=%__MVNW_PSMODULEP_SAVE%
|
||||
@SET __MVNW_PSMODULEP_SAVE=
|
||||
@SET __MVNW_ARG0_NAME__=
|
||||
@SET MVNW_USERNAME=
|
||||
@SET MVNW_PASSWORD=
|
||||
@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*)
|
||||
@echo Cannot start maven from wrapper >&2 && exit /b 1
|
||||
@GOTO :EOF
|
||||
: end batch / begin powershell #>
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
if ($env:MVNW_VERBOSE -eq "true") {
|
||||
$VerbosePreference = "Continue"
|
||||
}
|
||||
|
||||
# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties
|
||||
$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl
|
||||
if (!$distributionUrl) {
|
||||
Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties"
|
||||
}
|
||||
|
||||
switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) {
|
||||
"maven-mvnd-*" {
|
||||
$USE_MVND = $true
|
||||
$distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip"
|
||||
$MVN_CMD = "mvnd.cmd"
|
||||
break
|
||||
}
|
||||
default {
|
||||
$USE_MVND = $false
|
||||
$MVN_CMD = $script -replace '^mvnw','mvn'
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
# apply MVNW_REPOURL and calculate MAVEN_HOME
|
||||
# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-<version>,maven-mvnd-<version>-<platform>}/<hash>
|
||||
if ($env:MVNW_REPOURL) {
|
||||
$MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" }
|
||||
$distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')"
|
||||
}
|
||||
$distributionUrlName = $distributionUrl -replace '^.*/',''
|
||||
$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$',''
|
||||
$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain"
|
||||
if ($env:MAVEN_USER_HOME) {
|
||||
$MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain"
|
||||
}
|
||||
$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join ''
|
||||
$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME"
|
||||
|
||||
if (Test-Path -Path "$MAVEN_HOME" -PathType Container) {
|
||||
Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME"
|
||||
Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
|
||||
exit $?
|
||||
}
|
||||
|
||||
if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) {
|
||||
Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl"
|
||||
}
|
||||
|
||||
# prepare tmp dir
|
||||
$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile
|
||||
$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir"
|
||||
$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null
|
||||
trap {
|
||||
if ($TMP_DOWNLOAD_DIR.Exists) {
|
||||
try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
|
||||
catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
|
||||
}
|
||||
}
|
||||
|
||||
New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null
|
||||
|
||||
# Download and Install Apache Maven
|
||||
Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
|
||||
Write-Verbose "Downloading from: $distributionUrl"
|
||||
Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
|
||||
|
||||
$webclient = New-Object System.Net.WebClient
|
||||
if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) {
|
||||
$webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD)
|
||||
}
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||
$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null
|
||||
|
||||
# If specified, validate the SHA-256 sum of the Maven distribution zip file
|
||||
$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum
|
||||
if ($distributionSha256Sum) {
|
||||
if ($USE_MVND) {
|
||||
Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties."
|
||||
}
|
||||
Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash
|
||||
if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) {
|
||||
Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property."
|
||||
}
|
||||
}
|
||||
|
||||
# unzip and move
|
||||
Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null
|
||||
Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null
|
||||
try {
|
||||
Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null
|
||||
} catch {
|
||||
if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) {
|
||||
Write-Error "fail to move MAVEN_HOME"
|
||||
}
|
||||
} finally {
|
||||
try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
|
||||
catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
|
||||
}
|
||||
|
||||
Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
|
||||
58
org-ccalm-translation.yml
Normal file
58
org-ccalm-translation.yml
Normal file
@ -0,0 +1,58 @@
|
||||
server:
|
||||
port: 8085
|
||||
ssl:
|
||||
enabled: true
|
||||
key-store: classpath:keystore.jks
|
||||
key-store-password: MFNX344yh4
|
||||
key-store-type: PKCS12
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: org-ccalm-translation
|
||||
datasource:
|
||||
url: jdbc:postgresql://almaty.ccalm.org:5432/CCALM?ApplicationName=org_ccalm_translation&ssl=true&sslmode=require&connectTimeout=10000&socketTimeout=10000
|
||||
#url: jdbc:postgresql://127.0.0.1:5432/CCALM?ApplicationName=org_ccalm_main&ssl=true&sslmode=require&connectTimeout=10000&socketTimeout=10000
|
||||
username: app_translation_1
|
||||
password: ZsiVuv7l4iTpVJgtP0tg
|
||||
driver-class-name: org.postgresql.Driver
|
||||
hikari:
|
||||
connection-init-sql: "SET timezone TO 'UTC';"
|
||||
maximum-pool-size: 10
|
||||
minimum-idle: 5
|
||||
max-lifetime: 1740000
|
||||
idle-timeout: 300000
|
||||
connection-timeout: 30000
|
||||
connection-test-query: SELECT 1
|
||||
validation-timeout: 5000
|
||||
leak-detection-threshold: 30000
|
||||
keepalive-time: 60000
|
||||
redis:
|
||||
host: 127.0.0.1
|
||||
port: 6379
|
||||
password: 9F3/NKWeOjd815vkadT2DcgVHf6fEpVQXw==
|
||||
|
||||
public:
|
||||
key: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzYLWgn7uUJYVn1PGyQKKC6F/m6PwEbL6FlCX+TaHZBjor83uS6rbuXquqbU/oFSiviBLI6Zg7BTzAhNglu8S2X4G7a1pkz3fn4kW9mf3zLnXnaNeuh+VhIEt/kw1ire1pCwP95KryKnQaLbi+ARDcGY+giIxjXRtNUTbAmgwP78U5M8fZ48+pH4AHWv/sG3TiTcIzUYCG/QMnnUE+Tir6kV3qrs66zig/cK5tTuJ7/JQOlhYOWBDElu0+lkSHgK2bEK9Wh7+qpIruO2K3gKX3RSFh8XfUIpwPVqyz2HVlzja+/scr6kuDB0iYfWZgrzLHPx3Bd0RyYBMIIgvBOoYmQIDAQAB
|
||||
access:
|
||||
time: 600
|
||||
refresh:
|
||||
time: 43200
|
||||
|
||||
captcha:
|
||||
key: PPExpv36jk4Vzda3NpYnXLfuHCLYXqaNrxlOH/Jr/1M=
|
||||
time: 600
|
||||
|
||||
mail:
|
||||
host: smtp.yandex.ru
|
||||
port: 465
|
||||
login: info@ccalm.org
|
||||
password: fu2lpsoGPGiq1xlRm8ag
|
||||
|
||||
data:
|
||||
dir: logs/
|
||||
|
||||
#logging:
|
||||
# level:
|
||||
# com:
|
||||
# zaxxer:
|
||||
# hikari: DEBUG
|
||||
141
pom.xml
Normal file
141
pom.xml
Normal file
@ -0,0 +1,141 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.4.2</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>org.ccalm</groupId>
|
||||
<artifactId>translation</artifactId>
|
||||
<version>1.0.3</version>
|
||||
<name>translation</name>
|
||||
<description>Translation project</description>
|
||||
<url/>
|
||||
<licenses>
|
||||
<license/>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer/>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection/>
|
||||
<developerConnection/>
|
||||
<tag/>
|
||||
<url/>
|
||||
</scm>
|
||||
<properties>
|
||||
<java.version>21</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-jdbc</artifactId>
|
||||
<version>6.2.5</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!--dependency>
|
||||
<groupId>com.zaxxer</groupId>
|
||||
<artifactId>HikariCP</artifactId>
|
||||
<version>6.1.12</version>
|
||||
</dependency-->
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||
<version>2.8.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.annotation</groupId>
|
||||
<artifactId>javax.annotation-api</artifactId>
|
||||
<version>1.3.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.36</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>20231013</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<version>3.7.0</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-api</artifactId>
|
||||
<version>0.11.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-impl</artifactId>
|
||||
<version>0.11.5</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-jackson</artifactId>
|
||||
<version>0.11.5</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>org-ccalm-translation</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>build-info</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.2</version>
|
||||
<configuration>
|
||||
<systemPropertyVariables>
|
||||
<spring.config.location>file:org-ccalm-translation.yml</spring.config.location>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
360
src/main/java/org/ccalm/translation/MainController.java
Normal file
360
src/main/java/org/ccalm/translation/MainController.java
Normal file
@ -0,0 +1,360 @@
|
||||
package org.ccalm.translation;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import jakarta.servlet.ServletContext;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.ccalm.translation.models.ErrorResponseModel;
|
||||
import org.ccalm.translation.tools.DBTools;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.http.CacheControl;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.context.ServletContextAware;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.web.multipart.support.StandardServletMultipartResolver;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.Types;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.ccalm.translation.tools.Tools.getURLText;
|
||||
|
||||
@Controller
|
||||
public class MainController implements ServletContextAware {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(MainController.class);
|
||||
private final StandardServletMultipartResolver standardServletMultipartResolver;
|
||||
|
||||
@Value("${spring.application.name}")
|
||||
String application_name = "";
|
||||
|
||||
private ServletContext context;
|
||||
private Properties m_props=null;
|
||||
|
||||
@Override
|
||||
public void setServletContext(ServletContext context){
|
||||
this.context=context;
|
||||
}
|
||||
|
||||
private final NamedParameterJdbcTemplate jdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
public MainController(NamedParameterJdbcTemplate jdbcTemplate, StandardServletMultipartResolver standardServletMultipartResolver) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
this.m_props = new Properties();
|
||||
this.standardServletMultipartResolver = standardServletMultipartResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing new main index page
|
||||
*/
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
@Operation(summary = "Get API version(date) of build", description = "Returns the date and API name")
|
||||
@RequestMapping(value = "/",method = RequestMethod.GET,produces = "application/json;charset=utf-8")
|
||||
@ResponseBody
|
||||
public ResponseEntity<Object> index(
|
||||
@CookieValue(value = "lng", defaultValue = "1") String language_id
|
||||
) {
|
||||
Translation trt = new Translation(language_id,jdbcTemplate);
|
||||
try {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("error_code",0);
|
||||
json.put("error_message","");
|
||||
json.put("error_marker",(String)null);
|
||||
String buildDate="";
|
||||
String buildVersion="";
|
||||
try {
|
||||
InputStream inputStream = MainController.class.getClassLoader().getResourceAsStream("META-INF/build-info.properties");
|
||||
if (inputStream != null) {
|
||||
Properties properties = new Properties();
|
||||
properties.load(inputStream);
|
||||
buildDate = properties.getProperty("build.time");
|
||||
buildVersion = properties.getProperty("build.version");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
json.put("build_date",buildDate);
|
||||
json.put("version",buildVersion);
|
||||
json.put("name",application_name);
|
||||
//json.put("active_connections",dataSource.getHikariPoolMXBean().getActiveConnections());
|
||||
//json.put("idle_connections",dataSource.getHikariPoolMXBean().getIdleConnections());
|
||||
|
||||
// Вывод всех зарегистрированных маршрутов в системе
|
||||
/*ApplicationContext context = SpringContext.getApplicationContext();
|
||||
if (context != null) {
|
||||
RequestMappingHandlerMapping mapping = context.getBean(RequestMappingHandlerMapping.class);
|
||||
Set<String> endpoints = mapping.getHandlerMethods().keySet().stream()
|
||||
.map(info -> info.toString())
|
||||
.collect(Collectors.toSet());
|
||||
System.out.println("=== Registered API endpoints ===");
|
||||
endpoints.forEach(System.out::println);
|
||||
}*/
|
||||
|
||||
return new ResponseEntity<>(json.toString(), HttpStatus.OK);
|
||||
} catch (Exception e) {
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
logger.error(uuid, e);
|
||||
return new ResponseEntity<>(new ErrorResponseModel(500, 10000, trt.trt(false, "Internal_Server_Error"), null, uuid), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function foe getting translation in JSON format
|
||||
* backend transit_translation_v01_kz
|
||||
* balance roundrobin
|
||||
* mode http
|
||||
* option http-keep-alive
|
||||
* http-request replace-path /api/translation/v01(.*) \1
|
||||
* server web_index_01 10.101.1.13:8086 ssl verify none check inter 5s
|
||||
*/
|
||||
@GetMapping(value = "/list", produces = "application/json")
|
||||
@ResponseBody
|
||||
public Map<String, String> getTranslations(
|
||||
@CookieValue(value = "lng", defaultValue = "1") String language_id
|
||||
) {
|
||||
|
||||
Map<String, String> translations = new HashMap<>();
|
||||
|
||||
try {
|
||||
String sql = """
|
||||
select
|
||||
identifier,
|
||||
translation
|
||||
from
|
||||
main._translations t
|
||||
where
|
||||
t.del = false
|
||||
and t.language_id = :language_id
|
||||
and translation_type_id = 1
|
||||
and identifier ~ '^[a-zA-Z_][a-zA-Z0-9_]*$'
|
||||
order by identifier
|
||||
""";
|
||||
|
||||
MapSqlParameterSource parameters = new MapSqlParameterSource();
|
||||
parameters.addValue("language_id", language_id, Types.INTEGER);
|
||||
List<Map<String, Object>> rows = jdbcTemplate.queryForList(sql, parameters);
|
||||
|
||||
for (Map<String, Object> row : rows) {
|
||||
String identifier = (String) row.get("identifier");
|
||||
String translation = (String) row.get("translation");
|
||||
translations.put(identifier, translation);
|
||||
}
|
||||
} catch (DataAccessException ex) {
|
||||
logger.info("Error fetching translations: " + ex.getMessage());
|
||||
}
|
||||
|
||||
return translations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simply selects the home view to render by returning its name.
|
||||
*/
|
||||
@RequestMapping(value = "/array", method = RequestMethod.GET, produces = "application/javascript")
|
||||
@ResponseBody
|
||||
public String home(
|
||||
Model model,
|
||||
@CookieValue(value = "lng", defaultValue = "1") String language_id
|
||||
) {
|
||||
Properties props = new Properties();
|
||||
String error="":
|
||||
try {
|
||||
String sql="""
|
||||
select
|
||||
identifier,
|
||||
translation
|
||||
from
|
||||
main._translations t
|
||||
where
|
||||
t.del=false
|
||||
and t.language_id=:language_id
|
||||
and translation_type_id=1
|
||||
and identifier ~ '^[a-zA-Z_][a-zA-Z0-9_]*$'
|
||||
order by
|
||||
identifier
|
||||
""";
|
||||
MapSqlParameterSource parameters = new MapSqlParameterSource();
|
||||
parameters.addValue("language_id", language_id, Types.INTEGER);
|
||||
List<String> ret = jdbcTemplate.query(sql, parameters, new DBTools.JsonRowMapper());
|
||||
for (String str : ret) {
|
||||
JSONObject obj = new JSONObject(str);
|
||||
props.setProperty(obj.getString("identifier"), obj.getString("translation"));
|
||||
}
|
||||
} catch( DataAccessException ex )
|
||||
{
|
||||
logger.info(ex.getMessage());
|
||||
}
|
||||
|
||||
//In JavaScript code
|
||||
JSONObject data = new JSONObject();
|
||||
Set<Object> keys = props.keySet();
|
||||
for(Object k:keys){
|
||||
String key = ((String)k).trim();
|
||||
String val = props.getProperty(key,"");
|
||||
data.put(key,val);
|
||||
}
|
||||
|
||||
return "var g_lng=\""+language_id+"\";\nvar g_translations = "+data.toString();
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = "/translate_all", method = RequestMethod.GET, produces = "text/html")
|
||||
@ResponseBody
|
||||
public String translateAll(
|
||||
) {
|
||||
String result="";
|
||||
//Properties props = new Properties();
|
||||
try {
|
||||
String sql="""
|
||||
select t1.identifier from
|
||||
(select sum(1) cnt,identifier from main._translations where del=false and translation_type_id=1 group by identifier) t1
|
||||
where
|
||||
t1.cnt < (select sum(1) from main._languages where del=false and id!=666)
|
||||
and identifier ~ '^[a-zA-Z_][a-zA-Z0-9_]*$'
|
||||
order by
|
||||
identifier
|
||||
""";
|
||||
List<String> ret = jdbcTemplate.query(sql, new DBTools.JsonRowMapper());
|
||||
for (String str : ret) {
|
||||
JSONObject obj = new JSONObject(str);
|
||||
//props.setProperty(obj.getString("identifier"), obj.getString("translation"));
|
||||
sql = """
|
||||
select
|
||||
l.id,
|
||||
l.short_name,
|
||||
(select translation from main._translations where del=false and translation_type_id=1 and identifier=:identifier and language_id=l.id) as translation
|
||||
from
|
||||
main._languages l
|
||||
where
|
||||
del=false
|
||||
and l.id!=666
|
||||
order by l.id
|
||||
""";
|
||||
MapSqlParameterSource parameters = new MapSqlParameterSource();
|
||||
parameters.addValue("identifier", obj.getString("identifier"), Types.VARCHAR);
|
||||
System.out.println("id = "+obj.getString("identifier"));
|
||||
List<String> ret_t = jdbcTemplate.query(sql, parameters, new DBTools.JsonRowMapper());
|
||||
|
||||
String identifier = obj.getString("identifier");
|
||||
String ru="";
|
||||
String en="";
|
||||
|
||||
for (String str_t : ret_t) {
|
||||
JSONObject obj_t = new JSONObject(str_t);
|
||||
if(!obj_t.isNull("short_name") && obj_t.getString("short_name").equals("ru")) {
|
||||
if(!obj_t.isNull("translation"))
|
||||
ru = obj_t.getString("translation");
|
||||
}
|
||||
if(!obj_t.isNull("short_name") && obj_t.getString("short_name").equals("en")) {
|
||||
if(!obj_t.isNull("translation"))
|
||||
en = obj_t.getString("translation");
|
||||
}
|
||||
if(!ru.isEmpty() && !en.isEmpty()) break;
|
||||
}
|
||||
|
||||
en = en.replace('_', ' ');
|
||||
ru = ru.replace('_', ' ');
|
||||
|
||||
result+="id = "+identifier+", ru = "+ru+", en = "+en+"<br>";
|
||||
System.out.println("ru = "+ru+", en = "+en);
|
||||
if(en.isEmpty() && ru.isEmpty())
|
||||
continue;
|
||||
//Если есть русский то переводим с него
|
||||
|
||||
for (String str_t : ret_t) {
|
||||
JSONObject obj_t = new JSONObject(str_t);
|
||||
|
||||
Long language_id=obj_t.getLong("id");
|
||||
|
||||
if(obj_t.isNull("translation") || obj_t.getString("translation").isEmpty()){
|
||||
//https://console.cloud.google.com/apis/credentials?inv=1&invt=AbwYdQ&project=ccalm-335705
|
||||
//String urlStr = "https://translation.googleapis.com/language/translate/v2?key=AIzaSyAOtc8E9Yg0O1uuZ_0EMYgqFP7W3p_0LGI";
|
||||
//https://translation.googleapis.com/language/translate/v2?key=AIzaSyAOtc8E9Yg0O1uuZ_0EMYgqFP7W3p_0LGI&q=Hello%20world&target=fr
|
||||
|
||||
String urlStr = "https://translation.googleapis.com/language/translate/v2?key=AIzaSyDGddDFW3AufSFCjpQa9obi-OnzIYorJ1s";
|
||||
|
||||
JSONObject myObj = new JSONObject();
|
||||
if(!ru.isEmpty()) {
|
||||
myObj.put("source", "ru");
|
||||
myObj.put("q", new JSONArray().put(ru));
|
||||
}else if(!en.isEmpty()) {
|
||||
myObj.put("source", "en");
|
||||
myObj.put("q", new JSONArray().put(en));
|
||||
}
|
||||
|
||||
myObj.put("target", obj_t.getString("short_name")); //На какой язык нужно перевести
|
||||
String jsonRequest = myObj.toString();
|
||||
String jsonResponse = getURLText(urlStr, jsonRequest);
|
||||
try {
|
||||
Thread.sleep(1000); // Пауза между запросами а то гугел может заблокировать IP
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
|
||||
System.out.println("Запрос: " + jsonRequest);
|
||||
System.out.println("Ответ от API: " + jsonResponse);
|
||||
System.out.println("");
|
||||
|
||||
JSONObject obj_tt = new JSONObject(jsonResponse);
|
||||
String translation = obj_tt
|
||||
.getJSONObject("data")
|
||||
.getJSONArray("translations")
|
||||
.getJSONObject(0)
|
||||
.getString("translatedText");
|
||||
|
||||
sql="""
|
||||
insert into main._translations(
|
||||
translation_type_id,
|
||||
language_id,
|
||||
identifier,
|
||||
translation,
|
||||
auto
|
||||
)values(
|
||||
1,
|
||||
:language_id,
|
||||
:identifier,
|
||||
:translation,
|
||||
true
|
||||
);
|
||||
""";
|
||||
parameters = new MapSqlParameterSource();
|
||||
parameters.addValue("language_id", language_id, Types.INTEGER);
|
||||
parameters.addValue("identifier", identifier, Types.VARCHAR);
|
||||
parameters.addValue("translation", translation, Types.VARCHAR);
|
||||
jdbcTemplate.update(sql, parameters);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch( DataAccessException ex )
|
||||
{
|
||||
logger.info(ex.getMessage());
|
||||
result = ex.getMessage();
|
||||
} catch( Exception ex )
|
||||
{
|
||||
logger.info(ex.getMessage());
|
||||
result = ex.getMessage();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/*
|
||||
SELECT *
|
||||
FROM main._translations
|
||||
WHERE
|
||||
translation LIKE '%\_s\_%' ESCAPE '\'
|
||||
OR translation LIKE '%\_s' ESCAPE '\'
|
||||
OR translation LIKE 's\_%' ESCAPE '\';
|
||||
*/
|
||||
68
src/main/java/org/ccalm/translation/Translation.java
Normal file
68
src/main/java/org/ccalm/translation/Translation.java
Normal file
@ -0,0 +1,68 @@
|
||||
package org.ccalm.translation;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.ccalm.translation.tools.DBTools;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Translation {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(Translation.class);
|
||||
|
||||
public int language_id;
|
||||
public NamedParameterJdbcTemplate jdbcTemplate;
|
||||
Translation(String lng, NamedParameterJdbcTemplate jdbcTemplate){
|
||||
language_id=1;
|
||||
switch (lng) {
|
||||
case "kz":
|
||||
case "kk":
|
||||
language_id = 2;
|
||||
break;
|
||||
case "en":
|
||||
language_id = 3;
|
||||
break;
|
||||
case "uz":
|
||||
language_id = 4;
|
||||
break;
|
||||
case "ru":
|
||||
default:
|
||||
language_id = 1;
|
||||
break;
|
||||
}
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
String trt(boolean translate,String text){
|
||||
if(translate) {
|
||||
String sql = """
|
||||
select
|
||||
translation
|
||||
from
|
||||
main._translations
|
||||
where
|
||||
del=false
|
||||
and language_id=:language_id
|
||||
and identifier=:identifier;
|
||||
""";
|
||||
MapSqlParameterSource parameters = new MapSqlParameterSource();
|
||||
parameters.addValue("language_id", language_id);
|
||||
parameters.addValue("identifier", text);
|
||||
List<String> ret = jdbcTemplate.query(sql, parameters, new DBTools.JsonRowMapper());
|
||||
int i = 0;
|
||||
for (i = 0; i < ret.size(); i++) {
|
||||
JSONObject json = new JSONObject(ret.get(i));
|
||||
text = json.getString("translation");
|
||||
}
|
||||
if(i==0){
|
||||
text = text.replace("_", " ");
|
||||
}
|
||||
return text;
|
||||
}else {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package org.ccalm.translation;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class TranslationApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(TranslationApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package org.ccalm.translation.models;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
|
||||
@Schema(description = "Model for getting actions by name")
|
||||
public class ActionNameModel {
|
||||
|
||||
@Schema(description = "Action name", example = "arm_")
|
||||
@JsonProperty("action_name")
|
||||
private String action_name;
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
package org.ccalm.translation.models;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Schema(
|
||||
description = "Standard API response",
|
||||
example = "{ \"error_code\": 0, \"error_message\": \"\", \"data\": [\"arm_accounting\",\"arm_carrier\",\"arm_hr\"] }"
|
||||
)
|
||||
public class ApiResponseData<T> {
|
||||
|
||||
@Schema(description = "Error code", example = "0")
|
||||
@JsonProperty("error_code")
|
||||
private int errorCode;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@Schema(description = "Data")
|
||||
private List<String> data;
|
||||
|
||||
public ApiResponseData(List<String> data) {
|
||||
errorCode = 0;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public static ApiResponseData success(List<String> data) {
|
||||
return new ApiResponseData(data);
|
||||
}
|
||||
|
||||
public int getError_code() {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
public void setError_code(int errorCode) {
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
}
|
||||
12
src/main/java/org/ccalm/translation/models/EmailModel.java
Normal file
12
src/main/java/org/ccalm/translation/models/EmailModel.java
Normal file
@ -0,0 +1,12 @@
|
||||
package org.ccalm.translation.models;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class EmailModel {
|
||||
@JsonProperty("email")
|
||||
private String email;
|
||||
@JsonProperty("width")
|
||||
private String width;
|
||||
}
|
||||
21
src/main/java/org/ccalm/translation/models/ErrorModel.java
Normal file
21
src/main/java/org/ccalm/translation/models/ErrorModel.java
Normal file
@ -0,0 +1,21 @@
|
||||
package org.ccalm.translation.models;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ErrorModel {
|
||||
@JsonProperty("timestamp")
|
||||
private String timestamp;
|
||||
|
||||
@JsonProperty("status")
|
||||
private int status;
|
||||
|
||||
@JsonProperty("error")
|
||||
private String error;
|
||||
|
||||
@JsonProperty("path")
|
||||
private String path;
|
||||
|
||||
// Конструктор, геттеры и сеттеры
|
||||
}
|
||||
@ -0,0 +1,113 @@
|
||||
package org.ccalm.translation.models;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Schema(
|
||||
description = "Error API response",
|
||||
example = "{ \"error_code\": 10000, \"error_message\": [\"Internal_Server_Error\",\"Please_log_in\"], \"error_setting\": [\"99;day\",\"1;2\"], \"error_marker\": \"2a449883-c7c6-468e-b3ae-5f73fc96627d\" }"
|
||||
)
|
||||
|
||||
public class ErrorResponseModel {
|
||||
|
||||
@JsonIgnore
|
||||
private int httpCode;
|
||||
|
||||
@Schema(description = "Error code", example = "10000")
|
||||
@JsonProperty("error_code")
|
||||
private int errorCode;
|
||||
|
||||
@Schema(description = "List of error descriptions", example = "[\"Internal_Server_Error\",\"Please_log_in\"]")
|
||||
@JsonProperty("error_message")
|
||||
private List<String> errorMessage;
|
||||
|
||||
@Schema(description = "Options for translated text", example = "[\"99;day\",\"1;2\"]")
|
||||
@JsonProperty("error_setting")
|
||||
private List<String> errorSetting;
|
||||
|
||||
@Schema(description = "Unique identifier for searching in the database", example = "4260aad8-f7ee-4be4-b52c-15d56ec83232")
|
||||
@JsonProperty("error_marker")
|
||||
private String errorMarker;
|
||||
|
||||
public ErrorResponseModel(int httpCode, int errorCode) {
|
||||
this.httpCode = httpCode;
|
||||
this.errorCode = errorCode;
|
||||
this.errorMessage = null;
|
||||
this.errorSetting = null;
|
||||
this.errorMarker = UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
public ErrorResponseModel(int httpCode, int errorCode, List<String> errorMessage, String errorMarker) {
|
||||
this.httpCode = httpCode;
|
||||
this.errorCode = errorCode;
|
||||
this.errorMessage = errorMessage;
|
||||
this.errorMarker = errorMarker;
|
||||
}
|
||||
|
||||
public ErrorResponseModel(int httpCode, int errorCode, String errorMessage, String errorMarker) {
|
||||
this.httpCode = httpCode;
|
||||
this.errorCode = errorCode;
|
||||
this.errorMessage = Collections.singletonList(errorMessage);
|
||||
this.errorMarker = errorMarker;
|
||||
}
|
||||
|
||||
public ErrorResponseModel(int httpCode, int errorCode, String errorMessage, String errorSetting, String errorMarker) {
|
||||
this.httpCode = httpCode;
|
||||
this.errorCode = errorCode;
|
||||
this.errorMessage = Collections.singletonList(errorMessage);
|
||||
this.errorSetting = Collections.singletonList(errorSetting);
|
||||
this.errorMarker = errorMarker;
|
||||
}
|
||||
|
||||
public ErrorResponseModel(int httpCode, int errorCode, List<String> errorMessage, List<String> errorSetting, String errorMarker) {
|
||||
this.httpCode = httpCode;
|
||||
this.errorCode = errorCode;
|
||||
this.errorMessage = errorMessage;
|
||||
this.errorSetting = errorSetting;
|
||||
this.errorMarker = errorMarker;
|
||||
}
|
||||
|
||||
public int getHttp_code() {
|
||||
return httpCode;
|
||||
}
|
||||
public void setHttp_code(int errorCode) {
|
||||
this.httpCode = httpCode;
|
||||
}
|
||||
|
||||
public int getError_code() {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
public void setError_code(int errorCode) {
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
public List<String> getError_message() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setError_message(List<String> errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public void setError_setting(List<String> errorSetting) {
|
||||
this.errorSetting = errorSetting;
|
||||
}
|
||||
|
||||
public List<String> getError_setting() {
|
||||
return errorSetting;
|
||||
}
|
||||
|
||||
public void setError_marker(String errorMarker) {
|
||||
this.errorMarker = errorMarker;
|
||||
}
|
||||
|
||||
public String getError_marker() {
|
||||
return errorMarker;
|
||||
}
|
||||
}
|
||||
14
src/main/java/org/ccalm/translation/models/LoginModel.java
Normal file
14
src/main/java/org/ccalm/translation/models/LoginModel.java
Normal file
@ -0,0 +1,14 @@
|
||||
package org.ccalm.translation.models;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class LoginModel {
|
||||
//@JsonProperty("login")
|
||||
private String login;
|
||||
//@JsonProperty("password")
|
||||
private String password;
|
||||
//@JsonProperty("appid")
|
||||
private String totp;
|
||||
private String appid;
|
||||
}
|
||||
90
src/main/java/org/ccalm/translation/models/NewUserModel.java
Normal file
90
src/main/java/org/ccalm/translation/models/NewUserModel.java
Normal file
@ -0,0 +1,90 @@
|
||||
package org.ccalm.translation.models;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class NewUserModel {
|
||||
@JsonProperty("country")
|
||||
private String country;
|
||||
@JsonProperty("name")
|
||||
private String name;
|
||||
@JsonProperty("surname")
|
||||
private String surname;
|
||||
@JsonProperty("company")
|
||||
private String company;
|
||||
@JsonProperty("position")
|
||||
private String position;
|
||||
@JsonProperty("phone")
|
||||
private String phone;
|
||||
@JsonProperty("email")
|
||||
private String email;
|
||||
@JsonProperty("iin")
|
||||
private String iin;
|
||||
@JsonProperty("code")
|
||||
private String code;
|
||||
@JsonProperty("token")
|
||||
private String token;
|
||||
/*
|
||||
public String getCountry() {
|
||||
if(country==null) return "";
|
||||
else return country;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
if(name==null) return "";
|
||||
else return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getSurname() {
|
||||
if(surname==null) return "";
|
||||
else return surname;
|
||||
}
|
||||
public void setSurname(String surname) {
|
||||
this.surname = surname;
|
||||
}
|
||||
|
||||
|
||||
public String getEmail() {
|
||||
if(email==null) return "";
|
||||
else return email;
|
||||
}
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
|
||||
public String getIin() {
|
||||
if(iin==null) return "";
|
||||
else return iin;
|
||||
}
|
||||
public void setIin(String iin) {
|
||||
this.iin = iin;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
if(code==null) return "";
|
||||
else return code;
|
||||
}
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
if(token==null) return "";
|
||||
else return token;
|
||||
}
|
||||
public void setToken(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
*/
|
||||
}
|
||||
13
src/main/java/org/ccalm/translation/models/RestoreModel.java
Normal file
13
src/main/java/org/ccalm/translation/models/RestoreModel.java
Normal file
@ -0,0 +1,13 @@
|
||||
package org.ccalm.translation.models;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class RestoreModel {
|
||||
|
||||
@JsonProperty("code")
|
||||
String code;
|
||||
@JsonProperty("token")
|
||||
String token;
|
||||
}
|
||||
13
src/main/java/org/ccalm/translation/models/SettingModel.java
Normal file
13
src/main/java/org/ccalm/translation/models/SettingModel.java
Normal file
@ -0,0 +1,13 @@
|
||||
package org.ccalm.translation.models;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SettingModel {
|
||||
@JsonProperty("identifier")
|
||||
private String identifier;
|
||||
@JsonProperty("value")
|
||||
private String value;
|
||||
}
|
||||
|
||||
42
src/main/java/org/ccalm/translation/models/UpdateModel.java
Normal file
42
src/main/java/org/ccalm/translation/models/UpdateModel.java
Normal file
@ -0,0 +1,42 @@
|
||||
package org.ccalm.translation.models;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class UpdateModel {
|
||||
|
||||
@JsonProperty("login")
|
||||
private String login;
|
||||
@JsonProperty("password")
|
||||
private String password;
|
||||
@JsonProperty("password_new")
|
||||
private String passwordNew;
|
||||
|
||||
// Геттеры и сеттеры для полей
|
||||
|
||||
public String getLogin() {
|
||||
if(login==null) return "";
|
||||
else return login;
|
||||
}
|
||||
|
||||
public void setLogin(String login) {
|
||||
this.login = login;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
if(password==null) return "";
|
||||
else return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getPasswordNew() {
|
||||
if(passwordNew==null) return "";
|
||||
else return passwordNew;
|
||||
}
|
||||
|
||||
public void setPasswordNew(String passwordNew) {
|
||||
this.passwordNew = passwordNew;
|
||||
}
|
||||
}
|
||||
27
src/main/java/org/ccalm/translation/models/UserModel.java
Normal file
27
src/main/java/org/ccalm/translation/models/UserModel.java
Normal file
@ -0,0 +1,27 @@
|
||||
package org.ccalm.translation.models;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UserModel {
|
||||
@JsonProperty("country_id")
|
||||
private Long countryId;
|
||||
@JsonProperty("company_name")
|
||||
private String companyName;
|
||||
@JsonProperty("position")
|
||||
private String position;
|
||||
@JsonProperty("name")
|
||||
private String name;
|
||||
@JsonProperty("surname")
|
||||
private String surname;
|
||||
@JsonProperty("patronymic")
|
||||
private String patronymic;
|
||||
@JsonProperty("phone")
|
||||
private String phone;
|
||||
@JsonProperty("email")
|
||||
private String email;
|
||||
@JsonProperty("password")
|
||||
private String password;
|
||||
}
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
package org.ccalm.translation.models;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class VerificationModel {
|
||||
@JsonProperty("email")
|
||||
private String email;
|
||||
@JsonProperty("code")
|
||||
private String code;
|
||||
@JsonProperty("token")
|
||||
private String token;
|
||||
}
|
||||
54
src/main/java/org/ccalm/translation/tools/Cache.java
Normal file
54
src/main/java/org/ccalm/translation/tools/Cache.java
Normal file
@ -0,0 +1,54 @@
|
||||
package org.ccalm.translation.tools;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import redis.clients.jedis.Jedis;
|
||||
|
||||
public class Cache implements AutoCloseable {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(Cache.class);
|
||||
private Jedis jedis = null;
|
||||
|
||||
String host = null;
|
||||
int port = 0;
|
||||
String password = null;
|
||||
|
||||
public Cache(String host,int port,String password) {
|
||||
this.host=host;
|
||||
this.port=port;
|
||||
this.password=password;
|
||||
}
|
||||
|
||||
public boolean open(){
|
||||
try {
|
||||
jedis = new Jedis(host, port);
|
||||
jedis.auth(password);
|
||||
}catch (Exception e)
|
||||
{
|
||||
logger.error(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
if(jedis!=null)
|
||||
jedis.close();
|
||||
}
|
||||
|
||||
public String get(String key) {
|
||||
return jedis.get(key);
|
||||
}
|
||||
|
||||
public boolean set(String key,String data,int ttl){
|
||||
jedis.set(key, data);
|
||||
long currentTimeMillis = System.currentTimeMillis();
|
||||
long expireTimeMillis = currentTimeMillis + ttl * 1000;
|
||||
jedis.expireAt(key, expireTimeMillis / 1000);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void delete(String key) {
|
||||
jedis.del(key.getBytes());
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,82 @@
|
||||
package org.ccalm.translation.tools;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.ccalm.translation.models.ErrorResponseModel;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
public class CustomException extends Exception {
|
||||
private static final Logger logger = LogManager.getLogger(CustomException.class);
|
||||
|
||||
private ErrorResponseModel error;
|
||||
@Getter
|
||||
private boolean saveToLog = false;
|
||||
|
||||
public CustomException(int httpCode, int errorCode, String errorMessage, String marker, boolean saveToLog) {
|
||||
super(errorMessage);
|
||||
error = new ErrorResponseModel(httpCode, errorCode, errorMessage, marker);
|
||||
this.saveToLog = saveToLog;
|
||||
}
|
||||
|
||||
public CustomException(int httpCode, int errorCode, String errorMessage, String errorSetting, String marker, boolean saveToLog) {
|
||||
super(errorMessage);
|
||||
error = new ErrorResponseModel(httpCode, errorCode, errorMessage, errorSetting, marker);
|
||||
this.saveToLog = saveToLog;
|
||||
}
|
||||
|
||||
public CustomException(int httpCode, int errorCode, List<String> errorMessages, String marker, boolean saveToLog) {
|
||||
super(String.join(" ", errorMessages));
|
||||
error = new ErrorResponseModel(httpCode, errorCode, errorMessages, marker);
|
||||
this.saveToLog = saveToLog;
|
||||
}
|
||||
|
||||
public CustomException(int httpCode, int errorCode, List<String> errorMessages, List<String> errorSettings, String marker, boolean saveToLog) {
|
||||
super(String.join(" ", errorMessages));
|
||||
error = new ErrorResponseModel(httpCode, errorCode, errorMessages, errorSettings, marker);
|
||||
this.saveToLog = saveToLog;
|
||||
}
|
||||
|
||||
public int getHttpCode() {
|
||||
return error.getHttp_code();
|
||||
}
|
||||
|
||||
public int getErrorCode() {
|
||||
return error.getError_code();
|
||||
}
|
||||
|
||||
public String getErrorMarker() {
|
||||
return error.getError_marker();
|
||||
}
|
||||
|
||||
public List<String> getErrorMessages() {
|
||||
return error.getError_message();
|
||||
}
|
||||
|
||||
public List<String> getErrorSettings() {
|
||||
return error.getError_setting();
|
||||
}
|
||||
|
||||
public JSONObject getJson() {
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
json.put("error_code", this.getErrorCode());
|
||||
json.put("error_message", this.getErrorMessages());
|
||||
json.put("error_setting", this.getErrorSettings());
|
||||
json.put("error_marker", this.getErrorMarker());
|
||||
} catch (JSONException e) {
|
||||
logger.error("Error", e);
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
public ErrorResponseModel getErrorResponseModel() {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
36
src/main/java/org/ccalm/translation/tools/DBTools.java
Normal file
36
src/main/java/org/ccalm/translation/tools/DBTools.java
Normal file
@ -0,0 +1,36 @@
|
||||
package org.ccalm.translation.tools;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class DBTools {
|
||||
|
||||
public static class JsonRowMapper implements RowMapper<String> {
|
||||
|
||||
@Override
|
||||
public String mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
|
||||
// Получаем метаданные ResultSet для получения названий столбцов
|
||||
int columnCount = rs.getMetaData().getColumnCount();
|
||||
for (int i = 1; i <= columnCount; i++) {
|
||||
String columnName = rs.getMetaData().getColumnName(i);
|
||||
Object columnValue = rs.getObject(i);
|
||||
resultMap.put(columnName, columnValue);
|
||||
}
|
||||
|
||||
// Преобразовываем Map в JSON строку
|
||||
try {
|
||||
return objectMapper.writeValueAsString(resultMap);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to convert Map to JSON", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
168
src/main/java/org/ccalm/translation/tools/Storage.java
Normal file
168
src/main/java/org/ccalm/translation/tools/Storage.java
Normal file
@ -0,0 +1,168 @@
|
||||
package org.ccalm.translation.tools;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
public class Storage implements AutoCloseable {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(Storage.class);
|
||||
private Connection conn = null;
|
||||
|
||||
public Storage(){
|
||||
String url = "jdbc:sqlite:temporary.sqlite";
|
||||
try {
|
||||
conn = DriverManager.getConnection(url);
|
||||
Statement stmt = conn.createStatement();
|
||||
String sql= """
|
||||
CREATE TABLE IF NOT EXISTS _users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
email TEXT NOT NULL, --Email пользователя
|
||||
key TEXT NOT NULL, --Ключ для токена обновления (refresh token)
|
||||
jwt_r TEXT NOT NULL, --Сам ключ обновления
|
||||
jwt_a TEXT NOT NULL, --Сам ключ доступа
|
||||
time_r INTEGER, --Unix time в секундах, когда заканчивается токен обновления
|
||||
time_a INTEGER --Unix time в секундах, когда заканчивается токен доступа
|
||||
);
|
||||
""";
|
||||
stmt.execute(sql);
|
||||
stmt.close();
|
||||
} catch (SQLException e) {
|
||||
logger.error("Error connecting or executing SQL query in SQLite", e);
|
||||
}
|
||||
}
|
||||
|
||||
//Для выполнения: try-with-resources
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
if(conn!=null) {
|
||||
try {
|
||||
conn.close();
|
||||
conn=null;
|
||||
} catch (SQLException e) {
|
||||
logger.error("SQLite close error", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// В коде не надеюсь на finalize, использую try-with-resources из AutoCloseable
|
||||
/*@Override
|
||||
protected void finalize() throws Throwable {
|
||||
if(conn!=null) {
|
||||
try {
|
||||
conn.close();
|
||||
conn=null;
|
||||
} catch (SQLException e) {
|
||||
logger.error("SQLite close error", e);
|
||||
}
|
||||
}
|
||||
super.finalize();
|
||||
}*/
|
||||
|
||||
//Получаю поля из базы email пользователя
|
||||
public JSONObject getJWT(String email){
|
||||
JSONObject result = new JSONObject();
|
||||
try {
|
||||
PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM _users WHERE email=?");
|
||||
pstmt.setString(1, email);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
if (rs.next()) {
|
||||
result.put("id", rs.getInt("id"));
|
||||
result.put("email", rs.getString("email"));
|
||||
result.put("key", rs.getString("key"));
|
||||
result.put("jwt_r", rs.getString("jwt_r"));
|
||||
result.put("jwt_a", rs.getString("jwt_a"));
|
||||
result.put("time_r", rs.getLong("time_r"));
|
||||
result.put("time_a", rs.getLong("time_a"));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
logger.error("An error occurred", e);
|
||||
} catch (Exception e) {
|
||||
logger.error("An error occurred", e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//Сохранить либо обновить Refresh токен
|
||||
public boolean setJWT(String email,String key,String jwt_r,String jwt_a,long time_r,long time_a){
|
||||
try {
|
||||
// Проверка существует ли запись с данным email
|
||||
PreparedStatement selectStmt = conn.prepareStatement("SELECT * FROM _users WHERE email=?");
|
||||
selectStmt.setString(1, email);
|
||||
ResultSet rs = selectStmt.executeQuery();
|
||||
boolean exists = rs.next();
|
||||
selectStmt.close();
|
||||
if (exists) {
|
||||
String updateSql = "UPDATE _users SET key=?, jwt_r=?, jwt_a=?, time_r=?, time_a=? WHERE email=?";
|
||||
PreparedStatement updateStmt = conn.prepareStatement(updateSql);
|
||||
updateStmt.setString(1, key);
|
||||
updateStmt.setString(2, jwt_r);
|
||||
updateStmt.setString(3, jwt_a);
|
||||
updateStmt.setLong(4, time_r); // Время в секундах
|
||||
updateStmt.setLong(5, time_a); // Время в секундах
|
||||
updateStmt.setString(6, email);
|
||||
updateStmt.executeUpdate();
|
||||
updateStmt.close();
|
||||
} else {
|
||||
String insertSql = "INSERT INTO _users(email, key, jwt_r, jwt_a, time_r, time_a) VALUES (?, ?, ?, ?, ?, ?)";
|
||||
PreparedStatement insertStmt = conn.prepareStatement(insertSql);
|
||||
insertStmt.setString(1, email);
|
||||
insertStmt.setString(2, key);
|
||||
insertStmt.setString(3, jwt_r);
|
||||
insertStmt.setString(4, jwt_a);
|
||||
insertStmt.setLong(5, time_r); // Время в секундах
|
||||
insertStmt.setLong(6, time_a); // Время в секундах
|
||||
insertStmt.executeUpdate();
|
||||
insertStmt.close();
|
||||
}
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
logger.error("SQLite query execution error", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//Получаю пароль для токена обновления из базы
|
||||
public String getKey(String email){
|
||||
String key="";
|
||||
try {
|
||||
PreparedStatement pstmt = conn.prepareStatement("SELECT key FROM _users WHERE email=?");
|
||||
pstmt.setString(1, email);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
if (rs.next()) {
|
||||
key = rs.getString("key");
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
logger.error("SQLite query execution error", e);
|
||||
}
|
||||
return key;
|
||||
}
|
||||
//Получаю время когда Refresh token "протухнет"
|
||||
public long getTime(String email){
|
||||
long time = 1;
|
||||
try {
|
||||
PreparedStatement pstmt = conn.prepareStatement("SELECT time_r FROM _users WHERE email=?");
|
||||
pstmt.setString(1, email);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
if (rs.next()) {
|
||||
time = rs.getLong("time_r");
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
logger.error("SQLite query execution error", e);
|
||||
}
|
||||
return time;
|
||||
}
|
||||
//Удалить токен обновления из базы данных
|
||||
public boolean delToken(String email){
|
||||
try {
|
||||
PreparedStatement pstmt = conn.prepareStatement("DELETE FROM _users WHERE email=?");
|
||||
pstmt.setString(1, email);
|
||||
pstmt.executeUpdate();
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
logger.error("SQLite query execution error", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
197
src/main/java/org/ccalm/translation/tools/Tools.java
Normal file
197
src/main/java/org/ccalm/translation/tools/Tools.java
Normal file
@ -0,0 +1,197 @@
|
||||
package org.ccalm.translation.tools;
|
||||
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
import io.jsonwebtoken.security.Keys;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import javax.crypto.*;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
public class Tools {
|
||||
//---------------------------------------------------------------------------
|
||||
private static final Logger logger = LogManager.getLogger(Tools.class);
|
||||
//---------------------------------------------------------------------------
|
||||
public static JSONObject createJSONError(int code, String message, String setting, String marker) {
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
json.put("error_code", code);
|
||||
json.put("error_message", Arrays.asList(message));
|
||||
json.put("error_setting", Arrays.asList(setting));
|
||||
json.put("error_marker", marker);
|
||||
} catch (JSONException e) {
|
||||
logger.error(e);
|
||||
}
|
||||
return json;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
//Зашифровать
|
||||
public static String encryptText(String pass,String data){
|
||||
String encryptedBase64="";
|
||||
String encryptionIV = "jazz_tyt_net_111"; // Ваш вектор инициализации
|
||||
try {
|
||||
Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding");
|
||||
SecretKeySpec key = new SecretKeySpec(Base64.getDecoder().decode(pass), "AES");
|
||||
IvParameterSpec iv = new IvParameterSpec(encryptionIV.getBytes()); // Создание объекта IvParameterSpec для вектора инициализации
|
||||
cipher.init(Cipher.ENCRYPT_MODE, key, iv); // Инициализация шифра с ключом и вектором инициализации
|
||||
byte[] encrypted = cipher.doFinal(data.getBytes()); // Шифрование строки
|
||||
encryptedBase64 = Base64.getEncoder().encodeToString(encrypted); // Преобразование зашифрованных данных в base64
|
||||
} catch (InvalidKeyException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (InvalidAlgorithmParameterException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (NoSuchPaddingException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IllegalBlockSizeException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (BadPaddingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return encryptedBase64;
|
||||
}
|
||||
|
||||
public static String decryptText(String pass,String data){
|
||||
String encryptionIV = "jazz_tyt_net_111"; // Ваш вектор инициализации
|
||||
String decryptedText= "";
|
||||
try {
|
||||
Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding");
|
||||
SecretKeySpec key = new SecretKeySpec(Base64.getDecoder().decode(pass), "AES");
|
||||
IvParameterSpec iv = new IvParameterSpec(encryptionIV.getBytes()); // Создание объекта IvParameterSpec для вектора инициализации
|
||||
cipher.init(Cipher.DECRYPT_MODE, key, iv); // Инициализация шифра с ключом и вектором инициализации
|
||||
|
||||
byte[] decrypted = cipher.doFinal(Base64.getDecoder().decode(data)); // Расшифровка данных
|
||||
decryptedText = new String(decrypted); // Преобразование расшифрованных данных в строку
|
||||
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException |
|
||||
InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return decryptedText;
|
||||
}
|
||||
|
||||
public static String generateSignature(String pass,String input) {
|
||||
try {
|
||||
SecretKey secretKey = new SecretKeySpec(Base64.getDecoder().decode(pass), "HmacSHA256");
|
||||
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||
byte[] encodedInput = digest.digest(input.getBytes(StandardCharsets.UTF_8));
|
||||
byte[] encodedKey = secretKey.getEncoded();
|
||||
|
||||
// Создание HMAC-подписи
|
||||
SecretKeySpec keySpec = new SecretKeySpec(encodedKey, "HmacSHA256");
|
||||
Mac mac = Mac.getInstance("HmacSHA256");
|
||||
mac.init(keySpec);
|
||||
byte[] rawHmac = mac.doFinal(encodedInput);
|
||||
|
||||
// Кодирование подписи в base64
|
||||
return Base64.getEncoder().encodeToString(rawHmac);
|
||||
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isValidEmail(String email) {
|
||||
if(email==null || email.isEmpty()) return false;
|
||||
String EMAIL_REGEX = "^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$";
|
||||
Pattern pattern = Pattern.compile(EMAIL_REGEX);
|
||||
Matcher matcher = pattern.matcher(email);
|
||||
return matcher.matches();
|
||||
}
|
||||
|
||||
public static boolean isInteger(String str) {
|
||||
if (str == null || str.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
Integer.parseInt(str);
|
||||
return true;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static String genKey(){
|
||||
SecretKey key = Keys.secretKeyFor(SignatureAlgorithm.HS256);
|
||||
byte[] keyBytes = key.getEncoded();
|
||||
return Base64.getEncoder().encodeToString(keyBytes);
|
||||
}
|
||||
|
||||
public static String generatePassword(int length) {
|
||||
String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
SecureRandom random = new SecureRandom();
|
||||
StringBuilder sb = new StringBuilder(length);
|
||||
for (int i = 0; i < length; i++) {
|
||||
int randomIndex = random.nextInt(CHARACTERS.length());
|
||||
sb.append(CHARACTERS.charAt(randomIndex));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
// Метод для извлечения подписи из JWT токена
|
||||
public static String extractSignature(String jwtToken) {
|
||||
String[] jwtParts = jwtToken.split("\\.");
|
||||
if (jwtParts.length != 3) {
|
||||
return null;
|
||||
}
|
||||
return jwtParts[2];
|
||||
}
|
||||
|
||||
//Для извлечения содержимого токена
|
||||
public static JSONObject extractToken(String jwtToken) {
|
||||
String[] jwtParts = jwtToken.split("\\.");
|
||||
if (jwtParts.length != 3) {
|
||||
return null;
|
||||
}
|
||||
String payloadJson = new String(Base64.getUrlDecoder().decode(jwtParts[1]));
|
||||
JSONObject payload=null;
|
||||
try {
|
||||
payload = new JSONObject(payloadJson);
|
||||
} catch (JSONException e) {
|
||||
return null;
|
||||
}
|
||||
return payload;
|
||||
}
|
||||
|
||||
// Метод для отправки POST-запроса с JSON-телом
|
||||
public static String getURLText(String urlStr, String jsonBody) throws IOException {
|
||||
|
||||
URL url = new URL(urlStr);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setRequestProperty("Content-Type", "application/json; utf-8");
|
||||
conn.setDoOutput(true);
|
||||
|
||||
// Отправка тела запроса
|
||||
try (OutputStream os = conn.getOutputStream()) {
|
||||
byte[] input = jsonBody.getBytes("utf-8");
|
||||
os.write(input, 0, input.length);
|
||||
}
|
||||
|
||||
// Чтение ответа
|
||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"))) {
|
||||
StringBuilder response = new StringBuilder();
|
||||
String responseLine;
|
||||
while ((responseLine = br.readLine()) != null) {
|
||||
response.append(responseLine.trim());
|
||||
}
|
||||
return response.toString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
BIN
src/main/resources/keystore.jks
Normal file
BIN
src/main/resources/keystore.jks
Normal file
Binary file not shown.
32
src/main/resources/logback-spring.xml
Normal file
32
src/main/resources/logback-spring.xml
Normal file
@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
|
||||
<property name="LOGS" value="logs" />
|
||||
<springProperty scope="context" name="appName" source="spring.application.name"/>
|
||||
|
||||
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${LOGS}/${appName}.log</file>
|
||||
<encoder>
|
||||
<pattern>{"timestamp":"%d{yyyy-MM-dd'T'HH:mm:ss.SSS'Z'}","thread":"[%thread]","level":"%level","logger":"%logger{36}","message":"%msg"}%n</pattern>
|
||||
</encoder>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${LOGS}/${appName}.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
|
||||
<maxFileSize>100MB</maxFileSize>
|
||||
<maxHistory>30</maxHistory>
|
||||
<totalSizeCap>3GB</totalSizeCap>
|
||||
</rollingPolicy>
|
||||
</appender>
|
||||
|
||||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSS'Z'} | %level | %logger{36} | %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!--root level="info"-->
|
||||
<root level="warn">
|
||||
<appender-ref ref="FILE" />
|
||||
<appender-ref ref="CONSOLE" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
||||
@ -0,0 +1,13 @@
|
||||
package org.ccalm.translation;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class TranslationApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user