master - 114 - fix GSLayerEncoder21
This commit is contained in:
parent
9b520e3d24
commit
0392ca309b
@ -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;
|
||||
|
||||
@ -50,7 +52,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()
|
||||
+ "\":\"" + entry.getValue() + "\"," + "\""
|
||||
+ AuthorityURLInfo.href.name() + "\":\""
|
||||
+ value + "\"" + "},";
|
||||
}
|
||||
}
|
||||
metadata.set("identifiers", "["+jsonStr+"]");
|
||||
delete = true;
|
||||
@ -145,15 +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+"]");
|
||||
}
|
||||
@ -171,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;
|
||||
|
||||
@ -54,6 +54,8 @@ public class GSLayerEncoder21Test {
|
||||
"authority2", "http://www.authority2.org"));
|
||||
layerEncoder.addIdentifier(new GSIdentifierInfoEncoder("authority2",
|
||||
"identifier2"));
|
||||
layerEncoder.addIdentifier(new GSIdentifierInfoEncoder("authority2",
|
||||
"additionalId"));
|
||||
}
|
||||
|
||||
|
||||
@ -112,9 +114,17 @@ public class GSLayerEncoder21Test {
|
||||
String[] kvp2_1 = props2[0].split("\":");
|
||||
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 GeoserverRESTTest {
|
||||
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