Changeset 5892
- Timestamp:
- Nov 28, 2011, 1:58:56 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/clients/web/net/sf/basedb/clients/web/ExperimentExplorer.java
r5885 r5892 63 63 import net.sf.basedb.core.SessionControl; 64 64 import net.sf.basedb.core.VirtualColumn; 65 import net.sf.basedb.core.VirtualDb;66 65 import net.sf.basedb.core.VirtualTable; 67 66 import net.sf.basedb.core.ItemContext.SortDirection; … … 138 137 */ 139 138 private static final ItemContext defaultReporterContext = 140 Base.createDefaultContext("@externalId", "externalId ");139 Base.createDefaultContext("@externalId", "externalId,symbol"); 141 140 142 141 /** … … 190 189 private final Experiment experiment; 191 190 192 private final VirtualDb virtualDb;193 191 194 192 /** … … 244 242 this.bioAssaySet = bioAssaySet; 245 243 this.experiment = bioAssaySet.getExperiment(); 246 this.virtualDb = experiment.getVirtualDb();247 244 this.bioAssays = new HashMap<Short, Integer>(); 248 245 this.snapshotManager = new SnapshotManager(); … … 693 690 if (cache == null) initReporterCache(dc); 694 691 692 Experiment exp = getExperiment(dc); 695 693 ItemContext cc = dc.getSessionControl().getCurrentContext(Item.REPORTER, getSubContext(), null); 696 694 if (exp.getVirtualDb().hasClonedReporters()) 695 { 696 cc.setPropertyInspector(exp.getVirtualDb().getQueryPropertyInspector()); 697 } 698 else 699 { 700 cc.setPropertyInspector(null); 701 } 702 697 703 // Get the reporter id:s to show on the current page 698 704 List<Integer> reporterIds = new ArrayList<Integer>(cc.getRowsPerPage()+1); … … 706 712 707 713 // Create reporter query 708 DynamicReporterQuery reporterQuery = Reporter.getDynamicQuery( getExperiment(dc));714 DynamicReporterQuery reporterQuery = Reporter.getDynamicQuery(exp); 709 715 // Guard against no hits 710 716 if (reporterIds.size() == 0) reporterIds.add(-1); … … 935 941 reporterQuery.select(position); 936 942 ItemContext cc = dc.getSessionControl().getCurrentContext(Item.REPORTER, getSubContext(), null); 943 if (getExperiment(dc).getVirtualDb().hasClonedReporters()) 944 { 945 cc.setPropertyInspector(getExperiment(dc).getVirtualDb().getQueryPropertyInspector()); 946 } 947 else 948 { 949 cc.setPropertyInspector(null); 950 } 937 951 cc.configureQuery(dc, reporterQuery, null); 938 952 reporterQuery.order(Orders.asc(Expressions.selected(position))); -
trunk/src/clients/web/net/sf/basedb/clients/web/taglib/table/Data.java
r4889 r5892 154 154 if (!(getParent() instanceof Table)) throw new JspTagException("Tag <tbl:data> must be inside a <tbl:table> tag"); 155 155 table = (Table)getParent(); 156 table.endColumnDefinitions(); 156 157 157 158 StringBuilder sb = new StringBuilder(); -
trunk/src/clients/web/net/sf/basedb/clients/web/taglib/table/Form.java
r5111 r5892 96 96 { 97 97 table = (Table)findAncestorWithClass(this, Table.class); 98 table.endColumnDefinitions(); 98 99 // Make a copy of the headers 99 100 headers = new HashMap<String, String>(table.getColumnContent()); -
trunk/src/clients/web/net/sf/basedb/clients/web/taglib/table/Table.java
r5643 r5892 272 272 The ID of all visible columns, sorted by the order they should appear. 273 273 */ 274 private LinkedHashSet<String> visibleColumns; 274 private Set<String> visibleColumns; 275 276 /** 277 The ID of all defined columns 278 */ 279 private Set<String> definedColumns; 275 280 276 281 private Map<String, String> columnContent; … … 406 411 visibleColumns.add(columnId); 407 412 } 413 definedColumns.add(columnId); 408 414 if (cd.getFormatter() != null) columnFormatter.put(columnId, cd.getFormatter()); 409 415 … … 426 432 } 427 433 434 void endColumnDefinitions() 435 { 436 visibleColumns.retainAll(definedColumns); 437 } 438 428 439 boolean isColumnVisible(String columnId) 429 440 { … … 555 566 visibleColumns.remove("-"); // "-" represents the required columns 556 567 } 568 definedColumns = new HashSet<String>(); 557 569 558 570 hiddenForm = new StringBuilder(); -
trunk/src/core/net/sf/basedb/core/ItemContext.java
r5817 r5892 43 43 import net.sf.basedb.util.encode.EncodeUtil; 44 44 import net.sf.basedb.util.encode.TabCrLfEncoderDecoder; 45 import net.sf.basedb.util.filter.Filter; 45 46 import net.sf.basedb.util.jep.ChannelFunction; 46 47 import net.sf.basedb.util.jep.Jep; … … 183 184 private Map<String, Object> objects; 184 185 private Query query; 186 private Filter<String> propertyInspector; 185 187 186 188 /** … … 1143 1145 { 1144 1146 this.query = query; 1147 } 1148 1149 /** 1150 Set a filter for this context that is used to inspect which properties 1151 that are allowed to be used in queries. If a filter has been set the 1152 {@link #configureQuery(DbControl, EntityQuery, boolean)} and 1153 {@link #configureQuery(DbControl, AbstractSqlQuery, List)} methods will 1154 check each property before it is used for sorting, filtering, etc. 1155 1156 @param filter A filter or null to disable property inspection 1157 @since 3.1 1158 */ 1159 public void setPropertyInspector(Filter<String> filter) 1160 { 1161 this.propertyInspector = filter; 1145 1162 } 1146 1163 … … 1194 1211 for (String sortProperty : sp) 1195 1212 { 1196 String alias = null; 1197 if (sortProperty.startsWith("$")) 1213 if (propertyInspector == null || propertyInspector.evaluate(sortProperty)) 1198 1214 { 1199 // sortProperty is $alias.property or $alias only 1200 int dotIndex = sortProperty.indexOf("."); 1201 if (dotIndex == -1) 1215 String alias = null; 1216 if (sortProperty.startsWith("$")) 1202 1217 { 1203 // alias only 1204 alias = sortProperty.substring(1); 1205 sortProperty = null; 1218 // sortProperty is $alias.property or $alias only 1219 int dotIndex = sortProperty.indexOf("."); 1220 if (dotIndex == -1) 1221 { 1222 // alias only 1223 alias = sortProperty.substring(1); 1224 sortProperty = null; 1225 } 1226 else 1227 { 1228 // alias.property 1229 alias = sortProperty.substring(1, dotIndex); 1230 sortProperty = sortProperty.substring(dotIndex+1); 1231 } 1206 1232 } 1207 else 1233 // left join if sort property is association 1234 if (autoLeftJoin) 1208 1235 { 1209 // alias.property 1210 alias = sortProperty.substring(1, dotIndex); 1211 sortProperty = sortProperty.substring(dotIndex+1); 1236 int dotIndex = sortProperty.lastIndexOf("."); 1237 if (dotIndex >= 0) 1238 { 1239 String toJoin = sortProperty.substring(0, dotIndex); 1240 if (alias != null) toJoin = "$" + alias + "." + toJoin; 1241 leftJoins.add(toJoin); 1242 sortedProperties.add(toJoin); 1243 } 1212 1244 } 1245 Expression hqlSortby = Hql.property(alias, sortProperty); 1246 query.order(SortDirection.ASC == getSortDirection() ? Orders.asc(hqlSortby) : Orders.desc(hqlSortby)); 1213 1247 } 1214 // left join if sort property is association1215 if (autoLeftJoin)1216 {1217 int dotIndex = sortProperty.lastIndexOf(".");1218 if (dotIndex >= 0)1219 {1220 String toJoin = sortProperty.substring(0, dotIndex);1221 if (alias != null) toJoin = "$" + alias + "." + toJoin;1222 leftJoins.add(toJoin);1223 sortedProperties.add(toJoin);1224 }1225 }1226 Expression hqlSortby = Hql.property(alias, sortProperty);1227 query.order(SortDirection.ASC == getSortDirection() ? Orders.asc(hqlSortby) : Orders.desc(hqlSortby));1228 1248 } 1229 1249 } … … 1254 1274 { 1255 1275 PropertyFilter filter = filterPair.getEffectiveFilter(); 1256 try1276 if (propertyInspector == null || propertyInspector.evaluate(filter.getProperty())) 1257 1277 { 1258 Restriction r = filter.getRestriction(dc, query); 1259 if (r != null) 1278 try 1260 1279 { 1261 restrictions[i] = r; 1262 i++; 1263 // left join if filter property is association 1264 if (autoLeftJoin) 1280 Restriction r = filter.getRestriction(dc, query); 1281 if (r != null) 1265 1282 { 1266 String filterProperty = filter.getProperty(); 1267 if (filterProperty != null && !filterProperty.startsWith("£") && !filterProperty.startsWith("&") && !filterProperty.startsWith("!")) 1283 restrictions[i] = r; 1284 i++; 1285 // left join if filter property is association 1286 if (autoLeftJoin) 1268 1287 { 1269 int lastDotIndex = filterProperty.lastIndexOf('.'); 1270 int firstDotIndex = filterProperty.indexOf('.'); 1271 if (lastDotIndex >= 0) 1288 String filterProperty = filter.getProperty(); 1289 if (filterProperty != null && !filterProperty.startsWith("£") && !filterProperty.startsWith("&") && !filterProperty.startsWith("!")) 1272 1290 { 1273 filterProperty = filterProperty.substring(0, lastDotIndex); 1274 if (!filterProperty.startsWith("$") || lastDotIndex != firstDotIndex) 1291 int lastDotIndex = filterProperty.lastIndexOf('.'); 1292 int firstDotIndex = filterProperty.indexOf('.'); 1293 if (lastDotIndex >= 0) 1275 1294 { 1276 leftJoins.add(filterProperty); 1295 filterProperty = filterProperty.substring(0, lastDotIndex); 1296 if (!filterProperty.startsWith("$") || lastDotIndex != firstDotIndex) 1297 { 1298 leftJoins.add(filterProperty); 1299 } 1277 1300 } 1278 1301 } … … 1280 1303 } 1281 1304 } 1282 }1283 catch (Throwable ex)1284 {1285 String msg = "Could not filter on '" + getItemType() + "." + filter.getProperty() + "'";1286 Application.getLogger().warn(msg, ex);1287 setMessage(msg + ": " + ex.getMessage());1305 catch (Throwable ex) 1306 { 1307 String msg = "Could not filter on '" + getItemType() + "." + filter.getProperty() + "'"; 1308 Application.getLogger().warn(msg, ex); 1309 setMessage(msg + ": " + ex.getMessage()); 1310 } 1288 1311 } 1289 1312 } … … 1397 1420 query.setMaxResults(getRowsPerPage()); 1398 1421 1422 1399 1423 // Add selection elements 1400 1424 if (selectionList != null) … … 1402 1426 for (String selectProperty : selectionList) 1403 1427 { 1404 Select select = getDynamicSelect(dc, selectProperty); //, joins); 1405 if (select != null) 1428 if (propertyInspector == null || propertyInspector.evaluate(selectProperty)) 1406 1429 { 1407 query.select(select); 1430 Select select = getDynamicSelect(dc, selectProperty); //, joins); 1431 if (select != null) 1432 { 1433 query.select(select); 1434 } 1408 1435 } 1409 1436 } … … 1420 1447 for (String sortProperty : sp) 1421 1448 { 1422 Expression sortby = getDynamicExpression(dc, sortProperty); 1423 if (sortby != null) 1449 if (propertyInspector == null || propertyInspector.evaluate(sortProperty)) 1424 1450 { 1425 query.order(SortDirection.ASC == getSortDirection() ? Orders.asc(sortby) : Orders.desc(sortby));1426 if (s electionList == null || !selectionList.contains(sortProperty))1451 Expression sortby = getDynamicExpression(dc, sortProperty); 1452 if (sortby != null) 1427 1453 { 1428 // We must add the sort property to the selection list 1429 query.select(Selects.expression(sortby, "sorted" + sortIndex)); 1454 query.order(SortDirection.ASC == getSortDirection() ? Orders.asc(sortby) : Orders.desc(sortby)); 1455 if (selectionList == null || !selectionList.contains(sortProperty)) 1456 { 1457 // We must add the sort property to the selection list 1458 query.select(Selects.expression(sortby, "sorted" + sortIndex)); 1459 } 1430 1460 } 1461 sortIndex++; 1431 1462 } 1432 sortIndex++;1433 1463 } 1434 1464 } … … 1442 1472 { 1443 1473 PropertyFilter filter = filterPair.getEffectiveFilter(); 1444 try1474 if (propertyInspector == null || propertyInspector.evaluate(filter.getProperty())) 1445 1475 { 1446 Restriction r = filter.getDynamicRestriction(dc); 1447 if (r != null) 1476 try 1448 1477 { 1449 restrictions[i] = r; 1450 i++; 1478 Restriction r = filter.getDynamicRestriction(dc); 1479 if (r != null) 1480 { 1481 restrictions[i] = r; 1482 i++; 1483 } 1451 1484 } 1452 }1453 catch (Throwable ex)1454 {1455 setMessage(ex.getClass().getSimpleName() + ": " + ex.getMessage());1485 catch (Throwable ex) 1486 { 1487 setMessage(ex.getClass().getSimpleName() + ": " + ex.getMessage()); 1488 } 1456 1489 } 1457 1490 } -
trunk/src/core/net/sf/basedb/core/VirtualDb.java
r5879 r5892 27 27 import net.sf.basedb.core.data.SharedData; 28 28 import net.sf.basedb.core.hibernate.ExecuteUpdateWork; 29 import net.sf.basedb.util.filter.Filter; 29 30 30 31 import java.sql.SQLException; … … 210 211 { 211 212 return hasClonedReporters() && getData().getReporterCloneTemplate().getProperties().containsKey(propertyName); 213 } 214 215 /** 216 Return a filter that can be used to check that a query is only 217 using cloned reporter properties for sorting, filtering, etc. 218 The filter will reject reporter properties (starting with '@') 219 that have not been cloned. 220 221 @return A filter or null if this virtual db doesn't have cloned reporters 222 @since 3.1 223 @see ItemContext#setPropertyInspector(Filter) 224 */ 225 public Filter<String> getQueryPropertyInspector() 226 { 227 Filter<String> filter = null; 228 if (hasClonedReporters()) 229 { 230 filter = new Filter<String>() 231 { 232 @Override 233 public boolean evaluate(String property) 234 { 235 if (!property.startsWith("@")) return true; 236 return hasClonedReporterProperty(property.substring(1)); 237 } 238 }; 239 } 240 return filter; 212 241 } 213 242 -
trunk/www/views/experiments/explorer/view/view.jsp
r5885 r5892 88 88 <%! 89 89 private static final Item itemType = Item.SPOTDATA; 90 private static final String defaultReporterColumns = "externalId ";90 private static final String defaultReporterColumns = "externalId,symbol"; 91 91 %> 92 92 <% … … 385 385 value="<%=String.valueOf(bioAssaySetId)%>" 386 386 /> 387 388 387 <% 389 388 for (TableColumn tc : reporterColumns) … … 394 393 clazz="prompt" 395 394 title="<%=HTML.encodeTags(tc.getTitle())%>" 396 397 395 formatter="<%=tc.getFormatter()%>" 398 396 /> 399 397 <% 400 398 } 401 %>402 403 <%404 399 List<ExtendedProperty> reporterProperties = ExtendedProperties.getProperties("ReporterData"); 405 400 %> … … 419 414 { 420 415 String name = ep.getName(); 421 Formatter formatter = FormatterFactory.getExtendedPropertyFormatter(sc, ep);422 416 %> 423 417 <tbl:cell column="<%=ep.getName()%>"><tbl:cellvalue value="<%=reporter.getExtended(name)%>" /></tbl:cell>
Note: See TracChangeset
for help on using the changeset viewer.