Changeset 5755
- Timestamp:
- Nov 25, 2019, 9:40:49 AM (3 years ago)
- Location:
- extensions/net.sf.basedb.reggie/branches/4.24-stable
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/net.sf.basedb.reggie/branches/4.24-stable/resources/mipsprep/lib_registration.js
r5754 r5755 137 137 var tmp = templates[i]; 138 138 var option = new Option(tmp.name, tmp.id); 139 option.template = tmp; 139 140 frm.barcodeTemplate[frm.barcodeTemplate.length] = option; 140 141 } … … 147 148 148 149 Wizard.setInputStatus('barcodeTemplate'); 150 Wizard.hideGoNextConfirmation(); 149 151 barcodeTemplateIsValid = false; 150 152 … … 164 166 165 167 barcodeTemplateIsValid = true; 166 Wizard.setInputStatus('barcodeTemplate', 'valid'); 168 169 var template = frm.barcodeTemplate[frm.barcodeTemplate.selectedIndex].template; 170 if (template.otherPlates && template.otherPlates.length > 0) 171 { 172 var msg = 'This template is also used by ' + Strings.encodeTags(template.otherPlates[0].name); 173 if (template.otherPlates.length > 1) 174 { 175 msg += ' and '+(template.otherPlates.length-1)+' more plate(s)'; 176 } 177 Wizard.setInputStatus('barcodeTemplate', 'warning', msg); 178 Wizard.showGoNextConfirmation(true, 'Verify registration of plate with duplicate barcode template'); 179 } 180 else 181 { 182 Wizard.setInputStatus('barcodeTemplate', 'valid'); 183 } 167 184 } 168 185 -
extensions/net.sf.basedb.reggie/branches/4.24-stable/src/net/sf/basedb/reggie/query/AnyToAnyRestriction.java
r3051 r5755 2 2 3 3 import java.util.Collection; 4 import java.util.Collections; 4 5 5 6 import net.sf.basedb.core.DbControl; 6 7 import net.sf.basedb.core.Item; 7 8 import net.sf.basedb.core.Type; 9 import net.sf.basedb.core.query.Expressions; 10 import net.sf.basedb.core.query.Hql; 8 11 import net.sf.basedb.core.query.Query; 9 12 import net.sf.basedb.core.query.QueryElement; 10 13 import net.sf.basedb.core.query.Restriction; 14 import net.sf.basedb.core.query.Restrictions; 11 15 import net.sf.basedb.util.EqualsHelper; 12 16 … … 29 33 public static AnyToAnyRestriction exists(String linkName, Item linkedTo) 30 34 { 31 return new AnyToAnyRestriction(linkName, linkedTo, true); 35 Restriction link = linkedTo == null ? null : 36 Restrictions.eq(Hql.property("at", "toType"), Expressions.integer(linkedTo.getValue())); 37 return new AnyToAnyRestriction(linkName, link, true); 32 38 } 39 40 /** 41 Create a restriction that restrict a query to return 42 items that has a linked item with the given link name. 43 An optional restriction can be used to limit the query 44 to on the linked item (use "at" as prefix in the HQL). 45 @since 4.24.1 46 */ 47 public static AnyToAnyRestriction exists(String linkName, Restriction restriction) 48 { 49 return new AnyToAnyRestriction(linkName, restriction, true); 50 } 51 33 52 34 53 /** … … 39 58 public static AnyToAnyRestriction missing(String linkName, Item linkedTo) 40 59 { 41 return new AnyToAnyRestriction(linkName, linkedTo, false); 60 Restriction link = linkedTo == null ? null : 61 Restrictions.eq(Hql.property("at", "toType"), Expressions.integer(linkedTo.getValue())); 62 return new AnyToAnyRestriction(linkName, link, false); 42 63 } 43 64 44 65 private final String parameterName; 45 private final String subQuery;66 private final Restriction linkRestriction; 46 67 private final String linkName; 47 68 private final boolean hasLink; 48 69 49 private AnyToAnyRestriction(String linkName, Item linkedTo, boolean hasLink)70 private AnyToAnyRestriction(String linkName, Restriction linkRestriction, boolean hasLink) 50 71 { 51 72 this.linkName = linkName; 52 73 this.hasLink = hasLink; 53 74 this.parameterName = "LN" + System.identityHashCode(this); 54 StringBuilder sb = new StringBuilder(); 55 sb.append("(SELECT at.fromId FROM AnyToAnyData at WHERE at.name = :"); 56 sb.append(parameterName); 57 if (linkedTo != null) 58 { 59 sb.append(" AND at.toType=").append(linkedTo.getValue()); 60 } 61 sb.append(")"); 62 this.subQuery = sb.toString(); 75 this.linkRestriction = linkRestriction; 63 76 } 64 77 … … 67 80 { 68 81 query.setParameter(parameterName, linkName, Type.STRING); 69 return query.getRootAlias() + (hasLink ? ".id = ANY" : ".id <> ALL") + subQuery;82 return query.getRootAlias() + (hasLink ? ".id = ANY" : ".id <> ALL") + getSubQuery(query, dc); 70 83 } 71 84 … … 73 86 public Collection<? extends QueryElement> getChildren() 74 87 { 75 return null;88 return linkRestriction != null ? Collections.singleton(linkRestriction) : null; 76 89 } 77 90 91 private String getSubQuery(Query query, DbControl dc) 92 { 93 StringBuilder sb = new StringBuilder(); 94 sb.append("(SELECT at.fromId FROM AnyToAnyData at WHERE at.name = :"); 95 sb.append(parameterName); 96 if (linkRestriction != null) 97 { 98 if (query == null) 99 { 100 sb.append(" AND ").append(linkRestriction.toString()); 101 } 102 else 103 { 104 sb.append(" AND ").append(linkRestriction.toQl(query, dc)); 105 } 106 } 107 sb.append(")"); 108 return sb.toString(); 109 } 78 110 79 111 @Override 80 112 public String toString() 81 113 { 82 return (hasLink ? "id = ANY" : "id <> ALL") + subQuery;114 return (hasLink ? "id = ANY" : "id <> ALL") + getSubQuery(null, null); 83 115 } 84 116 -
extensions/net.sf.basedb.reggie/branches/4.24-stable/src/net/sf/basedb/reggie/servlet/MipsServlet.java
r5603 r5755 65 65 import net.sf.basedb.reggie.plugins.AliquotImporter; 66 66 import net.sf.basedb.reggie.plugins.AliquotImporter.AliquotPlate; 67 import net.sf.basedb.reggie.query.AnyToAnyRestriction; 67 68 import net.sf.basedb.util.EqualsHelper; 68 69 import net.sf.basedb.util.FileUtil; … … 348 349 query.order(Orders.asc(Hql.property("name"))); 349 350 351 // Find other MIPs plates with a given template that has not yet been pooled 352 // We use this information to display a warning if registering more than one plate with 353 // the same barcode template since that is typically a mistake 354 ItemQuery<BioPlate> unpooledQuery = BioPlate.getQuery(); 355 unpooledQuery.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT); 356 // Only MIPs plates that are not destroyed 357 BioplateType.MIPS.addFilter(dc, unpooledQuery, true); 358 // Must have a PLATE_PROCESS_RESULT=Success annotation 359 unpooledQuery.join(Annotations.innerJoin(null, Annotationtype.PLATE_PROCESS_RESULT.load(dc), "ppr")); 360 unpooledQuery.restrict(Restrictions.eq(Hql.alias("ppr"), Expressions.string(ReactionPlate.PROCESS_SUCCESSFUL))); 361 // Must NOT have a PoolDate annotation 362 unpooledQuery.join(Annotations.leftJoin(null, Annotationtype.POOL_DATE.load(dc), "pd")); 363 unpooledQuery.restrict(Restrictions.eq(Hql.alias("pd"), null)); 364 // Filter on BarcodeTemplate link 365 unpooledQuery.restrict(AnyToAnyRestriction.exists("BarcodeTemplate", 366 Restrictions.eq(Hql.property("at", "toId"), Hql.entityParameter("template", Item.BIOPLATE)))); 367 unpooledQuery.order(Orders.asc(Hql.property("name"))); 368 350 369 List<BioPlate> result = query.list(dc); 351 370 JSONArray jsonPlates = new JSONArray(); … … 359 378 jsonPlate.put("comments", plate.getDescription()); 360 379 jsonPlates.add(jsonPlate); 380 381 JSONArray jsonUnpooled = new JSONArray(); 382 unpooledQuery.setEntityParameter("template", plate); 383 for (BioPlate unpooled : unpooledQuery.list(dc)) 384 { 385 JSONObject jsonUP = new JSONObject(); 386 jsonUP.put("id", unpooled.getId()); 387 jsonUP.put("name", unpooled.getName()); 388 jsonUnpooled.add(jsonUP); 389 } 390 jsonPlate.put("otherPlates", jsonUnpooled); 391 361 392 } 362 393 json.put("templates", jsonPlates);
Note: See TracChangeset
for help on using the changeset viewer.