Search in sources :

Example 6 with ClientResource

use of org.restlet.resource.ClientResource in project vcell by virtualcell.

the class PublicationServerResource method get_html.

@Override
public Representation get_html() {
    VCellApiApplication application = ((VCellApiApplication) getApplication());
    User vcellUser = application.getVCellUser(getChallengeResponse(), AuthenticationPolicy.ignoreInvalidCredentials);
    PublicationRepresentation publication = null;
    Map<String, Object> dataModel = new HashMap<String, Object>();
    Object pubIdObj = getRequestAttributes().get(VCellApiApplication.PUBLICATIONID);
    if (pubIdObj != null) {
        publication = getPublicationRepresentation(((VCellApiApplication) getApplication()).getRestDatabaseService(), vcellUser, new KeyValue(pubIdObj.toString()));
    } else {
        throw new RuntimeException("publication not found");
    }
    // +"?"+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(VCellApiApplication.PUBLICATIONID));
    dataModel.put("publication", publication);
    Gson gson = new Gson();
    dataModel.put("jsonResponse", gson.toJson(publication));
    Configuration templateConfiguration = application.getTemplateConfiguration();
    Representation formFtl = new ClientResource(LocalReference.createClapReference("/publication.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) KeyValue(org.vcell.util.document.KeyValue) Configuration(freemarker.template.Configuration) HashMap(java.util.HashMap) Gson(com.google.gson.Gson) TemplateRepresentation(org.restlet.ext.freemarker.TemplateRepresentation) MathmodelReferenceRepresentation(org.vcell.rest.common.MathmodelReferenceRepresentation) BiomodelReferenceRepresentation(org.vcell.rest.common.BiomodelReferenceRepresentation) StringRepresentation(org.restlet.representation.StringRepresentation) 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 7 with ClientResource

use of org.restlet.resource.ClientResource in project vcell by virtualcell.

the class PublicationServerResource method handleForm.

@Post
public Representation handleForm(Representation entity) {
    try {
        String myHost = getHostRef().getHostDomain();
        String allowedPublicationHost = PropertyLoader.getProperty(PropertyLoader.vcellPublicationHost, "");
        if (!allowedPublicationHost.equals(myHost)) {
            throw new PermissionException("Host '" + myHost + "' not allowed to edit publications");
        }
        Form form = new Form(entity);
        VCellApiApplication application = ((VCellApiApplication) getApplication());
        User vcellUser = application.getVCellUser(getChallengeResponse(), AuthenticationPolicy.ignoreInvalidCredentials);
        if (vcellUser == null) {
            throw new PermissionException("must be authenticated to edit publication info");
        }
        // The form contains input with names "user" and "password"
        String pubop = form.getFirstValue("pubop");
        // String password = form.getFirstValue("password");
        Map<String, Object> dataModel = new HashMap<String, Object>();
        if (pubop == null) {
            return new StringRepresentation(("value of publication 'operation' cannot be null"));
        } else if (pubop.equals("editNew")) {
            PublicationRepresentation value = new PublicationRepresentation();
            value.pubKey = AUTOMATICALLY_GENERATED;
            dataModel.put("publicationRepr", value);
        } else if (pubop.equals("editWithKey")) {
            Object pubidObj = getRequestAttributes().get(VCellApiApplication.PUBLICATIONID);
            PublicationRepresentation publication = getPublicationRepresentation(((VCellApiApplication) getApplication()).getRestDatabaseService(), vcellUser, new KeyValue(pubidObj.toString()));
            dataModel.put("publicationRepr", publication);
        } else if (pubop.equals("applyEdit")) {
            SimpleDateFormat sdf = new java.text.SimpleDateFormat("MM/dd/yyyy", java.util.Locale.US);
            // PublicationRepresentation publication = getPublicationRepresentation(((VCellApiApplication)getApplication()).getRestDatabaseService(),vcellUser,new KeyValue(form.getFirstValue("pubid")));
            String[] authors = StringUtils.split(form.getFirstValue("authors"), ";");
            for (int i = 0; i < authors.length; i++) {
                authors[i] = authors[i].trim();
            }
            String thePubID = form.getFirstValue("pubId");
            BioModelReferenceRep[] bioModelReferenceReps = (BioModelReferenceRep[]) convertToReferenceRep(form.getFirstValue("biomodelReferences"), BioModelReferenceRep.class);
            MathModelReferenceRep[] mathModelReferenceReps = (MathModelReferenceRep[]) convertToReferenceRep(form.getFirstValue("mathmodelReferences"), MathModelReferenceRep.class);
            PublicationRep publicationRep = new PublicationRep((thePubID == null || thePubID.equals(AUTOMATICALLY_GENERATED) ? null : new KeyValue(Integer.valueOf(thePubID).toString())), form.getFirstValue("title"), authors, (form.getFirstValue("year") == null || form.getFirstValue("year").trim().length() == 0 ? null : Integer.valueOf(form.getFirstValue("year"))), form.getFirstValue("citation"), form.getFirstValue("pubmedid"), form.getFirstValue("doi"), form.getFirstValue("endnoteid"), form.getFirstValue("url"), bioModelReferenceReps, mathModelReferenceReps, form.getFirstValue("wittid"), (form.getFirstValue("pubdate") == null || form.getFirstValue("pubdate").trim().length() == 0 ? null : sdf.parse(form.getFirstValue("pubdate"))));
            KeyValue savedOrEditedPubID = ((VCellApiApplication) getApplication()).getRestDatabaseService().savePublicationRep(publicationRep, vcellUser);
            // String address = getRequest().getClientInfo().getAddress();
            // int port = getRequest().getClientInfo().getPort();
            StringRepresentation s = getPubInfoHtml(myHost, savedOrEditedPubID);
            return s;
        } else if (pubop.equals("makepublic")) {
            String[] bmKeys = form.getValuesArray("bmpublic");
            KeyValue[] publishTheseBiomodels = new KeyValue[(bmKeys == null ? 0 : bmKeys.length)];
            for (int i = 0; i < publishTheseBiomodels.length; i++) {
                publishTheseBiomodels[i] = new KeyValue(bmKeys[i]);
            }
            String[] mmKeys = form.getValuesArray("mmpublic");
            KeyValue[] publishTheseMathmodels = new KeyValue[(mmKeys == null ? 0 : mmKeys.length)];
            for (int i = 0; i < publishTheseMathmodels.length; i++) {
                publishTheseMathmodels[i] = new KeyValue(mmKeys[i]);
            }
            if (publishTheseBiomodels.length > 0 || publishTheseMathmodels.length > 0) {
                ((VCellApiApplication) getApplication()).getRestDatabaseService().publishDirectly(publishTheseBiomodels, publishTheseMathmodels, vcellUser);
            }
            Object pubidObj = getRequestAttributes().get(VCellApiApplication.PUBLICATIONID);
            StringRepresentation s = getPubInfoHtml(myHost, new KeyValue(pubidObj.toString()));
            return s;
        } else {
            return new StringRepresentation(("value of pubop=" + pubop + " not expected").toCharArray());
        }
        Configuration templateConfiguration = application.getTemplateConfiguration();
        Representation myRepresentation = new ClientResource(LocalReference.createClapReference("/newpublication.ftl")).get();
        TemplateRepresentation templateRepresentation = new TemplateRepresentation(myRepresentation, templateConfiguration, dataModel, MediaType.TEXT_HTML);
        return templateRepresentation;
    } catch (Exception e) {
        return new StringRepresentation(e.getClass().getName() + " " + e.getMessage());
    }
}
Also used : PermissionException(org.vcell.util.PermissionException) TemplateRepresentation(org.restlet.ext.freemarker.TemplateRepresentation) User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) Configuration(freemarker.template.Configuration) Form(org.restlet.data.Form) HashMap(java.util.HashMap) SimpleDateFormat(java.text.SimpleDateFormat) PublicationRepresentation(org.vcell.rest.common.PublicationRepresentation) BioModelReferenceRep(cbit.vcell.modeldb.BioModelReferenceRep) PublicationRep(cbit.vcell.modeldb.PublicationRep) StringRepresentation(org.restlet.representation.StringRepresentation) VCellApiApplication(org.vcell.rest.VCellApiApplication) ClientResource(org.restlet.resource.ClientResource) MathModelReferenceRep(cbit.vcell.modeldb.MathModelReferenceRep) TemplateRepresentation(org.restlet.ext.freemarker.TemplateRepresentation) MathmodelReferenceRepresentation(org.vcell.rest.common.MathmodelReferenceRepresentation) BiomodelReferenceRepresentation(org.vcell.rest.common.BiomodelReferenceRepresentation) StringRepresentation(org.restlet.representation.StringRepresentation) PublicationRepresentation(org.vcell.rest.common.PublicationRepresentation) Representation(org.restlet.representation.Representation) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) ResourceException(org.restlet.resource.ResourceException) SimpleDateFormat(java.text.SimpleDateFormat) Post(org.restlet.resource.Post)

Example 8 with ClientResource

use of org.restlet.resource.ClientResource in project vcell by virtualcell.

the class BiomodelSimulationServerResource method get_html.

@Override
public Representation get_html() {
    VCellApiApplication application = ((VCellApiApplication) getApplication());
    User vcellUser = application.getVCellUser(getChallengeResponse(), AuthenticationPolicy.ignoreInvalidCredentials);
    SimulationRepresentation simulation = getBiomodelSimulationRepresentation(vcellUser);
    if (simulation == null) {
        throw new RuntimeException("simulation not found");
    }
    Map<String, Object> dataModel = new HashMap<String, Object>();
    dataModel.put("simulation", simulation);
    // +"?"+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());
    }
    Gson gson = new Gson();
    dataModel.put("jsonResponse", gson.toJson(simulation));
    Configuration templateConfiguration = application.getTemplateConfiguration();
    Representation formFtl = new ClientResource(LocalReference.createClapReference("/simulation.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) SimulationRepresentation(org.vcell.rest.common.SimulationRepresentation) Representation(org.restlet.representation.Representation) SimulationRepresentation(org.vcell.rest.common.SimulationRepresentation) VCellApiApplication(org.vcell.rest.VCellApiApplication) ClientResource(org.restlet.resource.ClientResource)

Example 9 with ClientResource

use of org.restlet.resource.ClientResource 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;
}
Also used : BiomodelRepresentation(org.vcell.rest.common.BiomodelRepresentation) 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) BiomodelRepresentation(org.vcell.rest.common.BiomodelRepresentation) Representation(org.restlet.representation.Representation) VCellApiApplication(org.vcell.rest.VCellApiApplication) ClientResource(org.restlet.resource.ClientResource) ParseException(java.text.ParseException)

Example 10 with ClientResource

use of org.restlet.resource.ClientResource in project vcell by virtualcell.

the class SimDataServerResource method get_html.

@Override
public Representation get_html() {
    VCellApiApplication application = ((VCellApiApplication) getApplication());
    User vcellUser = application.getVCellUser(getChallengeResponse(), AuthenticationPolicy.ignoreInvalidCredentials);
    SimDataRepresentation simData = null;
    try {
        simData = getSimDataRepresentation(vcellUser);
    } catch (Exception e) {
        e.printStackTrace(System.out);
    }
    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("simId", getQueryValue(PARAM_SIM_ID));
    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("simdata", simData);
    Gson gson = new Gson();
    dataModel.put("jsonResponse", gson.toJson(simData));
    Configuration templateConfiguration = application.getTemplateConfiguration();
    Representation formFtl = new ClientResource(LocalReference.createClapReference("/simdata.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) SimDataRepresentation(org.vcell.rest.common.SimDataRepresentation) TemplateRepresentation(org.restlet.ext.freemarker.TemplateRepresentation) SimDataRepresentation(org.vcell.rest.common.SimDataRepresentation) Representation(org.restlet.representation.Representation) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) ResourceException(org.restlet.resource.ResourceException) VCellApiApplication(org.vcell.rest.VCellApiApplication) ClientResource(org.restlet.resource.ClientResource)

Aggregations

ClientResource (org.restlet.resource.ClientResource)13 Representation (org.restlet.representation.Representation)12 Configuration (freemarker.template.Configuration)11 HashMap (java.util.HashMap)11 TemplateRepresentation (org.restlet.ext.freemarker.TemplateRepresentation)11 VCellApiApplication (org.vcell.rest.VCellApiApplication)11 User (org.vcell.util.document.User)11 Gson (com.google.gson.Gson)9 ResourceException (org.restlet.resource.ResourceException)4 StringRepresentation (org.restlet.representation.StringRepresentation)3 PublicationRepresentation (org.vcell.rest.common.PublicationRepresentation)3 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)3 PermissionException (org.vcell.util.PermissionException)3 JSONObject (org.json.JSONObject)2 JsonRepresentation (org.restlet.ext.json.JsonRepresentation)2 BiomodelReferenceRepresentation (org.vcell.rest.common.BiomodelReferenceRepresentation)2 BiomodelRepresentation (org.vcell.rest.common.BiomodelRepresentation)2 MathmodelReferenceRepresentation (org.vcell.rest.common.MathmodelReferenceRepresentation)2 KeyValue (org.vcell.util.document.KeyValue)2 BioModelReferenceRep (cbit.vcell.modeldb.BioModelReferenceRep)1