2 * Copyright (C) 2015 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.cdm
.api
.longrunningService
;
11 import java
.io
.Serializable
;
13 import java
.util
.UUID
;
15 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
16 import org
.springframework
.stereotype
.Service
;
17 import org
.springframework
.transaction
.annotation
.Transactional
;
19 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptiveDataSetService
;
20 import eu
.etaxonomy
.cdm
.api
.service
.IProgressMonitorService
;
21 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonNodeService
;
22 import eu
.etaxonomy
.cdm
.api
.service
.UpdateResult
;
23 import eu
.etaxonomy
.cdm
.api
.service
.config
.ForSubtreeConfiguratorBase
;
24 import eu
.etaxonomy
.cdm
.api
.service
.config
.PublishForSubtreeConfigurator
;
25 import eu
.etaxonomy
.cdm
.api
.service
.config
.SecundumForSubtreeConfigurator
;
26 import eu
.etaxonomy
.cdm
.common
.monitor
.IRemotingProgressMonitor
;
27 import eu
.etaxonomy
.cdm
.common
.monitor
.RemotingProgressMonitorThread
;
28 import eu
.etaxonomy
.cdm
.model
.description
.DescriptiveDataSet
;
36 @Transactional(readOnly
= false)
37 public class LongRunningTasksServiceImpl
implements ILongRunningTasksService
{
39 ITaxonNodeService taxonNodeService
;
42 IDescriptiveDataSetService descriptiveDataSetService
;
45 IProgressMonitorService progressMonitorService
;
50 public UUID
monitGetRowWrapper(DescriptiveDataSet descriptiveDataSet
) {
51 RemotingProgressMonitorThread monitorThread
= new RemotingProgressMonitorThread() {
53 public Serializable
doRun(IRemotingProgressMonitor monitor
) {
54 return descriptiveDataSetService
.getRowWrapper(descriptiveDataSet
, monitor
);
57 UUID uuid
= progressMonitorService
.registerNewRemotingMonitor(monitorThread
);
58 monitorThread
.setPriority(3);
59 monitorThread
.start();
64 public UUID
aggregateComputedTaxonDescriptions(UUID taxonNodeUuid
, UUID descriptiveDataSetUuid
){
65 RemotingProgressMonitorThread monitorThread
= new RemotingProgressMonitorThread() {
67 public Serializable
doRun(IRemotingProgressMonitor monitor
) {
68 UpdateResult updateResult
= descriptiveDataSetService
.aggregateTaxonDescription(taxonNodeUuid
, descriptiveDataSetUuid
, monitor
);
69 for(Exception e
: updateResult
.getExceptions()) {
70 monitor
.addReport(e
.getMessage());
72 monitor
.setResult(updateResult
);
77 UUID uuid
= progressMonitorService
.registerNewRemotingMonitor(monitorThread
);
78 monitorThread
.setPriority(2);
79 monitorThread
.start();
84 public UUID
monitLongRunningTask(ForSubtreeConfiguratorBase config
) {
86 RemotingProgressMonitorThread monitorThread
= new RemotingProgressMonitorThread() {
88 public Serializable
doRun(IRemotingProgressMonitor monitor
) {
90 config
.setMonitor(monitor
);
92 result
= updateData(config
);
93 for(Exception e
: result
.getExceptions()) {
94 monitor
.addReport(e
.getMessage());
96 monitor
.setResult(result
);
100 UUID uuid
= progressMonitorService
.registerNewRemotingMonitor(monitorThread
);
101 monitorThread
.setPriority(2);
102 monitorThread
.start();
106 private UpdateResult
updateData(ForSubtreeConfiguratorBase config
){
107 if (config
instanceof SecundumForSubtreeConfigurator
){
108 return taxonNodeService
.setSecundumForSubtree((SecundumForSubtreeConfigurator
)config
);
110 return taxonNodeService
.setPublishForSubtree(config
.getSubtreeUuid(), ((PublishForSubtreeConfigurator
)config
).isPublish(), ((PublishForSubtreeConfigurator
)config
).isIncludeAcceptedTaxa(), ((PublishForSubtreeConfigurator
)config
).isIncludeSynonyms(), ((PublishForSubtreeConfigurator
)config
).isIncludeSharedTaxa(), config
.getMonitor());
115 public UUID
monitLongRunningTask(Set
<UUID
> movingUuids
, UUID targetTreeNodeUuid
, int movingType
) {
117 RemotingProgressMonitorThread monitorThread
= new RemotingProgressMonitorThread() {
119 public Serializable
doRun(IRemotingProgressMonitor remotingMonitor
) {
122 result
= taxonNodeService
.moveTaxonNodes(movingUuids
,targetTreeNodeUuid
, movingType
, remotingMonitor
);
123 for(Exception e
: result
.getExceptions()) {
124 remotingMonitor
.addReport(e
.getMessage());
126 remotingMonitor
.setResult(result
);
130 UUID uuid
= progressMonitorService
.registerNewRemotingMonitor(monitorThread
);
131 monitorThread
.setPriority(2);
132 monitorThread
.start();