-// $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;
/**
- * <p>AgentEditorInput class.</p>
- *
* @author p.ciardelli
* @created 25.06.2009
* @version 1.0
*/
public class AgentEditorInput extends AbstractBulkEditorInput<TeamOrPersonBase> {
- /**
- *
- */
private static final long serialVersionUID = 3387950621617078479L;
- /** Constant <code>ID="bulkeditor.input.author"</code> */
public static final String ID = "bulkeditor.input.author";
private static AgentEditorInput instance;
- /**
- * <p>getID</p>
- *
- * @return the iD
- */
+ 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;
}
- /* (non-Javadoc)
- * @see org.eclipse.ui.IEditorInput#getName()
- */
- /**
- * <p>getName</p>
- *
- * @return a {@link java.lang.String} object.
- */
@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;
}
- /* (non-Javadoc)
- * @see org.eclipse.ui.IEditorInput#getToolTipText()
- */
- /**
- * <p>getToolTipText</p>
- *
- * @return a {@link java.lang.String} object.
- */
@Override
- public String getToolTipText() {
- return getName();
+ 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);
}
- /**
- * <p>Getter for the field <code>instance</code>.</p>
- *
- * @return a {@link eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput} object.
- */
+ @Override
+ 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();
return instance;
}
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInput#isMergingEnabled()
- */
/** {@inheritDoc} */
@Override
public boolean isMergingEnabled() {
return true;
}
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInput#isMergingEnabled()
- */
+
/** {@inheritDoc} */
@Override
public boolean isConvertingEnabled() {
public boolean merge(TeamOrPersonBase entity, TeamOrPersonBase mergeTarget) {
if (entity instanceof IMergable) {
try {
- IMergeStrategy strategy = DefaultMergeStrategy.NewInstance(Person.class);
- strategy.setMergeMode("institutionalMemberships", MergeMode.FIRST);
- CdmStore.getCommonService().merge((IMergable)mergeTarget, (IMergable)entity, Person.class);
+ if(entity instanceof Person && mergeTarget instanceof Person) {
+ IMergeStrategy strategy = DefaultMergeStrategy.NewInstance(Person.class);
+ strategy.setMergeMode("institutionalMemberships", MergeMode.FIRST);
+ CdmStore.getCommonService().merge(mergeTarget.getUuid(), entity.getUuid(), Person.class);
+ } else {
+ IMergeStrategy strategy = DefaultMergeStrategy.NewInstance(TeamOrPersonBase.class);
+ CdmStore.getCommonService().merge(mergeTarget.getUuid(), entity.getUuid(), TeamOrPersonBase.class);
+ }
} catch (MergeException e) {
MessagingUtils.errorDialog("Bulk Editor Merge Error",
this,
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;
-// }
-
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#getSortProviders()
- */
@Override
public List<IBulkEditorSortProvider<TeamOrPersonBase>> getSortProviders() {
List<IBulkEditorSortProvider<TeamOrPersonBase>> sortProviders = super.getSortProviders();
return sortProviders;
}
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#createEntityCreator()
- */
@Override
protected IEntityCreator<TeamOrPersonBase> createEntityCreator() {
return new AgentCreator();
}
@Override
- public boolean save(TeamOrPersonBase entity) {
- if(CdmStore.getCurrentSessionManager().isRemoting()) {
- return CdmStore.getService(IAgentService.class).merge(entity) != null;
- } else {
- return CdmStore.getService(IAgentService.class).saveOrUpdate(entity) != null;
- }
+ public TeamOrPersonBase save(TeamOrPersonBase 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);
+ }
}