Search in sources :

Example 1 with JSONException

use of org.springframework.security.oauth2.common.json.JSONException in project OpenClinica by OpenClinica.

the class DynamicsMetadataService method getValue.

private String getValue(PropertyBean property, RuleSetBean ruleSet, EventCRFBean eventCrfBean, List<StratificationFactorBean> stratificationFactorBeans) {
    String value = null;
    if (property.getValue() != null && property.getValue().length() > 0) {
        logger.info("Value from property value is : {}", value);
        value = property.getValue();
    }
    if (property.getValueExpression() == null) {
        logger.info("There is no ValueExpression for property =" + property.getOid());
        if (stratificationFactorBeans != null)
            try {
                value = getRandomizeService().getRandomizationCode(eventCrfBean, stratificationFactorBeans, ruleSet);
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    } else {
        String expression = getExpressionService().constructFullExpressionIfPartialProvided(property.getValueExpression().getValue(), ruleSet.getTarget().getValue());
        if (expression != null && !expression.isEmpty()) {
            ItemBean itemBean = getExpressionService().getItemBeanFromExpression(expression);
            String itemGroupBOrdinal = getExpressionService().getGroupOrdninalCurated(expression);
            ItemDataBean itemData = getItemDataDAO().findByItemIdAndEventCRFIdAndOrdinal(itemBean.getId(), eventCrfBean.getId(), itemGroupBOrdinal == "" ? 1 : Integer.valueOf(itemGroupBOrdinal));
            if (itemData.getId() == 0) {
                logger.info("Cannot get Value for ExpressionValue {}", expression);
            } else {
                value = itemData.getValue();
                logger.info("Value from ExpressionValue '{}'  is : {}", expression, value);
            }
        }
    }
    return value;
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) JSONException(org.springframework.security.oauth2.common.json.JSONException)

Example 2 with JSONException

use of org.springframework.security.oauth2.common.json.JSONException in project OpenClinica by OpenClinica.

the class RandomizeService method retrieveARandomisation.

private JSONObject retrieveARandomisation(String randomiseUrl, StudySubjectBean studySubject, HttpHeaders headers) throws JSONException {
    // method : GET
    // concatenate
    randomiseUrl = randomiseUrl + "/api/randomisation?identifier=" + studySubject.getOid();
    // Study_Siubject_oid
    RestTemplate rest = new RestTemplate(requestFactory);
    ResponseEntity<String> response = null;
    String body = null;
    JSONObject jsonObject = null;
    HttpEntity<String> request = new HttpEntity<String>(headers);
    try {
        response = rest.exchange(randomiseUrl, HttpMethod.GET, request, String.class);
        body = response.getBody();
        jsonObject = new JSONObject(body);
    // if (!jsonObject.get("error").equals("0"))
    // jsonObject= null;
    } catch (Exception e) {
        System.out.println(e.getMessage());
        logger.error(e.getMessage());
        logger.error(ExceptionUtils.getStackTrace(e));
    }
    return jsonObject;
}
Also used : JSONObject(org.springframework.security.oauth2.common.json.JSONObject) HttpEntity(org.springframework.http.HttpEntity) RestTemplate(org.springframework.web.client.RestTemplate) JSONException(org.springframework.security.oauth2.common.json.JSONException)

Example 3 with JSONException

use of org.springframework.security.oauth2.common.json.JSONException in project OpenClinica by OpenClinica.

the class RandomizeService method getRandomizationCode.

// Rest Call to OCUI to get Randomization
public String getRandomizationCode(EventCRFBean eventCrfBean, List<StratificationFactorBean> stratificationFactorBeans, RuleSetBean ruleSet) throws JSONException {
    StudySubjectDAO ssdao = new StudySubjectDAO<>(ds);
    StudySubjectBean ssBean = (StudySubjectBean) ssdao.findByPK(eventCrfBean.getStudySubjectId());
    // study subject oid
    String identifier = ssBean.getOid();
    StudyDAO sdao = new StudyDAO<>(ds);
    StudyBean sBean = (StudyBean) sdao.findByPK(ssBean.getStudyId());
    // site or study oid
    String siteIdentifier = sBean.getOid();
    // site or study name
    String name = sBean.getName();
    UserAccountDAO udao = new UserAccountDAO(ds);
    int userId = 0;
    if (eventCrfBean.getUpdaterId() == 0) {
        userId = eventCrfBean.getOwnerId();
    } else {
        userId = eventCrfBean.getUpdaterId();
    }
    UserAccountBean uBean = (UserAccountBean) udao.findByPK(userId);
    String user = uBean.getName();
    // sBean should be parent study
    // put randomization object in cache
    StudyBean study = getParentStudy(sBean.getOid());
    SeRandomizationDTO randomization = null;
    try {
        randomization = getCachedRandomizationDTOObject(study.getOid(), false);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    String randomiseUrl = randomization.getUrl();
    String username = randomization.getUsername();
    String password = randomization.getPassword();
    String timezone = "America/New_York";
    // String randomiseUrl = "https://evaluation.sealedenvelope.com/redpill/seti2";
    // String username = "oc";
    // String password = "secret";
    HttpHeaders headers = createHeaders(username, password);
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    // retrieve json object if Randomization exist ,otherwise return a null object
    JSONObject jsonRandObject = retrieveARandomisation(randomiseUrl, ssBean, headers);
    if (jsonRandObject != null) {
        return (String) jsonRandObject.get("code");
    } else {
        // if Site identifier exists ,then update otherwise create new Site identifier
        addOrUpdateASite(randomiseUrl, sBean, headers, timezone);
        // send for Randomization
        JSONObject jsonRandomisedObject = randomiseSubject(randomiseUrl, ssBean, sBean, headers, user, stratificationFactorBeans, eventCrfBean, ruleSet);
        if (jsonRandomisedObject != null)
            return (String) jsonRandomisedObject.get("code");
        else
            return "";
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) JSONObject(org.springframework.security.oauth2.common.json.JSONObject) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) SeRandomizationDTO(org.akaza.openclinica.service.pmanage.SeRandomizationDTO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) JSONException(org.springframework.security.oauth2.common.json.JSONException)

Aggregations

JSONException (org.springframework.security.oauth2.common.json.JSONException)3 JSONObject (org.springframework.security.oauth2.common.json.JSONObject)2 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)1 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)1 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)1 DisplayItemBean (org.akaza.openclinica.bean.submit.DisplayItemBean)1 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)1 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)1 UserAccountDAO (org.akaza.openclinica.dao.login.UserAccountDAO)1 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)1 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)1 SeRandomizationDTO (org.akaza.openclinica.service.pmanage.SeRandomizationDTO)1 HttpEntity (org.springframework.http.HttpEntity)1 HttpHeaders (org.springframework.http.HttpHeaders)1 RestTemplate (org.springframework.web.client.RestTemplate)1