Project

General

Profile

Download (2.88 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2018 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
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.
8
*/
9
package eu.etaxonomy.taxeditor.navigation.navigator.operation;
10

    
11
import java.util.List;
12
import java.util.UUID;
13

    
14
import org.eclipse.core.runtime.IAdaptable;
15
import org.eclipse.core.runtime.IProgressMonitor;
16

    
17
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
18
import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
19
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
20
import eu.etaxonomy.cdm.api.service.UpdateResult;
21
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
22
import eu.etaxonomy.cdm.model.taxon.TaxonNodeStatus;
23
import eu.etaxonomy.cdm.persistence.dto.MergeResult;
24
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
25
import eu.etaxonomy.taxeditor.operation.CdmUpdateOperation;
26

    
27
/**
28
 * @author k.luther
29
 * @since 11.10.2018
30
 *
31
 */
32
public class SetUnplacedExcludedDoubtfulOperation extends CdmUpdateOperation {
33
    private final static String LABEL = Messages.TaxonNavigatorLabels_SET_UNPLACED;
34
    private List<UUID> sourceTaxonNodeUuids;
35
    private Boolean unplaced = null;
36
    private Boolean excluded = null;
37
    private Boolean doubtful = null;
38
    /**
39
     * @param source
40
     * @param async
41
     */
42
    public SetUnplacedExcludedDoubtfulOperation(Object source,
43
            boolean async,
44
            List<UUID> sourceTaxonNodeUuids,
45
            Boolean unplaced, Boolean excluded, Boolean doubtful) {
46
        super(LABEL, Action.Update, source, async);
47
        this.sourceTaxonNodeUuids = sourceTaxonNodeUuids;
48
        if (unplaced != null){
49
            this.unplaced = unplaced;
50
        }
51
        if (excluded != null){
52
            this.excluded = excluded;
53
        }
54
        if (doubtful != null){
55
            this.doubtful = doubtful;
56
        }
57
    }
58

    
59
    /**
60
     * {@inheritDoc}
61
     */
62
    @Override
63
    protected UpdateResult doUpdateExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
64

    
65
        List<TaxonNode> nodes = CdmApplicationState.getService(ITaxonNodeService.class).load(sourceTaxonNodeUuids, null);
66

    
67
        for (TaxonNode node: nodes){
68
            if (unplaced != null){
69
                node.setStatus(TaxonNodeStatus.UNPLACED);
70
            }
71
            if (excluded != null){
72
                node.setStatus(TaxonNodeStatus.EXCLUDED);
73
            }
74
            if (doubtful != null){
75
                node.setStatus(TaxonNodeStatus.DOUBTFUL);
76
            }
77
        }
78
        List<MergeResult<TaxonNode>> results = CdmApplicationState.getService(ITaxonNodeService.class).merge(nodes, true);
79
        UpdateResult updateResult = new UpdateResult();
80
        for (MergeResult<TaxonNode>result: results){
81
            updateResult.addUpdatedObject(result.getMergedEntity());
82
        }
83
        return updateResult;
84
    }
85

    
86
}
(9-9/10)