FormParamConverter { public static Dataset.Builder getDatasetBuilder(Map<String,List<String>> formParams){ HashMap<String, List<String>> datasetInfo = new HashMap<>(); HashMap<String,List<String>> locationInfo = new LinkedHashMap<>(); List<String> formParamKeys = new ArrayList<>(formParams.keySet()); Dataset.Builder builder = new Dataset.Builder(); Collections.sort( formParamKeys ); for(String name: formParamKeys){ if(name.startsWith("location")){ locationInfo.put( name, formParams.get( name )); } else if(name.equals("versionMetadata")){ builder.versionMetadata(processMetadata(formParams.get(name))); } else { datasetInfo.put(name, formParams.get( name)); } } ObjectMapper mapper = new ObjectMapper(); buildFromParams(mapper, builder, datasetSetters, datasetInfo); if(!locationInfo.isEmpty()){ HashMap<String,HashMap<String,List<String>>> locationsEntries = new LinkedHashMap<>(); List<DatasetLocationModel> locations = new ArrayList<>(); for(String locParam: locationInfo.keySet()){ String[] keys = locParam.split( "\\."); String locEntry = keys[0]; String field = keys[1]; if(!locationsEntries.containsKey( locEntry)){ locationsEntries.put(locEntry, new HashMap<String,List<String>>()); } locationsEntries.get(locEntry).put(field, formParams.get(locParam)); } for(HashMap<String,List<String>> loc: locationsEntries.values()){ DatasetLocation.Builder dsb = new DatasetLocation.Builder(); buildFromParams(mapper, dsb, locationSetters, loc); locations.add(dsb.build()); } if(locations.size() == 1){ builder.location(locations.get(0)); } else { builder.locations(locations); } } return builder; }  static DatasetContainerBuilder getContainerBuilder(RecordType type, MultivaluedMap<String,String> formParams); static Dataset.Builder getDatasetBuilder(Map<String,List<String>> formParams);  }
@Test public void testFlatDataset(){ HashMap<String, List<String>> dsMap = null; Dataset.Builder b = null; FlatDataset ds = null; dsMap = startDataset("hello"); b = FormParamConverter.getDatasetBuilder( dsMap ); ds = (FlatDataset) b.build(); TestCase.assertEquals("hello", ds.getName()); TestCase.assertEquals(HSqlDbHarness.JUNIT_DATASET_DATASOURCE, ds.getDatasetSource()); System.out.println(ds.isMaster()); dsMap = startDataset("test2"); dsMap.put("resource", Arrays.asList("file: dsMap.put("site", Arrays.asList("SLAC")); b = FormParamConverter.getDatasetBuilder( dsMap ); ds = (FlatDataset) b.build(); TestCase.assertEquals("test2", ds.getName()); TestCase.assertEquals("file: TestCase.assertEquals("SLAC", ds.getSite()); System.out.println(ds.isMaster()); String locationId = null; locationId = "location1."; dsMap = startDataset("test3"); dsMap.put(locationId + "resource", Arrays.asList("file: dsMap.put(locationId + "site", Arrays.asList("SLAC")); dsMap.put(locationId + "master", Arrays.asList("true")); b = FormParamConverter.getDatasetBuilder( dsMap ); ds = (FlatDataset) b.build(); TestCase.assertEquals("test3", ds.getName()); TestCase.assertEquals("file: TestCase.assertEquals("SLAC", ds.getSite()); TestCase.assertTrue(ds.isMaster()); }