use of org.n52.shetland.ogc.swe.SweField in project arctic-sea by 52North.
the class SweDataArrayValue method getPhenomenonTime.
@Override
public Time getPhenomenonTime() {
final TimePeriod timePeriod = new TimePeriod();
Set<Integer> dateTokenIndizes = Sets.newHashSet();
if (getValue() != null && getValue().getElementType() != null && getValue().getEncoding() != null) {
// get index of time token from elementtype
if (getValue().getElementType() instanceof SweDataRecord) {
final SweDataRecord elementType = (SweDataRecord) getValue().getElementType();
final List<SweField> fields = elementType.getFields();
for (int i = 0; i < fields.size(); i++) {
final SweField sweField = fields.get(i);
if (sweField.getElement() instanceof SweTime || sweField.getElement() instanceof SweTimeRange) {
if (checkFieldNameAndElementDefinition(sweField)) {
dateTokenIndizes.add(i);
}
}
}
}
if (CollectionHelper.isNotEmpty(dateTokenIndizes)) {
for (final List<String> block : getValue().getValues()) {
// datetimehelper to DateTime from joda time
for (Integer index : dateTokenIndizes) {
String token = null;
try {
token = block.get(index);
final Time time = DateTimeHelper.parseIsoString2DateTime2Time(token);
timePeriod.extendToContain(time);
} catch (final DateTimeParseException dte) {
LOGGER.error(String.format("Could not parse ISO8601 string \"%s\"", token), dte);
// try next block;
continue;
}
}
}
} else {
final String errorMsg = "PhenomenonTime field could not be found in ElementType";
LOGGER.error(errorMsg);
}
} else {
final String errorMsg = String.format("Value of type \"%s\" not set correct.", SweDataArrayValue.class.getName());
LOGGER.error(errorMsg);
}
return timePeriod;
}
use of org.n52.shetland.ogc.swe.SweField in project arctic-sea by 52North.
the class SweDataRecordTest method getFieldIndexByIdentifier_should_not_fail_on_bad_input.
@Test
public void getFieldIndexByIdentifier_should_not_fail_on_bad_input() {
final SweDataRecord dataRecord = new SweDataRecord();
dataRecord.addField(new SweField("identifier", new SweBoolean()));
final SweBoolean b = new SweBoolean();
b.setDefinition("test-element-definition");
dataRecord.addField(new SweField("test-field-name", b));
assertThat(dataRecord.getFieldIndexByIdentifier(null), is(-1));
assertThat(dataRecord.getFieldIndexByIdentifier(""), is(-1));
}
use of org.n52.shetland.ogc.swe.SweField in project arctic-sea by 52North.
the class SweHelper method getFieldForValue.
private SweField getFieldForValue(Value<?> iValue, String name) throws EncodingException {
SweAbstractDataComponent value = getValue(iValue);
value.setDefinition(name);
return new SweField(name, value);
}
use of org.n52.shetland.ogc.swe.SweField in project arctic-sea by 52North.
the class SweHelper method getPhenomenonTimeField.
private SweField getPhenomenonTimeField(Time sosTime) {
SweAbstractUomType<?> time;
if (sosTime instanceof TimePeriod) {
time = new SweTimeRange();
} else {
time = new SweTime();
}
time.setDefinition(OmConstants.PHENOMENON_TIME);
time.setUom(OmConstants.PHEN_UOM_ISO8601);
return new SweField(OmConstants.PHENOMENON_TIME_NAME, time);
}
use of org.n52.shetland.ogc.swe.SweField in project arctic-sea by 52North.
the class FieldDecoder method decodeJSON.
public SweField decodeJSON(JsonNode node) throws DecodingException {
final String type = node.path(JSONConstants.TYPE).textValue();
final SweAbstractDataComponent element;
if (type.equals(JSONConstants.BOOLEAN_TYPE)) {
element = decodeBoolean(node);
} else if (type.equals(JSONConstants.COUNT_TYPE)) {
element = decodeCount(node);
} else if (type.equals(JSONConstants.COUNT_RANGE_TYPE)) {
element = decodeCountRange(node);
} else if (type.equals(JSONConstants.OBSERVABLE_PROPERTY_TYPE)) {
element = decodeObservableProperty(node);
} else if (type.equals(JSONConstants.QUALITY_TYPE)) {
element = decodeQuality(node);
} else if (type.equals(JSONConstants.TEXT_TYPE)) {
element = decodeText(node);
} else if (type.equals(JSONConstants.QUANTITY_TYPE)) {
element = decodeQuantity(node);
} else if (type.equals(JSONConstants.QUANTITY_RANGE_TYPE)) {
element = decodeQuantityRange(node);
} else if (type.equals(JSONConstants.TIME_TYPE)) {
element = decodeTime(node);
} else if (type.equals(JSONConstants.TIME_RANGE_TYPE)) {
element = decodeTimeRange(node);
} else if (type.equals(JSONConstants.CATEGORY_TYPE)) {
element = decodeCategory(node);
} else {
throw new UnsupportedDecoderInputException(this, node);
}
final String name = node.path(JSONConstants.NAME).textValue();
element.setDescription(node.path(JSONConstants.DESCRIPTION).textValue());
element.setIdentifier(node.path(JSONConstants.IDENTIFIER).textValue());
element.setDefinition(node.path(JSONConstants.DEFINITION).textValue());
element.setLabel(node.path(JSONConstants.LABEL).textValue());
return new SweField(name, element);
}
Aggregations