Changeset 4597
- Timestamp:
- Oct 22, 2008, 11:46:10 AM (15 years ago)
- Location:
- trunk/src/plugins/core/net/sf/basedb/plugins/batchimport
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/AbstractItemImporter.java
r4595 r4597 241 241 ); 242 242 243 private static final PluginParameter<String> lackOfUsePermissionOnReferencedItemErrorParameter = new PluginParameter<String>( 244 "lackOfUsePermissionOnReferencedItemError", 245 "Lack of use permission on referenced item", 246 "What to do if the plug-in finds a referenced item and has no permission to use it.\n\n"+ 243 private static final PluginParameter<String> noWritePermissionToItemErrorParameter = new PluginParameter<String>( 244 "noWritePermissionToItemError", 245 "Not granted write permission to item", 246 "What to do if the plug-in finds an existing item but has no write permission to it.\n\n"+ 247 "skip = Skip the current data line and continue.\n"+ 248 "fail = Stop with an error message", 249 new StringParameterType(255, null, false, 1, 0, 0, 250 Arrays.asList( new String[] { "skip", "fail"} )) 251 ); 252 253 private static final PluginParameter<String> noUsePermissionToReferenceErrorParameter = new PluginParameter<String>( 254 "noUsePermissionToReferenceError", 255 "Not granted use permission to reference", 256 "What to do if the plug-in finds a reference but has no permission to use it.\n\n"+ 247 257 "ignore = Do not set/update the reference\n" + 248 258 "fail = Stop with an error message", … … 414 424 storeValue(job, request, numberFormatErrorParameter); 415 425 storeValue(job, request, numberOutOfRangeErrorParameter); 416 storeValue(job, request, lackOfUsePermissionOnReferencedItemErrorParameter); 426 storeValue(job, request, noWritePermissionToItemErrorParameter); 427 storeValue(job, request, noUsePermissionToReferenceErrorParameter); 417 428 418 429 // Save context info … … 476 487 private boolean failIfNotFoundReference; 477 488 private boolean failIfMultipleFoundReferences; 478 private boolean failIfNoUsePermissionOnReference; 489 private boolean failIfNoWritePermissionToItem; 490 private boolean failIfNoUsePermissionToReference; 479 491 480 492 // Status report … … 530 542 this.failIfNotFoundReference = "fail".equals(getErrorOption("referenceNotFoundError")); 531 543 this.failIfMultipleFoundReferences = "fail".equals(getErrorOption("multipleReferencesFoundError")); 532 this.failIfNoUsePermissionOnReference = "fail".equals(getErrorOption("lackOfUsePermissionOnReferencedItemError")); 544 this.failIfNoWritePermissionToItem = "fail".equals(getErrorOption("noWritePermissionToItemError")); 545 this.failIfNoUsePermissionToReference = "fail".equals(getErrorOption("noUsePermissionToReferenceError")); 546 533 547 this.cropStrings = "crop".equals(getErrorOption("stringTooLongError")); 534 548 … … 565 579 if (Boolean.TRUE.equals((Boolean)job.getValue("includeOthers"))) includes.add(Include.OTHERS); 566 580 itemQuery = idMethod.prepareQuery(dc, createItemQuery()); 567 itemQuery.setItemPermission(Permission.WRITE);568 581 itemQuery.include(includes); 569 582 } … … 606 619 else 607 620 { 621 // and only query the database if not found 608 622 List<I> items = idMethod.find(dc, itemQuery, identifier); 609 // and only query the database if not found 610 if (items.size() == 1) 611 { 612 item = items.get(0); 623 // pick out items on which write permission is granted 624 List<I> writableItems = new ArrayList<I>(); 625 for (I i : items) 626 { 627 if (i.hasPermission(Permission.WRITE)) 628 { 629 writableItems.add(i); 630 } 631 } 632 if (writableItems.size() == 1) 633 { 634 item = writableItems.get(0); 613 635 itemCache.put(cacheKey, item); 614 636 } 615 else if ( items.size() > 1)637 else if (writableItems.size() > 1) 616 638 { 617 639 // If we find multiple items, we either throw an error or do nothing 618 640 if (failIfMultipleFoundItems) 619 641 { 620 throw new BaseException("Found " + items.size() + " items [" + idMethod + "=" + identifier + "]");642 throw new BaseException("Found " + writableItems.size() + " items [" + idMethod + "=" + identifier + "]"); 621 643 } 622 log("Found " + items.size() + " items: " + idMethod + "=" + identifier, data); 644 log("Found " + writableItems.size() + " items: " + idMethod + "=" + identifier, data); 645 return; 646 } 647 else if (items.size() > 0) 648 { 649 // Found item(s) but none with write permission to. Either throw an exception or do nothing 650 if (failIfNoWritePermissionToItem) 651 { 652 throw new PermissionDeniedException(Permission.WRITE, 653 itemQuery.getItemType()+"[" + idMethod + "=" + identifier + "]"); 654 } 655 log("Not granted write permission to " + itemQuery.getItemType()+"[" + idMethod + "=" + identifier + "]", data); 623 656 return; 624 657 } … … 1576 1609 { 1577 1610 // No use permission on item 1578 if (failIfNoUsePermission OnReference)1611 if (failIfNoUsePermissionToReference) 1579 1612 { 1580 1613 throw new PermissionDeniedException(Permission.USE, itemType+"[" +idMethod + "=" + identifier + "]"); … … 1776 1809 if (!updateMode) parameters.add(itemExistsErrorParameter); 1777 1810 parameters.add(multipleItemsFoundErrorParameter); 1778 parameters.add(lackOfUsePermissionOnReferencedItemErrorParameter);1811 if (updateMode) parameters.add(noWritePermissionToItemErrorParameter); 1779 1812 parameters.add(referenceNotFoundErrorParameter); 1813 parameters.add(noUsePermissionToReferenceErrorParameter); 1780 1814 parameters.add(multipleReferencesFoundErrorParameter); 1781 1815 parameters.add(Parameters.invalidUseOfNullError(null, null, null)); -
trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/HybridizationImporter.java
r4585 r4597 255 255 if (slide != null && slide.isUsedByOther(hyb)) 256 256 { 257 // NOTE! There is currently no error handling option to bypass this 258 // It will be implemented in 2.9 259 throw new PermissionDeniedException(Permission.USE, 260 slide + ". It is already used by another hybridization."); 257 if ("fail".equals(getErrorOption("noUsePermissionToReferenceError"))) 258 { 259 throw new PermissionDeniedException(Permission.USE, 260 slide + ". It is already used by another hybridization."); 261 } 261 262 } 262 if (nameOrId == null || slide != null) hyb.setArraySlide(slide);263 else if (nameOrId == null || slide != null) hyb.setArraySlide(slide); 263 264 } 264 265 updateMultiLineItem(dc, hyb, data, 0);
Note: See TracChangeset
for help on using the changeset viewer.