Changeset 4597


Ignore:
Timestamp:
Oct 22, 2008, 11:46:10 AM (13 years ago)
Author:
Martin Svensson
Message:

Fixes #1142 Lack of permission when trying to write to an item or use a reference is now handled. The last case covers also when an array slide is used by another hyb.

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  
    241241    );
    242242 
    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"+
    247257      "ignore = Do not set/update the reference\n" +
    248258      "fail = Stop with an error message",
     
    414424        storeValue(job, request, numberFormatErrorParameter);
    415425        storeValue(job, request, numberOutOfRangeErrorParameter);
    416         storeValue(job, request, lackOfUsePermissionOnReferencedItemErrorParameter);
     426        storeValue(job, request, noWritePermissionToItemErrorParameter);
     427        storeValue(job, request, noUsePermissionToReferenceErrorParameter);
    417428       
    418429        // Save context info
     
    476487  private boolean failIfNotFoundReference;
    477488  private boolean failIfMultipleFoundReferences;
    478   private boolean failIfNoUsePermissionOnReference;
     489  private boolean failIfNoWritePermissionToItem;
     490  private boolean failIfNoUsePermissionToReference;
    479491 
    480492  // Status report
     
    530542    this.failIfNotFoundReference = "fail".equals(getErrorOption("referenceNotFoundError"));
    531543    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   
    533547    this.cropStrings = "crop".equals(getErrorOption("stringTooLongError"));
    534548
     
    565579    if (Boolean.TRUE.equals((Boolean)job.getValue("includeOthers"))) includes.add(Include.OTHERS);
    566580    itemQuery = idMethod.prepareQuery(dc, createItemQuery());
    567     itemQuery.setItemPermission(Permission.WRITE);
    568581    itemQuery.include(includes);
    569582  }
     
    606619      else
    607620      {
     621        // and only query the database if not found
    608622        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);
    613635          itemCache.put(cacheKey, item);
    614636        }
    615         else if (items.size() > 1)
     637        else if (writableItems.size() > 1)
    616638        {
    617639          // If we find multiple items, we either throw an error or do nothing
    618640          if (failIfMultipleFoundItems)
    619641          {
    620             throw new BaseException("Found " + items.size() + " items [" + idMethod + "=" + identifier + "]");
     642            throw new BaseException("Found " + writableItems.size() + " items [" + idMethod + "=" + identifier + "]");
    621643          }
    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);
    623656          return;
    624657        }
     
    15761609        {
    15771610          // No use permission on item
    1578           if (failIfNoUsePermissionOnReference)
     1611          if (failIfNoUsePermissionToReference)
    15791612          {
    15801613            throw new PermissionDeniedException(Permission.USE, itemType+"[" +idMethod + "=" + identifier + "]");
     
    17761809      if (!updateMode) parameters.add(itemExistsErrorParameter);
    17771810      parameters.add(multipleItemsFoundErrorParameter);
    1778       parameters.add(lackOfUsePermissionOnReferencedItemErrorParameter);
     1811      if (updateMode) parameters.add(noWritePermissionToItemErrorParameter);
    17791812      parameters.add(referenceNotFoundErrorParameter);
     1813      parameters.add(noUsePermissionToReferenceErrorParameter);
    17801814      parameters.add(multipleReferencesFoundErrorParameter);
    17811815      parameters.add(Parameters.invalidUseOfNullError(null, null, null));
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/HybridizationImporter.java

    r4585 r4597  
    255255      if (slide != null && slide.isUsedByOther(hyb))
    256256      {
    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        }
    261262      }
    262       if (nameOrId == null || slide != null) hyb.setArraySlide(slide);
     263      else if (nameOrId == null || slide != null) hyb.setArraySlide(slide);
    263264    }
    264265    updateMultiLineItem(dc, hyb, data, 0);
Note: See TracChangeset for help on using the changeset viewer.