use of org.springframework.transaction.annotation.Transactional in project perun by CESNET.
the class MailManagerImpl method updateMailById.
@Override
@Transactional(rollbackFor = Exception.class)
public void updateMailById(PerunSession sess, ApplicationMail mail) throws PerunException {
ApplicationForm form = registrarManager.getFormById(sess, mail.getFormId());
// update sending (enabled / disabled)
jdbc.update("update application_mails set send=? where id=?", mail.getSend() ? "1" : "0", mail.getId());
// update texts (easy way = delete and new insert)
jdbc.update("delete from application_mail_texts where mail_id=?", mail.getId());
for (Locale loc : mail.getMessage().keySet()) {
MailText text = mail.getMessage(loc);
jdbc.update("insert into application_mail_texts(mail_id,locale,subject,text) values (?,?,?,?)", mail.getId(), loc.toString(), text.getSubject(), text.getText());
}
if (form.getGroup() != null) {
perun.getAuditer().log(sess, "Mail ID: {} of Type: {} updated for Group ID: {}.", mail.getId(), mail.getMailType() + "/" + mail.getAppType(), form.getGroup().getId());
} else {
perun.getAuditer().log(sess, "Mail ID: {} of Type: {} updated for VO ID: {}.", mail.getId(), mail.getMailType() + "/" + mail.getAppType(), form.getVo().getId());
}
}
use of org.springframework.transaction.annotation.Transactional in project OpenClinica by OpenClinica.
the class ImportDataRuleRunner method runRules.
@Transactional
private MessageContainer runRules(StudyBean currentStudy, UserAccountBean ub, HashMap<String, String> variableAndValue, HashMap<String, ArrayList<RuleActionContainer>> toBeExecuted) {
//Copied from DataEntryRuleRunner runRules
MessageContainer messageContainer = new MessageContainer();
for (Map.Entry<String, ArrayList<RuleActionContainer>> entry : toBeExecuted.entrySet()) {
// Sort the list of actions
Collections.sort(entry.getValue(), new RuleActionContainerComparator());
for (RuleActionContainer ruleActionContainer : entry.getValue()) {
logger.info("START Expression is : {} , RuleAction : {} ", new Object[] { ruleActionContainer.getExpressionBean().getValue(), ruleActionContainer.getRuleAction().toString() });
ruleActionContainer.getRuleSetBean().setTarget(ruleActionContainer.getExpressionBean());
ruleActionContainer.getRuleAction().setCuratedMessage(curateMessage(ruleActionContainer.getRuleAction(), ruleActionContainer.getRuleAction().getRuleSetRule()));
ActionProcessor ap = ActionProcessorFacade.getActionProcessor(ruleActionContainer.getRuleAction().getActionType(), ds, getMailSender(), dynamicsMetadataService, ruleActionContainer.getRuleSetBean(), getRuleActionRunLogDao(), ruleActionContainer.getRuleAction().getRuleSetRule());
ItemDataBean itemData = getExpressionService().getItemDataBeanFromDb(ruleActionContainer.getRuleSetBean().getTarget().getValue());
RuleActionBean rab = ap.execute(RuleRunnerMode.IMPORT_DATA, ExecutionMode.SAVE, ruleActionContainer.getRuleAction(), itemData, DiscrepancyNoteBean.ITEM_DATA, currentStudy, ub, prepareEmailContents(ruleActionContainer.getRuleSetBean(), ruleActionContainer.getRuleAction().getRuleSetRule(), currentStudy, ruleActionContainer.getRuleAction()));
if (rab != null) {
if (rab instanceof ShowActionBean) {
messageContainer.add(getExpressionService().getGroupOidOrdinal(ruleActionContainer.getRuleSetBean().getTarget().getValue()), rab);
} else {
messageContainer.add(getExpressionService().getGroupOrdninalConcatWithItemOid(ruleActionContainer.getRuleSetBean().getTarget().getValue()), ruleActionContainer.getRuleAction());
}
}
logger.info("END Expression is : {} , RuleAction : {} ", new Object[] { ruleActionContainer.getExpressionBean().getValue(), ruleActionContainer.getRuleAction().toString() });
}
}
return messageContainer;
}
use of org.springframework.transaction.annotation.Transactional in project OpenClinica by OpenClinica.
the class ImportDataRuleRunnerContainer method initRuleSetsAndTargets.
/**
* Populate importDataTrueRuleSets and variableAndValue.
* Precondition: import data file passed validation which means all OIDs are not empty.
* @param ds
* @param studyBean
* @param subjectDataBean
* @param ruleSetService
*/
@Transactional
public void initRuleSetsAndTargets(DataSource ds, StudyBean studyBean, SubjectDataBean subjectDataBean, RuleSetServiceInterface ruleSetService) {
this.shouldRunRules = this.shouldRunRules == null ? Boolean.FALSE : this.shouldRunRules;
this.importDataTrueRuleSets = this.importDataTrueRuleSets == null ? new ArrayList<RuleSetBean>() : this.importDataTrueRuleSets;
this.variableAndValue = this.variableAndValue == null ? new HashMap<String, String>() : this.variableAndValue;
studyOid = studyBean.getOid();
studySubjectOid = subjectDataBean.getSubjectOID();
StudySubjectBean studySubject = new StudySubjectDAO<String, ArrayList>(ds).findByOid(studySubjectOid);
HashMap<String, StudyEventDefinitionBean> seds = new HashMap<String, StudyEventDefinitionBean>();
HashMap<String, CRFVersionBean> cvs = new HashMap<String, CRFVersionBean>();
ArrayList<StudyEventDataBean> studyEventDataBeans = subjectDataBean.getStudyEventData();
for (StudyEventDataBean studyEventDataBean : studyEventDataBeans) {
String sedOid = studyEventDataBean.getStudyEventOID();
StudyEventDefinitionBean sed;
if (seds.containsKey(sedOid))
sed = seds.get(sedOid);
else {
sed = new StudyEventDefinitionDAO<String, ArrayList>(ds).findByOid(sedOid);
seds.put(sedOid, sed);
}
ArrayList<FormDataBean> formDataBeans = studyEventDataBean.getFormData();
for (FormDataBean formDataBean : formDataBeans) {
String cvOid = formDataBean.getFormOID();
CRFVersionBean crfVersion;
if (cvs.containsKey(cvOid))
crfVersion = cvs.get(cvOid);
else {
crfVersion = new CRFVersionDAO<String, ArrayList>(ds).findByOid(cvOid);
cvs.put(cvOid, crfVersion);
}
String sedOrd = studyEventDataBean.getStudyEventRepeatKey();
Integer sedOrdinal = sedOrd != null && !sedOrd.isEmpty() ? Integer.valueOf(sedOrd) : 1;
StudyEventBean studyEvent = (StudyEventBean) new StudyEventDAO(ds).findByStudySubjectIdAndDefinitionIdAndOrdinal(studySubject.getId(), sed.getId(), sedOrdinal);
List<RuleSetBean> ruleSets = ruleSetService.getRuleSetsByCrfStudyAndStudyEventDefinition(studyBean, sed, crfVersion);
//Set<String> targetItemOids = new HashSet<String>();
if (ruleSets != null && !ruleSets.isEmpty()) {
ruleSets = filterByImportDataEntryTrue(ruleSets);
if (ruleSets != null && !ruleSets.isEmpty()) {
ruleSets = ruleSetService.filterByStatusEqualsAvailable(ruleSets);
ruleSets = ruleSetService.filterRuleSetsByStudyEventOrdinal(ruleSets, studyEvent, crfVersion, sed);
//ruleSets = ruleSetService.filterRuleSetsByHiddenItems(ruleSets, eventCrfBean, crfVersion, new ArrayList<ItemBean>());
shouldRunRules = ruleSetService.shouldRunRulesForRuleSets(ruleSets, Phase.IMPORT);
if (shouldRunRules != null && shouldRunRules == Boolean.TRUE) {
//targetItemOids = collectTargetItemOids(ruleSets);
HashMap<String, Integer> grouped = new HashMap<String, Integer>();
ArrayList<ImportItemGroupDataBean> itemGroupDataBeans = formDataBean.getItemGroupData();
for (ImportItemGroupDataBean itemGroupDataBean : itemGroupDataBeans) {
ArrayList<ImportItemDataBean> itemDataBeans = itemGroupDataBean.getItemData();
for (ImportItemDataBean importItemDataBean : itemDataBeans) {
//if(targetItemOids.contains(importItemDataBean.getItemOID())) {
ItemBean item = new ItemDAO<String, ArrayList>(ds).findByOid(importItemDataBean.getItemOID()).get(0);
String igOid = itemGroupDataBean.getItemGroupOID();
String igOrd = itemGroupDataBean.getItemGroupRepeatKey();
Integer igOrdinal = igOrd != null && !igOrd.isEmpty() ? Integer.valueOf(igOrd) : 1;
//logic from DataEntryServlet method: populateRuleSpecificHashMaps()
if (isRepeatIGForSure(ds, crfVersion.getId(), igOid, igOrdinal, item.getId())) {
String key1 = igOid + "[" + igOrdinal + "]." + importItemDataBean.getItemOID();
String key = igOid + "." + importItemDataBean.getItemOID();
variableAndValue.put(key1, importItemDataBean.getValue());
if (grouped.containsKey(key)) {
grouped.put(key, grouped.get(key) + 1);
} else {
grouped.put(key, 1);
}
} else {
variableAndValue.put(importItemDataBean.getItemOID(), importItemDataBean.getValue());
grouped.put(importItemDataBean.getItemOID(), 1);
}
//
//}
}
}
ruleSets = ruleSetService.solidifyGroupOrdinalsUsingFormProperties(ruleSets, grouped);
importDataTrueRuleSets.addAll(ruleSets);
}
}
}
}
}
}
use of org.springframework.transaction.annotation.Transactional in project OpenClinica by OpenClinica.
the class XformMetaDataService method createCRFMetaData.
@Transactional
public FormLayout createCRFMetaData(CrfMetaDataObject cmdObject) throws Exception {
CrfVersion crfVersion = null;
FormLayout formLayout = null;
CrfBean crfBean = null;
Section section = null;
crfBean = (CrfBean) crfDao.findByOcOID(cmdObject.crf.getOcoid());
if (crfBean != null) {
crfBean.setUpdateId(cmdObject.ub.getId());
crfBean.setDateUpdated(new Date());
crfBean = crfDao.saveOrUpdate(crfBean);
formLayout = formLayoutDao.findByOcOID(cmdObject.version.getOcoid());
if (formLayout == null) {
formLayout = new FormLayout();
formLayout = populateFormLayout(formLayout, crfBean, cmdObject);
formLayout = formLayoutDao.saveOrUpdate(formLayout);
}
crfVersion = crfVersionDao.findAllByCrfId(crfBean.getCrfId()).get(0);
section = sectionDao.findByCrfVersionOrdinal(crfVersion.getCrfVersionId(), 1);
} else {
crfBean = new CrfBean();
crfBean = populateCrf(crfBean, cmdObject);
Integer crfId = (Integer) crfDao.save(crfBean);
crfBean.setCrfId(crfId);
// Create new Form Layout
formLayout = new FormLayout();
formLayout = populateFormLayout(formLayout, crfBean, cmdObject);
formLayout = formLayoutDao.saveOrUpdate(formLayout);
// Create new CRF Version
crfVersion = new CrfVersion();
crfVersion = populateCrfVersion(crfBean, crfVersion, cmdObject);
crfVersion = crfVersionDao.saveOrUpdate(crfVersion);
// Create Section
section = sectionDao.findByCrfVersionOrdinal(crfVersion.getCrfVersionId(), 1);
if (section == null) {
section = new Section();
section = populateCrfVersion(section, crfVersion, cmdObject);
sectionDao.saveOrUpdate(section);
section = sectionDao.findByCrfVersionOrdinal(crfVersion.getCrfVersionId(), 1);
}
}
createGroups(cmdObject.container, crfBean, crfVersion, formLayout, section, cmdObject.ub, cmdObject.errors);
if (cmdObject.errors.hasErrors()) {
logger.error("Encounter validation errors while saving CRF. Rolling back transaction.");
throw new RuntimeException("Encountered validation errors while saving CRF.");
}
return formLayout;
}
use of org.springframework.transaction.annotation.Transactional in project OpenClinica by OpenClinica.
the class RuleSetService method saveImportFromDesigner.
@Transactional
public void saveImportFromDesigner(RulesPostImportContainer rulesContainer) {
HashMap<String, RuleBean> ruleBeans = new HashMap<String, RuleBean>();
for (AuditableBeanWrapper<RuleBean> ruleBeanWrapper : rulesContainer.getValidRuleDefs()) {
RuleBean r = getRuleDao().saveOrUpdate(ruleBeanWrapper.getAuditableBean());
ruleBeans.put(r.getOid(), r);
}
for (AuditableBeanWrapper<RuleBean> ruleBeanWrapper : rulesContainer.getDuplicateRuleDefs()) {
RuleBean r = getRuleDao().saveOrUpdate(ruleBeanWrapper.getAuditableBean());
ruleBeans.put(r.getOid(), r);
}
for (AuditableBeanWrapper<RuleSetBean> ruleBeanWrapper : rulesContainer.getValidRuleSetDefs()) {
loadRuleSetRuleWithPersistentRules(ruleBeanWrapper.getAuditableBean());
saveRuleSet(ruleBeanWrapper.getAuditableBean());
}
for (AuditableBeanWrapper<RuleSetBean> ruleBeanWrapper : rulesContainer.getDuplicateRuleSetDefs()) {
loadRuleSetRuleWithPersistentRulesWithHashMap(ruleBeanWrapper.getAuditableBean(), ruleBeans);
replaceRuleSet(ruleBeanWrapper.getAuditableBean());
}
}
Aggregations