Merge branch 'release/5.19.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / key / polytomous / PolytomousKeyEditorInput.java
1 /**
2 * Copyright (C) 2007 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.editor.key.polytomous;
10
11 import java.util.ArrayList;
12 import java.util.Arrays;
13 import java.util.HashMap;
14 import java.util.List;
15 import java.util.Map;
16 import java.util.UUID;
17
18 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
19 import eu.etaxonomy.cdm.api.service.IPolytomousKeyService;
20 import eu.etaxonomy.cdm.model.description.PolytomousKey;
21 import eu.etaxonomy.taxeditor.editor.key.AbstractIdentificationEditorInput;
22 import eu.etaxonomy.taxeditor.store.CdmStore;
23
24 /**
25 * @author n.hoffmann
26 */
27 public class PolytomousKeyEditorInput extends AbstractIdentificationEditorInput<PolytomousKey> {
28
29 private final String name;
30 private PolytomousKey key;
31
32
33 protected PolytomousKeyEditorInput(ConversationHolder conversation,
34 UUID polytomousKeyUuid) {
35 super(conversation);
36 List<String> propertyPath = new ArrayList<>();
37 propertyPath.add("root");
38 propertyPath.add("root.*");
39 this.key = CdmStore.getService(IPolytomousKeyService.class).load(polytomousKeyUuid, propertyPath);
40 this.name = key.getTitleCache();
41 }
42
43 // public PolytomousKeyEditorInput(UUID polytomousKeyUuid, String name) {
44 // super(CdmStore.createConversation());
45 // this.keyUuid = polytomousKeyUuid;
46 // this.name = name;
47 // }
48
49 public static PolytomousKeyEditorInput NewInstance(UUID polytomousKeyUuid) throws Exception{
50 try{
51 ConversationHolder conversation = CdmStore.createConversation();
52 return new PolytomousKeyEditorInput(conversation, polytomousKeyUuid);
53 }catch(Exception e){
54 throw e;
55 }
56 }
57
58 @Override
59 public PolytomousKey getKey() {
60 return key;
61 }
62
63 @Override
64 public boolean equals(Object object) {
65 if (object instanceof PolytomousKeyEditorInput
66 && getKey() != null
67 && getKey().equals(((PolytomousKeyEditorInput) object).getKey())
68 ){
69 return true;
70 }
71 return super.equals(object);
72 }
73
74 @Override
75 public List<PolytomousKey> getRootEntities() {
76 return Arrays.asList(key);
77 }
78
79 @Override
80 public void merge() {
81 key = CdmStore.getService(IPolytomousKeyService.class).merge(key,true).getMergedEntity();
82 }
83
84 @Override
85 public Map<Object, List<String>> getPropertyPathsMap() {
86 Map<Object,List<String>> propertyPathsMap = new HashMap<Object,List<String>>();
87
88 List<String> polytomousKeyNodePropertyPaths = Arrays.asList(new String[] {
89 "statement" //$NON-NLS-1$
90 });
91 propertyPathsMap.put("children", polytomousKeyNodePropertyPaths); //$NON-NLS-1$
92 return propertyPathsMap;
93 }
94 }