-// $Id$
/**
* Copyright (C) 2007 EDIT
* European Distributed Institute of Taxonomy
*/
package eu.etaxonomy.taxeditor.bulkeditor.input;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
+import java.util.UUID;
import eu.etaxonomy.cdm.api.service.IAgentService;
+import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
import eu.etaxonomy.cdm.model.agent.AgentBase;
import eu.etaxonomy.cdm.model.agent.Person;
+import eu.etaxonomy.cdm.model.agent.Team;
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
import eu.etaxonomy.cdm.strategy.merge.DefaultMergeStrategy;
import eu.etaxonomy.cdm.strategy.merge.IMergable;
private static AgentEditorInput instance;
+ private static final String PROPERTY_NOMENCLATURAL_TITLE = "Nomenclatural Title";
+ private static final String PROPERTY_FAMILY_NAME = "Family Name";
+ private static final String PROPERTY_OTHER_NAME = "Other Name";
+ private static final String PROPERTY_INITIALS = "Initials";
+ private static final String PROPERTY_TEAM_HAS_MORE_MEMBERS = "et al";
+
public static String getID() {
return ID;
}
-
@Override
- public String getName() {
- return BulkEditorInputType.AGENT.label;
+ protected List<String> getPropertyKeys_internal() {
+ List<String> propertyKeysInternal = new ArrayList<>();
+ propertyKeysInternal.add(PROPERTY_NOMENCLATURAL_TITLE);
+ propertyKeysInternal.add(PROPERTY_FAMILY_NAME);
+ propertyKeysInternal.add(PROPERTY_OTHER_NAME);
+ propertyKeysInternal.add(PROPERTY_INITIALS);
+ propertyKeysInternal.add(PROPERTY_TEAM_HAS_MORE_MEMBERS);
+ return propertyKeysInternal;
}
+ @Override
+ public Object getPropertyValue(TeamOrPersonBase cdmBase, String property) {
+ if(property.equals(PROPERTY_NOMENCLATURAL_TITLE)){
+ return cdmBase.getNomenclaturalTitle();
+ }
+ else if(property.equals(PROPERTY_FAMILY_NAME)
+ && cdmBase.isInstanceOf(Person.class)){
+ return HibernateProxyHelper.deproxy(cdmBase, Person.class).getFamilyName();
+ }
+ else if(property.equals(PROPERTY_OTHER_NAME)
+ && cdmBase.isInstanceOf(Person.class)){
+ return HibernateProxyHelper.deproxy(cdmBase, Person.class).getGivenName();
+ }
+ else if(property.equals(PROPERTY_INITIALS)
+ && cdmBase.isInstanceOf(Person.class)){
+ return HibernateProxyHelper.deproxy(cdmBase, Person.class).getInitials();
+ }
+ else if(property.equals(PROPERTY_TEAM_HAS_MORE_MEMBERS)
+ && cdmBase.isInstanceOf(Team.class)){
+ return HibernateProxyHelper.deproxy(cdmBase, Team.class).isHasMoreMembers();
+ }
+ return super.getPropertyValue(cdmBase, property);
+ }
@Override
- public String getToolTipText() {
- return getName();
+ public boolean isBooleanProperty(String property) {
+ if(property.equals(PROPERTY_TEAM_HAS_MORE_MEMBERS)){
+ return true;
+ }
+ return super.isBooleanProperty(property);
+ }
+
+ @Override
+ public String getName() {
+ return BulkEditorInputType.AGENT.label;
}
+
public static AbstractBulkEditorInput getInstance() {
if (instance == null) {
instance = new AgentEditorInput();
if(entity instanceof Person && mergeTarget instanceof Person) {
IMergeStrategy strategy = DefaultMergeStrategy.NewInstance(Person.class);
strategy.setMergeMode("institutionalMemberships", MergeMode.FIRST);
- CdmStore.getCommonService().merge(mergeTarget.getId(), entity.getId(), Person.class);
+ CdmStore.getCommonService().merge(mergeTarget.getUuid(), entity.getUuid(), Person.class);
} else {
IMergeStrategy strategy = DefaultMergeStrategy.NewInstance(TeamOrPersonBase.class);
- CdmStore.getCommonService().merge(mergeTarget.getId(), entity.getId(), TeamOrPersonBase.class);
+ CdmStore.getCommonService().merge(mergeTarget.getUuid(), entity.getUuid(), TeamOrPersonBase.class);
}
} catch (MergeException e) {
MessagingUtils.errorDialog("Bulk Editor Merge Error",
return true;
}
- /** {@inheritDoc} */
@Override
- public List<TeamOrPersonBase> listEntities(IIdentifiableEntityServiceConfigurator configurator) {
- return CdmStore.getSearchManager().findTeamOrPersons(configurator);
+ protected int getPageSize() {
+ return 200;
}
- /** {@inheritDoc}
+ @Override
+ protected long countEntities(IIdentifiableEntityServiceConfigurator configurator) {
+ return CdmStore.getService(IAgentService.class).countByTitle(configurator);
+ }
+
+ /** {@inheritDoc} */
@Override
- public AgentBase loadEntity(UUID uuid) {
- List<String> propertyPaths = Arrays.asList(new String[]{});
- return CdmStore.getService(IAgentService.class).load(uuid, propertyPaths);
- }*/
+ public List<TeamOrPersonBase> listEntities(IIdentifiableEntityServiceConfigurator configurator) {
+ return CdmStore.getSearchManager().findTeamOrPersons(configurator);
+ }
public boolean delete(AgentBase entity) throws ReferencedObjectUndeletableException {
return CdmStore.getService(IAgentService.class).delete(entity) != null;
}
- /** {@inheritDoc} */
- public boolean save(AgentBase entity) {
-
- return CdmStore.getService(IAgentService.class).saveOrUpdate(entity) != null;
- }
-
@Override
public List<IBulkEditorSortProvider<TeamOrPersonBase>> getSortProviders() {
List<IBulkEditorSortProvider<TeamOrPersonBase>> sortProviders = super.getSortProviders();
return sortProviders;
}
-
@Override
protected IEntityCreator<TeamOrPersonBase> createEntityCreator() {
return new AgentCreator();
@Override
public TeamOrPersonBase save(TeamOrPersonBase entity) {
- if(CdmStore.getCurrentSessionManager().isRemoting()) {
- return (TeamOrPersonBase) CdmStore.getService(IAgentService.class).merge(entity, true).getMergedEntity();
- } else {
- CdmStore.getService(IAgentService.class).saveOrUpdate(entity) ;
- return entity;
- }
+ return (TeamOrPersonBase) CdmStore.getService(IAgentService.class).merge(entity, true).getMergedEntity();
+
}
@Override
- public boolean delete(TeamOrPersonBase entity)
+ public boolean delete(TeamOrPersonBase entity, DeleteConfiguratorBase config)
throws ReferencedObjectUndeletableException {
- // TODO Auto-generated method stub
- return false;
+ if (entity.getUuid() != null){
+ return CdmStore.getService(IAgentService.class).delete(entity.getUuid()) != null;
+ }else{
+ return false;
+ }
}
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput#merge()
- */
@Override
public void merge() {
}
+ @Override
+ protected TeamOrPersonBase loadEntity(UUID entityUuid) {
+ List<String> propertyPaths = Arrays.asList(new String[]{});
+ return HibernateProxyHelper.deproxy(CdmStore.getService(IAgentService.class).load(entityUuid, propertyPaths), TeamOrPersonBase.class);
+ }
}