Esempio n. 1
0
 protected String getObjectUrlPart(Object object) {
   final Identifiable identifiable = (Identifiable) object;
   final ModelObject<?> valueModelObject = ModelResolver.getInstance().getModelObject(object);
   return ModelUtils.getQualifiedNameFromEClass(valueModelObject.eClass())
       + "/"
       + identifiable.getDb_Id(); // $NON-NLS-1$
 }
Esempio n. 2
0
  protected void convertContent(EObject eObject) {
    final Object target = objectMapping.get(eObject);

    final ModelObject<?> modelObject = ModelResolver.getInstance().getModelObject(target);
    for (final EStructuralFeature eStructuralFeature :
        modelObject.eClass().getEAllStructuralFeatures()) {
      if (!eStructuralFeature.isChangeable() || eStructuralFeature.isVolatile()) {
        continue;
      }

      // not set, not convert
      if (!eStructuralFeature.isMany() && !eObject.eIsSet(eStructuralFeature)) {
        continue;
      }

      if (FeatureMapUtil.isFeatureMap(eStructuralFeature)) {
        convertFeatureMap(eObject, modelObject, eStructuralFeature);
      } else if (eStructuralFeature.isMany()) {
        if (eStructuralFeature instanceof EAttribute) {
          final EAttribute eAttribute = (EAttribute) eStructuralFeature;
          convertManyEAttribute(eObject, modelObject, eAttribute);
        } else {
          final EReference eReference = (EReference) eStructuralFeature;
          if (eReference.isContainer()) {
            continue;
          }
          convertManyEReference(eObject, modelObject, eReference);
        }
      } else {
        if (eStructuralFeature instanceof EAttribute) {
          final EAttribute eAttribute = (EAttribute) eStructuralFeature;
          convertSingleEAttribute(eObject, modelObject, eAttribute);
        } else {
          final EReference eReference = (EReference) eStructuralFeature;
          if (eReference.isContainer()) {
            continue;
          }
          convertSingleEReference(eObject, modelObject, eReference);
        }
      }
    }
  }
Esempio n. 3
0
  @Test
  public void testRetrievalAndDelete() {
    final Library lib = createTestData();

    // children
    final Writer w = lib.getWriters().get(0);
    final Book bk = lib.getBooks().get(0);

    // get model information
    if (!isXmlTest()) {
      {
        final String content =
            doGetRequest("model/epackage?id=library", null, HttpServletResponse.SC_OK);
        final List<Object> objects = deserialize(content);
        Assert.assertEquals(1, objects.size());
        Assert.assertTrue(objects.get(0) instanceof DynamicModelObject);
        final DynamicModelObject dmo = (DynamicModelObject) objects.get(0);
        Assert.assertTrue(dmo.eClass() == EcorePackage.eINSTANCE.getEPackage());
        Assert.assertEquals("library", dmo.eGet(EcorePackage.eINSTANCE.getENamedElement_Name()));
        Assert.assertEquals(
            LibraryModelPackage.NS_URI, dmo.eGet(EcorePackage.eINSTANCE.getEPackage_NsURI()));
      }

      {
        final String content =
            doGetRequest(
                "model/epackage?id=" + LibraryModelPackage.NS_URI, null, HttpServletResponse.SC_OK);
        final List<Object> objects = deserialize(content);
        Assert.assertEquals(1, objects.size());
        Assert.assertTrue(objects.get(0) instanceof DynamicModelObject);
        final DynamicModelObject dmo = (DynamicModelObject) objects.get(0);
        Assert.assertTrue(dmo.eClass() == EcorePackage.eINSTANCE.getEPackage());
        Assert.assertEquals("library", dmo.eGet(EcorePackage.eINSTANCE.getENamedElement_Name()));
        Assert.assertEquals(
            LibraryModelPackage.NS_URI, dmo.eGet(EcorePackage.eINSTANCE.getEPackage_NsURI()));
      }

      {
        final String content =
            doGetRequest(
                "model/eclass?name=Book&epackage=" + LibraryModelPackage.NS_URI,
                null,
                HttpServletResponse.SC_OK);
        final List<Object> objects = deserialize(content);
        Assert.assertEquals(1, objects.size());
        Assert.assertTrue(objects.get(0) instanceof DynamicModelObject);
        final DynamicModelObject dmo = (DynamicModelObject) objects.get(0);
        Assert.assertTrue(dmo.eClass() == EcorePackage.eINSTANCE.getEClass());
        Assert.assertEquals("Book", dmo.eGet(EcorePackage.eINSTANCE.getENamedElement_Name()));
      }

      {
        final String content =
            doGetRequest(
                "model/eclassifier?name=BookCategory&epackage=" + LibraryModelPackage.NS_URI,
                null,
                HttpServletResponse.SC_OK);
        final List<Object> objects = deserialize(content);
        Assert.assertEquals(1, objects.size());
        Assert.assertTrue(objects.get(0) instanceof DynamicModelObject);
        final DynamicModelObject dmo = (DynamicModelObject) objects.get(0);
        Assert.assertTrue(dmo.eClass() == EcorePackage.eINSTANCE.getEEnum());
        Assert.assertEquals(
            "BookCategory", dmo.eGet(EcorePackage.eINSTANCE.getENamedElement_Name()));
      }
    }
    // get all libraries
    {
      final String content =
          doGetRequest(
              LibraryModelPackage.INSTANCE.getLibraryEClass().getName(),
              null,
              HttpServletResponse.SC_OK);
      final List<Object> objects = deserialize(content);
      Assert.assertEquals(1, objects.size());
      final ResponseType responseType = (ResponseType) objects.get(0);
      final Library libResult = (Library) responseType.getData().get(0);
      Assert.assertNotSame(lib, libResult);
      Assert.assertEquals(lib.getDb_Id(), libResult.getDb_Id());
    }

    // get one library, and call its content
    {
      String content = getOneObject(lib);
      getValidateOneObject(lib);

      System.err.println(content);
      // and all its content
      final ModelObject<?> modelObject = ModelResolver.getInstance().getModelObject(lib);
      for (EReference eReference : modelObject.eClass().getEAllReferences()) {
        final Object value = modelObject.eGet(eReference);
        if (value == null) {
          continue;
        }
        if (eReference.isMany()) {
          for (Object element : (List<?>) value) {
            if (element instanceof Identifiable) {
              getValidateOneObject(element);
            }
          }
        } else {
          if (value instanceof Identifiable) {
            getValidateOneObject(value);
          }
        }
      }
    }

    // now delete the library
    doDeleteRequest(
        LibraryModelPackage.INSTANCE.getLibraryEClass().getName() + "/" + lib.getDb_Id(),
        HttpServletResponse.SC_OK); // $NON-NLS-1$
    // this should fail
    {
      final String content =
          doGetRequest(
              LibraryModelPackage.INSTANCE.getLibraryEClass().getName() + "/" + lib.getDb_Id(),
              null,
              HttpServletResponse.SC_NOT_FOUND); // $NON-NLS-1$
      final List<Object> objects = deserialize(content);
      Assert.assertEquals(1, objects.size());
      final ErrorType errorType = (ErrorType) objects.get(0);
      Assert.assertTrue(errorType.getMessage().contains("Resource not found")); // $NON-NLS-1$
    }

    // children are removed
    checkExists(w, false);
    checkExists(bk, false);
  }