use of com.google.gson.internal.LinkedTreeMap in project components by Talend.
the class MarketoBaseRESTClientTest method testParseRecords.
@Test
public void testParseRecords() throws Exception {
Schema schema = //
SchemaBuilder.builder().record("test").fields().name("field1").type().nullable().stringType().noDefault().name("fields").type().nullable().stringType().noDefault().name("field2").type().nullable().intType().noDefault().name("field3").type().nullable().longType().noDefault().name("field4").type().nullable().booleanType().noDefault().name("field5").type().nullable().doubleType().noDefault().name("field6").type().nullable().floatType().noDefault().name(//
"field7").prop(SchemaConstants.TALEND_COLUMN_PATTERN, //
DATETIME_PATTERN_REST).prop(SchemaConstants.JAVA_CLASS_FLAG, //
Date.class.getCanonicalName()).type(AvroUtils._logicalTimestamp()).noDefault().name(//
"field8").prop(SchemaConstants.TALEND_COLUMN_PATTERN, //
DATETIME_PATTERN_REST).prop(SchemaConstants.JAVA_CLASS_FLAG, //
Date.class.getCanonicalName()).type(AvroUtils._logicalTimestamp()).noDefault().name("field9").type().nullType().noDefault().endRecord();
//
List<LinkedTreeMap> values = new ArrayList<>();
LinkedTreeMap map = new LinkedTreeMap();
map.put("field1", "value1");
map.put("fields", "{value1: 1223}");
map.put("field2", 12345);
map.put("field3", 1234567890L);
map.put("field4", true);
map.put("field5", 123456.5);
map.put("field6", 123456.5);
map.put("field7", new Date());
map.put("field8", new SimpleDateFormat(DATETIME_PATTERN_REST).format(new Date().getTime()));
map.put("field9", "nullType");
values.add(map);
//
assertEquals(Collections.emptyList(), client.parseRecords(values, null));
assertEquals(Collections.emptyList(), client.parseRecords(null, schema));
List<IndexedRecord> records = client.parseRecords(values, schema);
assertNotNull(records);
IndexedRecord record = records.get(0);
assertNotNull(record);
assertEquals("value1", record.get(0));
assertEquals("\"{value1: 1223}\"", record.get(1));
assertEquals(12345, record.get(2));
assertEquals(1234567890L, record.get(3));
assertEquals(true, record.get(4));
assertEquals(123456.5, record.get(5));
assertEquals((float) 123456.5, record.get(6));
assertEquals(null, record.get(7));
assertTrue(record.get(8) instanceof Long);
assertEquals("nullType", record.get(9));
}
use of com.google.gson.internal.LinkedTreeMap in project components by Talend.
the class MarketoBaseRESTClient method parseRecords.
public List<IndexedRecord> parseRecords(List<LinkedTreeMap> values, Schema schema) {
List<IndexedRecord> records = new ArrayList<>();
if (values == null || schema == null) {
return records;
}
for (LinkedTreeMap r : values) {
IndexedRecord record = new GenericData.Record(schema);
for (Field f : schema.getFields()) {
Object o = r.get(f.name());
record.put(f.pos(), getValueType(f, o));
}
records.add(record);
}
return records;
}
use of com.google.gson.internal.LinkedTreeMap in project components by Talend.
the class MarketoBaseRESTClient method executeGetRequest.
public MarketoRecordResult executeGetRequest(Schema schema) throws MarketoException {
try {
URL url = new URL(current_uri.toString());
HttpsURLConnection urlConn = (HttpsURLConnection) url.openConnection();
urlConn.setRequestMethod("GET");
urlConn.setDoOutput(true);
urlConn.setRequestProperty(REQUEST_PROPERTY_ACCEPT, REQUEST_VALUE_TEXT_JSON);
int responseCode = urlConn.getResponseCode();
if (responseCode == 200) {
InputStream inStream = urlConn.getInputStream();
Reader reader = new InputStreamReader(inStream);
Gson gson = new Gson();
MarketoRecordResult mkr = new MarketoRecordResult();
LinkedTreeMap ltm = (LinkedTreeMap) gson.fromJson(reader, Object.class);
mkr.setRequestId(REST + "::" + ltm.get("requestId"));
mkr.setSuccess(Boolean.parseBoolean(ltm.get("success").toString()));
mkr.setStreamPosition((String) ltm.get(FIELD_NEXT_PAGE_TOKEN));
if (!mkr.isSuccess() && ltm.get(FIELD_ERRORS) != null) {
List<LinkedTreeMap> errors = (List<LinkedTreeMap>) ltm.get(FIELD_ERRORS);
for (LinkedTreeMap err : errors) {
MarketoError error = new MarketoError(REST, (String) err.get("code"), (String) err.get("message"));
mkr.setErrors(Arrays.asList(error));
}
}
if (mkr.isSuccess()) {
List<LinkedTreeMap> tmp = (List<LinkedTreeMap>) ltm.get("result");
if (tmp != null) {
mkr.setRecordCount(tmp.size());
mkr.setRecords(parseRecords(tmp, schema));
}
if (mkr.getStreamPosition() != null) {
mkr.setRemainCount(mkr.getRecordCount());
}
}
return mkr;
} else {
LOG.error("GET request failed: {}", responseCode);
throw new MarketoException(REST, responseCode, "Request failed! Please check your request setting!");
}
} catch (IOException e) {
LOG.error("GET request failed: {}", e.getMessage());
throw new MarketoException(REST, e.getMessage());
}
}
use of com.google.gson.internal.LinkedTreeMap in project ballerina by ballerina-lang.
the class CommandExecutor method executeAddAllDocumentation.
/**
* Generate workspace edit for generating doc comments for all top level nodes and resources.
* @param context Workspace Service Context
*/
private static void executeAddAllDocumentation(WorkspaceServiceContext context) {
String documentUri = "";
VersionedTextDocumentIdentifier textDocumentIdentifier = new VersionedTextDocumentIdentifier();
for (Object arg : context.get(ExecuteCommandKeys.COMMAND_ARGUMENTS_KEY)) {
if (((LinkedTreeMap) arg).get(ARG_KEY).equals(CommandConstants.ARG_KEY_DOC_URI)) {
documentUri = (String) ((LinkedTreeMap) arg).get(ARG_VALUE);
textDocumentIdentifier.setUri(documentUri);
context.put(DocumentServiceKeys.FILE_URI_KEY, documentUri);
}
}
BLangPackage bLangPackage = TextDocumentServiceUtil.getBLangPackage(context, context.get(ExecuteCommandKeys.DOCUMENT_MANAGER_KEY), false, LSCustomErrorStrategy.class, false).get(0);
String fileContent = context.get(ExecuteCommandKeys.DOCUMENT_MANAGER_KEY).getFileContent(Paths.get(URI.create(documentUri)));
String[] contentComponents = fileContent.split(System.lineSeparator());
List<TextEdit> textEdits = new ArrayList<>();
bLangPackage.topLevelNodes.forEach(topLevelNode -> {
CommandUtil.DocAttachmentInfo docAttachmentInfo = getDocumentEditForNode(topLevelNode);
if (docAttachmentInfo != null) {
textEdits.add(getTextEdit(docAttachmentInfo, contentComponents));
}
if (topLevelNode instanceof BLangService) {
((BLangService) topLevelNode).getResources().forEach(bLangResource -> {
CommandUtil.DocAttachmentInfo resourceInfo = getDocumentEditForNode(bLangResource);
if (resourceInfo != null) {
textEdits.add(getTextEdit(resourceInfo, contentComponents));
}
});
}
});
TextDocumentEdit textDocumentEdit = new TextDocumentEdit(textDocumentIdentifier, textEdits);
applyWorkspaceEdit(Collections.singletonList(textDocumentEdit), context.get(ExecuteCommandKeys.LANGUAGE_SERVER_KEY).getClient());
}
use of com.google.gson.internal.LinkedTreeMap in project lite-apps by chimbori.
the class LiteAppsValidator method validateSettings.
private void validateSettings(String tag, File manifest) {
Gson gson = GsonInstance.getPrettyPrinter();
LinkedTreeMap<String, Object> json = null;
try {
// noinspection unchecked
json = (LinkedTreeMap<String, Object>) gson.fromJson(new FileReader(manifest), Object.class);
} catch (FileNotFoundException e) {
fail(e.getMessage());
}
// noinspection unchecked
LinkedTreeMap settings = (LinkedTreeMap<String, Object>) json.get("hermit_settings");
if (settings != null) {
for (Object key : settings.keySet()) {
assertTrue(String.format("Unexpected setting found: [%s] in [%s]", key, tag), SETTINGS_SET.contains(key));
}
}
}
Aggregations