/** * Create result values from observation according to ResultEncoding and ResultStructure * * @param observations Observation to create result values from * @param sosResultEncoding The ResultEncoding * @param sosResultStructure The ResultStructure * @return Result values String from observation according to ResultEncoding and ResultStructure * @throws OwsExceptionReport If creation fails */ public static String createResultValuesFromObservations( final List<AbstractObservation> observations, final SosResultEncoding sosResultEncoding, final SosResultStructure sosResultStructure) throws OwsExceptionReport { final StringBuilder builder = new StringBuilder(); if (CollectionHelper.isNotEmpty(observations)) { final String tokenSeparator = getTokenSeparator(sosResultEncoding.getEncoding()); final String blockSeparator = getBlockSeparator(sosResultEncoding.getEncoding()); final Map<Integer, String> valueOrder = getValueOrderMap(sosResultStructure.getResultStructure()); addElementCount(builder, observations.size(), blockSeparator); for (final AbstractObservation observation : observations) { for (final Integer intger : valueOrder.keySet()) { final String definition = valueOrder.get(intger); if (definition.equals(PHENOMENON_TIME)) { builder.append( getTimeStringForPhenomenonTime( observation.getPhenomenonTimeStart(), observation.getPhenomenonTimeEnd())); } else if (definition.equals(RESULT_TIME)) { builder.append(getTimeStringForResultTime(observation.getResultTime())); } else { builder.append(getValueAsStringForObservedProperty(observation, definition)); } builder.append(tokenSeparator); } builder.delete(builder.lastIndexOf(tokenSeparator), builder.length()); builder.append(blockSeparator); } if (builder.length() > 0) { builder.delete(builder.lastIndexOf(blockSeparator), builder.length()); } } return builder.toString(); }
private static String getValueAsStringForObservedProperty( final AbstractObservation observation, final String definition) { final String observedProperty = observation.getObservableProperty().getIdentifier(); if (observedProperty.equals(definition)) { if (observation instanceof NumericObservation) { return String.valueOf(((NumericObservation) observation).getValue()); } else if (observation instanceof BooleanObservation) { return String.valueOf(((BooleanObservation) observation).getValue()); } else if (observation instanceof CategoryObservation) { return String.valueOf(((CategoryObservation) observation).getValue()); } else if (observation instanceof CountObservation) { return String.valueOf(((CountObservation) observation).getValue()); } else if (observation instanceof TextObservation) { return String.valueOf(((TextObservation) observation).getValue()); } else if (observation instanceof GeometryObservation) { final WKTWriter writer = new WKTWriter(); return writer.write(((GeometryObservation) observation).getValue()); } else if (observation instanceof BlobObservation) { return String.valueOf(((BlobObservation) observation).getValue()); } // // TODO multiple values? // Set<BooleanValue> booleanValues = observation.getBooleanValue(); // if (booleanValues != null && !booleanValues.isEmpty()) { // return // String.valueOf(booleanValues.iterator().next().getValue()); // } // // Set<CategoryValue> categoryValues = // observation.getCategoryValue(); // if (categoryValues != null && !categoryValues.isEmpty()) { // return categoryValues.iterator().next().getValue(); // } // // Set<CountValue> countValues = observation.getCountValue(); // if (countValues != null && !countValues.isEmpty()) { // return String.valueOf(countValues.iterator().next().getValue()); // } // // Set<NumericValue> numericValues = observation.getNumericValues(); // if (numericValues != null && !numericValues.isEmpty()) { // return // String.valueOf(numericValues.iterator().next().getValue()); // } // // //TODO geometry values; // // Set<TextValue> textValues = observation.getTextValues(); // if (textValues != null && !textValues.isEmpty()) { // StringBuilder builder = new StringBuilder(); // for (TextValue textValue : textValues) { // builder.append(textValue.getValue()); // } // return builder.toString(); // } } return Configurator.getInstance() .getProfileHandler() .getActiveProfile() .getResponseNoDataPlaceholder(); }