@Override
 public Representation put(Representation entity) throws ResourceException {
   this.userId = UmlgURLDecoder.decode((String) getRequestAttributes().get("userId"));
   User c = UMLG.get().getEntity(this.userId);
   try {
     String entityText = entity.getText();
     c.fromJson(entityText);
     String lookupUri =
         UmlgURLDecoder.decode(getReference().getQueryAsForm(false).getFirstValue("lookupUri"));
     lookupUri = "riap://host" + lookupUri;
     int fakeIdIndex = lookupUri.indexOf("fake");
     if (fakeIdIndex != -1) {
       int indexOfForwardSlash = lookupUri.indexOf("/", fakeIdIndex);
       String fakeId = lookupUri.substring(fakeIdIndex, indexOfForwardSlash);
       Object id = UmlgTmpIdManager.INSTANCE.get(fakeId);
       lookupUri = lookupUri.replace(fakeId, UmlgURLDecoder.encode(id.toString()));
     }
     ClientResource cr = new ClientResource(lookupUri);
     Representation result = cr.get();
     return result;
   } catch (Exception e) {
     if (e instanceof RuntimeException) {
       throw (RuntimeException) e;
     }
     throw new RuntimeException(e);
   } finally {
     UmlgTmpIdManager.INSTANCE.remove();
     UMLG.get().rollback();
   }
 }
 private void removeEdge(Vertex v) {
   Set<Edge> edges = UMLG.get().getEdgesBetween(this.vertex, v, this.getLabel());
   for (Edge edge : edges) {
     Vertex associationClassVertex =
         UMLG.get().v(edge.value(UmlgCollection.ASSOCIATION_CLASS_VERTEX_ID));
     // The remove code will delete all in and out edges
     associationClassVertex.remove();
   }
 }
Ejemplo n.º 3
0
  @Test
  public void testNavToAssociationClassPropertyOtherWayAround() {
    VirtualGroup vg1 = new VirtualGroup();
    vg1.setName("vg1");

    WorkspaceElement we1 = new WorkspaceElement();
    we1.setName("we1");
    WorkspaceElement we2 = new WorkspaceElement();
    we2.setName("we2");

    VirtualGroupWorkspaceElementAC ac1 = new VirtualGroupWorkspaceElementAC();
    ac1.setName("ac1");
    VirtualGroupWorkspaceElementAC ac2 = new VirtualGroupWorkspaceElementAC();
    ac2.setName("ac2");

    we1.addToVirtualgroup(vg1, ac1);
    we2.addToVirtualgroup(vg1, ac2);

    UMLG.get().commit();

    vg1.reload();
    Assert.assertEquals(2, vg1.getVirtualGroupWorkspaceElementAC_workspaceelement().size());
    for (VirtualGroupWorkspaceElementAC virtualGroupWorkspaceElementAC :
        vg1.getVirtualGroupWorkspaceElementAC_workspaceelement()) {
      System.out.println(virtualGroupWorkspaceElementAC.getName());
    }

    Assert.assertEquals(2, vg1.getWorkspaceelement().size());
    // This will null pointer if its the wrong type
    for (WorkspaceElement we : vg1.getWorkspaceelement()) {
      System.out.println(we.getName());
    }
  }
 private void add(User parentResource, Map<String, Object> propertyMap) {
   String qualifiedName = (String) propertyMap.get("qualifiedName");
   Class<UserGroup> baseTumlClass = UmlgSchemaFactory.getUmlgSchemaMap().get(qualifiedName);
   try {
     Object id = propertyMap.get("id");
     UserGroup childResource = UMLG.get().getEntity(id);
     parentResource.addToUsergroup(childResource);
     childResource.fromJson(propertyMap);
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
  @Test
  public void testInheritanceOnAssociationClass() {
    Hour hour1 = new Hour();
    hour1.setHour(1);
    ObjectType objectType1 = new ObjectType();
    objectType1.setName("objectType1");
    ObjectType objectType2 = new ObjectType();
    objectType2.setName("objectType2");

    HourMeasurement hourMeasurement1 = new HourMeasurement();
    hourMeasurement1.setName("hourMeasurement1");
    hour1.addToObjectType(objectType1, hourMeasurement1);

    HourMeasurement hourMeasurement2 = new HourMeasurement();
    hourMeasurement2.setName("hourMeasurement2");
    hour1.addToObjectType(objectType2, hourMeasurement2);

    UMLG.get().commit();

    hour1.reload();

    List<HourMeasurement> hourMeasurementList =
        HourMeasurement.hourMeasurement_findByAggregated(false);
    assertEquals(2, hourMeasurementList.size());
    for (HourMeasurement hourMeasurement : hourMeasurementList) {
      System.out.println(hourMeasurement.getName());
    }

    assertEquals(2, hour1.getHourMeasurement_objectType().size());
    boolean found1 = false, found2 = false;
    for (HourMeasurement hourMeasurement : hour1.getHourMeasurement_objectType()) {
      assertEquals(hour1, hourMeasurement.getHour());
      assertTrue(
          hourMeasurement.getObjectType().equals(objectType1)
              || hourMeasurement.getObjectType().equals(objectType2));
      if (hourMeasurement.getObjectType().equals(objectType1)) {
        found1 = true;
      }
      if (hourMeasurement.getObjectType().equals(objectType2)) {
        found2 = true;
      }
    }
    assertTrue(found1 && found2);
  }
Ejemplo n.º 6
0
  /**
   * This is a tad sensitive. Associations between the 2 models must be from the one generated to
   * the other.
   */
  @Test
  public void testModelImport() {
    A a = new A();
    a.setAttribute1("testA");
    B b1 = new B();
    b1.setAttribute1("testB1");
    a.addToB(b1);
    B b2 = new B();
    b2.setAttribute1("testB2");
    a.addToB(b2);
    UMLG.get().commit();

    Assert.assertEquals(1, A.allInstances().size());
    Assert.assertEquals(2, B.allInstances().size());
    A next = A.allInstances().iterator().next();
    Iterator<B> iterator = next.getB().iterator();
    Assert.assertTrue(B.allInstances().contains(iterator.next()));
    Assert.assertTrue(B.allInstances().contains(iterator.next()));
  }
  @Test
  public void testQualifierToAbstractClass() {
    Q q = new Q();
    q.setName("q1");
    ConcreteQ1 concreteQ1 = new ConcreteQ1();
    concreteQ1.setName("concreteQ11");
    q.addToAbstractQ(concreteQ1);
    ConcreteQ1 concreteQ2 = new ConcreteQ1();
    concreteQ2.setName("concreteQ12");
    q.addToAbstractQ(concreteQ2);

    ConcreteQ2 concreteQ21 = new ConcreteQ2();
    concreteQ21.setName("concreteQ21");
    q.addToAbstractQ(concreteQ21);
    ConcreteQ2 concreteQ22 = new ConcreteQ2();
    concreteQ22.setName("concreteQ22");
    q.addToAbstractQ(concreteQ22);

    UMLG.get().commit();

    q.reload();
    Assert.assertEquals(4, q.getAbstractQ().size());
    Assert.assertNotNull(
        q.getAbstractQForAbstractQNameQualifier(Pair.of(Compare.eq, "concreteQ11")));
    Assert.assertNotNull(
        q.getAbstractQForAbstractQNameQualifier(Pair.of(Compare.eq, "concreteQ12")));
    Assert.assertNotNull(
        q.getAbstractQForAbstractQNameQualifier(Pair.of(Compare.eq, "concreteQ21")));
    Assert.assertNotNull(
        q.getAbstractQForAbstractQNameQualifier(Pair.of(Compare.eq, "concreteQ22")));

    Assert.assertEquals(
        concreteQ1, q.getAbstractQForAbstractQNameQualifier(Pair.of(Compare.eq, "concreteQ11")));
    Assert.assertEquals(
        concreteQ2, q.getAbstractQForAbstractQNameQualifier(Pair.of(Compare.eq, "concreteQ12")));
    Assert.assertEquals(
        concreteQ21, q.getAbstractQForAbstractQNameQualifier(Pair.of(Compare.eq, "concreteQ21")));
    Assert.assertEquals(
        concreteQ22, q.getAbstractQForAbstractQNameQualifier(Pair.of(Compare.eq, "concreteQ22")));
  }
Ejemplo n.º 8
0
  @Test
  public void testSelfAssociationClass() {
    E a = new E();
    a.setName("A");
    E b = new E();
    b.setName("B");
    E c = new E();
    c.setName("C");
    E d = new E();
    d.setName("D");

    EAC ab = new EAC();
    ab.setName("AB");
    a.addToTo(b, ab);
    UMLG.get().commit();
    EAC ac = new EAC();
    ac.setName("AC");
    a.addToTo(c, ac);
    EAC ad = new EAC();
    ad.setName("AD");
    a.addToTo(d, ad);
    db.commit();

    a.reload();
    b.reload();
    Assert.assertEquals(3, a.getTo().size());
    Assert.assertEquals(b, a.getTo().get(0));
    Assert.assertEquals(c, a.getTo().get(1));
    Assert.assertEquals(d, a.getTo().get(2));
    Assert.assertEquals(1, b.getFrom().size());
    Assert.assertEquals(1, c.getFrom().size());
    Assert.assertEquals(1, d.getFrom().size());
    Assert.assertEquals(a, b.getFrom().get(0));
    Assert.assertEquals(a, c.getFrom().get(0));
    Assert.assertEquals(a, d.getFrom().get(0));
    Assert.assertEquals(0, b.getTo().size());

    Assert.assertEquals(3, a.getEAC_to().size());
    for (EAC eac : a.getEAC_to()) {
      Assert.assertTrue(Arrays.asList("AB", "AC", "AD").contains(eac.getName()));
    }
    Assert.assertEquals(1, b.getEAC_from().size());
    Assert.assertEquals(1, b.getEAC_from().size());
    Assert.assertEquals(1, b.getEAC_from().size());
    Assert.assertEquals(0, b.getEAC_to().size());
    Assert.assertEquals(0, b.getEAC_to().size());
    Assert.assertEquals(0, b.getEAC_to().size());

    E e = new E();
    e.setName("E");

    EAC dc = new EAC();
    dc.setName("DC");
    b.addToTo(c, dc);
    EAC dd = new EAC();
    dd.setName("DD");
    b.addToTo(d, dd);
    EAC de = new EAC();
    de.setName("DE");
    b.addToTo(e, de);

    db.commit();
    a.reload();
    b.reload();
    c.reload();
    d.reload();
    e.reload();

    Assert.assertEquals(3, b.getTo().size());
    Assert.assertEquals(c, b.getTo().get(0));
    Assert.assertEquals(d, b.getTo().get(1));
    Assert.assertEquals(e, b.getTo().get(2));

    Assert.assertEquals(1, b.getFrom().size());
    Assert.assertEquals(a, b.getFrom().get(0));

    Assert.assertEquals(3, a.getEAC_to().size());
    Assert.assertEquals(3, b.getEAC_to().size());
    Assert.assertEquals(2, c.getEAC_from().size());
  }
Ejemplo n.º 9
0
 private static void setUpStart() {
   Inicialise.main();
   UMLG.get().commit();
 }
 @SuppressWarnings("unchecked")
 @Override
 public Representation post(Representation entity) throws ResourceException {
   this.userId = UmlgURLDecoder.decode((String) getRequestAttributes().get("userId"));
   User parentResource = UMLG.get().getEntity(userId);
   try {
     ObjectMapper mapper = ObjectMapperFactory.INSTANCE.getObjectMapper();
     String entityText = entity.getText();
     Map<String, Object> overloaded = mapper.readValue(entityText, Map.class);
     Object o = overloaded.get("insert");
     if (o != null) {
       if (o instanceof ArrayList) {
         ArrayList<Map<String, Object>> array = (ArrayList<Map<String, Object>>) o;
         for (Map<String, Object> map : array) {
           add(parentResource, map);
         }
       } else {
         Map<String, Object> map = (Map<String, Object>) o;
         add(parentResource, map);
       }
     }
     o = overloaded.get("delete");
     if (o != null) {
       if (o instanceof ArrayList) {
         ArrayList<Map<String, Object>> array = (ArrayList<Map<String, Object>>) o;
         for (Map<String, Object> map : array) {
           delete(parentResource, map);
         }
       } else {
         Map<String, Object> map = (Map<String, Object>) o;
         delete(parentResource, map);
       }
     }
     o = overloaded.get("update");
     if (o != null) {
       if (o instanceof ArrayList) {
         ArrayList<Map<String, Object>> array = (ArrayList<Map<String, Object>>) o;
         for (Map<String, Object> map : array) {
           put(map);
         }
       } else {
         Map<String, Object> map = (Map<String, Object>) o;
         put(map);
       }
     }
     String lookupUri =
         UmlgURLDecoder.decode(getReference().getQueryAsForm(false).getFirstValue("lookupUri"));
     lookupUri = "riap://host" + lookupUri;
     int fakeIdIndex = lookupUri.indexOf("fake");
     if (fakeIdIndex != -1) {
       int indexOfForwardSlash = lookupUri.indexOf("/", fakeIdIndex);
       String fakeId = lookupUri.substring(fakeIdIndex, indexOfForwardSlash);
       Object id = UmlgTmpIdManager.INSTANCE.get(fakeId);
       lookupUri = lookupUri.replace(fakeId, UmlgURLDecoder.encode(id.toString()));
     }
     ClientResource cr = new ClientResource(lookupUri);
     Representation result = cr.get();
     return result;
   } catch (Exception e) {
     throw UmlgExceptionUtilFactory.getTumlExceptionUtil().handle(e);
   } finally {
     UmlgTmpIdManager.INSTANCE.remove();
     UMLG.get().rollback();
   }
 }
 private void put(Map<String, Object> propertyMap) {
   Object id = propertyMap.get("id");
   UserGroup childResource = UMLG.get().getEntity(id);
   childResource.fromJson(propertyMap);
   Class<? extends UserGroup> baseTumlClass = childResource.getClass();
 }
 private void delete(User parentResource, Map<String, Object> propertyMap) {
   Object id = propertyMap.get("id");
   UserGroup childResource = UMLG.get().getEntity(id);
   parentResource.removeFromUsergroup(childResource);
 }