Search in sources :

Example 1 with SimulationTaskRepresentation

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

the class SimulationTasksServerResource method getSimulationTaskRepresentations.

private SimulationTaskRepresentation[] getSimulationTaskRepresentations(User vcellUser) {
    // if (!application.authenticate(getRequest(), getResponse())){
    // // not authenticated
    // return new SimulationTaskRepresentation[0];
    // }else{
    ArrayList<SimulationTaskRepresentation> simTaskReps = new ArrayList<SimulationTaskRepresentation>();
    RestDatabaseService restDatabaseService = ((VCellApiApplication) getApplication()).getRestDatabaseService();
    try {
        SimpleJobStatus[] simJobStatusList = restDatabaseService.query(this, vcellUser);
        for (SimpleJobStatus simpleJobStatus : simJobStatusList) {
            SimulationTaskRepresentation simTaskRep = new SimulationTaskRepresentation(simpleJobStatus);
            simTaskReps.add(simTaskRep);
        }
    } catch (PermissionException ee) {
        throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED, "permission denied to requested resource");
    } catch (DataAccessException e) {
        e.printStackTrace();
        throw new RuntimeException("failed to retrieve active jobs from VCell Database : " + e.getMessage());
    } catch (SQLException e) {
        e.printStackTrace();
        throw new RuntimeException("failed to retrieve active jobs from VCell Database : " + e.getMessage());
    }
    return simTaskReps.toArray(new SimulationTaskRepresentation[0]);
// }
}
Also used : SimulationTaskRepresentation(org.vcell.rest.common.SimulationTaskRepresentation) PermissionException(org.vcell.util.PermissionException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) VCellApiApplication(org.vcell.rest.VCellApiApplication) ResourceException(org.restlet.resource.ResourceException) DataAccessException(org.vcell.util.DataAccessException) SimpleJobStatus(cbit.vcell.server.SimpleJobStatus)

Example 2 with SimulationTaskRepresentation

use of org.vcell.rest.common.SimulationTaskRepresentation 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)

Aggregations

VCellApiApplication (org.vcell.rest.VCellApiApplication)2 SimulationTaskRepresentation (org.vcell.rest.common.SimulationTaskRepresentation)2 SimpleJobStatus (cbit.vcell.server.SimpleJobStatus)1 Gson (com.google.gson.Gson)1 Configuration (freemarker.template.Configuration)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)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 ResourceException (org.restlet.resource.ResourceException)1 DataAccessException (org.vcell.util.DataAccessException)1 PermissionException (org.vcell.util.PermissionException)1 User (org.vcell.util.document.User)1