use of org.geotoolkit.processing.chain.model.StringMap in project geotoolkit by Geomatys.
the class ChainProcessDescriptor method convertParameterDtoToParameterDescriptor.
public static ParameterDescriptor convertParameterDtoToParameterDescriptor(final Parameter param, final boolean realType) {
final Map<String, Object> ext = new HashMap<>();
Class type;
if (realType) {
type = param.getType().getRealClass();
} else {
ext.put(KEY_DISTANT_CLASS, param.getType());
try {
type = Class.forName(param.getType().getName());
} catch (ClassNotFoundException ex) {
type = Object.class;
}
}
if (param.getFormats() != null && !param.getFormats().isEmpty()) {
List<Map> formats = new ArrayList<>();
for (ParameterFormat format : param.getFormats()) {
Map m = new HashMap<>();
if (format.getEncoding() != null)
m.put("encoding", format.getEncoding());
if (format.getMimeType() != null)
m.put("mimetype", format.getMimeType());
if (format.getSchema() != null)
m.put("schema", format.getSchema());
formats.add(m);
}
ext.put("formats", formats);
}
if (param.getTitle() != null) {
ext.put("Title", param.getTitle());
}
if (param.getUserMap() != null) {
Map<String, Object> userMap = new HashMap<>();
// remove hack for serialisation String map
for (Entry<String, Object> entry : param.getUserMap().entrySet()) {
if (entry.getValue() instanceof StringMap) {
userMap.put(entry.getKey(), ((StringMap) entry.getValue()).getMap());
} else if (entry.getValue() instanceof StringMapList) {
StringMapList sml = (StringMapList) entry.getValue();
Map<String, Collection<String>> map = new HashMap<>();
for (Entry<String, StringList> ent : sml.getMap().entrySet()) {
map.put(ent.getKey(), ent.getValue().getList());
}
userMap.put(entry.getKey(), map);
} else {
userMap.put(entry.getKey(), entry.getValue());
}
}
ext.putAll(userMap);
}
if (param.getFormats() != null && !param.getFormats().isEmpty()) {
List<Map> formats = new ArrayList<>();
for (ParameterFormat format : param.getFormats()) {
Map m = new HashMap<>();
if (format.getEncoding() != null)
m.put("encoding", format.getEncoding());
if (format.getMimeType() != null)
m.put("mimetype", format.getMimeType());
if (format.getSchema() != null)
m.put("schema", format.getSchema());
formats.add(m);
}
ext.put("formats", formats);
}
return new ExtendedParameterDescriptor(param.getCode(), null, param.getRemarks(), param.getMinOccurs(), param.getMaxOccurs(), type, convertDefaultValueInClass(param.getDefaultValue(), type), param.getValidValues(), ext);
}
use of org.geotoolkit.processing.chain.model.StringMap in project geotoolkit by Geomatys.
the class ChainProcessTest method testXmlRW.
@Test
public void testXmlRW() throws ProcessException, JAXBException, IOException {
// test various problematic case
final Chain chain = new Chain("myChain");
// sting/string in user map
Parameter param = new Parameter("in1", String.class, "enumerated string", "none", 0, 12, "def", new String[] { "def", "undef" });
Map<String, Object> userMap = new HashMap<>();
userMap.put("test", "test");
param.setUserMap(userMap);
chain.getInputs().add(param);
Parameter param2 = new Parameter("in2", Character.class, "char", "none", 0, 12, 'c');
chain.getInputs().add(param2);
File f = File.createTempFile("chain", ".xml");
chain.write(f);
final Chain chainr = Chain.read(f);
Parameter p = chainr.getInput("in2");
// assertEquals('c', p.getDefaultValue()); problem here char are rw to integer...
// sting/double in user map
userMap = new HashMap<>();
userMap.put("test-double", 125d);
param.setUserMap(userMap);
f = File.createTempFile("chain", ".xml");
chain.write(f);
// sting/map in user map
userMap = new HashMap<>();
HashMap<String, String> typeMap = new HashMap<>();
typeMap.put("String", "String");
userMap.put("test-map", new StringMap(typeMap));
param.setUserMap(userMap);
f = File.createTempFile("chain", ".xml");
chain.write(f);
// sting/map/list in user map
userMap = new HashMap<>();
HashMap<String, StringList> typeMapList = new HashMap<>();
ArrayList a = new ArrayList<>();
a.add("String");
a.add("String2");
typeMapList.put("String", new StringList(a));
userMap.put("test-map", new StringMapList(typeMapList));
param.setUserMap(userMap);
f = File.createTempFile("chain", ".xml");
chain.write(f);
}
Aggregations