use of org.vcell.rest.common.SimulationStatusRepresentation in project vcell by virtualcell.
the class RestDatabaseService method query.
public SimulationStatusRepresentation[] query(SimulationStatusServerResource resource, User vcellUser) throws SQLException, DataAccessException {
if (vcellUser == null) {
vcellUser = VCellApiApplication.DUMMY_USER;
}
String userID = vcellUser.getName();
SimpleJobStatusQuerySpec simQuerySpec = new SimpleJobStatusQuerySpec();
simQuerySpec.userid = userID;
simQuerySpec.simId = resource.getLongQueryValue(SimulationStatusServerResource.PARAM_SIM_ID);
String hasData = resource.getQueryValue(SimulationStatusServerResource.PARAM_HAS_DATA);
if (hasData != null && hasData.equals("yes")) {
simQuerySpec.hasData = true;
} else if (hasData != null && hasData.equals("no")) {
simQuerySpec.hasData = false;
} else {
simQuerySpec.hasData = null;
}
simQuerySpec.waiting = resource.getBooleanQueryValue(SimulationStatusServerResource.PARAM_STATUS_ACTIVE, false);
simQuerySpec.queued = resource.getBooleanQueryValue(SimulationStatusServerResource.PARAM_STATUS_ACTIVE, false);
simQuerySpec.dispatched = resource.getBooleanQueryValue(SimulationStatusServerResource.PARAM_STATUS_ACTIVE, false);
simQuerySpec.running = resource.getBooleanQueryValue(SimulationStatusServerResource.PARAM_STATUS_ACTIVE, false);
simQuerySpec.completed = resource.getBooleanQueryValue(SimulationStatusServerResource.PARAM_STATUS_COMPLETED, false);
simQuerySpec.failed = resource.getBooleanQueryValue(SimulationStatusServerResource.PARAM_STATUS_FAILED, false);
simQuerySpec.stopped = resource.getBooleanQueryValue(SimulationStatusServerResource.PARAM_STATUS_STOPPED, false);
simQuerySpec.submitLowMS = resource.getLongQueryValue(SimulationStatusServerResource.PARAM_SUBMIT_LOW);
simQuerySpec.submitHighMS = resource.getLongQueryValue(SimulationStatusServerResource.PARAM_SUBMIT_HIGH);
simQuerySpec.startLowMS = resource.getLongQueryValue(SimulationStatusServerResource.PARAM_START_LOW);
simQuerySpec.startHighMS = resource.getLongQueryValue(SimulationStatusServerResource.PARAM_START_HIGH);
simQuerySpec.endLowMS = resource.getLongQueryValue(SimulationStatusServerResource.PARAM_END_LOW);
simQuerySpec.endHighMS = resource.getLongQueryValue(SimulationStatusServerResource.PARAM_END_HIGH);
Long startRowParam = resource.getLongQueryValue(SimulationStatusServerResource.PARAM_START_ROW);
// default
simQuerySpec.startRow = 1;
if (startRowParam != null) {
simQuerySpec.startRow = startRowParam.intValue();
}
Long maxRowsParam = resource.getLongQueryValue(SimulationTasksServerResource.PARAM_MAX_ROWS);
// default
simQuerySpec.maxRows = 10;
if (maxRowsParam != null) {
simQuerySpec.maxRows = maxRowsParam.intValue();
}
SimulationStatus[] simStatuses = null;
HashMap<KeyValue, SimulationDocumentLink> simDocLinks = new HashMap<KeyValue, SimulationDocumentLink>();
//
// ask server for simJobStatuses with above query spec.
// find set of simulation IDs from the result set of simJobStatus
// ask server for simulationStatuses from list of sim IDs.
//
VCMessageSession rpcSession = vcMessagingService.createProducerSession();
try {
UserLoginInfo userLoginInfo = new UserLoginInfo(vcellUser.getName(), null);
try {
userLoginInfo.setUser(vcellUser);
} catch (Exception e) {
e.printStackTrace();
throw new DataAccessException(e.getMessage());
}
RpcSimServerProxy rpcSimServerProxy = new RpcSimServerProxy(userLoginInfo, rpcSession);
SimpleJobStatus[] simpleJobStatusArray = rpcSimServerProxy.getSimpleJobStatus(vcellUser, simQuerySpec);
// gather unique simIDs and go back and ask server for SimulationStatuses
for (SimpleJobStatus simpleJobStatus : simpleJobStatusArray) {
KeyValue simulationKey = simpleJobStatus.jobStatus.getVCSimulationIdentifier().getSimulationKey();
SimulationDocumentLink simulationDocumentLink = simpleJobStatus.simulationDocumentLink;
simDocLinks.put(simulationKey, simulationDocumentLink);
}
KeyValue[] simKeys = simDocLinks.keySet().toArray(new KeyValue[0]);
if (simKeys.length > 0) {
simStatuses = rpcSimServerProxy.getSimulationStatus(vcellUser, simKeys);
}
} finally {
rpcSession.close();
}
ArrayList<SimulationStatusRepresentation> simStatusReps = new ArrayList<SimulationStatusRepresentation>();
for (int i = 0; simStatuses != null && i < simStatuses.length; i++) {
KeyValue simulationKey = simStatuses[i].getVCSimulationIdentifier().getSimulationKey();
SimulationRep simRep = getSimulationRep(simulationKey);
try {
SimulationRepresentation simRepresentation = new SimulationRepresentation(simRep, simDocLinks.get(simulationKey));
simStatusReps.add(new SimulationStatusRepresentation(simRepresentation, simStatuses[i]));
} catch (ExpressionException e) {
e.printStackTrace(System.out);
}
}
return simStatusReps.toArray(new SimulationStatusRepresentation[0]);
}
use of org.vcell.rest.common.SimulationStatusRepresentation 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;
}
Aggregations