Search in sources :

Example 26 with ConnectionFactory

use of org.vcell.db.ConnectionFactory 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

ConnectionFactory (org.vcell.db.ConnectionFactory)26 KeyFactory (org.vcell.db.KeyFactory)15 File (java.io.File)11 SQLException (java.sql.SQLException)9 DatabaseServerImpl (cbit.vcell.modeldb.DatabaseServerImpl)7 IOException (java.io.IOException)7 Connection (java.sql.Connection)7 AdminDBTopLevel (cbit.vcell.modeldb.AdminDBTopLevel)5 ZipFile (java.util.zip.ZipFile)5 VCMessagingService (cbit.vcell.message.VCMessagingService)4 DataAccessException (org.vcell.util.DataAccessException)4 ServerMessagingDelegate (cbit.vcell.message.server.ServerMessagingDelegate)3 ServiceInstanceStatus (cbit.vcell.message.server.ServiceInstanceStatus)3 FileFilter (java.io.FileFilter)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 TreeSet (java.util.TreeSet)3 Matcher (java.util.regex.Matcher)3 Pattern (java.util.regex.Pattern)3 User (org.vcell.util.document.User)3