public PartnerConnection createBinding( ConnectorConfig config ) throws ConnectionException { if ( this.binding == null ) { this.binding = new PartnerConnection( config ); } return this.binding; }
private boolean isIdField( Field field ) { return field.getType() == ID_FIELD_TYPE ? true : false; }
/** * Method returns names of the fields specified. * @param fields fields * @return fields' names * @throws KettleException in case of error * @see #getObjectFields(String) */ public String[] getFields( Field[] fields ) throws KettleException { if ( fields != null ) { int nrFields = fields.length; String[] fieldsMapp = new String[nrFields]; for ( int i = 0; i < nrFields; i++ ) { Field field = fields[i]; fieldsMapp[i] = field.getName(); } return fieldsMapp; } return null; }
DescribeSObjectResult describeSObjectResult = getBinding().describeSObject( getModule() ); if ( describeSObjectResult == null ) { throw new KettleException( BaseMessages.getString( PKG, "SalesforceInput.ErrorGettingObject" ) ); if ( !describeSObjectResult.isQueryable() ) { throw new KettleException( BaseMessages.getString( PKG, "SalesforceInputDialog.ObjectNotQueryable", module ) ); if ( !describeSObjectResult.isReplicateable() ) { throw new KettleException( BaseMessages.getString( PKG, "SalesforceInput.Error.ObjectNotReplicateable", getModule() ) ); GetUpdatedResult updatedRecords = getBinding().getUpdated( getModule(), this.startDate, this.endDate ); if ( updatedRecords.getIds() != null ) { int nr = updatedRecords.getIds().length; if ( nr > 0 ) { String[] ids = updatedRecords.getIds(); int desPos = 0; for ( int i = 0; i < nr; i++ ) { list.add( updatedRecords.getIds()[i] ); getBinding().retrieve( this.fieldsList, getModule(), list.toArray( new String[list.size()] ) ); System.arraycopy( s, 0, this.sObjects, desPos, s.length ); this.sObjects = getBinding().retrieve( this.fieldsList, getModule(), ids );
private void addField( Field field ) { String fieldType = field.getType().toString(); String fieldLength = null; String fieldPrecision = null; if ( !fieldType.equals( "boolean" ) && !fieldType.equals( "datetime" ) && !fieldType.equals( "date" ) ) { fieldLength = Integer.toString( field.getLength() ); fieldPrecision = Integer.toString( field.getPrecision() ); } addFieldToTable( field.getLabel(), field.getName(), field.isIdLookup(), field.getType().toString(), fieldLength, fieldPrecision ); }
public boolean queryMore() throws KettleException { try { // check the done attribute on the QueryResult and call QueryMore // with the QueryLocator if there are more records to be retrieved if ( !getQueryResult().isDone() ) { this.qr = getBinding().queryMore( getQueryResult().getQueryLocator() ); this.sObjects = getQueryResult().getRecords(); if ( this.sObjects != null ) { this.recordsCount = this.sObjects.length; } this.queryResultSize = getQueryResult().getSize(); return true; } else { // Query is done .. we finished ! return false; } } catch ( Exception e ) { throw new KettleException( BaseMessages.getString( PKG, "SalesforceInput.Error.QueringMore" ), e ); } }
pConnection.setAllOrNoneHeader( true ); pConnection.login( config.getUsername(), Encr.decryptPasswordOptionallyEncrypted( config.getPassword() ) ); + " : " + this.loginResult.getSessionId() ); log.logDebug( BaseMessages.getString( PKG, "SalesforceInput.Log.NewServerURL" ) + " : " + this.loginResult.getServerUrl() ); pConnection.setSessionHeader( loginResult.getSessionId() ); config.setServiceEndpoint( loginResult.getServerUrl() ); this.userInfo = pConnection.getUserInfo(); if ( log.isDebug() ) { log.logDebug( BaseMessages.getString( PKG, "SalesforceInput.Log.UserInfos" ) + " : " + this.userInfo.getUserFullName() ); log.logDebug( "----------------------------------------->" ); log.logDebug( BaseMessages.getString( PKG, "SalesforceInput.Log.UserName" ) + " : " + this.userInfo.getUserFullName() ); log.logDebug( BaseMessages.getString( PKG, "SalesforceInput.Log.UserEmail" ) + " : " + this.userInfo.getUserEmail() ); log.logDebug( BaseMessages.getString( PKG, "SalesforceInput.Log.UserLanguage" ) + " : " + this.userInfo.getUserLanguage() ); log.logDebug( BaseMessages.getString( PKG, "SalesforceInput.Log.UserOrganization" ) + " : " + this.userInfo.getOrganizationName() ); log.logDebug( "<-----------------------------------------" ); this.serverTimestamp = pConnection.getServerTimestamp().getTimestamp().getTime(); if ( log.isDebug() ) { BaseMessages.getString( PKG, "SalesforceInput.Log.ServerTimestamp", getServerTimestamp() );
try { dgr = getBinding().describeGlobal(); sobjectResults = dgr.getSobjects(); int nrObjects = dgr.getSobjects().length; DescribeGlobalSObjectResult o = dgr.getSobjects()[i]; if ( ( OnlyQueryableObjects && o.isQueryable() ) || !OnlyQueryableObjects ) { objects.add( o.getName() );
int nr = data.deleteResult.length; for ( int j = 0; j < nr; j++ ) { if ( data.deleteResult[j].isSuccess() ) { com.sforce.soap.partner.Error err = data.deleteResult[j].getErrors()[0]; throw new KettleException( BaseMessages .getString( PKG, "SalesforceDelete.Error.FlushBuffer", new Integer( j ), err.getStatusCode(), err .getMessage() ) ); int nrErrors = data.deleteResult[j].getErrors().length; for ( int i = 0; i < nrErrors; i++ ) { com.sforce.soap.partner.Error err = data.deleteResult[j].getErrors()[i]; errorMessage += BaseMessages.getString( PKG, "SalesforceDelete.Error.FlushBuffer", new Integer( j ), err .getStatusCode(), err.getMessage() );
for ( Field field : fields ) { fieldsList.add( field.getName() ); String referenceTo = field.getReferenceTo()[0]; Field[] referenceObjectFields = this.getObjectFields( referenceTo, excludeNonUpdatableFields ); if ( f.isIdLookup() && !isIdField( f ) ) { fieldsList.add( String.format( "%s:%s/%s", referenceTo, f.getName(), field.getRelationshipName() ) );
public XmlObject[] getElements() throws Exception { // Query first this.qr = getBinding().query( getSQL() ); // and then return records SObject con = getQueryResult().getRecords()[0]; if ( con == null ) { return null; } return getChildren( con ); }
public Field[] getObjectFields( String objectName ) throws KettleException { DescribeSObjectResult describeSObjectResult = null; try { // Get object describeSObjectResult = getBinding().describeSObject( objectName ); if ( describeSObjectResult == null ) { return null; } if ( !describeSObjectResult.isQueryable() ) { throw new KettleException( BaseMessages.getString( PKG, "SalesforceInputDialog.ObjectNotQueryable", this.module ) ); } else { // we can query this object return describeSObjectResult.getFields(); } } catch ( Exception e ) { throw new KettleException( BaseMessages.getString( PKG, "SalesforceInput.Error.GettingModuleFields", this.module ), e ); } finally { if ( describeSObjectResult != null ) { describeSObjectResult = null; } } }
public void close() throws KettleException { try { if ( !getQueryResult().isDone() ) { this.qr.setDone( true ); this.qr = null; } if ( this.sObjects != null ) { this.sObjects = null; } if ( this.binding != null ) { this.binding = null; } if ( this.loginResult != null ) { this.loginResult = null; } if ( this.userInfo != null ) { this.userInfo = null; } if ( this.getDeletedList != null ) { getDeletedList.clear(); getDeletedList = null; } if ( log.isDetailed() ) { log.logDetailed( BaseMessages.getString( PKG, "SalesforceInput.Log.ConnectionClosed" ) ); } } catch ( Exception e ) { throw new KettleException( BaseMessages.getString( PKG, "SalesforceInput.Error.ClosingConnection" ), e ); } }
public SaveResult[] update( SObject[] sfBuffer ) throws KettleException { try { return getBinding().update( sfBuffer ); } catch ( Exception e ) { throw new KettleException( BaseMessages.getString( PKG, "SalesforceInput.ErrorUpdate", e ) ); } }
@SuppressWarnings( "unchecked" ) private String buildJsonQueryResult( QueryResult queryResult ) throws KettleException { JSONArray list = new JSONArray(); for ( SObject sobject : queryResult.getRecords() ) { list.add( buildJSONSObject( sobject ) ); } StringWriter sw = new StringWriter(); try { list.writeJSONString( sw ); } catch ( IOException e ) { throw new KettleException( e ); } return sw.toString(); }
public SaveResult[] insert( SObject[] sfBuffer ) throws KettleException { try { List<SObject> normalizedSfBuffer = new ArrayList<>(); for ( SObject part : sfBuffer ) { if ( part != null ) { normalizedSfBuffer.add( part ); } } return getBinding().create( normalizedSfBuffer.toArray( new SObject[normalizedSfBuffer.size()] ) ); } catch ( Exception e ) { throw new KettleException( BaseMessages.getString( PKG, "SalesforceInput.ErrorInsert", e ) ); } }
public DeleteResult[] delete( String[] id ) throws KettleException { try { return getBinding().delete( id ); } catch ( Exception e ) { throw new KettleException( BaseMessages.getString( PKG, "SalesforceInput.ErrorDelete", e ) ); } }
/**Returns only updatable object fields and ID field if <b>excludeNonUpdatableFields</b> is true, * otherwise all object field * @param objectName the name of Saleforce object * @param excludeNonUpdatableFields the flag that indicates if non-updatable fields should be excluded or not * @return the list of object fields depending on filter or not non-updatable fields. * @throws KettleException if any exception occurs */ public Field[] getObjectFields( String objectName, boolean excludeNonUpdatableFields ) throws KettleException { Field[] fieldList = getObjectFields( objectName ); if ( excludeNonUpdatableFields ) { ArrayList<Field> finalFieldList = new ArrayList<Field>(); for ( Field f : fieldList ) { // Leave out fields that can't be updated but if ( isIdField( f ) || !f.isCalculated() && f.isUpdateable() ) { finalFieldList.add( f ); } } fieldList = finalFieldList.toArray( new Field[finalFieldList.size()] ); } return fieldList; }
public UpsertResult[] upsert( String upsertField, SObject[] sfBuffer ) throws KettleException { try { return getBinding().upsert( upsertField, sfBuffer ); } catch ( Exception e ) { throw new KettleException( BaseMessages.getString( PKG, "SalesforceInput.ErrorUpsert", e ) ); } }
private boolean isReferenceField( Field field ) { return field.getType() == REFERENCE_FIELD_TYPE ? true : false; }