MapContentProvider extends AbstractJrxmlContentProvider { List<OrderedDatasource<?>> anaylizeRequestOrder( List<AbstractDatasourceType> datasources ) { List<OrderedDatasource<?>> orderedDatasources = new ArrayList<OrderedDatasource<?>>(); for ( AbstractDatasourceType datasource : datasources ) { if ( datasource instanceof WMSDatasource ) { WMSDatasource wmsDatasource = (WMSDatasource) datasource; List<Layer> layers = wmsDatasource.getLayers().getLayer(); int index = 0; for ( Layer layer : layers ) { BigInteger position = layer.getPosition(); if ( position != null ) { int intPos = position.intValue(); WMSOrderedDatasource contains = contains( orderedDatasources, wmsDatasource, intPos ); if ( contains != null ) { List<Layer> orderedLayers = contains.layers; int i = 0; for ( Layer orderedLayer : orderedLayers ) { if ( orderedLayer.getPosition().intValue() < intPos ) { i++; } } contains.layers.add( i, layer ); contains.min = contains.min < intPos ? contains.min : intPos; contains.max = contains.max > intPos ? contains.max : intPos; } else { List<Layer> newLayerList = new ArrayList<Layer>(); newLayerList.add( layer ); int indexToAdd = getIndexToAdd( orderedDatasources, intPos ); orderedDatasources.add( indexToAdd, new WMSOrderedDatasource( wmsDatasource, newLayerList, intPos, intPos ) ); } } else { WMSOrderedDatasource contains = contains( orderedDatasources, wmsDatasource ); if ( contains != null ) { contains.layers.add( layer ); } else { List<Layer> newLayerList = new ArrayList<Layer>(); newLayerList.add( layer ); orderedDatasources.add( new WMSOrderedDatasource( wmsDatasource, newLayerList ) ); } } index++; } } else if ( datasource instanceof WFSDatasource ) { WFSDatasource wfsDatasource = (WFSDatasource) datasource; WFSOrderedDatasource newDatasource = new WFSOrderedDatasource( wfsDatasource ); if ( wfsDatasource.getPosition() != null ) { int indexToAdd = getIndexToAdd( orderedDatasources, wfsDatasource.getPosition().intValue() ); orderedDatasources.add( indexToAdd, newDatasource ); } else { orderedDatasources.add( newDatasource ); } } } return orderedDatasources; } MapContentProvider( Workspace workspace ); @Override void inspectInputParametersFromJrxml( Map<String, ParameterDescription> parameterDescriptions,
                                                 List<JAXBElement<? extends ProcessletInputDefinition>> inputs,
                                                 XMLAdapter jrxmlAdapter, Map<String, String> parameters,
                                                 List<String> handledParameters ); @Override Pair<InputStream, Boolean> prepareJrxmlAndReadInputParameters( InputStream jrxml,
                                                                          Map<String, Object> params,
                                                                          ProcessletInputs in,
                                                                          List<CodeType> processedIds,
                                                                          Map<String, String> parameters ); static final double INCH2M; }
@Test public void testAnaylizeRequestOrder() throws JAXBException, IOException { MapContentProvider wmsContentProvider = getProvider(); JAXBContext jc = JAXBContext.newInstance( org.deegree.services.wps.provider.jrxml.jaxb.map.Map.class ); Unmarshaller unmarshaller = jc.createUnmarshaller(); InputStream is = TestMapContentProviderTest.class.getResourceAsStream( "mapDescription.xml" ); org.deegree.services.wps.provider.jrxml.jaxb.map.Map map = (org.deegree.services.wps.provider.jrxml.jaxb.map.Map) unmarshaller.unmarshal( is ); List<OrderedDatasource<?>> anaylizeRequestOrder = wmsContentProvider.anaylizeRequestOrder( map.getDatasources().getWMSDatasourceOrWFSDatasource() ); List<Pair<String, String>> expectedParts = new ArrayList<Pair<String, String>>(); expectedParts.add( new Pair<String, String>( "http: expectedParts.add( new Pair<String, String>( "http: expectedParts.add( new Pair<String, String>( "http: expectedParts.add( new Pair<String, String>( "http: "Vegetation,Wood" ) ); expectedParts.add( new Pair<String, String>( "http: int index = 0; assertEquals( expectedParts.size(), anaylizeRequestOrder.size() ); for ( OrderedDatasource<?> ds : anaylizeRequestOrder ) { assertTrue( ds instanceof WMSOrderedDatasource ); WMSOrderedDatasource wds = (WMSOrderedDatasource) ds; Pair<String, String> expected = expectedParts.get( index++ ); assertTrue( wds.datasource.getUrl().startsWith( expected.first ) ); String layersAsString = ""; boolean isFirst = true; for ( Layer l : wds.layers ) { if ( !isFirst ) { layersAsString += ","; } layersAsString += l.getName(); isFirst = false; } assertEquals( expected.second, layersAsString ); } is.close(); }
@Test public void testAnaylizeRequestOrderSimple() throws JAXBException, IOException { MapContentProvider wmsContentProvider = getProvider(); JAXBContext jc = JAXBContext.newInstance( org.deegree.services.wps.provider.jrxml.jaxb.map.Map.class ); Unmarshaller unmarshaller = jc.createUnmarshaller(); InputStream is = TestMapContentProviderTest.class.getResourceAsStream( "mapDescription_simple.xml" ); org.deegree.services.wps.provider.jrxml.jaxb.map.Map map = (org.deegree.services.wps.provider.jrxml.jaxb.map.Map) unmarshaller.unmarshal( is ); List<OrderedDatasource<?>> anaylizeRequestOrder = wmsContentProvider.anaylizeRequestOrder( map.getDatasources().getWMSDatasourceOrWFSDatasource() ); assertEquals( 1, anaylizeRequestOrder.size() ); OrderedDatasource<?> ds = anaylizeRequestOrder.get( 0 ); assertTrue( ds instanceof WMSOrderedDatasource ); WMSOrderedDatasource wds = (WMSOrderedDatasource) ds; assertTrue( wds.datasource.getUrl().startsWith( "http: assertEquals( 2, wds.layers.size() ); assertEquals( wds.layers.get( 0 ).getName(), "StateOverview" ); assertEquals( wds.layers.get( 1 ).getName(), "Lake" ); is.close(); }