Exemplo n.º 1
0
def company_relations_by_domain():
    """
    Get a company relations by DOMAIN
    This endpoint returns all properties of a company by a given DOMAIN in a key/value fashion
    ---
    tags:
      - company
    parameters:
      - name: domain
        in: query
        type: string
        description: domain of a company
        required: true
      - name: filter
        in: query
        type: string
        description: relation type to use as filter (case-insensitive)
    responses:
      200:
        description: A single company item
        schema:
          properties:
            property-1:
              type: string
              description: A property
              default: 'value-1'
            property-2:
              type: string
              description: A property
              default: 'value-2'
            property-N:
              type: string
              description: A property
              default: 'value-N'
      400:
        description: Bad request. Missing/wrong parameter.
      404:
        description: Company not found
    """
    domain = request.args.get('domain', None)
    if domain is None:
        return 'No domain provided. Mandatory parameter', 400

    company = Store.get_company({"domain": domain})
    if company is None:
        return 'No company with domain %s found' % domain, 404

    filter = request.args.get('filter', None)

    data = company.get_relations(filter)
    response = app.response_class(response=json.dumps(data),
                                  status=200,
                                  mimetype='application/json')
    return response
Exemplo n.º 2
0
    def get_relations(self, filter=None):
        """
        Looks at raw data of person entity and returns all relations.

        :return: List of tupples, each tupple: (target_aid, relationship type, relationship properties)
        """
        from store.store import Store

        relations = set()

        # C:C - Create ACQUIRED_BY relation
        if C.ACQUIRED_BY in self.deduced:
            #acquiring_company = Store.get_company({C.NAME: self.deduced[C.ACQUIRED_BY]})
            acquiring_company = Store.get_company(
                {C.ALIASES: self.deduced[C.ACQUIRED_BY].lower()})
            if acquiring_company:
                relations.add((self.aid, G.RELATION_LABEL_ACQUIRED_BY,
                               acquiring_company.aid, ''))

        # C:C - Create the INVESTED_IN relation
        if C.ORGANIZATION_TYPE in self.deduced and self.deduced[
                C.ORGANIZATION_TYPE] == C.ORGANIZATION_TYPE_VENTURE_CAPITAL:
            for portfolio_company in self.deduced.get(C.PORTFOLIO_COMPANIES,
                                                      []):
                ccc_company = Store.get_company(
                    {C.ALIASES: portfolio_company.lower()})
                if ccc_company:
                    relations.add((self.aid, G.RELATION_LABEL_INVESTS_IN,
                                   ccc_company.aid, ''))

        # P:C - Create EMPLOYEE_OF relation (Team. past_team)
        for team_mate in self.deduced.get(C.TEAM, []):
            person = Store.get_person({P.FULL_NAME: team_mate})
            if person:
                relations.add(
                    (person.aid, G.RELATION_LABEL_EMPLOYEE_OF, self.aid, ''))

        # P:C - Create BOARD_AT relation (Advisors)
        for advisor in self.deduced.get(C.ADVISORS, []):
            person = Store.get_person({P.FULL_NAME: advisor})
            if person:
                relations.add(
                    (person.aid, G.RELATION_LABEL_ADVISOR_AT, self.aid, ''))

        # P:C - Create FOUNDER_OF relation (Company)
        for founder in self.deduced.get(C.FOUNDERS, []):
            person = Store.get_person({P.FULL_NAME: founder})
            if person:
                relations.add(
                    (person.aid, G.RELATION_LABEL_FOUNDER_OF, self.aid, ''))

        # P:C - Create INVESTS_AT relation (Investors)
        for investor_name, investor_type, investment_info in self.deduced.get(
                C.INVESTORS, []):

            # Find info on investment type -> relation_properties
            relation_properties = []
            investment_round = AcureRateUtils.get_investment_round(
                investment_info)
            if investment_round:
                relation_properties.append("investment_type: '%s'" %
                                           investment_round)
            investment_lead = AcureRateUtils.is_investment_lead(
                investment_info)
            if investment_lead:  # TODO: should be label and not property
                relation_properties.append("investment_lead: True")

            if investor_type == 'person':
                person = Store.get_person(
                    {'deduced.' + P.FULL_NAME: investor_name})
                if person:
                    relations.add((person.aid, G.RELATION_LABEL_INVESTS_IN,
                                   self.aid, ', '.join(relation_properties)))
            elif investor_type == 'organization':
                investing_company = Store.get_company({C.NAME: investor_name})
                if investing_company:
                    relations.add(
                        (investing_company.aid, G.RELATION_LABEL_INVESTS_IN,
                         self.aid, ', '.join(relation_properties)))

        # If filter provided, leave only relations that are relevant
        if filter:
            relations = [
                tup for tup in relations if tup[1].lower() == filter.lower()
            ]

        return relations