Mercurial > hg > ismi-richfaces
diff src/main/java/de/mpiwg/itgroup/ismi/browse/FullEntityRepositoryBean.java @ 180:0d31c8be7c31
new MissingRelations feature and UI.
including searchByRelations() with Filter in FullEntityRepositoryBean.
author | Robert Casties <casties@mpiwg-berlin.mpg.de> |
---|---|
date | Wed, 13 Jun 2018 14:57:13 +0200 |
parents | aa564b1b5e1f |
children | 34ac2e1b323a |
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/itgroup/ismi/browse/FullEntityRepositoryBean.java Fri Jun 08 18:59:49 2018 +0200 +++ b/src/main/java/de/mpiwg/itgroup/ismi/browse/FullEntityRepositoryBean.java Wed Jun 13 14:57:13 2018 +0200 @@ -9,6 +9,8 @@ import org.mpi.openmind.cache.WrapperService; import org.mpi.openmind.repository.bo.Attribute; import org.mpi.openmind.repository.bo.Entity; +import org.mpi.openmind.repository.bo.Relation; +import org.mpi.openmind.repository.services.utils.RelationFilter; /** * EntityRepositoryBean for full Entities with Attributes and Relations loaded. @@ -24,8 +26,9 @@ protected boolean sortAttributeNumerically = false; - /* - * (non-Javadoc) + /** + * updateAdvancedEntities() method that makes sure that the current Entities + * are not lightweight. * * @see de.mpiwg.itgroup.ismi.browse.AbstractEntityRepositoryBean# * updateAdvancedEntities() @@ -71,7 +74,15 @@ return GOTO_ENTITY_REPOSITORY; } + /** + * Loads all entities of this.objectClass and sorts by this.sortAttributeName. + * + * Sort attributes as integer if this.sortAttributeNumerically. + * + * @throws Exception + */ public void sortByAttributes() throws Exception { + logger.debug("Start sortByAttributes..."); this.resultMode = MODE_ADVANCED; this.setPage(""); this.entities = new ArrayList<Entity>(); @@ -83,7 +94,7 @@ * run search and sort result (by attribute) */ List<Entity> resultList = getWrapper().getEntitiesByDef(this.objectClass); - // sort List (by ownvalue) + // sort List (by attribute) Collections.sort(resultList, getEntityAttributeComparator(this.sortAttributeName, this.sortAttributeNumerically)); this.entities = resultList; @@ -97,8 +108,18 @@ } else { this.resultSummaryMsg = "No items were found!"; } + logger.debug("Done sortByAttributes."); } + /** + * Returns Comparator for Entities that uses the Attribute attname. + * + * Sorts as integer if numerically. + * + * @param attName + * @param numerically + * @return + */ public Comparator<Entity> getEntityAttributeComparator(final String attName, final boolean numerically) { return new Comparator<Entity>() { @Override @@ -143,6 +164,84 @@ } }; } + + /** + * Loads all entities of this.objectClass matching the given RelationFilters. + * + * Filters Relations by relObjectClass and either srcObjectClass or tarObjectClass. + * + * Requires all RelationFilters to match. + * + * @throws Exception + */ + public void searchByRelations(List<RelationFilter> relationFilters) { + logger.debug("Start searchByRelations..."); + this.resultMode = MODE_ADVANCED; + this.setPage(""); + this.entities = new ArrayList<Entity>(); + this.currentEntities = new ArrayList<Entity>(); + this.resultSummaryMsg = ""; + + /* + * get all entities and filter result (by relation) + */ + List<Entity> resultList = getWrapper().getEntitiesByDef(this.objectClass); + for (Entity entity : resultList) { + if (entity.isLightweight()) { + entity = getWrapper().getEntityContent(entity); + } + boolean condFailed = false; + for (RelationFilter filter :relationFilters) { + if (filter.tarObjectClass != null) { + List<Relation> rels = entity.getSourceRelations(filter.relObjectClass, filter.tarObjectClass); + if (filter.relationMissing) { + // is the relation missing? + if (!rels.isEmpty()) { + condFailed = true; + break; + } + } else { + if (rels.isEmpty()) { + condFailed = true; + break; + } + } + } else if (filter.srcObjectClass != null) { + List<Relation> rels = entity.getTargetRelations(filter.relObjectClass, filter.srcObjectClass); + if (filter.relationMissing) { + // is the relation missing? + if (!rels.isEmpty()) { + condFailed = true; + break; + } + } else { + if (rels.isEmpty()) { + condFailed = true; + break; + } + } + } + } + if (!condFailed) { + // all conditions matched + entities.add(entity); + } + } + + // sort List (by ownValue) + Collections.sort(entities); + + if (entities.size() > 0) { + int entitiesCount = entities.size(); + this.resultSummaryMsg = entitiesCount + " items were found!"; + this.advancedPaginator.setCurrentPage(0); + this.advancedPaginator.resetNumberOfPages(entitiesCount); + this.updateAdvancedEntities(); + } else { + this.resultSummaryMsg = "No items were found!"; + } + logger.debug("Done searchByRelations."); + } /** * @return the sortAttributeName