Skip to content

Commit 86c100e

Browse files
committed
CSW Improvements: GEOS-5930 , GEOS-5937, GEOS-5934, tutorial prefixed name in mapping
1 parent 03c7ed1 commit 86c100e

File tree

12 files changed

+120
-19
lines changed

12 files changed

+120
-19
lines changed
File renamed without changes.

doc/en/user/source/community/csw/tutorial.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Configuration
1010

1111
In the :file:`<data_dir>/csw` directory, create a new file named :file:`MD_Metadata` (ISO Metadata Profile mapping file) with the following contents::
1212

13-
@fileIdentifier.CharacterString=id
13+
@fileIdentifier.CharacterString=prefixedName
1414
identificationInfo.AbstractMD_Identification.citation.CI_Citation.title.CharacterString=title
1515
identificationInfo.AbstractMD_Identification.descriptiveKeywords.MD_Keywords.keyword.CharacterString=keywords
1616
identificationInfo.AbstractMD_Identification.abstract.CharacterString=abstract

src/community/csw/core/src/main/java/org/geoserver/csw/DefaultWebCatalogService.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,19 @@ public class DefaultWebCatalogService implements WebCatalogService, ApplicationC
3838

3939
private CSWInfo csw;
4040

41-
//private GeoServer gs;
41+
private GeoServer gs;
4242

4343
private CatalogStore store;
4444

4545
protected ApplicationContext context;
4646

4747
public DefaultWebCatalogService(GeoServer gs) {
4848
this.csw = gs.getService(CSWInfo.class);
49-
// this.gs = gs;
49+
this.gs = gs;
50+
}
51+
52+
public CSWInfo getServiceInfo() {
53+
return gs.getService(CSWInfo.class);
5054
}
5155

5256
@Override

src/community/csw/core/src/main/java/org/geoserver/csw/WebCatalogService.java

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
* @author Andrea Aime - GeoSolutions
2828
*/
2929
public interface WebCatalogService {
30+
/**
31+
* The configuration of the service.
32+
*/
33+
CSWInfo getServiceInfo();
34+
3035
/**
3136
* Returns a object model representing the capabilities document
3237
*/

src/community/csw/core/src/main/java/org/geoserver/csw/store/internal/CatalogStoreFeatureCollection.java

-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
import org.geoserver.csw.feature.MemoryFeatureCollection;
1313
import org.geoserver.csw.records.CSWRecordDescriptor;
1414
import org.geoserver.csw.records.RecordDescriptor;
15-
import org.geotools.data.complex.filter.XPathUtil;
1615
import org.geotools.data.store.FilteringFeatureCollection;
1716
import org.geotools.feature.FeatureCollection;
18-
import org.geotools.filter.SortByImpl;
1917
import org.opengis.feature.Feature;
2018
import org.opengis.feature.type.FeatureType;
2119
import org.opengis.filter.Filter;

src/community/csw/core/src/main/java/org/geoserver/csw/store/internal/CatalogStoreFeatureIterator.java

-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
import org.geoserver.csw.records.RecordDescriptor;
1818
import org.opengis.filter.Filter;
1919
import org.opengis.filter.sort.SortBy;
20-
import org.geotools.data.complex.filter.XPathUtil;
21-
import org.geotools.filter.SortByImpl;
2220
import org.geotools.geometry.jts.ReferencedEnvelope;
2321
import org.geotools.util.logging.Logging;
2422
import org.opengis.feature.Feature;

src/community/csw/core/src/main/java/org/geoserver/csw/store/internal/GeoServerInternalCatalogStore.java

+40-8
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
package org.geoserver.csw.store.internal;
66

77
import java.io.File;
8-
import java.io.FileInputStream;
98
import java.io.IOException;
109
import java.util.HashMap;
1110
import java.util.Map;
12-
import java.util.Properties;
11+
import java.util.logging.Level;
12+
import java.util.logging.Logger;
1313

1414
import org.geoserver.config.GeoServer;
1515
import org.geoserver.platform.GeoServerResourceLoader;
16+
import org.geoserver.security.PropertyFileWatcher;
17+
import org.geotools.util.logging.Logging;
1618

1719
/**
1820
* Internal Catalog Store that automatically loads mappings from mapping files in GeoServer Data Directory.
@@ -21,6 +23,31 @@
2123
*
2224
*/
2325
public class GeoServerInternalCatalogStore extends InternalCatalogStore {
26+
27+
protected static final Logger LOGGER = Logging.getLogger(GeoServerInternalCatalogStore.class);
28+
29+
protected Map<String, PropertyFileWatcher> watchers = new HashMap<String, PropertyFileWatcher>();
30+
31+
/**
32+
* Get Mapping, update from file if changed
33+
*
34+
* @param typeName
35+
* @return the mapping
36+
*/
37+
public CatalogStoreMapping getMapping(String typeName) {
38+
39+
PropertyFileWatcher watcher = watchers.get(typeName);
40+
41+
if (watcher!=null && watcher.isModified() ) {
42+
try {
43+
addMapping (typeName, CatalogStoreMapping.parse(new HashMap<String, String>((Map) watcher.getProperties())));
44+
} catch (IOException e) {
45+
LOGGER.log(Level.WARNING, e.toString());
46+
}
47+
}
48+
49+
return super.getMapping( typeName);
50+
}
2451

2552
/**
2653
* Create GeoServerInternalCatalogStore
@@ -32,12 +59,17 @@ public GeoServerInternalCatalogStore(GeoServer geoserver) throws IOException {
3259
super( geoserver.getCatalog());
3360
GeoServerResourceLoader loader = geoserver.getCatalog().getResourceLoader();
3461
File dir = loader.findOrCreateDirectory("csw");
35-
for (File f : dir.listFiles()) {
36-
Properties properties = new Properties();
37-
FileInputStream in = new FileInputStream(f);
38-
properties.load(in);
39-
in.close();
40-
addMapping (f.getName(), CatalogStoreMapping.parse(new HashMap<String, String>((Map) properties)));
62+
for (String typeName : descriptorByType.keySet()) {
63+
File f = new File(dir, typeName + ".properties");
64+
65+
PropertyFileWatcher watcher = new PropertyFileWatcher(f);
66+
watchers.put(typeName, watcher);
67+
68+
if (f.exists()) {
69+
addMapping (typeName, CatalogStoreMapping.parse(new HashMap<String, String>((Map) watcher.getProperties())));
70+
} else {
71+
addMapping (typeName, new CatalogStoreMapping());
72+
}
4173
}
4274
}
4375

src/community/csw/core/src/main/java/org/geoserver/csw/store/internal/InternalCatalogStore.java

+11-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import java.util.HashMap;
1111
import java.util.Map;
1212

13-
import net.opengis.cat.csw20.ElementSetType;
14-
1513
import org.geoserver.catalog.Catalog;
1614
import org.geoserver.csw.feature.MemoryFeatureCollection;
1715
import org.geoserver.csw.feature.sort.ComplexComparatorFactory;
@@ -59,11 +57,21 @@ public InternalCatalogStore(Catalog catalog) {
5957
public void addMapping(String typeName, CatalogStoreMapping mapping) {
6058
mappings.put(typeName, mapping);
6159
}
60+
61+
/**
62+
* Get Mapping
63+
*
64+
* @param typeName
65+
* @return the mapping
66+
*/
67+
public CatalogStoreMapping getMapping(String typeName) {
68+
return mappings.get(typeName);
69+
}
6270

6371
@Override
6472
public FeatureCollection getRecordsInternal(RecordDescriptor rd, Query q, Transaction t) throws IOException {
6573

66-
CatalogStoreMapping mapping = mappings.get(q.getTypeName());
74+
CatalogStoreMapping mapping = getMapping(q.getTypeName());
6775

6876
int startIndex = 0;
6977
if (q.getStartIndex() != null) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package org.geoserver.csw.store.internal;
2+
3+
import static org.junit.Assert.*;
4+
5+
import java.io.BufferedWriter;
6+
import java.io.File;
7+
import java.io.FileWriter;
8+
import java.io.IOException;
9+
import java.io.PrintWriter;
10+
11+
import org.apache.commons.io.FileUtils;
12+
import org.geoserver.csw.CSWTestSupport;
13+
import org.junit.Test;
14+
15+
public class GeoServerInternalCatalogStoreTest extends CSWTestSupport {
16+
17+
@Test
18+
public void testModifyMappingFiles() throws IOException, InterruptedException {
19+
20+
//test empty mappings
21+
InternalCatalogStore store = new GeoServerInternalCatalogStore(this.getGeoServer());
22+
23+
assertNull(store.getMapping("MD_Metadata").getElement("fileIdentifier.CharacterString"));
24+
assertNull(store.getMapping("Record").getElement("identifier.value"));
25+
26+
// copy all mappings into the data directory
27+
File root = testData.getDataDirectoryRoot();
28+
File csw = new File(root, "csw");
29+
File records = new File("./src/main/resources/org/geoserver/csw/store/internal");
30+
FileUtils.copyDirectory(records, csw);
31+
32+
//wait a second, that is exactly what it takes FileWatcher to update
33+
Thread.sleep(1001);
34+
35+
//now there should be mappings
36+
37+
assertNotNull(store.getMapping("MD_Metadata").getElement("fileIdentifier.CharacterString"));
38+
assertNotNull(store.getMapping("Record").getElement("identifier.value"));
39+
40+
assertNull(store.getMapping("Record").getElement("format.value"));
41+
42+
//modify mapping file
43+
44+
File record = new File(csw, "Record.properties");
45+
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(record, true)));
46+
out.println("\nformat.value='img/jpeg'");
47+
out.close();
48+
49+
//wait a second, that is exactly what it takes FileWatcher to update
50+
Thread.sleep(1001);
51+
52+
//mapping should be automatically reloaded
53+
54+
assertEquals( "img/jpeg", store.getMapping("Record").getElement("format.value").getContent().toString());
55+
}
56+
}

src/community/csw/core/src/test/java/org/geoserver/csw/store/internal/GetRecordsTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public void testFullTextSearch() throws Exception {
156156
String request = "csw?service=CSW&version=2.0.2&request=GetRecords&typeNames=csw:Record&resultType=results&elementSetName=brief&constraint=AnyText like '%25about B%25'";
157157
Document d = getAsDOM(request);
158158
checkValidationErrors(d, new CSWConfiguration());
159-
//print(d);
159+
print(d);
160160

161161
// basic checks
162162
assertXpathEvaluatesTo("3", "//csw:SearchResults/@numberOfRecordsMatched", d);

0 commit comments

Comments
 (0)