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;
}
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;
}
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 "";
}
}
Aggregations