Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
Import registry records
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
3
Issues
3
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
develop
Import registry records
Commits
9aab783b
Commit
9aab783b
authored
Sep 25, 2019
by
Alina Habibulina
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[
#2
] Version 2
parent
9032954f
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
218 additions
and
160 deletions
+218
-160
build.gradle
build.gradle
+5
-3
src/main/java/kz/arta/ext/sap/db/ClientManager.java
src/main/java/kz/arta/ext/sap/db/ClientManager.java
+0
-64
src/main/java/kz/arta/ext/sap/util/HTTPRequestUtils.java
src/main/java/kz/arta/ext/sap/util/HTTPRequestUtils.java
+61
-33
src/main/java/kz/arta/ext/sap/util/ImportBean.java
src/main/java/kz/arta/ext/sap/util/ImportBean.java
+65
-16
src/main/webapp/WEB-INF/jboss-deployment-structure.xml
src/main/webapp/WEB-INF/jboss-deployment-structure.xml
+0
-9
src/main/webapp/index.html
src/main/webapp/index.html
+77
-34
src/main/webapp/index.js
src/main/webapp/index.js
+10
-1
No files found.
build.gradle
View file @
9aab783b
...
...
@@ -16,14 +16,13 @@ dependencies {
compile
(
group:
'org.slf4j'
,
name:
'slf4j-api'
,
version:
'1.7.25'
,
transitive:
false
)
compile
'org.apache.httpcomponents:httpclient:4.5.1'
compile
group:
'org.jboss.resteasy'
,
name:
'resteasy-jaxrs'
,
version:
'3.8.0.Final'
providedCompile
(
group:
'org.jboss.resteasy'
,
name:
'resteasy-jaxrs'
,
version:
'3.8.0.Final'
)
// https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-multipart-provider
compile
group:
'org.jboss.resteasy'
,
name:
'resteasy-multipart-provider'
,
version:
'3.8.0.Final'
providedCompile
(
group:
'org.jboss.resteasy'
,
name:
'resteasy-multipart-provider'
,
version:
'3.8.0.Final'
)
// https://mvnrepository.com/artifact/commons-io/commons-io
compile
group:
'commons-io'
,
name:
'commons-io'
,
version:
'2.6'
compile
(
'org.jboss.spec:jboss-javaee-7.0:1.1.1.Final'
)
// https://mvnrepository.com/artifact/org.apache.poi/poi
providedCompile
group:
'org.jboss.spec.javax.ejb'
,
name:
'jboss-ejb-api_3.2_spec'
,
version:
'1.0.2.Final'
compile
group:
'org.apache.poi'
,
name:
'poi'
,
version:
'3.9'
// https://mvnrepository.com/artifact/com.google.code.gson/gson
compile
group:
'com.google.code.gson'
,
name:
'gson'
,
version:
'2.7'
...
...
@@ -31,5 +30,8 @@ dependencies {
compile
group:
'joda-time'
,
name:
'joda-time'
,
version:
'2.10.3'
// https://mvnrepository.com/artifact/org.json/json
compile
group:
'org.json'
,
name:
'json'
,
version:
'20180813'
compile
group:
'org.apache.httpcomponents'
,
name:
'httpcore'
,
version:
'4.4.12'
compile
group:
'org.apache.httpcomponents'
,
name:
'httpclient'
,
version:
'4.5.10'
compile
group:
'org.apache.commons'
,
name:
'commons-lang3'
,
version:
'3.9'
}
\ No newline at end of file
src/main/java/kz/arta/ext/sap/db/ClientManager.java
deleted
100644 → 0
View file @
9032954f
package
kz.arta.ext.sap.db
;
import
kz.arta.ext.sap.util.ConnectionPool
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
javax.naming.NamingException
;
import
java.sql.Connection
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
/**
*
* Пример класса для работы с СУБД
* использует соединение, указанное в @{@link ConnectionPool}
*/
public
class
ClientManager
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
ClientManager
.
class
);
public
static
void
log
(
Object
logItem
)
{
Connection
con
=
null
;
try
{
con
=
ConnectionPool
.
getConnection
();
PreparedStatement
st
=
con
.
prepareStatement
(
"INSERT INTO log(logged, clientid, hostname, extip, localip) VALUES (CURRENT_TIMESTAMP, ?, ?, ?, ?)"
);
st
.
setString
(
1
,
"clientId"
);
st
.
setString
(
2
,
"hostname"
);
st
.
setString
(
3
,
"extip"
);
st
.
setString
(
4
,
"localip"
);
st
.
execute
();
}
catch
(
SQLException
|
NamingException
e
)
{
LOGGER
.
error
(
""
,
e
);
}
finally
{
ConnectionPool
.
close
(
con
);
}
}
public
static
String
getFormDefinition
(
String
registryCode
)
{
Connection
con
=
null
;
try
{
con
=
ConnectionPool
.
getConnection
();
PreparedStatement
ps
=
con
.
prepareStatement
(
"SELECT asf_definition.definition FROM asf_definition JOIN registries ON registries.formid = asf_definition.uuid WHERE registries.code = ? "
);
ps
.
setString
(
1
,
registryCode
);
ResultSet
rs
=
ps
.
executeQuery
();
while
(
rs
.
next
())
{
return
"{"
+
rs
.
getString
(
"asf_definition.definition"
)
+
"}"
;
}
}
catch
(
SQLException
|
NamingException
e
)
{
LOGGER
.
error
(
""
,
e
);
}
finally
{
ConnectionPool
.
close
(
con
);
}
return
null
;
}
}
\ No newline at end of file
src/main/java/kz/arta/ext/sap/util/HTTPRequestUtils.java
View file @
9aab783b
...
...
@@ -2,11 +2,12 @@ package kz.arta.ext.sap.util;
import
com.sun.org.apache.xerces.internal.impl.dv.util.Base64
;
import
org.apache.http.Consts
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.client.HttpClient
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.entity.StringEntity
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.DefaultHttpClient
;
import
javax.ejb.TransactionAttribute
;
...
...
@@ -19,56 +20,83 @@ public class HTTPRequestUtils {
@TransactionAttribute
(
TransactionAttributeType
.
REQUIRES_NEW
)
public
static
String
sendGet
(
String
url
,
String
login
,
String
password
)
throws
Exception
{
HttpClient
client
=
new
DefaultHttpClient
();
HttpGet
request
=
new
HttpGet
(
url
);
CloseableHttpClient
client
=
new
DefaultHttpClient
();
InputStreamReader
isr
=
null
;
BufferedReader
rd
=
null
;
String
usernameColonPassword
=
login
+
":"
+
password
;
String
basicAuthPayload
=
"Basic "
+
Base64
.
encode
(
usernameColonPassword
.
getBytes
(
"UTF-8"
));
request
.
addHeader
(
"Authorization"
,
basicAuthPayload
);
try
{
HttpResponse
response
=
client
.
execute
(
request
);
HttpGet
request
=
new
HttpGet
(
url
);
BufferedReader
rd
=
new
BufferedReader
(
new
InputStreamReader
(
response
.
getEntity
().
getContent
()));
String
usernameColonPassword
=
login
+
":"
+
password
;
String
basicAuthPayload
=
"Basic "
+
Base64
.
encode
(
usernameColonPassword
.
getBytes
(
"UTF-8"
));
request
.
addHeader
(
"Authorization"
,
basicAuthPayload
);
StringBuffer
result
=
new
StringBuffer
();
String
line
=
""
;
while
((
line
=
rd
.
readLine
())
!=
null
)
{
result
.
append
(
line
);
}
HttpResponse
response
=
client
.
execute
(
request
);
request
.
completed
();
isr
=
new
InputStreamReader
(
response
.
getEntity
().
getContent
());
rd
=
new
BufferedReader
(
isr
);
StringBuffer
result
=
new
StringBuffer
();
String
line
=
""
;
while
((
line
=
rd
.
readLine
())
!=
null
)
{
result
.
append
(
line
);
}
return
result
.
toString
();
return
result
.
toString
();
}
finally
{
isr
.
close
();
rd
.
close
();
client
.
close
();
}
}
@TransactionAttribute
(
TransactionAttributeType
.
REQUIRES_NEW
)
public
static
String
sendPost
(
String
url
,
String
json
,
String
login
,
String
password
)
throws
Exception
{
HttpClient
client
=
new
DefaultHttpClient
();
HttpPost
request
=
new
HttpPost
(
url
);
CloseableHttpClient
client
=
new
DefaultHttpClient
();
InputStreamReader
isr
=
null
;
BufferedReader
rd
=
null
;
String
usernameColonPassword
=
login
+
":"
+
password
;
String
basicAuthPayload
=
"Basic "
+
Base64
.
encode
(
usernameColonPassword
.
getBytes
(
"UTF-8"
));
request
.
addHeader
(
"Authorization"
,
basicAuthPayload
);
try
{
request
.
setHeader
(
"Content-type"
,
"application/json; charset=utf-8"
);
StringEntity
entity
=
new
StringEntity
(
json
);
request
.
setEntity
(
entity
);
client
=
new
DefaultHttpClient
();
HttpPost
request
=
new
HttpPost
(
url
);
client
.
execute
(
request
);
String
usernameColonPassword
=
login
+
":"
+
password
;
String
basicAuthPayload
=
"Basic "
+
Base64
.
encode
(
usernameColonPassword
.
getBytes
(
"UTF-8"
));
request
.
addHeader
(
"Authorization"
,
basicAuthPayload
);
HttpResponse
response
=
client
.
execute
(
request
);
request
.
setHeader
(
"Content-type"
,
"application/json; charset=utf-8"
);
StringEntity
entity
=
new
StringEntity
(
json
,
Consts
.
UTF_8
);
request
.
setEntity
(
entity
);
BufferedReader
rd
=
new
BufferedReader
(
new
InputStreamReader
(
response
.
getEntity
().
getContent
())
);
HttpResponse
response
=
client
.
execute
(
request
);
request
.
completed
(
);
StringBuffer
result
=
new
StringBuffer
();
String
line
=
""
;
while
((
line
=
rd
.
readLine
())
!=
null
)
{
result
.
append
(
line
);
}
isr
=
new
InputStreamReader
(
response
.
getEntity
().
getContent
());
rd
=
new
BufferedReader
(
isr
);
StringBuffer
result
=
new
StringBuffer
();
String
line
=
""
;
while
((
line
=
rd
.
readLine
())
!=
null
)
{
result
.
append
(
line
);
}
return
result
.
toString
();
return
result
.
toString
();
}
finally
{
isr
.
close
();
rd
.
close
();
client
.
close
();
}
}
}
src/main/java/kz/arta/ext/sap/util/ImportBean.java
View file @
9aab783b
package
kz.arta.ext.sap.util
;
import
com.google.gson.*
;
import
org.apache.commons.lang3.StringEscapeUtils
;
import
org.apache.poi.hssf.usermodel.HSSFWorkbook
;
import
org.apache.poi.ss.usermodel.*
;
import
org.json.JSONObject
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -113,25 +113,22 @@ public class ImportBean {
String
jsonData
=
"["
;
int
i
=
0
;
for
(
FormField
ff
:
data
){
//добавляем поля в json
//ПОКА ЧТО Я НЕ РЕАЛИЗОВАЛА ИХ ПАРСИНГ И ФОРМАТИРОВАНИЕ
jsonData
+=
"{ \"id\": "
+
JSONObject
.
quote
(
ff
.
getCode
())
+
", \"type\": "
+
JSONObject
.
quote
(
ff
.
getType
());
jsonData
+=
"{ \"id\": \""
+
ff
.
getCode
()
+
"\", \"type\": \""
+
ff
.
getType
()
+
"\""
;
//если это словарь и не чек бокс, нужно просто задать ему значение key
if
(
ff
.
getType
().
equals
(
FormFieldType
.
LISTBOX
.
value
)){
jsonData
+=
", \"key\":
"
+
JSONObject
.
quote
(
ff
.
getKey
())
+
", \"value\": "
+
JSONObject
.
quote
(
ff
.
getValue
())
;
jsonData
+=
", \"key\":
\""
+
ff
.
getKey
()
+
"\", \"value\": \""
+
ff
.
getValue
()
+
"\""
;
}
else
if
(
ff
.
getType
().
equals
(
FormFieldType
.
RADIO
.
value
)){
jsonData
+=
", \"key\":
"
+
JSONObject
.
quote
(
ff
.
getValue
())
+
", \"value\": "
+
JSONObject
.
quote
(
ff
.
getKey
())
;
jsonData
+=
", \"key\":
\""
+
ff
.
getValue
()
+
"\", \"value\": \""
+
ff
.
getKey
()
+
"\""
;
}
else
if
(
ff
.
getType
().
equals
(
FormFieldType
.
CHECKBOX
.
value
)){
jsonData
+=
", \"values\": ["
;
for
(
String
key
:
ff
.
getKeys
()){
jsonData
+=
JSONObject
.
quote
(
key
)
;
jsonData
+=
"\""
+
key
+
"\""
;
if
(
key
!=
ff
.
getKeys
().
get
(
ff
.
getKeys
().
size
()
-
1
)){
jsonData
+=
", "
;
...
...
@@ -140,7 +137,7 @@ public class ImportBean {
jsonData
+=
"], \"keys\": ["
;
for
(
String
val
:
ff
.
getValues
()){
jsonData
+=
JSONObject
.
quote
(
val
)
;
jsonData
+=
"\""
+
val
+
"\""
;
if
(
val
!=
ff
.
getValues
().
get
(
ff
.
getValues
().
size
()
-
1
)){
jsonData
+=
", "
;
...
...
@@ -152,27 +149,27 @@ public class ImportBean {
}
else
if
(
ff
.
getType
().
equals
(
FormFieldType
.
NUMERICINPUT
.
value
)){
jsonData
+=
", \"key\":
"
+
JSONObject
.
quote
(
ff
.
getValue
())
+
", \"value\": "
+
JSONObject
.
quote
(
ff
.
getValue
())
;
jsonData
+=
", \"key\":
\""
+
ff
.
getValue
()
+
"\", \"value\": \""
+
ff
.
getValue
()
+
"\""
;
}
else
if
(
ff
.
getType
().
equals
(
FormFieldType
.
REGLINK
.
value
)){
if
(
ff
.
getKey
()
!=
null
)
{
jsonData
+=
", \"key\":
"
+
JSONObject
.
quote
(
ff
.
getKey
())
+
", \"value\": "
+
JSONObject
.
quote
(
ff
.
getValue
())
+
", \"valueID\": "
+
JSONObject
.
quote
(
ff
.
getKey
())
;
jsonData
+=
", \"key\":
\""
+
ff
.
getKey
()
+
"\", \"value\": \""
+
ff
.
getValue
()
+
"\", \"valueID\": \""
+
ff
.
getKey
()
+
"\""
;
}
}
else
if
(
ff
.
getType
().
equals
(
FormFieldType
.
ENTITY
.
value
)){
jsonData
+=
", \"value\":
"
+
JSONObject
.
quote
(
ff
.
getValue
())
;
jsonData
+=
", \"value\":
\""
+
ff
.
getValue
()
+
"\""
;
}
else
if
(
ff
.
getType
().
equals
(
FormFieldType
.
DATE
.
value
)){
String
value
=
formatDate
(
ff
.
getDateFormat
(),
ff
.
getKey
());
jsonData
+=
", \"key\":
"
+
JSONObject
.
quote
(
ff
.
getKey
())
+
", \"value\": "
+
JSONObject
.
quote
(
value
)
;
jsonData
+=
", \"key\":
\""
+
ff
.
getKey
()
+
"\", \"value\": \""
+
value
+
"\""
;
}
else
{
//если текстовое поле
jsonData
+=
", \"value\":
"
+
JSONObject
.
quote
(
ff
.
getValue
())
;
jsonData
+=
", \"value\":
\""
+
ff
.
getValue
()
+
"\""
;
}
...
...
@@ -225,11 +222,12 @@ public class ImportBean {
Cell
cell
=
iter
.
next
();
CellValue
cellValue
=
evaluator
.
evaluate
(
cell
);
if
(
cellValue
==
null
||
cellValue
.
equals
(
""
))
continue
;
//получили заголовок ячейки
String
header
=
cell
.
getSheet
().
getRow
(
0
).
getCell
(
cell
.
getColumnIndex
()).
getRichStringCellValue
().
toString
();
if
(
header
.
equals
(
NO
))
{
if
(
header
.
equals
(
NO
)
||
header
.
equals
(
""
)
)
{
continue
;
}
...
...
@@ -262,7 +260,8 @@ public class ImportBean {
if
(
cellValue
.
getStringValue
()
==
null
||
cellValue
.
getStringValue
().
equals
(
""
))
{
continue
;
}
String
value
=
cellValue
.
getStringValue
().
replaceAll
(
"\""
,
"\\\\\""
);
String
value
=
StringEscapeUtils
.
escapeJson
(
cellValue
.
getStringValue
());
if
(
value
.
equals
(
""
))
continue
;
valueFF
.
setValue
(
value
);
break
;
case
Cell
.
CELL_TYPE_BLANK
:
...
...
@@ -586,6 +585,56 @@ public class ImportBean {
}
public
static
String
escapeAllSpecialSymbols
(
String
string
)
{
if
(
string
==
null
||
string
.
length
()
==
0
)
{
return
""
;
}
char
c
=
0
;
int
i
;
int
len
=
string
.
length
();
StringBuilder
sb
=
new
StringBuilder
(
len
+
4
);
String
t
;
for
(
i
=
0
;
i
<
len
;
i
+=
1
)
{
c
=
string
.
charAt
(
i
);
switch
(
c
)
{
case
'\\'
:
case
'"'
:
sb
.
append
(
'\\'
);
sb
.
append
(
c
);
break
;
case
'/'
:
sb
.
append
(
'\\'
);
sb
.
append
(
c
);
break
;
case
'\b'
:
sb
.
append
(
"\\b"
);
break
;
case
'\t'
:
sb
.
append
(
"\\t"
);
break
;
case
'\n'
:
sb
.
append
(
"\\n"
);
break
;
case
'\f'
:
sb
.
append
(
"\\f"
);
break
;
case
'\r'
:
sb
.
append
(
"\\r"
);
break
;
default
:
if
(
c
<
' '
)
{
t
=
"000"
+
Integer
.
toHexString
(
c
);
sb
.
append
(
"\\u"
+
t
.
substring
(
t
.
length
()
-
4
));
}
else
{
sb
.
append
(
c
);
}
}
}
return
sb
.
toString
();
}
@PreDestroy
public
void
destroy
()
{
executor
.
shutdown
();
...
...
src/main/webapp/WEB-INF/jboss-deployment-structure.xml
deleted
100644 → 0
View file @
9032954f
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module
name=
"org.codehaus.jackson.jackson-jaxrs"
/>
<module
name=
"org.codehaus.jackson.jackson-mapper-asl"
/>
</dependencies>
</deployment>
</jboss-deployment-structure>
src/main/webapp/index.html
View file @
9aab783b
This diff is collapsed.
Click to expand it.
src/main/webapp/index.js
View file @
9aab783b
...
...
@@ -18,6 +18,15 @@ $(document).ready(function(){
});
$
(
"
#instructions-button
"
).
click
(
function
(){
if
(
$
(
"
#instructions-block
"
).
hasClass
(
"
ib-open
"
)){
$
(
"
#instructions-block
"
).
removeClass
(
"
ib-open
"
);
$
(
"
#instructions-block
"
).
addClass
(
"
ib-close
"
);
}
else
{
$
(
"
#instructions-block
"
).
removeClass
(
"
ib-close
"
);
$
(
"
#instructions-block
"
).
addClass
(
"
ib-open
"
);
}
});
$
(
"
#start_import
"
).
click
(
function
(){
...
...
@@ -48,7 +57,7 @@ $(document).ready(function(){
fd
.
append
(
'
file
'
,
file
.
prop
(
'
files
'
)[
0
]);
$
.
ajax
({
url
:
window
.
location
.
origin
+
"
/import/
import
/registry/import_file?formcode=
"
+
formCode
+
"
®istrycode=
"
+
regCode
url
:
window
.
location
.
origin
+
"
/import/
api
/registry/import_file?formcode=
"
+
formCode
+
"
®istrycode=
"
+
regCode
+
"
&activate=
"
+
isActivate
+
"
&action=
"
+
action
+
"
&defaultValue=
"
+
defaultValue
+
"
&searchString=
"
+
searchString
,
data
:
fd
,
beforeSend
:
function
(
xhr
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment