Changeset 7591
- Timestamp:
- Feb 19, 2019, 11:17:42 AM (5 years ago)
- Location:
- trunk/src/plugins/core/net/sf/basedb/plugins
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/plugins/core/net/sf/basedb/plugins/AnnotationFlatFileImporter.java
r7478 r7591 75 75 import net.sf.basedb.core.plugin.Request; 76 76 import net.sf.basedb.core.plugin.Response; 77 import net.sf.basedb.core.query.Expressions;78 77 import net.sf.basedb.core.query.Hql; 79 78 import net.sf.basedb.core.query.Orders; 80 import net.sf.basedb.core.query.Restrictions;81 79 import net.sf.basedb.core.signal.ThreadSignalHandler; 80 import net.sf.basedb.plugins.batchimport.AnnotationIdMethod; 81 import net.sf.basedb.plugins.batchimport.IdMethod; 82 import net.sf.basedb.plugins.batchimport.InternalIdMethod; 83 import net.sf.basedb.plugins.batchimport.PropertyIdMethod; 82 84 import net.sf.basedb.plugins.util.Parameters; 83 85 import net.sf.basedb.util.Enumeration; … … 159 161 optionalColumnMapping 160 162 ); 163 164 /** 165 Column mapping parameter for the annotation column used for item identification. 166 @since 3.15 167 */ 168 private static final PluginParameter<String> idAnnotationColumnMapping = new PluginParameter<String>( 169 "idAnnotationColumnMapping", 170 "Annotation ID", 171 "Mapping that picks the annotation value to use for item identification from the data columns. This " + 172 "parameter is required if the selected identification method is based on an annotation, " + 173 "otherwise it is ignored. Example: \\Sample-ID\\", 174 optionalColumnMapping 175 ); 161 176 162 177 /** … … 174 189 ); 175 190 176 private static final PluginParameter<String> findItemsSection = new PluginParameter<String>(177 "findItemsSection",178 "Search for items",179 "Options that affect which items are searched when matching the name/external ID from the file",180 null181 );182 191 private static final PluginParameter<String> identificationSection = new PluginParameter<String>( 192 "idSection", 193 "Item identification", 194 "Options related to how find existing items.", 195 null 196 ); 197 183 198 private static final PluginParameter<String> addReplaceSection = new PluginParameter<String>( 184 199 "addReplaceSection", … … 418 433 { 419 434 String command = request.getCommand(); 435 DbControl dc = null; 420 436 try 421 437 { … … 457 473 } 458 474 459 // Check that a mapping for name OR external ID is given 460 boolean hasExternalId = context == null || hasExternalId(context.getItem()); 461 String nameMapping = (String)request.getParameterValue("nameColumnMapping"); 462 String externalIdMapping = (String)request.getParameterValue("externalIdColumnMapping"); 463 String internalIdMapping = (String)request.getParameterValue("internalIdColumnMapping"); 464 int nullCount = 0; 465 if (nameMapping == null) nullCount++; 466 if (internalIdMapping == null) nullCount++; 467 if (hasExternalId) 468 { 469 if (externalIdMapping == null) nullCount++; 470 if (nullCount == 3) 471 { 472 response.setError("A mapping for either 'Name', 'External Id' or " + 473 "'Internal ID' must be given.", null); 474 return; 475 } 476 if (nullCount != 2) 477 { 478 response.setError("It is not possible to use a mapping for more than one of " + 479 "'Name', 'External Id' and 'Internal ID'.", null); 480 return; 481 } 482 } 483 else 484 { 485 if (nullCount == 2) 486 { 487 response.setError("A mapping for either 'Name' or " + 488 "'Internal ID' must be given.", null); 489 return; 490 } 491 if (nullCount != 1) 492 { 493 response.setError("It is not possible to use a mapping for both " + 494 "'Name' and 'Internal ID'.", null); 495 return; 496 } 475 dc = sc.newDbControl(); 476 // Check that a mapping for name, internal/external ID or annotation is given 477 IdMethod idMethod = getIdMethod(dc, context == null ? null : context.getItem(), (String)request.getParameterValue("idMethod")); 478 PluginParameter<?> idMappingParameter = ri.getParameter(idMethod.getColumnMappingParameterName()); 479 String idMapping = (String)request.getParameterValue(idMappingParameter.getName()); 480 if (idMapping == null) 481 { 482 response.setError("No colum mapping provided for item identification: " + 483 idMappingParameter.getLabel(), null); 484 return; 497 485 } 498 486 499 487 // Check the mapping expressions 500 488 boolean allowComplex = "allow".equals(request.getParameterValue(complexMappings.getName())); 501 checkColumnMapping(parser, nameMapping, allowComplex, nameColumnMapping.getLabel()); 502 checkColumnMapping(parser, externalIdMapping, allowComplex, externalIdColumnMapping.getLabel()); 503 checkColumnMapping(parser, internalIdMapping, allowComplex, internalIdColumnMapping.getLabel()); 489 checkColumnMapping(parser, idMapping, allowComplex, idMappingParameter.getLabel()); 504 490 505 491 // Everything is ok, save values 506 492 if (forJob) storeValue(wrapper, request, fileParameter); 493 storeValue(wrapper, request, ri.getParameter("idMethod")); 494 // Include options 495 if (forJob) 496 { 497 storeValue(job, request, ri.getParameter("includeMine")); 498 storeValue(job, request, ri.getParameter("includeShared")); 499 storeValue(job, request, ri.getParameter("includeInProject")); 500 storeValue(job, request, ri.getParameter("includeOthers")); 501 } 502 507 503 storeValue(wrapper, request, dataHeaderRegexpParameter); 508 504 storeValue(wrapper, request, dataSplitterRegexpParameter); … … 520 516 storeValue(wrapper, request, complexMappings); 521 517 storeValue(wrapper, request, nameColumnMapping); 522 if (hasExternalId) 523 { 524 storeValue(wrapper, request, externalIdColumnMapping); 525 } 518 storeValue(wrapper, request, externalIdColumnMapping); 526 519 storeValue(wrapper, request, internalIdColumnMapping); 520 storeValue(wrapper, request, idAnnotationColumnMapping); 527 521 528 522 if (forJob) … … 563 557 return; 564 558 } 565 566 // Include options567 storeValue(job, request, ri.getParameter("includeMine"));568 storeValue(job, request, ri.getParameter("includeShared"));569 storeValue(job, request, ri.getParameter("includeInProject"));570 storeValue(job, request, ri.getParameter("includeOthers"));571 559 572 560 // Add/Replace options … … 599 587 response.setError(ex.getMessage(), Arrays.asList(ex)); 600 588 } 589 finally 590 { 591 if (dc != null) dc.close(); 592 } 601 593 } 602 594 // ------------------------------------------- … … 616 608 private DateFormatter timestampFormatter; 617 609 private Item itemType; 618 private String searchProperty; 619 private String searchMapping; 620 private Type searchParameterType; 610 private IdMethod idMethod; 611 private String idMapping; 621 612 private Mapper itemMapper; 622 613 private Map<Mapper, AnnotationType> mappers; … … 679 670 protected void begin(FlatFileParser ffp) 680 671 { 672 this.dc = sc.newDbControl(); 681 673 this.ffp = ffp; 682 674 // Formatting options … … 690 682 691 683 this.itemType = Item.valueOf((String)job.getValue("itemType")); 684 this.idMethod = getIdMethod(dc, itemType, (String)job.getValue("idMethod")); 685 this.idMapping = (String)job.getValue(idMethod.getColumnMappingParameterName()); 686 687 /* 692 688 if (job.getValue("externalIdColumnMapping") != null) 693 689 { … … 708 704 this.searchMapping = (String)job.getValue("nameColumnMapping"); 709 705 } 706 */ 707 710 708 this.addToUnlimited = Boolean.TRUE.equals(job.getValue("addToUnlimited")); 711 709 this.replaceExisting = Boolean.TRUE.equals(job.getValue("replaceExisting")); … … 739 737 protected void beginData() 740 738 { 741 this.dc = sc.newDbControl();742 739 this.unitCache = new UnitCache(dc); 743 740 744 741 // Mapper to get name or external ID 745 this.itemMapper = getMapper(ffp, searchMapping, null, null);742 this.itemMapper = getMapper(ffp, idMapping, null, null); 746 743 747 744 // Annotation type mappers … … 780 777 if (Boolean.TRUE.equals((Boolean)job.getValue("includeOthers"))) includes.add(Include.OTHERS); 781 778 782 itemQuery = createQuery(itemType, searchProperty, includes); 779 itemQuery = idMethod.prepareQuery(dc, createQuery(itemType)); 780 itemQuery.setIncludes(includes); 783 781 } 784 782 … … 805 803 if (nameOrId != null) 806 804 { 807 // The 'name' parameter can also query against the external ID 808 itemQuery.setParameter("nameOrId", searchParameterType.parseString(nameOrId), searchParameterType); 809 List<?> result = itemQuery.list(dc); 805 List<?> result = idMethod.find(dc, itemQuery, nameOrId); 810 806 if (result.isEmpty()) 811 807 { … … 814 810 { 815 811 throw new ItemNotFoundException(itemType + 816 "[" + searchProperty+ "=" + nameOrId + "]");812 "[" + idMethod + "=" + nameOrId + "]"); 817 813 } 818 814 else … … 824 820 { 825 821 throw new BaseException("Found " + result.size() + " " + itemType.toString().toLowerCase() + 826 " with " + searchProperty+ "=" + nameOrId);822 " with " + idMethod + "=" + nameOrId); 827 823 } 828 824 for (Object item : result) … … 835 831 else if (!ignoreNotFoundItems) 836 832 { 837 throw new ItemNotFoundException(itemType + "[" + searchProperty+ " has no value in file]");833 throw new ItemNotFoundException(itemType + "[" + idMethod + " has no value in file]"); 838 834 } 839 835 else … … 1047 1043 if (configureParser == null) 1048 1044 { 1049 List<PluginParameter<?>> parameters = new ArrayList<PluginParameter<?>>(); 1050 1051 if (forJob) 1052 { 1053 // The file to import from 1054 parameters.add(fileParameter); 1055 } 1056 else 1057 { 1058 Enumeration<String, String> items = new Enumeration<String, String>(); 1059 for (GuiContext ctx : getGuiContexts()) 1060 { 1061 Item i = ctx.getItem(); 1062 ctx.getItem().name(); 1063 items.add(i.name(), i.toString()); 1064 } 1065 items.sortValues(); 1045 DbControl dc = null; 1046 try 1047 { 1048 dc = sc.newDbControl(); 1049 List<PluginParameter<?>> parameters = new ArrayList<PluginParameter<?>>(); 1050 1051 if (forJob) 1052 { 1053 // The file to import from 1054 parameters.add(fileParameter); 1055 parameters.add(identificationSection); 1056 } 1057 else 1058 { 1059 Enumeration<String, String> items = new Enumeration<String, String>(); 1060 for (GuiContext ctx : getGuiContexts()) 1061 { 1062 Item i = ctx.getItem(); 1063 ctx.getItem().name(); 1064 items.add(i.name(), i.toString()); 1065 } 1066 items.sortValues(); 1067 1068 PluginParameter<String> itemTypesParameter = 1069 new PluginParameter<String>("itemTypes", "Item types", 1070 "Specify which types of items this file format is used for. If " + 1071 "not specified it will be used for all types.", 1072 new StringParameterType(255, null, false, 0, 0, 0, items)); 1073 1074 parameters.add(itemTypesParameter); 1075 } 1066 1076 1067 PluginParameter<String> itemTypesParameter = 1068 new PluginParameter<String>("itemTypes", "Item types", 1069 "Specify which types of items this file format is used for. If " + 1070 "not specified it will be used for all types.", 1071 new StringParameterType(255, null, false, 0, 0, 0, items)); 1077 Enumeration<String, String> idMethods = new Enumeration<String, String>(); 1078 boolean hasAnnotationIdMethod = false; 1079 for (IdMethod idm : getIdMethods(dc, context == null ? null : context.getItem())) 1080 { 1081 if (idm instanceof AnnotationIdMethod) hasAnnotationIdMethod = true; 1082 idMethods.add(idm.getMethod(), idm.getTitle()); 1083 } 1084 PluginParameter<String> idMethodParameter = new PluginParameter<String>( 1085 "idMethod", 1086 "Identification method", 1087 "The method to use for finding existing items. You can use either the " + 1088 "internal ID, the name, external ID or an annotation. If not specified, a " + 1089 "method is automatically selected based on the available column mappings. " + 1090 "If a method is selected, you need to makes sure that the corresponding " + 1091 "column mapping is defined.", 1092 new StringParameterType(null, idMethods.getKey(0), true, 1, 0, 0, idMethods) 1093 ); 1094 parameters.add(idMethodParameter); 1095 1096 if (forJob) 1097 { 1098 ItemContext cc = sc.getCurrentContext(context.getItem()); 1099 Set<Include> include = cc.getInclude(); 1100 parameters.add(new PluginParameter<Boolean>( 1101 "includeMine", 1102 "Owned by me", 1103 "Search items that are owned by yourself.", 1104 include.contains(Include.MINE) ? Boolean.TRUE : null, 1105 optionalBooleanType) 1106 ); 1107 parameters.add(new PluginParameter<Boolean>( 1108 "includeShared", 1109 "Shared to me", 1110 "Search items that have been shared to you by other users.", 1111 include.contains(Include.SHARED) ? Boolean.TRUE : null, 1112 optionalBooleanType) 1113 ); 1114 1115 if (sc.getActiveProjectId() != 0) 1116 { 1117 parameters.add(new PluginParameter<Boolean>( 1118 "includeInProject", 1119 "In current project", 1120 "Search items that are shared to the current project.", 1121 include.contains(Include.IN_PROJECT) ? Boolean.TRUE : null, 1122 optionalBooleanType) 1123 ); 1124 } 1125 if (sc.hasPermission(Permission.READ, context.getItem())) 1126 { 1127 parameters.add(new PluginParameter<Boolean>( 1128 "includeOthers", 1129 "Owned by others", 1130 "Search items that are owned by other users.", 1131 include.contains(Include.OTHERS) ? Boolean.TRUE : null, 1132 optionalBooleanType) 1133 ); 1134 } 1135 } 1072 1136 1073 parameters.add(itemTypesParameter); 1074 } 1075 1076 // Parser regular expressions 1077 parameters.add(parserSection); 1078 parameters.add(dataHeaderRegexpParameter); 1079 parameters.add(dataSplitterRegexpParameter); 1080 parameters.add(trimQuotesParameter); 1081 parameters.add(ignoreRegexpParameter); 1082 parameters.add(dataFooterRegexpParameter); 1083 parameters.add(minDataColumnsParameter); 1084 parameters.add(maxDataColumnsParameter); 1085 parameters.add(Parameters.charsetParameter(null, null, getCharset())); 1086 parameters.add(Parameters.decimalSeparatorParameter(null, null, getDecimalSeparator())); 1087 parameters.add(Parameters.dateFormatParameter(null, null, sc.getUserClientSetting("formatter.date.formatstring"))); 1088 parameters.add(Parameters.timestampFormatParameter(null, null, sc.getUserClientSetting("formatter.datetime.formatstring"))); 1089 1090 // Mappings for Name and External ID 1091 parameters.add(mappingSection); 1092 parameters.add(complexMappings); 1093 parameters.add(nameColumnMapping); 1094 if (context == null || hasExternalId(context.getItem())) 1095 { 1096 parameters.add(externalIdColumnMapping); 1097 } 1098 parameters.add(internalIdColumnMapping); 1099 1100 if (forJob) 1101 { 1102 configureParser = new RequestInformation 1103 ( 1104 Request.COMMAND_CONFIGURE_JOB, 1105 "Select a file to import annotations from", 1106 "Here you select which file to import annotations from, and the " + 1107 "regular expressions and other settings used to parse it. Step 1 of 3", 1108 parameters 1109 ); 1110 } 1111 else 1112 { 1113 configureParser = new RequestInformation 1114 ( 1115 Request.COMMAND_CONFIGURE_PLUGIN, 1116 "Specify parser regular expressions and settings", 1117 "This plug-in can be configured with the regular expressions and " + 1118 "settings used to parse files. Mapping file columns to annotation types must " + 1119 "be done for each import.", 1120 parameters 1121 ); 1137 // Parser regular expressions 1138 parameters.add(parserSection); 1139 parameters.add(dataHeaderRegexpParameter); 1140 parameters.add(dataSplitterRegexpParameter); 1141 parameters.add(trimQuotesParameter); 1142 parameters.add(ignoreRegexpParameter); 1143 parameters.add(dataFooterRegexpParameter); 1144 parameters.add(minDataColumnsParameter); 1145 parameters.add(maxDataColumnsParameter); 1146 parameters.add(Parameters.charsetParameter(null, null, getCharset())); 1147 parameters.add(Parameters.decimalSeparatorParameter(null, null, getDecimalSeparator())); 1148 parameters.add(Parameters.dateFormatParameter(null, null, sc.getUserClientSetting("formatter.date.formatstring"))); 1149 parameters.add(Parameters.timestampFormatParameter(null, null, sc.getUserClientSetting("formatter.datetime.formatstring"))); 1150 1151 // Mappings for Name and External ID 1152 parameters.add(mappingSection); 1153 parameters.add(complexMappings); 1154 parameters.add(nameColumnMapping); 1155 parameters.add(internalIdColumnMapping); 1156 if (context == null || hasExternalId(context.getItem())) 1157 { 1158 parameters.add(externalIdColumnMapping); 1159 } 1160 if (hasAnnotationIdMethod) 1161 { 1162 parameters.add(idAnnotationColumnMapping); 1163 } 1164 1165 if (forJob) 1166 { 1167 configureParser = new RequestInformation 1168 ( 1169 Request.COMMAND_CONFIGURE_JOB, 1170 "Select a file to import annotations from", 1171 "Here you select which file to import annotations from, and the " + 1172 "regular expressions and other settings used to parse it. Step 1 of 3", 1173 parameters 1174 ); 1175 } 1176 else 1177 { 1178 configureParser = new RequestInformation 1179 ( 1180 Request.COMMAND_CONFIGURE_PLUGIN, 1181 "Specify parser regular expressions and settings", 1182 "This plug-in can be configured with the regular expressions and " + 1183 "settings used to parse files. Mapping file columns to annotation types must " + 1184 "be done for each import.", 1185 parameters 1186 ); 1187 } 1188 } 1189 finally 1190 { 1191 if (dc != null) dc.close(); 1122 1192 } 1123 1193 } … … 1193 1263 List<PluginParameter<?>> parameters = new ArrayList<PluginParameter<?>>(); 1194 1264 1195 ItemContext cc = sc.getCurrentContext(context.getItem());1196 Set<Include> include = cc.getInclude();1197 1198 // Should we search in MINE, SHARED, IN_PROJECT, etc.1199 parameters.add(findItemsSection);1200 parameters.add(new PluginParameter<Boolean>(1201 "includeMine",1202 "Owned by me",1203 "Search items that are owned by yourself.",1204 include.contains(Include.MINE) ? Boolean.TRUE : null,1205 optionalBooleanType)1206 );1207 parameters.add(new PluginParameter<Boolean>(1208 "includeShared",1209 "Shared to me",1210 "Search items that have been shared to you by other users.",1211 include.contains(Include.SHARED) ? Boolean.TRUE : null,1212 optionalBooleanType)1213 );1214 1215 if (sc.getActiveProjectId() != 0)1216 {1217 parameters.add(new PluginParameter<Boolean>(1218 "includeInProject",1219 "In current project",1220 "Search items that are shared to the current project.",1221 include.contains(Include.IN_PROJECT) ? Boolean.TRUE : null,1222 optionalBooleanType)1223 );1224 }1225 if (sc.hasPermission(Permission.READ, context.getItem()))1226 {1227 parameters.add(new PluginParameter<Boolean>(1228 "includeOthers",1229 "Owned by others",1230 "Search items that are owned by other users.",1231 include.contains(Include.OTHERS) ? Boolean.TRUE : null,1232 optionalBooleanType)1233 );1234 }1235 1236 1265 // Update/add/replace options 1237 1266 parameters.add(addReplaceSection); … … 1281 1310 } 1282 1311 1312 private List<IdMethod> getIdMethods(DbControl dc, Item item) 1313 { 1314 List<IdMethod> methods = new ArrayList<>(); 1315 methods.add(PropertyIdMethod.NAME); 1316 methods.add(InternalIdMethod.INTERNAL_ID); 1317 if (item == null || hasExternalId(item)) methods.add(PropertyIdMethod.EXTERNAL_ID); 1318 methods.addAll(AnnotationIdMethod.getIdMethods(dc, item)); 1319 return methods; 1320 } 1321 1322 /** 1323 1324 */ 1325 protected IdMethod getIdMethod(DbControl dc, Item item, String method) 1326 { 1327 for (IdMethod im : getIdMethods(dc, item)) 1328 { 1329 if (im.getMethod().equals(method)) 1330 { 1331 return im; 1332 } 1333 } 1334 return PropertyIdMethod.NAME; 1335 } 1336 1283 1337 /** 1284 1338 Create a query that return items of the specified type. We use reflection 1285 1339 to call the static method 'getQuery' on the item's item class, for 1286 example {@link net.sf.basedb.core.Sample#getQuery()}. We add a restriction 1287 to either the 'name' or the 'externalId' property but the parameter is 1288 always called 'name' to make it easier to implement the code that is 1289 using the query. 1340 example {@link net.sf.basedb.core.Sample#getQuery()}. 1290 1341 1291 1342 @param itemType The type of items to search 1292 @param searchProperty If we should search by name, external ID or internal ID1293 @param includes Include options passed to {@link ItemQuery#include(java.util.Collection)}1294 1343 @return A query that searches items of the specified type. 1295 1344 */ 1296 private ItemQuery<?> createQuery(Item itemType, String searchProperty, Set<Include> includes) 1297 { 1298 // Try to create an ItemQuery through reflection 1299 // We assume that the item class has a static method: getQuery() 1300 Class<?> itemClass = itemType.getItemClass(); 1301 Method queryMethod = null; 1302 ItemQuery<?> query = null; 1303 try 1304 { 1305 queryMethod = itemClass.getMethod("getQuery"); 1306 } 1307 catch (NoSuchMethodException ex) 1308 { 1309 throw new BaseException("Can't find method: " + itemType + ".getQuery()", ex); 1310 } 1311 try 1312 { 1313 query = (ItemQuery<?>)queryMethod.invoke(null); 1314 } 1315 catch (Exception ex) 1316 { 1317 throw new BaseException("Can't invoke method: " + itemType + ".getQuery()", ex); 1318 } 1319 1320 // Search on name, external ID or internal ID 1321 // To make it easier set values, the parameter is always called 'nameOrId' 1322 query.restrictPermanent( 1323 Restrictions.eq( 1324 Hql.property(searchProperty), 1325 Expressions.parameter("nameOrId") 1326 ) 1327 ); 1328 1329 // Include options 1330 query.include(includes); 1331 return query; 1345 private ItemQuery<?> createQuery(Item itemType) 1346 { 1347 return itemType.getQuery(); 1332 1348 } 1333 1349 -
trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/AbstractItemImporter.java
r7590 r7591 34 34 import java.util.regex.Pattern; 35 35 36 import net.sf.basedb.core.AnnotationType;37 36 import net.sf.basedb.core.AnnotationTypeCategory; 38 37 import net.sf.basedb.core.ArrayBatch; … … 106 105 import net.sf.basedb.core.query.Expressions; 107 106 import net.sf.basedb.core.query.Hql; 108 import net.sf.basedb.core.query.Orders;109 107 import net.sf.basedb.core.query.Restrictions; 110 108 import net.sf.basedb.plugins.AbstractFlatFileImporter; … … 925 923 if (itemType != null) 926 924 { 927 ItemQuery<AnnotationType> query = AnnotationType.getQuery(itemType); 928 query.include(Include.MINE, Include.IN_PROJECT, Include.SHARED); 929 // The annotation type must be STRING, INTEGER or LONG 930 query.restrict(Restrictions.in(Hql.property("valueType"), Expressions.parameter("valueTypes", Type.INT))); 931 query.setParameter("valueTypes", Arrays.asList(Type.STRING.getValue(), Type.INT.getValue(), Type.LONG.getValue()), Type.INT); 932 // Enumerations can't be used 933 query.restrict(Restrictions.eq(Hql.property("enumeration"), Expressions.bool(false))); 934 935 query.order(Orders.asc(Hql.property("name"))); 936 // Get a list of possible annotation types 937 List<AnnotationType> annotationTypes = new ArrayList<AnnotationType>(query.list(dc)); 938 939 for (AnnotationType at : annotationTypes) 940 { 941 idMethods.add(new AnnotationIdMethod(at)); 942 } 925 idMethods = AnnotationIdMethod.getIdMethods(dc, itemType); 943 926 } 944 927 return idMethods; -
trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/AnnotationIdMethod.java
r7590 r7591 22 22 package net.sf.basedb.plugins.batchimport; 23 23 24 import java.util.ArrayList; 25 import java.util.Arrays; 24 26 import java.util.List; 25 27 … … 29 31 import net.sf.basedb.core.BasicItem; 30 32 import net.sf.basedb.core.DbControl; 33 import net.sf.basedb.core.Include; 34 import net.sf.basedb.core.Item; 31 35 import net.sf.basedb.core.ItemQuery; 32 36 import net.sf.basedb.core.Type; … … 34 38 import net.sf.basedb.core.query.Expressions; 35 39 import net.sf.basedb.core.query.Hql; 40 import net.sf.basedb.core.query.Orders; 36 41 import net.sf.basedb.core.query.Restrictions; 37 42 … … 47 52 { 48 53 54 /** 55 Get identification methods that are based on annotations. The default implementation 56 first calls the {@link #getItemForAnnotationTypes()}. If this returns a non-null value it will 57 make a query for all annotation types that are suitable as identifiers: 58 59 * The value type must be one of STRING, INT or LONG 60 * It must not be an enumeration 61 @param itemType Either a specified item or null to return all possible annotation id methods 62 */ 63 public static List<IdMethod> getIdMethods(DbControl dc, Item itemType) 64 { 65 ItemQuery<AnnotationType> query = AnnotationType.getQuery(itemType); 66 query.include(Include.MINE, Include.IN_PROJECT, Include.SHARED); 67 // The annotation type must be STRING, INTEGER or LONG 68 query.restrict(Restrictions.in(Hql.property("valueType"), Expressions.parameter("valueTypes", Type.INT))); 69 query.setParameter("valueTypes", Arrays.asList(Type.STRING.getValue(), Type.INT.getValue(), Type.LONG.getValue()), Type.INT); 70 // Enumerations can't be used 71 query.restrict(Restrictions.eq(Hql.property("enumeration"), Expressions.bool(false))); 72 73 query.order(Orders.asc(Hql.property("name"))); 74 // Get a list of possible annotation types 75 List<AnnotationType> annotationTypes = new ArrayList<AnnotationType>(query.list(dc)); 76 77 List<IdMethod> idMethods = new ArrayList<>(); 78 for (AnnotationType at : annotationTypes) 79 { 80 idMethods.add(new AnnotationIdMethod(at)); 81 } 82 return idMethods; 83 } 84 85 49 86 private final AnnotationType annotationType; 50 87 /**
Note: See TracChangeset
for help on using the changeset viewer.