Changeset 7853
- Timestamp:
- Oct 19, 2020, 9:33:29 AM (2 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/core/AnyToAny.java
r7381 r7853 24 24 25 25 import java.util.ArrayList; 26 import java.util.Collections; 26 27 import java.util.List; 27 28 … … 35 36 import net.sf.basedb.core.query.Restrictions; 36 37 import net.sf.basedb.core.signal.ThreadSignalHandler; 38 import net.sf.basedb.util.AnyToAnyLinkStatistics; 39 import net.sf.basedb.util.AnyToAnyLinkStatistics.Options; 37 40 38 41 /** … … 341 344 } 342 345 346 /** 347 Get information about existing links from the items that are returned by 348 the given query. If the query returns a lot of items a max number of samples 349 to be used may be specified. The samples are randomly selected. See 350 {@link Options} for more information. 351 @return A list with statistics about links (can be empty) 352 @since 3.17 353 */ 354 public static List<AnyToAnyLinkStatistics> getExistingLinkStatistics(DbControl dc, ItemQuery<?> query, Options options) 355 { 356 List<Integer> idList = query.idList(dc); 357 if (idList.size() == 0) return Collections.emptyList(); 358 359 if (options == null) options = new Options(); 360 if (options.getMaxRandomSamples() > 0 && idList.size() > options.getMaxRandomSamples()) 361 { 362 // Shuffle the list and then use the first 'maxRandomSamples' in it. 363 Collections.shuffle(idList); 364 idList = idList.subList(0, options.getMaxRandomSamples()); 365 } 366 int minCount = Math.max(1, Math.min(options.getMinCount(), idList.size() / options.getMinFraction())); 367 int sampleSize = idList.size(); 368 369 String hql = "SELECT t.name, t.toType, COUNT(*)"; 370 hql += " FROM AnyToAnyData t "; 371 hql += " WHERE t.fromType="+query.getItemType().getValue(); 372 hql += " AND t.fromId IN (" + net.sf.basedb.util.Values.getString(idList, ",", true) + ")"; 373 hql += " GROUP BY t.name, t.toType"; 374 hql += " HAVING COUNT(*) >= " + minCount; 375 hql += " ORDER BY COUNT(*), t.name"; 376 377 org.hibernate.query.Query<Object[]> ataquery = HibernateUtil.createQuery(dc.getHibernateSession(), hql); 378 List<Object[]> list = HibernateUtil.loadList(ataquery, dc.getSessionControl()); 379 List<AnyToAnyLinkStatistics> stats = new ArrayList<>(list.size()); 380 for (Object[] row : list) 381 { 382 AnyToAnyLinkStatistics stat = new AnyToAnyLinkStatistics(); 383 stat.setSampleSize(sampleSize); 384 stat.setLinkName((String)row[0]); 385 stat.setTargetType(Item.fromValue((Integer)row[1])); 386 stat.setCount(((Long)row[2]).intValue()); 387 stats.add(stat); 388 } 389 return stats; 390 } 391 343 392 /** 344 393 Delete all links that are linking to non-existing items. This method -
trunk/src/core/net/sf/basedb/core/HibernateUtil.java
r7729 r7853 1889 1889 */ 1890 1890 @SuppressWarnings({ "unchecked", "rawtypes" }) 1891 static Query<?> createQuery(Session session, String hql)1891 static <T> Query<T> createQuery(Session session, String hql) 1892 1892 throws BaseException 1893 1893 { -
trunk/www/common/columns/add_linkeditem_column.js
r7852 r7853 33 33 configure.initPage = function() 34 34 { 35 Events.addEventHandler('presets', 'change', configure.presetSelected); 35 36 Events.addEventHandler(document.body, 'click', configure.hideMessage); 36 37 … … 38 39 Buttons.addClickHandler('close', App.closeWindow); 39 40 Buttons.addClickHandler('btnAdd', configure.addColumn); 41 } 42 43 configure.presetSelected = function(event) 44 { 45 var frm = document.forms['linkedItems']; 46 47 if (frm.presets.selectedIndex > 0) 48 { 49 var selected = frm.presets[frm.presets.selectedIndex]; 50 frm.linkName.value = Data.get(selected, 'linkname'); 51 Forms.selectListOption(frm.targetItemType, Data.get(selected, 'targettype')); 52 frm.presets.selectedIndex = 0; 53 } 40 54 } 41 55 -
trunk/www/common/columns/add_linkeditem_column.jsp
r7852 r7853 22 22 --%> 23 23 <%@ page pageEncoding="UTF-8" session="false" 24 import="net.sf.basedb.core.AnyToAny" 25 import="net.sf.basedb.core.DbControl" 24 26 import="net.sf.basedb.core.SessionControl" 25 27 import="net.sf.basedb.core.Item" 28 import="net.sf.basedb.core.ItemQuery" 26 29 import="net.sf.basedb.core.ItemContext" 27 import="net.sf.basedb.core.Metadata" 30 import="net.sf.basedb.core.Metadata" 31 import="net.sf.basedb.util.AnyToAnyLinkStatistics" 28 32 import="net.sf.basedb.clients.web.Base" 29 33 import="net.sf.basedb.clients.web.util.HTML" … … 37 41 final String ID = sc.getId(); 38 42 final Item itemType = Item.valueOf(request.getParameter("item_type")); 43 final String subContext = Values.getString(request.getParameter("subcontext"), ""); 39 44 final ItemContext cc = Base.getAndSetCurrentContext(sc, Item.ANYTOANY, null, null); 40 %> 41 <base:page type="popup" title="Add linked item column"> 42 <base:head scripts="~add_linkeditem_column.js" /> 43 <base:body> 44 <h1>Add linked item column <base:help helpid="columns.configure.add_linkeditem_column" /></h1> 45 46 <form name="linkedItems" method="post"> 47 <input type="hidden" name="ID" value="<%=ID%>"> 48 <input type="hidden" name="item_type" value="<%=itemType.name()%>"> 45 final DbControl dc = sc.newDbControl(); 46 try 47 { 48 ItemQuery<?> statQuery = itemType.getQuery(); 49 ItemContext ccList = Base.getAndSetCurrentContext(sc, itemType, subContext, null, null); 50 ccList.configureQuery(dc, statQuery, true); 51 statQuery.setMaxResults(-1); 52 statQuery.setFirstResult(0); 53 final List<AnyToAnyLinkStatistics> stats = AnyToAny.getExistingLinkStatistics(dc, statQuery, new AnyToAnyLinkStatistics.Options()); 54 %> 55 <base:page type="popup" title="Add linked item column"> 56 <base:head scripts="~add_linkeditem_column.js" /> 57 <base:body> 58 <h1>Add linked item column <base:help helpid="columns.configure.add_linkeditem_column" /></h1> 49 59 50 <div class="content"> 51 <table class="fullform input100 bottomborder"> 52 <tr> 53 <th>Link name</th> 54 <td> 55 <input class="text required auto-init" data-auto-init="focus" 56 type="text" name="linkName" id="linkName"> 57 </td> 58 </tr> 59 <tr> 60 <th>Target item type</th> 61 <td> 62 <select name="targetItemType" id="targetItemType" style="min-width: 15em;"> 63 <option value="">- any - 64 <% 65 List<String> recentTypes = cc.getRecent("toTypes"); 66 if (recentTypes.size() == 0) 67 { 68 recentTypes = Arrays.asList("FILE"); 69 } 70 %> 71 <option value="0" disabled class="recentheader">- recently used - 72 <% 73 for (String r : recentTypes) 74 { 60 <form name="linkedItems" method="post"> 61 <input type="hidden" name="ID" value="<%=ID%>"> 62 <input type="hidden" name="item_type" value="<%=itemType.name()%>"> 63 64 <div class="content"> 65 <table class="fullform input100 bottomborder"> 66 <tr> 67 <th></th> 68 <td> 69 <select name="presets" id="presets" style="width: 25em;"> 70 <option value="">- presets - 71 <% 72 for (AnyToAnyLinkStatistics stat : stats) 73 { 74 String name = HTML.encodeTags(stat.getLinkName()); 75 String targetType = stat.getTargetType().name(); 76 %> 77 <option data-linkname="<%=name%>" data-targettype="<%=targetType%>"><%=name%> [<%=targetType%>] 78 <% 79 } 75 80 %> 76 <option value="<%=r%>"><%=r%> 81 </select> 82 </td> 83 </tr> 84 <tr> 85 <th style="border-top-width: 0;">Link name</th> 86 <td> 87 <input class="text required auto-init" data-auto-init="focus" 88 type="text" name="linkName" id="linkName" style="width: 25em;"> 89 </td> 90 </tr> 91 <tr> 92 <th>Target item type</th> 93 <td> 94 <select name="targetItemType" id="targetItemType" style="min-width: 25em;"> 95 <option value="">- any - 77 96 <% 78 } 79 %> 80 <option value="0" disabled class="recentheader">- all - 81 <% 82 for (Item targetItem : Metadata.getNameableItems()) 83 { 84 if (targetItem.getDefinedPermissions() != null) 97 List<String> recentTypes = cc.getRecent("toTypes"); 98 if (recentTypes.size() == 0) 99 { 100 recentTypes = Arrays.asList("FILE"); 101 } 102 %> 103 <option value="0" disabled class="recentheader">- recently used - 104 <% 105 for (String r : recentTypes) 85 106 { 86 107 %> 87 <option value="<%= targetItem.name() %>"><%=targetItem.name()%>108 <option value="<%=r%>"><%=r%> 88 109 <% 89 110 } 90 } 91 %> 92 </select> 93 </td> 94 </tr> 95 <tr class="dynamic"> 96 <th></th> 97 <td><div id="added-column-msg" class="messagecontainer note" style="display:none; margin: 0.5em 0;"></div></td> 98 </tr> 99 </table> 100 </div> 101 </form> 102 103 <base:buttongroup subclass="dialogbuttons"> 104 <base:button id="btnAdd" title="Add" /> 105 <base:button id="close" title="Close" /> 106 </base:buttongroup> 107 108 </base:body> 109 </base:page> 111 %> 112 <option value="0" disabled class="recentheader">- all - 113 <% 114 for (Item targetItem : Metadata.getNameableItems()) 115 { 116 if (targetItem.getDefinedPermissions() != null) 117 { 118 %> 119 <option value="<%=targetItem.name() %>"><%=targetItem.name() %> 120 <% 121 } 122 } 123 %> 124 </select> 125 </td> 126 </tr> 127 <tr class="dynamic"> 128 <th></th> 129 <td><div id="added-column-msg" class="messagecontainer note" style="display:none; margin: 0.5em 0;"></div></td> 130 </tr> 131 </table> 132 </div> 133 </form> 134 135 <base:buttongroup subclass="dialogbuttons"> 136 <base:button id="btnAdd" title="Add" /> 137 <base:button id="close" title="Close" /> 138 </base:buttongroup> 139 140 </base:body> 141 </base:page> 142 <% 143 } 144 finally 145 { 146 if (dc != null) dc.close(); 147 } 148 %> 110 149 111 150 -
trunk/www/common/columns/configure.js
r7851 r7853 248 248 var url = 'add_linkeditem_column.jsp?ID='+App.getSessionId(); 249 249 url += '&item_type='+Data.get('page-data', 'item-type'); 250 url += '&subcontext='+encodeURIComponent(Data.get('page-data', 'subcontext') || ''); 250 251 Dialogs.openPopup(url, 'SelectLinkedItemColumn', 600, 400); 251 252 }
Note: See TracChangeset
for help on using the changeset viewer.