use of org.n52.svalbard.encode.exception.UnsupportedEncoderInputException in project arctic-sea by 52North.
the class GmlEncoderv321 method createAbstractGeometry.
private AbstractGeometryType createAbstractGeometry(AbstractGeometry element, EncodingContext ctx) throws EncodingException {
XmlObject xbGeometry = createPosition(element.getGeometry(), ctx);
AbstractGeometryType abstractGeometryType = null;
if (xbGeometry instanceof AbstractGeometryType) {
abstractGeometryType = (AbstractGeometryType) xbGeometry;
} else if (xbGeometry instanceof GeometryPropertyType) {
abstractGeometryType = ((GeometryPropertyType) xbGeometry).getAbstractGeometry();
} else {
throw new UnsupportedEncoderInputException(this, element);
}
if (element.isSetIdentifier()) {
abstractGeometryType.setIdentifier(createCodeWithAuthorityType(element.getIdentifierCodeWithAuthority()));
}
if (element.isSetName()) {
for (org.n52.shetland.ogc.gml.CodeType codeType : element.getName()) {
abstractGeometryType.addNewName().set(createCodeType(codeType));
}
}
if (element.isSetDescription()) {
abstractGeometryType.addNewDescription().setStringValue(element.getDescription());
}
return abstractGeometryType;
}
use of org.n52.svalbard.encode.exception.UnsupportedEncoderInputException in project arctic-sea by 52North.
the class SweCommonEncoderv101 method createDataArray.
private DataArrayDocument createDataArray(SweDataArray sosDataArray) throws EncodingException {
if (sosDataArray != null) {
if (sosDataArray.isSetElementTyp()) {
DataArrayDocument xbDataArrayDoc = DataArrayDocument.Factory.newInstance(getXmlOptions());
DataArrayType xbDataArray = xbDataArrayDoc.addNewDataArray1();
// set element count
if (sosDataArray.isSetElementCount()) {
xbDataArray.addNewElementCount().addNewCount().set(createCount(sosDataArray.getElementCount()));
}
if (sosDataArray.isSetElementTyp()) {
DataComponentPropertyType xbElementType = xbDataArray.addNewElementType();
xbElementType.setName("Components");
// FIXME use visitor pattern
if (sosDataArray.getElementType() instanceof SweBoolean) {
xbElementType.addNewBoolean().set(createSimpleType((SweBoolean) sosDataArray.getElementType()));
} else if (sosDataArray.getElementType() instanceof SweCategory) {
xbElementType.addNewCategory().set(createSimpleType((SweCategory) sosDataArray.getElementType()));
} else if (sosDataArray.getElementType() instanceof SweCount) {
xbElementType.addNewCount().set(createSimpleType((SweCount) sosDataArray.getElementType()));
} else if (sosDataArray.getElementType() instanceof SweQuantity) {
xbElementType.addNewQuantity().set(createSimpleType((SweQuantity) sosDataArray.getElementType()));
} else if (sosDataArray.getElementType() instanceof SweText) {
xbElementType.addNewText().set(createSimpleType((SweText) sosDataArray.getElementType()));
} else if (sosDataArray.getElementType() instanceof SweTimeRange) {
xbElementType.addNewTimeRange().set(createSimpleType((SweTimeRange) sosDataArray.getElementType()));
} else if (sosDataArray.getElementType() instanceof SweTime) {
xbElementType.addNewTime().set(createSimpleType((SweTime) sosDataArray.getElementType()));
} else if (sosDataArray.getElementType() instanceof SweEnvelope) {
xbElementType.addNewAbstractDataRecord().set(createEnvelope((SweEnvelope) sosDataArray.getElementType()));
xbElementType.getAbstractDataRecord().substitute(SweConstants.QN_ENVELOPE_SWE_101, EnvelopeType.type);
} else if (sosDataArray.getElementType() instanceof SweDataRecord) {
xbElementType.addNewAbstractDataRecord().set(createDataRecord((SweDataRecord) sosDataArray.getElementType()));
xbElementType.getAbstractDataRecord().substitute(SweConstants.QN_DATA_RECORD_SWE_101, DataRecordType.type);
} else if (sosDataArray.getElementType() instanceof SweDataArray) {
xbElementType.addNewAbstractDataArray1().set(createDataArray((SweDataArray) sosDataArray.getElementType()).getDataArray1());
xbElementType.getAbstractDataArray1().substitute(SweConstants.QN_DATA_RECORD_SWE_101, DataArrayType.type);
} else {
throw new UnsupportedEncoderInputException(this, sosDataArray.getElementType());
}
}
if (sosDataArray.isSetEncoding()) {
BlockEncodingPropertyType xbEncoding = xbDataArray.addNewEncoding();
xbEncoding.set(createBlockEncoding(sosDataArray.getEncoding()));
// xbDataArray.getEncoding().substitute(
// new QName(SWEConstants.NS_SWE_101,
// SWEConstants.EN_TEXT_ENCODING,
// SWEConstants.NS_SWE_PREFIX), TextBlock.type);
}
// }
if (sosDataArray.isSetValues()) {
xbDataArray.addNewValues().set(createValues(sosDataArray.getValues(), sosDataArray.getEncoding()));
}
return xbDataArrayDoc;
} else if (sosDataArray.isSetXml()) {
try {
XmlObject xmlObject = XmlObject.Factory.parse(sosDataArray.getXml().trim());
if (xmlObject instanceof DataArrayDocument) {
return (DataArrayDocument) xmlObject;
} else {
DataArrayDocument xbDataArrayDoc = DataArrayDocument.Factory.newInstance(getXmlOptions());
xbDataArrayDoc.setDataArray1(DataArrayType.Factory.parse(sosDataArray.getXml().trim()));
return xbDataArrayDoc;
}
} catch (XmlException e) {
throw new EncodingException("Error while encoding SweDataArray!", e);
}
}
}
return null;
}
use of org.n52.svalbard.encode.exception.UnsupportedEncoderInputException in project arctic-sea by 52North.
the class WmlTDREncoderv20 method createMeasurementDomainRange.
/**
* Create a XML MeasurementTimeseriesDomainRange object from SOS observation
* for om:result
*
* @param sosObservation
* SOS observation
* @return XML MeasurementTimeseriesDomainRange object for om:result
* @throws EncodingException
* If an error occurs
*/
private XmlObject createMeasurementDomainRange(OmObservation sosObservation) throws EncodingException {
if (!sosObservation.getObservationConstellation().isSetObservationType() || (sosObservation.getObservationConstellation().isSetObservationType() && isInvalidObservationType(sosObservation.getObservationConstellation().getObservationType()))) {
throw new UnsupportedEncoderInputException(this, sosObservation.getObservationConstellation().isSetObservationType());
}
MeasurementTimeseriesDomainRangeDocument xbMearuementTimeseriesDomainRangeDoc = MeasurementTimeseriesDomainRangeDocument.Factory.newInstance();
MeasurementTimeseriesCoverageType xbMeasurementTimeseriesDomainRange = xbMearuementTimeseriesDomainRangeDoc.addNewMeasurementTimeseriesDomainRange();
xbMeasurementTimeseriesDomainRange.setId(TIMESERIES_ID_PREFIX + sosObservation.getObservationID());
// set time position list
xbMeasurementTimeseriesDomainRange.addNewDomainSet().set(getTimePositionList(sosObservation));
// initialize unit
AbstractPhenomenon observableProperty = sosObservation.getObservationConstellation().getObservableProperty();
String unit = null;
// create quantity list from values
QuantityListDocument quantityListDoc = QuantityListDocument.Factory.newInstance();
MeasureOrNilReasonListType quantityList = quantityListDoc.addNewQuantityList();
if (sosObservation.getValue() instanceof MultiObservationValues) {
MultiObservationValues<?> observationValue = (MultiObservationValues<?>) sosObservation.getValue();
TVPValue tvpValue = (TVPValue) observationValue.getValue();
List<TimeValuePair> timeValuePairs = tvpValue.getValue();
if (Strings.isNullOrEmpty(unit) && CollectionHelper.isNotEmpty(timeValuePairs) && timeValuePairs.get(0).getValue().isSetUnit()) {
unit = timeValuePairs.get(0).getValue().getUnit();
}
quantityList.setListValue(getValueList(timeValuePairs));
}
if (Strings.isNullOrEmpty(unit)) {
unit = OGCConstants.UNKNOWN;
}
quantityList.setUom(unit);
// set unit to SosObservableProperty if not set.
if (observableProperty instanceof OmObservableProperty && !((OmObservableProperty) observableProperty).isSetUnit()) {
((OmObservableProperty) observableProperty).setUnit(unit);
}
// set up range set
xbMeasurementTimeseriesDomainRange.addNewRangeSet().set(quantityListDoc);
// set up rangeType
xbMeasurementTimeseriesDomainRange.addNewRangeType().set(createDataRecord(sosObservation));
// set om:Result
return xbMearuementTimeseriesDomainRangeDoc;
}
use of org.n52.svalbard.encode.exception.UnsupportedEncoderInputException in project arctic-sea by 52North.
the class SamplingEncoderv20 method createFeature.
protected XmlObject createFeature(final AbstractFeature absFeature) throws EncodingException {
if (absFeature instanceof AbstractSamplingFeature) {
final AbstractSamplingFeature sampFeat = (AbstractSamplingFeature) absFeature;
final SFSpatialSamplingFeatureDocument xbSampFeatDoc = SFSpatialSamplingFeatureDocument.Factory.newInstance(getXmlOptions());
if (sampFeat.isSetXml()) {
try {
final XmlObject feature = XmlObject.Factory.parse(sampFeat.getXml(), getXmlOptions());
if (XmlHelper.getNamespace(feature).equals(SfConstants.NS_SAMS)) {
XmlHelper.updateGmlIDs(feature.getDomNode().getFirstChild(), absFeature.getGmlId(), null);
if (feature instanceof SFSpatialSamplingFeatureType) {
xbSampFeatDoc.setSFSpatialSamplingFeature((SFSpatialSamplingFeatureType) feature);
encodeShape(xbSampFeatDoc.getSFSpatialSamplingFeature().getShape(), sampFeat);
addNameDescription(xbSampFeatDoc.getSFSpatialSamplingFeature(), sampFeat);
return xbSampFeatDoc;
}
encodeShape(((SFSpatialSamplingFeatureDocument) feature).getSFSpatialSamplingFeature().getShape(), sampFeat);
addNameDescription(((SFSpatialSamplingFeatureDocument) feature).getSFSpatialSamplingFeature(), sampFeat);
sampFeat.wasEncoded();
return feature;
} else {
return encodeObjectToXml(XmlHelper.getNamespace(feature), absFeature);
}
} catch (final XmlException xmle) {
throw new EncodingException("Error while encoding GetFeatureOfInterest response, invalid samplingFeature description!", xmle);
}
}
final SFSpatialSamplingFeatureType xbSampFeature = xbSampFeatDoc.addNewSFSpatialSamplingFeature();
// TODO: CHECK for all fields set gml:id
addId(xbSampFeature, sampFeat);
addIdentifier(xbSampFeature, sampFeat);
// set type
addFeatureType(xbSampFeature, sampFeat);
// set type
addNameDescription(xbSampFeature, sampFeat);
setMetaDataProperty(xbSampFeature, sampFeat);
// set sampledFeatures
// TODO: CHECK
addSampledFeatures(xbSampFeature, sampFeat);
addParameter(xbSampFeature, sampFeat);
// set position
encodeShape(xbSampFeature.addNewShape(), sampFeat);
sampFeat.wasEncoded();
return xbSampFeatDoc;
}
throw new UnsupportedEncoderInputException(this, absFeature);
}
use of org.n52.svalbard.encode.exception.UnsupportedEncoderInputException in project arctic-sea by 52North.
the class SensorMLEncoderv101 method encode.
@Override
public XmlObject encode(final Object response, final EncodingContext additionalValues) throws EncodingException {
XmlObject encodedObject = null;
if (response instanceof AbstractSensorML) {
encodedObject = createSensorDescription((AbstractSensorML) response);
// }
// FIXME workaround? if of type UnknowProcedureType try to parse the
// description string, UNIT is missing "NOT_DEFINED"?!
// else if (response instanceof SosProcedureDescriptionUnknownType)
// {
// final String procDescXMLString = ((SosProcedureDescription)
// response).getXml();
// final AbstractSensorML sensorDesc = new AbstractSensorML();
// sensorDesc.setXml(procDescXMLString);
// encodedObject = createSensorDescriptionFromString(sensorDesc);
} else {
throw new UnsupportedEncoderInputException(this, response);
}
// check if all gml:id are unique
XmlHelper.makeGmlIdsUnique(encodedObject.getDomNode());
XmlHelper.validateDocument(encodedObject, EncodingException::new);
return encodedObject;
}
Aggregations