2 * Copyright (C) 2007 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
.taxeditor
.bulkeditor
.input
;
11 import java
.util
.Arrays
;
12 import java
.util
.List
;
13 import java
.util
.UUID
;
15 import eu
.etaxonomy
.cdm
.api
.service
.IAgentService
;
16 import eu
.etaxonomy
.cdm
.api
.service
.config
.DeleteConfiguratorBase
;
17 import eu
.etaxonomy
.cdm
.api
.service
.config
.IIdentifiableEntityServiceConfigurator
;
18 import eu
.etaxonomy
.cdm
.api
.service
.exception
.ReferencedObjectUndeletableException
;
19 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
20 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
21 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
22 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
23 import eu
.etaxonomy
.cdm
.strategy
.merge
.DefaultMergeStrategy
;
24 import eu
.etaxonomy
.cdm
.strategy
.merge
.IMergable
;
25 import eu
.etaxonomy
.cdm
.strategy
.merge
.IMergeStrategy
;
26 import eu
.etaxonomy
.cdm
.strategy
.merge
.MergeException
;
27 import eu
.etaxonomy
.cdm
.strategy
.merge
.MergeMode
;
28 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.IEntityCreator
;
29 import eu
.etaxonomy
.taxeditor
.bulkeditor
.IBulkEditorSortProvider
;
30 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.entitycreator
.AgentCreator
;
31 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.sortprovider
.IdentifiableEntitySortProvider
;
32 import eu
.etaxonomy
.taxeditor
.bulkeditor
.internal
.TaxeditorBulkeditorPlugin
;
33 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
34 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
42 public class AgentEditorInput
extends AbstractBulkEditorInput
<TeamOrPersonBase
> {
44 private static final long serialVersionUID
= 3387950621617078479L;
46 public static final String ID
= "bulkeditor.input.author";
48 private static AgentEditorInput instance
;
50 public static String
getID() {
55 public String
getName() {
56 return BulkEditorInputType
.AGENT
.label
;
61 public String
getToolTipText() {
65 public static AbstractBulkEditorInput
getInstance() {
66 if (instance
== null) {
67 instance
= new AgentEditorInput();
74 public boolean isMergingEnabled() {
81 public boolean isConvertingEnabled() {
87 public boolean merge(TeamOrPersonBase entity
, TeamOrPersonBase mergeTarget
) {
88 if (entity
instanceof IMergable
) {
90 if(entity
instanceof Person
&& mergeTarget
instanceof Person
) {
91 IMergeStrategy strategy
= DefaultMergeStrategy
.NewInstance(Person
.class);
92 strategy
.setMergeMode("institutionalMemberships", MergeMode
.FIRST
);
93 CdmStore
.getCommonService().merge(mergeTarget
.getUuid(), entity
.getUuid(), Person
.class);
95 IMergeStrategy strategy
= DefaultMergeStrategy
.NewInstance(TeamOrPersonBase
.class);
96 CdmStore
.getCommonService().merge(mergeTarget
.getUuid(), entity
.getUuid(), TeamOrPersonBase
.class);
98 } catch (MergeException e
) {
99 MessagingUtils
.errorDialog("Bulk Editor Merge Error",
101 "Could not merge chosen objects of type " + entity
.getClass().getName(),
102 TaxeditorBulkeditorPlugin
.PLUGIN_ID
,
112 public List
<TeamOrPersonBase
> listEntities(IIdentifiableEntityServiceConfigurator configurator
) {
113 return CdmStore
.getSearchManager().findTeamOrPersons(configurator
);
116 public boolean delete(AgentBase entity
) throws ReferencedObjectUndeletableException
{
117 return CdmStore
.getService(IAgentService
.class).delete(entity
) != null;
122 public List
<IBulkEditorSortProvider
<TeamOrPersonBase
>> getSortProviders() {
123 List
<IBulkEditorSortProvider
<TeamOrPersonBase
>> sortProviders
= super.getSortProviders();
125 sortProviders
.add(0, new IdentifiableEntitySortProvider
<TeamOrPersonBase
>());
127 return sortProviders
;
131 protected IEntityCreator
<TeamOrPersonBase
> createEntityCreator() {
132 return new AgentCreator();
136 public TeamOrPersonBase
save(TeamOrPersonBase entity
) {
137 return (TeamOrPersonBase
) CdmStore
.getService(IAgentService
.class).merge(entity
, true).getMergedEntity();
142 public boolean delete(TeamOrPersonBase entity
, DeleteConfiguratorBase config
)
143 throws ReferencedObjectUndeletableException
{
144 if (entity
.getUuid() != null){
145 return CdmStore
.getService(IAgentService
.class).delete(entity
.getUuid()) != null;
152 public void merge() {
157 protected TeamOrPersonBase
loadEntity(UUID entityUuid
) {
158 List
<String
> propertyPaths
= Arrays
.asList(new String
[]{});
159 return HibernateProxyHelper
.deproxy(CdmStore
.getService(IAgentService
.class).load(entityUuid
, propertyPaths
), TeamOrPersonBase
.class);