Search in sources :

Example 1 with FieldType

use of com.salesforce.soap.partner.FieldType in project tdi-studio-se by Talend.

the class SObjectsToSchema method generateOutputTable.

public String generateOutputTable(String moduleName, DescribeSObjectResult descSObjectRslt, String operation) throws InvalidSObjectFault, UnexpectedErrorFault, RemoteException {
    StringBuffer content = new StringBuffer();
    content.append("<TABLE IF=\"");
    content.append("(MODULENAME=='" + moduleName + "') ");
    content.append("and (ACTION=='" + operation + "') ");
    content.append("and (PROPERTY=='BUILT_IN')\">");
    content.append("\r\n");
    // DescribeSObjectResult descSObjectRslt;
    // descSObjectRslt = binding.describeSObject(moduleName);
    Field[] fields = descSObjectRslt.getFields();
    if (fields != null) {
        for (Field field : fields) {
            if (!field.isCustom()) {
                String colName = field.getName();
                FieldType type = field.getType();
                String typeName = ConvertSFTypeToTOSType.getTOSValue(type.getValue());
                boolean readOnly = field.isNillable() == false && field.isAutoNumber() == false && field.isDefaultedOnCreate() == false;
                boolean nullable = field.isNillable();
                if (operation.equals(INSERT) && !field.isCreateable()) {
                    continue;
                }
                if (operation.equals(UPDATE) && !field.isUpdateable()) {
                    if (type.getValue().equals("id")) {
                        content.append(generateOutputColumn(colName.equals(KEY), colName, typeName, field.getLength(), true, false));
                    }
                    continue;
                }
                if (operation.equals(UPSERT) && !field.isCreateable() && !field.isUpdateable()) {
                    if (type.getValue().equals("id")) {
                        content.append(generateOutputColumn(colName.equals(KEY), colName, typeName, field.getLength(), true, false));
                    }
                    continue;
                }
                if (typeName.equals("id_Date")) {
                    String pattern = ConvertSFTypeToTOSType.getPattern(type.getValue());
                    if (pattern == null) {
                        System.out.println(moduleName + ":" + colName + " is not have pattern!");
                    }
                    content.append(generateOutputColumn(colName.equals(KEY), colName, typeName, pattern, field.getLength(), readOnly, nullable));
                } else {
                    content.append(generateOutputColumn(colName.equals(KEY), colName, typeName, field.getLength(), readOnly, nullable));
                }
            }
        }
    }
    content.append("</TABLE>");
    content.append("\r\n");
    return content.toString();
}
Also used : Field(com.salesforce.soap.partner.Field) FieldType(com.salesforce.soap.partner.FieldType)

Example 2 with FieldType

use of com.salesforce.soap.partner.FieldType in project tdi-studio-se by Talend.

the class SObjectsToSchema method generateInputTable.

private String generateInputTable(String moduleName, DescribeSObjectResult descSObjectRslt) throws InvalidSObjectFault, UnexpectedErrorFault, RemoteException {
    StringBuffer content = new StringBuffer();
    content.append("<TABLE IF=\"");
    content.append("MODULENAME=='" + moduleName + "' ");
    content.append("\">");
    content.append("\r\n");
    // DescribeSObjectResult descSObjectRslt;
    // descSObjectRslt = binding.describeSObject(moduleName);
    Field[] fields = descSObjectRslt.getFields();
    if (fields != null) {
        for (Field field : fields) {
            if (!field.isCustom()) {
                String colName = field.getName();
                FieldType type = field.getType();
                String typeName = ConvertSFTypeToTOSType.getTOSValue(type.getValue());
                if (typeName.equals("id_Date")) {
                    String pattern = ConvertSFTypeToTOSType.getPattern(type.getValue());
                    if (pattern == null) {
                        System.out.println(moduleName + ":" + colName + " is not have pattern!");
                    }
                    content.append(generateInputColumn(colName.equals(KEY), colName, typeName, pattern, field.getLength()));
                } else {
                    content.append(generateInputColumn(colName.equals(KEY), colName, typeName, field.getLength()));
                }
            }
        }
    }
    content.append("</TABLE>");
    content.append("\r\n");
    return content.toString();
}
Also used : Field(com.salesforce.soap.partner.Field) FieldType(com.salesforce.soap.partner.FieldType)

Example 3 with FieldType

use of com.salesforce.soap.partner.FieldType in project tdi-studio-se by Talend.

the class PartnerSamples method describeSample.

private void describeSample() {
    if (!loggedIn) {
        if (!login()) {
            return;
        }
    }
    String objectToDescribe = getUserInput("\nType the name of the object to describe (try Account): ");
    try {
        DescribeSObjectResult ds;
        DescribeSObjectResult describeSObjectResult = binding.describeSObject(objectToDescribe);
        if (!(describeSObjectResult == null)) {
            Field[] fields = describeSObjectResult.getFields();
            String objectName = describeSObjectResult.getName();
            boolean isActivateable = describeSObjectResult.isActivateable();
            boolean isCreateable = describeSObjectResult.isCreateable();
            boolean isCustom = describeSObjectResult.isCustom();
            boolean isDeleteable = describeSObjectResult.isDeletable();
            boolean isQueryable = describeSObjectResult.isQueryable();
            boolean isReplicateable = describeSObjectResult.isReplicateable();
            boolean isRetrieveable = describeSObjectResult.isRetrieveable();
            boolean isSearchable = describeSObjectResult.isSearchable();
            boolean isUndeleteable = describeSObjectResult.isUndeletable();
            boolean isUpdateable = describeSObjectResult.isUpdateable();
            System.out.println("Metadata for " + objectToDescribe + " object:\n");
            System.out.println("Object name                       = " + objectName);
            System.out.println("Number of fields                  = " + fields.length);
            System.out.println("Object can be activated           = " + isActivateable);
            System.out.println("Can create rows of data           = " + isCreateable);
            System.out.println("Object is custom object           = " + isCustom);
            System.out.println("Can delete rows of data           = " + isDeleteable);
            System.out.println("Can query for rows of data        = " + isQueryable);
            System.out.println("Object can be used in replication = " + isReplicateable);
            System.out.println("Can use retrieve method on object = " + isRetrieveable);
            System.out.println("Can use search method on object   = " + isSearchable);
            System.out.println("Can un-delete rows of data        = " + isUndeleteable);
            System.out.println("Can update rows of data           = " + isUpdateable);
            System.out.println("\nField metadata for " + objectToDescribe + " object:\n");
            if (!(fields == null)) {
                for (int i = 0; i < fields.length; i++) {
                    Field field = fields[i];
                    int byteLength = field.getByteLength();
                    int digits = field.getDigits();
                    String label = field.getLabel();
                    int length = field.getLength();
                    String name = field.getName();
                    PicklistEntry[] picklistValues = field.getPicklistValues();
                    int precision = field.getPrecision();
                    String[] referenceTos = field.getReferenceTo();
                    int scale = field.getScale();
                    FieldType fieldType = field.getType();
                    boolean fieldIsAutoNumber = field.isAutoNumber();
                    boolean fieldIsCreateable = field.isCreateable();
                    boolean fieldIsCustom = field.isCustom();
                    boolean fieldIsDefaultedOnCreate = field.isDefaultedOnCreate();
                    boolean fieldIsFilterable = field.isFilterable();
                    boolean fieldIsNillable = field.isNillable();
                    boolean fieldIsRestrictedPicklist = field.isRestrictedPicklist();
                    boolean fieldIsUpdateable = field.isUpdateable();
                    System.out.println("*************  New Field  ***************");
                    System.out.println("Name            = " + name);
                    System.out.println("Label           = " + label);
                    System.out.println("Length          = " + length);
                    System.out.println("Bytelength      = " + byteLength);
                    System.out.println("Digits          = " + digits);
                    System.out.println("Precision       = " + precision);
                    System.out.println("Scale           = " + scale);
                    System.out.println("Field type      = " + fieldType);
                    if (picklistValues != null) {
                        System.out.println("Picklist values = ");
                        for (int j = 0; j < picklistValues.length; j++) {
                            if (picklistValues[j].getLabel() != null) {
                                System.out.println("    Item:  " + picklistValues[j].getLabel());
                            } else {
                                System.out.println("    Item:  " + picklistValues[j].getValue());
                            }
                            System.out.println("        value           = " + picklistValues[j].getValue());
                            System.out.println("        is default      = " + picklistValues[j].isDefaultValue());
                        }
                    }
                    if (referenceTos != null) {
                        System.out.println("Field references the following objects:");
                        for (int j = 0; j < referenceTos.length; j++) {
                            System.out.println("    " + referenceTos[j]);
                        }
                    }
                    System.out.println("\n");
                }
                getUserInput("\nDescribe " + objectToDescribe + " was successful.\n\nHit the enter key to conutinue....");
            }
        }
    } catch (ApiFault af) {
        System.out.println("\nFailed to get " + objectToDescribe + " description, error message was: \n" + af.getExceptionMessage());
        getUserInput("\nHit return to continue...");
    } catch (Exception ex) {
        System.out.println("\nFailed to get " + objectToDescribe + " description, error message was: \n" + ex.getMessage());
        getUserInput("\nHit return to continue...");
    }
}
Also used : Field(com.salesforce.soap.partner.Field) DescribeSoftphoneLayoutInfoField(com.salesforce.soap.partner.DescribeSoftphoneLayoutInfoField) ApiFault(com.salesforce.soap.partner.fault.ApiFault) DescribeSObjectResult(com.salesforce.soap.partner.DescribeSObjectResult) PicklistEntry(com.salesforce.soap.partner.PicklistEntry) RemoteException(java.rmi.RemoteException) ServiceException(javax.xml.rpc.ServiceException) IOException(java.io.IOException) FieldType(com.salesforce.soap.partner.FieldType)

Example 4 with FieldType

use of com.salesforce.soap.partner.FieldType in project tdi-studio-se by Talend.

the class PartnerSamples method describeSObjectsSample.

private void describeSObjectsSample() {
    if (!loggedIn) {
        if (!login()) {
            return;
        }
    }
    try {
        DescribeSObjectResult[] describeSObjectResults = binding.describeSObjects(new String[] { "account", "contact", "lead" });
        for (int x = 0; x < describeSObjectResults.length; x++) {
            DescribeSObjectResult describeSObjectResult = describeSObjectResults[x];
            // Retrieve fields from the results
            Field[] fields = describeSObjectResult.getFields();
            // Get the name of the object
            String objectName = describeSObjectResult.getName();
            // Get some flags
            boolean isActivateable = describeSObjectResult.isActivateable();
            // Many other values are accessible
            if (fields != null) {
                // field
                for (int i = 0; i < fields.length; i++) {
                    Field field = fields[i];
                    int byteLength = field.getByteLength();
                    int digits = field.getDigits();
                    String label = field.getLabel();
                    int length = field.getLength();
                    String name = field.getName();
                    PicklistEntry[] picklistValues = field.getPicklistValues();
                    int precision = field.getPrecision();
                    String[] referenceTos = field.getReferenceTo();
                    int scale = field.getScale();
                    FieldType fieldType = field.getType();
                    boolean fieldIsCreateable = field.isCreateable();
                    // Determine whether there are picklist values
                    if (picklistValues != null && picklistValues[0] != null) {
                        System.out.println("Picklist values = ");
                        for (int j = 0; j < picklistValues.length; j++) {
                            if (picklistValues[j].getLabel() != null) {
                                System.out.println(" Item: " + picklistValues[j].getLabel());
                            }
                        }
                    }
                    // Determine whether this field refers to another object
                    if (referenceTos != null && referenceTos[0] != null) {
                        System.out.println("Field references the following objects:");
                        for (int j = 0; j < referenceTos.length; j++) {
                            System.out.println(" " + referenceTos[j]);
                        }
                    }
                }
            }
        }
        getUserInput("\nHit return to continue...");
    } catch (ApiFault af) {
        System.out.println("\nFailed to get describe multiple objects, error message was: \n" + af.getExceptionMessage());
        getUserInput("\nHit return to continue...");
    } catch (Exception ex) {
        System.out.println("\nFailed to get describe multiple objects, error message was: \n" + ex.getMessage());
        getUserInput("\nHit return to continue...");
    }
}
Also used : DescribeSObjectResult(com.salesforce.soap.partner.DescribeSObjectResult) RemoteException(java.rmi.RemoteException) ServiceException(javax.xml.rpc.ServiceException) IOException(java.io.IOException) FieldType(com.salesforce.soap.partner.FieldType) Field(com.salesforce.soap.partner.Field) DescribeSoftphoneLayoutInfoField(com.salesforce.soap.partner.DescribeSoftphoneLayoutInfoField) ApiFault(com.salesforce.soap.partner.fault.ApiFault) PicklistEntry(com.salesforce.soap.partner.PicklistEntry)

Aggregations

Field (com.salesforce.soap.partner.Field)4 FieldType (com.salesforce.soap.partner.FieldType)4 DescribeSObjectResult (com.salesforce.soap.partner.DescribeSObjectResult)2 DescribeSoftphoneLayoutInfoField (com.salesforce.soap.partner.DescribeSoftphoneLayoutInfoField)2 PicklistEntry (com.salesforce.soap.partner.PicklistEntry)2 ApiFault (com.salesforce.soap.partner.fault.ApiFault)2 IOException (java.io.IOException)2 RemoteException (java.rmi.RemoteException)2 ServiceException (javax.xml.rpc.ServiceException)2