Search in sources :

Example 46 with VCellApiApplication

use of org.vcell.rest.VCellApiApplication 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 47 with VCellApiApplication

use of org.vcell.rest.VCellApiApplication 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 48 with VCellApiApplication

use of org.vcell.rest.VCellApiApplication 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 49 with VCellApiApplication

use of org.vcell.rest.VCellApiApplication in project vcell by virtualcell.

the class BiomodelServerResource method get_html.

@Override
public Representation get_html() {
    VCellApiApplication application = ((VCellApiApplication) getApplication());
    User vcellUser = application.getVCellUser(getChallengeResponse(), AuthenticationPolicy.ignoreInvalidCredentials);
    BiomodelRepresentation biomodel = getBiomodelRepresentation(vcellUser);
    if (biomodel == null) {
        throw new RuntimeException("biomodel not found");
    }
    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("bmId", getQueryValue(VCellApiApplication.BIOMODELID));
    dataModel.put("biomodel", biomodel);
    Gson gson = new Gson();
    dataModel.put("jsonResponse", gson.toJson(biomodel));
    Configuration templateConfiguration = application.getTemplateConfiguration();
    Representation formFtl = new ClientResource(LocalReference.createClapReference("/biomodel.ftl")).get();
    TemplateRepresentation templateRepresentation = new TemplateRepresentation(formFtl, templateConfiguration, dataModel, MediaType.TEXT_HTML);
    return templateRepresentation;
}
Also used : BiomodelRepresentation(org.vcell.rest.common.BiomodelRepresentation) 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) BiomodelRepresentation(org.vcell.rest.common.BiomodelRepresentation) Representation(org.restlet.representation.Representation) VCellApiApplication(org.vcell.rest.VCellApiApplication) ClientResource(org.restlet.resource.ClientResource)

Example 50 with VCellApiApplication

use of org.vcell.rest.VCellApiApplication in project vcell by virtualcell.

the class BiomodelServerResource method get_json.

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

Aggregations

VCellApiApplication (org.vcell.rest.VCellApiApplication)53 User (org.vcell.util.document.User)34 ResourceException (org.restlet.resource.ResourceException)21 PermissionException (org.vcell.util.PermissionException)20 Gson (com.google.gson.Gson)14 Representation (org.restlet.representation.Representation)14 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)14 HashMap (java.util.HashMap)13 Configuration (freemarker.template.Configuration)12 TemplateRepresentation (org.restlet.ext.freemarker.TemplateRepresentation)11 ClientResource (org.restlet.resource.ClientResource)11 JsonRepresentation (org.restlet.ext.json.JsonRepresentation)9 Form (org.restlet.data.Form)8 StringRepresentation (org.restlet.representation.StringRepresentation)8 BioModel (cbit.vcell.biomodel.BioModel)6 XMLSource (cbit.vcell.xml.XMLSource)6 SQLException (java.sql.SQLException)6 ArrayList (java.util.ArrayList)6 BiomodelRepresentation (org.vcell.rest.common.BiomodelRepresentation)6 PublicationRepresentation (org.vcell.rest.common.PublicationRepresentation)6