Changeset 7594
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/plugins/core/net/sf/basedb/plugins/AnnotationFlatFileImporter.java
r7593 r7594 1029 1029 private ItemList getItemListFromContext(DbControl dc, GuiContext context) 1030 1030 { 1031 if (context == null) return null; 1031 1032 ItemList list = null; 1032 1033 String subcontext = context.getSubContext(); -
trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/AbstractItemImporter.java
r7591 r7594 65 65 import net.sf.basedb.core.ItemContext; 66 66 import net.sf.basedb.core.ItemKey; 67 import net.sf.basedb.core.ItemList; 67 68 import net.sf.basedb.core.ItemNotFoundException; 68 69 import net.sf.basedb.core.ItemQuery; … … 530 531 private ItemSubtype selectedSubtype; 531 532 private ItemQuery<I> itemQuery; 533 private ItemList itemList; 532 534 533 535 private String lastIdentifier; … … 588 590 this.idMethod = getIdMethod(dc, (String)job.getValue("idMethod")); 589 591 this.idMapping = (String)job.getValue(idMethod.getColumnMappingParameterName()); 592 this.itemList = (ItemList)job.getValue("memberOfList"); 590 593 this.itemCache = new HashMap<String, BasicItem>(); 591 594 String mode = (String)job.getValue("mode"); 592 595 boolean updateMode = mode == null || mode.contains("update"); 593 boolean createMode = mode == null || mode.contains("create");596 boolean createMode = (mode == null || mode.contains("create")) && itemList == null; 594 597 595 598 // Error handling, we don't use the error handling in AbstractFlatFileImporter 596 599 this.dryRun = job.getJob().isDryRun(); 597 this.createNotFoundItems = createMode || "create".equals(getErrorOption("itemNotFoundError"));600 this.createNotFoundItems = createMode; 598 601 this.failIfNotFoundItems = !createMode && "fail".equals(getErrorOption("itemNotFoundError")); 599 this.updateExistingItems = updateMode || "update".equals(getErrorOption("itemExistsError"));602 this.updateExistingItems = updateMode; 600 603 this.failIfItemExists = !updateMode && "fail".equals(getErrorOption("itemExistsError")); 601 604 this.failIfMultipleFoundItems = "fail".equals(getErrorOption("multipleItemsFoundError")); … … 644 647 if (Boolean.TRUE.equals((Boolean)job.getValue("includeInProject"))) includes.add(Include.IN_PROJECT); 645 648 if (Boolean.TRUE.equals((Boolean)job.getValue("includeOthers"))) includes.add(Include.OTHERS); 646 itemQuery = idMethod.prepareQuery(dc, createItemQuery( ));649 itemQuery = idMethod.prepareQuery(dc, createItemQuery(itemList)); 647 650 itemQuery.setIncludes(includes); 648 651 … … 973 976 protected void addMoreErrorParameters(List<PluginParameter<?>> parameters) 974 977 {} 978 979 /** 980 Create a new query that returns items that are members of the given list. 981 The default implementation calls {@link #createItemQuery()} and then 982 applies a restriction to it if the list is not null and have the 983 same member type as the query. 984 @since 3.15 985 */ 986 protected ItemQuery<I> createItemQuery(ItemList list) 987 { 988 ItemQuery<I> query = createItemQuery(); 989 if (list != null && list.getMemberType() == query.getItemType()) 990 { 991 query.restrictPermanent( 992 Hql.restriction("$id=ANY(SELECT mmb FROM ItemListData lst INNER JOIN lst.members mmb WHERE lst.id=" + list.getId()+")", "$") 993 ); 994 } 995 return query; 996 } 975 997 976 998 /** … … 2359 2381 } 2360 2382 2383 /** 2384 If the current context is the "Members" tab for an item list we load 2385 the item list and will later require that all items to be annotated 2386 are members of that list. 2387 */ 2388 private ItemList getItemListFromContext(DbControl dc, GuiContext context) 2389 { 2390 if (context == null) return null; 2391 ItemList list = null; 2392 String subcontext = context.getSubContext(); 2393 if (subcontext != null && subcontext.startsWith("listmembers")) 2394 { 2395 // If subcontext is: "listmembers.nnnn" nnn is the id of the item list 2396 int listId = Values.getInt(subcontext.split("\\.")[1]); 2397 list = ItemList.getById(dc, listId); 2398 // Reject lists with different type of member item (should not happen) 2399 if (list.getMemberType() != context.getItem()) list = null; 2400 } 2401 return list; 2402 } 2403 2361 2404 protected RequestInformation getConfigureParserParameters(GuiContext context, boolean forJob) 2362 2405 { … … 2368 2411 dc = sc.newDbControl(); 2369 2412 List<PluginParameter<?>> parameters = new ArrayList<PluginParameter<?>>(); 2370 2413 ItemList list = getItemListFromContext(dc, context); 2414 2371 2415 if (forJob) 2372 2416 { … … 2380 2424 List<String> allowedModes = new ArrayList<String>(); 2381 2425 String defaultMode = "update"; 2382 if (context == null || sc.hasPermission(Permission.CREATE, context.getItem())) 2383 { 2426 if (list != null) 2427 { 2428 allowedModes.add(null); // To force the user to manually select a mode (BASE will auto-select the first option) 2429 allowedModes.add("add-members"); 2430 allowedModes.add("remove-members"); 2431 defaultMode = null; 2432 } 2433 else if (context == null || sc.hasPermission(Permission.CREATE, context.getItem())) 2434 { 2435 allowedModes.add(null); // To force the user to manually select a mode (BASE will auto-select the first option) 2384 2436 allowedModes.add("create+update"); 2385 2437 allowedModes.add("create"); 2386 defaultMode = "create+update";2438 defaultMode = null; 2387 2439 } 2388 2440 allowedModes.add("update"); … … 2390 2442 "mode", 2391 2443 "Mode", 2392 "Select an import mode: \n" + 2393 "create+update = create missing items, update existing items\n" + 2394 "create = create missing items only\n" + 2395 "update = update existing items only\n\n" + 2396 "NOTE! Not all modes may be available due to lack of permissions.", 2444 "Select an import mode: \n\n" + 2445 (allowedModes.contains("add-members") ? "<b>add-members</b> = add members to the list (no updates)\n" : "") + 2446 (allowedModes.contains("remove-members") ? "<b>remove-members</b> = remove members from the list (no updates)\n" : "") + 2447 (allowedModes.contains("create+update") ? "<b>create+update</b> = create missing items, update existing items\n" : "") + 2448 (allowedModes.contains("create") ? "<b>create</b> = create missing items only\n" : "") + 2449 (allowedModes.contains("update") ? "<b>update</b> = update existing items only\n" : ""), 2397 2450 new StringParameterType(255, defaultMode, forJob, 1, 0, 0, allowedModes) 2398 2451 ); … … 2431 2484 ); 2432 2485 parameters.add(idMethodParameter); 2486 2487 if (list != null) 2488 { 2489 parameters.add(new PluginParameter<ItemList>( 2490 "memberOfList", "Member of list", 2491 "In 'update' mode the plug-in will only update values for items if they are members of this list.", 2492 new ItemParameterType<>(ItemList.class, list, true, 1, Arrays.asList(list)) 2493 )); 2494 } 2433 2495 2434 2496 if (getItemForSubtypes() != null) … … 2443 2505 int selectedSubtypeId = Values.getInt(cc.getPropertyValue("itemSubtype")); 2444 2506 ItemSubtype defaultSubtype = selectedSubtypeId == 0 ? null : ItemSubtype.getById(dc, selectedSubtypeId); 2507 if (defaultSubtype == null && list != null) defaultSubtype = list.getItemSubtype(); 2445 2508 2446 2509 // Create parameter … … 2558 2621 2559 2622 String mode = (String)job.getValue("mode"); 2623 ItemList itemList = (ItemList)job.getValue("memberOfList"); 2560 2624 boolean updateMode = mode == null || mode.contains("update"); 2561 boolean createMode = mode == null || mode.contains("create");2625 boolean createMode = (mode == null || mode.contains("create")) && itemList == null;; 2562 2626 2563 2627 // Error handling options … … 2567 2631 parameters.add(defaultErrorParameter); 2568 2632 if (!createMode) parameters.add(itemNotFoundErrorParameter); 2569 if ( !updateMode) parameters.add(itemExistsErrorParameter);2633 if (createMode) parameters.add(itemExistsErrorParameter); 2570 2634 parameters.add(multipleItemsFoundErrorParameter); 2571 2635 if (updateMode) parameters.add(noWritePermissionToItemErrorParameter); -
trunk/www/common/plugin/configure.jsp
r7494 r7594 537 537 { 538 538 listValue = HTML.encodeTags(value == null ? "" : value.toString()); 539 if (enumeration == null) listText = listValue;539 if (enumeration == null) listText = value == null ? "- not specified -" : listValue; 540 540 } 541 541 %>
Note: See TracChangeset
for help on using the changeset viewer.