Changeset 4372
- Timestamp:
- Jul 4, 2008, 11:22:35 AM (15 years ago)
- Location:
- trunk/src
- Files:
-
- 5 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/core/Install.java
r4366 r4372 642 642 createPluginDefinition("net.sf.basedb.plugins.batchimport.BioSourceImporter", null, keyEveryoneUse, true, null, false); 643 643 createPluginDefinition("net.sf.basedb.plugins.batchimport.SampleImporter", null, keyEveryoneUse, true, null, false); 644 644 createPluginDefinition("net.sf.basedb.plugins.batchimport.ExtractImporter", null, keyEveryoneUse, true, null, false); 645 createPluginDefinition("net.sf.basedb.plugins.batchimport.LabeledExtractImporter", null, keyEveryoneUse, true, null, false); 646 645 647 646 648 // Plugin configurations -
trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/AbstractItemImporter.java
r4366 r4372 41 41 import net.sf.basedb.core.BooleanParameterType; 42 42 import net.sf.basedb.core.DbControl; 43 import net.sf.basedb.core.Extract; 43 44 import net.sf.basedb.core.File; 45 import net.sf.basedb.core.Hardware; 46 import net.sf.basedb.core.HardwareType; 44 47 import net.sf.basedb.core.Include; 45 48 import net.sf.basedb.core.IntegerUtil; … … 50 53 import net.sf.basedb.core.ItemQuery; 51 54 import net.sf.basedb.core.Job; 55 import net.sf.basedb.core.Label; 56 import net.sf.basedb.core.LabeledExtract; 52 57 import net.sf.basedb.core.NumberOutOfRangeException; 53 58 import net.sf.basedb.core.Permission; … … 59 64 import net.sf.basedb.core.StringTooLongException; 60 65 import net.sf.basedb.core.StringUtil; 66 import net.sf.basedb.core.SystemItems; 61 67 import net.sf.basedb.core.plugin.GuiContext; 62 68 import net.sf.basedb.core.plugin.InteractivePlugin; … … 65 71 import net.sf.basedb.core.plugin.Request; 66 72 import net.sf.basedb.core.plugin.Response; 73 import net.sf.basedb.core.query.Expressions; 74 import net.sf.basedb.core.query.Hql; 75 import net.sf.basedb.core.query.Restrictions; 67 76 import net.sf.basedb.plugins.AbstractFlatFileImporter; 68 77 import net.sf.basedb.plugins.util.Parameters; … … 393 402 private String lastIdentifier; 394 403 private int numMultiLines; 404 private boolean skippedLast; 395 405 396 406 // Error handling … … 483 493 if (Boolean.TRUE.equals((Boolean)job.getValue("includeOthers"))) includes.add(Include.OTHERS); 484 494 itemQuery = idMethod.prepareQuery(dc, createItemQuery()); 495 itemQuery.setItemPermission(Permission.WRITE); 485 496 itemQuery.include(includes); 486 497 } … … 498 509 lastIdentifier = identifier; 499 510 511 if (sameAsLast && skippedLast) 512 { 513 // If the first line in a multi-line entry was skipped, skip the remaining lines also 514 log("Skipped: " + idMethod + "=" + identifier, data); 515 return; 516 } 517 500 518 I item = null; 501 519 if (identifier != null) … … 545 563 itemCache.put(cacheKey, item); 546 564 log("Created: " + idMethod + "=" + identifier, data); 565 skippedLast = false; 547 566 numCreated++; 548 567 } … … 553 572 errorHandler.handleError(t); 554 573 log("Skipped: " + idMethod + "=" + identifier, data, t); 574 skippedLast = true; 555 575 numError++; 556 576 // The error should be ignored if we get passed the above line … … 567 587 { 568 588 log("Not found: " + idMethod + "=" + identifier, data); 589 skippedLast = true; 569 590 numNotFound++; 570 591 } … … 586 607 } 587 608 log("Updated: " + idMethod + "=" + identifier, data); 609 skippedLast = false; 588 610 } 589 611 catch (Throwable t) … … 593 615 errorHandler.handleError(t); 594 616 log("Skipped: " + idMethod + "=" + identifier, data); 617 skippedLast = true; 595 618 numError++; 596 619 // The error should be ignored if we get passed the above line … … 798 821 @param dc The DbControl to use for database access 799 822 @param identifier The identifier protocol 800 @return A protocol, or null if no protocolcould be found823 @return A protocol, or null if no item could be found 801 824 */ 802 825 protected Protocol findProtocol(DbControl dc, IdMethod idMetod, String identifier) … … 807 830 } 808 831 832 private ItemQuery<Label> labelQuery; 833 /** 834 Find a label with a given identifier. This is a utility method that 835 subclasses can use when creating or updating items. 836 <p> 837 NOTE! The first time this method is called a query object is initialised 838 using the {@link IdMethod#prepareQuery(DbControl, ItemQuery)} method. 839 Subsequent calls uses the same query. Thus, this method should always be 840 called with the same id method object, otherwise the result is undefined. 841 842 @param dc The DbControl to use for database access 843 @param identifier The identifier protocol 844 @return A label, or null if no item could be found 845 */ 846 protected Label findLabel(DbControl dc, IdMethod idMetod, String identifier) 847 { 848 if (identifier == null) return null; 849 if (labelQuery == null) labelQuery = initReferenceQuery(dc, idMethod, Label.getQuery()); 850 return findReferencedItem(dc, idMethod, labelQuery, identifier); 851 } 852 853 private ItemQuery<Hardware> scannerQuery; 854 /** 855 Find a scanner with a given identifier. This is a utility method that 856 subclasses can use when creating or updating items. 857 858 <p> 859 NOTE! A scanner is a {@link Hardware} item with it type set to 860 {@link HardwareType#SCANNER}. 861 862 <p> 863 NOTE! The first time this method is called a query object is initialised 864 using the {@link IdMethod#prepareQuery(DbControl, ItemQuery)} method. 865 Subsequent calls uses the same query. Thus, this method should always be 866 called with the same id method object, otherwise the result is undefined. 867 868 @param dc The DbControl to use for database access 869 @param identifier The identifier protocol 870 @return A scanner, or null if no item could be found 871 */ 872 protected Hardware findScanner(DbControl dc, IdMethod idMetod, String identifier) 873 { 874 if (identifier == null) return null; 875 if (scannerQuery == null) 876 { 877 scannerQuery = initReferenceQuery(dc, idMethod, Hardware.getQuery()); 878 scannerQuery.restrictPermanent( 879 Restrictions.eq(Hql.property("hardwareType"), 880 Expressions.integer(SystemItems.getId(HardwareType.SCANNER))) 881 ); 882 } 883 return findReferencedItem(dc, idMethod, scannerQuery, identifier); 884 } 885 809 886 private ItemQuery<BioSource> bioSourceQuery; 810 887 /** … … 849 926 } 850 927 928 private ItemQuery<Extract> extractQuery; 929 /** 930 Find an extract with a given identifier. This is a utility method that 931 subclasses can use when creating or updating items. 932 <p> 933 NOTE! The first time this method is called a query object is initialised 934 using the {@link IdMethod#prepareQuery(DbControl, ItemQuery)} method. 935 Subsequent calls uses the same query. Thus, this method should always be 936 called with the same id method object, otherwise the result is undefined. 937 938 @param dc The DbControl to use for database access 939 @param identifier The identifier protocol 940 @return An extract, or null if no item could be found 941 */ 942 protected Extract findExtract(DbControl dc, IdMethod idMetod, String identifier) 943 { 944 if (identifier == null) return null; 945 if (extractQuery == null) extractQuery = initReferenceQuery(dc, idMethod, Extract.getQuery()); 946 return findReferencedItem(dc, idMethod, extractQuery, identifier); 947 } 948 949 private ItemQuery<LabeledExtract> labeledExtractQuery; 950 /** 951 Find a labled extract with a given identifier. This is a utility method that 952 subclasses can use when creating or updating items. 953 <p> 954 NOTE! The first time this method is called a query object is initialised 955 using the {@link IdMethod#prepareQuery(DbControl, ItemQuery)} method. 956 Subsequent calls uses the same query. Thus, this method should always be 957 called with the same id method object, otherwise the result is undefined. 958 959 @param dc The DbControl to use for database access 960 @param identifier The identifier protocol 961 @return A labeled extract, or null if no item could be found 962 */ 963 protected LabeledExtract findLabeledExtract(DbControl dc, IdMethod idMetod, String identifier) 964 { 965 if (identifier == null) return null; 966 if (labeledExtractQuery == null) 967 { 968 labeledExtractQuery = initReferenceQuery(dc, idMethod, LabeledExtract.getQuery()); 969 } 970 return findReferencedItem(dc, idMethod, labeledExtractQuery, identifier); 971 } 972 851 973 /** 852 974 Cache that holds loaded/created items. The cache key is item type + identifier, … … 860 982 Initialise a query that is used to find referenced items. This method 861 983 delegates to {@link IdMethod#prepareQuery(DbControl, ItemQuery)} and 862 the adds {@link Include} options: MINE, IN_PROJECT, SHARED and OTHERS. 984 then adds {@link Include} options: MINE, IN_PROJECT, SHARED and OTHERS. 985 The query will only search for items that the logged in user has 986 USE permission for. 863 987 864 988 @param dc A DbControl used for database access … … 871 995 query = idMethod.prepareQuery(dc, query); 872 996 query.include(Include.MINE, Include.IN_PROJECT, Include.SHARED, Include.OTHERS); 997 query.setItemPermission(Permission.USE); 873 998 return query; 874 999 } -
trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/BioSourceImporter.java
r4366 r4372 108 108 <li>{@link PropertyIdMethod#NAME} 109 109 <li>{@link PropertyIdMethod#EXTERNAL_ID} 110 <li>{@link PropertyIdMethod#INTERNAL_ID}110 <li>{@link InternalIdMethod#INTERNAL_ID} 111 111 <li>{@link FallbackIdMethod#NAME_OR_ID} 112 112 </ul> … … 116 116 { 117 117 return new IdMethod[] { PropertyIdMethod.NAME, PropertyIdMethod.EXTERNAL_ID, 118 PropertyIdMethod.INTERNAL_ID, FallbackIdMethod.NAME_OR_ID};118 InternalIdMethod.INTERNAL_ID, FallbackIdMethod.NAME_OR_ID}; 119 119 } 120 120 -
trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/IdMethod.java
r4366 r4372 65 65 other modifications. 66 66 @param query The query to prepare 67 @return The query that is used for item lookup 67 68 */ 68 69 public <I extends BasicItem> ItemQuery<I> prepareQuery(DbControl dc, ItemQuery<I> query); -
trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/PropertyIdMethod.java
r4366 r4372 47 47 48 48 /** 49 Use the internal ID for finding items.50 */51 public static final PropertyIdMethod INTERNAL_ID =52 new PropertyIdMethod("internalId", "Internal ID", "id", true, Type.INT);53 54 /**55 49 Use the name for finding items. 56 50 */ … … 71 65 72 66 public static final IdMethod[] DEFAULT_METHODS = 73 new IdMethod[] { NAME, I NTERNAL_ID, FallbackIdMethod.NAME_OR_ID };67 new IdMethod[] { NAME, InternalIdMethod.INTERNAL_ID, FallbackIdMethod.NAME_OR_ID }; 74 68 75 69 private final String method; -
trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/SampleImporter.java
r4366 r4372 180 180 <li>{@link PropertyIdMethod#NAME} 181 181 <li>{@link PropertyIdMethod#EXTERNAL_ID} 182 <li>{@link PropertyIdMethod#INTERNAL_ID}182 <li>{@link InternalIdMethod#INTERNAL_ID} 183 183 <li>{@link FallbackIdMethod#NAME_OR_ID} 184 184 </ul> … … 188 188 { 189 189 return new IdMethod[] { PropertyIdMethod.NAME, PropertyIdMethod.EXTERNAL_ID, 190 PropertyIdMethod.INTERNAL_ID, FallbackIdMethod.NAME_OR_ID};190 InternalIdMethod.INTERNAL_ID, FallbackIdMethod.NAME_OR_ID}; 191 191 } 192 192 -
trunk/src/test/TestAll.java
r4239 r4372 138 138 results.put("TestJob", TestJob.test_all()); 139 139 results.put("TestJobAgent", TestJobAgent.test_all()); 140 results.put("TestItemImporter", TestItemImporter.test_all()); 140 141 results.put("TestReporterFlatFileImporter", TestReporterFlatFileImporter.test_all()); 141 142 results.put("TestReporterMapFlatFileImporter", TestReporterMapFlatFileImporter.test_all()); -
trunk/src/test/TestExtract.java
r3679 r4372 25 25 */ 26 26 import net.sf.basedb.core.*; 27 27 28 import java.util.Date; 28 29 … … 234 235 } 235 236 237 static void test_delete_all() 238 { 239 DbControl dc = null; 240 try 241 { 242 dc = TestUtil.getDbControl(); 243 ItemResultList<Extract> l = Extract.getQuery().list(dc); 244 Trashcan.delete(dc.getSessionControl(), l, true, null); 245 dc.commit(); 246 write("--Delete all extracts OK ("+l.size()+")"); 247 } 248 catch (Throwable ex) 249 { 250 write("--Delete all extracts FAILED"); 251 ex.printStackTrace(); 252 ok = false; 253 } 254 finally 255 { 256 if (dc != null) dc.close(); 257 } 258 } 259 260 236 261 static void write_header() 237 262 { -
trunk/src/test/TestItemImporter.java
r4366 r4372 58 58 // Create referenced items 59 59 int samplingProtocolId = TestProtocol.test_create(SystemItems.getId(ProtocolType.SAMPLING), "Sampling", false); 60 int extractionProtocolId = TestProtocol.test_create(SystemItems.getId(ProtocolType.EXTRACTION), "Extraction", false); 61 int labelingProtocolId = TestProtocol.test_create(SystemItems.getId(ProtocolType.LABELING), "Labeling", false); 60 62 int poolingProtocolId = TestProtocol.test_create(SystemItems.getId(ProtocolType.POOLING), "Pooling", false); 61 63 … … 73 75 ok &= TestJob.test_execute(sampleJobId); 74 76 TestSample.test_list(4); 77 78 // Import extracts 79 int extractFileId = TestFile.test_create("data/test.batchimport.extracts.txt", false, false); 80 int extractImporterId = TestPluginDefinition.test_get("net.sf.basedb.plugins.batchimport.ExtractImporter"); 81 int extractJobId = test_create_item_import_job(Item.EXTRACT, extractImporterId, extractFileId); 82 ok &= TestJob.test_execute(extractJobId); 83 TestExtract.test_list(4); 84 85 // Import labeled extracts 86 int labledExtractFileId = TestFile.test_create("data/test.batchimport.labeledextracts.txt", false, false); 87 int labledExtractImporterId = TestPluginDefinition.test_get("net.sf.basedb.plugins.batchimport.LabeledExtractImporter"); 88 int labledExtractJobId = test_create_item_import_job(Item.LABELEDEXTRACT, labledExtractImporterId, labledExtractFileId); 89 ok &= TestJob.test_execute(labledExtractJobId); 90 TestLabeledExtract.test_list(7); 75 91 76 92 if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); 77 93 94 // Delete labeled extracts 95 TestLabeledExtract.test_delete_all(); 96 TestJob.test_delete(labledExtractJobId); 97 TestFile.test_delete(labledExtractFileId); 98 99 // Delete extracts 100 TestExtract.test_delete_all(); 101 TestJob.test_delete(extractJobId); 102 TestFile.test_delete(extractFileId); 103 78 104 // Delete samples 79 105 TestSample.test_delete_all(); … … 88 114 // References items 89 115 TestProtocol.test_delete(samplingProtocolId); 116 TestProtocol.test_delete(extractionProtocolId); 117 TestProtocol.test_delete(labelingProtocolId); 90 118 TestProtocol.test_delete(poolingProtocolId); 91 119 … … 180 208 request.setParameterValue("idMethod", "name"); 181 209 request.setParameterValue("idColumnMapping", "\\Name\\"); 182 183 210 } 184 211 … … 189 216 request.setParameterValue("externalIdColumnMapping", "\\External ID\\"); 190 217 191 if (itemType == Item.SAMPLE )218 if (itemType == Item.SAMPLE || itemType == Item.EXTRACT || itemType == Item.LABELEDEXTRACT) 192 219 { 193 220 request.setParameterValue("protocolColumnMapping", "\\Protocol\\"); … … 198 225 request.setParameterValue("usedQuantityColumnMapping", "\\Used quantity\\"); 199 226 } 227 if (itemType == Item.LABELEDEXTRACT) 228 { 229 request.setParameterValue("labelColumnMapping", "\\Label\\"); 230 } 200 231 } 201 232 -
trunk/src/test/TestLabeledExtract.java
r3679 r4372 24 24 */ 25 25 import net.sf.basedb.core.*; 26 26 27 import java.util.Date; 27 28 … … 237 238 } 238 239 } 240 241 static void test_delete_all() 242 { 243 DbControl dc = null; 244 try 245 { 246 dc = TestUtil.getDbControl(); 247 ItemResultList<LabeledExtract> l = LabeledExtract.getQuery().list(dc); 248 Trashcan.delete(dc.getSessionControl(), l, true, null); 249 dc.commit(); 250 write("--Delete all labeled extracts OK ("+l.size()+")"); 251 } 252 catch (Throwable ex) 253 { 254 write("--Delete all labeled extracts FAILED"); 255 ex.printStackTrace(); 256 ok = false; 257 } 258 finally 259 { 260 if (dc != null) dc.close(); 261 } 262 } 239 263 240 264 static void write_header()
Note: See TracChangeset
for help on using the changeset viewer.