示例#1
0
  @Path("/updatetype")
  @POST
  public XMLEntityMappings updateType(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);
      JpaMapHelper.replaceClassAccessor(DynamicMetaSource.getEntityMaps(), 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);
      JpaMapHelper.replaceClassAccessor(DynamicMetaSource.getEntityMaps(), embeddableAccessor);
    }
    DynamicMetaSource.normalize();
    mapPersister.save(DynamicMetaSource.getEntityMaps());
    return getSingleType(name);
  }
示例#2
0
  @Path("deleteprop/{typename}/{propname}")
  @GET
  public XMLEntityMappings deleteProp(
      @PathParam("typename") String typeName, @PathParam("propname") String propName)
      throws Exception {
    ClassAccessor entity =
        JpaMapHelper.findClassAccessor(DynamicMetaSource.getEntityMaps(), typeName);
    Attribute<?, ?> attr = JpaMetamodelHelper.getAttribute(typeName, propName);
    if (JpaMapHelper.findPropertyBbyMappedBy(
            JpaMetamodelHelper.getAttributeType(attr).getSimpleName(), propName)
        != null) {
      throw new CodedExceptionImpl(
          PROP_REFERED,
          "Deletion can not be performed. Target Property is referred by other types");
    }

    EntityManager eManager = App.getEM();
    eManager.getTransaction().begin();
    Connection connection = eManager.unwrap(Connection.class);
    for (String sql : JpaHelper.deletePropDBStructure(eManager, typeName, propName)) {
      LOGGER.info(sql);
      connection.createStatement().execute(sql);
    }
    eManager.getTransaction().commit();
    JpaMapHelper.deleteProp(entity, propName);
    App.getPersistenceUnit().refresh(false);
    mapPersister.save(DynamicMetaSource.getEntityMaps());
    return DynamicMetaSource.getEntityMaps();
  }
示例#3
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;
  }
示例#4
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;
  }
示例#5
0
 @Path("deletetype/{typename}")
 @GET
 public XMLEntityMappings deleteType(@PathParam("typename") String typeName) throws Exception {
   List<Attribute<?, ?>> attrs = JpaMetamodelHelper.findReferringProps(typeName, true);
   if (!attrs.isEmpty()) {
     throw new CodedExceptionImpl(
         TYPE_REFERED, "Deletion can not be performed. Target type is referred by other types");
   }
   EntityManager eManager = App.getEM();
   eManager.getTransaction().begin();
   Connection connection = eManager.unwrap(Connection.class);
   for (String sql : JpaHelper.deletePropDBStructure(eManager, typeName)) {
     LOGGER.info(sql);
     connection.createStatement().execute(sql);
   }
   eManager.getTransaction().commit();
   JpaMapHelper.deleteClassAccessor(DynamicMetaSource.getEntityMaps(), typeName);
   App.getPersistenceUnit().refresh(false);
   mapPersister.save(DynamicMetaSource.getEntityMaps());
   return DynamicMetaSource.getEntityMaps();
 }
示例#6
0
  @SuppressWarnings("rawtypes")
  public static FileIDs searchFileIDs(FleximsDynamicEntityImpl de, String propName, String prefix) {
    FileIDs fileIDs = new FileIDs();
    XMLEntityMappings mappings = JpaMapHelper.getInternaEntityMappings();
    Class<?> clz = de.getClass();
    String firstName = null;
    String subName = null;
    if (propName != null) {
      int i = propName.indexOf('.');
      if (i != -1) {
        firstName = propName.substring(0, i);
        subName = propName.substring(i + 1);
      } else {
        firstName = propName;
      }
    }

    while (clz != FleximsDynamicEntityImpl.class && clz != Object.class) {
      ClassAccessor accessor = JpaMapHelper.findClassAccessor(mappings, clz.getSimpleName());
      if (accessor != null && accessor.getAttributes() != null) {

        // single file.
        for (BasicAccessor prop : accessor.getAttributes().getBasics()) {
          if (firstName != null && !prop.getName().equals(firstName)) {
            continue;
          }
          Object value = de.get(prop.getName());
          if (value == null) {
            continue;
          }
          if (isFileUpload(prop)) {
            FileID fileID = FileID.valueOf((String) value);

            if (fileID != null) {
              fileIDs.getFileIDs().add(fileID);
              fileID.setPropName(prefix == null ? prop.getName() : prefix + "/" + prop.getName());
            }
          }
        }

        for (ElementCollectionAccessor prop : accessor.getAttributes().getElementCollections()) {
          if (firstName != null && !prop.getName().equals(firstName)) {
            continue;
          }
          Collection values = de.get(prop.getName());
          if (values == null || values.isEmpty()) {
            continue;
          }
          if (isFileUpload(prop)) {
            for (Object value : values) {
              FileID fileID = FileID.valueOf((String) value);
              if (fileID != null) {
                fileIDs.getFileIDs().add(fileID);
                fileID.setPropName(prefix == null ? prop.getName() : prefix + "/" + prop.getName());
              }
            }
            continue;
          }
          Object firstObject = values.iterator().next();
          // collection of embedded
          if (firstObject instanceof FleximsDynamicEntityImpl) {
            for (Object obj : values) {
              FleximsDynamicEntityImpl embeded = (FleximsDynamicEntityImpl) obj;
              FileIDs iDs =
                  searchFileIDs(
                      embeded,
                      subName,
                      prefix == null ? prop.getName() : prefix + "/" + prop.getName());
              fileIDs.getFileIDs().addAll(iDs.getFileIDs());
            }
          }
        }
        for (EmbeddedAccessor prop : accessor.getAttributes().getEmbeddeds()) {
          if (firstName != null && !prop.getName().equals(firstName)) {
            continue;
          }
          FleximsDynamicEntityImpl embeded = de.get(prop.getName());
          if (embeded == null) {
            continue;
          }
          if (embeded != null) {
            FileIDs iDs =
                searchFileIDs(
                    embeded,
                    subName,
                    prefix == null ? prop.getName() : prefix + "/" + prop.getName());
            fileIDs.getFileIDs().addAll(iDs.getFileIDs());
          }
        }
      }
      clz = clz.getSuperclass();
    }
    return fileIDs;
  }
示例#7
0
  @SuppressWarnings("rawtypes")
  public static FileInfos searchServerFileInfos(
      FleximsDynamicEntityImpl de, String propName, Path prefix, Path start) {
    FileInfos fileInfos = new FileInfos();
    if (prefix == null) {
      prefix = serverFileTopDir();
    }
    if (start == null) {
      start = serverFileTopDir();
    }
    XMLEntityMappings mappings = JpaMapHelper.getInternaEntityMappings();
    Class<?> clz = de.getClass();
    String firstName = null;
    String subName = null;
    if (propName != null) {
      int i = propName.indexOf('.');
      if (i != -1) {
        firstName = propName.substring(0, i);
        subName = propName.substring(i + 1);
      } else {
        firstName = propName;
      }
    }

    while (clz != FleximsDynamicEntityImpl.class && clz != Object.class) {
      ClassAccessor accessor = JpaMapHelper.findClassAccessor(mappings, clz.getSimpleName());
      if (accessor != null) {

        // single file.
        for (BasicAccessor prop : accessor.getAttributes().getBasics()) {
          if (firstName != null && !prop.getName().equals(firstName)) {
            continue;
          }
          Object value = de.get(prop.getName());
          if (value == null) {
            continue;
          }
          if (isServerFile(prop)) {
            Path filePath = prefix.resolve((String) value);
            if (!filePath.startsWith(prefix)) {
              // you can not navigate out.
              continue;
            }
            FileInfo fileInfo = pathToFileInfo(filePath, start);
            fileInfos.getFileInfos().add(fileInfo);
          }
        }

        for (ElementCollectionAccessor prop : accessor.getAttributes().getElementCollections()) {
          if (firstName != null && !prop.getName().equals(firstName)) {
            continue;
          }
          Collection values = de.get(prop.getName());
          if (values == null || values.isEmpty()) {
            continue;
          }
          if (isServerFile(prop)) {
            for (Object value : values) {
              Path filePath = prefix.resolve((String) value);
              if (!filePath.startsWith(prefix)) {
                // you can not navigate out.
                continue;
              }
              FileInfo fileInfo = pathToFileInfo(filePath, start);
              fileInfos.getFileInfos().add(fileInfo);
            }
            continue;
          }

          Object firstObject = values.iterator().next();
          // collection of embedded
          if (firstObject instanceof FleximsDynamicEntityImpl) {
            for (Object obj : values) {
              FleximsDynamicEntityImpl embeded = (FleximsDynamicEntityImpl) obj;
              FileInfos fileInfos2 = searchServerFileInfos(embeded, subName, prefix, start);
              fileInfos.getFileInfos().addAll(fileInfos2.getFileInfos());
            }
          }
        }
        for (EmbeddedAccessor prop : accessor.getAttributes().getEmbeddeds()) {
          if (firstName != null && !prop.getName().equals(firstName)) {
            continue;
          }
          FleximsDynamicEntityImpl embeded = de.get(prop.getName());
          if (embeded == null) {
            continue;
          }
          if (embeded != null) {
            FileInfos fileInfos2 = searchServerFileInfos(embeded, subName, prefix, start);
            fileInfos.getFileInfos().addAll(fileInfos2.getFileInfos());
          }
        }
      }
      clz = clz.getSuperclass();
    }
    return fileInfos;
  }
 public MappingAccessor getTargetPropertyConfig() {
   ClassAccessor queryType =
       JpaMapHelper.findClassAccessor(DynamicMetaSource.getEntityMaps(), query.getQueryType());
   return JpaMapHelper.findProp(queryType, getProp());
 }