Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openbis
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sispub
openbis
Commits
01bff5ba
Commit
01bff5ba
authored
6 years ago
by
felmer
Browse files
Options
Downloads
Patches
Plain Diff
SSDM-7430: handle all cases for attachments: add, update, delete
parent
121210c2
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
datastore_server/source/java/ch/ethz/sis/openbis/generic/server/dss/plugins/sync/harvester/synchronizer/parallelizedExecutor/AttachmentsSynchronizer.java
+77
-58
77 additions, 58 deletions
...ronizer/parallelizedExecutor/AttachmentsSynchronizer.java
with
77 additions
and
58 deletions
datastore_server/source/java/ch/ethz/sis/openbis/generic/server/dss/plugins/sync/harvester/synchronizer/parallelizedExecutor/AttachmentsSynchronizer.java
+
77
−
58
View file @
01bff5ba
...
...
@@ -33,6 +33,7 @@ import ch.ethz.sis.openbis.generic.asapi.v3.IApplicationServerApi;
import
ch.ethz.sis.openbis.generic.asapi.v3.dto.attachment.Attachment
;
import
ch.ethz.sis.openbis.generic.asapi.v3.dto.attachment.create.AttachmentCreation
;
import
ch.ethz.sis.openbis.generic.asapi.v3.dto.attachment.fetchoptions.AttachmentFetchOptions
;
import
ch.ethz.sis.openbis.generic.asapi.v3.dto.attachment.id.AttachmentFileName
;
import
ch.ethz.sis.openbis.generic.asapi.v3.dto.attachment.update.AttachmentListUpdateValue
;
import
ch.ethz.sis.openbis.generic.asapi.v3.dto.common.interfaces.IAttachmentsHolder
;
import
ch.ethz.sis.openbis.generic.asapi.v3.dto.common.interfaces.IPermIdHolder
;
...
...
@@ -63,7 +64,7 @@ public class AttachmentsSynchronizer implements ITaskExecutor<List<IncomingEntit
private
Map
<
SyncEntityKind
,
AbstractHandler
>
handlersByEntityKind
;
public
AttachmentsSynchronizer
(
IApplicationServerApi
v3api
,
String
sessionToken
,
IApplicationServerApi
v3apiDataSource
,
String
sessionTokenDataSource
,
Date
lastSyncTimestamp
,
IApplicationServerApi
v3apiDataSource
,
String
sessionTokenDataSource
,
Date
lastSyncTimestamp
,
AttachmentSynchronizationSummary
synchronizationSummary
)
{
handlersByEntityKind
=
new
HashMap
<>();
...
...
@@ -127,9 +128,9 @@ public class AttachmentsSynchronizer implements ITaskExecutor<List<IncomingEntit
protected
IApplicationServerApi
v3apiDataSource
;
protected
String
sessionTokenDataSource
;
protected
Date
lastSyncTimestamp
;
protected
AttachmentSynchronizationSummary
synchronizationSummary
;
public
void
setV3api
(
IApplicationServerApi
v3api
)
...
...
@@ -168,15 +169,14 @@ public class AttachmentsSynchronizer implements ITaskExecutor<List<IncomingEntit
List
<
IncomingEntity
<?>>
filteredEntities
=
entities
.
stream
().
filter
(
e
->
e
.
hasAttachments
()).
collect
(
Collectors
.
toList
());
Map
<
String
,
Map
<
String
,
Attachment
>>
attachmentsFromDataSource
=
retrievAttachments
(
v3apiDataSource
,
sessionTokenDataSource
,
filteredEntities
);
List
<
NewAttachment
>
newAttachments
=
new
ArrayList
<>();
List
<
AttachmentReplacement
>
attachmentReplacements
=
new
ArrayList
<>();
List
<
AttachmentChange
>
attachmentChanges
=
new
ArrayList
<>();
for
(
Entry
<
String
,
Map
<
String
,
Attachment
>>
entry
:
attachmentsFromDataSource
.
entrySet
())
{
String
permId
=
entry
.
getKey
();
Map
<
String
,
Attachment
>
existingAttachmentsByFile
=
existingAttachments
.
get
(
permId
);
if
(
existingAttachmentsByFile
==
null
)
{
throw
new
RuntimeException
(
"Severe error: Entity with permId "
+
permId
throw
new
RuntimeException
(
"Severe error: Entity with permId "
+
permId
+
" should exist because it has been just registered on the harvester openBIS instance."
);
}
Map
<
String
,
Attachment
>
attachmentsFromDataSourceByFile
=
entry
.
getValue
();
...
...
@@ -188,31 +188,33 @@ public class AttachmentsSynchronizer implements ITaskExecutor<List<IncomingEntit
int
version
=
existingAttachment
==
null
?
0
:
existingAttachment
.
getVersion
();
if
(
attachmentFromDataSource
.
getVersion
()
<
version
)
{
attachmentReplacements
.
add
(
new
AttachmentReplacement
(
attachmentFromDataSource
,
permId
));
attachmentChanges
.
add
(
new
AttachmentChange
(
attachmentFromDataSource
,
permId
,
true
,
0
));
synchronizationSummary
.
updatedCount
.
getAndIncrement
();
}
else
if
(
attachmentFromDataSource
.
getVersion
()
==
version
)
{
if
(
attachmentFromDataSource
.
getRegistrationDate
().
after
(
lastSyncTimestamp
))
{
attachmentReplacements
.
add
(
new
AttachmentReplacement
(
attachmentFromDataSource
,
permId
));
}
else
if
(
equals
(
attachmentFromDataSource
.
getTitle
(),
existingAttachment
.
getTitle
())
==
false
if
(
attachmentFromDataSource
.
getRegistrationDate
().
after
(
lastSyncTimestamp
)
||
equals
(
attachmentFromDataSource
.
getTitle
(),
existingAttachment
.
getTitle
())
==
false
||
equals
(
attachmentFromDataSource
.
getDescription
(),
existingAttachment
.
getDescription
())
==
false
)
{
// TODO: update attachment
attachmentChanges
.
add
(
new
AttachmentChange
(
attachmentFromDataSource
,
permId
,
true
,
0
));
synchronizationSummary
.
updatedCount
.
getAndIncrement
();
}
}
else
{
newAttachments
.
add
(
new
NewAttachment
(
attachmentFromDataSource
,
version
,
permId
));
attachmentChanges
.
add
(
new
AttachmentChange
(
attachmentFromDataSource
,
permId
,
false
,
version
));
synchronizationSummary
.
addedCount
.
getAndIncrement
();
}
}
for
(
Attachment
existingAttachment
:
existingAttachmentsByFile
.
values
())
{
if
(
attachmentsFromDataSourceByFile
.
get
(
existingAttachment
.
getFileName
())
==
null
)
{
// TODO: delete attachment
attachmentChanges
.
add
(
new
AttachmentChange
(
existingAttachment
,
permId
,
true
,
null
));
synchronizationSummary
.
deletedCount
.
getAndIncrement
();
}
}
}
handle
New
Attachment
s
(
newA
ttachments
);
handleAttachment
Changes
(
a
ttachment
Change
s
);
}
private
<
AH
extends
IPermIdHolder
&
IAttachmentsHolder
>
Map
<
String
,
Map
<
String
,
Attachment
>>
retrievAttachments
(
...
...
@@ -232,44 +234,55 @@ public class AttachmentsSynchronizer implements ITaskExecutor<List<IncomingEntit
protected
abstract
<
AH
extends
IPermIdHolder
&
IAttachmentsHolder
>
Collection
<
AH
>
getAttachments
(
IApplicationServerApi
v3api
,
String
sessionToken
,
List
<
String
>
permIds
);
private
void
handleAttachmentChanges
(
List
<
AttachmentChange
>
attachmentChanges
)
{
Map
<
String
,
AttachmentListUpdateValue
>
attachmentUpdatesByPermId
=
new
HashMap
<>();
for
(
AttachmentChange
attachmentChange:
attachmentChanges
)
{
String
permId
=
attachmentChange
.
getPermId
();
AttachmentListUpdateValue
attachmentListUpdateValue
=
attachmentUpdatesByPermId
.
get
(
permId
);
if
(
attachmentListUpdateValue
==
null
)
{
attachmentListUpdateValue
=
new
AttachmentListUpdateValue
();
attachmentUpdatesByPermId
.
put
(
permId
,
attachmentListUpdateValue
);
}
Attachment
attachment
=
attachmentChange
.
getAttachment
();
if
(
attachmentChange
.
isRemove
())
{
attachmentListUpdateValue
.
remove
(
new
AttachmentFileName
(
attachment
.
getFileName
()));
}
Integer
version
=
attachmentChange
.
getVersion
();
if
(
version
!=
null
)
{
addAttachments
(
attachmentListUpdateValue
,
attachment
,
version
);
}
}
handleAttachments
(
attachmentUpdatesByPermId
);
}
private
void
handleNewA
ttachment
s
(
List
<
New
Attachment
>
newA
ttachment
s
)
private
void
addAttachments
(
AttachmentListUpdateValue
a
ttachmentList
Update
,
Attachment
a
ttachment
,
int
fromVersion
)
{
Map
<
String
,
AttachmentListUpdateValue
>
attachmentCreationsByPermId
=
new
HashMap
<>();
List
<
AttachmentCreation
>
attachmentCreations
=
new
ArrayList
<>();
for
(
NewAttachment
newAttachment
:
newAttachments
)
for
(
int
i
=
attachment
.
getVersion
();
i
>
fromVersion
;
i
--
)
{
String
permId
=
newAttachment
.
getPermId
();
AttachmentListUpdateValue
attachmentListUpdate
=
new
AttachmentListUpdateValue
();
int
fromVersion
=
newAttachment
.
getVersion
();
Attachment
attachment
=
newAttachment
.
getAttachment
();
for
(
int
i
=
attachment
.
getVersion
();
i
>
fromVersion
;
i
--)
AttachmentCreation
attachmentCreation
=
new
AttachmentCreation
();
attachmentCreation
.
setFileName
(
attachment
.
getFileName
());
attachmentCreation
.
setTitle
(
attachment
.
getTitle
());
attachmentCreation
.
setDescription
(
attachment
.
getDescription
());
attachmentCreation
.
setContent
(
attachment
.
getContent
());
attachmentCreations
.
add
(
attachmentCreation
);
if
(
attachment
.
getFetchOptions
().
hasPreviousVersion
())
{
AttachmentCreation
attachmentCreation
=
new
AttachmentCreation
();
attachmentCreation
.
setFileName
(
attachment
.
getFileName
());
attachmentCreation
.
setTitle
(
attachment
.
getTitle
());
attachmentCreation
.
setDescription
(
attachment
.
getDescription
());
attachmentCreation
.
setContent
(
attachment
.
getContent
());
attachmentCreations
.
add
(
attachmentCreation
);
if
(
attachment
.
getFetchOptions
().
hasPreviousVersion
())
{
attachment
=
attachment
.
getPreviousVersion
();
}
attachment
=
attachment
.
getPreviousVersion
();
}
attachmentListUpdate
.
add
(
attachmentCreations
.
toArray
(
new
AttachmentCreation
[
0
]));
attachmentCreationsByPermId
.
put
(
permId
,
attachmentListUpdate
);
}
handleAttachments
(
attachmentCreationsByPermId
);
synchronizationSummary
.
addedCount
.
addAndGet
(
attachmentCreationsByPermId
.
size
());
attachmentListUpdate
.
add
(
attachmentCreations
.
toArray
(
new
AttachmentCreation
[
0
]));
}
protected
abstract
void
handleAttachments
(
Map
<
String
,
AttachmentListUpdateValue
>
attachmentsByPermId
);
private
void
handleAttachmentReplacements
(
List
<
AttachmentReplacement
>
replacements
)
{
}
protected
void
specifiyAttachmentFetchOptions
(
AttachmentFetchOptions
attachmentFetchOptions
)
{
attachmentFetchOptions
.
withContent
();
...
...
@@ -285,6 +298,7 @@ public class AttachmentsSynchronizer implements ITaskExecutor<List<IncomingEntit
private
static
final
class
ProjectsHandler
extends
AbstractHandler
{
@SuppressWarnings
(
"unchecked"
)
@Override
protected
<
AH
extends
IPermIdHolder
&
IAttachmentsHolder
>
Collection
<
AH
>
getAttachments
(
IApplicationServerApi
v3api
,
String
sessionToken
,
List
<
String
>
permIds
)
...
...
@@ -312,6 +326,7 @@ public class AttachmentsSynchronizer implements ITaskExecutor<List<IncomingEntit
private
static
final
class
ExperimentsHandler
extends
AbstractHandler
{
@SuppressWarnings
(
"unchecked"
)
@Override
protected
<
AH
extends
IPermIdHolder
&
IAttachmentsHolder
>
Collection
<
AH
>
getAttachments
(
IApplicationServerApi
v3api
,
String
sessionToken
,
List
<
String
>
permIds
)
...
...
@@ -339,6 +354,7 @@ public class AttachmentsSynchronizer implements ITaskExecutor<List<IncomingEntit
private
static
final
class
SamplesHandler
extends
AbstractHandler
{
@SuppressWarnings
(
"unchecked"
)
@Override
protected
<
AH
extends
IPermIdHolder
&
IAttachmentsHolder
>
Collection
<
AH
>
getAttachments
(
IApplicationServerApi
v3api
,
String
sessionToken
,
List
<
String
>
permIds
)
...
...
@@ -363,18 +379,23 @@ public class AttachmentsSynchronizer implements ITaskExecutor<List<IncomingEntit
v3api
.
updateSamples
(
sessionToken
,
updates
);
}
}
private
static
final
class
New
Attachment
private
static
final
class
Attachment
Change
{
private
Attachment
attachment
;
private
int
version
;
private
String
permId
;
NewAttachment
(
Attachment
attachment
,
int
version
,
String
permId
)
private
boolean
remove
;
private
Integer
version
;
AttachmentChange
(
Attachment
attachment
,
String
permId
,
boolean
remove
,
Integer
version
)
{
this
.
attachment
=
attachment
;
this
.
version
=
version
;
this
.
permId
=
permId
;
this
.
remove
=
remove
;
this
.
version
=
version
;
}
public
Attachment
getAttachment
()
...
...
@@ -382,22 +403,20 @@ public class AttachmentsSynchronizer implements ITaskExecutor<List<IncomingEntit
return
attachment
;
}
public
in
t
get
V
er
sion
()
public
Str
in
g
get
P
er
mId
()
{
return
v
er
sion
;
return
p
er
mId
;
}
public
String
getPermId
()
public
boolean
isRemove
()
{
return
permId
;
return
remove
;
}
}
private
static
final
class
AttachmentReplacement
{
AttachmentReplacement
(
Attachment
attachment
,
String
permId
)
public
Integer
getVersion
()
{
return
version
;
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment