Search in sources :

Example 1 with SimulationRepresentation

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

the class BiomodelSimulationServerResource method get_json.

@Override
public SimulationRepresentation get_json() {
    VCellApiApplication application = ((VCellApiApplication) getApplication());
    User vcellUser = application.getVCellUser(getChallengeResponse(), AuthenticationPolicy.prohibitInvalidCredentials);
    SimulationRepresentation simulationRep = getBiomodelSimulationRepresentation(vcellUser);
    if (simulationRep != null) {
        return simulationRep;
    }
    throw new RuntimeException("simulation not found");
}
Also used : User(org.vcell.util.document.User) VCellApiApplication(org.vcell.rest.VCellApiApplication) SimulationRepresentation(org.vcell.rest.common.SimulationRepresentation)

Example 2 with SimulationRepresentation

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

the class RestDatabaseService method query.

public SimulationRepresentation query(BiomodelSimulationServerResource resource, User vcellUser) throws SQLException, DataAccessException, ExpressionException, XmlParseException, MappingException, MathException, MatrixException, ModelException {
    if (vcellUser == null) {
        vcellUser = VCellApiApplication.DUMMY_USER;
    }
    ArrayList<String> conditions = new ArrayList<String>();
    String bioModelID = (String) resource.getRequestAttributes().get(VCellApiApplication.BIOMODELID);
    if (bioModelID != null) {
        conditions.add("(" + BioModelTable.table.id.getQualifiedColName() + " = " + bioModelID + ")");
    } else {
        throw new RuntimeException(VCellApiApplication.BIOMODELID + " not specified");
    }
    StringBuffer conditionsBuffer = new StringBuffer();
    for (String condition : conditions) {
        if (conditionsBuffer.length() > 0) {
            conditionsBuffer.append(" AND ");
        }
        conditionsBuffer.append(condition);
    }
    int startRow = 1;
    int maxRows = 1;
    BioModelRep[] bioModelReps = databaseServerImpl.getBioModelReps(vcellUser, conditionsBuffer.toString(), null, startRow, maxRows);
    for (BioModelRep bioModelRep : bioModelReps) {
        KeyValue[] simContextKeys = bioModelRep.getSimContextKeyList();
        for (KeyValue scKey : simContextKeys) {
            SimContextRep scRep = getSimContextRep(scKey);
            if (scRep != null) {
                bioModelRep.addSimContextRep(scRep);
            }
        }
        KeyValue[] simulationKeys = bioModelRep.getSimKeyList();
        for (KeyValue simKey : simulationKeys) {
            SimulationRep simulationRep = getSimulationRep(simKey);
            if (simulationRep != null) {
                bioModelRep.addSimulationRep(simulationRep);
            }
        }
    }
    if (bioModelReps == null || bioModelReps.length != 1) {
        // 
        // try to determine if the current credentials are insufficient, try to fetch BioModel again with administrator privilege.
        // 
        User adminUser = new User(PropertyLoader.ADMINISTRATOR_ACCOUNT, new KeyValue(PropertyLoader.ADMINISTRATOR_ID));
        BioModelRep[] allBioModelReps = databaseServerImpl.getBioModelReps(adminUser, conditionsBuffer.toString(), null, startRow, 1);
        if (allBioModelReps != null && allBioModelReps.length >= 0) {
            throw new PermissionException("insufficient privilege to retrive BioModel " + bioModelID);
        } else {
            throw new RuntimeException("failed to get biomodel");
        }
    }
    String simulationId = (String) resource.getRequestAttributes().get(VCellApiApplication.SIMULATIONID);
    if (simulationId == null) {
        throw new RuntimeException(VCellApiApplication.SIMULATIONID + " not specified");
    }
    SimulationRep simRep = getSimulationRep(new KeyValue(simulationId));
    BigString bioModelXML = databaseServerImpl.getBioModelXML(vcellUser, bioModelReps[0].getBmKey());
    BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(bioModelXML.toString()));
    return new SimulationRepresentation(simRep, bioModel);
}
Also used : PermissionException(org.vcell.util.PermissionException) KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) ArrayList(java.util.ArrayList) BioModelRep(cbit.vcell.modeldb.BioModelRep) BigString(org.vcell.util.BigString) BigString(org.vcell.util.BigString) SimulationRepresentation(org.vcell.rest.common.SimulationRepresentation) BioModel(cbit.vcell.biomodel.BioModel) XMLSource(cbit.vcell.xml.XMLSource) SimContextRep(cbit.vcell.modeldb.SimContextRep) SimulationRep(cbit.vcell.modeldb.SimulationRep)

Example 3 with SimulationRepresentation

use of org.vcell.rest.common.SimulationRepresentation 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]);
}
Also used : SimpleJobStatusQuerySpec(cbit.vcell.server.SimpleJobStatusQuerySpec) KeyValue(org.vcell.util.document.KeyValue) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) RpcSimServerProxy(org.vcell.rest.rpc.RpcSimServerProxy) VCMessageSession(cbit.vcell.message.VCMessageSession) ArrayList(java.util.ArrayList) BigString(org.vcell.util.BigString) PropertyVetoException(java.beans.PropertyVetoException) MatrixException(cbit.vcell.matrix.MatrixException) ParseException(java.text.ParseException) ModelException(cbit.vcell.model.ModelException) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) SQLException(java.sql.SQLException) XmlParseException(cbit.vcell.xml.XmlParseException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) UseridIDExistsException(org.vcell.util.UseridIDExistsException) MappingException(cbit.vcell.mapping.MappingException) MathException(cbit.vcell.math.MathException) ExpressionException(cbit.vcell.parser.ExpressionException) SimpleJobStatus(cbit.vcell.server.SimpleJobStatus) SimulationRepresentation(org.vcell.rest.common.SimulationRepresentation) SimulationDocumentLink(cbit.vcell.server.SimulationDocumentLink) SimulationStatus(cbit.vcell.server.SimulationStatus) UserLoginInfo(org.vcell.util.document.UserLoginInfo) DataAccessException(org.vcell.util.DataAccessException) SimulationRep(cbit.vcell.modeldb.SimulationRep) SimulationStatusRepresentation(org.vcell.rest.common.SimulationStatusRepresentation)

Example 4 with SimulationRepresentation

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

the class BiomodelSimulationServerResource method get_html.

@Override
public Representation get_html() {
    VCellApiApplication application = ((VCellApiApplication) getApplication());
    User vcellUser = application.getVCellUser(getChallengeResponse(), AuthenticationPolicy.ignoreInvalidCredentials);
    SimulationRepresentation simulation = getBiomodelSimulationRepresentation(vcellUser);
    if (simulation == null) {
        throw new RuntimeException("simulation not found");
    }
    Map<String, Object> dataModel = new HashMap<String, Object>();
    dataModel.put("simulation", simulation);
    // +"?"+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());
    }
    Gson gson = new Gson();
    dataModel.put("jsonResponse", gson.toJson(simulation));
    Configuration templateConfiguration = application.getTemplateConfiguration();
    Representation formFtl = new ClientResource(LocalReference.createClapReference("/simulation.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) SimulationRepresentation(org.vcell.rest.common.SimulationRepresentation) Representation(org.restlet.representation.Representation) SimulationRepresentation(org.vcell.rest.common.SimulationRepresentation) VCellApiApplication(org.vcell.rest.VCellApiApplication) ClientResource(org.restlet.resource.ClientResource)

Aggregations

SimulationRepresentation (org.vcell.rest.common.SimulationRepresentation)4 User (org.vcell.util.document.User)3 SimulationRep (cbit.vcell.modeldb.SimulationRep)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 VCellApiApplication (org.vcell.rest.VCellApiApplication)2 BigString (org.vcell.util.BigString)2 PermissionException (org.vcell.util.PermissionException)2 KeyValue (org.vcell.util.document.KeyValue)2 BioModel (cbit.vcell.biomodel.BioModel)1 MappingException (cbit.vcell.mapping.MappingException)1 MathException (cbit.vcell.math.MathException)1 MatrixException (cbit.vcell.matrix.MatrixException)1 VCMessageSession (cbit.vcell.message.VCMessageSession)1 ModelException (cbit.vcell.model.ModelException)1 BioModelRep (cbit.vcell.modeldb.BioModelRep)1 SimContextRep (cbit.vcell.modeldb.SimContextRep)1 ExpressionException (cbit.vcell.parser.ExpressionException)1 SimpleJobStatus (cbit.vcell.server.SimpleJobStatus)1 SimpleJobStatusQuerySpec (cbit.vcell.server.SimpleJobStatusQuerySpec)1