Mercurial > hg > ismi-richfaces
view src/main/java/de/mpiwg/itgroup/ismi/auxObjects/AliasListenerObject.java @ 112:59f26a5ef2b3
AliasListenerObject adds aliases to ListenerObject. Change all forms to enable ALIAS for (historical) PLACE fields. Remove REPOSITORY from event forms.
author | casties |
---|---|
date | Tue, 13 Dec 2016 19:04:45 +0100 |
parents | 22a18bfc66b0 |
children |
line wrap: on
line source
package de.mpiwg.itgroup.ismi.auxObjects; import java.util.ArrayList; import java.util.Collections; import java.util.List; import javax.faces.model.SelectItem; import org.mpi.openmind.repository.bo.Attribute; import org.mpi.openmind.repository.bo.Entity; /** * ListenerObject that searches in Entity Attributes and ALIASes connected by a given Relation. * * @author casties * */ public class AliasListenerObject extends ListenerObject { private static final long serialVersionUID = 2072530246758155955L; public String aliasRelName; /** * ListenerObject that searches in Entity Attributes and also in ALIASes connected by a given Relation. * * Uses relation ALIAS - aliasRelName -> ENTITY (usually "is_alias_name_of"). * * @param classObj * @param attName * @param aliasRelName */ public AliasListenerObject(String classObj, String attName, String aliasRelName) { super(classObj, attName); this.aliasRelName = aliasRelName; } /** * Sets the current entity and displays the selected attribute if it is not already set. * This is meant not to overwrite an entity already set by an alias. * * @see de.mpiwg.itgroup.ismi.auxObjects.ListenerObject#setEntityAndAttribute(org.mpi.openmind.repository.bo.Entity) */ public void setEntityAndAttributeIfEmpty(Entity ent) { if ((this.entity == null) || (this.entity.getObjectClass() == null)) { super.setEntityAndAttribute(ent); } } /* (non-Javadoc) * @see de.mpiwg.itgroup.ismi.auxObjects.AbstractListenerObject#updateSuggestedItems(java.lang.String, java.lang.String, java.lang.String) */ @Override protected List<SelectItem> updateSuggestedItems(String searchWord, String objClass, String attName) { // find matching entity attributes List<Attribute> attList = getWrapper().getAttributesByDefByAttName(objClass, attName, searchWord.toString(), MAX_SUGGEST); // find all matching aliases List<Attribute> aliasAtts = getWrapper().getAttributesByDefByAttName("ALIAS", "alias", searchWord.toString(), 0); // filter related aliases int aliasCnt = 0; for (Attribute att : aliasAtts) { Long aliasId = att.getSourceId(); // find the Entities with the correct Relation List<Entity> ents = getWrapper().getTargetsForSourceRelation(aliasId, aliasRelName, objClass, 1); if (!ents.isEmpty()) { // ALIAS is related to Entity attList.add(att); aliasCnt += 1; if (aliasCnt > MAX_SUGGEST) { break; } } } if (aliasCnt > 0) { // re-sort with added aliases Collections.sort(attList); } List<SelectItem> suggestedItems = new ArrayList<SelectItem>(); if (attList == null) return suggestedItems; for (Attribute att : attList) { String label = att.getOwnValue(); if (att.getSourceObjectClass().equals("ALIAS")) { label += " [ALIAS " + att.getSourceId() + "]"; } else { label += " [" + att.getSourceId() + "]"; } SelectItem item = new SelectItem(att, label, "description: " + att); suggestedItems.add(item); } return suggestedItems; } /** * @return the aliasRelName */ public String getAliasRelName() { return aliasRelName; } /** * @param aliasRelName the aliasRelName to set */ public void setAliasRelName(String aliasRelName) { this.aliasRelName = aliasRelName; } }