Search in sources :

Example 1 with PermissionException

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

the class BiomodelBNGLServerResource method getBiomodelBNGL.

private String getBiomodelBNGL(User vcellUser) {
    RestDatabaseService restDatabaseService = ((VCellApiApplication) getApplication()).getRestDatabaseService();
    try {
        // Make temporary resource compatible with restDatabaseService so we can re-use
        BiomodelVCMLServerResource bmsr = new BiomodelVCMLServerResource() {

            @Override
            public Map<String, Object> getRequestAttributes() {
                HashMap<String, Object> hashMap = new HashMap<String, Object>();
                hashMap.put(VCellApiApplication.BIOMODELID, BiomodelBNGLServerResource.this.biomodelid);
                return hashMap;
            }

            @Override
            public Request getRequest() {
                // TODO Auto-generated method stub
                return BiomodelBNGLServerResource.this.getRequest();
            }
        };
        StringWriter bnglStringWriter = new StringWriter();
        PrintWriter pw = new PrintWriter(bnglStringWriter);
        String biomodelVCML = restDatabaseService.query(bmsr, vcellUser);
        BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(biomodelVCML));
        SimulationContext chosenSimContext = bioModel.getSimulationContext(0);
        RbmNetworkGenerator.writeBngl(chosenSimContext, pw, false, true);
        String resultString = bnglStringWriter.toString();
        return resultString;
    } catch (PermissionException e) {
        e.printStackTrace();
        throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED, "permission denied to requested resource");
    } catch (Exception e) {
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage());
    }
}
Also used : PermissionException(org.vcell.util.PermissionException) HashMap(java.util.HashMap) SimulationContext(cbit.vcell.mapping.SimulationContext) PermissionException(org.vcell.util.PermissionException) ResourceException(org.restlet.resource.ResourceException) StringWriter(java.io.StringWriter) BioModel(cbit.vcell.biomodel.BioModel) VCellApiApplication(org.vcell.rest.VCellApiApplication) ResourceException(org.restlet.resource.ResourceException) XMLSource(cbit.vcell.xml.XMLSource) PrintWriter(java.io.PrintWriter)

Example 2 with PermissionException

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

the class PublicationServerResource method getPublicationRepresentation.

private static PublicationRepresentation getPublicationRepresentation(RestDatabaseService restDatabaseService, User vcellUser, KeyValue pubID) {
    // RestDatabaseService restDatabaseService = ((VCellApiApplication)getApplication()).getRestDatabaseService();
    try {
        PublicationRep publicationRep = restDatabaseService.getPublicationRep(pubID, vcellUser);
        PublicationRepresentation publicationRepresentation = new PublicationRepresentation(publicationRep);
        return publicationRepresentation;
    } 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, "publication not found");
    } catch (Exception e) {
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage());
    }
// }
}
Also used : PermissionException(org.vcell.util.PermissionException) PublicationRepresentation(org.vcell.rest.common.PublicationRepresentation) PublicationRep(cbit.vcell.modeldb.PublicationRep) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) ResourceException(org.restlet.resource.ResourceException) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) ResourceException(org.restlet.resource.ResourceException)

Example 3 with PermissionException

use of org.vcell.util.PermissionException 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 4 with PermissionException

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

the class SimDataValuesServerResource method getSimDataValuesRepresentation.

private SimDataValuesRepresentation getSimDataValuesRepresentation(User vcellUser) {
    // if (!application.authenticate(getRequest(), getResponse())){
    // // not authenticated
    // return new SimulationTaskRepresentation[0];
    // }else{
    RestDatabaseService restDatabaseService = ((VCellApiApplication) getApplication()).getRestDatabaseService();
    try {
        DataSetTimeSeries dataSetTimeSeries = restDatabaseService.getDataSetTimeSeries(this, vcellUser);
        SimDataValuesRepresentation simDataRepresentation = new SimDataValuesRepresentation(dataSetTimeSeries);
        return simDataRepresentation;
    } 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) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) VCellApiApplication(org.vcell.rest.VCellApiApplication) ResourceException(org.restlet.resource.ResourceException) DataSetTimeSeries(cbit.vcell.simdata.DataSetTimeSeries) SimDataValuesRepresentation(org.vcell.rest.common.SimDataValuesRepresentation) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) ResourceException(org.restlet.resource.ResourceException)

Example 5 with PermissionException

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

the class SimulationTasksServerResource method getSimulationTaskRepresentations.

private SimulationTaskRepresentation[] getSimulationTaskRepresentations(User vcellUser) {
    // if (!application.authenticate(getRequest(), getResponse())){
    // // not authenticated
    // return new SimulationTaskRepresentation[0];
    // }else{
    ArrayList<SimulationTaskRepresentation> simTaskReps = new ArrayList<SimulationTaskRepresentation>();
    RestDatabaseService restDatabaseService = ((VCellApiApplication) getApplication()).getRestDatabaseService();
    try {
        SimpleJobStatus[] simJobStatusList = restDatabaseService.query(this, vcellUser);
        for (SimpleJobStatus simpleJobStatus : simJobStatusList) {
            SimulationTaskRepresentation simTaskRep = new SimulationTaskRepresentation(simpleJobStatus);
            simTaskReps.add(simTaskRep);
        }
    } catch (PermissionException ee) {
        throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED, "permission denied to requested resource");
    } catch (DataAccessException e) {
        e.printStackTrace();
        throw new RuntimeException("failed to retrieve active jobs from VCell Database : " + e.getMessage());
    } catch (SQLException e) {
        e.printStackTrace();
        throw new RuntimeException("failed to retrieve active jobs from VCell Database : " + e.getMessage());
    }
    return simTaskReps.toArray(new SimulationTaskRepresentation[0]);
// }
}
Also used : SimulationTaskRepresentation(org.vcell.rest.common.SimulationTaskRepresentation) PermissionException(org.vcell.util.PermissionException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) VCellApiApplication(org.vcell.rest.VCellApiApplication) ResourceException(org.restlet.resource.ResourceException) DataAccessException(org.vcell.util.DataAccessException) SimpleJobStatus(cbit.vcell.server.SimpleJobStatus)

Aggregations

PermissionException (org.vcell.util.PermissionException)28 ResourceException (org.restlet.resource.ResourceException)18 VCellApiApplication (org.vcell.rest.VCellApiApplication)17 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)17 DataAccessException (org.vcell.util.DataAccessException)9 KeyValue (org.vcell.util.document.KeyValue)8 User (org.vcell.util.document.User)8 BioModel (cbit.vcell.biomodel.BioModel)6 SimulationRep (cbit.vcell.modeldb.SimulationRep)6 XMLSource (cbit.vcell.xml.XMLSource)6 SQLException (java.sql.SQLException)6 ArrayList (java.util.ArrayList)5 BigString (org.vcell.util.BigString)5 PublicationRep (cbit.vcell.modeldb.PublicationRep)4 ExpressionException (cbit.vcell.parser.ExpressionException)4 PublicationRepresentation (org.vcell.rest.common.PublicationRepresentation)4 BioModelRep (cbit.vcell.modeldb.BioModelRep)3 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)3 BigDecimal (java.math.BigDecimal)3 PreparedStatement (java.sql.PreparedStatement)3