Revision 8859
Added by Jing Tao about 10 years ago
metacat-common/src/test/java/edu/ucsb/nceas/metacat/common/resourcemap/ResourceMapNamespacesTest.java | ||
---|---|---|
1 |
/** |
|
2 |
* '$RCSfile$' |
|
3 |
* Purpose: A class represents the possible namespaces of the resource map documents. |
|
4 |
* Copyright: 2013 Regents of the University of California and the |
|
5 |
* National Center for Ecological Analysis and Synthesis |
|
6 |
* Authors: Jing Tao |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or modify |
|
9 |
* it under the terms of the GNU General Public License as published by |
|
10 |
* the Free Software Foundation; either version 2 of the License, or |
|
11 |
* (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
21 |
*/ |
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
package edu.ucsb.nceas.metacat.common.resourcemap; |
|
26 |
|
|
27 |
import static org.junit.Assert.assertTrue; |
|
28 |
|
|
29 |
import java.io.FileNotFoundException; |
|
30 |
import java.io.IOException; |
|
31 |
import java.util.List; |
|
32 |
|
|
33 |
import org.apache.commons.configuration.ConfigurationException; |
|
34 |
import org.apache.solr.client.solrj.SolrServer; |
|
35 |
import org.junit.Before; |
|
36 |
import org.junit.Test; |
|
37 |
|
|
38 |
import edu.ucsb.nceas.metacat.common.MetacatCommonTestBase; |
|
39 |
|
|
40 |
public class ResourceMapNamespacesTest extends MetacatCommonTestBase { |
|
41 |
|
|
42 |
private static final String NAMESPACE1="http://www.w3.org/TR/rdf-syntax-grammar"; |
|
43 |
private static final String NAMESPACE2="http://www.openarchives.org/ore/terms"; |
|
44 |
private static final String NAMESPACE3="eml://eml.ecoinformatics.org"; |
|
45 |
/** |
|
46 |
* The setup method |
|
47 |
*/ |
|
48 |
@Before |
|
49 |
public void setup () throws FileNotFoundException, ConfigurationException, IOException { |
|
50 |
super.setup(); |
|
51 |
} |
|
52 |
|
|
53 |
@Test |
|
54 |
public void testIsResourceMap() throws Exception { |
|
55 |
assertTrue(NAMESPACE1+"should be a namespace of the resource map document ", ResourceMapNamespaces.isResourceMap(NAMESPACE1)); |
|
56 |
assertTrue(NAMESPACE2+"should be a namespace of the resource map document ", ResourceMapNamespaces.isResourceMap(NAMESPACE2)); |
|
57 |
assertTrue(NAMESPACE3+"should NOT be a namespace of the resource map document ", ResourceMapNamespaces.isResourceMap(NAMESPACE3)==false); |
|
58 |
} |
|
59 |
} |
metacat-common/src/test/resources/org/dataone/configuration/test.properties | ||
---|---|---|
5 | 5 |
dataone.hazelcast.storageCluster.identifiersSet=hzIdentifiers |
6 | 6 |
index.hazelcast.indexqueue=hzIndexQueue |
7 | 7 |
index.hazelcast.indexeventmap=hzIndexEventMap |
8 |
index.resourcemap.namespace=http://www.w3.org/TR/rdf-syntax-grammar;http://www.openarchives.org/ore/terms |
|
8 | 9 |
|
9 | 10 |
#Embedded (default): |
10 | 11 |
solr.server.classname=org.apache.solr.client.solrj.embedded.EmbeddedSolrServer |
metacat-common/src/main/java/edu/ucsb/nceas/metacat/common/resourcemap/ResourceMapNamespaces.java | ||
---|---|---|
1 |
/** |
|
2 |
* '$RCSfile$' |
|
3 |
* Purpose: A class represents the possible namespaces of the resource map documents. |
|
4 |
* Copyright: 2013 Regents of the University of California and the |
|
5 |
* National Center for Ecological Analysis and Synthesis |
|
6 |
* Authors: Jing Tao |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or modify |
|
9 |
* it under the terms of the GNU General Public License as published by |
|
10 |
* the Free Software Foundation; either version 2 of the License, or |
|
11 |
* (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
21 |
*/ |
|
22 |
|
|
23 |
/** |
|
24 |
* This classe represents the list of possible namespaces of the resource map documents. |
|
25 |
* The list reads the properties in the metacat.propertities file. |
|
26 |
* @author tao |
|
27 |
* |
|
28 |
*/ |
|
29 |
package edu.ucsb.nceas.metacat.common.resourcemap; |
|
30 |
|
|
31 |
import org.dataone.configuration.Settings; |
|
32 |
import org.dataone.service.types.v1.ObjectFormatIdentifier; |
|
33 |
|
|
34 |
import java.util.List; |
|
35 |
|
|
36 |
|
|
37 |
public class ResourceMapNamespaces { |
|
38 |
|
|
39 |
private static final String RESOURCEMAPPROPERYNAME = "index.resourcemap.namespace"; |
|
40 |
private static List<String> resourceMapNamespaces = null; |
|
41 |
|
|
42 |
/** |
|
43 |
* Constructor |
|
44 |
* @param solrIndex |
|
45 |
* @param systemMetadataListener |
|
46 |
*/ |
|
47 |
public ResourceMapNamespaces() { |
|
48 |
init(); |
|
49 |
} |
|
50 |
|
|
51 |
/* |
|
52 |
* Read the namespace list fromt the property file |
|
53 |
*/ |
|
54 |
private static void init() { |
|
55 |
resourceMapNamespaces = Settings.getConfiguration().getList(RESOURCEMAPPROPERYNAME); |
|
56 |
//System.out.println("Init list "+resourceMapNamespaces); |
|
57 |
} |
|
58 |
|
|
59 |
/** |
|
60 |
* Get the list of namespaces of the resourcemap. |
|
61 |
* @return the list of namespaces. It returns null if we can't find them. |
|
62 |
*/ |
|
63 |
public static List<String> getNamespaces() { |
|
64 |
if(resourceMapNamespaces == null) { |
|
65 |
init(); |
|
66 |
} |
|
67 |
return resourceMapNamespaces; |
|
68 |
} |
|
69 |
|
|
70 |
/** |
|
71 |
* If the specified namespace is a resource map namespace. |
|
72 |
* @param namespace the specified namespace |
|
73 |
* @return true if it is a namespace of the resource map. |
|
74 |
*/ |
|
75 |
public static boolean isResourceMap(String namespace) { |
|
76 |
boolean is = false; |
|
77 |
if(namespace != null && !namespace.trim().equals("")) { |
|
78 |
getNamespaces(); |
|
79 |
if(resourceMapNamespaces != null && resourceMapNamespaces.contains(namespace)) { |
|
80 |
is = true; |
|
81 |
} |
|
82 |
} |
|
83 |
return is; |
|
84 |
|
|
85 |
} |
|
86 |
|
|
87 |
/** |
|
88 |
* If the specified ObjectFormatIdentifier is a resrouce map namespace. |
|
89 |
* @param formatid the specified format identifier. |
|
90 |
* @return true if it is a namespace of the resource map. |
|
91 |
*/ |
|
92 |
public static boolean isResourceMap(ObjectFormatIdentifier formatId) { |
|
93 |
boolean is = false; |
|
94 |
if(formatId != null ) { |
|
95 |
is = isResourceMap(formatId.getValue()); |
|
96 |
} |
|
97 |
return is; |
|
98 |
} |
|
99 |
|
|
100 |
|
|
101 |
} |
Also available in: Unified diff
Add a util class to judge if a namespace is a resource map file.