def get_salesforce_suds_client(id):
    """Returns an authenticated suds client for the named Salesforce webservice."""
    auth_settings = get_webservice_settings('auth')
    settings = get_webservice_settings(id)
    login = settings.login or auth_settings.login
    password = (settings.password or auth_settings.password or '') + (settings.token or auth_settings.token or '')

    # log in via the auth service
    auth_client = get_suds_client(get_wsdl_uri(auth_settings.wsdl))
    auth_client.set_options(
        timeout = SOCKET_TIMEOUT,
        location = auth_settings.endpoint,
        )
    res = None
    try:
        res = auth_client.service.login(login, password)
    except WebFault:
        logger.exception('Unable to log in to Salesforce.')

    # connect to the service
    client = get_suds_client(get_wsdl_uri(settings.wsdl))
    token = client.factory.create('SessionHeader')
    if res is not None:
        token.sessionId = res.sessionId
    client.set_options(
        timeout = SOCKET_TIMEOUT,
        location = settings.endpoint,
        soapheaders = [token]
        )

    return client
예제 #2
0
    def generateGraph(self):
        context = aq_inner(self.context)
        if not context.webServiceURL: raise MissingParameterError(context, 'webServiceURL')
        if not context.operationName: raise MissingParameterError(context, 'operationName')
        if not context.identifyingKey: raise MissingParameterError(context, 'identifyingKey')
        if not context.uriPrefix: raise MissingParameterError(context, 'uriPrefix')
        if not context.typeURI: raise MissingParameterError(context, 'typeURI')
        verificationNum = context.verificationNum if context.verificationNum else DEFAULT_VERIFICATION_NUM
        predicates = {}
        for objID, item in context.contentItems():
            predicates[item.title] = IAsserter(item)
        client = get_suds_client(context.webServiceURL, context)
        function = getattr(client.service, context.operationName)
        horribleString = function(verificationNum)
        graph = rdflib.Graph()
        for row in splitDMCCRows(horribleString):
            subjectURI, statements, statementsMade = None, [], False
            for key, value in parseTokens(row):
                if key == context.identifyingKey and not subjectURI:
                    subjectURI = URIRef(context.uriPrefix + value)
                elif key in predicates and len(value) > 0:
                    statements.extend(predicates[key].characterize(value))
                    statementsMade = True
            # DMCC is giving out empty rows: they have an Identifier number, but no values in any of the columns.
            # While we may wish to generate RDF for those (essentially just saying "Disease #31 exists", for example)
            # It means we need to update EDRN Portal code to handle them, which we can't do right now.
            # So just drop these.  TODO: Add them back, but update the EDRN Portal.
            if statementsMade:
                graph.add((subjectURI, rdflib.RDF.type, URIRef(context.typeURI)))
                for predicate, obj in statements:
                    graph.add((subjectURI, predicate, obj))
        return graph

                        
예제 #3
0
 def __init__(self, bus_user, bus_pass, wsdl):
     # Crear client SOA amb Securitiy activat
     # Obtenim el client amb z3c.suds i no amb suds.Client
     self.client = get_suds_client(wsdl)
     security = Security()
     token = UsernameToken(bus_user, bus_pass)
     security.tokens.append(token)
     self.client.set_options(wsse=security)
def get_salesforce_suds_client(id):
    """Returns an authenticated suds client for the named Salesforce webservice."""
    auth_settings = get_webservice_settings("auth")
    settings = get_webservice_settings(id)
    login = settings.login or auth_settings.login
    password = (settings.password or auth_settings.password or "") + (settings.token or auth_settings.token or "")

    # log in via the auth service
    auth_client = get_suds_client(get_wsdl_uri(auth_settings.wsdl))
    auth_client.set_options(timeout=SOCKET_TIMEOUT, location=auth_settings.endpoint)
    res = auth_client.service.login(login, password)

    # connect to the service
    client = get_suds_client(get_wsdl_uri(settings.wsdl))
    token = client.factory.create("SessionHeader")
    token.sessionId = res.sessionId
    client.set_options(timeout=SOCKET_TIMEOUT, location=settings.endpoint, soapheaders=[token])

    return client
예제 #5
0
 def generateGraph(self):
     graph = rdflib.Graph()
     context = aq_inner(self.context)
     verificationNum = context.verificationNum if context.verificationNum else DEFAULT_VERIFICATION_NUM
     client = get_suds_client(context.webServiceURL, context)
     committees = getattr(client.service, context.committeeOperation)
     members = getattr(client.service, context.membershipOperation)
     
     # Get the committees
     horribleCommittees = committees(verificationNum)
     for row in splitDMCCRows(horribleCommittees):
         subjectURI = None
         statements = {}
         for key, value in parseTokens(row):
             if key == u'Identifier' and not subjectURI:
                 subjectURI = URIRef(context.uriPrefix + value)
                 graph.add((subjectURI, rdflib.RDF.type, URIRef(context.typeURI)))
             elif key in _committeePredicates and len(value) > 0:
                 predicateURI = URIRef(getattr(context, _committeePredicates[key]))
                 statements[predicateURI] = Literal(value)
         for predicateURI, obj in statements.iteritems():
             graph.add((subjectURI, predicateURI, obj))
     
     # Get the members of the committees
     horribleMembers = members(verificationNum)
     for row in splitDMCCRows(horribleMembers):
         subjectURI = predicateURI = obj = None
         for key, value in parseTokens(row):
             if not value: continue
             if key == u'committee_identifier':
                 subjectURI = URIRef(context.uriPrefix + value)
             elif key == u'Registered_Person_Identifer':
                 obj = URIRef(context.personPrefix + value)
             elif key == u'roleName':
                 if value not in _roleNamePredicates: continue
                 predicateURI = URIRef(getattr(context, _roleNamePredicates[value]))
         if subjectURI and predicateURI and obj:
             graph.add((subjectURI, predicateURI, obj))
     
     # C'est tout.
     return graph
예제 #6
0
    def sendTransaction(self, **kws):
        """Builds a transaction object, sends, and commits to First Data GGe4
           Pass in properties for the transaction object as keyword args.
        """
        # Parameters for transactions allowed by First Data GGe4
        # (Transaction){
        #    ExactID = None (String [10])
        #    Password = None (String [30])
        #    Transaction_Type = None (String [2])
        #    DollarAmount = None (Double)
        #    SurchargeAmount = None 
        #    Card_Number = None (String [16])
        #    Transaction_Tag = None (Integer)
        #    Track1 = None (String [75])
        #    Track2 = None (String)
        #    PAN = None 
        #    Authorization_Num = None (String [8])
        #    Expiry_Date = None (String [4])
        #    CardHoldersName = None (String [30])
        #    VerificationStr1 = None (String [41])
        #    This string is populated with the cardholders address information
        #    in a specific format. The address is verified and a result is
        #    returned (AVS property) that indicates how well the address
        #    matched. 
        #    VerificationStr2 = None (String [4])
        #    CVD_Presence_Ind = None (String [1])
        #    ZipCode = None (String [10])
        #    Tax1Amount = None  (Double [99,999.99])
        #    Tax1Number = None (String [20])
        #    Tax2Amount = None (Double [99,999.99])
        #    Tax2Number = None (String [20])
        #    Secure_AuthRequired = None 
        #    Secure_AuthResult = None
        #    Ecommerce_Flag = None
        #    XID = None
        #    CAVV = None
        #    CAVV_Algorithm = None
        #    Reference_No = None
        #    Customer_Ref = None (String [20])
        #    Reference_3 = None (Char [30])
        #    Language = None 
        #    Client_IP = None (String [15])
        #    Client_Email = None (String [30])
        #    User_Name = None 
        #    Currency = None (String [3]) 
        #    https://firstdata.zendesk.com/entries/450214-supported-currencies
        #    PartialRedemption = None
        #  }
        
        wsdl_uri = self.server + '/transaction/wsdl'
        client = get_suds_client(wsdl_uri)
        tx = client.factory.create('ns0:Transaction')
        tx.ExactID = self.login
        tx.Password = self.password
        for key, val in kws.items():
            if tx.__contains__(key):
                tx.__setattr__(key, val)

        # can also set tx.headers
        # can also set tx.proxy
        response = client.service.SendAndCommit(tx)
        return response
예제 #7
0
 def client(self):
     return get_suds_client(self.context.webServiceURL, self.context)