use of org.n52.shetland.ogc.swe.simpleType.SweQuantity in project arctic-sea by 52North.
the class SensorMLEncoderV101Test method should_encode_single_contact_person.
// @Test
// public void should_encode_features_of_interest() throws EncodingException {
// final SensorML sensorMl = new SensorML();
// final System system = new System();
// sensorMl.addMember(system);
// system.addFeatureOfInterest(TEST_ID_1);
// system.addFeatureOfInterest(TEST_ID_2);
// final SimpleDataRecordType xbSimpleDataRecord =
// encodeSimpleDataRecord(sensorMl, SensorMLConstants.ELEMENT_NAME_FEATURES_OF_INTEREST, 2);
// validateField(xbSimpleDataRecord.getFieldArray()[0], SensorMLConstants.FEATURE_OF_INTEREST_FIELD_NAME + 1,
// SensorMLConstants.FEATURE_OF_INTEREST_FIELD_DEFINITION, TEST_ID_1);
// validateField(xbSimpleDataRecord.getFieldArray()[1], SensorMLConstants.FEATURE_OF_INTEREST_FIELD_NAME + 2,
// SensorMLConstants.FEATURE_OF_INTEREST_FIELD_DEFINITION, TEST_ID_2);
// }
//
// @Test
// public void should_encode_offerings() throws EncodingException {
// final SensorML sensorMl = new SensorML();
// final System system = new System();
// sensorMl.addMember(system);
// system.addOffering(new SosOffering(TEST_ID_1, TEST_NAME_1));
// system.addOffering(new SosOffering(TEST_ID_2, TEST_NAME_2));
// final SimpleDataRecordType xbSimpleDataRecord =
// encodeSimpleDataRecord(sensorMl, SensorMLConstants.ELEMENT_NAME_OFFERINGS, 2);
// validateField(xbSimpleDataRecord.getFieldArray()[0], TEST_NAME_1, SensorMLConstants.OFFERING_FIELD_DEFINITION,
// TEST_ID_1);
// validateField(xbSimpleDataRecord.getFieldArray()[1], TEST_NAME_2, SensorMLConstants.OFFERING_FIELD_DEFINITION,
// TEST_ID_2);
// }
//
// @Test
// public void should_encode_parent_procedures() throws EncodingException {
// final SensorML sensorMl = new SensorML();
// final System system = new System();
// sensorMl.addMember(system);
// system.addParentProcedure(TEST_ID_1);
// system.addParentProcedure(TEST_ID_2);
// final SimpleDataRecordType xbSimpleDataRecord =
// encodeSimpleDataRecord(sensorMl, SensorMLConstants.ELEMENT_NAME_PARENT_PROCEDURES, 2);
// validateField(xbSimpleDataRecord.getFieldArray()[0], SensorMLConstants.PARENT_PROCEDURE_FIELD_NAME + 1,
// SensorMLConstants.PARENT_PROCEDURE_FIELD_DEFINITION, TEST_ID_1);
// validateField(xbSimpleDataRecord.getFieldArray()[1], SensorMLConstants.PARENT_PROCEDURE_FIELD_NAME + 2,
// SensorMLConstants.PARENT_PROCEDURE_FIELD_DEFINITION, TEST_ID_2);
// }
//
// @Test
// public void should_encode_child_procedures() throws EncodingException {
// final SensorML sensorMl = new SensorML();
// final System system = new System();
// sensorMl.addMember(system);
// final System childProcedure = new System();
// childProcedure.setIdentifier(TEST_CHILD_1);
// system.addChildProcedure(childProcedure);
// childProcedure.addFeatureOfInterest(TEST_ID_1);
// final SystemType xbSystemType = encodeSystem(sensorMl);
// assertThat(xbSystemType.getComponents().getComponentList().sizeOfComponentArray(), is(1));
// final Component xbComponent = xbSystemType.getComponents().getComponentList().getComponentArray(0);
// assertThat(xbComponent.getProcess(), instanceOf(SystemType.class));
// final SystemType xbComponentSystem = (SystemType) xbComponent.getProcess();
// final SimpleDataRecordType xbSimpleDataRecord =
// encodeSimpleDataRecord(xbComponentSystem, SensorMLConstants.ELEMENT_NAME_FEATURES_OF_INTEREST, 1);
// validateField(xbSimpleDataRecord.getFieldArray(0), SensorMLConstants.FEATURE_OF_INTEREST_FIELD_NAME,
// SensorMLConstants.FEATURE_OF_INTEREST_FIELD_DEFINITION, TEST_ID_1);
// }
//
// @Test
// @SuppressWarnings("unchecked")
// public void should_aggregate_child_outputs() throws EncodingException {
// final SweQuantity q1 = new SweQuantity();
// q1.setDefinition("def1");
// q1.setUom("uom1");
// final SmlIo<?> output1 = new SmlIo<SweQuantity>(q1);
//
// final SweQuantity q2 = new SweQuantity();
// q2.setDefinition("def2");
// q2.setUom("uom2");
// final SmlIo<?> output2 = new SmlIo<SweQuantity>(q2);
//
// final SweQuantity q3 = new SweQuantity();
// q3.setDefinition("def3");
// q3.setUom("uom3");
// final SmlIo<?> output3 = new SmlIo<SweQuantity>(q3);
//
// final SensorML sensorMl = new SensorML();
// sensorMl.setIdentifier("sensorMl");
// final System system = new System();
// system.setIdentifier("system");
// sensorMl.addMember(system);
// system.getOutputs().add(output1);
//
// final SensorML childSml = new SensorML();
// childSml.setIdentifier("childSml");
// final System childSystem = new System();
// childSystem.setIdentifier("childSystem");
// childSml.addMember(childSystem);
// system.addChildProcedure(childSml);
// childSystem.getOutputs().add(output2);
//
// final SensorML grandchildSml = new SensorML();
// grandchildSml.setIdentifier("grandchildSml");
// final System grandchildSystem = new System();
// grandchildSystem.setIdentifier("grandchildSystem");
// grandchildSml.addMember(grandchildSystem);
// childSystem.addChildProcedure(grandchildSml);
// grandchildSystem.getOutputs().add(output3);
//
// encodeSystem(sensorMl);
//
// assertThat(system.getOutputs(), hasItems(output1, output2, output3));
// assertThat(childSystem.getOutputs(), hasItems(output2, output3));
// assertThat(grandchildSystem.getOutputs(), hasItem(output3));
// }
@Test
public void should_encode_single_contact_person() throws EncodingException {
final SensorML sensorML = new SensorML();
final System system = new System();
sensorML.addMember(system);
final SmlPerson contact = createPerson("");
system.addContact(contact);
final SystemType xbSystem = encodeSystem(sensorML);
assertThat(xbSystem.sizeOfContactArray(), is(1));
assertThat(xbSystem.getContactArray(0).getContactList().getMemberArray(0).isSetPerson(), is(true));
checkPerson(contact, xbSystem.getContactArray(0).getContactList().getMemberArray(0).getPerson());
}
use of org.n52.shetland.ogc.swe.simpleType.SweQuantity in project arctic-sea by 52North.
the class SweCommonEncoderv101Test method should_encode_simpleDatarecord_with_quantities.
@Test
public void should_encode_simpleDatarecord_with_quantities() throws EncodingException {
final String name = "field-1";
final String unit = "m";
final Double value = 1.1;
final String name2 = "field-2";
final String unit2 = "urn:ogc:def:uom:UCUM::m";
final Double value2 = 1.2;
final XmlObject encode = sweCommonEncoderv101.encode(new SweSimpleDataRecord().addField(new SweField(name, new SweQuantity().setUom(unit).setValue(value))).addField(new SweField(name2, new SweQuantity().setUom(unit2).setValue(value2))));
assertThat(encode, instanceOf(SimpleDataRecordType.class));
final SimpleDataRecordType xbSimpleDataRecord = (SimpleDataRecordType) encode;
assertThat(xbSimpleDataRecord.getFieldArray().length, is(2));
final AnyScalarPropertyType field1 = xbSimpleDataRecord.getFieldArray(0);
final AnyScalarPropertyType field2 = xbSimpleDataRecord.getFieldArray(1);
// unit in code
assertThat(field1.getName(), is(name));
assertThat(field1.isSetQuantity(), is(TRUE));
assertThat(field1.getQuantity().getValue(), is(value));
assertThat(field1.getQuantity().getUom().getCode(), is(unit));
// unit in href
assertThat(field2.getName(), is(name2));
assertThat(field2.isSetQuantity(), is(TRUE));
assertThat(field2.getQuantity().getValue(), is(value2));
assertThat(field2.getQuantity().getUom().getHref(), is(unit2));
}
use of org.n52.shetland.ogc.swe.simpleType.SweQuantity in project arctic-sea by 52North.
the class SweCommonEncoderv101Test method should_encode_simpleDatarecord_with_fieldQuantity.
@Test
public void should_encode_simpleDatarecord_with_fieldQuantity() throws EncodingException {
final String name = "field-1";
final double value = 42.5;
final XmlObject encode = sweCommonEncoderv101.encode(new SweSimpleDataRecord().addField(new SweField(name, new SweQuantity().setValue(value))));
assertThat(encode, instanceOf(SimpleDataRecordType.class));
final SimpleDataRecordType xbSimpleDataRecord = (SimpleDataRecordType) encode;
final AnyScalarPropertyType field1 = xbSimpleDataRecord.getFieldArray(0);
assertThat(xbSimpleDataRecord.getFieldArray().length, is(1));
assertThat(field1.getName(), is(name));
assertThat(field1.isSetQuantity(), is(TRUE));
assertThat(field1.getQuantity().getValue(), is(value));
}
use of org.n52.shetland.ogc.swe.simpleType.SweQuantity 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.shetland.ogc.swe.simpleType.SweQuantity in project arctic-sea by 52North.
the class SweCommonEncoderv101 method createField.
private DataComponentPropertyType createField(SweField sweField) throws EncodingException {
SweAbstractDataComponent sosElement = sweField.getElement();
DataComponentPropertyType xbField = DataComponentPropertyType.Factory.newInstance(getXmlOptions());
if (sweField.isSetName()) {
xbField.setName(sweField.getName().getValue());
}
if (sosElement instanceof SweBoolean) {
xbField.addNewBoolean().set(createSimpleType((SweBoolean) sosElement));
} else if (sosElement instanceof SweCategory) {
xbField.addNewCategory().set(createSimpleType((SweCategory) sosElement));
} else if (sosElement instanceof SweCount) {
xbField.addNewCount().set(createSimpleType((SweCount) sosElement));
} else if (sosElement instanceof SweCountRange) {
xbField.addNewCount().set(createSimpleType((SweCountRange) sosElement));
} else if (sosElement instanceof SweQuantity) {
xbField.addNewQuantity().set(createSimpleType((SweQuantity) sosElement));
} else if (sosElement instanceof SweQuantityRange) {
xbField.addNewQuantity().set(createSimpleType((SweQuantityRange) sosElement));
} else if (sosElement instanceof SweText) {
xbField.addNewText().set(createSimpleType((SweText) sosElement));
} else if (sosElement instanceof SweTimeRange) {
xbField.addNewTimeRange().set(createSimpleType((SweTimeRange) sosElement));
} else if (sosElement instanceof SweTime) {
xbField.addNewTime().set(createSimpleType((SweTime) sosElement));
} else if (sosElement instanceof SweEnvelope) {
EnvelopeType xbEnvelope = (EnvelopeType) xbField.addNewAbstractDataRecord().substitute(SweConstants.QN_ENVELOPE_SWE_101, EnvelopeType.type);
xbEnvelope.set(createEnvelope((SweEnvelope) sosElement));
} else if (sosElement instanceof SweDataRecord) {
DataRecordType xbEnvelope = (DataRecordType) xbField.addNewAbstractDataRecord().substitute(SweConstants.QN_DATA_RECORD_SWE_101, DataRecordType.type);
xbEnvelope.set(createDataRecord((SweDataRecord) sosElement));
} else if (sosElement instanceof SweDataArray) {
DataArrayType xbEnvelope = (DataArrayType) xbField.addNewAbstractDataRecord().substitute(SweConstants.QN_DATA_RECORD_SWE_101, DataArrayType.type);
xbEnvelope.set(createDataArray((SweDataArray) sosElement).getDataArray1());
} 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