Search in sources :

Example 16 with KeyFactory

use of org.vcell.db.KeyFactory in project vcell by virtualcell.

the class TestRestServerBlinov method getRestDatabaseService.

// Create Fake RestDatabaseService that doesn't query a database but the local cache generated when this program started (see main(...))
public static RestDatabaseService getRestDatabaseService() throws DataAccessException {
    // Created unimplemented ConnectionFactory (we don't use actual database connections)
    ConnectionFactory connFac = new ConnectionFactory() {

        @Override
        public void close() throws SQLException {
        // TODO Auto-generated method stub
        }

        @Override
        public void failed(Connection con, Object lock) throws SQLException {
        // TODO Auto-generated method stub
        }

        @Override
        public Connection getConnection(Object lock) throws SQLException {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public void release(Connection con, Object lock) throws SQLException {
        // TODO Auto-generated method stub
        }

        @Override
        public KeyFactory getKeyFactory() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public DatabaseSyntax getDatabaseSyntax() {
            // TODO Auto-generated method stub
            return null;
        }
    };
    // Create unimplemented KeyFactory (we don't make keys for the database)
    KeyFactory keyf = new KeyFactory() {

        @Override
        public String getCreateSQL() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String getDestroySQL() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String nextSEQ() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String currSEQ() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public KeyValue getNewKey(Connection con) throws SQLException {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public BigDecimal getUniqueBigDecimal(Connection con) throws SQLException {
            // TODO Auto-generated method stub
            return null;
        }
    };
    // Create unimplemented DatabaseServerImpl (required argument for RestDatabaseService but will never be called for our tests)
    DatabaseServerImpl dbsi = new DatabaseServerImpl(connFac, keyf) {

        @Override
        public AdminDBTopLevel getAdminDBTopLevel() {
            return null;
        }
    };
    // the methods use local caches of imported biomodels to respond to queries
    return new RestDatabaseService(dbsi, null, null) {

        @Override
        public String query(BiomodelVCMLServerResource resource, User vcellUser) throws SQLException, DataAccessException {
            try {
                // 
                // Both BiomodelVCMLServerResource and BiomodelSBMLServerResource use this to get the initial BioModel vcml content
                // 
                // Responds to queries (e.g. http://myhost:8182/biomodel/173365344/biomodel.vcml) ending in "/"+BIOMODEL+"/{"+BIOMODELID+"}/"+VCML_DOWNLOAD (ass set in getVCellApiApplication())
                // final ConcurrentMap<String, Object> attributes = resource.getRequest().getAttributes();
                // Get the values between the / slashes in the query URL
                final List<String> segments = resource.getRequest().getOriginalRef().getSegments();
                // For this Resource segments[0] ="biomodel", segments[1] = BIOMODELID, segments[2] = "biomodel.vcml"
                String bmKey = segments.get(1);
                // String docType = segments.get(2);
                // if(docType.endsWith(".vcml")) {
                // Read the cached file contents and return
                // http://dockerbuild:8182/biomodel/0/biomodel.sbml
                File f = mapBMidToFileName.get(bmKey);
                // final Map<String, String> valuesMap = resource.getQuery().getValuesMap();
                return new String(Files.readAllBytes(f.toPath()));
            // }else if(docType.endsWith(".sbml")) {
            // 
            // }
            // throw new IllegalArgumentException("Unexpected docType="+docType);
            } catch (IOException e) {
                throw new DataAccessException(e.getMessage(), e);
            }
        }

        @Override
        public BioModelRep getBioModelRep(KeyValue bmKey, User vcellUser) throws SQLException, ObjectNotFoundException, DataAccessException {
            return mapBMidToBiomodelRep.get(bmKey.toString());
        }

        @Override
        public BioModelRep[] query(BiomodelsServerResource resource, User vcellUser) throws SQLException, DataAccessException {
            return bioModelRepArr.toArray(new BioModelRep[0]);
        }
    };
}
Also used : User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) Connection(java.sql.Connection) BioModelRep(cbit.vcell.modeldb.BioModelRep) IOException(java.io.IOException) ConnectionFactory(org.vcell.db.ConnectionFactory) DatabaseServerImpl(cbit.vcell.modeldb.DatabaseServerImpl) File(java.io.File) KeyFactory(org.vcell.db.KeyFactory) DataAccessException(org.vcell.util.DataAccessException)

Aggregations

KeyFactory (org.vcell.db.KeyFactory)16 ConnectionFactory (org.vcell.db.ConnectionFactory)15 DatabaseServerImpl (cbit.vcell.modeldb.DatabaseServerImpl)7 File (java.io.File)7 AdminDBTopLevel (cbit.vcell.modeldb.AdminDBTopLevel)5 VCMessagingService (cbit.vcell.message.VCMessagingService)4 DataAccessException (org.vcell.util.DataAccessException)4 User (org.vcell.util.document.User)4 ServerMessagingDelegate (cbit.vcell.message.server.ServerMessagingDelegate)3 ServiceInstanceStatus (cbit.vcell.message.server.ServiceInstanceStatus)3 SQLException (java.sql.SQLException)3 Date (java.util.Date)3 ExportServiceImpl (cbit.vcell.export.server.ExportServiceImpl)2 VCMessagingServiceActiveMQ (cbit.vcell.message.jms.activeMQ.VCMessagingServiceActiveMQ)2 SimulationDatabaseDirect (cbit.vcell.message.server.dispatcher.SimulationDatabaseDirect)2 HtcProxy (cbit.vcell.message.server.htc.HtcProxy)2 LocalAdminDbServer (cbit.vcell.modeldb.LocalAdminDbServer)2 PropertyLoader (cbit.vcell.resource.PropertyLoader)2 AdminDatabaseServer (cbit.vcell.server.AdminDatabaseServer)2 Cachetable (cbit.vcell.simdata.Cachetable)2