Search in sources :

Example 26 with VCellApiApplication

use of org.vcell.rest.VCellApiApplication in project vcell by virtualcell.

the class SimulationStatusServerResource method get_json.

@Override
public SimulationStatusRepresentation[] get_json() {
    VCellApiApplication application = ((VCellApiApplication) getApplication());
    User vcellUser = application.getVCellUser(getChallengeResponse(), AuthenticationPolicy.prohibitInvalidCredentials);
    return getSimulationStatusRepresentations(vcellUser);
}
Also used : User(org.vcell.util.document.User) VCellApiApplication(org.vcell.rest.VCellApiApplication)

Example 27 with VCellApiApplication

use of org.vcell.rest.VCellApiApplication in project vcell by virtualcell.

the class SimulationStatusServerResource method get_html.

@Override
public Representation get_html() {
    VCellApiApplication application = ((VCellApiApplication) getApplication());
    User vcellUser = application.getVCellUser(getChallengeResponse(), AuthenticationPolicy.ignoreInvalidCredentials);
    SimulationStatusRepresentation[] simStatuses = getSimulationStatusRepresentations(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("userId", getAttribute(PARAM_USER));
    dataModel.put("simId", getQueryValue(PARAM_SIM_ID));
    dataModel.put("hasData", getQueryValue(PARAM_HAS_DATA));
    dataModel.put("neverran", getBooleanQueryValue(PARAM_STATUS_NEVERRAN, false));
    dataModel.put("active", getBooleanQueryValue(PARAM_STATUS_ACTIVE, false));
    dataModel.put("completed", getBooleanQueryValue(PARAM_STATUS_COMPLETED, false));
    dataModel.put("failed", getBooleanQueryValue(PARAM_STATUS_FAILED, false));
    dataModel.put("stopped", getBooleanQueryValue(PARAM_STATUS_STOPPED, false));
    dataModel.put("submitLow", getLongQueryValue(PARAM_SUBMIT_LOW));
    dataModel.put("submitHigh", getLongQueryValue(PARAM_SUBMIT_HIGH));
    dataModel.put("startLow", getLongQueryValue(PARAM_START_LOW));
    dataModel.put("startHigh", getLongQueryValue(PARAM_START_HIGH));
    dataModel.put("endLow", getLongQueryValue(PARAM_END_LOW));
    dataModel.put("endHigh", getLongQueryValue(PARAM_END_HIGH));
    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("simStatuses", Arrays.asList(simStatuses));
    Gson gson = new Gson();
    dataModel.put("jsonResponse", gson.toJson(simStatuses));
    Configuration templateConfiguration = application.getTemplateConfiguration();
    Representation formFtl = new ClientResource(LocalReference.createClapReference("/simulationStatus.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) SimulationStatusRepresentation(org.vcell.rest.common.SimulationStatusRepresentation) Representation(org.restlet.representation.Representation) VCellApiApplication(org.vcell.rest.VCellApiApplication) ClientResource(org.restlet.resource.ClientResource) SimulationStatusRepresentation(org.vcell.rest.common.SimulationStatusRepresentation)

Example 28 with VCellApiApplication

use of org.vcell.rest.VCellApiApplication in project vcell by virtualcell.

the class SimulationTasksServerResource method get_json.

@Override
public SimulationTaskRepresentation[] get_json() {
    VCellApiApplication application = ((VCellApiApplication) getApplication());
    User vcellUser = application.getVCellUser(getChallengeResponse(), AuthenticationPolicy.prohibitInvalidCredentials);
    return getSimulationTaskRepresentations(vcellUser);
}
Also used : User(org.vcell.util.document.User) VCellApiApplication(org.vcell.rest.VCellApiApplication)

Example 29 with VCellApiApplication

use of org.vcell.rest.VCellApiApplication in project vcell by virtualcell.

the class SimulationTasksServerResource method get_html.

@Override
public Representation get_html() {
    VCellApiApplication application = ((VCellApiApplication) getApplication());
    User vcellUser = application.getVCellUser(getChallengeResponse(), AuthenticationPolicy.ignoreInvalidCredentials);
    SimulationTaskRepresentation[] simTasks = getSimulationTaskRepresentations(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("userId", getAttribute(PARAM_USER));
    dataModel.put("simId", getQueryValue(PARAM_SIM_ID));
    dataModel.put("jobId", getLongQueryValue(PARAM_JOB_ID));
    dataModel.put("taskId", getLongQueryValue(PARAM_TASK_ID));
    dataModel.put("computeHost", getQueryValue(PARAM_COMPUTE_HOST));
    dataModel.put("serverId", getQueryValue(PARAM_SERVER_ID));
    dataModel.put("hasData", getQueryValue(PARAM_HAS_DATA));
    dataModel.put("waiting", getBooleanQueryValue(PARAM_STATUS_WAITING, false));
    dataModel.put("queued", getBooleanQueryValue(PARAM_STATUS_QUEUED, false));
    dataModel.put("dispatched", getBooleanQueryValue(PARAM_STATUS_DISPATCHED, false));
    dataModel.put("running", getBooleanQueryValue(PARAM_STATUS_RUNNING, false));
    dataModel.put("completed", getBooleanQueryValue(PARAM_STATUS_COMPLETED, false));
    dataModel.put("failed", getBooleanQueryValue(PARAM_STATUS_FAILED, false));
    dataModel.put("stopped", getBooleanQueryValue(PARAM_STATUS_STOPPED, false));
    dataModel.put("submitLow", getLongQueryValue(PARAM_SUBMIT_LOW));
    dataModel.put("submitHigh", getLongQueryValue(PARAM_SUBMIT_HIGH));
    dataModel.put("startLow", getLongQueryValue(PARAM_START_LOW));
    dataModel.put("startHigh", getLongQueryValue(PARAM_START_HIGH));
    dataModel.put("endLow", getLongQueryValue(PARAM_END_LOW));
    dataModel.put("endHigh", getLongQueryValue(PARAM_END_HIGH));
    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("simTasks", Arrays.asList(simTasks));
    Gson gson = new Gson();
    dataModel.put("jsonResponse", gson.toJson(simTasks));
    Configuration templateConfiguration = application.getTemplateConfiguration();
    Representation formFtl = new ClientResource(LocalReference.createClapReference("/simulationTasks.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) SimulationTaskRepresentation(org.vcell.rest.common.SimulationTaskRepresentation) Representation(org.restlet.representation.Representation) SimulationTaskRepresentation(org.vcell.rest.common.SimulationTaskRepresentation) VCellApiApplication(org.vcell.rest.VCellApiApplication) ClientResource(org.restlet.resource.ClientResource)

Example 30 with VCellApiApplication

use of org.vcell.rest.VCellApiApplication in project vcell by virtualcell.

the class NewUserRestlet method handleJsonRequest.

private void handleJsonRequest(Request request, Response response) {
    String content = request.getEntityAsText();
    Gson gson = new Gson();
    org.vcell.api.common.UserInfo userinfo = gson.fromJson(content, org.vcell.api.common.UserInfo.class);
    if (userinfo.email.length() < 4) {
        response.setStatus(Status.CLIENT_ERROR_FORBIDDEN);
        response.setEntity("valid email required", MediaType.TEXT_PLAIN);
        return;
    }
    if (userinfo.userid.length() < 4 || !userinfo.userid.equals(org.vcell.util.TokenMangler.fixTokenStrict(userinfo.userid))) {
        response.setStatus(Status.CLIENT_ERROR_FORBIDDEN);
        response.setEntity("userid must be at least 4 characters and contain only alpha-numeric characters", MediaType.TEXT_PLAIN);
        return;
    }
    // form new UnverifiedUserInfo
    UserInfo newUserInfo = new UserInfo();
    newUserInfo.company = userinfo.company;
    newUserInfo.country = userinfo.country;
    newUserInfo.digestedPassword0 = DigestedPassword.createAlreadyDigested(userinfo.digestedPassword0);
    newUserInfo.email = userinfo.email;
    newUserInfo.wholeName = userinfo.wholeName;
    newUserInfo.notify = userinfo.notify;
    newUserInfo.title = userinfo.title;
    newUserInfo.userid = userinfo.userid;
    boolean bEmailVerification = false;
    if (!bEmailVerification) {
        // add Unverified UserInfo and send email
        VCellApiApplication vcellApiApplication = (VCellApiApplication) getApplication();
        try {
            UserInfo insertedUserInfo = vcellApiApplication.getRestDatabaseService().addUser(newUserInfo);
            org.vcell.api.common.UserInfo inserted = insertedUserInfo.getApiUserInfo();
            String userInfoJson = gson.toJson(inserted);
            JsonRepresentation userRep = new JsonRepresentation(userInfoJson);
            response.setStatus(Status.SUCCESS_CREATED);
            response.setEntity(userRep);
            return;
        } catch (SQLException | DataAccessException e) {
            e.printStackTrace();
            response.setStatus(Status.SERVER_ERROR_INTERNAL);
            response.setEntity("failed to add user " + newUserInfo.userid + ": " + e.getMessage(), MediaType.TEXT_PLAIN);
            return;
        } catch (UseridIDExistsException e) {
            e.printStackTrace();
            response.setStatus(Status.CLIENT_ERROR_FORBIDDEN);
            response.setEntity("failed to add user " + newUserInfo.userid + ": " + e.getMessage(), MediaType.TEXT_PLAIN);
            return;
        }
    } else {
        Date submitDate = new Date();
        // one hour
        long timeExpiresMS = 1000 * 60 * 60 * 1;
        Date expirationDate = new Date(System.currentTimeMillis() + timeExpiresMS);
        DigestedPassword emailVerifyToken = new DigestedPassword(Long.toString(System.currentTimeMillis()));
        UnverifiedUser unverifiedUser = new UnverifiedUser(newUserInfo, submitDate, expirationDate, emailVerifyToken.getString());
        // add Unverified UserInfo and send email
        VCellApiApplication vcellApiApplication = (VCellApiApplication) getApplication();
        vcellApiApplication.getUserVerifier().addUnverifiedUser(unverifiedUser);
        try {
            // Send new password to user
            PropertyLoader.loadProperties();
            BeanUtils.sendSMTP(PropertyLoader.getRequiredProperty(PropertyLoader.vcellSMTPHostName), new Integer(PropertyLoader.getRequiredProperty(PropertyLoader.vcellSMTPPort)).intValue(), PropertyLoader.getRequiredProperty(PropertyLoader.vcellSMTPEmailAddress), newUserInfo.email, "new VCell account verification", "You have received this email to verify that a Virtual Cell account has been associated " + "with this email address.  To activate this account, please follow this link: " + request.getResourceRef().getHostIdentifier() + "/" + VCellApiApplication.NEWUSER_VERIFY + "?" + VCellApiApplication.EMAILVERIFYTOKEN_FORMNAME + "=" + emailVerifyToken.getString());
        } catch (Exception e) {
            e.printStackTrace();
            response.setStatus(Status.SERVER_ERROR_INTERNAL);
            response.setEntity("we failed to send a verification email to " + newUserInfo.email, MediaType.TEXT_PLAIN);
            return;
        }
        response.setStatus(Status.SUCCESS_CREATED);
        response.setEntity("we sent you a verification email at " + newUserInfo.email + ", please follow the link in that email", MediaType.TEXT_PLAIN);
    }
}
Also used : SQLException(java.sql.SQLException) Gson(com.google.gson.Gson) UserInfo(org.vcell.util.document.UserInfo) DigestedPassword(org.vcell.util.document.UserLoginInfo.DigestedPassword) Date(java.util.Date) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) UseridIDExistsException(org.vcell.util.UseridIDExistsException) SQLException(java.sql.SQLException) VCellApiApplication(org.vcell.rest.VCellApiApplication) UseridIDExistsException(org.vcell.util.UseridIDExistsException) JsonRepresentation(org.restlet.ext.json.JsonRepresentation) DataAccessException(org.vcell.util.DataAccessException)

Aggregations

VCellApiApplication (org.vcell.rest.VCellApiApplication)53 User (org.vcell.util.document.User)34 ResourceException (org.restlet.resource.ResourceException)21 PermissionException (org.vcell.util.PermissionException)20 Gson (com.google.gson.Gson)14 Representation (org.restlet.representation.Representation)14 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)14 HashMap (java.util.HashMap)13 Configuration (freemarker.template.Configuration)12 TemplateRepresentation (org.restlet.ext.freemarker.TemplateRepresentation)11 ClientResource (org.restlet.resource.ClientResource)11 JsonRepresentation (org.restlet.ext.json.JsonRepresentation)9 Form (org.restlet.data.Form)8 StringRepresentation (org.restlet.representation.StringRepresentation)8 BioModel (cbit.vcell.biomodel.BioModel)6 XMLSource (cbit.vcell.xml.XMLSource)6 SQLException (java.sql.SQLException)6 ArrayList (java.util.ArrayList)6 BiomodelRepresentation (org.vcell.rest.common.BiomodelRepresentation)6 PublicationRepresentation (org.vcell.rest.common.PublicationRepresentation)6