use of com.sforce.soap.partner.Field in project components by Talend.
the class SalesforceAvroRegistryStringTest method testPickListWithParent.
@Test
public void testPickListWithParent() throws Exception {
DescribeSObjectResult describeSObjectResult = new DescribeSObjectResult();
Field pickList = new Field();
pickList.setName("pickList");
pickList.setType(FieldType.picklist);
pickList.setCompoundFieldName("parent");
describeSObjectResult.setFields(new Field[] { pickList });
Schema schema = SalesforceAvroRegistryString.get().inferSchema(describeSObjectResult);
assertTrue(schema.getFields().isEmpty());
}
use of com.sforce.soap.partner.Field in project pentaho-kettle by pentaho.
the class SalesforceConnection method getFields.
/**
* Method returns names of the fields specified.<br>
* For the type='reference' it also returns name in the
* <code>format: objectReferenceTo:externalIdField/lookupField</code>
*
* @param fields
* fields
* @param excludeNonUpdatableFields
* the flag that indicates if non-updatable fields should be excluded or not
* @return fields' names
* @throws KettleException
*/
public String[] getFields(Field[] fields, boolean excludeNonUpdatableFields) throws KettleException {
if (fields != null) {
ArrayList<String> fieldsList = new ArrayList<String>(fields.length);
for (Field field : fields) {
// Add the name of the field - always
fieldsList.add(field.getName());
// Get the referenced to the field object and for this object get all its field to find possible idLookup fields
if (isReferenceField(field)) {
String referenceTo = field.getReferenceTo()[0];
Field[] referenceObjectFields = this.getObjectFields(referenceTo, excludeNonUpdatableFields);
for (Field f : referenceObjectFields) {
if (f.isIdLookup() && !isIdField(f)) {
fieldsList.add(String.format("%s:%s/%s", referenceTo, f.getName(), field.getRelationshipName()));
}
}
}
}
return fieldsList.toArray(new String[fieldsList.size()]);
}
return null;
}
use of com.sforce.soap.partner.Field in project pentaho-kettle by pentaho.
the class SalesforceInputDialog method get.
private void get() {
SalesforceConnection connection = null;
try {
SalesforceInputMeta meta = new SalesforceInputMeta();
getInfo(meta);
// Clear Fields Grid
wFields.removeAll();
// get real values
String realModule = transMeta.environmentSubstitute(meta.getModule());
String realURL = transMeta.environmentSubstitute(meta.getTargetURL());
String realUsername = transMeta.environmentSubstitute(meta.getUsername());
String realPassword = Utils.resolvePassword(transMeta, meta.getPassword());
int realTimeOut = Const.toInt(transMeta.environmentSubstitute(meta.getTimeout()), 0);
connection = new SalesforceConnection(log, realURL, realUsername, realPassword);
connection.setTimeOut(realTimeOut);
String[] fieldsName = null;
if (meta.isSpecifyQuery()) {
// Free hand SOQL
String realQuery = transMeta.environmentSubstitute(meta.getQuery());
connection.setSQL(realQuery);
connection.connect();
// We are connected, so let's query
XmlObject[] fields = connection.getElements();
int nrFields = fields.length;
Set<String> fieldNames = new HashSet<>();
for (int i = 0; i < nrFields; i++) {
addFields("", fieldNames, fields[i]);
}
fieldsName = fieldNames.toArray(new String[fieldNames.size()]);
} else {
connection.connect();
Field[] fields = connection.getObjectFields(realModule);
fieldsName = new String[fields.length];
for (int i = 0; i < fields.length; i++) {
Field field = fields[i];
fieldsName[i] = field.getName();
addField(field);
}
}
if (fieldsName != null) {
colinf[1].setComboValues(fieldsName);
}
wFields.removeEmptyRows();
wFields.setRowNums();
wFields.optWidth(true);
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "SalesforceInputMeta.ErrorRetrieveData.DialogTitle"), BaseMessages.getString(PKG, "SalesforceInputMeta.ErrorRetrieveData.DialogMessage"), e);
} catch (Exception e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "SalesforceInputMeta.ErrorRetrieveData.DialogTitle"), BaseMessages.getString(PKG, "SalesforceInputMeta.ErrorRetrieveData.DialogMessage"), e);
} finally {
if (connection != null) {
try {
connection.close();
} catch (Exception e) {
// Ignore errors
}
}
}
}
use of com.sforce.soap.partner.Field in project pentaho-kettle by pentaho.
the class SalesforceConnectionTest method getFieldsTest.
// PDI-16459
@Test
public void getFieldsTest() throws KettleException {
String name = "name";
SalesforceConnection conn = new SalesforceConnection(null, "http://localhost:1234", "aUser", "aPass");
Field[] fields = new Field[1];
Field field = new Field();
field.setRelationshipName("Parent");
field.setName(name);
fields[0] = field;
String[] names = conn.getFields(fields);
Assert.assertEquals(name, names[0]);
}
use of com.sforce.soap.partner.Field in project teiid by teiid.
the class SalesForceMetadataProcessor method addColumns.
private boolean addColumns(DescribeSObjectResult objectMetadata, Table table) {
boolean hasUpdateableColumn = false;
Field[] fields = objectMetadata.getFields();
for (Field field : fields) {
String normalizedName = field.getName();
if (normalizeNames) {
normalizedName = NameUtil.normalizeName(normalizedName);
}
FieldType fieldType = field.getType();
if (!isModelAuditFields() && isAuditField(field.getName())) {
continue;
}
String sfTypeName = fieldType.name();
Column column = null;
switch(fieldType) {
case string:
case combobox:
case reference:
case phone:
case id:
case url:
case email:
case encryptedstring:
case anyType:
column = metadataFactory.addColumn(normalizedName, DataTypeManager.DefaultDataTypes.STRING, table);
column.setNativeType(sfTypeName);
if (sfTypeName.equals(FieldType.id.name())) {
column.setNullType(NullType.No_Nulls);
ArrayList<String> columnNames = new ArrayList<String>();
columnNames.add(field.getName());
// $NON-NLS-1$
metadataFactory.addPrimaryKey(field.getName() + "_PK", columnNames, table);
}
break;
case picklist:
column = metadataFactory.addColumn(normalizedName, DataTypeManager.DefaultDataTypes.STRING, table);
if (field.isRestrictedPicklist()) {
// $NON-NLS-1$
column.setNativeType("restrictedpicklist");
} else {
column.setNativeType(sfTypeName);
}
column.setProperty(COLUMN_PICKLIST_VALUES, getPicklistValues(field));
break;
case multipicklist:
column = metadataFactory.addColumn(normalizedName, DataTypeManager.DefaultDataTypes.STRING, table);
if (field.isRestrictedPicklist()) {
// $NON-NLS-1$
column.setNativeType("restrictedmultiselectpicklist");
} else {
column.setNativeType(sfTypeName);
}
column.setProperty(COLUMN_PICKLIST_VALUES, getPicklistValues(field));
break;
case base64:
column = metadataFactory.addColumn(normalizedName, DataTypeManager.DefaultDataTypes.BLOB, table);
column.setNativeType(sfTypeName);
break;
case _boolean:
column = metadataFactory.addColumn(normalizedName, DataTypeManager.DefaultDataTypes.BOOLEAN, table);
column.setNativeType(sfTypeName);
break;
case currency:
column = metadataFactory.addColumn(normalizedName, DataTypeManager.DefaultDataTypes.DOUBLE, table);
column.setNativeType(sfTypeName);
column.setCurrency(true);
column.setScale(field.getScale());
column.setPrecision(field.getPrecision());
break;
case textarea:
column = metadataFactory.addColumn(normalizedName, DataTypeManager.DefaultDataTypes.STRING, table);
column.setNativeType(sfTypeName);
column.setSearchType(SearchType.Unsearchable);
break;
case _int:
column = metadataFactory.addColumn(normalizedName, DataTypeManager.DefaultDataTypes.INTEGER, table);
column.setNativeType(sfTypeName);
column.setPrecision(field.getPrecision());
break;
case _double:
case percent:
column = metadataFactory.addColumn(normalizedName, DataTypeManager.DefaultDataTypes.DOUBLE, table);
column.setNativeType(sfTypeName);
column.setScale(field.getScale());
column.setPrecision(field.getPrecision());
break;
case date:
column = metadataFactory.addColumn(normalizedName, DataTypeManager.DefaultDataTypes.DATE, table);
column.setNativeType(sfTypeName);
break;
case datetime:
column = metadataFactory.addColumn(normalizedName, DataTypeManager.DefaultDataTypes.TIMESTAMP, table);
column.setNativeType(sfTypeName);
break;
case time:
column = metadataFactory.addColumn(normalizedName, DataTypeManager.DefaultDataTypes.TIME, table);
column.setNativeType(sfTypeName);
break;
default:
if (sfTypeName.equals("address")) {
// $NON-NLS-1$
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Ignoring composite address field", normalizedName);
} else {
LogManager.logWarning(LogConstants.CTX_CONNECTOR, SalesForcePlugin.Util.gs(SalesForcePlugin.Event.TEIID13001, sfTypeName));
}
continue;
}
column.setNameInSource(field.getName());
column.setLength(field.getLength());
if (field.isUpdateable() || field.isCreateable()) {
column.setUpdatable(true);
hasUpdateableColumn = true;
}
column.setProperty(COLUMN_CALCULATED, String.valueOf(field.isCalculated()));
column.setProperty(COLUMN_CUSTOM, String.valueOf(field.isCustom()));
column.setProperty(COLUMN_DEFAULTED, String.valueOf(field.isDefaultedOnCreate()));
if (field.isDefaultedOnCreate()) {
// $NON-NLS-1$
column.setDefaultValue("sf default");
}
column.setNullType(field.isNillable() ? NullType.Nullable : NullType.No_Nulls);
}
return hasUpdateableColumn;
}
Aggregations