Search in sources :

Example 1 with StudyEventTransferBean

use of org.akaza.openclinica.ws.bean.StudyEventTransferBean in project OpenClinica by OpenClinica.

the class StudyEventTransferValidator method validate.

public void validate(Object obj, Errors e) {
    StudyEventTransferBean studyEventTransferBean = (StudyEventTransferBean) obj;
    // Non Business Validation
    if (studyEventTransferBean.getStudyUniqueId() == null || studyEventTransferBean.getStudyUniqueId().length() < 1) {
        e.reject("studyEventTransferValidator.invalid_study_identifier");
        return;
    }
    // Business Validation
    Status[] included_status = new Status[] { Status.AVAILABLE, Status.PENDING };
    StudyBean study = helper.verifyStudy(getStudyDAO(), studyEventTransferBean.getStudyUniqueId(), included_status, e);
    if (study == null) {
        return;
    }
    studyEventTransferBean.setStudy(study);
    StudyBean site = null;
    int site_id = -1;
    if (studyEventTransferBean.getSiteUniqueId() != null) {
        site = helper.verifySite(getStudyDAO(), studyEventTransferBean.getStudyUniqueId(), studyEventTransferBean.getSiteUniqueId(), included_status, e);
        if (site == null) {
            return;
        }
        site_id = site.getId();
        studyEventTransferBean.setStudy(site);
    }
    boolean isRoleVerified = helper.verifyRole(studyEventTransferBean.getUser(), study.getId(), site_id, Role.MONITOR, e);
    if (!isRoleVerified)
        return;
    // Non Business Validation
    if (studyEventTransferBean.getSubjectLabel() == null) {
        e.reject("studyEventTransferValidator.studySubjectId_required");
        return;
    }
    StudySubjectBean studySubject = getStudySubjectDAO().findByLabelAndStudy(studyEventTransferBean.getSubjectLabel(), studyEventTransferBean.getStudy());
    //it is not null but label null
    if (studySubject == null || studySubject.getOid() == null) {
        e.reject("studyEventTransferValidator.study_subject_does_not_exist", new Object[] { studyEventTransferBean.getSubjectLabel(), studyEventTransferBean.getStudy().getName() }, "StudySubject label you specified " + studyEventTransferBean.getSubjectLabel() + " does not correspond to a study " + studyEventTransferBean.getStudy().getName());
        return;
    }
    // Non Business Validation
    if (studyEventTransferBean.getEventDefinitionOID() == null || studyEventTransferBean.getEventDefinitionOID().length() < 1) {
        e.reject("studyEventTransferValidator.eventDefinitionOID_required");
        return;
    }
    if (studyEventTransferBean.getStartDateTime() == null) {
        e.reject("studyEventTransferValidator.startDateTime_required");
        return;
    }
    StudyParameterValueBean eventLocationRequiredSetting = getStudyParameterValueDAO().findByHandleAndStudy(studyEventTransferBean.getStudy().getId(), "eventLocationRequired");
    //        if ("true".equals(eventLocationRequiredSetting.getValue()) && (studyEventTransferBean.getLocation() == null || studyEventTransferBean.getLocation().length() < 1)) {
    if (REQUIRED.equals(eventLocationRequiredSetting.getValue()) && (studyEventTransferBean.getLocation() == null || studyEventTransferBean.getLocation().length() < 1)) {
        e.reject("studyEventTransferValidator.location_required");
        return;
    }
    if (studyEventTransferBean.getEndDateTime() != null && studyEventTransferBean.getStartDateTime() != null) {
        if (studyEventTransferBean.getEndDateTime().compareTo(studyEventTransferBean.getStartDateTime()) == -1) {
            e.reject("studyEventTransferValidator.start_date_after_end_date", new Object[] { studyEventTransferBean.getStartDateTime(), studyEventTransferBean.getEndDateTime() }, "Start date " + studyEventTransferBean.getStartDateTime() + "  after end date (" + studyEventTransferBean.getEndDateTime() + ").");
            return;
        }
    }
    int parentStudyId = study.getParentStudyId();
    StudyEventDefinitionBean studyEventDefinition = getStudyEventDefinitionDAO().findByOidAndStudy(studyEventTransferBean.getEventDefinitionOID(), study.getId(), parentStudyId);
    if (studyEventDefinition == null) {
        e.reject("studyEventTransferValidator.invalid_eventDefinitionOID", new Object[] { studyEventTransferBean.getEventDefinitionOID() }, "EventDefinitionOID you specified " + studyEventTransferBean.getEventDefinitionOID() + " is not valid.");
        return;
    }
}
Also used : Status(org.akaza.openclinica.bean.core.Status) StudyParameterValueBean(org.akaza.openclinica.bean.service.StudyParameterValueBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyEventTransferBean(org.akaza.openclinica.ws.bean.StudyEventTransferBean) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)

Example 2 with StudyEventTransferBean

use of org.akaza.openclinica.ws.bean.StudyEventTransferBean in project OpenClinica by OpenClinica.

the class EventEndpoint method unMarshallToEventTransfer.

/**
     * Process createEvent request by creating StudyEventTransferBean from received payload.
     * 
     * @param subjectElement
     * @return SubjectTransferBean
     * @throws ParseException
     */
private StudyEventTransferBean unMarshallToEventTransfer(Element eventElement) throws ParseException {
    Element eventDefinitionOidElement = DomUtils.getChildElementByTagName(eventElement, "eventDefinitionOID");
    Element locationElement = DomUtils.getChildElementByTagName(eventElement, "location");
    Element startDateElement = DomUtils.getChildElementByTagName(eventElement, "startDate");
    Element endDateElement = DomUtils.getChildElementByTagName(eventElement, "endDate");
    Element startTimeElement = DomUtils.getChildElementByTagName(eventElement, "startTime");
    Element endTimeElement = DomUtils.getChildElementByTagName(eventElement, "endTime");
    Element subjectRefElement = DomUtils.getChildElementByTagName(eventElement, "studySubjectRef");
    Element labelElement = DomUtils.getChildElementByTagName(subjectRefElement, "label");
    Element studyRefElement = DomUtils.getChildElementByTagName(eventElement, "studyRef");
    Element studyIdentifierElement = DomUtils.getChildElementByTagName(studyRefElement, "identifier");
    Element siteRef = DomUtils.getChildElementByTagName(studyRefElement, "siteRef");
    Element siteIdentifierElement = siteRef == null ? null : DomUtils.getChildElementByTagName(siteRef, "identifier");
    String studySubjectId = DomUtils.getTextValue(labelElement).trim();
    String eventDefinitionOID = DomUtils.getTextValue(eventDefinitionOidElement).trim();
    String studyIdentifier = DomUtils.getTextValue(studyIdentifierElement).trim();
    String siteIdentifier = siteIdentifierElement == null ? null : DomUtils.getTextValue(siteIdentifierElement).trim();
    String location = locationElement == null ? null : DomUtils.getTextValue(locationElement).trim();
    String startDate = DomUtils.getTextValue(startDateElement).trim();
    String startTime = startTimeElement == null ? null : DomUtils.getTextValue(startTimeElement).trim();
    String endDate = endDateElement == null ? null : DomUtils.getTextValue(endDateElement).trim();
    String endTime = endTimeElement == null ? null : DomUtils.getTextValue(endTimeElement).trim();
    StudyEventTransferBean studyEventTransferBean = new StudyEventTransferBean(studySubjectId, studyIdentifier, siteIdentifier, eventDefinitionOID, location, getDate(startDate, startTime), getDate(endDate, endTime), getUserAccount());
    return studyEventTransferBean;
}
Also used : Element(org.w3c.dom.Element) StudyEventTransferBean(org.akaza.openclinica.ws.bean.StudyEventTransferBean)

Example 3 with StudyEventTransferBean

use of org.akaza.openclinica.ws.bean.StudyEventTransferBean in project OpenClinica by OpenClinica.

the class EventEndpoint method scheduleEventInTransaction.

protected Source scheduleEventInTransaction(NodeList event) throws Exception {
    ResourceBundleProvider.updateLocale(new Locale("en_US"));
    Element eventElement = (Element) event.item(0);
    StudyEventTransferBean studyEventTransferBean = unMarshallToEventTransfer(eventElement);
    DataBinder dataBinder = new DataBinder((studyEventTransferBean));
    Errors errors = dataBinder.getBindingResult();
    StudyEventTransferValidator studyEventTransferValidator = new StudyEventTransferValidator(dataSource);
    studyEventTransferValidator.validate((studyEventTransferBean), errors);
    if (!errors.hasErrors()) {
        try {
            HashMap<String, String> h = getEventService().scheduleEvent(studyEventTransferBean.getUser(), studyEventTransferBean.getStartDateTime(), studyEventTransferBean.getEndDateTime(), studyEventTransferBean.getLocation(), studyEventTransferBean.getStudyUniqueId(), studyEventTransferBean.getSiteUniqueId(), studyEventTransferBean.getEventDefinitionOID(), studyEventTransferBean.getSubjectLabel());
            return new DOMSource(mapSuccessConfirmation(h));
        } catch (OpenClinicaSystemException ose) {
            errors.reject("eventEndpoint.cannot_schedule", "Cannot schedule an event for this Subject.");
            return new DOMSource(mapFailConfirmation(errors));
        } catch (Exception e) {
            logger.error(e.getMessage());
            logger.error(ExceptionUtils.getStackTrace(e));
            throw e;
        }
    } else {
        return new DOMSource(mapFailConfirmation(errors));
    }
}
Also used : Locale(java.util.Locale) Errors(org.springframework.validation.Errors) DOMSource(javax.xml.transform.dom.DOMSource) Element(org.w3c.dom.Element) StudyEventTransferBean(org.akaza.openclinica.ws.bean.StudyEventTransferBean) DataBinder(org.springframework.validation.DataBinder) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) ParseException(java.text.ParseException) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) StudyEventTransferValidator(org.akaza.openclinica.ws.validator.StudyEventTransferValidator)

Aggregations

StudyEventTransferBean (org.akaza.openclinica.ws.bean.StudyEventTransferBean)3 Element (org.w3c.dom.Element)2 ParseException (java.text.ParseException)1 Locale (java.util.Locale)1 DOMSource (javax.xml.transform.dom.DOMSource)1 Status (org.akaza.openclinica.bean.core.Status)1 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)1 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)1 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)1 StudyParameterValueBean (org.akaza.openclinica.bean.service.StudyParameterValueBean)1 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)1 StudyEventTransferValidator (org.akaza.openclinica.ws.validator.StudyEventTransferValidator)1 DataBinder (org.springframework.validation.DataBinder)1 Errors (org.springframework.validation.Errors)1