def with_same_name(self):
     q = """
         MATCH (n:Node {handle_id: {handle_id}}), (other:Node:Relation {name: {name}})
         WHERE other.handle_id <> n.handle_id
         RETURN COLLECT(other.handle_id) as ids
         """
     return core.query_to_dict(self.manager, q, handle_id=self.handle_id, name=self.data.get('name'))
 def with_same_name(self):
     q = """
         MATCH (n:Node {handle_id: {handle_id}}), (other:Node:Relation {name: {name}})
         WHERE other.handle_id <> n.handle_id
         RETURN COLLECT(other.handle_id) as ids
         """
     return core.query_to_dict(self.manager, q, handle_id=self.handle_id, name=self.data.get('name'))
 def get_location_path(self):
     q = """
         MATCH (n:Node {handle_id: {handle_id}})-[:Part_of]->(parent)
         OPTIONAL MATCH p=()-[:Has*0..20]->(r)<-[:Located_in]-()-[:Has*0..20]->(parent)
         WITH COLLECT(nodes(p)) as paths, MAX(length(nodes(p))) AS maxLength
         WITH FILTER(path IN paths WHERE length(path)=maxLength) AS longestPaths
         UNWIND(longestPaths) as location_path
         RETURN location_path
         """
     return core.query_to_dict(self.manager, q, handle_id=self.handle_id)
 def get_location_path(self):
     q = """
         MATCH (n:Node {handle_id: {handle_id}})-[:Part_of]->(parent)
         OPTIONAL MATCH p=()-[:Has*0..20]->(r)<-[:Located_in]-()-[:Has*0..20]->(parent)
         WITH COLLECT(nodes(p)) as paths, MAX(length(nodes(p))) AS maxLength
         WITH FILTER(path IN paths WHERE length(path)=maxLength) AS longestPaths
         UNWIND(longestPaths) as location_path
         RETURN location_path
         """
     return core.query_to_dict(self.manager, q, handle_id=self.handle_id)
    def remove_role_from_contacts(self, rolename):
        handle_id = self.handle_id
        if isinstance(self.handle_id, six.string_types):
            handle_id = "'{}'".format(handle_id)

        q = """
            MATCH (role:Node:Role)<-[r:Is]-(cont:Node:Contact)-[:Works_for]->(org:Node:Organization)
            WHERE org.handle_id = {handle_id} AND role.name = '{rolename}'
            DELETE r
            RETURN cont
            """.format(handle_id=handle_id, rolename=rolename)

        return core.query_to_dict(self.manager, q)
 def get_dependent_as_types(self):
     q = """
         MATCH (n:Node {handle_id: {handle_id}})-[:Connected_to*1..20]-(equip)
         WITH DISTINCT equip
         MATCH (equip)<-[:Part_of|Depends_on*1..10]-(dep)
         WITH collect(DISTINCT dep) as deps
         WITH deps, filter(n in deps WHERE n:Service) as services
         WITH deps, services, filter(n in deps WHERE n:Optical_Path) as paths
         WITH deps, services, paths, filter(n in deps WHERE n:Optical_Multiplex_Section) as oms
         WITH deps, services, paths, oms, filter(n in deps WHERE n:Optical_Link) as links
         RETURN services, paths, oms, links
         """
     return core.query_to_dict(self.manager, q, handle_id=self.handle_id)
 def get_dependent_as_types(self):
     q = """
         MATCH (n:Node {handle_id: {handle_id}})-[:Connected_to*1..20]-(equip)
         WITH DISTINCT equip
         MATCH (equip)<-[:Part_of|Depends_on*1..10]-(dep)
         WITH collect(DISTINCT dep) as deps
         WITH deps, filter(n in deps WHERE n:Service) as services
         WITH deps, services, filter(n in deps WHERE n:Optical_Path) as paths
         WITH deps, services, paths, filter(n in deps WHERE n:Optical_Multiplex_Section) as oms
         WITH deps, services, paths, oms, filter(n in deps WHERE n:Optical_Link) as links
         RETURN services, paths, oms, links
         """
     return core.query_to_dict(self.manager, q, handle_id=self.handle_id)
 def get_dependent_as_types(self):  # Does not return Host_Service as a direct dependent
     q = """
         MATCH (node:Node {handle_id: {handle_id}})
         OPTIONAL MATCH (node)<-[:Depends_on]-(d)
         WITH node, filter(n in collect(DISTINCT d) WHERE NOT(n:Host_Service)) as direct
         MATCH (node)<-[:Depends_on*1..20]-(dep)
         WITH direct, collect(DISTINCT dep) as deps
         WITH direct, deps, filter(n in deps WHERE n:Service) as services
         WITH direct, deps, services, filter(n in deps WHERE n:Optical_Path) as paths
         WITH direct, deps, services, paths, filter(n in deps WHERE n:Optical_Multiplex_Section) as oms
         WITH direct, deps, services, paths, oms, filter(n in deps WHERE n:Optical_Link) as links
         RETURN direct, services, paths, oms, links
         """
     return core.query_to_dict(self.manager, q, handle_id=self.handle_id)
 def get_dependent_as_types(self):  # Does not return Host_Service as a direct dependent
     q = """
         MATCH (node:Node {handle_id: {handle_id}})
         OPTIONAL MATCH (node)<-[:Depends_on]-(d)
         WITH node, filter(n in collect(DISTINCT d) WHERE NOT(n:Host_Service)) as direct
         MATCH (node)<-[:Depends_on*1..20]-(dep)
         WITH direct, collect(DISTINCT dep) as deps
         WITH direct, deps, filter(n in deps WHERE n:Service) as services
         WITH direct, deps, services, filter(n in deps WHERE n:Optical_Path) as paths
         WITH direct, deps, services, paths, filter(n in deps WHERE n:Optical_Multiplex_Section) as oms
         WITH direct, deps, services, paths, oms, filter(n in deps WHERE n:Optical_Link) as links
         RETURN direct, services, paths, oms, links
         """
     return core.query_to_dict(self.manager, q, handle_id=self.handle_id)
 def get_dependent_as_types(self):
     q = """
         MATCH (node:Node {handle_id: {handle_id}})
         OPTIONAL MATCH (node)<-[:Depends_on]-(d)
         WITH node, collect(DISTINCT d) as direct
         OPTIONAL MATCH (node)-[:Has*1..20]->()<-[:Part_of|Depends_on*1..20]-(dep)
         OPTIONAL MATCH (node)-[:Has*1..20]->()<-[:Connected_to]-()-[:Connected_to]->()<-[:Depends_on*1..20]-(cable_dep)
         WITH direct, collect(DISTINCT dep) + collect(DISTINCT cable_dep) as coll UNWIND coll AS x
         WITH direct, collect(DISTINCT x) as deps
         WITH direct, deps, filter(n in deps WHERE n:Service) as services
         WITH direct, deps, services, filter(n in deps WHERE n:Optical_Path) as paths
         WITH direct, deps, services, paths, filter(n in deps WHERE n:Optical_Multiplex_Section) as oms
         WITH direct, deps, services, paths, oms, filter(n in deps WHERE n:Optical_Link) as links
         RETURN direct, services, paths, oms, links
         """
     return core.query_to_dict(self.manager, q, handle_id=self.handle_id)
 def get_dependencies_as_types(self):
     q = """
         MATCH (node:Node {handle_id: {handle_id}})
         OPTIONAL MATCH (node)-[:Depends_on]->(d)
         WITH node, collect(DISTINCT d) as direct
         MATCH (node)-[:Depends_on*1..20]->(dep)
         WITH node, direct, collect(DISTINCT dep) as deps
         WITH node, direct, deps, filter(n in deps WHERE n:Service) as services
         WITH node, direct, deps, services, filter(n in deps WHERE n:Optical_Path) as paths
         WITH node, direct, deps, services, paths, filter(n in deps WHERE n:Optical_Multiplex_Section) as oms
         WITH node, direct, deps, services, paths, oms, filter(n in deps WHERE n:Optical_Link) as links
         WITH node, direct, services, paths, oms, links
         OPTIONAL MATCH (node)-[:Depends_on*1..20]->()-[:Connected_to*1..50]-(cable)
         RETURN direct, services, paths, oms, links, filter(n in collect(DISTINCT cable) WHERE n:Cable) as cables
         """
     return core.query_to_dict(self.manager, q, handle_id=self.handle_id)
 def get_dependent_as_types(self):
     q = """
         MATCH (node:Node {handle_id: {handle_id}})
         OPTIONAL MATCH (node)<-[:Depends_on]-(d)
         WITH node, collect(DISTINCT d) as direct
         OPTIONAL MATCH (node)-[:Has*1..20]->()<-[:Part_of|Depends_on*1..20]-(dep)
         OPTIONAL MATCH (node)-[:Has*1..20]->()<-[:Connected_to]-()-[:Connected_to]->()<-[:Depends_on*1..20]-(cable_dep)
         WITH direct, collect(DISTINCT dep) + collect(DISTINCT cable_dep) as coll UNWIND coll AS x
         WITH direct, collect(DISTINCT x) as deps
         WITH direct, deps, filter(n in deps WHERE n:Service) as services
         WITH direct, deps, services, filter(n in deps WHERE n:Optical_Path) as paths
         WITH direct, deps, services, paths, filter(n in deps WHERE n:Optical_Multiplex_Section) as oms
         WITH direct, deps, services, paths, oms, filter(n in deps WHERE n:Optical_Link) as links
         RETURN direct, services, paths, oms, links
         """
     return core.query_to_dict(self.manager, q, handle_id=self.handle_id)
 def get_dependencies_as_types(self):
     q = """
         MATCH (node:Node {handle_id: {handle_id}})
         OPTIONAL MATCH (node)-[:Depends_on]->(d)
         WITH node, collect(DISTINCT d) as direct
         MATCH (node)-[:Depends_on*1..20]->(dep)
         WITH node, direct, collect(DISTINCT dep) as deps
         WITH node, direct, deps, filter(n in deps WHERE n:Service) as services
         WITH node, direct, deps, services, filter(n in deps WHERE n:Optical_Path) as paths
         WITH node, direct, deps, services, paths, filter(n in deps WHERE n:Optical_Multiplex_Section) as oms
         WITH node, direct, deps, services, paths, oms, filter(n in deps WHERE n:Optical_Link) as links
         WITH node, direct, services, paths, oms, links
         OPTIONAL MATCH (node)-[:Depends_on*1..20]->()-[:Connected_to*1..50]-(cable)
         RETURN direct, services, paths, oms, links, filter(n in collect(DISTINCT cable) WHERE n:Cable) as cables
         """
     return core.query_to_dict(self.manager, q, handle_id=self.handle_id)