use of org.openremote.model.value.ValueException in project openremote by openremote.
the class AssetResourceImpl method writeAttributeValue.
@Override
public void writeAttributeValue(RequestParams requestParams, String assetId, String attributeName, String rawJson) {
try {
try {
Value value = Values.instance().parse(rawJson).orElse(// When parsing literal JSON "null"
null);
AttributeEvent event = new AttributeEvent(new AttributeRef(assetId, attributeName), value, timerService.getCurrentTimeMillis());
// Process asynchronously but block for a little while waiting for the result
Map<String, Object> headers = new HashMap<>();
headers.put(AttributeEvent.HEADER_SOURCE, CLIENT);
headers.put(Constants.AUTH_CONTEXT, getAuthContext());
Object result = messageBrokerService.getProducerTemplate().requestBodyAndHeaders(AssetProcessingService.ASSET_QUEUE, event, headers);
if (result instanceof AssetProcessingException) {
AssetProcessingException processingException = (AssetProcessingException) result;
switch(processingException.getReason()) {
case ILLEGAL_SOURCE:
case NO_AUTH_CONTEXT:
case INSUFFICIENT_ACCESS:
throw new WebApplicationException(FORBIDDEN);
case ASSET_NOT_FOUND:
case ATTRIBUTE_NOT_FOUND:
throw new WebApplicationException(NOT_FOUND);
case INVALID_AGENT_LINK:
case ILLEGAL_AGENT_UPDATE:
case INVALID_ATTRIBUTE_EXECUTE_STATUS:
throw new IllegalStateException(processingException);
default:
throw processingException;
}
}
} catch (ValueException ex) {
throw new IllegalStateException("Error parsing JSON", ex);
}
} catch (IllegalStateException ex) {
throw new WebApplicationException(ex, BAD_REQUEST);
}
}
use of org.openremote.model.value.ValueException in project openremote by openremote.
the class JsonEditorImpl method parseValue.
protected Value parseValue() {
errorPanel.clear();
Value value = null;
String error = null;
try {
value = Values.parse(editor.getText()).orElse(null);
if (value == null)
error = managerMessages.emptyJsonData();
} catch (ValueException ex) {
error = ex.getMessage();
}
if (error != null) {
errorPanel.add(new IconLabel("warning"));
InlineLabel errorMessage = new InlineLabel(error);
errorPanel.add(errorMessage);
errorPanel.setVisible(true);
return null;
}
errorPanel.setVisible(false);
return value;
}
Aggregations