Skip to content

Commit

Permalink
Fix api biomodels begin/end search date
Browse files Browse the repository at this point in the history
  • Loading branch information
vcfrmgit committed Jan 25, 2022
1 parent 3645d9b commit 24b51ef
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.vcell.rest.server;

import java.sql.SQLException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -103,15 +104,30 @@ public BiomodelRepresentation[] get_json() {
VCellApiApplication application = ((VCellApiApplication)getApplication());
User vcellUser = application.getVCellUser(getChallengeResponse(),AuthenticationPolicy.prohibitInvalidCredentials);

return getBiomodelRepresentations(vcellUser);
BiomodelRepresentation[] bmReps = new BiomodelRepresentation[0];
try {
getBiomodelRepresentations(vcellUser);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return bmReps;
}

@Override
public Representation get_html() {
VCellApiApplication application = ((VCellApiApplication)getApplication());
User vcellUser = application.getVCellUser(getChallengeResponse(),AuthenticationPolicy.ignoreInvalidCredentials);

BiomodelRepresentation[] biomodels = getBiomodelRepresentations(vcellUser);
BiomodelRepresentation[] biomodels = new BiomodelRepresentation[0];
boolean bFormatErr = false;
try {
biomodels = getBiomodelRepresentations(vcellUser);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
bFormatErr = true;
}
Map<String,Object> dataModel = new HashMap<String,Object>();

dataModel.put("loginurl", "/"+VCellApiApplication.LOGINFORM); // +"?"+VCellApiApplication.REDIRECTURL_FORMNAME+"="+getRequest().getResourceRef().toUrl());
Expand All @@ -123,8 +139,8 @@ public Representation get_html() {
dataModel.put("userId", getAttribute(PARAM_USER));
dataModel.put("bmName", getQueryValue(PARAM_BM_NAME));
dataModel.put("bmId", getQueryValue(PARAM_BM_ID));
dataModel.put("savedLow", getLongQueryValue(PARAM_SAVED_LOW));
dataModel.put("savedHigh", getLongQueryValue(PARAM_SAVED_HIGH));
dataModel.put("savedLow", (bFormatErr?"Error":getQueryValue(PARAM_SAVED_LOW)));
dataModel.put("savedHigh", (bFormatErr?"Error":getQueryValue(PARAM_SAVED_HIGH)));
dataModel.put("ownerName", getQueryValue(PARAM_BM_OWNER));
dataModel.put("category", getQueryValue(PARAM_CATEGORY));
dataModel.put("orderBy", getQueryValue(PARAM_ORDERBY));
Expand Down Expand Up @@ -155,7 +171,7 @@ public Representation get_html() {
}


private BiomodelRepresentation[] getBiomodelRepresentations(User vcellUser) {
private BiomodelRepresentation[] getBiomodelRepresentations(User vcellUser) throws ParseException{
// if (!application.authenticate(getRequest(), getResponse())){
// // not authenticated
// return new SimulationTaskRepresentation[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import java.beans.PropertyVetoException;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import java.util.TreeMap;
Expand Down Expand Up @@ -281,14 +284,14 @@ public DataSetTimeSeries getDataSetTimeSeries(SimDataValuesServerResource resour
}
}

public BioModelRep[] query(BiomodelsServerResource resource, User vcellUser) throws SQLException, DataAccessException {
public BioModelRep[] query(BiomodelsServerResource resource, User vcellUser) throws SQLException, DataAccessException, ParseException {
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);
String savedLow = resource.getQueryValue(BiomodelsServerResource.PARAM_SAVED_LOW);
String savedHigh = resource.getQueryValue(BiomodelsServerResource.PARAM_SAVED_HIGH);
Long startRowParam = resource.getLongQueryValue(BiomodelsServerResource.PARAM_START_ROW);
Long maxRowsParam = resource.getLongQueryValue(BiomodelsServerResource.PARAM_MAX_ROWS);
String categoryParam = resource.getQueryValue(BiomodelsServerResource.PARAM_CATEGORY); // it is ok if the category is null;
Expand All @@ -304,13 +307,16 @@ public BioModelRep[] query(BiomodelsServerResource resource, User vcellUser) thr
}
ArrayList<String> conditions = new ArrayList<String>();

java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss", java.util.Locale.US);
//java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss", java.util.Locale.US);
SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd",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 (savedLow != null && savedLow.length()>0){
df.parse(savedLow);
conditions.add("(" + BioModelTable.table.versionDate.getQualifiedColName() + " >= to_date('" + savedLow + "', 'yyyy/mm/dd'))");
}
if (savedHigh != null){
conditions.add("(" + BioModelTable.table.versionDate.getQualifiedColName() + " <= to_date('" + df.format(new Date(savedHigh)) + "', 'mm/dd/yyyy HH24:MI:SS'))");
if (savedHigh != null && savedHigh.length()>0){
df.parse(savedHigh);
conditions.add("(" + BioModelTable.table.versionDate.getQualifiedColName() + " <= to_date('" + savedHigh + "', 'yyyy/mm/dd'))");
}
if (bioModelName != null && bioModelName.trim().length()>0){
String pattern = bioModelName.trim();
Expand Down
4 changes: 2 additions & 2 deletions vcell-api/src/main/resources/biomodels.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<input type='radio' name='category' value='education' <#if category?? && category == "education">checked=on</#if>>educational</input>
</td></tr>
<tr><td>Owner</td><td><input type='text' name='owner' value='${ownerName!""}'/></td></tr>
<tr><td>Begin Time</td><td><input type='text' name='savedLow' value='${savedLow!""}'/></td></tr>
<tr><td>End Timestamp</td><td><input type='text' name='savedHigh' value='${savedHigh!""}'/></td></tr>
<tr><td>Begin Date (yyyy/mm/dd)</td><td><input type='text' name='savedLow' value='${savedLow!""}'/></td></tr>
<tr><td>End Date (yyyy/mm/dd)</td><td><input type='text' name='savedHigh' value='${savedHigh!""}'/></td></tr>
<tr><td>start row</td><td><input type='text' name='startRow' value='${startRow}'/></td></tr>
<tr><td>max num rows</td><td><input type='text' name='maxRows' value='${maxRows}'/></td></tr>
<tr><td>Order By</td><td>
Expand Down

0 comments on commit 24b51ef

Please sign in to comment.