Search in sources :

Example 1 with SimDataRepresentation

use of org.vcell.rest.common.SimDataRepresentation 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 2 with SimDataRepresentation

use of org.vcell.rest.common.SimDataRepresentation in project vcell by virtualcell.

the class SimDataServerResource method getSimDataRepresentation.

private SimDataRepresentation getSimDataRepresentation(User vcellUser) {
    // if (!application.authenticate(getRequest(), getResponse())){
    // // not authenticated
    // return new SimulationTaskRepresentation[0];
    // }else{
    RestDatabaseService restDatabaseService = ((VCellApiApplication) getApplication()).getRestDatabaseService();
    try {
        DataSetMetadata dataSetMetadata = restDatabaseService.getDataSetMetadata(this, vcellUser);
        SimulationRep simRep = restDatabaseService.getSimulationRep(dataSetMetadata.getSimKey());
        SimDataRepresentation simDataRepresentation = new SimDataRepresentation(dataSetMetadata, simRep.getScanCount());
        return simDataRepresentation;
    } catch (PermissionException e) {
        e.printStackTrace();
        throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED, "not authorized");
    } catch (ObjectNotFoundException e) {
        e.printStackTrace();
        throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "simulation metadata not found");
    } catch (Exception e) {
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage());
    }
// }
}
Also used : PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) VCellApiApplication(org.vcell.rest.VCellApiApplication) SimDataRepresentation(org.vcell.rest.common.SimDataRepresentation) ResourceException(org.restlet.resource.ResourceException) DataSetMetadata(cbit.vcell.simdata.DataSetMetadata) SimulationRep(cbit.vcell.modeldb.SimulationRep) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) ResourceException(org.restlet.resource.ResourceException)

Aggregations

ResourceException (org.restlet.resource.ResourceException)2 VCellApiApplication (org.vcell.rest.VCellApiApplication)2 SimDataRepresentation (org.vcell.rest.common.SimDataRepresentation)2 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)2 PermissionException (org.vcell.util.PermissionException)2 SimulationRep (cbit.vcell.modeldb.SimulationRep)1 DataSetMetadata (cbit.vcell.simdata.DataSetMetadata)1 Gson (com.google.gson.Gson)1 Configuration (freemarker.template.Configuration)1 HashMap (java.util.HashMap)1 TemplateRepresentation (org.restlet.ext.freemarker.TemplateRepresentation)1 Representation (org.restlet.representation.Representation)1 ClientResource (org.restlet.resource.ClientResource)1 User (org.vcell.util.document.User)1