Search in sources :

Example 1 with PublicationRepresentation

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());
    }
// }
}
Also used : PermissionException(org.vcell.util.PermissionException) PublicationRepresentation(org.vcell.rest.common.PublicationRepresentation) PublicationRep(cbit.vcell.modeldb.PublicationRep) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) ResourceException(org.restlet.resource.ResourceException) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) ResourceException(org.restlet.resource.ResourceException)

Example 2 with PublicationRepresentation

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;
}
Also used : TemplateRepresentation(org.restlet.ext.freemarker.TemplateRepresentation) User(org.vcell.util.document.User) Configuration(freemarker.template.Configuration) HashMap(java.util.HashMap) Gson(com.google.gson.Gson) TemplateRepresentation(org.restlet.ext.freemarker.TemplateRepresentation) PublicationRepresentation(org.vcell.rest.common.PublicationRepresentation) Representation(org.restlet.representation.Representation) PublicationRepresentation(org.vcell.rest.common.PublicationRepresentation) VCellApiApplication(org.vcell.rest.VCellApiApplication) ClientResource(org.restlet.resource.ClientResource)

Example 3 with PublicationRepresentation

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());
    }
// }
}
Also used : PermissionException(org.vcell.util.PermissionException) PublicationRepresentation(org.vcell.rest.common.PublicationRepresentation) PublicationRep(cbit.vcell.modeldb.PublicationRep) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) VCellApiApplication(org.vcell.rest.VCellApiApplication) ResourceException(org.restlet.resource.ResourceException) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) ResourceException(org.restlet.resource.ResourceException)

Example 4 with PublicationRepresentation

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]);
}
Also used : PermissionException(org.vcell.util.PermissionException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ExpressionException(cbit.vcell.parser.ExpressionException) PublicationRepresentation(org.vcell.rest.common.PublicationRepresentation) PublicationRep(cbit.vcell.modeldb.PublicationRep) VCellApiApplication(org.vcell.rest.VCellApiApplication) ResourceException(org.restlet.resource.ResourceException) DataAccessException(org.vcell.util.DataAccessException)

Example 5 with PublicationRepresentation

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");
}
Also used : PublicationRepresentation(org.vcell.rest.common.PublicationRepresentation) User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) VCellApiApplication(org.vcell.rest.VCellApiApplication)

Aggregations

PublicationRepresentation (org.vcell.rest.common.PublicationRepresentation)7 VCellApiApplication (org.vcell.rest.VCellApiApplication)6 PublicationRep (cbit.vcell.modeldb.PublicationRep)4 ResourceException (org.restlet.resource.ResourceException)4 PermissionException (org.vcell.util.PermissionException)4 User (org.vcell.util.document.User)4 Configuration (freemarker.template.Configuration)3 HashMap (java.util.HashMap)3 TemplateRepresentation (org.restlet.ext.freemarker.TemplateRepresentation)3 Representation (org.restlet.representation.Representation)3 ClientResource (org.restlet.resource.ClientResource)3 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)3 KeyValue (org.vcell.util.document.KeyValue)3 Gson (com.google.gson.Gson)2 StringRepresentation (org.restlet.representation.StringRepresentation)2 BiomodelReferenceRepresentation (org.vcell.rest.common.BiomodelReferenceRepresentation)2 MathmodelReferenceRepresentation (org.vcell.rest.common.MathmodelReferenceRepresentation)2 BioModelReferenceRep (cbit.vcell.modeldb.BioModelReferenceRep)1 MathModelReferenceRep (cbit.vcell.modeldb.MathModelReferenceRep)1 ExpressionException (cbit.vcell.parser.ExpressionException)1