Search in sources :

Example 1 with Authorization

use of org.akaza.openclinica.service.pmanage.Authorization in project OpenClinica by OpenClinica.

the class EnketoUrlService method getRedirectUrl.

private String getRedirectUrl(String studySubjectOid, String studyOid) {
    String portalURL = CoreResources.getField("portalURL");
    String url = "";
    if (portalURL != null && !portalURL.equals("")) {
        ParticipantPortalRegistrar registrar = new ParticipantPortalRegistrar();
        Authorization pManageAuthorization = registrar.getAuthorization(studyOid);
        try {
            URL pManageUrl = new URL(portalURL);
            if (pManageAuthorization != null && pManageAuthorization.getStudy() != null && pManageAuthorization.getStudy().getHost() != null && !pManageAuthorization.getStudy().getHost().equals("")) {
                url = pManageUrl.getProtocol() + "://" + pManageAuthorization.getStudy().getHost() + "." + pManageUrl.getHost() + ((pManageUrl.getPort() > 0) ? ":" + String.valueOf(pManageUrl.getPort()) : "");
            }
        } catch (MalformedURLException e) {
            logger.error("Error building redirect URL: " + e.getMessage());
            logger.error(ExceptionUtils.getStackTrace(e));
            return "";
        }
    }
    if (!url.equals(""))
        url = url + "/#/event/" + studySubjectOid + "/dashboard";
    return url;
}
Also used : Authorization(org.akaza.openclinica.service.pmanage.Authorization) MalformedURLException(java.net.MalformedURLException) ParticipantPortalRegistrar(org.akaza.openclinica.service.pmanage.ParticipantPortalRegistrar) URL(java.net.URL)

Example 2 with Authorization

use of org.akaza.openclinica.service.pmanage.Authorization in project OpenClinica by OpenClinica.

the class EditFormController method getRedirectUrl.

private String getRedirectUrl(String studySubjectOid, String studyOid) {
    String portalURL = CoreResources.getField("portalURL");
    String url = "";
    if (portalURL != null && !portalURL.equals("")) {
        ParticipantPortalRegistrar registrar = new ParticipantPortalRegistrar();
        Authorization pManageAuthorization = registrar.getAuthorization(studyOid);
        try {
            URL pManageUrl = new URL(portalURL);
            if (pManageAuthorization != null && pManageAuthorization.getStudy() != null && pManageAuthorization.getStudy().getHost() != null && !pManageAuthorization.getStudy().getHost().equals("")) {
                url = pManageUrl.getProtocol() + "://" + pManageAuthorization.getStudy().getHost() + "." + pManageUrl.getHost() + ((pManageUrl.getPort() > 0) ? ":" + String.valueOf(pManageUrl.getPort()) : "");
            }
        } catch (MalformedURLException e) {
            logger.error("Error building redirect URL: " + e.getMessage());
            logger.error(ExceptionUtils.getStackTrace(e));
            return "";
        }
    }
    if (!url.equals(""))
        url = url + "/#/event/" + studySubjectOid + "/dashboard";
    return url;
}
Also used : Authorization(org.akaza.openclinica.service.pmanage.Authorization) MalformedURLException(java.net.MalformedURLException) ParticipantPortalRegistrar(org.akaza.openclinica.service.pmanage.ParticipantPortalRegistrar) URL(java.net.URL)

Example 3 with Authorization

use of org.akaza.openclinica.service.pmanage.Authorization in project OpenClinica by OpenClinica.

the class EnketoCredentials method getInstance.

public static EnketoCredentials getInstance(String studyOid) {
    EnketoCredentials credentials = new EnketoCredentials();
    String pManageUrl = CoreResources.getField("portalURL") + "/app/rest/oc/authorizations";
    String ocUrl = CoreResources.getField("sysURL.base") + "rest2/openrosa/" + studyOid;
    RestTemplate rest = new RestTemplate();
    try {
        Authorization[] response = rest.getForObject(pManageUrl + "?studyoid=" + studyOid + "&instanceurl=" + ocUrl, Authorization[].class);
        if (response.length > 0) {
            credentials.setServerUrl(response[0].getPformUrl());
            credentials.setApiKey(response[0].getPformApiKey());
            credentials.setOcInstanceUrl(ocUrl);
        } else {
            logger.error("Unexpected response received from Participant Portal while retrieving PForm credentials.  Returning empty credentials.");
        }
    } catch (Exception e) {
        logger.error(e.getMessage());
        logger.error(ExceptionUtils.getStackTrace(e));
        logger.error("Unexpected Exception received from Participant Portal while retrieving PForm credentials: " + e.getMessage() + ".  Returning empty credentials.");
    }
    return credentials;
}
Also used : Authorization(org.akaza.openclinica.service.pmanage.Authorization) RestTemplate(org.springframework.web.client.RestTemplate)

Example 4 with Authorization

use of org.akaza.openclinica.service.pmanage.Authorization in project OpenClinica by OpenClinica.

the class EnketoCredentials method getInstance.

public static EnketoCredentials getInstance(String studyOid) {
    Study study = getParentStudy(studyOid);
    studyOid = study.getOc_oid();
    EnketoCredentials credentials = new EnketoCredentials();
    String pManageUrl = CoreResources.getField("portalURL") + "/app/rest/oc/authorizations";
    String ocUrl = CoreResources.getField("sysURL.base") + "rest2/openrosa/" + studyOid;
    RestTemplate rest = new RestTemplate();
    try {
        Authorization[] response = rest.getForObject(pManageUrl + "?studyoid=" + studyOid + "&instanceurl=" + ocUrl, Authorization[].class);
        if (response.length > 0) {
            credentials.setServerUrl(response[0].getPformUrl());
            credentials.setApiKey(response[0].getPformApiKey());
            credentials.setOcInstanceUrl(ocUrl);
        } else {
            logger.error("Unexpected response received from Participant Portal while retrieving PForm credentials.  Returning empty credentials.");
        }
    } catch (Exception e) {
        logger.error(e.getMessage());
        logger.error(ExceptionUtils.getStackTrace(e));
        logger.error("Unexpected Exception received from Participant Portal while retrieving PForm credentials: " + e.getMessage() + ".  Returning empty credentials.");
    }
    return credentials;
}
Also used : Authorization(org.akaza.openclinica.service.pmanage.Authorization) Study(org.akaza.openclinica.domain.datamap.Study) RestTemplate(org.springframework.web.client.RestTemplate)

Example 5 with Authorization

use of org.akaza.openclinica.service.pmanage.Authorization in project OpenClinica by OpenClinica.

the class SecureController method baseUrl.

protected void baseUrl() throws MalformedURLException {
    String portalURL = CoreResources.getField("portalURL");
    URL pManageUrl = new URL(portalURL);
    ParticipantPortalRegistrar registrar = new ParticipantPortalRegistrar();
    Authorization pManageAuthorization = registrar.getAuthorization(currentStudy.getOid());
    String url = "";
    if (pManageAuthorization != null)
        url = pManageUrl.getProtocol() + "://" + pManageAuthorization.getStudy().getHost() + "." + pManageUrl.getHost() + ((pManageUrl.getPort() > 0) ? ":" + String.valueOf(pManageUrl.getPort()) : "");
    System.out.println("the url :  " + url);
    request.setAttribute("participantUrl", url + "/");
}
Also used : Authorization(org.akaza.openclinica.service.pmanage.Authorization) ParticipantPortalRegistrar(org.akaza.openclinica.service.pmanage.ParticipantPortalRegistrar) URL(java.net.URL)

Aggregations

Authorization (org.akaza.openclinica.service.pmanage.Authorization)7 URL (java.net.URL)5 ParticipantPortalRegistrar (org.akaza.openclinica.service.pmanage.ParticipantPortalRegistrar)5 MalformedURLException (java.net.MalformedURLException)4 HashMap (java.util.HashMap)2 RestTemplate (org.springframework.web.client.RestTemplate)2 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Map (java.util.Map)1 MessagingException (javax.mail.MessagingException)1 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)1 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)1 StudyParameterValueBean (org.akaza.openclinica.bean.service.StudyParameterValueBean)1 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)1 UserAccountDAO (org.akaza.openclinica.dao.login.UserAccountDAO)1 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)1 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)1 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)1