use of org.n52.shetland.ogc.swe.SweAbstractDataComponent in project arctic-sea by 52North.
the class SweCommonEncoderv20 method createField.
private DataRecordType.Field createField(SweField field) throws EncodingException {
SweAbstractDataComponent element = field.getElement();
DataRecordType.Field xmlField = DataRecordType.Field.Factory.newInstance(getXmlOptions());
if (field.isSetName()) {
xmlField.setName(NcName.makeValid(field.getName().getValue()));
}
XmlObject encodeObjectToXml = createAbstractDataComponent(element, EncodingContext.empty());
XmlObject substituteElement = XmlHelper.substituteElement(xmlField.addNewAbstractDataComponent(), encodeObjectToXml);
substituteElement.set(encodeObjectToXml);
return xmlField;
}
use of org.n52.shetland.ogc.swe.SweAbstractDataComponent in project arctic-sea by 52North.
the class SweCommonEncoderv101Test method should_throw_NoApplicableCodeException_with_DataRecord_and_field_with_not_supported_element.
@Test
public void should_throw_NoApplicableCodeException_with_DataRecord_and_field_with_not_supported_element() throws EncodingException {
thrown.expect(EncodingException.class);
thrown.expectMessage("The element type '" + getClass().getName() + "$1' " + "of the received '" + SweField.class.getName() + "' is not supported" + " by this encoder '" + SweCommonEncoderv101.class.getName() + "'.");
sweCommonEncoderv101.encode(new SweDataRecord().addField(new SweField("test", new SweAbstractDataComponent() {
@Override
public SweDataComponentType getDataComponentType() {
return null;
}
@Override
public <T, X extends Throwable> T accept(SweDataComponentVisitor<T, X> visitor) {
return null;
}
@Override
public <X extends Throwable> void accept(VoidSweDataComponentVisitor<X> visitor) {
}
@Override
public SweAbstractDataComponent copy() {
return null;
}
})));
}
use of org.n52.shetland.ogc.swe.SweAbstractDataComponent in project arctic-sea by 52North.
the class SweHelper method createBlock.
@SuppressFBWarnings("BC_VACUOUS_INSTANCEOF")
private List<String> createBlock(SweAbstractDataComponent elementType, Time phenomenonTime, String phenID, Value<?> value) {
if (elementType instanceof SweDataRecord) {
SweDataRecord elementTypeRecord = (SweDataRecord) elementType;
List<String> block = new ArrayList<>(elementTypeRecord.getFields().size());
if (!(value instanceof NilTemplateValue)) {
elementTypeRecord.getFields().forEach(field -> {
if (field.getElement() instanceof SweTime || field.getElement() instanceof SweTimeRange) {
block.add(DateTimeHelper.format(phenomenonTime));
} else if (field.getElement() instanceof SweAbstractDataComponent && field.getElement().getDefinition().equals(phenID)) {
block.add(value.getValue().toString());
} else if (field.getElement() instanceof SweObservableProperty) {
block.add(phenID);
}
});
}
return block;
}
String exceptionMsg = String.format("Type of ElementType is not supported: %s", elementType != null ? elementType.getClass().getName() : "null");
LOGGER.debug(exceptionMsg);
throw new IllegalArgumentException(exceptionMsg);
}
use of org.n52.shetland.ogc.swe.SweAbstractDataComponent in project arctic-sea by 52North.
the class SweHelper method createElementType.
private SweAbstractDataComponent createElementType(SingleObservationValue<?> sov, String name) throws EncodingException {
SweDataRecord dataRecord = new SweDataRecord();
dataRecord.addField(getPhenomenonTimeField(sov.getPhenomenonTime()));
dataRecord.addField(getFieldForValue(sov.getValue(), name));
return dataRecord;
}
use of org.n52.shetland.ogc.swe.SweAbstractDataComponent in project arctic-sea by 52North.
the class FieldDecoder method decodeTime.
protected SweAbstractDataComponent decodeTime(JsonNode node) throws DecodingException {
SweTime swe = new SweTime();
if (node.hasNonNull(JSONConstants.VALUE)) {
String value = node.path(JSONConstants.VALUE).textValue();
swe.setValue(parseDateTime(value));
}
return swe.setUom(node.path(JSONConstants.UOM).textValue());
}
Aggregations