use of org.vcell.rest.common.BiomodelRepresentation in project vcell by virtualcell.
the class BiomodelsServerResource method get_json.
@Override
public BiomodelRepresentation[] get_json() {
VCellApiApplication application = ((VCellApiApplication) getApplication());
User vcellUser = application.getVCellUser(getChallengeResponse(), AuthenticationPolicy.prohibitInvalidCredentials);
BiomodelRepresentation[] bmReps = new BiomodelRepresentation[0];
try {
bmReps = getBiomodelRepresentations(vcellUser);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return bmReps;
}
use of org.vcell.rest.common.BiomodelRepresentation in project vcell by virtualcell.
the class BiomodelsServerResource method get_html.
@Override
public Representation get_html() {
VCellApiApplication application = ((VCellApiApplication) getApplication());
User vcellUser = application.getVCellUser(getChallengeResponse(), AuthenticationPolicy.ignoreInvalidCredentials);
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>();
// +"?"+VCellApiApplication.REDIRECTURL_FORMNAME+"="+getRequest().getResourceRef().toUrl());
dataModel.put("loginurl", "/" + VCellApiApplication.LOGINFORM);
dataModel.put("logouturl", "/" + VCellApiApplication.LOGOUT + "?" + VCellApiApplication.REDIRECTURL_FORMNAME + "=" + Reference.encode(getRequest().getResourceRef().toUrl().toString()));
if (vcellUser != null) {
dataModel.put("userid", vcellUser.getName());
}
dataModel.put("userId", getAttribute(PARAM_USER));
dataModel.put("bmName", getQueryValue(PARAM_BM_NAME));
dataModel.put("bmId", getQueryValue(PARAM_BM_ID));
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));
Long startRowParam = getLongQueryValue(PARAM_START_ROW);
if (startRowParam != null) {
dataModel.put("startRow", startRowParam);
} else {
dataModel.put("startRow", 1);
}
Long maxRowsParam = getLongQueryValue(PARAM_MAX_ROWS);
if (maxRowsParam != null) {
dataModel.put("maxRows", maxRowsParam);
} else {
dataModel.put("maxRows", 10);
}
dataModel.put("biomodels", Arrays.asList(biomodels));
Gson gson = new Gson();
dataModel.put("jsonResponse", gson.toJson(biomodels));
Configuration templateConfiguration = application.getTemplateConfiguration();
Representation formFtl = new ClientResource(LocalReference.createClapReference("/biomodels.ftl")).get();
TemplateRepresentation templateRepresentation = new TemplateRepresentation(formFtl, templateConfiguration, dataModel, MediaType.TEXT_HTML);
return templateRepresentation;
}
use of org.vcell.rest.common.BiomodelRepresentation in project vcell by virtualcell.
the class BiomodelsServerResource method getBiomodelRepresentations.
private BiomodelRepresentation[] getBiomodelRepresentations(User vcellUser) throws ParseException {
// if (!application.authenticate(getRequest(), getResponse())){
// // not authenticated
// return new SimulationTaskRepresentation[0];
// }else{
ArrayList<BiomodelRepresentation> biomodelReps = new ArrayList<BiomodelRepresentation>();
RestDatabaseService restDatabaseService = ((VCellApiApplication) getApplication()).getRestDatabaseService();
try {
BioModelRep[] bioModelReps = restDatabaseService.query(this, vcellUser);
for (BioModelRep bioModelRep : bioModelReps) {
BiomodelRepresentation biomodelRep = new BiomodelRepresentation(bioModelRep);
biomodelReps.add(biomodelRep);
}
} catch (PermissionException ee) {
ee.printStackTrace();
throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED, "not authorized");
} catch (DataAccessException | SQLException | ExpressionException e) {
e.printStackTrace();
throw new RuntimeException("failed to retrieve biomodels from VCell Database : " + e.getMessage());
}
return biomodelReps.toArray(new BiomodelRepresentation[0]);
// }
}
use of org.vcell.rest.common.BiomodelRepresentation in project vcell by virtualcell.
the class BiomodelServerResource method getBiomodelRepresentation.
private BiomodelRepresentation getBiomodelRepresentation(User vcellUser) {
// if (!application.authenticate(getRequest(), getResponse())){
// // not authenticated
// return new SimulationTaskRepresentation[0];
// }else{
RestDatabaseService restDatabaseService = ((VCellApiApplication) getApplication()).getRestDatabaseService();
try {
BioModelRep bioModelRep = restDatabaseService.query(this, vcellUser);
BiomodelRepresentation biomodelRep = new BiomodelRepresentation(bioModelRep);
return biomodelRep;
} catch (PermissionException e) {
e.printStackTrace();
throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED, "permission denied to requested resource");
} catch (ObjectNotFoundException e) {
e.printStackTrace();
throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "biomodel not found");
} catch (Exception e) {
throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage());
}
// }
}
use of org.vcell.rest.common.BiomodelRepresentation in project vcell by virtualcell.
the class BiomodelServerResource method get_html.
@Override
public Representation get_html() {
VCellApiApplication application = ((VCellApiApplication) getApplication());
User vcellUser = application.getVCellUser(getChallengeResponse(), AuthenticationPolicy.ignoreInvalidCredentials);
BiomodelRepresentation biomodel = getBiomodelRepresentation(vcellUser);
if (biomodel == null) {
throw new RuntimeException("biomodel not found");
}
Map<String, Object> dataModel = new HashMap<String, Object>();
// +"?"+VCellApiApplication.REDIRECTURL_FORMNAME+"="+getRequest().getResourceRef().toUrl());
dataModel.put("loginurl", "/" + VCellApiApplication.LOGINFORM);
dataModel.put("logouturl", "/" + VCellApiApplication.LOGOUT + "?" + VCellApiApplication.REDIRECTURL_FORMNAME + "=" + Reference.encode(getRequest().getResourceRef().toUrl().toString()));
if (vcellUser != null) {
dataModel.put("userid", vcellUser.getName());
}
dataModel.put("bmId", getQueryValue(VCellApiApplication.BIOMODELID));
dataModel.put("biomodel", biomodel);
Gson gson = new Gson();
dataModel.put("jsonResponse", gson.toJson(biomodel));
Configuration templateConfiguration = application.getTemplateConfiguration();
Representation formFtl = new ClientResource(LocalReference.createClapReference("/biomodel.ftl")).get();
TemplateRepresentation templateRepresentation = new TemplateRepresentation(formFtl, templateConfiguration, dataModel, MediaType.TEXT_HTML);
return templateRepresentation;
}
Aggregations