Search in sources :

Example 11 with DatabaseServerImpl

use of cbit.vcell.modeldb.DatabaseServerImpl 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

DatabaseServerImpl (cbit.vcell.modeldb.DatabaseServerImpl)11 File (java.io.File)7 ConnectionFactory (org.vcell.db.ConnectionFactory)7 KeyFactory (org.vcell.db.KeyFactory)7 AdminDBTopLevel (cbit.vcell.modeldb.AdminDBTopLevel)6 User (org.vcell.util.document.User)5 VCMessagingService (cbit.vcell.message.VCMessagingService)4 IOException (java.io.IOException)4 ServerMessagingDelegate (cbit.vcell.message.server.ServerMessagingDelegate)3 ServiceInstanceStatus (cbit.vcell.message.server.ServiceInstanceStatus)3 Cachetable (cbit.vcell.simdata.Cachetable)3 DataSetControllerImpl (cbit.vcell.simdata.DataSetControllerImpl)3 SQLException (java.sql.SQLException)3 Date (java.util.Date)3 BigString (org.vcell.util.BigString)3 DataAccessException (org.vcell.util.DataAccessException)3 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)3 VCDocument (org.vcell.util.document.VCDocument)3 VCDocumentType (org.vcell.util.document.VCDocument.VCDocumentType)3 BioModel (cbit.vcell.biomodel.BioModel)2