use of org.n52.shetland.ogc.swe.simpleType.SweCategory in project arctic-sea by 52North.
the class FieldDecoderTest method testCategory.
@Test
public void testCategory() throws DecodingException {
ObjectNode json = createField().put(JSONConstants.TYPE, JSONConstants.CATEGORY_TYPE).put(JSONConstants.CODESPACE, CODESPACE);
SweField field = checkCommon(json, false);
assertThat(field.getElement(), is(instanceOf(SweCategory.class)));
SweCategory swe = (SweCategory) field.getElement();
errors.checkThat(swe.getValue(), is(nullValue()));
errors.checkThat(swe.getCodeSpace(), is(CODESPACE));
}
use of org.n52.shetland.ogc.swe.simpleType.SweCategory in project arctic-sea by 52North.
the class FieldEncoder method encodeSweCategoryField.
private ObjectNode encodeSweCategoryField(SweField field) {
ObjectNode jfield = createField(field);
jfield.put(JSONConstants.TYPE, JSONConstants.CATEGORY_TYPE);
SweCategory sweCategory = (SweCategory) field.getElement();
jfield.put(JSONConstants.CODESPACE, sweCategory.getCodeSpace());
if (sweCategory.isSetValue()) {
jfield.put(JSONConstants.VALUE, sweCategory.getValue());
}
return jfield;
}
use of org.n52.shetland.ogc.swe.simpleType.SweCategory in project arctic-sea by 52North.
the class ObservationEncoder method getFieldForValue.
private SweField getFieldForValue(String phenomenon, Value<?> value) throws EncodingException {
final SweAbstractDataComponent def;
if (value instanceof BooleanValue) {
def = new SweBoolean();
} else if (value instanceof CategoryValue) {
SweCategory sweCategory = new SweCategory();
CategoryValue categoryValue = (CategoryValue) value;
sweCategory.setCodeSpace(categoryValue.getUnit());
def = sweCategory;
} else if (value instanceof CountValue) {
def = new SweCount();
} else if (value instanceof QuantityValue) {
SweQuantity sweQuantity = new SweQuantity();
QuantityValue quantityValue = (QuantityValue) value;
sweQuantity.setUom(quantityValue.getUnit());
def = sweQuantity;
} else if (value instanceof TextValue) {
def = new SweText();
} else if (value instanceof NilTemplateValue) {
def = new SweText();
} else if (value instanceof BooleanValue) {
def = new SweBoolean();
} else if (value instanceof GeometryValue) {
def = new SweText();
} else {
throw new UnsupportedEncoderInputException(this, value);
}
def.setDefinition(phenomenon);
return new SweField(phenomenon, def);
}
use of org.n52.shetland.ogc.swe.simpleType.SweCategory in project arctic-sea by 52North.
the class SweCommonEncoderv101 method createQuality.
private QualityPropertyType[] createQuality(Collection<SweQuality> quality) {
if (!quality.isEmpty()) {
ArrayList<QualityPropertyType> xbQualities = Lists.newArrayListWithCapacity(quality.size());
for (SweQuality sweQuality : quality) {
QualityPropertyType xbQuality = QualityPropertyType.Factory.newInstance();
if (sweQuality instanceof SweText) {
xbQuality.addNewText().set(createText((SweText) sweQuality));
} else if (sweQuality instanceof SweCategory) {
xbQuality.addNewCategory().set(createCategory((SweCategory) sweQuality));
} else if (sweQuality instanceof SweQuantity) {
xbQuality.addNewQuantity().set(createQuantity((SweQuantity) sweQuality));
} else if (sweQuality instanceof SweQuantityRange) {
xbQuality.addNewQuantityRange().set(createQuantityRange((SweQuantityRange) sweQuality));
}
xbQualities.add(xbQuality);
}
return xbQualities.toArray(new QualityPropertyType[xbQualities.size()]);
}
return new QualityPropertyType[] { QualityPropertyType.Factory.newInstance() };
}
use of org.n52.shetland.ogc.swe.simpleType.SweCategory in project arctic-sea by 52North.
the class SweCommonEncoderv101 method createFieldForSimpleDataRecord.
private AnyScalarPropertyType createFieldForSimpleDataRecord(SweField sweField) throws EncodingException {
SweAbstractDataComponent sosElement = sweField.getElement();
AnyScalarPropertyType xbField = AnyScalarPropertyType.Factory.newInstance(getXmlOptions());
if (sweField.isSetName()) {
xbField.setName(sweField.getName().getValue());
}
AbstractDataComponentType xbDCD;
if (sosElement instanceof SweBoolean) {
xbDCD = xbField.addNewBoolean();
xbDCD.set(createSimpleType((SweBoolean) sosElement));
} else if (sosElement instanceof SweCategory) {
xbDCD = xbField.addNewCategory();
xbDCD.set(createSimpleType((SweCategory) sosElement));
} else if (sosElement instanceof SweCount) {
xbDCD = xbField.addNewCount();
xbDCD.set(createSimpleType((SweCount) sosElement));
} else if (sosElement instanceof SweQuantity) {
xbDCD = xbField.addNewQuantity();
xbDCD.set(createSimpleType((SweQuantity) sosElement));
} else if (sosElement instanceof SweText) {
xbDCD = xbField.addNewText();
xbDCD.set(createSimpleType((SweText) sosElement));
} else if (sosElement instanceof SweTime) {
xbDCD = xbField.addNewTime();
xbDCD.set(createSimpleType((SweTime) sosElement));
} else {
throw new EncodingException("The element type '%s' of the received %s is not supported by this encoder '%s'.", new Object[] { sosElement != null ? sosElement.getClass().getName() : null, sweField.getClass().getName(), getClass().getName() });
}
return xbField;
}
Aggregations