Search in sources :

Example 21 with PermissionException

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

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

the class RestDatabaseService method stopSimulation.

public SimulationRep stopSimulation(BiomodelSimulationStopServerResource resource, User vcellUser) throws PermissionException, ObjectNotFoundException, DataAccessException, SQLException {
    // resource.getRequestAttributes().get(VCellApiApplication.SIMDATAID);
    String simId = resource.getAttribute(VCellApiApplication.SIMULATIONID);
    KeyValue simKey = new KeyValue(simId);
    SimulationRep simRep = getSimulationRep(simKey);
    if (simRep == null) {
        throw new ObjectNotFoundException("Simulation with key " + simKey + " not found");
    }
    User owner = simRep.getOwner();
    if (!owner.compareEqual(vcellUser)) {
        throw new PermissionException("not authorized to stop simulation");
    }
    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);
        VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(simKey, owner);
        rpcSimServerProxy.stopSimulation(vcellUser, vcSimID);
        return simRep;
    } finally {
        rpcSession.close();
    }
}
Also used : PermissionException(org.vcell.util.PermissionException) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) RpcSimServerProxy(org.vcell.rest.rpc.RpcSimServerProxy) VCMessageSession(cbit.vcell.message.VCMessageSession) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) BigString(org.vcell.util.BigString) UserLoginInfo(org.vcell.util.document.UserLoginInfo) SimulationRep(cbit.vcell.modeldb.SimulationRep) 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) DataAccessException(org.vcell.util.DataAccessException)

Example 23 with PermissionException

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

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

the class SimulationControllerImpl method getOrCreateSolverController.

/**
 * This method was created by a SmartGuide.
 * @throws SolverException
 * @throws DataAccessException
 * @throws ConfigurationException
 * @exception java.rmi.RemoteException The exception description.
 * @throws JMSException
 * @throws AuthenticationException
 * @throws SQLException
 * @throws FileNotFoundException
 */
LocalSolverController getOrCreateSolverController(SimulationTask simTask) throws FileNotFoundException, ConfigurationException, DataAccessException, AuthenticationException, SQLException, SolverException {
    Simulation simulation = simTask.getSimulation();
    VCSimulationIdentifier vcSimID = simulation.getSimulationInfo().getAuthoritativeVCSimulationIdentifier();
    if (vcSimID == null) {
        throw new IllegalArgumentException("cannot run an unsaved simulation");
    }
    if (!simulation.getVersion().getOwner().equals(localVCellConnection.getUserLoginInfo().getUser())) {
        throw new PermissionException("insufficient privilege: startSimulation()");
    }
    SimulationTaskID simTaskInfo = new SimulationTaskID(simTask);
    LocalSolverController solverController = solverControllerHash.get(simTaskInfo);
    if (solverController == null) {
        solverController = createNewSolverController(simTask);
        solverControllerHash.put(simTaskInfo, solverController);
    }
    return solverController;
}
Also used : PermissionException(org.vcell.util.PermissionException) LocalSolverController(cbit.vcell.solvers.LocalSolverController) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) Simulation(cbit.vcell.solver.Simulation) SimulationTaskID(cbit.vcell.server.SimulationTaskID)

Example 25 with PermissionException

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

the class SimulationContextDbDriver method deleteSimContextSQL.

/**
 * removeModel method comment.
 */
private void deleteSimContextSQL(Connection con, User user, KeyValue simContextKey) throws SQLException, PermissionException, DataAccessException, DependencyException {
    // log.print("deleteSimContextSQL(user=" + user + ", simContextKey=" + simContextKey + ")");
    // 
    // check for external references (from BioModel)
    // 
    failOnExternalRefs(con, BioModelSimContextLinkTable.table.simContextRef, BioModelSimContextLinkTable.table, simContextKey, SimContextTable.table);
    KeyValue mathKey = getDeletableMathKeyFromSimContext(con, user, simContextKey);
    // 
    // delete SimulationContext (Model and Geometry link tables are ON DELETE CASCADE)
    // 
    String sql;
    sql = DatabasePolicySQL.enforceOwnershipDelete(user, simContextTable, simContextTable.id.getQualifiedColName() + " = " + simContextKey);
    updateCleanSQL(con, sql);
    // 
    try {
        mathDescDB.deleteVersionable(con, user, VersionableType.MathDescription, mathKey);
        if (lg.isTraceEnabled()) {
            lg.trace("SimulationContextDbDriver.delete(" + simContextKey + ") deletion of MathDescription(" + mathKey + ") succeeded");
        }
    } catch (PermissionException | DependencyException e) {
        if (lg.isWarnEnabled()) {
            lg.warn("SimulationContextDbDriver.delete(" + simContextKey + ") deletion of MathDescription(" + mathKey + ") failed: " + e.getMessage());
        }
    }
}
Also used : PermissionException(org.vcell.util.PermissionException) KeyValue(org.vcell.util.document.KeyValue) DependencyException(org.vcell.util.DependencyException)

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