Changeset 5719
- Timestamp:
- Sep 6, 2011, 1:56:29 PM (12 years ago)
- Location:
- trunk/src
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/core/FileSet.java
r5718 r5719 307 307 is called. Calling this method is equivalent to first call 308 308 {@link #removeAllOfType(DataFileType)} and then {@link 309 #addMember(File, DataFileType)}. 309 #addMember(File, DataFileType)} except that if the given file 310 already is a member that member entry is kept. 310 311 311 312 @param file The file to set as a member (or null to remove it) … … 329 330 if (file != null) file.checkPermission(Permission.USE); 330 331 331 removeAllOfType(type); 332 return file == null ? null : addMember(file, type); 332 FileSetMember member = removeAllOfTypeExcept(type, file); 333 if (member == null && file != null) 334 { 335 member = addMember(file, type); 336 } 337 return member; 333 338 } 334 339 … … 408 413 of the specified type exists 409 414 */ 410 @Deprecated411 415 public FileSetMember getMember(DataFileType type) 412 416 { … … 537 541 return removed.size(); 538 542 } 543 544 /** 545 Remove all member files of the given type. 546 547 @param type A <code>DataFileType</code> object 548 @throws InvalidUseOfNullException If type is null 549 @throws PermissionDeniedException If the logged in user 550 doesn't have write permission for this file set 551 @return The number of removed files 552 @since 3.0 553 */ 554 private FileSetMember removeAllOfTypeExcept(DataFileType type, File file) 555 { 556 DbControl dc = getDbControl(); 557 int typeId = type.getId(); 558 int fileId = file.getId(); 559 FileSetMember remain = null; 560 Iterator<FileSetMemberData> it = getData().getMembers().iterator(); 561 // Keep track of removed members so that we can invoke metadata extensions 562 List<ValidatingFileSetMember> removed = new ArrayList<ValidatingFileSetMember>(); 563 while (it.hasNext()) 564 { 565 FileSetMemberData member = it.next(); 566 if (member.getDataFileType().getId() == typeId) 567 { 568 // Type is matching -- what about the file? 569 if (member.getFile().getId() == fileId) 570 { 571 // Keep 572 remain = dc.getItem(FileSetMember.class, member); 573 } 574 else 575 { 576 // Remove 577 it.remove(); 578 if (member.getId() > 0) 579 { 580 FileSetMember m = dc.getItem(FileSetMember.class, member); 581 dc.deleteItem(m); 582 removed.add(new ValidatingFileSetMember(m)); 583 } 584 } 585 } 586 } 587 if (removed.size() > 0) 588 { 589 // Create context and invoke the extensions system 590 ExtensionsInvoker<ValidationAction> invoker = getInvoker(dc); 591 592 // Reset the metadata 593 invoker.render(new ResetMetadataRenderer(removed)); 594 } 595 return remain; 596 } 597 539 598 540 599 /** -
trunk/src/core/net/sf/basedb/core/FileStoreUtil.java
r5713 r5719 219 219 FileSet fileSet = item.getFileSet(); 220 220 DataFileType type = DataFileType.getByExternalId(dc, dataFileType); 221 FileSetMember member = null; 222 if (file == null) 223 { 224 // TODO #1604 225 // fileSet.removeMember(type); 226 } 227 else 228 { 229 member = fileSet.setMember(file, type); 230 } 221 FileSetMember member = fileSet.setMember(file, type); 231 222 return member; 232 223 } … … 276 267 // Now, add/remove the file to the fileset 277 268 FileSet fileSet = item.getFileSet(); 278 FileSetMember member = null; 279 if (file == null) 280 { 281 // TODO #1604 282 // fileSet.removeMember(type); 283 } 284 else 285 { 286 member = fileSet.setMember(file, type); 287 } 269 FileSetMember member = fileSet.setMember(file, type); 288 270 return member; 289 271 } -
trunk/src/core/net/sf/basedb/core/data/FileSetMemberData.java
r5713 r5719 43 43 Get the file set this file belongs to. 44 44 @hibernate.many-to-one outer-join="false" update="false" 45 @hibernate.column name="`fileset_id`" not-null="true" 45 @hibernate.column name="`fileset_id`" not-null="true" unique-key="uniquefile" 46 46 */ 47 47 public FileSetData getFileSet() … … 58 58 Get the type of this file. A set may only contain one file for each type. 59 59 @hibernate.many-to-one outer-join="false" update="false" 60 @hibernate.column name="`datafiletype_id`" not-null="true" 60 @hibernate.column name="`datafiletype_id`" not-null="true" unique-key="uniquefile" 61 61 */ 62 62 public DataFileTypeData getDataFileType() … … 73 73 Get the file. 74 74 @hibernate.many-to-one outer-join="false" 75 @hibernate.column name="`file_id`" not-null="true" 75 @hibernate.column name="`file_id`" not-null="true" unique-key="uniquefile" 76 76 */ 77 77 public FileData getFile() -
trunk/src/plugins/core/net/sf/basedb/plugins/ManualTransformCreator.java
r5623 r5719 192 192 for (DataFileType ft : fileTypes) 193 193 { 194 File file = (File)job.getValue("file." + ft.getExternalId());195 if (file != null)194 List<File> files = (List<File>)job.getValues("file." + ft.getExternalId()); 195 if (files != null && files.size() > 0) 196 196 { 197 fs.setMember(file, ft); 197 for (File f : files) 198 { 199 fs.addMember(f, ft); 200 } 198 201 } 199 202 } … … 274 277 for (DataFileType ft : fileTypes) 275 278 { 276 storeValue (job, request, ri.getParameter("file." + ft.getExternalId()));279 storeValues(job, request, ri.getParameter("file." + ft.getExternalId())); 277 280 } 278 281 } … … 460 463 ft.getName(), 461 464 ft.getDescription(), 462 new FileParameterType( )465 new FileParameterType(null, false, 0) 463 466 )); 464 467 } … … 524 527 "fileTypes", 525 528 "File types", 526 "Select all registered file types that the external tool generates as " +529 "Select all registered file types that the external tool generates as " + 527 530 "output.", 528 531 new ItemParameterType<DataFileType>(DataFileType.class, null, false, 0, fileTypes) -
trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/AbstractItemImporter.java
r5696 r5719 28 28 import java.util.EnumSet; 29 29 import java.util.HashMap; 30 import java.util.HashSet; 30 31 import java.util.List; 31 32 import java.util.Map; … … 48 49 import net.sf.basedb.core.Extract; 49 50 import net.sf.basedb.core.File; 51 import net.sf.basedb.core.FileSet; 52 import net.sf.basedb.core.FileSetMember; 53 import net.sf.basedb.core.FileStoreEnabled; 50 54 import net.sf.basedb.core.Hardware; 51 55 import net.sf.basedb.core.ItemParameterType; … … 1915 1919 } 1916 1920 1921 private Set<String> fileCache; 1922 /** 1923 Set or add a file to a file set. The first time this method is called for 1924 a given item and file type combination {@link FileSet#setMember(File, DataFileType)} 1925 is used to add the file to the file set (which will replace all other files of 1926 the same file type. If this method is called more times then 1927 {@link FileSet#addMember(File, DataFileType)} is used so that already added 1928 files are preserved. 1929 1930 If the file is null the first time, all files of the given file types are removed. 1931 If the file is null after the first time, this call is ignored. 1932 1933 @param item The item to set/add a file to 1934 @param fileType The type of the file 1935 @param file The file, or null 1936 @return The new member entry, or null if the call didn't result in 1937 an addition 1938 @since 3.0 1939 */ 1940 protected FileSetMember setOrAddFile(FileStoreEnabled item, DataFileType fileType, File file) 1941 { 1942 if (fileCache == null) fileCache = new HashSet<String>(); 1943 String cacheId = item.getType().name() + "#" + item.getId() + "#" + fileType.getId(); 1944 FileSetMember added = null; 1945 if (!fileCache.contains(cacheId)) 1946 { 1947 // Has been called at least one time before 1948 if (file != null) 1949 { 1950 added = item.getFileSet().addMember(file, fileType); 1951 } 1952 } 1953 else 1954 { 1955 added = item.getFileSet().setMember(file, fileType); 1956 fileCache.add(cacheId); 1957 } 1958 return added; 1959 } 1960 1917 1961 /** 1918 1962 Cache that holds loaded/created items. The cache key is item type + identifier, -
trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/ArrayDesignImporter.java
r5713 r5719 313 313 file = File.getByPath(dc, new Path(filePath, Path.Type.FILE), false); 314 314 } 315 if (file != null) 316 { 317 design.getFileSet().setMember(file, fileType); 318 } 319 else 320 { 321 // TODO #1604 322 //design.getFileSet().removeMember(fileType); 323 } 315 setOrAddFile(design, fileType, file); 324 316 } 325 317 } -
trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/DerivedBioAssayImporter.java
r5713 r5719 391 391 file = File.getByPath(dc, new Path(filePath, Path.Type.FILE), false); 392 392 } 393 if (file != null) 394 { 395 bioAssay.getFileSet().setMember(file, fileType); 396 } 397 else 398 { 399 // TODO #1604 400 //bioAssay.getFileSet().removeMember(fileType); 401 } 393 setOrAddFile(bioAssay, fileType, file); 402 394 } 403 395 } -
trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/RawBioAssayImporter.java
r5713 r5719 461 461 file = File.getByPath(dc, new Path(filePath, Path.Type.FILE), false); 462 462 } 463 if (file != null) 464 { 465 rba.getFileSet().setMember(file, fileType); 466 } 467 else 468 { 469 // TODO #1604 470 //rba.getFileSet().removeMember(fileType); 471 } 463 setOrAddFile(rba, fileType, file); 472 464 } 473 465 } -
trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/ScanImporter.java
r5713 r5719 255 255 File imageFile = File.getByPath(dc, new Path(filePath, Path.Type.FILE), false); 256 256 DataFileType imageType = DataFileType.getByExternalId(dc, DataFileType.MICROARRAY_IMAGE); 257 if (imageFile != null) 258 { 259 scan.getFileSet().setMember(imageFile, imageType); 260 } 261 else 262 { 263 // TODO #1604 264 //scan.getFileSet().removeMember(imageType); 265 } 257 setOrAddFile(scan, imageType, imageFile); 266 258 } 267 259 } -
trunk/src/test/data/test.batchimport.rawbioassays.txt
r5177 r5719 2 2 Raw data 1 The first data set 1 Generic genepix Scan 1 Feature Feature Generic.1 Generic raw data test.gpr 3 3 Raw data 2 The second 1 Generic Variant GenePix Scan 2 Feature Feature Generic.2 Generic raw data test.gpr 4 Raw data 2 Generic raw data test.cel 4 5 Raw data 3.1 From same hyb 1 Affymetrix Scan 3 Feature Feature Affy CEL file test.cel 5 6 Raw data 3.2 From same hyb 2 Affymetrix Scan 3 Feature Feature Affy CEL file test.cel
Note: See TracChangeset
for help on using the changeset viewer.