1.5.x #114 - fix GSLayerEncoder21 (identifiers)
This commit is contained in:
parent
5c1569c129
commit
6fc77c7936
@ -25,7 +25,9 @@
|
||||
|
||||
package it.geosolutions.geoserver.rest.encoder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@ -49,7 +51,7 @@ public class GSLayerEncoder21 extends GSLayerEncoder {
|
||||
public final static String METADATA = "metadata";
|
||||
final private GSMetadataEncoder metadata = new GSMetadataEncoder();
|
||||
public Map<String, String> authorityURLList;
|
||||
public Map<String, String> identifierList;
|
||||
public Map<String, List<String>> identifierList;
|
||||
|
||||
private class GSMetadataEncoder extends NestedElementEncoder {
|
||||
public GSMetadataEncoder() {
|
||||
@ -125,11 +127,14 @@ public class GSLayerEncoder21 extends GSLayerEncoder {
|
||||
if (authorityURLList.containsKey(authorityURL)) {
|
||||
identifierList.remove(authorityURL);
|
||||
String jsonStr = "";
|
||||
for (Entry<String, String> entry : identifierList.entrySet()) {
|
||||
jsonStr += "{" + "\"" + AuthorityURLInfo.name.name()
|
||||
+ "\":\"" + entry.getValue() + "\"," + "\""
|
||||
+ AuthorityURLInfo.href.name() + "\":\""
|
||||
+ entry.getKey() + "\"" + "},";
|
||||
for (Entry<String, List<String>> entry : identifierList
|
||||
.entrySet()) {
|
||||
for (String value : entry.getValue()) {
|
||||
jsonStr += "{" + "\"" + AuthorityURLInfo.name.name()
|
||||
+ "\":\"" + value + "\"," + "\""
|
||||
+ AuthorityURLInfo.href.name() + "\":\""
|
||||
+ entry.getKey() + "\"" + "},";
|
||||
}
|
||||
}
|
||||
metadata.set("identifiers", "[" + jsonStr + "]");
|
||||
delete = true;
|
||||
@ -145,16 +150,29 @@ public class GSLayerEncoder21 extends GSLayerEncoder {
|
||||
*/
|
||||
public void addIdentifier(GSIdentifierInfoEncoder identifierInfo) {
|
||||
if (identifierList == null) {
|
||||
identifierList = new HashMap<String, String>();
|
||||
identifierList = new HashMap<String, List<String>>();
|
||||
}
|
||||
identifierList.put(identifierInfo.getAuthority(),
|
||||
identifierInfo.getIdentifier());
|
||||
|
||||
String authority = identifierInfo.getAuthority();
|
||||
|
||||
if (!identifierList.containsKey(authority)) {
|
||||
List<String> ids = new ArrayList<String>();
|
||||
ids.add(identifierInfo.getIdentifier());
|
||||
identifierList.put(authority, ids);
|
||||
} else {
|
||||
List<String> ids = identifierList.get(authority);
|
||||
ids.add(identifierInfo.getIdentifier());
|
||||
identifierList.put(authority, ids);
|
||||
}
|
||||
|
||||
String jsonStr = "";
|
||||
for (Entry<String, String> entry : identifierList.entrySet()) {
|
||||
jsonStr += "{" + "\"" + IdentifierInfo.authority.name() + "\":\""
|
||||
+ entry.getKey() + "\"," + "\""
|
||||
+ IdentifierInfo.identifier.name() + "\":\""
|
||||
+ entry.getValue() + "\"" + "},";
|
||||
for (Entry<String, List<String>> entry : identifierList.entrySet()) {
|
||||
for (String value : entry.getValue()) {
|
||||
jsonStr += "{" + "\"" + IdentifierInfo.authority.name()
|
||||
+ "\":\"" + entry.getKey() + "\"," + "\""
|
||||
+ IdentifierInfo.identifier.name() + "\":\"" + value
|
||||
+ "\"" + "},";
|
||||
}
|
||||
}
|
||||
metadata.set("identifiers", "[" + jsonStr + "]");
|
||||
}
|
||||
@ -172,11 +190,14 @@ public class GSLayerEncoder21 extends GSLayerEncoder {
|
||||
if (identifierList.containsKey(authority)) {
|
||||
identifierList.remove(authority);
|
||||
String jsonStr = "";
|
||||
for (Entry<String, String> entry : identifierList.entrySet()) {
|
||||
jsonStr += "{" + "\"" + IdentifierInfo.authority.name()
|
||||
+ "\":\"" + entry.getKey() + "\"," + "\""
|
||||
+ IdentifierInfo.identifier.name() + "\":\""
|
||||
+ entry.getValue() + "\"" + "},";
|
||||
for (Entry<String, List<String>> entry : identifierList
|
||||
.entrySet()) {
|
||||
for (String value : entry.getValue()) {
|
||||
jsonStr += "{" + "\"" + IdentifierInfo.authority.name()
|
||||
+ "\":\"" + entry.getKey() + "\"," + "\""
|
||||
+ IdentifierInfo.identifier.name() + "\":\""
|
||||
+ value + "\"" + "},";
|
||||
}
|
||||
}
|
||||
metadata.set("identifiers", "[" + jsonStr + "]");
|
||||
delete = true;
|
||||
|
||||
@ -53,6 +53,8 @@ public class GSLayerEncoder21Test {
|
||||
"authority2", "http://www.authority2.org"));
|
||||
layerEncoder.addIdentifier(new GSIdentifierInfoEncoder("authority2",
|
||||
"identifier2"));
|
||||
layerEncoder.addIdentifier(new GSIdentifierInfoEncoder("authority2",
|
||||
"additionalId"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -116,10 +118,18 @@ public class GSLayerEncoder21Test {
|
||||
String[] kvp2_2 = props2[1].split("\":");
|
||||
Assert.assertEquals(IdentifierInfo.authority.name(),
|
||||
kvp2_1[0].replace("\"", ""));
|
||||
Assert.assertEquals("authority1", kvp2_1[1].replace("\"", ""));
|
||||
Assert.assertEquals("authority2", kvp2_1[1].replace("\"", ""));
|
||||
Assert.assertEquals(IdentifierInfo.identifier.name(),
|
||||
kvp2_2[0].replace("\"", ""));
|
||||
Assert.assertEquals("identifier1", kvp2_2[1].replace("\"", ""));
|
||||
Assert.assertEquals("additionalId", kvp2_2[1].replace("\"", ""));
|
||||
|
||||
String[] props3 = items[2].split(",");
|
||||
String[] kvp3_1 = props3[0].split("\":");
|
||||
String[] kvp3_2 = props3[1].split("\":");
|
||||
Assert.assertEquals(IdentifierInfo.authority.name(), kvp3_1[0].replace("\"", ""));
|
||||
Assert.assertEquals("authority1", kvp3_1[1].replace("\"", ""));
|
||||
Assert.assertEquals(IdentifierInfo.identifier.name(), kvp3_2[0].replace("\"", ""));
|
||||
Assert.assertEquals("identifier1", kvp3_2[1].replace("\"", ""));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,9 +113,12 @@ public class GSFeatureEncoderTest extends GeoserverRESTPublisherTest {
|
||||
layerEncoder.addAuthorityURL(authorityURL);
|
||||
|
||||
// identifier
|
||||
GSIdentifierInfoEncoder identifier = new GSIdentifierInfoEncoder(
|
||||
GSIdentifierInfoEncoder identifier1 = new GSIdentifierInfoEncoder(
|
||||
"authority1", "identifier1");
|
||||
layerEncoder.addIdentifier(identifier);
|
||||
GSIdentifierInfoEncoder identifier2 = new GSIdentifierInfoEncoder(
|
||||
"authority1", "another_identifier");
|
||||
layerEncoder.addIdentifier(identifier1);
|
||||
layerEncoder.addIdentifier(identifier2);
|
||||
|
||||
publisher.createWorkspace(DEFAULT_WS);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user