Changeset 1427 for extensions
- Timestamp:
- Oct 28, 2011, 2:59:21 PM (12 years ago)
- Location:
- extensions/net.sf.basedb.reggie/branches/2.0-dev
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/net.sf.basedb.reggie/branches/2.0-dev/resources/install.jsp
r1342 r1427 85 85 } 86 86 lastItemType = check.itemType; 87 var name = check.name; 88 if (check.mainType) name += ' <span class="itemsubtype">[' + check.mainType + ']</span>'; 87 89 if (check.id) 88 90 { 89 91 html += '<td><div class="link" onclick="itemOnClick(event, \''+check.itemType+'\','+check.id+')"'; 90 html += ' title="View this item (use CTRL, ALT or SHIFT to edit)">'+ check.name+'</div></td>';92 html += ' title="View this item (use CTRL, ALT or SHIFT to edit)">'+name+'</div></td>'; 91 93 } 92 94 else 93 95 { 94 html += '<td><i>' + check.name + '</i></td>';96 html += '<td><i>' + name + '</i></td>'; 95 97 } 96 98 html += '<td><img src="../../images/'+icon+'"></td><td>'; -
extensions/net.sf.basedb.reggie/branches/2.0-dev/src/net/sf/basedb/reggie/Reggie.java
r1424 r1427 15 15 import net.sf.basedb.core.ItemNotFoundException; 16 16 import net.sf.basedb.core.ItemQuery; 17 import net.sf.basedb.core.ItemSubtype; 17 18 import net.sf.basedb.core.Type; 18 19 import net.sf.basedb.core.query.Expressions; 19 20 import net.sf.basedb.core.query.Hql; 20 21 import net.sf.basedb.core.query.Restrictions; 22 import net.sf.basedb.reggie.dao.Subtype; 21 23 22 24 /** … … 177 179 */ 178 180 public static final String ANNOTATION_PARTITION_DATE = "PartitionDate"; 181 182 183 /** 184 List all subtypes for the given item type that has the given name. 185 @since 2.0 186 */ 187 public static List<ItemSubtype> listSubtypes(DbControl dc, Subtype subtype) 188 { 189 ItemQuery<ItemSubtype> query = ItemSubtype.getQuery(subtype.getMainType()); 190 query.restrict( 191 Restrictions.eq( 192 Hql.property("name"), 193 Expressions.parameter("name", subtype.getName(), Type.STRING) 194 )); 195 query.include(Include.ALL); 196 return query.list(dc); 197 } 198 199 /** 200 Find a single item subtype with the given name. If exactly one is found it 201 is returned, otherwise null is returned or an exception is thrown 202 depending on the exceptionIfNotFound parameter. 203 */ 204 public static ItemSubtype findSubtype(DbControl dc, Subtype subtype, boolean exceptionIfNotFound) 205 { 206 List<ItemSubtype> result = listSubtypes(dc, subtype); 207 ItemSubtype s = null; 208 if (result.size() == 0) 209 { 210 if (exceptionIfNotFound) throw new ItemNotFoundException("ItemSubtype["+subtype.getName()+"]"); 211 } 212 else if (result.size() > 1) 213 { 214 if (exceptionIfNotFound) throw new InvalidDataException("Found > 1 ItemSubtype["+subtype.getName()+"]"); 215 } 216 else 217 { 218 s = result.get(0); 219 } 220 return s; 221 } 179 222 180 223 /** -
extensions/net.sf.basedb.reggie/branches/2.0-dev/src/net/sf/basedb/reggie/servlet/InstallServlet.java
r1409 r1427 2 2 3 3 import java.io.IOException; 4 import java.util.ArrayList;5 4 import java.util.Arrays; 6 5 import java.util.Collections; … … 23 22 import net.sf.basedb.core.Item; 24 23 import net.sf.basedb.core.ItemKey; 24 import net.sf.basedb.core.ItemSubtype; 25 25 import net.sf.basedb.core.MultiPermissions; 26 26 import net.sf.basedb.core.Permission; … … 31 31 import net.sf.basedb.core.Type; 32 32 import net.sf.basedb.reggie.Reggie; 33 import net.sf.basedb.reggie.dao.Subtype; 33 34 import net.sf.basedb.util.EqualsHelper; 34 35 import net.sf.basedb.util.error.ThrowableUtil; … … 92 93 sharedToActiveProject.set(Project.getById(dc, projectId), Permission.USE); 93 94 } 95 96 Map<String, Item> subtypeItems = new HashMap<String, Item>(); 97 98 // Subtype checks 99 jsonChecks.add(checkSubtype(dc, Subtype.PATIENT, createIfMissing)); 100 jsonChecks.add(checkSubtype(dc, Subtype.CASE, createIfMissing, Subtype.PATIENT)); 101 jsonChecks.add(checkSubtype(dc, Subtype.SPECIMEN,createIfMissing, Subtype.CASE)); 102 jsonChecks.add(checkSubtype(dc, Subtype.HISTOLOGY, createIfMissing, Subtype.SPECIMEN)); 103 jsonChecks.add(checkSubtype(dc, Subtype.LYSATE, createIfMissing, Subtype.SPECIMEN)); 94 104 95 105 // Annotation type checks … … 146 156 jsonChecks.add(checkAnnotationType(dc, Reggie.ANNOTATION_PARTITION_DATE, new Item[]{Item.SAMPLE, Item.EXTRACT}, Type.DATE, 1, 147 157 null, effectiveOptions, createIfMissing)); 158 148 159 149 160 json.put("checks", jsonChecks); … … 430 441 } 431 442 432 443 /** 444 Create a subtype with the given options. The subtype is created in 445 a separate transaction. 446 @since 2.0 447 */ 448 public ItemSubtype createSubtype(SessionControl sc, Subtype def, Subtype... relatedTo) 449 { 450 ItemSubtype subtype = null; 451 DbControl dc = sc.newDbControl(); 452 try 453 { 454 subtype = ItemSubtype.getNew(dc, def.getMainType()); 455 subtype.setName(def.getName()); 456 457 if (relatedTo != null) 458 { 459 for (Subtype related : relatedTo) 460 { 461 subtype.setRelatedSubtype(related.load(dc)); 462 } 463 } 464 465 dc.saveItem(subtype); 466 dc.commit(); 467 } 468 finally 469 { 470 if (dc != null) dc.close(); 471 } 472 return subtype; 473 } 474 475 /** 476 Check for an existing item subtype with the given options. 477 A JSONObject is returned with the result. The following 478 keys are used: 479 <ul> 480 <li>itemType: ITEMSUBTYPE 481 <li>name: The name of the subtype 482 <li>id: The id of the subtype if it exists 483 <li>mainType: The main item type that the subtype applies to 484 <li>status: ok, error, or missing 485 <li>message: A descriptive message in case of an error 486 </ul> 487 @since 2.0 488 */ 489 @SuppressWarnings("unchecked") 490 public JSONObject checkSubtype(DbControl dc, Subtype subtype, 491 boolean createIfMissing, Subtype... relatedTo) 492 { 493 494 JSONObject json = new JSONObject(); 495 JSONArray jsonMessages = new JSONArray(); 496 json.put("itemType", Item.ITEMSUBTYPE.name()); 497 json.put("name", subtype.getName()); 498 json.put("mainType", subtype.getMainType().name()); 499 500 List<ItemSubtype> result = Reggie.listSubtypes(dc, subtype); 501 if (result.size() == 0) 502 { 503 if (createIfMissing) 504 { 505 ItemSubtype s = createSubtype(dc.getSessionControl(), subtype, relatedTo); 506 json.put("id", s.getId()); 507 json.put("status", "ok"); 508 jsonMessages.add("Created"); 509 } 510 else 511 { 512 json.put("status", "missing"); 513 jsonMessages.add("Not found"); 514 } 515 } 516 else if (result.size() > 1) 517 { 518 json.put("status", "error"); 519 jsonMessages.add("Found > 1 subtype"); 520 } 521 else 522 { 523 ItemSubtype s = result.get(0); 524 json.put("id", s.getId()); 525 json.put("status", "ok"); // For now -- more checks below 526 527 if (relatedTo != null) 528 { 529 for (Subtype related : relatedTo) 530 { 531 ItemSubtype r = s.getRelatedSubtype(related.getMainType()); 532 if (r == null) 533 { 534 json.put("status", "error"); 535 jsonMessages.add("Should be related to '" + related.getName() + "'"); 536 } 537 else if (!r.getName().equals(related.getName())) 538 { 539 json.put("status", "error"); 540 jsonMessages.add("Should be related to: '" + 541 related.getName() + "' not '" + r.getName() + "'"); 542 } 543 } 544 } 545 546 } 547 if (jsonMessages.size() == 0) jsonMessages.add("Ok"); 548 json.put("messages", jsonMessages); 549 return json; 550 551 } 552 553 433 554 /** 434 555 Store options for enumerated annotation types.
Note: See TracChangeset
for help on using the changeset viewer.