當前位置: 首頁>>代碼示例>>Java>>正文


Java Controller.ok方法代碼示例

本文整理匯總了Java中play.mvc.Controller.ok方法的典型用法代碼示例。如果您正苦於以下問題:Java Controller.ok方法的具體用法?Java Controller.ok怎麽用?Java Controller.ok使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在play.mvc.Controller的用法示例。


在下文中一共展示了Controller.ok方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getInitialValueResponse

import play.mvc.Controller; //導入方法依賴的package包/類
/**
 * Return the response to a request for the initial values to be displayed
 * 
 * @return a JSON response
 */
public Result getInitialValueResponse(JsonNode json) {
    ObjectNode result = Json.newObject();

    // Get the values passed as parameters
    ArrayList<T> values = new ArrayList<T>();
    JsonNode valuesNode = json.get("values");
    if (valuesNode != null) {
        for (JsonNode node : valuesNode) {
            values.add(convertNodeToT(node));
        }
    }

    // Get context parameters
    HashMap<String, String> context = extractContextFromJsonRequest(json);

    // Create the return structure
    ISelectableValueHolderCollection<T> valueHolders = getHandle().getInitialValueHolders(values, context);
    valueHolderCollectionToJson(result, valueHolders);

    return Controller.ok(result);
}
 
開發者ID:theAgileFactory,項目名稱:app-framework,代碼行數:27,代碼來源:PickerHandler.java

示例2: downloadFileAttachment

import play.mvc.Controller; //導入方法依賴的package包/類
/**
 * This method is to be integrated within a controller.<br/>
 * It looks for the specified attachment and returns it if the user is
 * allowed to access it.
 * 
 * @param attachmentId
 *            the id of an attachment
 * @param attachmentManagerPlugin
 *            the service which is managing attachments
 * @param sessionManagerPlugin
 *            the service which is managing user sessions
 * @return the attachment as a stream
 */
public static Result downloadFileAttachment(Long attachmentId, IAttachmentManagerPlugin attachmentManagerPlugin,
        IUserSessionManagerPlugin sessionManagerPlugin) {
    @SuppressWarnings("unchecked")
    Set<Long> allowedIds = (Set<Long>) Cache
            .get(IFrameworkConstants.ATTACHMENT_READ_AUTHZ_CACHE_PREFIX + sessionManagerPlugin.getUserSessionId(Controller.ctx()));
    if (allowedIds != null && allowedIds.contains(attachmentId)) {
        try {
            Attachment attachment = attachmentManagerPlugin.getAttachmentFromId(attachmentId);

            if (attachment.mimeType.equals(FileAttachmentHelper.FileType.URL.name())) {
                return Controller.redirect(attachment.path);
            } else {
                Controller.response().setHeader("Content-Disposition", "attachment; filename=\"" + attachment.name + "\"");
                return Controller.ok(attachmentManagerPlugin.getAttachmentContent(attachmentId));
            }
        } catch (IOException e) {
            log.error("Error while retreiving the attachment content for " + attachmentId);
            return Controller.badRequest();
        }
    }
    return Controller.badRequest();
}
 
開發者ID:theAgileFactory,項目名稱:app-framework,代碼行數:36,代碼來源:FileAttachmentHelper.java

示例3: deleteFileAttachment

import play.mvc.Controller; //導入方法依賴的package包/類
/**
 * This method is to be integrated within a controller.<br/>
 * It looks for the specified attachment and delete it if the user is
 * allowed to erase it.<br/>
 * It is to be called by an AJAX GET with a single attribute : the id of the
 * attachment.
 *
 * @param attachmentId
 *            the id of an attachment
 * @param attachmentManagerPlugin
 *            the service which is managing attachments
 * @param sessionManagerPlugin
 *            the service which is managing user sessions
 * @return the result
 */
public static Result deleteFileAttachment(Long attachmentId, IAttachmentManagerPlugin attachmentManagerPlugin,
        IUserSessionManagerPlugin sessionManagerPlugin) {
    @SuppressWarnings("unchecked")
    Set<Long> allowedIds = (Set<Long>) Cache
            .get(IFrameworkConstants.ATTACHMENT_WRITE_AUTHZ_CACHE_PREFIX + sessionManagerPlugin.getUserSessionId(Controller.ctx()));
    if (allowedIds != null && allowedIds.contains(attachmentId)) {
        try {
            attachmentManagerPlugin.deleteAttachment(attachmentId);
            return Controller.ok();
        } catch (IOException e) {
            log.error("Error while deleting the attachment content for " + attachmentId);
            return Controller.badRequest();
        }
    }
    return Controller.badRequest();
}
 
開發者ID:theAgileFactory,項目名稱:app-framework,代碼行數:32,代碼來源:FileAttachmentHelper.java

示例4: getConfigResponse

import play.mvc.Controller; //導入方法依賴的package包/類
/**
 * Return the response to the initial configuration
 * 
 * @return a JSON response
 */
public Result getConfigResponse() {
    ObjectNode result = Json.newObject();
    Map<PickerHandler.Parameters, String> configParameters = getHandle().config(getParameters());
    if (configParameters != null) {
        for (Parameters configParameterName : configParameters.keySet()) {
            if (configParameterName.name().endsWith(I18N_PARAMETER_SUFFIX)) {
                result.put(configParameterName.name(), Msg.get(configParameters.get(configParameterName)));
            } else {
                result.put(configParameterName.name(), configParameters.get(configParameterName));
            }
        }
    }
    return Controller.ok(result);
}
 
開發者ID:theAgileFactory,項目名稱:app-framework,代碼行數:20,代碼來源:PickerHandler.java

示例5: getSearchResponse

import play.mvc.Controller; //導入方法依賴的package包/類
/**
 * Return the response to a request for the initial values to be displayed
 * 
 * @return a JSON response
 */
public Result getSearchResponse(JsonNode json) {
    ObjectNode result = Json.newObject();

    // Get context parameters
    HashMap<String, String> context = extractContextFromJsonRequest(json);

    ISelectableValueHolderCollection<T> valueHolders = getHandle().getFoundValueHolders(json.get("searchString").asText(), context);
    valueHolderCollectionToJson(result, valueHolders);
    return Controller.ok(result);
}
 
開發者ID:theAgileFactory,項目名稱:app-framework,代碼行數:16,代碼來源:PickerHandler.java

示例6: getFileStreamResult

import play.mvc.Controller; //導入方法依賴的package包/類
public static Result getFileStreamResult(FileDAO dao, int fileId) {
    be.ugent.degage.db.models.File file = dao.getFile(fileId);
    if (file != null) {
        try {
            FileInputStream is = new FileInputStream(Paths.get(UPLOAD_FOLDER, file.getPath()).toFile()); //TODO: this cannot be sent with a Try-with-resources (stream already closed), check if Play disposes properly
            return file.getContentType() != null && !file.getContentType().isEmpty() ? Controller.ok(is).as(file.getContentType()) : Controller.ok(is);
        } catch (FileNotFoundException e) {
            Logger.error("Missing file: " + file.getPath());
            return Controller.notFound();
        }
    } else {
        return Controller.notFound();
    }
}
 
開發者ID:degage,項目名稱:degapp,代碼行數:15,代碼來源:FileHelper.java

示例7: trend

import play.mvc.Controller; //導入方法依賴的package包/類
@Override
public Result trend(Context ctx) {

    String uid = ctx.request().getQueryString("kpiUid");
    Long objectId = Long.valueOf(ctx.request().getQueryString("objectId"));

    Kpi kpi = getKpi(uid);

    Date startDate = null;
    Date endDate = null;

    Triple<List<KpiData>, List<KpiData>, List<KpiData>> datas = kpi.getTrendData(objectId);
    Pair<String, List<KpiData>> staticTrendLine = kpi.getKpiRunner().getStaticTrendLine(this.getPreferenceManagerPlugin(), getScriptService(), kpi,
            objectId);

    SeriesContainer<TimeValueItem> seriesContainer = null;

    if (staticTrendLine != null || (datas.getLeft() != null && datas.getLeft().size() > 0) || (datas.getMiddle() != null && datas.getMiddle().size() > 0)
            || (datas.getRight() != null && datas.getRight().size() > 0)) {

        seriesContainer = new SeriesContainer<TimeValueItem>();

        if (datas.getLeft() != null && datas.getLeft().size() > 0) {
            addTrendSerieAndValues(seriesContainer, kpi, DataType.MAIN, datas.getLeft());
        }

        if (datas.getMiddle() != null && datas.getMiddle().size() > 0) {
            addTrendSerieAndValues(seriesContainer, kpi, DataType.ADDITIONAL1, datas.getMiddle());
        }

        if (datas.getRight() != null && datas.getRight().size() > 0) {
            addTrendSerieAndValues(seriesContainer, kpi, DataType.ADDITIONAL2, datas.getRight());
        }

        if (staticTrendLine != null) {
            framework.highcharts.data.Serie<TimeValueItem> timeSerie = new framework.highcharts.data.Serie<TimeValueItem>(
                    getMessagesPlugin().get(staticTrendLine.getLeft()));
            seriesContainer.addSerie(timeSerie);
            for (KpiData kpiData : staticTrendLine.getRight()) {
                timeSerie.add(new TimeValueItem(HighchartsUtils.convertToUTCAndClean(kpiData.timestamp), kpiData.value.doubleValue()));
            }

        }

        Pair<Date, Date> period = kpi.getKpiRunner().getTrendPeriod(this.getPreferenceManagerPlugin(), getScriptService(), kpi, objectId);
        if (period != null) {
            startDate = period.getLeft();
            endDate = period.getRight();
        }

    }

    return Controller.ok(views.html.framework_views.parts.kpi.display_kpi_trend.render(uid, seriesContainer, startDate, endDate));
}
 
開發者ID:theAgileFactory,項目名稱:app-framework,代碼行數:55,代碼來源:KpiServiceImpl.java


注:本文中的play.mvc.Controller.ok方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。