Search in sources :

Example 66 with ResourceException

use of org.restlet.resource.ResourceException 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 67 with ResourceException

use of org.restlet.resource.ResourceException 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)

Example 68 with ResourceException

use of org.restlet.resource.ResourceException in project vcell by virtualcell.

the class BiomodelsServerResource method getBiomodelRepresentations.

private BiomodelRepresentation[] getBiomodelRepresentations(User vcellUser) throws ParseException {
    // if (!application.authenticate(getRequest(), getResponse())){
    // // not authenticated
    // return new SimulationTaskRepresentation[0];
    // }else{
    ArrayList<BiomodelRepresentation> biomodelReps = new ArrayList<BiomodelRepresentation>();
    RestDatabaseService restDatabaseService = ((VCellApiApplication) getApplication()).getRestDatabaseService();
    try {
        BioModelRep[] bioModelReps = restDatabaseService.query(this, vcellUser);
        for (BioModelRep bioModelRep : bioModelReps) {
            BiomodelRepresentation biomodelRep = new BiomodelRepresentation(bioModelRep);
            biomodelReps.add(biomodelRep);
        }
    } catch (PermissionException ee) {
        ee.printStackTrace();
        throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED, "not authorized");
    } catch (DataAccessException | SQLException | ExpressionException e) {
        e.printStackTrace();
        throw new RuntimeException("failed to retrieve biomodels from VCell Database : " + e.getMessage());
    }
    return biomodelReps.toArray(new BiomodelRepresentation[0]);
// }
}
Also used : BiomodelRepresentation(org.vcell.rest.common.BiomodelRepresentation) PermissionException(org.vcell.util.PermissionException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) BioModelRep(cbit.vcell.modeldb.BioModelRep) ExpressionException(cbit.vcell.parser.ExpressionException) VCellApiApplication(org.vcell.rest.VCellApiApplication) ResourceException(org.restlet.resource.ResourceException) DataAccessException(org.vcell.util.DataAccessException)

Example 69 with ResourceException

use of org.restlet.resource.ResourceException in project vcell by virtualcell.

the class BiomodelDiagramServerResource method get_png.

@Override
@Get("image/png")
public ByteArrayRepresentation get_png() {
    VCellApiApplication application = ((VCellApiApplication) getApplication());
    User vcellUser = application.getVCellUser(getChallengeResponse(), AuthenticationPolicy.ignoreInvalidCredentials);
    String vcml = getBiomodelVCML(vcellUser);
    if (vcml == null) {
        throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "BioModel not found");
    }
    try {
        BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(vcml));
        Integer imageWidthInPixels = 1000;
        BufferedImage bufferedImage = ITextWriter.generateDocReactionsImage(bioModel.getModel(), imageWidthInPixels);
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        ImageIO.write(bufferedImage, "png", outputStream);
        byte[] imageBytes = outputStream.toByteArray();
        return new ByteArrayRepresentation(imageBytes, MediaType.IMAGE_PNG, imageBytes.length);
    } catch (Exception e) {
        e.printStackTrace();
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage());
    }
}
Also used : User(org.vcell.util.document.User) BioModel(cbit.vcell.biomodel.BioModel) VCellApiApplication(org.vcell.rest.VCellApiApplication) ByteArrayRepresentation(org.restlet.representation.ByteArrayRepresentation) ResourceException(org.restlet.resource.ResourceException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) XMLSource(cbit.vcell.xml.XMLSource) BufferedImage(java.awt.image.BufferedImage) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) ResourceException(org.restlet.resource.ResourceException) Get(org.restlet.resource.Get)

Example 70 with ResourceException

use of org.restlet.resource.ResourceException 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)

Aggregations

ResourceException (org.restlet.resource.ResourceException)70 Representation (org.restlet.representation.Representation)20 PermissionException (org.vcell.util.PermissionException)20 VCellApiApplication (org.vcell.rest.VCellApiApplication)18 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)15 IOException (java.io.IOException)13 StringRepresentation (org.restlet.representation.StringRepresentation)12 ArrayList (java.util.ArrayList)10 Reference (org.restlet.data.Reference)8 BioModel (cbit.vcell.biomodel.BioModel)7 Writer (java.io.Writer)7 HashMap (java.util.HashMap)7 JSONObject (org.json.JSONObject)7 WriterRepresentation (org.restlet.representation.WriterRepresentation)7 XMLSource (cbit.vcell.xml.XMLSource)6 Response (org.restlet.Response)6 User (org.vcell.util.document.User)6 EntitlementException (com.sun.identity.entitlement.EntitlementException)4 EntityReference (org.qi4j.api.entity.EntityReference)4 EntityTypeNotFoundException (org.qi4j.api.unitofwork.EntityTypeNotFoundException)4