Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jh-boot
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jan Hrabal
jh-boot
Commits
7f98b693
Commit
7f98b693
authored
Nov 05, 2019
by
Jan Hrabal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
attachments
parent
6b5784b6
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
0 deletions
+47
-0
AttachmentService.java
src/main/java/com/jh/boot/attachment/AttachmentService.java
+47
-0
No files found.
src/main/java/com/jh/boot/attachment/AttachmentService.java
View file @
7f98b693
package
com
.
jh
.
boot
.
attachment
;
package
com
.
jh
.
boot
.
attachment
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.HashSet
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Set
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
...
@@ -60,5 +65,47 @@ public interface AttachmentService {
...
@@ -60,5 +65,47 @@ public interface AttachmentService {
}
}
public
default
<
C
extends
Collection
<
Attachment
>>
C
syncAttachments
(
String
objectType
,
Long
objectId
,
C
currentAttachments
,
C
newAttachments
,
MultipartFile
[]
files
,
Class
<
C
>
clazz
)
{
return
syncAttachments
(
null
,
objectType
,
objectId
,
currentAttachments
,
newAttachments
,
files
,
clazz
);
}
public
default
<
C
extends
Collection
<
Attachment
>>
C
syncAttachments
(
Long
unitId
,
String
objectType
,
Long
objectId
,
C
currentAttachments
,
C
newAttachments
,
MultipartFile
[]
files
,
Class
<
C
>
clazz
)
{
//decide whether Set or List
if
(
currentAttachments
==
null
)
{
if
(
Set
.
class
.
isAssignableFrom
(
clazz
))
{
currentAttachments
=
(
C
)
new
HashSet
<
Attachment
>();
}
else
if
(
List
.
class
.
isAssignableFrom
(
clazz
))
{
currentAttachments
=
(
C
)
new
ArrayList
<
Attachment
>();
}
else
{
throw
new
IllegalArgumentException
(
"Invalid collection type"
);
}
}
if
(
newAttachments
==
null
||
newAttachments
.
isEmpty
())
{
currentAttachments
.
clear
();
}
else
{
Iterator
<
Attachment
>
it
=
currentAttachments
.
iterator
();
while
(
it
.
hasNext
())
{
Attachment
a
=
it
.
next
();
if
(!
newAttachments
.
contains
(
a
))
{
it
.
remove
();
}
}
}
//TODO add attachments?
if
(
files
!=
null
&&
files
.
length
>
0
)
{
for
(
MultipartFile
f
:
files
)
{
currentAttachments
.
add
(
addAttachment
(
unitId
,
objectType
,
objectId
,
f
));
}
}
return
currentAttachments
;
}
}
}
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