Search in sources :

Example 91 with Transactional

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());
    }
}
Also used : ApplicationForm(cz.metacentrum.perun.registrar.model.ApplicationForm) MailText(cz.metacentrum.perun.registrar.model.ApplicationMail.MailText) Transactional(org.springframework.transaction.annotation.Transactional)

Example 92 with Transactional

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;
}
Also used : ShowActionBean(org.akaza.openclinica.domain.rule.action.ShowActionBean) RuleActionBean(org.akaza.openclinica.domain.rule.action.RuleActionBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) ArrayList(java.util.ArrayList) ActionProcessor(org.akaza.openclinica.domain.rule.action.ActionProcessor) HashMap(java.util.HashMap) Map(java.util.Map) Transactional(org.springframework.transaction.annotation.Transactional)

Example 93 with Transactional

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);
                    }
                }
            }
        }
    }
}
Also used : ImportItemGroupDataBean(org.akaza.openclinica.bean.submit.crfdata.ImportItemGroupDataBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) HashMap(java.util.HashMap) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) ImportItemDataBean(org.akaza.openclinica.bean.submit.crfdata.ImportItemDataBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) StudyEventDataBean(org.akaza.openclinica.bean.submit.crfdata.StudyEventDataBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) FormDataBean(org.akaza.openclinica.bean.submit.crfdata.FormDataBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) Transactional(org.springframework.transaction.annotation.Transactional)

Example 94 with Transactional

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;
}
Also used : FormLayout(org.akaza.openclinica.domain.datamap.FormLayout) CrfBean(org.akaza.openclinica.domain.datamap.CrfBean) CrfVersion(org.akaza.openclinica.domain.datamap.CrfVersion) Section(org.akaza.openclinica.domain.datamap.Section) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 95 with Transactional

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());
    }
}
Also used : HashMap(java.util.HashMap) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) RuleBean(org.akaza.openclinica.domain.rule.RuleBean) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Transactional (org.springframework.transaction.annotation.Transactional)1415 Test (org.junit.Test)507 Query (javax.persistence.Query)166 Date (java.util.Date)121 ArrayList (java.util.ArrayList)99 ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)89 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)87 ServiceMethodAuthority (com.netsteadfast.greenstep.base.model.ServiceMethodAuthority)84 OnmsNode (org.opennms.netmgt.model.OnmsNode)83 TypedQuery (javax.persistence.TypedQuery)81 Rollback (org.springframework.test.annotation.Rollback)81 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)67 HashMap (java.util.HashMap)65 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)61 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)58 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)58 DBUnitTest (org.orcid.test.DBUnitTest)57 List (java.util.List)56 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)41 User (com.arnaugarcia.uplace.domain.User)39