use of org.apache.sling.commons.json.JSONObject in project acs-aem-commons by Adobe-Consulting-Services.
the class TranscriptionServiceImpl method startTranscriptionJob.
@Override
public String startTranscriptionJob(InputStream stream, String mimeType) {
Request request = httpClientFactory.post("/speech-to-text/api/v1/recognitions?continuous=true×tamps=true").addHeader("Content-Type", mimeType).bodyStream(stream);
try {
JSONObject json = httpClientFactory.getExecutor().execute(request).handleResponse(HANDLER);
log.trace("content: {}", json.toString(2));
return json.getString("id");
} catch (Exception e) {
log.error("error submitting job", e);
return null;
}
}
use of org.apache.sling.commons.json.JSONObject in project acs-aem-commons by Adobe-Consulting-Services.
the class ChildrenAsPropertyResourceTest method testAdd_Unsorted.
@Test
public void testAdd_Unsorted() throws Exception {
valueMap.put("animals", unsortedJSON.toString());
ValueMap properties = new ValueMapDecorator(new HashMap<String, Object>());
properties.put("name", "hyena");
properties.put("sound", "lolz");
properties.put("jcr:primaryType", "nt:unstructured");
JSONObject expectedJSON = new JSONObject(unsortedJSON.toString());
expectedJSON.put("entry-4", new JSONObject(properties));
childrenAsPropertyResource = new ChildrenAsPropertyResource(resource, "animals");
childrenAsPropertyResource.create("entry-4", "nt:unstructured", properties);
childrenAsPropertyResource.persist();
String actual = resource.getValueMap().get("animals", String.class);
String expected = expectedJSON.toString();
Assert.assertEquals(expected, actual);
}
use of org.apache.sling.commons.json.JSONObject in project acs-aem-commons by Adobe-Consulting-Services.
the class ChildrenAsPropertyResourceTest method testAdd_Sorted.
@Test
public void testAdd_Sorted() throws Exception {
valueMap.put("animals", unsortedJSON.toString());
ValueMap properties = new ValueMapDecorator(new HashMap<String, Object>());
properties.put("name", "hyena");
properties.put("sound", "lolz");
properties.put("jcr:primaryType", "nt:unstructured");
JSONObject expectedJSON = new JSONObject(sortedJSON.toString());
expectedJSON.put("entry-4", new JSONObject(properties));
childrenAsPropertyResource = new ChildrenAsPropertyResource(resource, "animals", ChildrenAsPropertyResource.RESOURCE_NAME_COMPARATOR);
childrenAsPropertyResource.create("entry-4", "nt:unstructured", properties);
childrenAsPropertyResource.persist();
String actual = resource.getValueMap().get("animals", String.class);
String expected = expectedJSON.toString();
Assert.assertEquals(expected, actual);
}
use of org.apache.sling.commons.json.JSONObject in project acs-aem-commons by Adobe-Consulting-Services.
the class ChildrenAsPropertyResourceTest method setUp.
@Before
public void setUp() throws Exception {
valueMap = new ModifiableValueMapDecorator(new HashMap<String, Object>());
when(resource.getPath()).thenReturn("/content/test");
when(resource.getValueMap()).thenReturn(valueMap);
when(resource.adaptTo(ValueMap.class)).thenReturn(valueMap);
when(resource.adaptTo(ModifiableValueMap.class)).thenReturn(valueMap);
when(resource.getResourceResolver()).thenReturn(resourceResolver);
entry1.put("name", "dog");
entry1.put("sound", "woof");
entry1.put("jcr:primaryType", "nt:unstructured");
entry2.put("name", "cat");
entry2.put("sound", "meow");
entry1.put("jcr:primaryType", "nt:unstructured");
entry3.put("name", "fish");
entry3.put("sound", "...");
entry1.put("jcr:primaryType", "nt:unstructured");
entry100.put("name", "dog");
entry100.put("sound", "woof");
entry100.put("double", 20.002D);
entry100.put("long", 2000L);
entry100.put("bigdecimal", "10000.000001");
entry100.put("bigdecimal2", "20000.000002");
entry100.put("integer", 100);
entry100.put("integerAsLong", 100L);
entry100.put("integerAsDouble", 100D);
Calendar cal = Calendar.getInstance();
cal.set(2001, 1, 1, 1, 1, 1);
entry100.put("date", cal.getTime());
entry100.put("calendar", cal);
entry100.put("boolean", true);
entry100.put("booleanAsString", "true");
entry100.put("strArray", new String[] { "one", "two" });
entry1.put("jcr:primaryType", "nt:unstructured");
unsortedJSON.put("entry-2", new JSONObject(entry2));
unsortedJSON.put("entry-1", new JSONObject(entry1));
unsortedJSON.put("entry-3", new JSONObject(entry3));
sortedJSON.put("entry-1", new JSONObject(entry1));
sortedJSON.put("entry-2", new JSONObject(entry2));
sortedJSON.put("entry-3", new JSONObject(entry3));
}
use of org.apache.sling.commons.json.JSONObject in project acs-aem-commons by Adobe-Consulting-Services.
the class TypeUtilTest method testToMap_withType.
@Test
public void testToMap_withType() throws JSONException {
final JSONObject json = new JSONObject();
json.put("one", "uno");
json.put("two", 2);
json.put("three", "tres");
final Map<String, String> expResult = new HashMap<String, String>();
expResult.put("one", "uno");
expResult.put("three", "tres");
final Map<String, String> actual = TypeUtil.toMap(json, String.class);
assertEquals(expResult, actual);
}
Aggregations