use of org.vcell.util.document.KeyValue in project vcell by virtualcell.
the class RestDatabaseService method query.
public BioModelRep[] query(BiomodelsServerResource resource, User vcellUser) throws SQLException, DataAccessException {
if (vcellUser == null) {
vcellUser = VCellApiApplication.DUMMY_USER;
}
String bioModelName = resource.getQueryValue(BiomodelsServerResource.PARAM_BM_NAME);
Long bioModelID = resource.getLongQueryValue(BiomodelsServerResource.PARAM_BM_ID);
Long savedLow = resource.getLongQueryValue(BiomodelsServerResource.PARAM_SAVED_LOW);
Long savedHigh = resource.getLongQueryValue(BiomodelsServerResource.PARAM_SAVED_HIGH);
Long startRowParam = resource.getLongQueryValue(BiomodelsServerResource.PARAM_START_ROW);
Long maxRowsParam = resource.getLongQueryValue(BiomodelsServerResource.PARAM_MAX_ROWS);
// it is ok if the category is null;
String categoryParam = resource.getQueryValue(BiomodelsServerResource.PARAM_CATEGORY);
// it is ok if the ownerName is null;
String ownerParam = resource.getQueryValue(BiomodelsServerResource.PARAM_BM_OWNER);
// it is ok if the orderBy is null;
String orderByParam = resource.getQueryValue(BiomodelsServerResource.PARAM_ORDERBY);
// default
int startRow = 1;
if (startRowParam != null) {
startRow = startRowParam.intValue();
}
// default
int maxRows = 10;
if (maxRowsParam != null) {
maxRows = maxRowsParam.intValue();
}
ArrayList<String> conditions = new ArrayList<String>();
java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss", java.util.Locale.US);
if (savedLow != null) {
conditions.add("(" + BioModelTable.table.versionDate.getQualifiedColName() + " >= to_date('" + df.format(new Date(savedLow)) + "', 'mm/dd/yyyy HH24:MI:SS'))");
}
if (savedHigh != null) {
conditions.add("(" + BioModelTable.table.versionDate.getQualifiedColName() + " <= to_date('" + df.format(new Date(savedHigh)) + "', 'mm/dd/yyyy HH24:MI:SS'))");
}
if (bioModelName != null && bioModelName.trim().length() > 0) {
String pattern = bioModelName.trim();
pattern = pattern.replace(" ", " ");
pattern = pattern.replace("(", " ");
pattern = pattern.replace(")", " ");
pattern = pattern.replace("'", " ");
pattern = pattern.replace("\"", " ");
pattern = pattern.replace("*", "%");
pattern = "%" + pattern + "%";
pattern = pattern.replace("%%", "%");
conditions.add("(" + "lower(" + BioModelTable.table.name.getQualifiedColName() + ")" + " like " + "lower('" + pattern + "')" + ")");
}
if (bioModelID != null) {
conditions.add("(" + BioModelTable.table.id.getQualifiedColName() + " = " + bioModelID + ")");
}
//
if (categoryParam == null && ownerParam != null) {
if (ownerParam.equals(VCellApiApplication.PSEUDOOWNER_PUBLIC)) {
categoryParam = VCellApiApplication.CATEGORY_PUBLIC;
ownerParam = null;
} else if (ownerParam.equals(VCellApiApplication.PSEUDOOWNER_EDUCATION)) {
categoryParam = VCellApiApplication.CATEGORY_EDUCATION;
ownerParam = null;
} else if (ownerParam.equals(VCellApiApplication.PSEUDOOWNER_SHARED)) {
categoryParam = VCellApiApplication.CATEGORY_SHARED;
ownerParam = null;
} else if (ownerParam.equals(VCellApiApplication.PSEUDOOWNER_TUTORIAL)) {
categoryParam = VCellApiApplication.CATEGORY_TUTORIAL;
ownerParam = null;
} else {
categoryParam = VCellApiApplication.CATEGORY_ALL;
}
} else if (categoryParam == null && ownerParam == null) {
categoryParam = VCellApiApplication.CATEGORY_ALL;
}
if (categoryParam.equals(VCellApiApplication.CATEGORY_MINE)) {
//
// return all models owned by me (none if not authenticated).
//
conditions.add("(" + UserTable.table.userid.getQualifiedColName() + " = '" + vcellUser.getName() + "')");
} else if (categoryParam.equals(VCellApiApplication.CATEGORY_PUBLIC)) {
//
// public models that aren't "Tutorial" or "Education"
//
// we will display all public models (even if owned by this user)
//
conditions.add("(" + BioModelTable.table.privacy.getQualifiedColName() + " = " + GroupAccess.GROUPACCESS_ALL + ")");
if (ownerParam != null && ownerParam.trim().length() > 0) {
conditions.add("(" + UserTable.table.userid.getQualifiedColName() + " = '" + ownerParam + "')");
}
conditions.add("(" + UserTable.table.userid.getQualifiedColName() + " != '" + VCellApiApplication.USERNAME_TUTORIAL + "')");
conditions.add("(" + UserTable.table.userid.getQualifiedColName() + " != '" + VCellApiApplication.USERNAME_EDUCATION + "')");
} else if (categoryParam.equals(VCellApiApplication.CATEGORY_EDUCATION)) {
//
// public models from "Education"
//
conditions.add("(" + UserTable.table.userid.getQualifiedColName() + " = '" + VCellApiApplication.USERNAME_EDUCATION + "')");
conditions.add("(" + BioModelTable.table.privacy.getQualifiedColName() + " = " + GroupAccess.GROUPACCESS_ALL + ")");
} else if (categoryParam.equals(VCellApiApplication.CATEGORY_TUTORIAL)) {
//
// public models from "tutorial"
//
conditions.add("(" + UserTable.table.userid.getQualifiedColName() + " = '" + VCellApiApplication.USERNAME_TUTORIAL + "')");
conditions.add("(" + BioModelTable.table.privacy.getQualifiedColName() + " = " + GroupAccess.GROUPACCESS_ALL + ")");
} else if (categoryParam.equals(VCellApiApplication.CATEGORY_SHARED)) {
//
if (!vcellUser.compareEqual(VCellApiApplication.DUMMY_USER)) {
conditions.add("(" + UserTable.table.userid.getQualifiedColName() + " != '" + vcellUser.getName() + "')");
}
if (ownerParam != null && ownerParam.trim().length() > 0) {
conditions.add("(" + UserTable.table.userid.getQualifiedColName() + " = '" + ownerParam + "')");
}
conditions.add("(" + BioModelTable.table.privacy.getQualifiedColName() + " != " + GroupAccess.GROUPACCESS_ALL + ")");
conditions.add("(" + BioModelTable.table.privacy.getQualifiedColName() + " != " + GroupAccess.GROUPACCESS_NONE + ")");
} else if (categoryParam.equals(VCellApiApplication.CATEGORY_ALL)) {
//
if (ownerParam != null && ownerParam.length() > 0) {
conditions.add("(" + UserTable.table.userid.getQualifiedColName() + " = '" + ownerParam + "')");
}
}
StringBuffer conditionsBuffer = new StringBuffer();
for (String condition : conditions) {
if (conditionsBuffer.length() > 0) {
conditionsBuffer.append(" AND ");
}
conditionsBuffer.append(condition);
}
// default
OrderBy orderBy = OrderBy.date_desc;
if (orderByParam != null) {
if (orderByParam.equals(BiomodelsServerResource.PARAM_ORDERBY_DATE_ASC)) {
orderBy = OrderBy.date_asc;
} else if (orderByParam.equals(BiomodelsServerResource.PARAM_ORDERBY_DATE_DESC)) {
orderBy = OrderBy.date_desc;
} else if (orderByParam.equals(BiomodelsServerResource.PARAM_ORDERBY_NAME_ASC)) {
orderBy = OrderBy.name_asc;
} else if (orderByParam.equals(BiomodelsServerResource.PARAM_ORDERBY_NAME_DESC)) {
orderBy = OrderBy.name_desc;
}
}
BioModelRep[] bioModelReps = databaseServerImpl.getBioModelReps(vcellUser, conditionsBuffer.toString(), orderBy, startRow, maxRows);
for (BioModelRep bioModelRep : bioModelReps) {
KeyValue[] simContextKeys = bioModelRep.getSimContextKeyList();
for (KeyValue scKey : simContextKeys) {
SimContextRep scRep = getSimContextRep(scKey);
if (scRep != null) {
bioModelRep.addSimContextRep(scRep);
}
}
KeyValue[] simulationKeys = bioModelRep.getSimKeyList();
for (KeyValue simKey : simulationKeys) {
SimulationRep simulationRep = getSimulationRep(simKey);
if (simulationRep != null) {
bioModelRep.addSimulationRep(simulationRep);
}
}
}
return bioModelReps;
}
use of org.vcell.util.document.KeyValue in project vcell by virtualcell.
the class RestDatabaseService method query.
public String query(BiomodelVCMLServerResource resource, User vcellUser) throws SQLException, DataAccessException {
if (vcellUser == null) {
vcellUser = VCellApiApplication.DUMMY_USER;
}
String bioModelID = (String) resource.getRequestAttributes().get(VCellApiApplication.BIOMODELID);
KeyValue bioModelKey = new KeyValue(bioModelID);
BigString vcmlBigString = databaseServerImpl.getBioModelXML(vcellUser, bioModelKey);
return vcmlBigString.toString();
}
use of org.vcell.util.document.KeyValue 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);
}
use of org.vcell.util.document.KeyValue 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();
}
}
use of org.vcell.util.document.KeyValue in project vcell by virtualcell.
the class UserDbDriverExtended method getUserFromEmail.
/**
* @param con not null
* @param email not null; lower case used
* @return existing user or null
* @throws SQLException
*/
public List<User> getUserFromEmail(Connection con, String email) throws SQLException {
String sql = "SELECT " + UserTable.table.id + ',' + UserTable.table.userid + " FROM " + userTable.getTableName() + " WHERE lower(" + UserTable.table.email + ") = lower('" + email + "')";
List<User> rval = new ArrayList<>();
User user;
try (Statement stmt = con.createStatement()) {
ResultSet rset = stmt.executeQuery(sql);
while (rset.next()) {
KeyValue userKey = new KeyValue(rset.getBigDecimal(UserTable.table.id.toString()));
String userid = rset.getString(UserTable.table.userid.toString());
user = new User(userid, userKey);
rval.add(user);
}
}
return rval;
}
Aggregations