Search in sources :

Example 31 with ObjectNotFoundException

use of org.vcell.util.ObjectNotFoundException in project vcell by virtualcell.

the class BiomodelServerResource method getBiomodelRepresentation.

private BiomodelRepresentation getBiomodelRepresentation(User vcellUser) {
    // if (!application.authenticate(getRequest(), getResponse())){
    // // not authenticated
    // return new SimulationTaskRepresentation[0];
    // }else{
    RestDatabaseService restDatabaseService = ((VCellApiApplication) getApplication()).getRestDatabaseService();
    try {
        BioModelRep bioModelRep = restDatabaseService.query(this, vcellUser);
        BiomodelRepresentation biomodelRep = new BiomodelRepresentation(bioModelRep);
        return biomodelRep;
    } catch (PermissionException e) {
        e.printStackTrace();
        throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED, "permission denied to requested resource");
    } catch (ObjectNotFoundException e) {
        e.printStackTrace();
        throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "biomodel not found");
    } catch (Exception e) {
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage());
    }
// }
}
Also used : BiomodelRepresentation(org.vcell.rest.common.BiomodelRepresentation) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) VCellApiApplication(org.vcell.rest.VCellApiApplication) BioModelRep(cbit.vcell.modeldb.BioModelRep) ResourceException(org.restlet.resource.ResourceException) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) ResourceException(org.restlet.resource.ResourceException)

Example 32 with ObjectNotFoundException

use of org.vcell.util.ObjectNotFoundException in project vcell by virtualcell.

the class BiomodelSimulationSaveServerResource method save.

@Override
public void save(JsonRepresentation jsonOverrides) throws JSONException {
    VCellApiApplication application = ((VCellApiApplication) getApplication());
    User vcellUser = application.getVCellUser(getChallengeResponse(), AuthenticationPolicy.prohibitInvalidCredentials);
    ArrayList<OverrideRepresentation> overrideRepresentations = new ArrayList<OverrideRepresentation>();
    if (jsonOverrides != null && jsonOverrides.getMediaType().isCompatible(MediaType.APPLICATION_JSON)) {
        JSONObject obj = jsonOverrides.getJsonObject();
        JSONArray overrideArray = obj.getJSONArray("overrides");
        for (int i = 0; i < overrideArray.length(); i++) {
            JSONObject overrideObj = overrideArray.getJSONObject(i);
            String name = overrideObj.getString("name");
            String type = overrideObj.getString("type");
            int cardinality = overrideObj.getInt("cardinality");
            double[] values = new double[0];
            if (overrideObj.has("values")) {
                JSONArray valuesArray = overrideObj.getJSONArray("values");
                values = new double[valuesArray.length()];
                for (int j = 0; j < valuesArray.length(); j++) {
                    values[j] = valuesArray.getDouble(j);
                }
            }
            String expression = null;
            if (overrideObj.has("expression")) {
                expression = overrideObj.getString("expression");
            }
            OverrideRepresentation overrideRep = new OverrideRepresentation(name, type, cardinality, values, expression);
            overrideRepresentations.add(overrideRep);
        }
    }
    RestDatabaseService restDatabaseService = application.getRestDatabaseService();
    try {
        if (vcellUser == null) {
            throw new PermissionException("must be authenticated to copy simulation");
        }
        SimulationSaveResponse simulationSavedResponse = restDatabaseService.saveSimulation(this, vcellUser, overrideRepresentations);
        JSONObject responseJson = new JSONObject();
        String redirectURL = "/" + VCellApiApplication.BIOMODEL + "/" + simulationSavedResponse.newBioModel.getVersion().getVersionKey() + "/" + VCellApiApplication.SIMULATION + "/" + simulationSavedResponse.newSimulation.getKey().toString();
        responseJson.put("redirect", redirectURL);
        responseJson.put("status", "simulation saved");
        JsonRepresentation representation = new JsonRepresentation(responseJson);
        redirectSeeOther(redirectURL);
    // return representation;
    } catch (PermissionException e) {
        e.printStackTrace();
        throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED, "not authorized to save simulation");
    } catch (ObjectNotFoundException e) {
        e.printStackTrace();
        throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "simulation not found");
    } catch (Exception e) {
        e.printStackTrace(System.out);
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage());
    }
}
Also used : PermissionException(org.vcell.util.PermissionException) User(org.vcell.util.document.User) SimulationSaveResponse(org.vcell.rest.server.RestDatabaseService.SimulationSaveResponse) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) OverrideRepresentation(org.vcell.rest.common.OverrideRepresentation) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) JSONException(org.json.JSONException) ResourceException(org.restlet.resource.ResourceException) JSONObject(org.json.JSONObject) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) VCellApiApplication(org.vcell.rest.VCellApiApplication) ResourceException(org.restlet.resource.ResourceException) JsonRepresentation(org.restlet.ext.json.JsonRepresentation)

Example 33 with ObjectNotFoundException

use of org.vcell.util.ObjectNotFoundException in project vcell by virtualcell.

the class BiomodelSimulationStartServerResource method start.

@Override
public Representation start() {
    VCellApiApplication application = ((VCellApiApplication) getApplication());
    User vcellUser = application.getVCellUser(getChallengeResponse(), AuthenticationPolicy.prohibitInvalidCredentials);
    RestDatabaseService restDatabaseService = application.getRestDatabaseService();
    try {
        SimulationRep simRep = restDatabaseService.startSimulation(this, vcellUser);
        Representation representation = new StringRepresentation("simulation started", MediaType.TEXT_PLAIN);
        redirectSeeOther("/" + VCellApiApplication.SIMTASK + "?" + SimulationTasksServerResource.PARAM_SIM_ID + "=" + simRep.getKey().toString() + "&" + SimulationTasksServerResource.PARAM_STATUS_COMPLETED + "=on" + "&" + SimulationTasksServerResource.PARAM_STATUS_DISPATCHED + "=on" + "&" + SimulationTasksServerResource.PARAM_STATUS_FAILED + "=on" + "&" + SimulationTasksServerResource.PARAM_STATUS_QUEUED + "=on" + "&" + SimulationTasksServerResource.PARAM_STATUS_RUNNING + "=on" + "&" + SimulationTasksServerResource.PARAM_STATUS_STOPPED + "=on" + "&" + SimulationTasksServerResource.PARAM_STATUS_WAITING + "=on" + "&" + SimulationTasksServerResource.PARAM_START_ROW + "=1" + "&" + SimulationTasksServerResource.PARAM_MAX_ROWS + "=" + Integer.toString(simRep.getScanCount() * 4));
        return representation;
    } catch (PermissionException e) {
        e.printStackTrace();
        throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED, "not authorized to start simulation");
    } catch (ObjectNotFoundException e) {
        e.printStackTrace();
        throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "simulation not found");
    } catch (Exception e) {
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage());
    }
}
Also used : PermissionException(org.vcell.util.PermissionException) User(org.vcell.util.document.User) StringRepresentation(org.restlet.representation.StringRepresentation) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) VCellApiApplication(org.vcell.rest.VCellApiApplication) StringRepresentation(org.restlet.representation.StringRepresentation) Representation(org.restlet.representation.Representation) ResourceException(org.restlet.resource.ResourceException) SimulationRep(cbit.vcell.modeldb.SimulationRep) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) ResourceException(org.restlet.resource.ResourceException)

Example 34 with ObjectNotFoundException

use of org.vcell.util.ObjectNotFoundException in project vcell by virtualcell.

the class BiomodelSimulationStopServerResource method stop.

@Override
public Representation stop() {
    VCellApiApplication application = ((VCellApiApplication) getApplication());
    User vcellUser = application.getVCellUser(getChallengeResponse(), AuthenticationPolicy.prohibitInvalidCredentials);
    RestDatabaseService restDatabaseService = application.getRestDatabaseService();
    try {
        SimulationRep simRep = restDatabaseService.stopSimulation(this, vcellUser);
        Representation representation = new StringRepresentation("simulation stopped", MediaType.TEXT_PLAIN);
        redirectSeeOther("/" + VCellApiApplication.SIMTASK + "?" + SimulationTasksServerResource.PARAM_SIM_ID + "=" + simRep.getKey().toString() + "&" + SimulationTasksServerResource.PARAM_STATUS_COMPLETED + "=on" + "&" + SimulationTasksServerResource.PARAM_STATUS_DISPATCHED + "=on" + "&" + SimulationTasksServerResource.PARAM_STATUS_FAILED + "=on" + "&" + SimulationTasksServerResource.PARAM_STATUS_QUEUED + "=on" + "&" + SimulationTasksServerResource.PARAM_STATUS_RUNNING + "=on" + "&" + SimulationTasksServerResource.PARAM_STATUS_STOPPED + "=on" + "&" + SimulationTasksServerResource.PARAM_STATUS_WAITING + "=on" + "&" + SimulationTasksServerResource.PARAM_START_ROW + "=1" + "&" + SimulationTasksServerResource.PARAM_MAX_ROWS + "=" + Integer.toString(simRep.getScanCount() * 4));
        return representation;
    } catch (PermissionException e) {
        e.printStackTrace();
        throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED, "not authorized to stop simulation");
    } catch (ObjectNotFoundException e) {
        e.printStackTrace();
        throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "simulation not found");
    } catch (Exception e) {
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage());
    }
}
Also used : PermissionException(org.vcell.util.PermissionException) User(org.vcell.util.document.User) StringRepresentation(org.restlet.representation.StringRepresentation) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) VCellApiApplication(org.vcell.rest.VCellApiApplication) StringRepresentation(org.restlet.representation.StringRepresentation) Representation(org.restlet.representation.Representation) ResourceException(org.restlet.resource.ResourceException) SimulationRep(cbit.vcell.modeldb.SimulationRep) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) ResourceException(org.restlet.resource.ResourceException)

Example 35 with ObjectNotFoundException

use of org.vcell.util.ObjectNotFoundException in project vcell by virtualcell.

the class BiomodelVCMLServerResource method getBiomodelVCML.

private String getBiomodelVCML(User vcellUser) {
    // if (!application.authenticate(getRequest(), getResponse())){
    // // not authenticated
    // return new SimulationTaskRepresentation[0];
    // }else{
    RestDatabaseService restDatabaseService = ((VCellApiApplication) getApplication()).getRestDatabaseService();
    try {
        String cachedVcml = restDatabaseService.query(this, vcellUser);
        BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(cachedVcml));
        String latestVcml = XmlHelper.bioModelToXML(bioModel);
        return latestVcml;
    } catch (PermissionException e) {
        e.printStackTrace();
        throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED, "permission denied to requested resource");
    } catch (ObjectNotFoundException e) {
        e.printStackTrace();
        throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "biomodel not found");
    } catch (Exception e) {
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage());
    }
// }
}
Also used : PermissionException(org.vcell.util.PermissionException) BioModel(cbit.vcell.biomodel.BioModel) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) VCellApiApplication(org.vcell.rest.VCellApiApplication) ResourceException(org.restlet.resource.ResourceException) XMLSource(cbit.vcell.xml.XMLSource) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) ResourceException(org.restlet.resource.ResourceException)

Aggregations

ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)62 DataAccessException (org.vcell.util.DataAccessException)26 KeyValue (org.vcell.util.document.KeyValue)21 ResultSet (java.sql.ResultSet)18 Statement (java.sql.Statement)17 PermissionException (org.vcell.util.PermissionException)17 SQLException (java.sql.SQLException)13 User (org.vcell.util.document.User)12 BigString (org.vcell.util.BigString)11 XmlParseException (cbit.vcell.xml.XmlParseException)10 VersionInfo (org.vcell.util.document.VersionInfo)10 Field (cbit.sql.Field)9 SimulationRep (cbit.vcell.modeldb.SimulationRep)9 XMLSource (cbit.vcell.xml.XMLSource)9 Table (cbit.sql.Table)8 OuterJoin (cbit.vcell.modeldb.DatabasePolicySQL.OuterJoin)8 PropertyVetoException (java.beans.PropertyVetoException)8 ResourceException (org.restlet.resource.ResourceException)8 VCellApiApplication (org.vcell.rest.VCellApiApplication)8 BioModel (cbit.vcell.biomodel.BioModel)7