Search in sources :

Example 76 with UserAccountBean

use of org.akaza.openclinica.bean.login.UserAccountBean in project OpenClinica by OpenClinica.

the class DiscrepancyNoteDAO method getEntityFromHashMap.

/**
     * <p>
     * getEntityFromHashMap, the method that gets the object from the database query.
     */
@Override
public Object getEntityFromHashMap(HashMap hm) {
    DiscrepancyNoteBean eb = new DiscrepancyNoteBean();
    Date dateCreated = (Date) hm.get("date_created");
    Integer ownerId = (Integer) hm.get("owner_id");
    eb.setCreatedDate(dateCreated);
    eb.setOwnerId(ownerId.intValue());
    // discrepancy_note_id serial NOT NULL,
    // description varchar(255),
    // discrepancy_note_type_id numeric,
    // resolution_status_id numeric,
    // detailed_notes varchar(1000),
    // date_created date,
    // owner_id numeric,
    // parent_dn_id numeric,
    eb.setId(selectInt(hm, "discrepancy_note_id"));
    eb.setDescription((String) hm.get("description"));
    eb.setDiscrepancyNoteTypeId(((Integer) hm.get("discrepancy_note_type_id")).intValue());
    eb.setResolutionStatusId(((Integer) hm.get("resolution_status_id")).intValue());
    eb.setParentDnId(((Integer) hm.get("parent_dn_id")).intValue());
    eb.setDetailedNotes((String) hm.get("detailed_notes"));
    eb.setEntityType((String) hm.get("entity_type"));
    eb.setDisType(DiscrepancyNoteType.get(eb.getDiscrepancyNoteTypeId()));
    eb.setResStatus(ResolutionStatus.get(eb.getResolutionStatusId()));
    eb.setStudyId(selectInt(hm, "study_id"));
    eb.setAssignedUserId(selectInt(hm, "assigned_user_id"));
    if (eb.getAssignedUserId() > 0) {
        UserAccountDAO userAccountDAO = new UserAccountDAO(ds);
        UserAccountBean assignedUser = (UserAccountBean) userAccountDAO.findByPK(eb.getAssignedUserId());
        eb.setAssignedUser(assignedUser);
    }
    eb.setAge(selectInt(hm, "age"));
    eb.setDays(selectInt(hm, "days"));
    return eb;
}
Also used : DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) Date(java.util.Date)

Example 77 with UserAccountBean

use of org.akaza.openclinica.bean.login.UserAccountBean 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.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.json.JSONException)

Example 78 with UserAccountBean

use of org.akaza.openclinica.bean.login.UserAccountBean in project OpenClinica by OpenClinica.

the class UserAccountDAO method findByApiKey.

public EntityBean findByApiKey(String name) {
    this.setTypesExpected();
    HashMap variables = new HashMap();
    variables.put(new Integer(1), name);
    ArrayList alist = this.select(digester.getQuery("findByApiKey"), variables);
    UserAccountBean eb = new UserAccountBean();
    Iterator it = alist.iterator();
    if (it.hasNext()) {
        eb = (UserAccountBean) this.getEntityFromHashMap((HashMap) it.next(), true);
    }
    return eb;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) Iterator(java.util.Iterator)

Example 79 with UserAccountBean

use of org.akaza.openclinica.bean.login.UserAccountBean in project OpenClinica by OpenClinica.

the class UserAccountDAO method findStudyUserRole.

public UserAccountBean findStudyUserRole(UserAccountBean user, StudyUserRoleBean studyRole) {
    this.setTypesExpected();
    this.setTypeExpected(1, TypeNames.STRING);
    this.setTypeExpected(2, TypeNames.INT);
    this.setTypeExpected(3, TypeNames.INT);
    this.setTypeExpected(4, TypeNames.INT);
    this.setTypeExpected(5, TypeNames.DATE);
    this.setTypeExpected(6, TypeNames.DATE);
    this.setTypeExpected(7, TypeNames.INT);
    this.setTypeExpected(8, TypeNames.STRING);
    HashMap variables = new HashMap();
    variables.put(new Integer(1), studyRole.getRoleName());
    variables.put(new Integer(2), new Integer(studyRole.getStudyId()));
    variables.put(new Integer(3), new Integer(studyRole.getStatus().getId()));
    variables.put(new Integer(4), user.getName());
    ArrayList alist = this.select(digester.getQuery("findStudyUserRole"), variables);
    UserAccountBean eb = new UserAccountBean();
    Iterator it = alist.iterator();
    if (it.hasNext()) {
        eb.setName((String) ((HashMap) it.next()).get("user_name"));
    }
    return eb;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) Iterator(java.util.Iterator)

Example 80 with UserAccountBean

use of org.akaza.openclinica.bean.login.UserAccountBean in project OpenClinica by OpenClinica.

the class UserAccountDAO method update.

@Override
public EntityBean update(EntityBean eb) {
    UserAccountBean uab = (UserAccountBean) eb;
    HashMap variables = new HashMap();
    HashMap nullVars = new HashMap();
    /*
         * update user_account set date_lastvisit=?, passwd_timestamp=?, passwd_challenge_question=?,
         * passwd_challenge_answer=?, phone=? where user_name=?
         */
    variables.put(new Integer(1), uab.getName());
    variables.put(new Integer(2), uab.getPasswd());
    variables.put(new Integer(3), uab.getFirstName());
    variables.put(new Integer(4), uab.getLastName());
    variables.put(new Integer(5), uab.getEmail());
    if (uab.getActiveStudyId() == 0) {
        nullVars.put(new Integer(6), new Integer(TypeNames.INT));
        variables.put(new Integer(6), null);
    } else {
        variables.put(new Integer(6), new Integer(uab.getActiveStudyId()));
    }
    variables.put(new Integer(7), uab.getInstitutionalAffiliation());
    variables.put(new Integer(8), new Integer(uab.getStatus().getId()));
    variables.put(new Integer(9), new Integer(uab.getUpdaterId()));
    if (uab.getLastVisitDate() == null) {
        nullVars.put(new Integer(10), new Integer(TypeNames.TIMESTAMP));
        variables.put(new Integer(10), null);
    } else {
        variables.put(new Integer(10), new Timestamp(uab.getLastVisitDate().getTime()));
    }
    if (uab.getPasswdTimestamp() == null) {
        nullVars.put(new Integer(11), new Integer(TypeNames.DATE));
        variables.put(new Integer(11), null);
    } else {
        variables.put(new Integer(11), uab.getPasswdTimestamp());
    }
    variables.put(new Integer(12), uab.getPasswdChallengeQuestion());
    variables.put(new Integer(13), uab.getPasswdChallengeAnswer());
    variables.put(new Integer(14), uab.getPhone());
    if (uab.isTechAdmin()) {
        variables.put(new Integer(15), new Integer(UserType.TECHADMIN.getId()));
    } else if (uab.isSysAdmin()) {
        variables.put(new Integer(15), new Integer(UserType.SYSADMIN.getId()));
    } else {
        variables.put(new Integer(15), new Integer(UserType.USER.getId()));
    }
    variables.put(new Integer(16), uab.getAccountNonLocked());
    variables.put(new Integer(17), uab.getLockCounter());
    variables.put(new Integer(18), uab.getRunWebservices());
    if (uab.getAccessCode() == null || uab.getAccessCode().equals("") || uab.getAccessCode().equals("null")) {
        nullVars.put(new Integer(19), new Integer(TypeNames.STRING));
        variables.put(new Integer(19), null);
    } else {
        variables.put(new Integer(19), uab.getAccessCode());
    }
    if (uab.getTime_zone() == null || uab.getTime_zone().equals("")) {
        nullVars.put(new Integer(20), new Integer(TypeNames.STRING));
        variables.put(new Integer(20), null);
    } else {
        variables.put(new Integer(20), uab.getTime_zone());
    }
    variables.put(new Integer(21), uab.isEnableApiKey());
    if (uab.getApiKey() == null || uab.getApiKey().equals("")) {
        nullVars.put(new Integer(22), new Integer(TypeNames.STRING));
        variables.put(new Integer(22), null);
    } else {
        variables.put(new Integer(22), uab.getApiKey());
    }
    variables.put(new Integer(23), new Integer(uab.getId()));
    String sql = digester.getQuery("update");
    this.execute(sql, variables, nullVars);
    if (!uab.isTechAdmin()) {
        setSysAdminRole(uab, false);
    }
    if (!this.isQuerySuccessful()) {
        eb.setId(0);
        logger.warn("query failed: " + sql);
    } else {
    // for bug testing, tbh
    // logger.warn("query succeeded: "+sql+" variables:
    // "+variables.toString());
    }
    return eb;
}
Also used : HashMap(java.util.HashMap) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) Timestamp(java.sql.Timestamp)

Aggregations

UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)152 UserAccountDAO (org.akaza.openclinica.dao.login.UserAccountDAO)64 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)56 ArrayList (java.util.ArrayList)52 HashMap (java.util.HashMap)38 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)36 StudyUserRoleBean (org.akaza.openclinica.bean.login.StudyUserRoleBean)35 Date (java.util.Date)32 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)32 Locale (java.util.Locale)30 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)18 Iterator (java.util.Iterator)16 InsufficientPermissionException (org.akaza.openclinica.web.InsufficientPermissionException)16 ResponseEntity (org.springframework.http.ResponseEntity)16 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)15 Validator (org.akaza.openclinica.control.form.Validator)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 Role (org.akaza.openclinica.bean.core.Role)11 DiscrepancyNoteBean (org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean)10 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)10