Search in sources :

Example 6 with JSONException

use of com.amazonaws.util.json.JSONException in project amos-ss17-alexa by c-i-ber.

the class StandingOrderDialog method getStandingOrdersModifyResponse.

private SpeechletResponse getStandingOrdersModifyResponse(Intent intent, SessionStorage.Storage storage) {
    String standingOrderToModify = (String) storage.get("StandingOrderToModify");
    String newAmount = (String) storage.get("NewAmount");
    String newExecutionRate = (String) storage.get("NewExecutionRate");
    String newFirstExecution = (String) storage.get("NewFirstExecution");
    ObjectMapper mapper = new ObjectMapper();
    // Create the Simple card content.
    SimpleCard card = new SimpleCard();
    card.setTitle("Ändere Dauerauftrag");
    // Create the plain text output.
    PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
    JSONObject jsonObject = new JSONObject();
    try {
        //TODO
        jsonObject.put("payee", "Max Mustermann");
        jsonObject.put("amount", newAmount);
        jsonObject.put("destinationAccount", "DE39100000007777777777");
        jsonObject.put("firstExecution", "2017-06-01");
        jsonObject.put("executionRate", "MONTHLY");
        jsonObject.put("description", "Updated standing Order");
    } catch (JSONException e) {
        LOGGER.error(e.getMessage());
    }
    BankingRESTClient bankingRESTClient = BankingRESTClient.getInstance();
    bankingRESTClient.putBankingModelObject("/api/v1_0/accounts/9999999999/standingorders/" + standingOrderToModify, jsonObject.toString(), StandingOrder.class);
    card.setContent("Dauerauftrag Nummer " + standingOrderToModify + " wurde geändert.");
    speech.setText("Dauerauftrag Nummer " + standingOrderToModify + " wurde geaendert.");
    return SpeechletResponse.newTellResponse(speech, card);
}
Also used : JSONObject(com.amazonaws.util.json.JSONObject) SimpleCard(com.amazon.speech.ui.SimpleCard) JSONException(com.amazonaws.util.json.JSONException) PlainTextOutputSpeech(com.amazon.speech.ui.PlainTextOutputSpeech) BankingRESTClient(api.BankingRESTClient) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 7 with JSONException

use of com.amazonaws.util.json.JSONException in project nutch by apache.

the class CloudSearchIndexWriter method delete.

@Override
public void delete(String url) throws IOException {
    try {
        JSONObject doc_builder = new JSONObject();
        doc_builder.put("type", "delete");
        // generate the id from the url
        String ID = CloudSearchUtils.getID(url);
        doc_builder.put("id", ID);
        // add to the batch
        addToBatch(doc_builder.toString(2), url);
    } catch (JSONException e) {
        LOG.error("Exception caught while building JSON object", e);
    }
}
Also used : JSONObject(com.amazonaws.util.json.JSONObject) JSONException(com.amazonaws.util.json.JSONException)

Example 8 with JSONException

use of com.amazonaws.util.json.JSONException in project nutch by apache.

the class CloudSearchIndexWriter method write.

@Override
public void write(NutchDocument doc) throws IOException {
    try {
        JSONObject doc_builder = new JSONObject();
        doc_builder.put("type", "add");
        String url = doc.getField("url").toString();
        // generate the id from the url
        String ID = CloudSearchUtils.getID(url);
        doc_builder.put("id", ID);
        JSONObject fields = new JSONObject();
        for (final Entry<String, NutchField> e : doc) {
            String fieldname = cleanFieldName(e.getKey());
            String type = csfields.get(fieldname);
            // undefined in index
            if (!dumpBatchFilesToTemp && type == null) {
                LOG.info("Field {} not defined in CloudSearch domain for {} - skipping.", fieldname, url);
                continue;
            }
            List<Object> values = e.getValue().getValues();
            // write the values
            for (Object value : values) {
                // Convert dates to an integer
                if (value instanceof Date) {
                    Date d = (Date) value;
                    value = DATE_FORMAT.format(d);
                } else // normalise strings
                if (value instanceof String) {
                    value = CloudSearchUtils.stripNonCharCodepoints((String) value);
                }
                fields.accumulate(fieldname, value);
            }
        }
        doc_builder.put("fields", fields);
        addToBatch(doc_builder.toString(2), url);
    } catch (JSONException e) {
        LOG.error("Exception caught while building JSON object", e);
    }
}
Also used : JSONObject(com.amazonaws.util.json.JSONObject) NutchField(org.apache.nutch.indexer.NutchField) JSONException(com.amazonaws.util.json.JSONException) JSONObject(com.amazonaws.util.json.JSONObject) Date(java.util.Date)

Aggregations

JSONException (com.amazonaws.util.json.JSONException)8 JSONObject (com.amazonaws.util.json.JSONObject)8 BankingRESTClient (api.BankingRESTClient)3 JSONArray (com.amazonaws.util.json.JSONArray)2 IOException (java.io.IOException)2 PlainTextOutputSpeech (com.amazon.speech.ui.PlainTextOutputSpeech)1 SimpleCard (com.amazon.speech.ui.SimpleCard)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Date (java.util.Date)1 Map (java.util.Map)1 NutchField (org.apache.nutch.indexer.NutchField)1 ZeppelinhubMessage (org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.protocol.ZeppelinhubMessage)1 Message (org.apache.zeppelin.notebook.socket.Message)1 WebSocketClient (org.eclipse.jetty.websocket.client.WebSocketClient)1