[155] | 1 | package org.biohackathon.SPARQLBuilder.endpointMetadata;
|
---|
| 2 |
|
---|
[158] | 3 | import java.io.File;
|
---|
[160] | 4 | import java.util.HashMap;
|
---|
| 5 | import java.util.Set;
|
---|
[155] | 6 |
|
---|
[158] | 7 | public class MetadataManager {
|
---|
| 8 |
|
---|
[160] | 9 | HashMap<String,MetadataFile> metadataTable = null;
|
---|
| 10 |
|
---|
| 11 |
|
---|
| 12 | public static void main(String[] args) throws Exception{
|
---|
| 13 | String dirStr = "c:\\temp\\crawl";
|
---|
| 14 | MetadataManager manager = new MetadataManager(dirStr);
|
---|
| 15 | String[] uris = manager.getURIList();
|
---|
| 16 | for(String uri: uris){
|
---|
| 17 | System.out.println(uri);
|
---|
| 18 | MetadataFile mFile = manager.getMetadataFile(uri);
|
---|
| 19 | System.out.println(mFile.getStartDateTime().getTime().toString());
|
---|
| 20 | System.out.println(mFile.getEndDateTime().getTime().toString());
|
---|
| 21 | }
|
---|
| 22 | }
|
---|
[158] | 23 |
|
---|
[179] | 24 | public MetadataFile[] getMetadataFiles(){
|
---|
| 25 | return metadataTable.values().toArray(new MetadataFile[0]);
|
---|
| 26 | }
|
---|
[160] | 27 | public MetadataFile getMetadataFile(String uri){
|
---|
| 28 | return metadataTable.get(uri);
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | public String[] getURIList(){
|
---|
| 32 | Set<String> keySet = metadataTable.keySet();
|
---|
| 33 | return keySet.toArray(new String[0]);
|
---|
| 34 | }
|
---|
[158] | 35 |
|
---|
[160] | 36 |
|
---|
[158] | 37 | public MetadataManager(String metadataDirStr) throws Exception {
|
---|
| 38 | init(metadataDirStr);
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 |
|
---|
| 42 | public void init(String metadataDirStr) throws Exception{
|
---|
[160] | 43 | metadataTable = new HashMap<String,MetadataFile>();
|
---|
[158] | 44 | File metadataDir = new File(metadataDirStr);
|
---|
| 45 | File[] files = null;
|
---|
| 46 | if( metadataDir.exists() ){
|
---|
| 47 | if( metadataDir.isFile()){
|
---|
| 48 | files = new File[]{metadataDir};
|
---|
| 49 | }else{
|
---|
| 50 | if( metadataDir.isDirectory()){
|
---|
| 51 | files = metadataDir.listFiles();
|
---|
| 52 | }else{
|
---|
| 53 | throw new Exception("Inernal File/Directory error: " + metadataDirStr);
|
---|
| 54 | }
|
---|
| 55 | }
|
---|
| 56 | }else{
|
---|
| 57 | throw new Exception("File/Directory not found: " + metadataDirStr);
|
---|
| 58 | }
|
---|
| 59 | for(File file: files){
|
---|
| 60 | MetadataFile metadataFile = null;
|
---|
| 61 | try{
|
---|
| 62 | metadataFile = new MetadataFile(file);
|
---|
[160] | 63 | String uri = metadataFile.getEndpointURI();
|
---|
| 64 | if( uri != null ){
|
---|
| 65 | metadataTable.put(uri, metadataFile);
|
---|
| 66 | }
|
---|
[158] | 67 | }catch(Exception ex){
|
---|
| 68 | // WARNING
|
---|
| 69 | System.out.println("Invalid metadata file: " + file.getAbsolutePath());
|
---|
[160] | 70 | ex.printStackTrace();
|
---|
[158] | 71 | }
|
---|
| 72 | }
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 |
|
---|
| 76 |
|
---|
[155] | 77 | }
|
---|