use of org.vcell.rest.common.PublicationRepresentation in project vcell by virtualcell.
the class PublicationServerResource method getPublicationRepresentation.
private static PublicationRepresentation getPublicationRepresentation(RestDatabaseService restDatabaseService, User vcellUser, KeyValue pubID) {
// RestDatabaseService restDatabaseService = ((VCellApiApplication)getApplication()).getRestDatabaseService();
try {
PublicationRep publicationRep = restDatabaseService.getPublicationRep(pubID, vcellUser);
PublicationRepresentation publicationRepresentation = new PublicationRepresentation(publicationRep);
return publicationRepresentation;
} 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, "publication not found");
} catch (Exception e) {
throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage());
}
// }
}
use of org.vcell.rest.common.PublicationRepresentation in project vcell by virtualcell.
the class PublicationsServerResource method get_html.
@Override
public Representation get_html() {
VCellApiApplication application = ((VCellApiApplication) getApplication());
User vcellUser = application.getVCellUser(getChallengeResponse(), AuthenticationPolicy.ignoreInvalidCredentials);
PublicationRepresentation[] publications = getPublicationRepresentations(vcellUser);
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("pubId", getQueryValue(PARAM_PUB_ID));
dataModel.put("orderBy", getQueryValue(PARAM_ORDERBY));
dataModel.put("publications", Arrays.asList(publications));
Gson gson = new Gson();
dataModel.put("jsonResponse", gson.toJson(publications));
Configuration templateConfiguration = application.getTemplateConfiguration();
Representation formFtl = new ClientResource(LocalReference.createClapReference("/publications.ftl")).get();
TemplateRepresentation templateRepresentation = new TemplateRepresentation(formFtl, templateConfiguration, dataModel, MediaType.TEXT_HTML);
return templateRepresentation;
}
use of org.vcell.rest.common.PublicationRepresentation in project vcell by virtualcell.
the class PublicationServerResource method getPublicationRepresentation.
private PublicationRepresentation getPublicationRepresentation(User vcellUser) {
// if (!application.authenticate(getRequest(), getResponse())){
// // not authenticated
// return new SimulationTaskRepresentation[0];
// }else{
RestDatabaseService restDatabaseService = ((VCellApiApplication) getApplication()).getRestDatabaseService();
try {
PublicationRep publicationRep = restDatabaseService.query(this, vcellUser);
PublicationRepresentation publicationRepresentation = new PublicationRepresentation(publicationRep);
return publicationRepresentation;
} 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, "publication not found");
} catch (Exception e) {
throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage());
}
// }
}
use of org.vcell.rest.common.PublicationRepresentation in project vcell by virtualcell.
the class PublicationsServerResource method getPublicationRepresentations.
private PublicationRepresentation[] getPublicationRepresentations(User vcellUser) {
ArrayList<PublicationRepresentation> publicationRepresentations = new ArrayList<PublicationRepresentation>();
RestDatabaseService restDatabaseService = ((VCellApiApplication) getApplication()).getRestDatabaseService();
try {
PublicationRep[] publicationReps = restDatabaseService.query(this, vcellUser);
for (PublicationRep publicationRep : publicationReps) {
PublicationRepresentation publicationRepresentation = new PublicationRepresentation(publicationRep);
publicationRepresentations.add(publicationRepresentation);
}
} 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 publicationRepresentations.toArray(new PublicationRepresentation[0]);
}
use of org.vcell.rest.common.PublicationRepresentation in project vcell by virtualcell.
the class PublicationServerResource method get_json.
@Override
public PublicationRepresentation get_json() {
VCellApiApplication application = ((VCellApiApplication) getApplication());
User vcellUser = application.getVCellUser(getChallengeResponse(), AuthenticationPolicy.prohibitInvalidCredentials);
Object pubIdObj = getRequestAttributes().get(VCellApiApplication.PUBLICATIONID);
PublicationRepresentation publicationRep = getPublicationRepresentation(((VCellApiApplication) getApplication()).getRestDatabaseService(), vcellUser, new KeyValue(pubIdObj.toString()));
if (publicationRep != null) {
return publicationRep;
}
throw new RuntimeException("publication not found");
}
Aggregations