예제 #1
0
 @RequestMapping(value = "/getEntities")
 public @ResponseBody Map<String, Object> getEntities(
     @RequestParam(value = "appId") Long appId, Model model) {
   Map<String, Object> data = new LinkedHashMap<String, Object>();
   logger.debug("Getting Entities for App Id : " + appId + " ...");
   try {
     App app = appAPI.findOne(appId);
     List<Entity> entities = new ArrayList<>();
     entities.addAll(app.getAppEntities());
     data.put("entities", entityAPI.mapEntitiesToJSON(entities));
     data.put("status", "1");
   } catch (Exception e) {
     data.put("status", "-1");
     data.put("message", "Can Not Retrieve Entities For App Id : " + appId + " !!!");
     logger.error(e.getMessage(), e);
   } finally {
     logger.debug("Getting Entities Is Ended.");
   }
   return data;
 }
예제 #2
0
  @RequestMapping(
      value = "/createEntity",
      consumes = {MediaType.APPLICATION_JSON_VALUE})
  public @ResponseBody Map<String, Object> createEntity(
      @RequestBody AppEntityVO appEntityVO, Model model) {
    Map<String, Object> data = new LinkedHashMap<String, Object>();
    logger.debug(
        "Creating Entity with Name : "
            + appEntityVO.getEntityName()
            + " to App Id : "
            + appEntityVO.getAppId());
    try {
      if (appEntityVO.getAppId() != null
          && appEntityVO.getAppId() > 0
          && StringUtils.isNotEmpty(appEntityVO.getEntityName())) {
        Entity entity = new Entity();
        entity.setEntityName(appEntityVO.getEntityName());
        entityAPI.save(entity);

        App app = appAPI.findOne(appEntityVO.getAppId());
        app.getAppEntities().add(entity);
        appAPI.save(app);
        data.put("status", "1");
        data.put("id", entity.getId());
        data.put("message", "Entity Is Successfully Created and Added To The App.");
      } else {
        data.put("status", "-2");
        data.put("message", "App Id and Entity Name Should Not Be Null!!!");
      }
    } catch (Exception e) {
      logger.error(e.getMessage(), e);
      data.put("status", "-1");
      data.put("message", "Creating Entity Was Failed!!!");
    } finally {
      logger.debug("Creating Entity is Ended.");
    }
    return data;
  }