public BeanInjectionInfo(Class<?> clazz) {
    LOG.logDebug("Collect bean injection info for " + clazz);
    try {
      this.clazz = clazz;
      clazzAnnotation = clazz.getAnnotation(InjectionSupported.class);
      if (clazzAnnotation == null) {
        throw new RuntimeException("Injection not supported in " + clazz);
      }

      Group gr0 = new Group("");
      groupsList.add(gr0);
      groupsMap.put(gr0.getName(), gr0);
      for (String group : clazzAnnotation.groups()) {
        Group gr = new Group(group);
        groupsList.add(gr);
        groupsMap.put(gr.getName(), gr);
      }

      BeanLevelInfo root = new BeanLevelInfo();
      root.leafClass = clazz;
      root.init(this);

      properties = Collections.unmodifiableMap(properties);
      groupsList = Collections.unmodifiableList(groupsList);
      groupsMap = null;
    } catch (Throwable ex) {
      LOG.logError(
          "Error bean injection info collection for " + clazz + ": " + ex.getMessage(), ex);
      throw ex;
    }
  }
Exemplo n.º 2
0
  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);
    }
  }
Exemplo n.º 3
0
  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);
    }
  }