Mercurial > hg > ismi-richfaces
comparison 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 |
comparison
equal
deleted
inserted
replaced
179:c9dec00f0f17 | 180:0d31c8be7c31 |
---|---|
7 | 7 |
8 import org.apache.commons.lang.StringUtils; | 8 import org.apache.commons.lang.StringUtils; |
9 import org.mpi.openmind.cache.WrapperService; | 9 import org.mpi.openmind.cache.WrapperService; |
10 import org.mpi.openmind.repository.bo.Attribute; | 10 import org.mpi.openmind.repository.bo.Attribute; |
11 import org.mpi.openmind.repository.bo.Entity; | 11 import org.mpi.openmind.repository.bo.Entity; |
12 import org.mpi.openmind.repository.bo.Relation; | |
13 import org.mpi.openmind.repository.services.utils.RelationFilter; | |
12 | 14 |
13 /** | 15 /** |
14 * EntityRepositoryBean for full Entities with Attributes and Relations loaded. | 16 * EntityRepositoryBean for full Entities with Attributes and Relations loaded. |
15 * | 17 * |
16 * @author casties | 18 * @author casties |
22 | 24 |
23 protected String sortAttributeName; | 25 protected String sortAttributeName; |
24 | 26 |
25 protected boolean sortAttributeNumerically = false; | 27 protected boolean sortAttributeNumerically = false; |
26 | 28 |
27 /* | 29 /** |
28 * (non-Javadoc) | 30 * updateAdvancedEntities() method that makes sure that the current Entities |
31 * are not lightweight. | |
29 * | 32 * |
30 * @see de.mpiwg.itgroup.ismi.browse.AbstractEntityRepositoryBean# | 33 * @see de.mpiwg.itgroup.ismi.browse.AbstractEntityRepositoryBean# |
31 * updateAdvancedEntities() | 34 * updateAdvancedEntities() |
32 */ | 35 */ |
33 @Override | 36 @Override |
69 logger.error(e.getMessage(), e); | 72 logger.error(e.getMessage(), e); |
70 } | 73 } |
71 return GOTO_ENTITY_REPOSITORY; | 74 return GOTO_ENTITY_REPOSITORY; |
72 } | 75 } |
73 | 76 |
77 /** | |
78 * Loads all entities of this.objectClass and sorts by this.sortAttributeName. | |
79 * | |
80 * Sort attributes as integer if this.sortAttributeNumerically. | |
81 * | |
82 * @throws Exception | |
83 */ | |
74 public void sortByAttributes() throws Exception { | 84 public void sortByAttributes() throws Exception { |
85 logger.debug("Start sortByAttributes..."); | |
75 this.resultMode = MODE_ADVANCED; | 86 this.resultMode = MODE_ADVANCED; |
76 this.setPage(""); | 87 this.setPage(""); |
77 this.entities = new ArrayList<Entity>(); | 88 this.entities = new ArrayList<Entity>(); |
78 this.currentEntities = new ArrayList<Entity>(); | 89 this.currentEntities = new ArrayList<Entity>(); |
79 | 90 |
81 | 92 |
82 /* | 93 /* |
83 * run search and sort result (by attribute) | 94 * run search and sort result (by attribute) |
84 */ | 95 */ |
85 List<Entity> resultList = getWrapper().getEntitiesByDef(this.objectClass); | 96 List<Entity> resultList = getWrapper().getEntitiesByDef(this.objectClass); |
86 // sort List (by ownvalue) | 97 // sort List (by attribute) |
87 Collections.sort(resultList, | 98 Collections.sort(resultList, |
88 getEntityAttributeComparator(this.sortAttributeName, this.sortAttributeNumerically)); | 99 getEntityAttributeComparator(this.sortAttributeName, this.sortAttributeNumerically)); |
89 this.entities = resultList; | 100 this.entities = resultList; |
90 | 101 |
91 if (resultList.size() > 0) { | 102 if (resultList.size() > 0) { |
95 this.advancedPaginator.resetNumberOfPages(entitiesCount); | 106 this.advancedPaginator.resetNumberOfPages(entitiesCount); |
96 this.updateAdvancedEntities(); | 107 this.updateAdvancedEntities(); |
97 } else { | 108 } else { |
98 this.resultSummaryMsg = "No items were found!"; | 109 this.resultSummaryMsg = "No items were found!"; |
99 } | 110 } |
100 } | 111 logger.debug("Done sortByAttributes."); |
101 | 112 } |
113 | |
114 /** | |
115 * Returns Comparator for Entities that uses the Attribute attname. | |
116 * | |
117 * Sorts as integer if numerically. | |
118 * | |
119 * @param attName | |
120 * @param numerically | |
121 * @return | |
122 */ | |
102 public Comparator<Entity> getEntityAttributeComparator(final String attName, final boolean numerically) { | 123 public Comparator<Entity> getEntityAttributeComparator(final String attName, final boolean numerically) { |
103 return new Comparator<Entity>() { | 124 return new Comparator<Entity>() { |
104 @Override | 125 @Override |
105 public int compare(Entity e1, Entity e2) { | 126 public int compare(Entity e1, Entity e2) { |
106 if (e1.isLightweight()) { | 127 if (e1.isLightweight()) { |
141 return att1.getValue().compareTo(att2.getValue()); | 162 return att1.getValue().compareTo(att2.getValue()); |
142 } | 163 } |
143 } | 164 } |
144 }; | 165 }; |
145 } | 166 } |
167 | |
168 /** | |
169 * Loads all entities of this.objectClass matching the given RelationFilters. | |
170 * | |
171 * Filters Relations by relObjectClass and either srcObjectClass or tarObjectClass. | |
172 * | |
173 * Requires all RelationFilters to match. | |
174 * | |
175 * @throws Exception | |
176 */ | |
177 public void searchByRelations(List<RelationFilter> relationFilters) { | |
178 logger.debug("Start searchByRelations..."); | |
179 this.resultMode = MODE_ADVANCED; | |
180 this.setPage(""); | |
181 this.entities = new ArrayList<Entity>(); | |
182 this.currentEntities = new ArrayList<Entity>(); | |
183 this.resultSummaryMsg = ""; | |
184 | |
185 /* | |
186 * get all entities and filter result (by relation) | |
187 */ | |
188 List<Entity> resultList = getWrapper().getEntitiesByDef(this.objectClass); | |
189 for (Entity entity : resultList) { | |
190 if (entity.isLightweight()) { | |
191 entity = getWrapper().getEntityContent(entity); | |
192 } | |
193 boolean condFailed = false; | |
194 for (RelationFilter filter :relationFilters) { | |
195 if (filter.tarObjectClass != null) { | |
196 List<Relation> rels = entity.getSourceRelations(filter.relObjectClass, filter.tarObjectClass); | |
197 if (filter.relationMissing) { | |
198 // is the relation missing? | |
199 if (!rels.isEmpty()) { | |
200 condFailed = true; | |
201 break; | |
202 } | |
203 } else { | |
204 if (rels.isEmpty()) { | |
205 condFailed = true; | |
206 break; | |
207 } | |
208 } | |
209 } else if (filter.srcObjectClass != null) { | |
210 List<Relation> rels = entity.getTargetRelations(filter.relObjectClass, filter.srcObjectClass); | |
211 if (filter.relationMissing) { | |
212 // is the relation missing? | |
213 if (!rels.isEmpty()) { | |
214 condFailed = true; | |
215 break; | |
216 } | |
217 } else { | |
218 if (rels.isEmpty()) { | |
219 condFailed = true; | |
220 break; | |
221 } | |
222 } | |
223 } | |
224 } | |
225 if (!condFailed) { | |
226 // all conditions matched | |
227 entities.add(entity); | |
228 } | |
229 } | |
230 | |
231 // sort List (by ownValue) | |
232 Collections.sort(entities); | |
233 | |
234 if (entities.size() > 0) { | |
235 int entitiesCount = entities.size(); | |
236 this.resultSummaryMsg = entitiesCount + " items were found!"; | |
237 this.advancedPaginator.setCurrentPage(0); | |
238 this.advancedPaginator.resetNumberOfPages(entitiesCount); | |
239 this.updateAdvancedEntities(); | |
240 } else { | |
241 this.resultSummaryMsg = "No items were found!"; | |
242 } | |
243 logger.debug("Done searchByRelations."); | |
244 } | |
146 | 245 |
147 /** | 246 /** |
148 * @return the sortAttributeName | 247 * @return the sortAttributeName |
149 */ | 248 */ |
150 public String getSortAttributeName() { | 249 public String getSortAttributeName() { |