Java 类play.mvc.BodyParser 实例源码

项目:premier-wherehows    文件:LineageController.java   
@BodyParser.Of(BodyParser.Json.class)
public static Result addJobLineage() {
  JsonNode lineage = request().body().asJson();
  ObjectNode resultJson = Json.newObject();

  try {

    LineageDaoLite.insertLineage(lineage);

    resultJson.put("return_code", 200);
    resultJson.put("message", "Lineage inserted!");
    Logger.info("lineage inserted");
  } catch (Exception e) {

    ContrUtil.failure(resultJson, e.getMessage());

    Logger.error("caught exception", e);
    Logger.info("Post JSON for insertion failure: " + lineage.toString());
  }
  return ok(resultJson);
}
项目:wherehowsX    文件:DatasetController.java   
@BodyParser.Of(BodyParser.Json.class)
public static Result addDataset() {
  JsonNode dataset = request().body().asJson();
  ObjectNode resultJson = Json.newObject();
  try {
    DatasetDao.setDatasetRecord(dataset);
    resultJson.put("return_code", 200);
    resultJson.put("message", "Dataset inserted!");
  } catch (Exception e) {
    e.printStackTrace();
    resultJson.put("return_code", 404);
    resultJson.put("error_message", e.getMessage());
  }

  return ok(resultJson);
}
项目:wherehowsX    文件:DatasetController.java   
@BodyParser.Of(BodyParser.Json.class)
public static Result getDatasetDependency() {
  String queryString = request().getQueryString("query");
  JsonNode input = Json.parse(queryString);
  ObjectNode resultJson = Json.newObject();

  try {
    resultJson = DatasetDao.getDatasetDependency(input);
  } catch (Exception e) {
    Logger.error(e.getMessage());
    resultJson.put("return_code", 404);
    resultJson.put("error_message", e.getMessage());
  }

  return ok(resultJson);
}
项目:wherehowsX    文件:LineageController.java   
@BodyParser.Of(BodyParser.Json.class)
public static Result addJobLineage() {
  JsonNode lineage = request().body().asJson();
  ObjectNode resultJson = Json.newObject();
  try {
    LineageDao.insertLineage(lineage);
    resultJson.put("return_code", 200);
    resultJson.put("message", "Lineage inserted!");
  } catch (Exception e) {
    e.printStackTrace();
    resultJson.put("return_code", 404);
    resultJson.put("error_message", e.getMessage());
  }

  return ok(resultJson);
}
项目:exam    文件:QuestionController.java   
@BodyParser.Of(BodyParser.Json.class)
@Restrict({@Group("TEACHER"), @Group("ADMIN")})
public Result updateQuestion(Long id) {
    User user = getLoggedUser();
    ExpressionList<Question> query = Ebean.find(Question.class).where().idEq(id);
    if (user.hasRole("TEACHER", getSession())) {
        query = query.disjunction()
                .eq("shared", true)
                .eq("questionOwners", user)
                .eq("examSectionQuestions.examSection.exam.examOwners", user)
                .endJunction();
    }
    Question question = query.findUnique();
    if (question == null) {
        return forbidden("sitnet_error_access_forbidden");
    }
    JsonNode body = request().body().asJson();
    Question updatedQuestion = parseFromBody(body, user, question);
    return question.getValidationResult(body).orElseGet(() -> {
        if (updatedQuestion.getType() != Question.Type.EssayQuestion) {
            processOptions(updatedQuestion, (ArrayNode) body.get("options"));
        }
        updatedQuestion.update();
        return ok(Json.toJson(updatedQuestion));
    });
}
项目:diferentonas-server    文件:MensagemController.java   
@Transactional
  @BodyParser.Of(BodyParser.Json.class)
  public Result save() {

    Cidadao cidadao = daoCidadao
        .find(UUID.fromString(request().username()));
if (!cidadao.isFuncionario()) {
    return unauthorized("Cidadão não autorizado");
}

      Form<Mensagem> form = formFactory.form(Mensagem.class).bindFromRequest();
      if (form.hasErrors()) {
          String recebido = Controller.request().body().asJson().toString();
          if (recebido.length() > 30) {
              recebido = recebido.substring(0, 30) + "...";
          }
          Logger.debug("Submissão com erros: " + recebido + "; Erros: " + form.errorsAsJson());
          return badRequest(form.errorsAsJson());
      }

      Mensagem mensagem = daoMensagem.create(form.get());
      mensagem.setAutor(cidadao.getMinisterioDeAfiliacao());

      return created(toJson(mensagem));
  }
项目:ground    文件:StructureController.java   
@BodyParser.Of(BodyParser.Json.class)
public final CompletionStage<Result> addStructure() {
  return CompletableFuture.supplyAsync(
    () -> {
      JsonNode json = request().body().asJson();
      Structure structure = Json.fromJson(json, Structure.class);

      try {
        structure = this.postgresStructureDao.create(structure);
      } catch (GroundException e) {
        throw new CompletionException(e);
      }
      return Json.toJson(structure);
    },

    PostgresUtils.getDbSourceHttpContext(this.actorSystem))
           .thenApply(Results::created)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:StructureController.java   
@BodyParser.Of(BodyParser.Json.class)
public final CompletionStage<Result> addStructureVersion() {
  return CompletableFuture.supplyAsync(
    () -> {
      JsonNode json = request().body().asJson();

      List<Long> parentIds = GroundUtils.getListFromJson(json, "parentIds");
      ((ObjectNode) json).remove("parentIds");

      StructureVersion structureVersion = Json.fromJson(json, StructureVersion.class);

      try {
        structureVersion = this.postgresStructureVersionDao.create(structureVersion, parentIds);
      } catch (GroundException e) {
        throw new CompletionException(e);
      }
      return Json.toJson(structureVersion);
    },
    PostgresUtils.getDbSourceHttpContext(this.actorSystem))
           .thenApply(Results::created)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:LineageEdgeController.java   
@BodyParser.Of(BodyParser.Json.class)
public final CompletionStage<Result> createLineageEdge() {
  return CompletableFuture.supplyAsync(
    () -> {
      JsonNode json = request().body().asJson();
      LineageEdge lineageEdge = Json.fromJson(json, LineageEdge.class);
      try {
        lineageEdge = this.postgresLineageEdgeDao.create(lineageEdge);
      } catch (GroundException e) {
        throw new CompletionException(e);
      }
      return Json.toJson(lineageEdge);
    },
    PostgresUtils.getDbSourceHttpContext(this.actorSystem))
           .thenApply(Results::created)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:LineageGraphController.java   
@BodyParser.Of(BodyParser.Json.class)
public final CompletionStage<Result> createLineageGraph() {
  return CompletableFuture.supplyAsync(
    () -> {
      JsonNode json = request().body().asJson();
      LineageGraph lineageGraph = Json.fromJson(json, LineageGraph.class);
      try {
        lineageGraph = this.postgresLineageGraphDao.create(lineageGraph);
      } catch (GroundException e) {
        throw new CompletionException(e);
      }
      return Json.toJson(lineageGraph);
    },
    PostgresUtils.getDbSourceHttpContext(this.actorSystem))
           .thenApply(Results::created)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:GraphController.java   
@BodyParser.Of(BodyParser.Json.class)
public final CompletionStage<Result> addGraph() {
  return CompletableFuture.supplyAsync(
    () -> {
      JsonNode json = request().body().asJson();
      Graph graph = Json.fromJson(json, Graph.class);

      try {
        graph = this.postgresGraphDao.create(graph);
      } catch (GroundException e) {
        throw new CompletionException(e);
      }

      return Json.toJson(graph);
    },
    PostgresUtils.getDbSourceHttpContext(actorSystem))
           .thenApply(Results::created)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:GraphController.java   
@BodyParser.Of(BodyParser.Json.class)
public final CompletionStage<Result> addGraphVersion() {
  return CompletableFuture.supplyAsync(
    () -> {
      JsonNode json = request().body().asJson();
      List<Long> parentIds = GroundUtils.getListFromJson(json, "parentIds");
      ((ObjectNode) json).remove("parentIds");
      GraphVersion graphVersion = Json.fromJson(json, GraphVersion.class);

      try {
        graphVersion = this.postgresGraphVersionDao.create(graphVersion, parentIds);
      } catch (GroundException e) {
        throw new CompletionException(e);
      }
      return Json.toJson(graphVersion);
    },
    PostgresUtils.getDbSourceHttpContext(actorSystem))
           .thenApply(Results::ok)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:EdgeController.java   
@BodyParser.Of(BodyParser.Json.class)
public final CompletionStage<Result> addEdge() {
  return CompletableFuture.supplyAsync(
    () -> {
      JsonNode json = request().body().asJson();
      Edge edge = Json.fromJson(json, Edge.class);

      try {
        edge = this.postgresEdgeDao.create(edge);
      } catch (GroundException e) {
        throw new CompletionException(e);
      }

      return Json.toJson(edge);
    },
    PostgresUtils.getDbSourceHttpContext(this.actorSystem))
           .thenApply(Results::created)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:EdgeController.java   
@BodyParser.Of(BodyParser.Json.class)
public final CompletionStage<Result> addEdgeVersion() {
  return CompletableFuture.supplyAsync(
    () -> {
      JsonNode json = request().body().asJson();
      List<Long> parentIds = GroundUtils.getListFromJson(json, "parentIds");

      ((ObjectNode) json).remove("parentIds");
      EdgeVersion edgeVersion = Json.fromJson(json, EdgeVersion.class);

      try {
        edgeVersion = this.postgresEdgeVersionDao.create(edgeVersion, parentIds);
      } catch (GroundException e) {
        throw new CompletionException(e);
      }

      return Json.toJson(edgeVersion);
    },
    PostgresUtils.getDbSourceHttpContext(actorSystem))
           .thenApply(Results::created)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:NodeController.java   
@BodyParser.Of(BodyParser.Json.class)
public final CompletionStage<Result> addNode() {
  return CompletableFuture.supplyAsync(
    () -> {
      JsonNode json = request().body().asJson();
      Node node = Json.fromJson(json, Node.class);
      try {
        node = this.postgresNodeDao.create(node);
      } catch (GroundException e) {
        throw new CompletionException(e);
      }
      return Json.toJson(node);
    },
    PostgresUtils.getDbSourceHttpContext(this.actorSystem))
           .thenApply(Results::created)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:NodeController.java   
@BodyParser.Of(BodyParser.Json.class)
public final CompletionStage<Result> addNodeVersion() {
  return CompletableFuture.supplyAsync(
    () -> {
      JsonNode json = request().body().asJson();

      List<Long> parentIds = GroundUtils.getListFromJson(json, "parentIds");
      ((ObjectNode) json).remove("parentIds");
      NodeVersion nodeVersion = Json.fromJson(json, NodeVersion.class);

      try {
        nodeVersion = this.postgresNodeVersionDao.create(nodeVersion, parentIds);
      } catch (GroundException e) {
        e.printStackTrace();
        throw new CompletionException(e);
      }
      return Json.toJson(nodeVersion);
    },
    PostgresUtils.getDbSourceHttpContext(this.actorSystem))
           .thenApply(Results::created)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:maf-desktop-app    文件:DashboardController.java   
/**
 * Add a new dashboard page.<br/>
 * This is a JSON post of the following format:
 * 
 * <pre>
 * {@code
 *      {name : "pageName", "isHome" : true}
 * }
 * </pre>
 * 
 * @return the id of the newly created page as JSON
 */
@BodyParser.Of(BodyParser.Json.class)
public Promise<Result> addNewDashboardPage() {
    return Promise.promise(new Function0<Result>() {
        @Override
        public Result apply() throws Throwable {
            try {
                JsonNode json = request().body().asJson();
                List<DashboardRowConfiguration> defaultConfig = new ArrayList<>();
                DashboardRowConfiguration row = new DashboardRowConfiguration();
                row.setLayout(DashboardRowTemplate.TPL12COL_1);
                row.setWidgets(Arrays.asList(new WidgetConfiguration(-1L, null, null)));
                defaultConfig.add(row);
                Long newDashboardPageId = getDashboardService().createDashboardPage(null, json.get("name").asText(), json.get("isHome").asBoolean(),
                        defaultConfig);
                JsonNode node = getObjectMapper().readTree("{\"id\" : " + newDashboardPageId + "}");
                return ok(node);
            } catch (Exception e) {
                log.error("Unable to add a new dashboard page", e);
                return badRequest();
            }
        }
    });

}
项目:maf-desktop-app    文件:DashboardController.java   
/**
 * Update the dashboard page configuration.<br/>
 * This method expects a POST with a JSON structure.
 * 
 * @param dashboardPageId
 *            the unique id of a dashboard page
 * @return
 */
@BodyParser.Of(BodyParser.Json.class)
public Promise<Result> updateDashboardPage(Long dashboardPageId) {
    return Promise.promise(new Function0<Result>() {
        @Override
        public Result apply() throws Throwable {
            try {
                JsonNode json = request().body().asJson();
                List<DashboardRowConfiguration> dashboardPageConfiguration = getObjectMapper().readValue(json.toString(),
                        new TypeReference<List<DashboardRowConfiguration>>() {
                });
                getDashboardService().updateDashboardPageConfiguration(dashboardPageId, null, dashboardPageConfiguration);
                return ok();
            } catch (Exception e) {
                log.error("Unable to update the dashboard page", e);
                return badRequest();
            }
        }
    });
}
项目:maf-desktop-app    文件:DashboardController.java   
/**
 * Create a new widget from the specified widget identifier and return the
 * widget id as a JSON structure.
 * 
 * <pre>
 * {@code
 *  {widgetId : 1}
 * }
 * </pre>
 * 
 * A POST parameter (as JSON is expected) : a widget entry.
 * 
 * @param dashboardPageId
 *            the unique Id for the dashboard page which is to be associated
 *            with this widget
 * @return JSON structure
 */
@BodyParser.Of(BodyParser.Json.class)
public Promise<Result> createNewWidget(Long dashboardPageId) {
    return Promise.promise(new Function0<Result>() {
        @Override
        public Result apply() throws Throwable {
            try {
                JsonNode json = request().body().asJson();
                WidgetCatalogEntry widgetCatalogEntry = getObjectMapper().readValue(json.toString(), WidgetCatalogEntry.class);
                Pair<Long, String> widgetConfig = getDashboardService().createNewWidget(dashboardPageId, null, widgetCatalogEntry, "A title");
                JsonNode node = getObjectMapper().readTree("{\"id\" : " + widgetConfig.getLeft() + ",\"url\" : \"" + widgetConfig.getRight()
                        + "\",\"identifier\" : \"" + widgetCatalogEntry.getIdentifier() + "\"}");
                return ok(node);
            } catch (Exception e) {
                log.error("Unable to create a new widget", e);
                return badRequest();
            }
        }
    });
}
项目:todo    文件:Todo.java   
@BodyParser.Of(BodyParser.Json.class)
public static Result update(Long id) {
    ObjectNode result = Json.newObject();

    models.Todo entity = models.Todo.find.byId(id.toString());
    Form<TodoForm> form = form(TodoForm.class).bindFromRequest();
    TodoForm todoForm = form.get();
    if (todoForm.title != null) {
        entity.setTitle(todoForm.title);
    }
    if (todoForm.note != null) {
        entity.setNote(todoForm.note);
    }
    entity.setUpdatedAt(System.currentTimeMillis());
    entity.update();

    result.put("result", 0);
    return ok(result);
}
项目:WhereHows    文件:DatasetController.java   
@BodyParser.Of(BodyParser.Json.class)
public static Result addDataset() {
  JsonNode dataset = request().body().asJson();
  ObjectNode resultJson = Json.newObject();
  try {
    DatasetDao.setDatasetRecord(dataset);
    resultJson.put("return_code", 200);
    resultJson.put("message", "Dataset inserted!");
  } catch (Exception e) {
    e.printStackTrace();
    resultJson.put("return_code", 404);
    resultJson.put("error_message", e.getMessage());
  }

  return ok(resultJson);
}
项目:WhereHows    文件:DatasetController.java   
@BodyParser.Of(BodyParser.Json.class)
public static Result getDatasetDependency() {
  String queryString = request().getQueryString("query");
  JsonNode input = Json.parse(queryString);
  ObjectNode resultJson = Json.newObject();

  try {
    resultJson = DatasetDao.getDatasetDependency(input);
  } catch (Exception e) {
    Logger.error(e.getMessage());
    resultJson.put("return_code", 404);
    resultJson.put("error_message", e.getMessage());
  }

  return ok(resultJson);
}
项目:WhereHows    文件:LineageController.java   
@BodyParser.Of(BodyParser.Json.class)
public static Result addJobLineage() {
  JsonNode lineage = request().body().asJson();
  ObjectNode resultJson = Json.newObject();
  try {
    LineageDao.insertLineage(lineage);
    resultJson.put("return_code", 200);
    resultJson.put("message", "Lineage inserted!");
  } catch (Exception e) {
    e.printStackTrace();
    resultJson.put("return_code", 404);
    resultJson.put("error_message", e.getMessage());
  }

  return ok(resultJson);
}
项目:Localizr    文件:Recommendation.java   
@BodyParser.Of(BodyParser.Json.class)
public static Result index() {
    try {
        // retrieve request
        JsonNode json = request().body().asJson();

        // get ressource-uri
        String resource = json.findPath("name").textValue();    

        // Workaroudn: deal with the doubles quotes from json string
        resource=resource.substring(1, resource.length()-1);

        // retrieve POI
        POIList list = GeoNamesRecommendation.retrieveRecommendedData(resource);

        // serve
        return ok(list.getJSON());

    } catch (Exception e) {
        return badRequest(e.getMessage());
    }
}
项目:PlayTraining    文件:Frontoffice.java   
/**
 * Get the list of {@link Film}.
 *
 * @throws Exception
 */
// @Cached(key = "list", duration = DURATION) => Pose un problème car ne tient pas compte du paramètrage
@BodyParser.Of(BodyParser.Json.class)
@play.db.jpa.Transactional(readOnly = true)
public static Result list(final String genre, final int size) throws Exception {
    PerfLogger perf = PerfLogger.start("http.frontoffice.list[{}]", genre + "," + size);
    Result result = Cache.getOrElse("list." + genre + ".size" + size, new Callable<Result>() {
        @Override
        public Result call() throws Exception {
            play.Logger.info("La requête [{}] ne fait pas appel au Cache", request().path());
            return ok(Json.toJson(Film.findBy(genre, size)));
        }
    }, DURATION);
    perf.stop();
    return result;
}
项目:PlayTraining    文件:Frontoffice.java   
/**
 * Get a {@link Film} by id.<br>
 * Can use @Cached annotation as
 *
 * @throws Exception
 */
// @Cached(key = "detail", duration = DURATION) => Pose un problème car ne tient pas compte du paramètrage
@BodyParser.Of(BodyParser.Json.class)
@play.db.jpa.Transactional(readOnly = true)
public static Result get(final Long id) throws Exception {
    PerfLogger perf = PerfLogger.start("http.frontoffice.get[{}]", id);
    Result result = Cache.getOrElse("detail." + id, new Callable<Result>() {
        @Override
        public Result call() throws Exception {
            play.Logger.info("La requête [{}] ne fait pas appel au Cache", request().path());
            return ok(Json.toJson(Film.findById(id)));
        }
    }, DURATION);
    perf.stop();
    return result;
}
项目:twistrating    文件:Application.java   
@BodyParser.Of(BodyParser.Json.class)
public Result rateTwist() {
    JsonNode json = request().body().asJson();
    String twistId = json.get("id").asText();
    int rating = json.get("rating").asInt(-1);

    if( ! hasBeenRated(twistId, rating)) {
        System.out.println("RATE " + twistId + " : " + rating);
        twistRating.rateTwist(twistId, rating);
    } else {
        changeRating(twistId, rating);
    }

    Twist twist = Twist.find.byId(twistId);
    return ok(toJson(twist));
}
项目:play-oauth2    文件:SecurityController.java   
@BodyParser.Of(BodyParser.Json.class)
public Promise<Result> authenticateClient() {
  JsonNode json = request().body().asJson();
  String clientId = json.findPath("clientId").textValue();
  String clientSecret = json.findPath("clientSecret").textValue();

  UsernamePasswordAuthenticationToken authRequest =
      new UsernamePasswordAuthenticationToken(clientId, clientSecret);
  clientAuthenticationManager.authenticate(authRequest);

  ClientDetails clientDetails = clientDetailsService.loadClientByClientId(clientId);
  TokenRequest tokenRequest = new TokenRequest(Collections.emptyMap(), clientId,
      clientDetails.getScope(), "password");
  OAuth2AccessToken token = tokenGranter.grant("client_credentials", tokenRequest);

  ObjectNode result = Json.newObject();
  result.setAll(ImmutableMap.of(
      "accessToken", result.textNode(token.getValue()),
      "clientId", result.textNode(clientId),
      "expiration", result.numberNode(token.getExpiration().getTime())));
  return Promise.pure(ok(result));
}
项目:play-oauth2    文件:SecurityController.java   
@BodyParser.Of(BodyParser.Json.class)
@PreAuthorize("#oauth2.clientHasRole('ROLE_CLIENT') and #oauth2.hasScope('trust')")
public Promise<Result> authenticateUser() {
  JsonNode json = request().body().asJson();
  String username = json.findPath("username").textValue();
  String password = json.findPath("password").textValue();

  Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
  OAuth2Request clientAuthenticationRequest =
      ((OAuth2Authentication) authentication).getOAuth2Request();
  Map<String, String> requestParameters = new HashMap<>();
  requestParameters.put("username", username);
  requestParameters.put("password", password);
  TokenRequest tokenRequest = new TokenRequest(requestParameters,
          clientAuthenticationRequest.getClientId(), clientAuthenticationRequest.getScope(),
          "password");
  OAuth2AccessToken token = tokenGranter.grant("password", tokenRequest);
  ObjectNode result = Json.newObject();
  result.setAll(ImmutableMap.of(
      "accessToken", result.textNode(token.getValue()),
      "username", result.textNode(username),
      "expiration", result.numberNode(token.getExpiration().getTime()),
      "refreshToken", result.textNode(token.getRefreshToken().getValue())));
  return Promise.pure(ok(result));
}
项目:play-oauth2    文件:SecurityController.java   
@BodyParser.Of(BodyParser.Json.class)
@PreAuthorize("#oauth2.clientHasRole('ROLE_CLIENT') and #oauth2.hasScope('trust')")
public Promise<Result> refreshUserAccessToken() {
  JsonNode body = request().body().asJson();
  String refreshToken = body.findPath("refreshToken").textValue();

  Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
  OAuth2Request clientAuthenticationRequest =
      ((OAuth2Authentication) authentication).getOAuth2Request();
  TokenRequest tokenRequest =
      new TokenRequest(Collections.emptyMap(), clientAuthenticationRequest.getClientId(),
          clientAuthenticationRequest.getScope(), "refresh");
  OAuth2AccessToken token = tokenServices.refreshAccessToken(refreshToken, tokenRequest);
  ObjectNode result = Json.newObject();
  result.setAll(ImmutableMap.of(
      "accessToken", result.textNode(token.getValue()),
      "expiration", result.numberNode(token.getExpiration().getTime()),
      "refreshToken", result.textNode(token.getRefreshToken().getValue())));
  return Promise.pure(ok(result));
}
项目:geo-publisher    文件:Styles.java   
@BodyParser.Of (value = BodyParser.Raw.class, maxLength = 2 * 1024 * 1024)
public static Result handleFileUploadRaw () {
    final String content = request ().body ().asRaw () != null 
            ? handleFileUpload (request ().body ().asRaw ().asFile ()) 
            : null;

    final ObjectNode result = Json.newObject ();
    if (content == null) {
        result.put ("valid", false);
    } else {
        result.put ("valid", true);
        result.put ("textContent", content);
    }

    return ok (result);
}
项目:colosseum    文件:SecurityController.java   
@Transactional @BodyParser.Of(BodyParser.Json.class) public Result authenticateApi() {
    final Form<LoginDto> filledForm = loginForm.bindFromRequest();
    if (filledForm.hasErrors()) {
        return badRequest(filledForm.errorsAsJson());
    }
    //generate a new token
    Token token = tokenService
        .newToken(this.frontendUserService.getByMail(filledForm.get().getEmail()));

    ObjectNode result = Json.newObject();
    result.put("createdOn", token.createdOn());
    result.put("expiresAt", token.expiresAt());
    result.put("token", token.token());
    result.put("userId", token.userId());
    return ok(result);
}
项目:w3act    文件:TargetController.java   
/**
 * @param frequency
 * @param whether to generate the paywall feed or not - i.e. this can exclude paywalled Targets, or be composed only of paywalled Targets.
 * @return
 * @throws ActException
 */
@BodyParser.Of(BodyParser.Json.class)
public static Result crawlFeedLdFrequencyJson(String frequency, boolean generatePaywallFeed) {
    JsonNode jsonData = null;
    if(frequency != null) {
        List<Target> targets = new ArrayList<Target>();
        targets = Target.exportLdFrequency(frequency);
        List<CrawlFeedItem> targetIds = new ArrayList<CrawlFeedItem>();
        for(Target t : targets) {
            // Only add 
            if(!generatePaywallFeed && t.secretId == null) {
                targetIds.add(new CrawlFeedItem(t));
            } else if( generatePaywallFeed && t.secretId != null) {
                targetIds.add(new CrawlFeedItem(t));
            }
        }
        jsonData = Json.toJson(targetIds);
    }
    return ok(jsonData);
}
项目:premier-wherehows    文件:PropertyController.java   
@BodyParser.Of(BodyParser.Json.class)
public static Result addAssignProp() {
    JsonNode props = request().body().asJson();
    ObjectNode resultJson = Json.newObject();
    try {
        PropertyDao.addAssignProp(props);
        resultJson.put("return_code", 200);
        resultJson.put("message", "Assignment Property inserted!");
    } catch (Exception e) {
        e.printStackTrace();
        ContrUtil.failure(resultJson, e.getMessage());
    }

    return ok(resultJson);
}
项目:premier-wherehows    文件:PropertyController.java   
@BodyParser.Of(BodyParser.Json.class)
public static Result updateAssignProp() {
    JsonNode props = request().body().asJson();
    ObjectNode resultJson = Json.newObject();
    try {
        PropertyDao.updateAssignProp(props);
        resultJson.put("return_code", 200);
        resultJson.put("message", "Assignment Property updated!");
    } catch (Exception e) {
        e.printStackTrace();
        ContrUtil.failure(resultJson, e.getMessage());
    }

    return ok(resultJson);
}
项目:premier-wherehows    文件:PropertyController.java   
@BodyParser.Of(BodyParser.Json.class)
public static Result addSortListProp() {
    JsonNode props = request().body().asJson();
    ObjectNode resultJson = Json.newObject();
    try {
        PropertyDao.addSortListProp(props);
        resultJson.put("return_code", 200);
        resultJson.put("message", "Sort List Property inserted!");
    } catch (Exception e) {
        e.printStackTrace();
        ContrUtil.failure(resultJson, e.getMessage());
    }

    return ok(resultJson);
}
项目:premier-wherehows    文件:PropertyController.java   
@BodyParser.Of(BodyParser.Json.class)
public static Result updateSortListProp() {
    JsonNode props = request().body().asJson();
    ObjectNode resultJson = Json.newObject();
    try {
        PropertyDao.updateSortListProp(props);
        resultJson.put("return_code", 200);
        resultJson.put("message", "Sort List Property updated!");
    } catch (Exception e) {
        ContrUtil.failure(resultJson, 404, e.getMessage());
        Logger.error(e.getMessage());        }

    return ok(resultJson);
}
项目:premier-wherehows    文件:PropertyController.java   
@BodyParser.Of(BodyParser.Json.class)
public static Result postProperty(String base, String attr) {
    JsonNode prop = request().body().asJson();
    ObjectNode resultJson = Json.newObject();
    try {
        PropertyDao.addProp(prop, base, attr, attr);
        resultJson.put("return_code", 200);
        resultJson.put("message", base + " " + attr + " inserted!");
    } catch (Exception e) {
        ContrUtil.failure(resultJson, e.getMessage());
        Logger.error(e.getMessage());
    }

    return ok(resultJson);
}
项目:premier-wherehows    文件:PropertyController.java   
@BodyParser.Of(BodyParser.Json.class)
public static Result putProperty(String base, String attr) {
    JsonNode prop = request().body().asJson();
    ObjectNode resultJson = Json.newObject();
    try {
        PropertyDao.updateProp(prop, base, attr, attr);
        resultJson.put("return_code", 200);
        resultJson.put("message", base + " " + attr + " updated!");
    } catch (Exception e) {
        ContrUtil.failure(resultJson, e.getMessage());
        Logger.error(e.getMessage());
    }

    return ok(resultJson);
}
项目:premier-wherehows    文件:PropertyController.java   
@BodyParser.Of(BodyParser.Json.class)
public static Result removeProperty() {
    JsonNode prop = request().body().asJson();
    ObjectNode resultJson = Json.newObject();
    try {
        PropertyDao.removeProperty(prop);
        resultJson.put("return_code", 200);
        resultJson.put("message", "property removed");
    } catch (Exception e) {
        Logger.error("exception when trying to remove property:", e);
        ContrUtil.failure(resultJson, e.getMessage());
    }
    return ok(resultJson);
}