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
b4b09319
Commit
b4b09319
authored
Nov 14, 2016
by
Raimbek Egemberdiev
Browse files
Options
Browse Files
Download
Plain Diff
рефакторинг импорта завершена
parents
e204aeb0
a132f0a8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
218 additions
and
0 deletions
+218
-0
src/main/java/kz/arta/synergy/api/services/StorageService.java
...ain/java/kz/arta/synergy/api/services/StorageService.java
+76
-0
src/main/java/kz/arta/synergy/api/services/storage/Attachment.java
...java/kz/arta/synergy/api/services/storage/Attachment.java
+87
-0
src/main/java/kz/arta/synergy/api/services/storage/AttachmentList.java
.../kz/arta/synergy/api/services/storage/AttachmentList.java
+11
-0
src/test/java/kz/arta/synergy/api/services/StorageServiceTest.java
...java/kz/arta/synergy/api/services/StorageServiceTest.java
+44
-0
No files found.
src/main/java/kz/arta/synergy/api/services/StorageService.java
0 → 100644
View file @
b4b09319
package
kz.arta.synergy.api.services
;
import
kz.arta.synergy.api.JsonUtils
;
import
kz.arta.synergy.api.Query
;
import
kz.arta.synergy.api.QueryContext
;
import
kz.arta.synergy.api.RestHttpQuery
;
import
kz.arta.synergy.api.services.storage.Attachment
;
import
kz.arta.synergy.api.services.storage.AttachmentList
;
import
java.io.IOException
;
/**
* Created by: Abzal Kultayev
* Date: 12.11.16
* Time: 16:37
*/
public
class
StorageService
{
private
final
RestHttpQuery
restHttpQuery
;
private
StorageService
(
QueryContext
context
)
{
this
.
restHttpQuery
=
new
RestHttpQuery
(
context
);
}
public
static
StorageService
newInstance
(
QueryContext
context
)
{
return
new
StorageService
(
context
);
}
/**
* Создает временный файл на сервере
* @return Возвращает путь временного файла на сервере
* @throws IOException
*/
public
String
startUploadFile
()
throws
IOException
{
Query
query
=
Query
.
newInstance
().
url
(
"/rest/api/storage/start_upload"
);
String
result
=
restHttpQuery
.
doQuery
(
query
);
return
JsonUtils
.
getValueByKey
(
result
,
"file"
);
}
/**
* Метод добавляет вложение к документу из временного файла, загруженного на сервер с помощью API метода rest/api/storage/start_upload
* @param documentID идентификатор документа
* @param filename название файла
* @param filepath путь до файла на сервере
* @return errorCode и errorMessage
* @throws IOException при проблеммах с сетью
*/
public
String
createAttachment
(
String
documentID
,
String
filename
,
String
filepath
)
throws
IOException
{
Query
query
=
Query
.
newInstance
()
.
methodPost
()
.
url
(
"/rest/api/docflow/doc/attachment/create"
)
.
formParam
(
"fileName"
,
filename
)
.
formParam
(
"filePath"
,
filepath
)
.
formParam
(
"path"
,
"ase:workContainer"
)
.
formParam
(
"documentID"
,
documentID
);
return
restHttpQuery
.
doQuery
(
query
);
}
public
Attachment
createAndGetAttachment
(
String
documentID
,
String
filename
,
String
filepath
)
throws
IOException
{
String
attachment
=
createAttachment
(
documentID
,
filename
,
filepath
);
if
(!
JsonUtils
.
getValueByKey
(
attachment
,
"errorCode"
).
equals
(
"0"
))
{
throw
new
IOException
(
"Attachment was not created"
);
}
AttachmentList
lastAttachments
=
getLastAttachments
(
documentID
);
return
lastAttachments
.
get
(
0
);
}
public
AttachmentList
getLastAttachments
(
String
documentID
)
throws
IOException
{
Query
query
=
Query
.
newInstance
()
.
url
(
"/rest/api/docflow/doc/last_attachments"
)
.
queryParam
(
"documentID"
,
documentID
);
return
JsonUtils
.
read
(
restHttpQuery
.
doQuery
(
query
),
AttachmentList
.
class
);
}
}
src/main/java/kz/arta/synergy/api/services/storage/Attachment.java
0 → 100644
View file @
b4b09319
package
kz.arta.synergy.api.services.storage
;
import
org.codehaus.jackson.annotate.JsonIgnoreProperties
;
import
org.codehaus.jackson.annotate.JsonProperty
;
/**
* Created by: Abzal Kultayev
* Date: 14.11.16
* Time: 13:19
*/
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
Attachment
{
private
String
uuid
;
private
String
dataUUID
;
private
boolean
mobile
;
private
String
name
;
@JsonProperty
(
"is_editable"
)
private
boolean
isEditable
;
@JsonProperty
(
"created_label"
)
private
String
createdLabel
;
private
String
created
;
private
String
icon
;
public
String
getUuid
()
{
return
uuid
;
}
public
void
setUuid
(
String
uuid
)
{
this
.
uuid
=
uuid
;
}
public
String
getDataUUID
()
{
return
dataUUID
;
}
public
void
setDataUUID
(
String
dataUUID
)
{
this
.
dataUUID
=
dataUUID
;
}
public
boolean
isMobile
()
{
return
mobile
;
}
public
void
setMobile
(
boolean
mobile
)
{
this
.
mobile
=
mobile
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
boolean
isEditable
()
{
return
isEditable
;
}
public
void
setEditable
(
boolean
editable
)
{
isEditable
=
editable
;
}
public
String
getCreatedLabel
()
{
return
createdLabel
;
}
public
void
setCreatedLabel
(
String
createdLabel
)
{
this
.
createdLabel
=
createdLabel
;
}
public
String
getCreated
()
{
return
created
;
}
public
void
setCreated
(
String
created
)
{
this
.
created
=
created
;
}
public
String
getIcon
()
{
return
icon
;
}
public
void
setIcon
(
String
icon
)
{
this
.
icon
=
icon
;
}
}
src/main/java/kz/arta/synergy/api/services/storage/AttachmentList.java
0 → 100644
View file @
b4b09319
package
kz.arta.synergy.api.services.storage
;
import
java.util.ArrayList
;
/**
* Created by: Abzal Kultayev
* Date: 14.11.16
* Time: 13:36
*/
public
class
AttachmentList
extends
ArrayList
<
Attachment
>
{
}
src/test/java/kz/arta/synergy/api/services/StorageServiceTest.java
0 → 100644
View file @
b4b09319
package
kz.arta.synergy.api.services
;
import
kz.arta.synergy.api.QueryContext
;
import
kz.arta.synergy.api.services.storage.Attachment
;
import
kz.arta.synergy.api.services.storage.AttachmentList
;
import
org.testng.annotations.Test
;
import
static
org
.
testng
.
Assert
.
assertEquals
;
import
static
org
.
testng
.
Assert
.
assertNotNull
;
/**
* Created by: Abzal Kultayev
* Date: 12.11.16
* Time: 16:56
*/
public
class
StorageServiceTest
{
StorageService
service
=
StorageService
.
newInstance
(
new
QueryContext
(
"http://192.168.3.233:8080/Synergy"
,
"NppAdmin"
,
"123456"
));
private
String
documentID
=
"05647530-a72f-11e6-bfd9-00163ebf20cd"
;
@Test
public
void
testStartUploadFile
()
throws
Exception
{
String
tempFileName
=
service
.
startUploadFile
();
assertNotNull
(
tempFileName
);
}
@Test
public
void
testCreateAttachment
()
throws
Exception
{
String
tempFileName
=
service
.
startUploadFile
();
String
attachment
=
service
.
createAttachment
(
documentID
,
"FILENAME.PDF"
,
tempFileName
);
assertEquals
(
attachment
,
""
);
}
@Test
public
void
testLastAttachments
()
throws
Exception
{
AttachmentList
attachmentList
=
service
.
getLastAttachments
(
documentID
);
assertNotNull
(
attachmentList
);
}
@Test
public
void
testCreateAndGetAttachment
()
throws
Exception
{
String
tempFileName
=
service
.
startUploadFile
();
Attachment
attachment
=
service
.
createAndGetAttachment
(
documentID
,
"Filename.pdf"
,
tempFileName
);
assertNotNull
(
attachment
);
}
}
\ No newline at end of file
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