Java Code Examples for play.mvc.Results#notFound()

The following examples show how to use play.mvc.Results#notFound() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractJudgelsAPIController.java    From judgels with GNU General Public License v2.0 6 votes vote down vote up
protected static Result okAsDownload(String resourceUrl) {
    try {
        new URL(resourceUrl);
        return redirect(resourceUrl);
    } catch (MalformedURLException e) {
        File resource = new File(resourceUrl);
        if (!resource.exists()) {
            return Results.notFound();
        }

        response().setContentType("application/x-download");
        response().setHeader("Content-disposition", "attachment; filename=" + resource.getName());

        return ok(resource);
    }
}
 
Example 2
Source File: ClientLessonAPIControllerV2.java    From judgels with GNU General Public License v2.0 6 votes vote down vote up
@Transactional(readOnly = true)
public Result getLessonStatement(String lessonJid) throws IOException {
    authenticateAsJudgelsAppClient(clientChecker);

    if (!lessonService.lessonExistsByJid(lessonJid)) {
        return Results.notFound();
    }

    String language = sanitizeLanguageCode(lessonJid, DynamicForm.form().bindFromRequest().get("language"));

    LessonStatement statement = lessonService.getStatement(null, lessonJid, language);

    judgels.sandalphon.api.lesson.LessonStatement result = new judgels.sandalphon.api.lesson.LessonStatement.Builder()
            .title(statement.getTitle())
            .text(statement.getText())
            .build();

    return okAsJson(result);
}
 
Example 3
Source File: NewspaperController.java    From NationStatesPlusPlus with MIT License 6 votes vote down vote up
public Result findNewspaper(String region) throws SQLException {
	region = Utils.sanitizeName(region);
	int regionId = getDatabase().getRegionId(region);
	if (regionId != -1) {
		try (Connection conn = getConnection()) {
			JsonNode newspaper = Json.toJson(getNewspaper(conn, getDatabase().getRegionId(region)));
			if (newspaper != null) {
				Result r = Utils.handleDefaultGetHeaders(request(), response(), String.valueOf(newspaper.hashCode()), "300");
				if (r != null) {
					return r;
				}
				return ok(newspaper).as("application/json");
			}
		}
	}
	Utils.handleDefaultPostHeaders(request(), response());
	response().setHeader("Cache-Control", "public, max-age=300");
	return Results.notFound();
}
 
Example 4
Source File: AbstractJudgelsController.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
protected static Result getResult(LazyHtml content, int statusCode) {
    HtmlCompressor htmlCompressor = new HtmlCompressor();
    Html compressedContent = new Html(htmlCompressor.compress(content.render().body()));
    switch (statusCode) {
        case Http.Status.OK:
            return Results.ok(compressedContent);
        case Http.Status.NOT_FOUND:
            return Results.notFound(compressedContent);
        default:
            return Results.badRequest(compressedContent);
    }
}
 
Example 5
Source File: LessonControllerUtils.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
public static Result downloadFile(File file) {
    if (!file.exists()) {
        return Results.notFound();
    }
    Controller.response().setContentType("application/x-download");
    Controller.response().setHeader("Content-disposition", "attachment; filename=" + file.getName());
    return Results.ok(file);
}
 
Example 6
Source File: ClientProblemAPIControllerV2.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@Transactional(readOnly = true)
public Result getProblem(String problemJid) throws IOException {
    authenticateAsJudgelsAppClient(clientChecker);

    if (!problemService.problemExistsByJid(problemJid)) {
        return Results.notFound();
    }

    return okAsJson(getProblemInfo(problemJid));
}
 
Example 7
Source File: ClientProblemAPIControllerV2.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@Transactional(readOnly = true)
public Result getProblemSubmissionConfig(String problemJid) {
    authenticateAsJudgelsAppClient(clientChecker);

    if (!problemService.problemExistsByJid(problemJid)) {
        return Results.notFound();
    }

    return okAsJson(getSubmissionConfig(problemJid));
}
 
Example 8
Source File: ClientProblemAPIControllerV2.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@Transactional(readOnly = true)
public Result getProgrammingProblemWorksheet(String problemJid) throws IOException {
    authenticateAsJudgelsAppClient(clientChecker);

    if (!problemService.problemExistsByJid(problemJid)) {
        return Results.notFound();
    }

    Problem problem = problemService.findProblemByJid(problemJid);
    if (ProblemType.valueOf(problem.getType().name()) != ProblemType.PROGRAMMING) {
        return Results.notFound();
    }

    judgels.sandalphon.api.problem.programming.ProblemWorksheet.Builder result =
            new judgels.sandalphon.api.problem.programming.ProblemWorksheet.Builder();

    ProblemSubmissionConfig submissionConfig = getSubmissionConfig(problemJid);
    result.submissionConfig(submissionConfig);

    GradingConfig config = getBlackBoxGradingConfig(problemJid, submissionConfig.getGradingEngine());

    String language = sanitizeLanguageCode(problemJid, DynamicForm.form().bindFromRequest().get("language"));

    ProblemStatement statement = problemService.getStatement(null, problemJid, language);
    result.statement(statement);

    ProblemLimits limits = new ProblemLimits.Builder()
            .timeLimit(config.getTimeLimit())
            .memoryLimit(config.getMemoryLimit())
            .build();
    result.limits(limits);

    return okAsJson(result.build());
}
 
Example 9
Source File: ClientLessonAPIControllerV2.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@Transactional(readOnly = true)
public Result getLesson(String lessonJid) throws IOException {
    authenticateAsJudgelsAppClient(clientChecker);

    if (!lessonService.lessonExistsByJid(lessonJid)) {
        return Results.notFound();
    }

    return okAsJson(getLessonInfo(lessonJid));
}
 
Example 10
Source File: InternalProgrammingProblemGradingAPIController.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@Transactional(readOnly = true)
public Result downloadGradingTestDataFile(long problemId, String filename) throws ProblemNotFoundException {
    Problem problem = problemService.findProblemById(problemId);

    if (!ProgrammingProblemControllerUtils.isAllowedToManageGrading(problemService, problem)) {
        return Results.notFound();
    }

    String testDataUrl = programmingProblemService.getGradingTestDataFileURL(IdentityUtils.getUserJid(), problem.getJid(), filename);

    return okAsDownload(testDataUrl);
}
 
Example 11
Source File: InternalProgrammingProblemGradingAPIController.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@Transactional(readOnly = true)
public Result downloadGradingHelperFile(long problemId, String filename) throws ProblemNotFoundException {
    Problem problem = problemService.findProblemById(problemId);

    if (!ProgrammingProblemControllerUtils.isAllowedToManageGrading(problemService, problem)) {
        return Results.notFound();
    }

    String helper = programmingProblemService.getGradingHelperFileURL(IdentityUtils.getUserJid(), problem.getJid(), filename);

    return okAsDownload(helper);
}
 
Example 12
Source File: ClientProblemAPIControllerV2.java    From judgels with GNU General Public License v2.0 4 votes vote down vote up
@Transactional(readOnly = true)
public Result getBundleProblemWorksheet(String problemJid) throws IOException {
    authenticateAsJudgelsAppClient(clientChecker);
    if (!problemService.problemExistsByJid(problemJid)) {
        return Results.notFound();
    }

    Problem problem = problemService.findProblemByJid(problemJid);
    if (ProblemType.valueOf(problem.getType().name()) != ProblemType.BUNDLE) {
        return Results.notFound();
    }

    String language = sanitizeLanguageCode(problemJid, DynamicForm.form().bindFromRequest().get("language"));

    ProblemStatement statement = problemService.getStatement(null, problemJid, language);

    List<BundleItem> items = bundleItemService.getBundleItemsInProblemWithClone(problemJid, null);
    List<Item> itemsWithConfig = new ArrayList<>();
    for (BundleItem item : items) {
        String itemConfigString = bundleItemService.getItemConfInProblemWithCloneByJid(
                problemJid, null, item.getJid(), language);
        ItemType type = ItemType.valueOf(item.getType().name());
        Optional<Integer> number = item.getNumber() == null
                ? Optional.empty()
                : Optional.of(item.getNumber().intValue());

        Item itemWithConfig = new Item.Builder()
                .jid(item.getJid())
                .type(type)
                .number(number)
                .meta(item.getMeta())
                .config(itemProcessorRegistry.get(type).parseItemConfigFromString(MAPPER, itemConfigString))
                .build();
        itemsWithConfig.add(itemWithConfig);
    }

    return okAsJson(
            new judgels.sandalphon.api.problem.bundle.ProblemWorksheet.Builder()
                    .statement(statement)
                    .items(itemsWithConfig)
                    .build()
    );
}