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); } }
protected String calculateString( String packageName, String key, Object[] parameters, Class<?> resourceClass) { String string = null; // First try the standard locale, in the local package try { string = findString(packageName, langChoice.getDefaultLocale(), key, parameters, resourceClass); } catch (MissingResourceException e) { } ; if (string != null) return string; // Then try to find it in the i18n package, in the system messages of the preferred language. try { string = findString( SYSTEM_BUNDLE_PACKAGE, langChoice.getDefaultLocale(), key, parameters, resourceClass); } catch (MissingResourceException e) { } ; if (string != null) return string; // Then try the failover locale, in the local package try { string = findString(packageName, langChoice.getFailoverLocale(), key, parameters, resourceClass); } catch (MissingResourceException e) { } ; if (string != null) return string; // Then try to find it in the i18n package, in the system messages of the failover language. try { string = findString( SYSTEM_BUNDLE_PACKAGE, langChoice.getFailoverLocale(), key, parameters, resourceClass); } catch (MissingResourceException e) { } ; if (string != null) return string; string = "!" + key + "!"; String message = "Message not found in the preferred and failover locale: key=[" + key + "], package=" + packageName; log.logDetailed(Const.getStackTracker(new KettleException(message))); return string; }
/** Construct a new Salesforce Connection */ public SalesforceConnection( LogChannelInterface logInterface, String url, String username, String password) throws KettleException { this.log = logInterface; this.url = url; setUsername(username); setPassword(password); setTimeOut(0); this.binding = null; this.loginResult = null; this.userInfo = null; this.sql = null; this.serverTimestamp = null; this.qr = null; this.condition = null; this.startDate = null; this.endDate = null; this.sObjects = null; this.recordsFilter = SalesforceConnectionUtils.RECORDS_FILTER_ALL; this.fieldsList = null; this.queryResultSize = 0; this.recordsCount = 0; setUsingCompression(false); rollbackAllChangesOnError(false); // check target URL if (Const.isEmpty(getURL())) { throw new KettleException( BaseMessages.getString(PKG, "SalesforceInput.TargetURLMissing.Error")); } // check username if (Const.isEmpty(getUsername())) { throw new KettleException( BaseMessages.getString(PKG, "SalesforceInput.UsernameMissing.Error")); } if (log.isDetailed()) { logInterface.logDetailed(BaseMessages.getString(PKG, "SalesforceInput.Log.NewConnection")); } }
public void query(boolean specifyQuery) throws KettleException { if (getBinding() == null) { throw new KettleException( BaseMessages.getString(PKG, "SalesforceInput.Exception.CanNotGetBiding")); } try { if (!specifyQuery) { // check if we can query this Object 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 (this.recordsFilter == SalesforceConnectionUtils.RECORDS_FILTER_UPDATED || this.recordsFilter == SalesforceConnectionUtils.RECORDS_FILTER_DELETED) { // The object must be replicateable if (!describeSObjectResult.isReplicateable()) { throw new KettleException( BaseMessages.getString( PKG, "SalesforceInput.Error.ObjectNotReplicateable", getModule())); } } } if (getSQL() != null && log.isDetailed()) { log.logDetailed( BaseMessages.getString(PKG, "SalesforceInput.Log.SQLString") + " : " + getSQL()); } switch (this.recordsFilter) { case SalesforceConnectionUtils.RECORDS_FILTER_UPDATED: // Updated records ... 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(); // We can pass a maximum of 2000 object IDs if (nr > SalesforceConnectionUtils.MAX_UPDATED_OBJECTS_IDS) { this.sObjects = new SObject[nr]; List<String> list = new ArrayList<String>(); int desPos = 0; for (int i = 0; i < nr; i++) { list.add(updatedRecords.getIds(i)); if (i % SalesforceConnectionUtils.MAX_UPDATED_OBJECTS_IDS == 0 || i == nr - 1) { SObject[] s = getBinding() .retrieve( this.fieldsList, getModule(), list.toArray(new String[list.size()])); System.arraycopy(s, 0, this.sObjects, desPos, s.length); desPos += s.length; s = null; list = new ArrayList<String>(); } } } else { this.sObjects = getBinding().retrieve(this.fieldsList, getModule(), ids); } if (this.sObjects != null) { this.queryResultSize = this.sObjects.length; } } } break; case SalesforceConnectionUtils.RECORDS_FILTER_DELETED: // Deleted records ... GetDeletedResult deletedRecordsResult = getBinding().getDeleted(getModule(), this.startDate, this.endDate); DeletedRecord[] deletedRecords = deletedRecordsResult.getDeletedRecords(); if (log.isDebug()) { log.logDebug( toString(), BaseMessages.getString( PKG, "SalesforceConnection.DeletedRecordsFound", String.valueOf(deletedRecords == null ? 0 : deletedRecords.length))); } if (deletedRecords != null && deletedRecords.length > 0) { getDeletedList = new HashMap<String, Date>(); for (DeletedRecord dr : deletedRecords) { getDeletedList.put(dr.getId(), dr.getDeletedDate().getTime()); } this.qr = getBinding().queryAll(getSQL()); this.sObjects = getQueryResult().getRecords(); if (this.sObjects != null) { this.queryResultSize = this.sObjects.length; } } break; default: // return query result this.qr = isQueryAll() ? getBinding().queryAll(getSQL()) : getBinding().query(getSQL()); this.sObjects = getQueryResult().getRecords(); this.queryResultSize = getQueryResult().getSize(); break; } if (this.sObjects != null) { this.recordsCount = this.sObjects.length; } } catch (Exception e) { log.logError(Const.getStackTracker(e)); throw new KettleException( BaseMessages.getString(PKG, "SalesforceConnection.Exception.Query"), e); } }
public void connect() throws KettleException { try { this.binding = (SoapBindingStub) new SforceServiceLocator().getSoap(); if (log.isDetailed()) { log.logDetailed( BaseMessages.getString( PKG, "SalesforceInput.Log.LoginURL", binding._getProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY))); } // Set timeout if (getTimeOut() > 0) { this.binding.setTimeout(getTimeOut()); if (log.isDebug()) { log.logDebug( BaseMessages.getString(PKG, "SalesforceInput.Log.SettingTimeout", "" + this.timeout)); } } // Set URL this.binding._setProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY, getURL()); // Do we need compression? if (isUsingCompression()) { this.binding._setProperty(HTTPConstants.MC_ACCEPT_GZIP, useCompression); this.binding._setProperty(HTTPConstants.MC_GZIP_REQUEST, useCompression); } if (isRollbackAllChangesOnError()) { // Set the SOAP header to rollback all changes // unless all records are processed successfully. AllOrNoneHeader allOrNoneHeader = new AllOrNoneHeader(); allOrNoneHeader.setAllOrNone(true); this.binding.setHeader( new SforceServiceLocator().getServiceName().getNamespaceURI(), "AllOrNoneHeader", allOrNoneHeader); } // Attempt the login giving the user feedback if (log.isDetailed()) { log.logDetailed(BaseMessages.getString(PKG, "SalesforceInput.Log.LoginNow")); log.logDetailed("----------------------------------------->"); log.logDetailed(BaseMessages.getString(PKG, "SalesforceInput.Log.LoginURL", getURL())); log.logDetailed( BaseMessages.getString(PKG, "SalesforceInput.Log.LoginUsername", getUsername())); if (getModule() != null) { log.logDetailed( BaseMessages.getString(PKG, "SalesforceInput.Log.LoginModule", getModule())); } if (getCondition() != null) { log.logDetailed( BaseMessages.getString(PKG, "SalesforceInput.Log.LoginCondition", getCondition())); } log.logDetailed("<-----------------------------------------"); } // Login this.loginResult = getBinding().login(getUsername(), getPassword()); if (log.isDebug()) { log.logDebug( BaseMessages.getString(PKG, "SalesforceInput.Log.SessionId") + " : " + this.loginResult.getSessionId()); log.logDebug( BaseMessages.getString(PKG, "SalesforceInput.Log.NewServerURL") + " : " + this.loginResult.getServerUrl()); } // set the session header for subsequent call authentication this.binding._setProperty( SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY, this.loginResult.getServerUrl()); // Create a new session header object and set the session id to that // returned by the login SessionHeader sh = new SessionHeader(); sh.setSessionId(loginResult.getSessionId()); this.binding.setHeader( new SforceServiceLocator().getServiceName().getNamespaceURI(), "SessionHeader", sh); // Return the user Infos this.userInfo = this.binding.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 = getBinding().getServerTimestamp().getTimestamp().getTime(); if (log.isDebug()) { BaseMessages.getString(PKG, "SalesforceInput.Log.ServerTimestamp", getServerTimestamp()); } if (log.isDetailed()) { log.logDetailed(BaseMessages.getString(PKG, "SalesforceInput.Log.Connected")); } } catch (LoginFault ex) { // The LoginFault derives from AxisFault ExceptionCode exCode = ex.getExceptionCode(); if (exCode == ExceptionCode.FUNCTIONALITY_NOT_ENABLED || exCode == ExceptionCode.INVALID_CLIENT || exCode == ExceptionCode.INVALID_LOGIN || exCode == ExceptionCode.LOGIN_DURING_RESTRICTED_DOMAIN || exCode == ExceptionCode.LOGIN_DURING_RESTRICTED_TIME || exCode == ExceptionCode.ORG_LOCKED || exCode == ExceptionCode.PASSWORD_LOCKOUT || exCode == ExceptionCode.SERVER_UNAVAILABLE || exCode == ExceptionCode.TRIAL_EXPIRED || exCode == ExceptionCode.UNSUPPORTED_CLIENT) { throw new KettleException( BaseMessages.getString(PKG, "SalesforceInput.Error.InvalidUsernameOrPassword")); } throw new KettleException( BaseMessages.getString(PKG, "SalesforceInput.Error.Connection"), ex); } catch (Exception e) { throw new KettleException(BaseMessages.getString(PKG, "SalesforceInput.Error.Connection"), e); } }