Changeset 7593


Ignore:
Timestamp:
Feb 20, 2019, 9:13:00 AM (5 years ago)
Author:
Nicklas Nordborg
Message:

References #2150: Batch item importers in item list members view

The annotation importer has been updated so that if it is started from the "Members" tab of an item list, it will only update annotations on items that are members of the list.

Location:
trunk/src/plugins/core/net/sf/basedb/plugins
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/plugins/core/net/sf/basedb/plugins/AnnotationFlatFileImporter.java

    r7591 r7593  
    5353import net.sf.basedb.core.Item;
    5454import net.sf.basedb.core.ItemContext;
     55import net.sf.basedb.core.ItemList;
    5556import net.sf.basedb.core.ItemNotFoundException;
    5657import net.sf.basedb.core.ItemParameterType;
     
    495496        if (forJob)
    496497        {
     498          storeValue(job, request, ri.getParameter("memberOfList"));
    497499          storeValue(job, request, ri.getParameter("includeMine"));
    498500          storeValue(job, request, ri.getParameter("includeShared"));
     
    614616  private Map<String, Set<NewAnnotations>> itemCache;
    615617  private ItemQuery<?> itemQuery;
     618  private ItemList itemList;
    616619  private boolean addToUnlimited;
    617620  private boolean replaceExisting;
     
    684687    this.idMethod = getIdMethod(dc, itemType, (String)job.getValue("idMethod"));
    685688    this.idMapping = (String)job.getValue(idMethod.getColumnMappingParameterName());
    686 
    687     /*
    688     if (job.getValue("externalIdColumnMapping") != null)
    689     {
    690       this.searchProperty = "externalId";
    691       this.searchParameterType = Type.STRING;
    692       this.searchMapping = (String)job.getValue("externalIdColumnMapping");
    693     }
    694     else if (job.getValue("internalIdColumnMapping") != null)
    695     {
    696       this.searchProperty = "id";
    697       this.searchParameterType = Type.INT;
    698       this.searchMapping = (String)job.getValue("internalIdColumnMapping");
    699     }
    700     else
    701     {
    702       this.searchProperty = "name";
    703       this.searchParameterType = Type.STRING;
    704       this.searchMapping = (String)job.getValue("nameColumnMapping");
    705     }
    706     */
     689    this.itemList = (ItemList)job.getValue("memberOfList");
    707690   
    708691    this.addToUnlimited = Boolean.TRUE.equals(job.getValue("addToUnlimited"));
     
    777760    if (Boolean.TRUE.equals((Boolean)job.getValue("includeOthers"))) includes.add(Include.OTHERS);
    778761   
    779     itemQuery = idMethod.prepareQuery(dc, createQuery(itemType));
     762    itemQuery = idMethod.prepareQuery(dc, createQuery(itemType, itemList));
    780763    itemQuery.setIncludes(includes);
    781764  }
     
    10391022  }
    10401023 
     1024  /**
     1025    If the current context is the "Members" tab for an item list we load
     1026    the item list and will later require that all items to be annotated
     1027    are members of that list.
     1028  */
     1029  private ItemList getItemListFromContext(DbControl dc, GuiContext context)
     1030  {
     1031    ItemList list = null;
     1032    String subcontext = context.getSubContext();
     1033    if (subcontext != null && subcontext.startsWith("listmembers"))
     1034    {
     1035      // If subcontext is: "listmembers.nnnn" nnn is the id of the item list
     1036      int listId = Values.getInt(subcontext.split("\\.")[1]);
     1037      list = ItemList.getById(dc, listId);
     1038      // Reject lists with different type of member item (should not happen)
     1039      if (list.getMemberType() != context.getItem()) list = null;
     1040    }
     1041    return list;
     1042  }
     1043 
    10411044  private RequestInformation getConfigureParserParameters(GuiContext context, boolean forJob)
    10421045  {
     
    10961099        if (forJob)
    10971100        {
     1101          ItemList list = getItemListFromContext(dc, context);
     1102          if (list != null)
     1103          {
     1104            parameters.add(new PluginParameter<ItemList>(
     1105              "memberOfList", "Member of list",
     1106              "The plug-in will only update annotations for items if they are members of this list.",
     1107              new ItemParameterType<>(ItemList.class, list, true, 1, Arrays.asList(list))
     1108            ));
     1109          }
     1110
    10981111          ItemContext cc = sc.getCurrentContext(context.getItem());
    10991112          Set<Include> include = cc.getInclude();
     
    13431356    @return A query that searches items of the specified type.
    13441357  */
    1345   private ItemQuery<?> createQuery(Item itemType)
    1346   {
    1347     return itemType.getQuery();
     1358  private ItemQuery<?> createQuery(Item itemType, ItemList list)
     1359  {
     1360    return list != null && list.getMemberType() == itemType ? list.getMembers() : itemType.getQuery();
    13481361  }
    13491362 
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/AnnotationIdMethod.java

    r7591 r7593  
    183183  public String toString()
    184184  {
    185     return "[A] " + annotationType.getName();
     185    return annotationType.getName();
    186186  }
    187187  // --------------------------
Note: See TracChangeset for help on using the changeset viewer.