use of org.talend.components.marketo.runtime.client.MarketoRESTClient in project components by Talend.
the class MarketoSourceOrSink method getEndpointSchema.
@Override
public Schema getEndpointSchema(RuntimeContainer container, String schemaName) throws IOException {
MarketoRESTClient client = (MarketoRESTClient) getClientService(null);
TMarketoInputProperties ip = new TMarketoInputProperties("retrieveSchema");
Schema describeSchema = MarketoConstants.getCustomObjectDescribeSchema();
ip.connection = properties.getConnectionProperties();
ip.inputOperation.setValue(InputOperation.CustomObject);
ip.customObjectAction.setValue(CustomObjectAction.describe);
ip.customObjectName.setValue(schemaName);
ip.schemaInput.schema.setValue(describeSchema);
MarketoRecordResult r = client.describeCustomObject(ip);
if (!r.isSuccess()) {
return null;
}
List<IndexedRecord> records = r.getRecords();
if (records == null || records.isEmpty()) {
return null;
}
IndexedRecord record = records.get(0);
return FieldDescription.getSchemaFromJson(schemaName, record.get(describeSchema.getField("fields").pos()).toString(), record.get(describeSchema.getField("dedupeFields").pos()).toString());
}
use of org.talend.components.marketo.runtime.client.MarketoRESTClient in project components by Talend.
the class MarketoSourceOrSink method getDynamicSchema.
/**
* Retrieve schema for Leads or CustomObjects.
*
* @param the ObjectName to get schema. If blank, assumes it's for Lead fields. Otherwise ObjectName should be the
* CustomObject API's name.
*
* @return the schema for the given CustomObject or all Lead fields.
*/
public Schema getDynamicSchema(String objectName, Schema design) throws IOException {
List<Field> designFields = new ArrayList<>();
List<String> existingFieldNames = new ArrayList<>();
for (Field f : design.getFields()) {
existingFieldNames.add(f.name());
Field nf = new Field(f.name(), f.schema(), f.doc(), f.defaultVal());
nf.getObjectProps().putAll(f.getObjectProps());
for (Map.Entry<String, Object> entry : f.getObjectProps().entrySet()) {
nf.addProp(entry.getKey(), entry.getValue());
}
designFields.add(nf);
}
List<Field> objectFields;
List<Field> resultFields = new ArrayList<>();
resultFields.addAll(designFields);
// will fetch fields...
MarketoRESTClient client = (MarketoRESTClient) getClientService(null);
if (StringUtils.isEmpty(objectName)) {
objectFields = client.getAllLeadFields();
} else {
objectFields = getSchemaFieldsList(getEndpointSchema(null, objectName));
}
for (Field f : objectFields) {
// test if field isn't already in the schema
if (!existingFieldNames.contains(f.name())) {
resultFields.add(f);
}
}
Schema resultSchema = Schema.createRecord(design.getName(), design.getDoc(), design.getNamespace(), design.isError());
resultSchema.getObjectProps().putAll(design.getObjectProps());
resultSchema.setFields(resultFields);
return resultSchema;
}
use of org.talend.components.marketo.runtime.client.MarketoRESTClient in project components by Talend.
the class MarketoSourceOrSink method getCompoundKeyFields.
@Override
public List<String> getCompoundKeyFields(String resource) throws IOException {
MarketoRESTClient client = (MarketoRESTClient) getClientService(null);
TMarketoInputProperties ip = new TMarketoInputProperties("retrieveSchema");
Schema describeSchema = MarketoConstants.getCustomObjectDescribeSchema();
ip.connection = properties.getConnectionProperties();
ip.inputOperation.setValue(InputOperation.CustomObject);
ip.customObjectAction.setValue(CustomObjectAction.describe);
ip.customObjectName.setValue(resource);
ip.schemaInput.schema.setValue(describeSchema);
MarketoRecordResult r = client.describeCustomObject(ip);
if (!r.isSuccess()) {
return null;
}
List<IndexedRecord> records = r.getRecords();
if (records == null || records.isEmpty()) {
return null;
}
IndexedRecord record = records.get(0);
String[] keys = new Gson().fromJson(record.get(describeSchema.getField("dedupeFields").pos()).toString(), String[].class);
return Arrays.asList(keys);
}
Aggregations