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]);
}
};
}
Aggregations