1   package com.trendmicro.grid.acl.ds.dummy;
2   
3   import com.trendmicro.grid.acl.ds.FileProvider;
4   import com.trendmicro.grid.acl.ds.TagQueryExpression;
5   import com.trendmicro.grid.acl.ds.datatypes.SharedFileDetails;
6   import com.trendmicro.grid.acl.ds.datatypes.SharedFileInformation;
7   import com.trendmicro.grid.acl.l0.datatypes.FileIdentiferListPage;
8   import com.trendmicro.grid.acl.l0.datatypes.FileIdentifier;
9   import com.trendmicro.grid.acl.l0.datatypes.Range;
10  import com.trendmicro.grid.acl.metadata.Meta;
11  import com.trendmicro.grid.acl.metadata.Metadata;
12  import org.springframework.stereotype.Repository;
13  
14  import java.util.*;
15  
16  /**
17   * Implements a dummy in-memory provider for files.
18   *
19   * @author juergen_kellerer, 2010-05-07
20   * @version 1.0
21   */
22  @Repository
23  public class DummyFileProvider implements FileProvider {
24  
25  	Metadata dummyMetadata = new Metadata(Arrays.asList(
26  			new Meta("dummyKey1").value("DummyValue1"),
27  			new Meta("dummyKey2").value(new Date()),
28  			new Meta("dummyKey3").value(354324.34D),
29  			new Meta("dummyKey4").value("value1", "value2")));
30  
31  	FileIdentifier id = new FileIdentifier(new byte[20]);
32  	SharedFileInformation dummyFileInformation = new SharedFileInformation(
33  			new Date(), new Date(), new Date(), new String[]{"tag1", "tag2"}, 3, 631);
34  	SharedFileDetails dummyFileDetails = new SharedFileDetails(id, dummyFileInformation, dummyMetadata);
35  
36  	@Override
37  	public Collection<Boolean> isFilesKnown(Collection<FileIdentifier> files) {
38  		return isFilesTaggedWith(files, null);
39  	}
40  
41  	@Override
42  	public Collection<Boolean> isFilesTaggedWith(Collection<FileIdentifier> files, String[] tags) {
43  		Collection<Boolean> result = new ArrayList<Boolean>();
44  		for (FileIdentifier file : files)
45  			result.add(id.equals(file));
46  		return result;
47  	}
48  
49  	public FileIdentiferListPage getFilesTaggedWith(String[] tags, int pageNumber) {
50  		return pageNumber > 0 ? null : new FileIdentiferListPage(0, true);
51  	}
52  
53  	@Override
54  	public Collection<FileIdentifier> getCanonicalIdentifiers(Collection<FileIdentifier> files) {
55  		return files;
56  	}
57  
58  	@Override
59  	public FileIdentiferListPage getMatchingFiles(TagQueryExpression expression, Range range, int pageNumber) {
60  		return getFilesTaggedWith(null, pageNumber);
61  	}
62  
63  	@Override
64  	public Collection<SharedFileInformation> getFileInformationList(Collection<FileIdentifier> files) {
65  		Collection<SharedFileInformation> results = new ArrayList<SharedFileInformation>();
66  		results.addAll(Collections.nCopies(files.size(), dummyFileInformation));
67  
68  		return results;
69  	}
70  
71  	@Override
72  	public Collection<SharedFileDetails> getFileDetailsList(Collection<FileIdentifier> files) {
73  		Collection<SharedFileDetails> results = new ArrayList<SharedFileDetails>();
74  		results.addAll(Collections.nCopies(files.size(), dummyFileDetails));
75  
76  		return results;
77  	}
78  }