Merge branch 'release/5.19.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / featuretree / e4 / operation / AddOntologyTermOperation.java
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.featuretree.e4.operation;
10
11 import eu.etaxonomy.cdm.common.URI;
12 import java.util.UUID;
13
14 import org.eclipse.core.commands.ExecutionException;
15 import org.eclipse.core.runtime.IAdaptable;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.core.runtime.IStatus;
18
19 import eu.etaxonomy.cdm.api.service.ITermNodeService;
20 import eu.etaxonomy.cdm.api.service.UpdateResult;
21 import eu.etaxonomy.cdm.model.description.Feature;
22 import eu.etaxonomy.cdm.model.term.TermNode;
23 import eu.etaxonomy.cdm.model.term.TermVocabulary;
24 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
25 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
26 import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
27 import eu.etaxonomy.taxeditor.store.CdmStore;
28 import eu.etaxonomy.taxeditor.store.StoreUtil;
29 import eu.etaxonomy.taxeditor.view.webimport.termimport.wrapper.OntologyTermWrapper;
30
31 /**
32 * @author pplitzner
33 * @since Apr 30, 2018
34 */
35 public class AddOntologyTermOperation extends AbstractPostOperation<TermNode> {
36
37 private UUID targetUuid;
38 private OntologyTermWrapper wrapper;
39 private TermVocabulary vocabulary;
40
41 public AddOntologyTermOperation(OntologyTermWrapper wrapper, UUID targetUuid, TermVocabulary vocabulary,
42 IPostOperationEnabled postOperationEnabled, ICdmEntitySessionEnabled<TermNode> cdmEntitySessionEnabled) {
43 super("Add ontology term", StoreUtil.getUndoContext(), null, postOperationEnabled, cdmEntitySessionEnabled);
44 this.wrapper = wrapper;
45 this.targetUuid = targetUuid;
46 this.vocabulary = vocabulary;
47 }
48
49 @Override
50 public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
51 Feature feature = Feature.NewInstance(wrapper.getDescription(), wrapper.getLabel(), null);
52 feature.setUri(URI.create(wrapper.getUri()));
53 UpdateResult updateResult = CdmStore.getService(ITermNodeService.class).createChildNode(targetUuid, feature, vocabulary.getUuid());
54
55 // UpdateResult updateResult = CdmStore.getService(ITermNodeService.class).addChildNode(targetUuid, element.getUuid());
56 return postExecute(updateResult.getCdmEntity());
57 }
58
59 @Override
60 public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
61 return null;
62 }
63
64 @Override
65 public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
66 return null;
67 }
68
69 }