Search in sources :

Example 1 with ValueException

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);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) ValueException(org.openremote.model.value.ValueException) Value(org.openremote.model.value.Value)

Example 2 with ValueException

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;
}
Also used : ValueException(org.openremote.model.value.ValueException) IconLabel(org.openremote.app.client.widget.IconLabel) Value(org.openremote.model.value.Value) InlineLabel(com.google.gwt.user.client.ui.InlineLabel)

Aggregations

Value (org.openremote.model.value.Value)2 ValueException (org.openremote.model.value.ValueException)2 InlineLabel (com.google.gwt.user.client.ui.InlineLabel)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 IconLabel (org.openremote.app.client.widget.IconLabel)1