bae14730a3e804fb7ad11e1ade91c9520d45ba64
[taxeditor.git] / eu.etaxonomy.taxeditor.bulkeditor / src / main / java / eu / etaxonomy / taxeditor / bulkeditor / input / AgentEditorInput.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10 package eu.etaxonomy.taxeditor.bulkeditor.input;
11
12 import java.util.List;
13
14 import eu.etaxonomy.cdm.api.service.IAgentService;
15 import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
16 import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;
17 import eu.etaxonomy.cdm.model.agent.AgentBase;
18 import eu.etaxonomy.cdm.model.agent.Person;
19 import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
20 import eu.etaxonomy.cdm.strategy.merge.DefaultMergeStrategy;
21 import eu.etaxonomy.cdm.strategy.merge.IMergable;
22 import eu.etaxonomy.cdm.strategy.merge.IMergeStrategy;
23 import eu.etaxonomy.cdm.strategy.merge.MergeException;
24 import eu.etaxonomy.cdm.strategy.merge.MergeMode;
25 import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
26 import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorSortProvider;
27 import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.AgentCreator;
28 import eu.etaxonomy.taxeditor.bulkeditor.input.sortprovider.IdentifiableEntitySortProvider;
29 import eu.etaxonomy.taxeditor.bulkeditor.internal.TaxeditorBulkeditorPlugin;
30 import eu.etaxonomy.taxeditor.model.MessagingUtils;
31 import eu.etaxonomy.taxeditor.store.CdmStore;
32
33
34 /**
35 * @author p.ciardelli
36 * @created 25.06.2009
37 * @version 1.0
38 */
39 public class AgentEditorInput extends AbstractBulkEditorInput<TeamOrPersonBase> {
40
41 private static final long serialVersionUID = 3387950621617078479L;
42
43 public static final String ID = "bulkeditor.input.author";
44
45 private static AgentEditorInput instance;
46
47 public static String getID() {
48 return ID;
49 }
50
51 @Override
52 public String getName() {
53 return BulkEditorInputType.AGENT.label;
54 }
55
56 @Override
57 public String getToolTipText() {
58 return getName();
59 }
60
61 public static AbstractBulkEditorInput getInstance() {
62 if (instance == null) {
63 instance = new AgentEditorInput();
64 }
65 return instance;
66 }
67
68 /** {@inheritDoc} */
69 @Override
70 public boolean isMergingEnabled() {
71 return true;
72 }
73
74 /** {@inheritDoc} */
75 @Override
76 public boolean isConvertingEnabled() {
77 return true;
78 }
79
80 /** {@inheritDoc} */
81 @Override
82 public boolean merge(TeamOrPersonBase entity, TeamOrPersonBase mergeTarget) {
83 if (entity instanceof IMergable) {
84 try {
85 IMergeStrategy strategy = DefaultMergeStrategy.NewInstance(Person.class);
86 strategy.setMergeMode("institutionalMemberships", MergeMode.FIRST);
87 CdmStore.getCommonService().merge((IMergable)mergeTarget, (IMergable)entity, strategy);
88 } catch (MergeException e) {
89 MessagingUtils.errorDialog("Bulk Editor Merge Error",
90 this,
91 "Could not merge chosen objects of type " + entity.getClass().getName(),
92 TaxeditorBulkeditorPlugin.PLUGIN_ID,
93 e,
94 true);
95 }
96 }
97 return true;
98 }
99
100 /** {@inheritDoc} */
101 @Override
102 public List<TeamOrPersonBase> listEntities(IIdentifiableEntityServiceConfigurator configurator) {
103 return CdmStore.getSearchManager().findTeamOrPersons(configurator);
104 }
105
106 /** {@inheritDoc}
107 @Override
108 public AgentBase loadEntity(UUID uuid) {
109 List<String> propertyPaths = Arrays.asList(new String[]{});
110 return CdmStore.getService(IAgentService.class).load(uuid, propertyPaths);
111 }*/
112
113
114 public boolean delete(AgentBase entity) throws ReferencedObjectUndeletableException {
115
116 return CdmStore.getService(IAgentService.class).delete(entity) != null;
117
118 }
119
120 /** {@inheritDoc} */
121 public boolean save(AgentBase entity) {
122
123 return CdmStore.getService(IAgentService.class).saveOrUpdate(entity) != null;
124 }
125
126 @Override
127 public List<IBulkEditorSortProvider<TeamOrPersonBase>> getSortProviders() {
128 List<IBulkEditorSortProvider<TeamOrPersonBase>> sortProviders = super.getSortProviders();
129
130 sortProviders.add(0, new IdentifiableEntitySortProvider<TeamOrPersonBase>());
131
132 return sortProviders;
133 }
134
135 @Override
136 protected IEntityCreator<TeamOrPersonBase> createEntityCreator() {
137 return new AgentCreator();
138 }
139
140 @Override
141 public boolean save(TeamOrPersonBase entity) {
142 return CdmStore.getService(IAgentService.class).saveOrUpdate(entity) != null;
143 }
144
145 @Override
146 public boolean delete(TeamOrPersonBase entity)
147 throws ReferencedObjectUndeletableException {
148 // TODO Auto-generated method stub
149 return false;
150 }
151
152 }