Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
synergy-api-util
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Raimbek Egemberdiev
synergy-api-util
Commits
f6d27a3b
Commit
f6d27a3b
authored
Jan 30, 2017
by
Raimbek Egemberdiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new types and services
parent
86e24d85
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
130 additions
and
1 deletion
+130
-1
src/main/java/kz/arta/synergy/api/RestHttpQuery.java
src/main/java/kz/arta/synergy/api/RestHttpQuery.java
+4
-0
src/main/java/kz/arta/synergy/api/pojo/DocumentFullAttachments.java
...ava/kz/arta/synergy/api/pojo/DocumentFullAttachments.java
+34
-0
src/main/java/kz/arta/synergy/api/services/DocflowService.java
...ain/java/kz/arta/synergy/api/services/DocflowService.java
+15
-0
src/main/java/kz/arta/synergy/api/services/StorageService.java
...ain/java/kz/arta/synergy/api/services/StorageService.java
+77
-1
No files found.
src/main/java/kz/arta/synergy/api/RestHttpQuery.java
View file @
f6d27a3b
...
...
@@ -131,4 +131,8 @@ public class RestHttpQuery {
conn
.
setRequestProperty
(
"Authorization"
,
"Basic "
+
context
.
getAuthHeader
());
}
}
public
QueryContext
getContext
()
{
return
context
;
}
}
src/main/java/kz/arta/synergy/api/pojo/DocumentFullAttachments.java
0 → 100644
View file @
f6d27a3b
package
kz.arta.synergy.api.pojo
;
import
org.codehaus.jackson.annotate.JsonIgnoreProperties
;
import
org.codehaus.jackson.annotate.JsonProperty
;
import
java.util.List
;
/**
* @author raimbek
* @since 30.01.2017
*/
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
DocumentFullAttachments
{
private
List
<
Attachment
>
attachments
;
@JsonProperty
(
"work_files"
)
private
List
<
Attachment
>
workFiles
;
public
List
<
Attachment
>
getAttachments
()
{
return
attachments
;
}
public
void
setAttachments
(
List
<
Attachment
>
attachments
)
{
this
.
attachments
=
attachments
;
}
public
List
<
Attachment
>
getWorkFiles
()
{
return
workFiles
;
}
public
void
setWorkFiles
(
List
<
Attachment
>
workFiles
)
{
this
.
workFiles
=
workFiles
;
}
}
src/main/java/kz/arta/synergy/api/services/DocflowService.java
View file @
f6d27a3b
...
...
@@ -5,6 +5,7 @@ import kz.arta.synergy.api.Query;
import
kz.arta.synergy.api.QueryContext
;
import
kz.arta.synergy.api.RestHttpQuery
;
import
kz.arta.synergy.api.pojo.DocSend
;
import
kz.arta.synergy.api.pojo.DocumentFullAttachments
;
import
kz.arta.synergy.api.pojo.DocumentInfo
;
import
java.io.IOException
;
...
...
@@ -14,6 +15,8 @@ import java.io.IOException;
* @since 14.11.2016
*/
public
class
DocflowService
{
public
static
String
ATTACHMENT_CONTAINER
=
"ase:attachmentContainer"
;
public
static
String
WORK_CONTAINER
=
"ase:workContainer"
;
private
final
RestHttpQuery
restHttpQuery
;
...
...
@@ -33,10 +36,15 @@ public class DocflowService {
}
public
String
createDocAttachment
(
String
documentID
,
String
fileName
,
String
filePath
)
throws
IOException
{
return
createDocAttachment
(
documentID
,
null
,
fileName
,
filePath
);
}
public
String
createDocAttachment
(
String
documentID
,
String
path
,
String
fileName
,
String
filePath
)
throws
IOException
{
Query
query
=
Query
.
newInstance
()
.
methodPost
()
.
url
(
"/rest/api/docflow/doc/attachment/create"
)
.
formParam
(
"documentID"
,
documentID
)
.
formParam
(
"path"
,
path
)
.
formParam
(
"fileName"
,
fileName
)
.
formParam
(
"filePath"
,
filePath
);
return
restHttpQuery
.
doQuery
(
query
);
...
...
@@ -50,4 +58,11 @@ public class DocflowService {
.
body
(
JsonUtils
.
toJson
(
docSend
));
return
restHttpQuery
.
doQuery
(
query
);
}
public
DocumentFullAttachments
getFullAttachments
(
String
documentId
)
throws
IOException
{
Query
query
=
Query
.
newInstance
()
.
url
(
"/rest/api/docflow/doc/attachments"
)
.
queryParam
(
"documentID"
,
documentId
);
return
JsonUtils
.
read
(
restHttpQuery
.
doQuery
(
query
),
DocumentFullAttachments
.
class
);
}
}
src/main/java/kz/arta/synergy/api/services/StorageService.java
View file @
f6d27a3b
...
...
@@ -9,7 +9,11 @@ import kz.arta.synergy.api.pojo.Attachment;
import
kz.arta.synergy.api.pojo.AttachmentList
;
import
org.codehaus.jackson.type.TypeReference
;
import
java.io.IOException
;
import
javax.xml.bind.DatatypeConverter
;
import
java.io.*
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.net.URLEncoder
;
import
java.util.List
;
/**
...
...
@@ -153,4 +157,76 @@ public class StorageService {
.
queryParam
(
"inline"
,
"true"
);
return
restHttpQuery
.
doQueryAndReturnBytes
(
query
);
}
public
String
upload
(
String
fileName
,
InputStream
inputStream
,
String
serverTmpFile
)
{
String
boundary
=
"qweasdzxczxcasdqwe"
;
String
crlf
=
"\r\n"
;
String
twoHyphens
=
"--"
;
try
{
int
partSize
=
1024
*
100
;
byte
[]
bytes
=
new
byte
[
partSize
];
int
position
=
0
;
int
read
=
0
;
StringBuilder
stringBuilder
=
new
StringBuilder
();
URL
url
=
new
URL
(
restHttpQuery
.
getContext
().
getAddress
()
+
"/rest/api/storage/upload_part?file="
+
serverTmpFile
);
while
((
read
=
inputStream
.
read
(
bytes
,
0
,
partSize
))
!=
-
1
){
byte
[]
readBytes
=
new
byte
[
read
];
System
.
arraycopy
(
bytes
,
0
,
readBytes
,
0
,
read
);
position
+=
read
;
HttpURLConnection
conn
=
(
HttpURLConnection
)
url
.
openConnection
();
conn
.
setRequestMethod
(
"POST"
);
conn
.
setRequestProperty
(
"Accept"
,
"application/json; charset=utf-8"
);
conn
.
setRequestProperty
(
"Content-Type"
,
"multipart/form-data;boundary="
+
boundary
);
conn
.
setRequestProperty
(
"Connection"
,
"Keep-Alive"
);
conn
.
setRequestProperty
(
"Cache-Control"
,
"no-cache"
);
conn
.
setRequestProperty
(
"Authorization"
,
"Basic "
+
restHttpQuery
.
getContext
().
getAuthHeader
());
conn
.
setUseCaches
(
false
);
conn
.
setDoInput
(
true
);
conn
.
setDoOutput
(
true
);
DataOutputStream
request
=
new
DataOutputStream
(
conn
.
getOutputStream
());
request
.
writeBytes
(
twoHyphens
+
boundary
+
crlf
);
request
.
writeBytes
(
"Content-Disposition: form-data; name=\"body\";filename=\""
+
URLEncoder
.
encode
(
fileName
,
"utf-8"
)+
"\""
+
crlf
);
request
.
writeBytes
(
crlf
);
byte
[]
fileBytes
=
DatatypeConverter
.
printBase64Binary
(
readBytes
).
getBytes
();
request
.
write
(
fileBytes
);
request
.
writeBytes
(
crlf
);
request
.
writeBytes
(
twoHyphens
+
boundary
+
twoHyphens
+
crlf
);
request
.
flush
();
request
.
close
();
InputStream
is
=
conn
.
getInputStream
();
BufferedReader
rd
=
new
BufferedReader
(
new
InputStreamReader
(
is
));
String
line
;
StringBuilder
response
=
new
StringBuilder
();
while
((
line
=
rd
.
readLine
())
!=
null
)
{
response
.
append
(
line
);
response
.
append
(
'\r'
);
}
rd
.
close
();
stringBuilder
.
append
(
response
.
toString
());
}
return
stringBuilder
.
toString
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
inputStream
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
return
null
;
}
}
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