OtherContentProvider extends AbstractJrxmlContentProvider { @Override public void inspectInputParametersFromJrxml( Map<String, ParameterDescription> parameterDescriptions, List<JAXBElement<? extends ProcessletInputDefinition>> inputs, XMLAdapter jrxmlAdapter, Map<String, String> parameters, List<String> handledParameters ) { for ( String parameterName : parameters.keySet() ) { if ( parameters.containsKey( parameterName ) && !handledParameters.contains( parameterName ) ) { LiteralInputDefinition lit = new LiteralInputDefinition(); addInput( lit, parameterDescriptions, parameterName, 1, 0 ); lit.setDefaultValue( parameterName ); String parameterType = parameters.get( parameterName ); String dtValue = null; String dtRef = null; if ( parameterType == null || "java.lang.String".equals( parameterType ) ) { dtValue = "string"; dtRef = "http: } else if ( "java.lang.Boolean".equals( parameterType ) ) { dtValue = "boolean"; dtRef = "http: } else if ( "java.lang.Double".equals( parameterType ) ) { dtValue = "double"; dtRef = "http: } else if ( "java.lang.Integer".equals( parameterType ) ) { dtValue = "integer"; dtRef = "http: } else if ( "java.lang.Float".equals( parameterType ) ) { dtValue = "float"; dtRef = "http: } else if ( "java.lang.Long".equals( parameterType ) ) { dtValue = "long"; dtRef = "http: } else if ( "java.util.Date".equals( parameterType ) ) { dtValue = "date"; dtRef = "http: } else if ( "java.sql.Timestamp".equals( parameterType ) ) { dtValue = "dateTime"; dtRef = "http: } else if ( "java.sql.Time".equals( parameterType ) ) { dtValue = "time"; dtRef = "http: } else if ( "java.math.BigDecimal".equals( parameterType ) || "java.lang.Number".equals( parameterType ) ) { dtValue = "decimal"; dtRef = "http: } else if ( "java.lang.Short".equals( parameterType ) ) { dtValue = "integer"; dtRef = "http: AllowedValues allowedValues = new AllowedValues(); Range range = new Range(); range.setMinimumValue( Short.toString( Short.MIN_VALUE ) ); range.setMaximumValue( Short.toString( Short.MAX_VALUE ) ); allowedValues.getValueOrRange().add( range ); lit.setAllowedValues( allowedValues ); } else if ( "java.lang.Byte".equals( parameterType ) ) { dtValue = "integer"; dtRef = "http: AllowedValues allowedValues = new AllowedValues(); Range range = new Range(); range.setMinimumValue( Byte.toString( Byte.MIN_VALUE ) ); range.setMaximumValue( Byte.toString( Byte.MAX_VALUE ) ); allowedValues.getValueOrRange().add( range ); lit.setAllowedValues( allowedValues ); } else { LOG.info( "Unknown datatype of parameter '" + parameterName + "': " + parameterType ); return; } if ( dtValue != null ) { DataType dataType = new DataType(); dataType.setValue( dtValue ); dataType.setReference( dtRef ); lit.setDataType( dataType ); } inputs.add( new JAXBElement<LiteralInputDefinition>( new QName( "ProcessInput" ), LiteralInputDefinition.class, lit ) ); handledParameters.add( parameterName ); } } } OtherContentProvider( 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 );  }
@Test public void testInspectInputParametersFromJrxml() { OtherContentProvider wmsContentProvider = new OtherContentProvider( null ); Map<String, String> parameters = new HashMap<String, String>(); parameters.put( "DATE", "java.util.Date" ); parameters.put( "DESCRIPTION", "java.lang.String" ); parameters.put( "MAPSCALE", "java.lang.Integer" ); parameters.put( "printOptTxt", "java.lang.Boolean" ); List<JAXBElement<? extends ProcessletInputDefinition>> inputs = new ArrayList<JAXBElement<? extends ProcessletInputDefinition>>(); XMLAdapter adapter = new XMLAdapter( TestOtherContentProviderTest.class.getResourceAsStream( "../testWPSreportTemplate.jrxml" ) ); List<String> handledParams = new ArrayList<String>(); wmsContentProvider.inspectInputParametersFromJrxml( new HashMap<String, ParameterDescription>(), inputs, adapter, parameters, handledParams ); assertEquals( 4, parameters.size() ); assertEquals( 4, handledParams.size() ); assertEquals( 4, inputs.size() ); JAXBElement<? extends ProcessletInputDefinition> pDate = null; JAXBElement<? extends ProcessletInputDefinition> pString = null; JAXBElement<? extends ProcessletInputDefinition> pInt = null; JAXBElement<? extends ProcessletInputDefinition> pBool = null; for ( JAXBElement<? extends ProcessletInputDefinition> in : inputs ) { if ( "DATE".equals( in.getValue().getIdentifier().getValue() ) ) { pDate = in; } else if ( "DESCRIPTION".equals( in.getValue().getIdentifier().getValue() ) ) { pString = in; } else if ( "MAPSCALE".equals( in.getValue().getIdentifier().getValue() ) ) { pInt = in; } else if ( "printOptTxt".equals( in.getValue().getIdentifier().getValue() ) ) { pBool = in; } } assertNotNull( pDate ); assertNotNull( pString ); assertNotNull( pInt ); assertNotNull( pBool ); assertTrue( pDate.getDeclaredType() == LiteralInputDefinition.class ); assertTrue( pString.getDeclaredType() == LiteralInputDefinition.class ); assertTrue( pInt.getDeclaredType() == LiteralInputDefinition.class ); assertTrue( pBool.getDeclaredType() == LiteralInputDefinition.class ); assertEquals( "date", ( ( (LiteralInputDefinition) pDate.getValue() ).getDataType().getValue() ) ); assertEquals( "string", ( ( (LiteralInputDefinition) pString.getValue() ).getDataType().getValue() ) ); assertEquals( "integer", ( ( (LiteralInputDefinition) pInt.getValue() ).getDataType().getValue() ) ); assertEquals( "boolean", ( ( (LiteralInputDefinition) pBool.getValue() ).getDataType().getValue() ) ); }