Search in sources :

Example 76 with Representation

use of org.restlet.representation.Representation in project vcell by virtualcell.

the class PublicationServerResource method get_html.

@Override
public Representation get_html() {
    VCellApiApplication application = ((VCellApiApplication) getApplication());
    User vcellUser = application.getVCellUser(getChallengeResponse(), AuthenticationPolicy.ignoreInvalidCredentials);
    PublicationRepresentation publication = getPublicationRepresentation(vcellUser);
    if (publication == null) {
        throw new RuntimeException("publication not found");
    }
    Map<String, Object> dataModel = new HashMap<String, Object>();
    // +"?"+VCellApiApplication.REDIRECTURL_FORMNAME+"="+getRequest().getResourceRef().toUrl());
    dataModel.put("loginurl", "/" + VCellApiApplication.LOGINFORM);
    dataModel.put("logouturl", "/" + VCellApiApplication.LOGOUT + "?" + VCellApiApplication.REDIRECTURL_FORMNAME + "=" + Reference.encode(getRequest().getResourceRef().toUrl().toString()));
    if (vcellUser != null) {
        dataModel.put("userid", vcellUser.getName());
    }
    dataModel.put("pubId", getQueryValue(VCellApiApplication.PUBLICATIONID));
    dataModel.put("publication", publication);
    Gson gson = new Gson();
    dataModel.put("jsonResponse", gson.toJson(publication));
    Configuration templateConfiguration = application.getTemplateConfiguration();
    Representation formFtl = new ClientResource(LocalReference.createClapReference("/publication.ftl")).get();
    TemplateRepresentation templateRepresentation = new TemplateRepresentation(formFtl, templateConfiguration, dataModel, MediaType.TEXT_HTML);
    return templateRepresentation;
}
Also used : TemplateRepresentation(org.restlet.ext.freemarker.TemplateRepresentation) User(org.vcell.util.document.User) Configuration(freemarker.template.Configuration) HashMap(java.util.HashMap) Gson(com.google.gson.Gson) TemplateRepresentation(org.restlet.ext.freemarker.TemplateRepresentation) PublicationRepresentation(org.vcell.rest.common.PublicationRepresentation) Representation(org.restlet.representation.Representation) PublicationRepresentation(org.vcell.rest.common.PublicationRepresentation) VCellApiApplication(org.vcell.rest.VCellApiApplication) ClientResource(org.restlet.resource.ClientResource)

Example 77 with Representation

use of org.restlet.representation.Representation in project vcell by virtualcell.

the class SimDataServerResource method get_html.

@Override
public Representation get_html() {
    VCellApiApplication application = ((VCellApiApplication) getApplication());
    User vcellUser = application.getVCellUser(getChallengeResponse(), AuthenticationPolicy.ignoreInvalidCredentials);
    SimDataRepresentation simData = null;
    try {
        simData = getSimDataRepresentation(vcellUser);
    } catch (Exception e) {
        e.printStackTrace(System.out);
    }
    Map<String, Object> dataModel = new HashMap<String, Object>();
    // +"?"+VCellApiApplication.REDIRECTURL_FORMNAME+"="+getRequest().getResourceRef().toUrl());
    dataModel.put("loginurl", "/" + VCellApiApplication.LOGINFORM);
    dataModel.put("logouturl", "/" + VCellApiApplication.LOGOUT + "?" + VCellApiApplication.REDIRECTURL_FORMNAME + "=" + Reference.encode(getRequest().getResourceRef().toUrl().toString()));
    if (vcellUser != null) {
        dataModel.put("userid", vcellUser.getName());
    }
    dataModel.put("userId", getAttribute(PARAM_USER));
    dataModel.put("simId", getQueryValue(PARAM_SIM_ID));
    Long startRowParam = getLongQueryValue(PARAM_START_ROW);
    if (startRowParam != null) {
        dataModel.put("startRow", startRowParam);
    } else {
        dataModel.put("startRow", 1);
    }
    Long maxRowsParam = getLongQueryValue(PARAM_MAX_ROWS);
    if (maxRowsParam != null) {
        dataModel.put("maxRows", maxRowsParam);
    } else {
        dataModel.put("maxRows", 10);
    }
    dataModel.put("simdata", simData);
    Gson gson = new Gson();
    dataModel.put("jsonResponse", gson.toJson(simData));
    Configuration templateConfiguration = application.getTemplateConfiguration();
    Representation formFtl = new ClientResource(LocalReference.createClapReference("/simdata.ftl")).get();
    TemplateRepresentation templateRepresentation = new TemplateRepresentation(formFtl, templateConfiguration, dataModel, MediaType.TEXT_HTML);
    return templateRepresentation;
}
Also used : TemplateRepresentation(org.restlet.ext.freemarker.TemplateRepresentation) User(org.vcell.util.document.User) Configuration(freemarker.template.Configuration) HashMap(java.util.HashMap) Gson(com.google.gson.Gson) SimDataRepresentation(org.vcell.rest.common.SimDataRepresentation) TemplateRepresentation(org.restlet.ext.freemarker.TemplateRepresentation) SimDataRepresentation(org.vcell.rest.common.SimDataRepresentation) Representation(org.restlet.representation.Representation) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) ResourceException(org.restlet.resource.ResourceException) VCellApiApplication(org.vcell.rest.VCellApiApplication) ClientResource(org.restlet.resource.ClientResource)

Example 78 with Representation

use of org.restlet.representation.Representation in project vcell by virtualcell.

the class SimulationStatusServerResource method get_html.

@Override
public Representation get_html() {
    VCellApiApplication application = ((VCellApiApplication) getApplication());
    User vcellUser = application.getVCellUser(getChallengeResponse(), AuthenticationPolicy.ignoreInvalidCredentials);
    SimulationStatusRepresentation[] simStatuses = getSimulationStatusRepresentations(vcellUser);
    Map<String, Object> dataModel = new HashMap<String, Object>();
    // +"?"+VCellApiApplication.REDIRECTURL_FORMNAME+"="+getRequest().getResourceRef().toUrl());
    dataModel.put("loginurl", "/" + VCellApiApplication.LOGINFORM);
    dataModel.put("logouturl", "/" + VCellApiApplication.LOGOUT + "?" + VCellApiApplication.REDIRECTURL_FORMNAME + "=" + Reference.encode(getRequest().getResourceRef().toUrl().toString()));
    if (vcellUser != null) {
        dataModel.put("userid", vcellUser.getName());
    }
    dataModel.put("userId", getAttribute(PARAM_USER));
    dataModel.put("simId", getQueryValue(PARAM_SIM_ID));
    dataModel.put("hasData", getQueryValue(PARAM_HAS_DATA));
    dataModel.put("neverran", getBooleanQueryValue(PARAM_STATUS_NEVERRAN, false));
    dataModel.put("active", getBooleanQueryValue(PARAM_STATUS_ACTIVE, false));
    dataModel.put("completed", getBooleanQueryValue(PARAM_STATUS_COMPLETED, false));
    dataModel.put("failed", getBooleanQueryValue(PARAM_STATUS_FAILED, false));
    dataModel.put("stopped", getBooleanQueryValue(PARAM_STATUS_STOPPED, false));
    dataModel.put("submitLow", getLongQueryValue(PARAM_SUBMIT_LOW));
    dataModel.put("submitHigh", getLongQueryValue(PARAM_SUBMIT_HIGH));
    dataModel.put("startLow", getLongQueryValue(PARAM_START_LOW));
    dataModel.put("startHigh", getLongQueryValue(PARAM_START_HIGH));
    dataModel.put("endLow", getLongQueryValue(PARAM_END_LOW));
    dataModel.put("endHigh", getLongQueryValue(PARAM_END_HIGH));
    Long startRowParam = getLongQueryValue(PARAM_START_ROW);
    if (startRowParam != null) {
        dataModel.put("startRow", startRowParam);
    } else {
        dataModel.put("startRow", 1);
    }
    Long maxRowsParam = getLongQueryValue(PARAM_MAX_ROWS);
    if (maxRowsParam != null) {
        dataModel.put("maxRows", maxRowsParam);
    } else {
        dataModel.put("maxRows", 10);
    }
    dataModel.put("simStatuses", Arrays.asList(simStatuses));
    Gson gson = new Gson();
    dataModel.put("jsonResponse", gson.toJson(simStatuses));
    Configuration templateConfiguration = application.getTemplateConfiguration();
    Representation formFtl = new ClientResource(LocalReference.createClapReference("/simulationStatus.ftl")).get();
    TemplateRepresentation templateRepresentation = new TemplateRepresentation(formFtl, templateConfiguration, dataModel, MediaType.TEXT_HTML);
    return templateRepresentation;
}
Also used : TemplateRepresentation(org.restlet.ext.freemarker.TemplateRepresentation) User(org.vcell.util.document.User) Configuration(freemarker.template.Configuration) HashMap(java.util.HashMap) Gson(com.google.gson.Gson) TemplateRepresentation(org.restlet.ext.freemarker.TemplateRepresentation) SimulationStatusRepresentation(org.vcell.rest.common.SimulationStatusRepresentation) Representation(org.restlet.representation.Representation) VCellApiApplication(org.vcell.rest.VCellApiApplication) ClientResource(org.restlet.resource.ClientResource) SimulationStatusRepresentation(org.vcell.rest.common.SimulationStatusRepresentation)

Example 79 with Representation

use of org.restlet.representation.Representation in project vcell by virtualcell.

the class SimulationTasksServerResource method get_html.

@Override
public Representation get_html() {
    VCellApiApplication application = ((VCellApiApplication) getApplication());
    User vcellUser = application.getVCellUser(getChallengeResponse(), AuthenticationPolicy.ignoreInvalidCredentials);
    SimulationTaskRepresentation[] simTasks = getSimulationTaskRepresentations(vcellUser);
    Map<String, Object> dataModel = new HashMap<String, Object>();
    // +"?"+VCellApiApplication.REDIRECTURL_FORMNAME+"="+getRequest().getResourceRef().toUrl());
    dataModel.put("loginurl", "/" + VCellApiApplication.LOGINFORM);
    dataModel.put("logouturl", "/" + VCellApiApplication.LOGOUT + "?" + VCellApiApplication.REDIRECTURL_FORMNAME + "=" + Reference.encode(getRequest().getResourceRef().toUrl().toString()));
    if (vcellUser != null) {
        dataModel.put("userid", vcellUser.getName());
    }
    dataModel.put("userId", getAttribute(PARAM_USER));
    dataModel.put("simId", getQueryValue(PARAM_SIM_ID));
    dataModel.put("jobId", getLongQueryValue(PARAM_JOB_ID));
    dataModel.put("taskId", getLongQueryValue(PARAM_TASK_ID));
    dataModel.put("computeHost", getQueryValue(PARAM_COMPUTE_HOST));
    dataModel.put("serverId", getQueryValue(PARAM_SERVER_ID));
    dataModel.put("hasData", getQueryValue(PARAM_HAS_DATA));
    dataModel.put("waiting", getBooleanQueryValue(PARAM_STATUS_WAITING, false));
    dataModel.put("queued", getBooleanQueryValue(PARAM_STATUS_QUEUED, false));
    dataModel.put("dispatched", getBooleanQueryValue(PARAM_STATUS_DISPATCHED, false));
    dataModel.put("running", getBooleanQueryValue(PARAM_STATUS_RUNNING, false));
    dataModel.put("completed", getBooleanQueryValue(PARAM_STATUS_COMPLETED, false));
    dataModel.put("failed", getBooleanQueryValue(PARAM_STATUS_FAILED, false));
    dataModel.put("stopped", getBooleanQueryValue(PARAM_STATUS_STOPPED, false));
    dataModel.put("submitLow", getLongQueryValue(PARAM_SUBMIT_LOW));
    dataModel.put("submitHigh", getLongQueryValue(PARAM_SUBMIT_HIGH));
    dataModel.put("startLow", getLongQueryValue(PARAM_START_LOW));
    dataModel.put("startHigh", getLongQueryValue(PARAM_START_HIGH));
    dataModel.put("endLow", getLongQueryValue(PARAM_END_LOW));
    dataModel.put("endHigh", getLongQueryValue(PARAM_END_HIGH));
    Long startRowParam = getLongQueryValue(PARAM_START_ROW);
    if (startRowParam != null) {
        dataModel.put("startRow", startRowParam);
    } else {
        dataModel.put("startRow", 1);
    }
    Long maxRowsParam = getLongQueryValue(PARAM_MAX_ROWS);
    if (maxRowsParam != null) {
        dataModel.put("maxRows", maxRowsParam);
    } else {
        dataModel.put("maxRows", 10);
    }
    dataModel.put("simTasks", Arrays.asList(simTasks));
    Gson gson = new Gson();
    dataModel.put("jsonResponse", gson.toJson(simTasks));
    Configuration templateConfiguration = application.getTemplateConfiguration();
    Representation formFtl = new ClientResource(LocalReference.createClapReference("/simulationTasks.ftl")).get();
    TemplateRepresentation templateRepresentation = new TemplateRepresentation(formFtl, templateConfiguration, dataModel, MediaType.TEXT_HTML);
    return templateRepresentation;
}
Also used : TemplateRepresentation(org.restlet.ext.freemarker.TemplateRepresentation) User(org.vcell.util.document.User) Configuration(freemarker.template.Configuration) HashMap(java.util.HashMap) Gson(com.google.gson.Gson) TemplateRepresentation(org.restlet.ext.freemarker.TemplateRepresentation) SimulationTaskRepresentation(org.vcell.rest.common.SimulationTaskRepresentation) Representation(org.restlet.representation.Representation) SimulationTaskRepresentation(org.vcell.rest.common.SimulationTaskRepresentation) VCellApiApplication(org.vcell.rest.VCellApiApplication) ClientResource(org.restlet.resource.ClientResource)

Example 80 with Representation

use of org.restlet.representation.Representation in project xwiki-platform by xwiki.

the class AbstractFormUrlEncodedAnnotationRequestReader method readFrom.

@Override
public T readFrom(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
    ObjectFactory objectFactory = new ObjectFactory();
    T annotationRequest = getReadObjectInstance(objectFactory);
    Representation representation = new InputRepresentation(entityStream, org.restlet.data.MediaType.APPLICATION_WWW_FORM);
    Form form = new Form(representation);
    /*
         * If the form is empty then it might have happened that some filter has invalidated the entity stream. Try to
         * read data using getParameter()
         */
    if (!form.getNames().isEmpty()) {
        for (String paramName : form.getNames()) {
            for (String paramValue : form.getValuesArray(paramName)) {
                saveField(annotationRequest, paramName, paramValue, objectFactory);
            }
        }
    } else {
        HttpServletRequest httpServletRequest = ServletUtils.getRequest(Request.getCurrent());
        for (Map.Entry<String, String[]> entry : httpServletRequest.getParameterMap().entrySet()) {
            // skip method & media parameters, used by REST to carry its own parameters
            if ("method".equals(entry.getKey()) || "media".equals(entry.getKey())) {
                continue;
            }
            // save all the values of this field, one by one
            String[] paramValues = entry.getValue();
            for (String value : paramValues) {
                saveField(annotationRequest, entry.getKey(), value, objectFactory);
            }
        }
    }
    return annotationRequest;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ObjectFactory(org.xwiki.annotation.rest.model.jaxb.ObjectFactory) InputRepresentation(org.restlet.representation.InputRepresentation) Form(org.restlet.data.Form) InputRepresentation(org.restlet.representation.InputRepresentation) Representation(org.restlet.representation.Representation) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) Map(java.util.Map)

Aggregations

Representation (org.restlet.representation.Representation)101 HashMap (java.util.HashMap)28 Test (org.testng.annotations.Test)27 StringRepresentation (org.restlet.representation.StringRepresentation)24 Request (org.restlet.Request)23 Response (org.restlet.Response)23 JacksonRepresentation (org.restlet.ext.jackson.JacksonRepresentation)23 ResourceException (org.restlet.resource.ResourceException)21 Reference (org.restlet.data.Reference)19 StringWriter (java.io.StringWriter)17 JsonRepresentation (org.restlet.ext.json.JsonRepresentation)16 IOException (java.io.IOException)14 Map (java.util.Map)14 Form (org.restlet.data.Form)14 VCellApiApplication (org.vcell.rest.VCellApiApplication)14 User (org.vcell.util.document.User)13 Configuration (freemarker.template.Configuration)10 StringReader (java.io.StringReader)10 ZNRecord (org.apache.helix.ZNRecord)10 TypeReference (org.codehaus.jackson.type.TypeReference)10