Esempio n. 1
0
    public CayenneMapEntry next() {
      String pathComp = toks.nextToken();

      // see if this is an attribute
      Attribute attr = currentEnt.getAttribute(pathComp);
      if (attr != null) {
        // do a sanity check...
        if (toks.hasMoreTokens())
          throw new ExpressionException(
              "Attribute must be the last component of the path: '" + pathComp + "'.", path, null);

        return attr;
      }

      Relationship rel = currentEnt.getRelationship(pathComp);
      if (rel != null) {
        currentEnt = rel.getTargetEntity();
        if (currentEnt != null || !toks.hasMoreTokens()) { // otherwise an exception will be thrown
          return rel;
        }
      }

      String entityName = (currentEnt != null) ? currentEnt.getName() : "(?)";

      // build error message
      StringBuilder buf = new StringBuilder();
      buf.append("Can't resolve path component: [")
          .append(entityName)
          .append('.')
          .append(pathComp)
          .append("].");
      throw new ExpressionException(buf.toString(), path, null);
    }
Esempio n. 2
0
    public Object next() {
      String pathComp = toks.nextToken();

      // see if this is an attribute
      Attribute attr = currentEnt.getAttribute(pathComp);
      if (attr != null) {
        // do a sanity check...
        if (toks.hasMoreTokens()) {
          throw new ExpressionException(
              "Attribute must be the last component of the path: '" + pathComp + "'.", path, null);
        }

        return attr;
      }

      Relationship rel = currentEnt.getRelationship(pathComp);
      if (rel != null) {
        currentEnt = rel.getTargetEntity();
        return rel;
      }

      // build error message
      StringBuffer buf = new StringBuffer();
      buf.append("Can't resolve path component: [")
          .append(currentEnt.getName())
          .append('.')
          .append(pathComp)
          .append("].");
      throw new ExpressionException(buf.toString(), path, null);
    }
  public Set<Person> getPeopleWithRelationship(String name, String relationship, Person head) {

    Relationship relation =
        relationshipClassMapping.get(Enum.valueOf(RelationEnum.class, relationship.toUpperCase()));

    return relation.getInstance().get(head, name);
  }
Esempio n. 4
0
 @Test
 public void testSourceEntity() {
   Relationship rel = new MockRelationship();
   Entity tstEntity = new MockEntity();
   rel.setSourceEntity(tstEntity);
   assertSame(tstEntity, rel.getSourceEntity());
 }
Esempio n. 5
0
 public Document writeXml() {
   if (this.relationships == null) {
     return this.xml;
   }
   int counter = 1;
   for (Iterator it = this.relationships.iterator(); it.hasNext(); ) {
     Object o = it.next();
     if (o instanceof Relationship) {
       Relationship r = (Relationship) o;
       if (r.id.equals("NONE")) {
         r.id = "rId" + counter;
         counter++;
       }
       this.root.appendChild(r.write(this.xml));
     } else {
       SubDocument r = (SubDocument) o;
       if (r.id.equals("NONE")) {
         r.id = "rId" + counter;
         counter++;
       }
       this.root.appendChild(r.write(this.xml));
     }
   }
   this.xml.appendChild(this.root);
   return this.xml;
 }
Esempio n. 6
0
  public void rn() throws IOException {
    List<RoadLink> links = loadToDatabase("/Users/duduba/gj.mif", "/Users/duduba/gj.mid", false);

    GraphDatabaseService graphDb = neo.getDb();
    Index<Node> nodeIndex = neo.getNodeIndex();

    for (RoadLink link : links) {
      Transaction tx = graphDb.beginTx();
      try {

        Node fromNode = nodeIndex.get("id", link.fromNode).getSingle();
        if (fromNode == null) {
          fromNode = graphDb.createNode();
          fromNode.setProperty("id", link.fromNode);
          nodeIndex.add(fromNode, "id", link.fromNode);
        }
        Node toNode = nodeIndex.get("id", link.toNode).getSingle();
        if (toNode == null) {
          toNode = graphDb.createNode();
          toNode.setProperty("id", link.toNode);
          nodeIndex.add(toNode, "id", link.toNode);
        }

        Relationship r = fromNode.createRelationshipTo(toNode, Neo.RelTypes.TO);
        r.setProperty("no", link.no);
        r.setProperty("name", link.name);

        tx.success();
      } finally {
        tx.finish();
      }
    }
    logger.debug("haha, it's ok!");
  }
Esempio n. 7
0
  @Test
  public void testName() throws Exception {
    Relationship rel = new MockRelationship();

    String tstName = "tst_name";
    rel.setName(tstName);
    assertEquals(tstName, rel.getName());
  }
 protected List<Node> getRelatedNodes(Node startNode, String type, Direction direction) {
   List<Node> result = new ArrayList<Node>();
   for (Relationship relationship :
       startNode.getRelationships(DynamicRelationshipType.withName(type), direction)) {
     result.add(relationship.getOtherNode(startNode));
   }
   return result;
 }
Esempio n. 9
0
  /**
   * Returns a relationship that has a specified entity as a target. If there is more than one
   * relationship for the same target, it is unpredictable which one will be returned.
   *
   * @since 1.1
   */
  public Relationship getAnyRelationship(Entity targetEntity) {
    if (getRelationships().isEmpty()) return null;

    for (Relationship r : getRelationships()) {
      if (r.getTargetEntity() == targetEntity) return r;
    }
    return null;
  }
Esempio n. 10
0
 @Test
 public void testTargetEntity() {
   Relationship rel = new MockRelationship();
   Entity tstEntity = new MockEntity();
   tstEntity.setName("abc");
   rel.setTargetEntityName(tstEntity);
   assertSame("abc", rel.getTargetEntityName());
 }
 @Test
 public void listing3_9_add_properties_to_relationships() {
   usersAndMovies.addPropertiesToRelationships();
   try (Transaction tx = graphDb.beginTx()) {
     Relationship hasSeen =
         usersAndMovies.user1.getSingleRelationship(
             MyRelationshipTypes.HAS_SEEN, Direction.OUTGOING);
     assertEquals(5, hasSeen.getProperty("stars"));
     tx.success();
   }
 }
 @Test
 @Transactional
 public void shouldCreateRelationshipWithProperty() throws Exception {
   Relationship relationship =
       neo4jTemplate.createRelationshipBetween(referenceNode, node1, "has", map("name", "rel2"));
   assertNotNull(relationship);
   assertEquals(referenceNode, relationship.getStartNode());
   assertEquals(node1, relationship.getEndNode());
   assertEquals(HAS.name(), relationship.getType().name());
   assertEquals("rel2", relationship.getProperty("name", "not set"));
 }
Esempio n. 13
0
  // ----- protected methods -----
  protected boolean hasPropertyValue(
      Relationship rel, PropertyKey propertyKey, Object propertyValue) {

    if (rel != null && rel.hasProperty(propertyKey.dbName())) {

      Object value = rel.getProperty(propertyKey.dbName());
      return value.equals(propertyValue);
    }

    return false;
  }
Esempio n. 14
0
  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (!(o instanceof Relationship)) return false;

    Relationship that = (Relationship) o;

    if (sourceUserId != that.getSourceUserId()) return false;
    if (targetUserId != that.getTargetUserId()) return false;
    if (!sourceUserScreenName.equals(that.getSourceUserScreenName())) return false;
    if (!targetUserScreenName.equals(that.getTargetUserScreenName())) return false;

    return true;
  }
  public RealizationRelationship(Element client, Element supplier, String name, String id) {
    setClient(client);
    setSupplier(supplier);
    setId(id);
    super.setName(name);
    super.setType(ElementsTypes.REALIZATION);

    if ((client instanceof Package) && (supplier instanceof Interface)) {
      ((Package) client).addImplementedInterface((Interface) supplier);
    }
    if ((client instanceof Class) && (supplier instanceof Interface)) {
      ((Class) client).addImplementedInterface((Interface) supplier);
    }
  }
 @Test
 public void testDeleteRelationship() {
   Transaction tx = restAPI.beginTx();
   Node n1 = restAPI.createNode(map("name", "newnode1"));
   Node n2 = restAPI.createNode(map("name", "newnode2"));
   Relationship rel = restAPI.createRelationship(n1, n2, Type.TEST, map("name", "rel"));
   rel.delete();
   tx.success();
   tx.finish();
   Relationship foundRelationship =
       TestHelper.firstRelationshipBetween(
           n1.getRelationships(Type.TEST, Direction.OUTGOING), n1, n2);
   Assert.assertNull("found relationship", foundRelationship);
 }
Esempio n. 17
0
  /**
   * Returns a relationship that has a specified entity as a target. If there is more than one
   * relationship for the same target, it is unpredictable which one will be returned.
   *
   * @since 1.1
   */
  public Relationship getAnyRelationship(Entity targetEntity) {
    Collection relationships = getRelationships();
    if (relationships.isEmpty()) {
      return null;
    }

    Iterator it = relationships.iterator();
    while (it.hasNext()) {
      Relationship r = (Relationship) it.next();
      if (r.getTargetEntity() == targetEntity) {
        return r;
      }
    }
    return null;
  }
  @Test
  public void testCreateRelationshipToNodeOutsideofBatch() throws Exception {
    final Node node1 = restAPI.createNode(map());
    final Transaction tx = restAPI.beginTx();

    Node node2 = restAPI.createNode(map());
    final Relationship relationship =
        node1.createRelationshipTo(node2, DynamicRelationshipType.withName("foo"));

    tx.success();
    tx.finish();
    assertEquals("foo", relationship.getType().name());
    assertEquals(
        "foo", getGraphDatabase().getRelationshipById(relationship.getId()).getType().name());
  }
Esempio n. 19
0
 @Test
 public void shouldGetSynonymsFromSavingSide() {
   wordRepository.save(earth);
   assertThat("earth's synonyms count", earth.getSynonymsCount(), is(0));
   wordRepository.save(globe);
   // as earth and globe both are under controll of springdata graph, no need to further call
   // earth.save()
   earth.synonymWith(globe, "the planet we live");
   assertThat("earth's synonyms count", earth.getSynonymsCount(), is(equalTo(1)));
   assertThat("earth's synonym contains globe", earth.getSynonyms(), hasItem(globe));
   Relationship relationship = earth.getSynonymRelationshipTo(globe);
   assertThat("relationship should work properly", relationship.getWord(), is(earth));
   assertThat("relationship should work properly", relationship.getAnotherWord(), is(globe));
   assertThat(
       "relationship should work properly", relationship.getOnEnglish(), is("the planet we live"));
 }
Esempio n. 20
0
 public void addPredecessor(Relationship relationship) {
   if (relationship.getSuccessor().equals(this)) {
     relationships.add(relationship);
   } else {
     throw new RuntimeException("Relationship is not a predecessor of this task");
   }
 }
Esempio n. 21
0
  @Override
  public Relationships getRelationships(Context ctx, PeopleId viewer, PeopleId... targets) {
    ParamChecker.notNull("ctx", ctx);
    ParamChecker.notNull("viewer", viewer);
    ParamChecker.notNull("targets", targets);

    Relationships rels = new Relationships();
    if (targets.length > 0) {
      for (PeopleId target : targets) rels.add(Relationship.disrelated(viewer, target));

      if (viewer.isUser()) {
        FriendEntries fes = getFriendEntries(ctx, viewer.getIdAsLong());
        if (fes != null) {
          for (PeopleId target : targets)
            rels.getRelation(viewer, target)
                .setTargetInViewerCircles(fes.getInCirclesByFriend(target));
        }
      }

      for (PeopleId target : targets) {
        if (!target.isUser()) break;

        FriendEntries fes = getFriendEntries(ctx, target.getIdAsLong());
        if (fes != null)
          rels.getRelation(viewer, target)
              .setViewerInTargetCircles(fes.getInCirclesByFriend(viewer));
      }
    }
    return rels;
  }
Esempio n. 22
0
  /** Adds new relationship to the entity. */
  public void addRelationship(Relationship relationship) {
    if (relationship.getName() == null)
      throw new IllegalArgumentException("Attempt to insert unnamed relationship.");

    // block overrides

    // TODO: change method signature to return replaced attribute and make sure the
    // Modeler handles it...
    Object existingRelationship = relationships.get(relationship.getName());
    if (existingRelationship != null) {
      if (existingRelationship == relationship) return;
      else
        throw new IllegalArgumentException(
            "An attempt to override relationship '" + relationship.getName() + "'");
    }

    // Check that there aren't any attributes with the same name as the given
    // relationship.
    Object existingAttribute = attributes.get(relationship.getName());
    if (existingAttribute != null)
      throw new IllegalArgumentException(
          "Relationship name conflict with existing attribute '" + relationship.getName() + "'");

    relationships.put(relationship.getName(), relationship);
    relationship.setSourceEntity(this);
  }
Esempio n. 23
0
 @Test
 public void shouldGetIdiomFromSavingSide() {
   wordRepository.save(earth);
   assertThat("earth's idioms count", earth.getIdiomsCount(), is(0));
   wordRepository.save(onEarth);
   // as earth and sky both are under controll of springdata graph, no need to further call
   // earth.save()
   earth.idiomWith(onEarth, "added a prefix 'on'");
   assertThat("earth's idioms count", earth.getIdiomsCount(), is(equalTo(1)));
   assertThat("earth's idioms contains onEarth", earth.getIdioms(), hasItem(onEarth));
   Relationship relationship = earth.getIdiomRelationshipTo(onEarth);
   assertThat("relationship should work properly", relationship.getWord(), is(earth));
   assertThat("relationship should work properly", relationship.getAnotherWord(), is(onEarth));
   assertThat(
       "relationship should work properly",
       relationship.getOnEnglish(),
       is("added a prefix 'on'"));
 }
Esempio n. 24
0
 @Override
 public int hashCode() {
   return super.hashCode()
       + relationship.hashCode()
       + ClassMetadata.hashCode(deleteAction)
       + ClassMetadata.hashCode(keyName)
       + ClassMetadata.hashCode(elementClassName)
       + ClassMetadata.hashCode(relatedEntity);
 }
Esempio n. 25
0
 @Test
 public void shouldGetExtensionFromSavingSide() {
   wordRepository.save(earth);
   assertThat("earth's extensions count", earth.getExtensionsCount(), is(0));
   wordRepository.save(sky);
   // as earth and sky both are under controll of springdata graph, no need to further call
   // earth.save()
   earth.extendWith(sky, "earth and sky just intuitive");
   assertThat("earth's extensions count", earth.getExtensionsCount(), is(equalTo(1)));
   assertThat("earth's extensions contains sky", earth.getExtensions(), hasItem(sky));
   Relationship relationship = earth.getExtensionRelationshipTo(sky);
   assertThat("relationship should work properly", relationship.getWord(), is(earth));
   assertThat("relationship should work properly", relationship.getAnotherWord(), is(sky));
   assertThat(
       "relationship should work properly",
       relationship.getOnEnglish(),
       is("earth and sky just intuitive"));
 }
Esempio n. 26
0
 /**
  * Packs a Pdu into the ByteBuffer.
  *
  * @throws java.nio.BufferOverflowException if buff is too small
  * @throws java.nio.ReadOnlyBufferException if buff is read only
  * @see java.nio.ByteBuffer
  * @param buff The ByteBuffer at the position to begin writing
  * @since ??
  */
 public void marshal(java.nio.ByteBuffer buff) {
   super.marshal(buff);
   orginatingEntityID.marshal(buff);
   receivingEntityID.marshal(buff);
   relationship.marshal(buff);
   partLocation.marshal(buff);
   namedLocationID.marshal(buff);
   partEntityType.marshal(buff);
 } // end of marshal method
  /**
   * Test method for {@link
   * RelationshipCalculator#calculateRelationships(org.gedcom4j.model.Individual,
   * org.gedcom4j.model.Individual, boolean)} .
   */
  @Test
  @SuppressWarnings("PMD.SystemPrintln")
  public void testCalculateRelationshipSonFather() {
    Individual james = getPerson("Andrews", "James");
    Individual robert = getPerson("Andrews", "Robert");

    rc.calculateRelationships(robert, james, true);
    assertNotNull(rc.getRelationshipsFound());
    if (VERBOSE) {
      System.out.println("Relationships between " + robert + " and " + james);
      for (Relationship r : rc.getRelationshipsFound()) {
        System.out.println("   " + r);
      }
    }
    assertEquals(
        "James is robert's father - there should be one relationship",
        1,
        rc.getRelationshipsFound().size());
    Relationship r = rc.getRelationshipsFound().get(0);
    assertEquals(robert, r.getIndividual1());
    assertEquals(james, r.getIndividual2());
    assertNotNull(r.getChain());
    assertEquals("The relationship length should be one hop long", 1, r.getChain().size());
    assertEquals(
        "The relationship should be an father/son one", FATHER, r.getChain().get(0).getName());
  }
Esempio n. 28
0
  @Test
  public void shouldGetAntonymFromSavingSide() {
    wordRepository.save(happy);
    assertThat("happy's antonym count", happy.getAntonymsCount(), is(0));
    wordRepository.save(sad);
    // as earth and sky both are under controll of springdata graph, no need to further call
    // earth.save()
    happy.antonymWith(sad, "feel good vs feel bad");
    assertThat("happy's antonym count", happy.getAntonymsCount(), is(equalTo(1)));
    assertThat("happy's antonym contains sad", happy.getAntonyms(), hasItem(sad));
    Relationship relationship = happy.getAntonymRelationshipTo(sad);
    assertThat("relationship should work properly", relationship.getWord(), is(happy));
    assertThat("relationship should work properly", relationship.getAnotherWord(), is(sad));
    assertThat(
        "relationship should work properly",
        relationship.getOnEnglish(),
        is("feel good vs feel bad"));

    Set<Relationship> relationships = happy.getRelationshipsTo(sad);
    assertThat(relationships.size(), is(1));
    assertThat(relationships, hasItem(relationship));
  }
Esempio n. 29
0
  public int getMarshalledSize() {
    int marshalSize = 0;

    marshalSize = super.getMarshalledSize();
    marshalSize = marshalSize + orginatingEntityID.getMarshalledSize(); // orginatingEntityID
    marshalSize = marshalSize + receivingEntityID.getMarshalledSize(); // receivingEntityID
    marshalSize = marshalSize + relationship.getMarshalledSize(); // relationship
    marshalSize = marshalSize + partLocation.getMarshalledSize(); // partLocation
    marshalSize = marshalSize + namedLocationID.getMarshalledSize(); // namedLocationID
    marshalSize = marshalSize + partEntityType.getMarshalledSize(); // partEntityType

    return marshalSize;
  }
Esempio n. 30
0
 /**
  * Checks the status of a friendship
  *
  * @param id the user to check friendship status with
  * @return a string representing the status
  */
 public String checkFriendship(Long id) {
   User current = Application.user();
   if (Application.user().id == id) {
     return "";
   }
   Relationship r1 =
       Relationship.find(
               "SELECT r FROM Relationship r where r.from = ?1 AND r.to = ?2", current, this)
           .first();
   Relationship r2 =
       Relationship.find(
               "SELECT r FROM Relationship r where r.to = ?1 AND r.from = ?2", current, this)
           .first();
   if (r1 != null) {
     if (r1.accepted) {
       return "Friends";
     }
     if (r1.requested) {
       return "Friendship Requested";
     }
   }
   return "Request Friendship";
 }