Ejemplo n.º 1
0
  @GET
  @Path("/getmultiple/{types}")
  public XMLEntityMappings getMutlipleType(@PathParam("types") String types) throws Exception {

    XMLEntityMappings entityMaps = MetaSourceBuilder.createEmptyEntityMappings();
    Set<String> processed = new HashSet<>();
    String[] names = types.split(",");
    for (String typename : names) {
      if (processed.contains(typename)) {
        continue;
      }
      ClassAccessor accessor =
          JpaMapHelper.findClassAccessor(DynamicMetaSource.getEntityMaps(), typename);
      if (accessor == null) {
        continue;
      }
      JpaMapHelper.addClassAccessor(entityMaps, accessor);
      TableGeneratorMetadata meta =
          JpaMapHelper.retrieveTableGenerator(DynamicMetaSource.getEntityMaps(), accessor);
      if (meta != null) {
        entityMaps.getTableGenerators().add(meta);
      }
    }
    return entityMaps;
  }
Ejemplo n.º 2
0
 @Path("/metajs/{jsonp}")
 @GET
 @Produces("application/javascript")
 public String getMetaJson(@PathParam("jsonp") String jsonp) throws NamingException {
   StringWriter writer = new StringWriter();
   MetaSourceBuilder.toJson(DynamicMetaSource.getEntityMaps(), writer);
   return jsonp + "(" + writer.toString() + ")";
 }
Ejemplo n.º 3
0
  @GET
  @Path("/getsingle/{typename}")
  public XMLEntityMappings getSingleType(@PathParam("typename") String typename) throws Exception {

    XMLEntityMappings entityMaps = MetaSourceBuilder.createEmptyEntityMappings();
    ClassAccessor accessor =
        JpaMapHelper.findClassAccessor(DynamicMetaSource.getEntityMaps(), typename);
    if (accessor == null) {
      throw new HttpCodeException(
          Status.NO_CONTENT.getStatusCode(), "type " + typename + " is not found");
    }

    JpaMapHelper.addClassAccessor(entityMaps, accessor);
    TableGeneratorMetadata meta =
        JpaMapHelper.retrieveTableGenerator(DynamicMetaSource.getEntityMaps(), accessor);
    if (meta != null) {
      entityMaps.getTableGenerators().add(meta);
    }

    return entityMaps;
  }
Ejemplo n.º 4
0
  @POST
  @Path("savetype")
  public XMLEntityMappings save(XMLEntityMappings entityMappings) throws Exception {
    String name = null;
    if (!entityMappings.getEntities().isEmpty()) {

      EntityAccessor entityAccessor = entityMappings.getEntities().get(0);
      name = entityAccessor.getName();
      name = Utils.upperFirstLetter(name);
      entityAccessor.setName(name);
      entityAccessor.setClassName(name);

      DynamicMetaSource.getEntityMaps().getEntities().add(entityAccessor);
      if (entityAccessor.getParentClassName().equals(FleximsDynamicEntityImpl.class.getName())) {
        MetaSourceBuilder.addID(entityAccessor, DynamicMetaSource.getEntityMaps());
        MetaSourceBuilder.addVersion(entityAccessor);
      } else {
        boolean foundParent = false;
        EntityAccessor parent = null;
        for (EntityAccessor entityAccessor1 : DynamicMetaSource.getEntityMaps().getEntities()) {
          if (entityAccessor1
              .getClassName()
              .equalsIgnoreCase(entityAccessor.getParentClassName())) {
            parent = entityAccessor1;
            break;
          }
        }

        if (parent != null) {
          foundParent = true;
          MetaSourceBuilder.establishInheritance(entityAccessor, parent);
        } else {
          for (MappedSuperclassAccessor entityAccessor2 :
              DynamicMetaSource.getEntityMaps().getMappedSuperclasses()) {
            if (entityAccessor2
                .getClassName()
                .equalsIgnoreCase(entityAccessor.getParentClassName())) {
              foundParent = true;
              break;
            }
          }
          MetaSourceBuilder.addID(entityAccessor, DynamicMetaSource.getEntityMaps());
          MetaSourceBuilder.addVersion(entityAccessor);
        }

        if (!foundParent) {
          // ignore parent from client.
          entityAccessor.setParentClassName(FleximsDynamicEntityImpl.class.getName());
          MetaSourceBuilder.addID(entityAccessor, DynamicMetaSource.getEntityMaps());
          MetaSourceBuilder.addVersion(entityAccessor);
        }
      }

    } else if (!entityMappings.getEmbeddables().isEmpty()) {

      EmbeddableAccessor embeddableAccessor = entityMappings.getEmbeddables().get(0);
      name = embeddableAccessor.getName();
      name = Utils.upperFirstLetter(name);
      embeddableAccessor.setName(name);
      embeddableAccessor.setClassName(name);
      DynamicMetaSource.getEntityMaps().getEmbeddables().add(embeddableAccessor);
    }

    DynamicMetaSource.normalize();
    App.getPersistenceUnit().refresh(false);
    mapPersister.save(DynamicMetaSource.getEntityMaps());
    return getSingleType(name);
  }