Search in sources :

Example 6 with ObjectNotFoundException

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

the class RestDatabaseService method saveSimulation.

public SimulationSaveResponse saveSimulation(BiomodelSimulationSaveServerResource resource, User vcellUser, List<OverrideRepresentation> overrideRepresentations) throws PermissionException, ObjectNotFoundException, DataAccessException, SQLException, XmlParseException, PropertyVetoException, MappingException, ExpressionException {
    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");
    }
    boolean myModel = simRep.getOwner().compareEqual(vcellUser);
    // get the bioModel
    String biomodelId = resource.getAttribute(VCellApiApplication.BIOMODELID);
    KeyValue biomodelKey = new KeyValue(biomodelId);
    BigString bioModelXML = this.databaseServerImpl.getBioModelXML(vcellUser, biomodelKey);
    BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(bioModelXML.toString()));
    // copy the simulation as new
    Simulation origSimulation = null;
    for (Simulation sim : bioModel.getSimulations()) {
        if (sim.getKey().equals(simKey)) {
            origSimulation = sim;
        }
    }
    if (origSimulation == null) {
        throw new RuntimeException("cannot find original Simulation");
    }
    SimulationContext simContext = bioModel.getSimulationContext(origSimulation);
    Simulation newUnsavedSimulation = simContext.copySimulation(origSimulation);
    // make appropriate changes
    // MATH OVERRIDES
    MathOverrides mathOverrides = new MathOverrides(newUnsavedSimulation);
    for (OverrideRepresentation overrideRep : overrideRepresentations) {
        overrideRep.applyMathOverrides(mathOverrides);
    }
    newUnsavedSimulation.setMathOverrides(mathOverrides);
    // save bioModel
    String editedBioModelXML = XmlHelper.bioModelToXML(bioModel);
    ServerDocumentManager serverDocumentManager = new ServerDocumentManager(this.databaseServerImpl);
    String modelName = bioModel.getName();
    if (!myModel) {
        modelName = modelName + "_" + Math.abs(new Random().nextInt());
    }
    String newBioModelXML = serverDocumentManager.saveBioModel(new QueryHashtable(), vcellUser, editedBioModelXML, modelName, null);
    BioModel savedBioModel = XmlHelper.XMLToBioModel(new XMLSource(newBioModelXML));
    Simulation savedSimulation = null;
    for (Simulation sim : savedBioModel.getSimulations()) {
        if (sim.getName().equals(newUnsavedSimulation.getName())) {
            savedSimulation = sim;
        }
    }
    if (savedSimulation == null) {
        throw new RuntimeException("cannot find new Simulation");
    }
    return new SimulationSaveResponse(savedBioModel, savedSimulation);
}
Also used : QueryHashtable(cbit.sql.QueryHashtable) KeyValue(org.vcell.util.document.KeyValue) BigString(org.vcell.util.BigString) SimulationContext(cbit.vcell.mapping.SimulationContext) BigString(org.vcell.util.BigString) OverrideRepresentation(org.vcell.rest.common.OverrideRepresentation) ServerDocumentManager(cbit.vcell.modeldb.ServerDocumentManager) MathOverrides(cbit.vcell.solver.MathOverrides) Simulation(cbit.vcell.solver.Simulation) Random(java.util.Random) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) BioModel(cbit.vcell.biomodel.BioModel) XMLSource(cbit.vcell.xml.XMLSource) SimulationRep(cbit.vcell.modeldb.SimulationRep)

Example 7 with ObjectNotFoundException

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

the class RestDatabaseService method getDataSetMetadata.

public DataSetMetadata getDataSetMetadata(SimDataServerResource resource, User vcellUser) throws ObjectNotFoundException, DataAccessException, SQLException {
    if (vcellUser == null) {
        vcellUser = VCellApiApplication.DUMMY_USER;
    }
    UserLoginInfo userLoginInfo = new UserLoginInfo(vcellUser.getName(), null);
    // resource.getRequestAttributes().get(VCellApiApplication.SIMDATAID);
    String simId = resource.getAttribute(VCellApiApplication.SIMDATAID);
    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();
    int jobIndex = 0;
    VCMessageSession rpcSession = vcMessagingService.createProducerSession();
    try {
        RpcDataServerProxy rpcDataServerProxy = new RpcDataServerProxy(userLoginInfo, rpcSession);
        VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(simKey, owner);
        VCDataIdentifier vcdID = new VCSimulationDataIdentifier(vcSimID, jobIndex);
        DataSetMetadata dataSetMetadata = rpcDataServerProxy.getDataSetMetadata(vcdID);
        return dataSetMetadata;
    } finally {
        rpcSession.close();
    }
}
Also used : VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) VCMessageSession(cbit.vcell.message.VCMessageSession) BigString(org.vcell.util.BigString) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) RpcDataServerProxy(org.vcell.rest.rpc.RpcDataServerProxy) DataSetMetadata(cbit.vcell.simdata.DataSetMetadata) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) UserLoginInfo(org.vcell.util.document.UserLoginInfo) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) SimulationRep(cbit.vcell.modeldb.SimulationRep)

Example 8 with ObjectNotFoundException

use of org.vcell.util.ObjectNotFoundException 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 9 with ObjectNotFoundException

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

the class UserVerifier method authenticateUser.

public User authenticateUser(String userid, char[] secret) {
    DigestedPassword digestedPassword = UserLoginInfo.DigestedPassword.createAlreadyDigested(new String(secret));
    AuthenticationInfo authInfo = useridMap.get(userid);
    if (authInfo != null) {
        if (authInfo.digestedPassword.equals(digestedPassword)) {
            return authInfo.user;
        }
    }
    if ((System.currentTimeMillis() - lastQueryTimestampMS) > MIN_QUERY_TIME_MS) {
        synchronized (adminDbTopLevel) {
            User user = null;
            try {
                user = adminDbTopLevel.getUser(userid, digestedPassword, true, false);
            } catch (ObjectNotFoundException e) {
                e.printStackTrace();
            } catch (DataAccessException e) {
                e.printStackTrace();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            // refresh stored list of user infos (for authentication)
            if (user != null) {
                useridMap.put(userid, new AuthenticationInfo(user, digestedPassword));
            }
            lastQueryTimestampMS = System.currentTimeMillis();
            return user;
        }
    } else {
        return null;
    }
}
Also used : User(org.vcell.util.document.User) UnverifiedUser(org.vcell.rest.users.UnverifiedUser) SQLException(java.sql.SQLException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) DigestedPassword(org.vcell.util.document.UserLoginInfo.DigestedPassword) DataAccessException(org.vcell.util.DataAccessException)

Example 10 with ObjectNotFoundException

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

the class RestDatabaseService method getPublicationRep.

public PublicationRep getPublicationRep(KeyValue pubKey, User vcellUser) throws SQLException, ObjectNotFoundException, DataAccessException {
    if (vcellUser == null) {
        vcellUser = VCellApiApplication.DUMMY_USER;
    }
    ArrayList<String> conditions = new ArrayList<String>();
    if (pubKey != null) {
        conditions.add("(" + PublicationTable.table.id.getQualifiedColName() + " = " + pubKey.toString() + ")");
    } else {
        throw new RuntimeException("bioModelID not specified");
    }
    StringBuffer conditionsBuffer = new StringBuffer();
    for (String condition : conditions) {
        if (conditionsBuffer.length() > 0) {
            conditionsBuffer.append(" AND ");
        }
        conditionsBuffer.append(condition);
    }
    PublicationRep[] publicationReps = databaseServerImpl.getPublicationReps(vcellUser, conditionsBuffer.toString(), null);
    if (publicationReps == null || publicationReps.length != 1) {
        throw new ObjectNotFoundException("failed to get publication");
    }
    return publicationReps[0];
}
Also used : PublicationRep(cbit.vcell.modeldb.PublicationRep) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) ArrayList(java.util.ArrayList) BigString(org.vcell.util.BigString)

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