Ejemplo n.º 1
0
  private DiscrepancyNote createQuery(QueryServiceHelperBean helperBean, QueryBean queryBean)
      throws Exception {
    DiscrepancyNote dn = new DiscrepancyNote();
    dn.setStudy(helperBean.getContainer().getStudy());
    dn.setEntityType("itemData");
    dn.setDescription("description");

    dn.setDetailedNotes(queryBean.getComment());
    dn.setDiscrepancyNoteType(new DiscrepancyNoteType(3));

    if (queryBean.getStatus().equals("new")) {
      dn.setResolutionStatus(resolutionStatusDao.findById(1));
    } else if (queryBean.getStatus().equals("updated")) {
      dn.setResolutionStatus(resolutionStatusDao.findById(2));
    } else if (queryBean.getStatus().equals("closed")) {
      dn.setResolutionStatus(resolutionStatusDao.findById(4));
    }

    String assignedTo = queryBean.getAssigned_to();
    if (!StringUtils.isEmpty(assignedTo)) {
      int endIndex = assignedTo.indexOf(")");
      int begIndex = assignedTo.indexOf("(");
      String userName = assignedTo.substring(begIndex + 1, endIndex);
      UserAccount userAccount = userAccountDao.findByUserName(userName);
      helperBean.setUserAccount(userAccount);
      dn.setUserAccount(userAccount);
    }
    dn.setUserAccountByOwnerId(helperBean.getContainer().getUser());
    // create itemData when a query is created without an autosaved itemdata
    if (helperBean.getItemData() == null) {
      helperBean.setItemData(createBlankItemData(helperBean));
    }
    dn.setDateCreated(new Date());
    return dn;
  }
Ejemplo n.º 2
0
  @Override
  public void process(
      QueryServiceHelperBean helperBean,
      SubmissionContainer container,
      Node itemNode,
      int itemOrdinal)
      throws Exception {
    helperBean.setContainer(container);
    helperBean.setItemOrdinal(itemOrdinal);
    helperBean.setItemNode(itemNode);
    helperBean.setItemData(getItemData(helperBean));
    // helperBean.setResStatus(resolutionStatusDao.findByResolutionStatusId(1));
    QueriesBean queries = null;
    try {
      ObjectMapper objectMapper = new ObjectMapper();
      queries = objectMapper.readValue(itemNode.getTextContent(), QueriesBean.class);
    } catch (IOException e) {
      logger.error(e.getMessage());
      throw e;
    }

    List<Integer> idList = new ArrayList();
    List<QueryBean> qBeans = queries.getQueries();
    QueryBean queryBean = null;
    DiscrepancyNote childDN = null;
    DiscrepancyNote parentDN = null;

    if (qBeans.size() == 1) {
      queryBean = qBeans.get(0);
      // this is the first entry , expected to build 2 records in DN table, one parent, the other
      // child
      parentDN = createQuery(helperBean, queryBean);
      parentDN = discrepancyNoteDao.saveOrUpdate(parentDN);

      childDN = createQuery(helperBean, queryBean);
      childDN.setParentDiscrepancyNote(parentDN);
      childDN = discrepancyNoteDao.saveOrUpdate(childDN);

      parentDN.setUserAccount(childDN.getUserAccount());
      parentDN = discrepancyNoteDao.saveOrUpdate(parentDN);
      helperBean.setDn(parentDN);
      saveQueryItemDatamap(helperBean);

    } else if (qBeans.size() > 1) {
      for (QueryBean qBean : qBeans) {
        idList.add(Integer.valueOf(qBean.getId()));
      }
      Collections.reverse(idList);
      queryBean = qBeans.get(0);

      // Enketo passes JSON "id" attribute for unsubmitted queries only
      // if (StringUtils.isEmpty(queryBean.getId())){

      childDN = createQuery(helperBean, queryBean);
      childDN.setParentDiscrepancyNote(findQueryParent(helperBean));
      childDN = discrepancyNoteDao.saveOrUpdate(childDN);

      parentDN = findQueryParent(helperBean);
      parentDN.setUserAccount(childDN.getUserAccount());
      parentDN = discrepancyNoteDao.saveOrUpdate(parentDN);
    }
    helperBean.setDn(childDN);
    saveQueryItemDatamap(helperBean);
    handleEmailNotification(helperBean, queryBean);
  }