public List<PointOfContactBean> findPointOfContactsBySampleId(String sampleId)
     throws PointOfContactException {
   try {
     CaNanoLabApplicationService appService =
         (CaNanoLabApplicationService) ApplicationServiceProvider.getApplicationService();
     DetachedCriteria crit =
         DetachedCriteria.forClass(Sample.class)
             .add(Property.forName("id").eq(new Long(sampleId)));
     crit.setFetchMode("primaryPointOfContact", FetchMode.JOIN);
     crit.setFetchMode("primaryPointOfContact.organization", FetchMode.JOIN);
     crit.setFetchMode("otherPointOfContactCollection", FetchMode.JOIN);
     crit.setFetchMode("otherPointOfContactCollection.organization", FetchMode.JOIN);
     crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
     List results = appService.query(crit);
     List<PointOfContactBean> pointOfContactCollection = new ArrayList<PointOfContactBean>();
     for (int i = 0; i < results.size(); i++) {
       Sample particle = (Sample) results.get(i);
       PointOfContact primaryPOC = particle.getPrimaryPointOfContact();
       Collection<PointOfContact> otherPOCs = particle.getOtherPointOfContactCollection();
       pointOfContactCollection.add(new PointOfContactBean(primaryPOC));
       for (PointOfContact poc : otherPOCs) {
         pointOfContactCollection.add(new PointOfContactBean(poc));
       }
     }
     return pointOfContactCollection;
   } catch (Exception e) {
     String err = "Problem finding all PointOfContact collections with the given sample ID.";
     logger.error(err, e);
     throw new PointOfContactException(err, e);
   }
 }
Пример #2
0
  @SuppressWarnings("unchecked")
  public List<Team> getTeam(int userId, TeamType type) {
    boolean isAdmin = false;
    HibernateTemplate template = getHibernateTemplate();
    Object obj = template.get(Employee.class, userId);
    List<Team> list = new ArrayList<Team>();
    if (null == obj) return list;
    else {
      Employee employee = (Employee) obj;
      isAdmin = employee.getIsAdmin();
      if (isAdmin) {
        DetachedCriteria criteria = DetachedCriteria.forClass(Team.class);

        if (type == TeamType.Product) criteria.add(Restrictions.eq("isProduct", true));
        else if (type == TeamType.Sales) criteria.add(Restrictions.eq("isSales", true));
        else if (type == TeamType.Operator) criteria.add(Restrictions.eq("isOperator", true));

        criteria.setResultTransformer(CriteriaSpecification.ROOT_ENTITY);

        list = getHibernateTemplate().findByCriteria(criteria);
      } else {
        Set<Team> team = employee.getTeamMemberships();
        for (Team team2 : team) {
          if (type == TeamType.Operator && team2.getIsOperator()) list.add(team2);
          else if (type == TeamType.Sales && team2.getIsSales()) list.add(team2);
          else if (type == TeamType.Product && team2.getIsProduct()) list.add(team2);
        }
      }

      return list;
    }
  }
  private List<Characterization> loadCharacterizations(String sampleId) throws Exception {
    List<Characterization> chars = new ArrayList<Characterization>();

    CaNanoLabApplicationService appService =
        (CaNanoLabApplicationService) ApplicationServiceProvider.getApplicationService();
    DetachedCriteria crit = DetachedCriteria.forClass(Characterization.class);
    crit.createAlias("sample", "sample");
    crit.add(Property.forName("sample.id").eq(new Long(sampleId)));
    // fully load characterization
    crit.setFetchMode("pointOfContact", FetchMode.JOIN);
    crit.setFetchMode("pointOfContact.organization", FetchMode.JOIN);
    crit.setFetchMode("protocol", FetchMode.JOIN);
    crit.setFetchMode("protocol.file", FetchMode.JOIN);
    crit.setFetchMode("protocol.file.keywordCollection", FetchMode.JOIN);
    crit.setFetchMode("experimentConfigCollection", FetchMode.JOIN);
    crit.setFetchMode("experimentConfigCollection.technique", FetchMode.JOIN);
    crit.setFetchMode("experimentConfigCollection.instrumentCollection", FetchMode.JOIN);
    crit.setFetchMode("findingCollection", FetchMode.JOIN);
    crit.setFetchMode("findingCollection.datumCollection", FetchMode.JOIN);
    crit.setFetchMode("findingCollection.datumCollection.conditionCollection", FetchMode.JOIN);
    crit.setFetchMode("findingCollection.fileCollection", FetchMode.JOIN);
    crit.setFetchMode("findingCollection.fileCollection.keywordCollection", FetchMode.JOIN);
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    List results = appService.query(crit);

    for (int i = 0; i < results.size(); i++) {
      Characterization achar = (Characterization) results.get(i);
      chars.add(achar);
    }
    return chars;
  }
Пример #4
0
  private List<HashMap<String, Object>> getQuestionAnswerData(ExamResult examResult) {
    DetachedCriteria criteria =
        DetachedCriteria.forClass(ExamResultAnswer.class, "examResultAnswer");
    criteria.createAlias("examResultAnswer.question", "question");
    criteria.createAlias("examResultAnswer.answer1", "answer1");
    criteria.createAlias("examResultAnswer.answer2", "answer2");
    criteria.createAlias("examResultAnswer.answer3", "answer3");
    criteria.createAlias("examResultAnswer.answer4", "answer4");

    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("question.questionId"), "questionId");
    projectionList.add(Projections.property("question.questionText"), "questionText");
    projectionList.add(Projections.property("answer1.answerId"), "answer1Id");
    projectionList.add(Projections.property("answer1.answerText"), "answer1Text");
    projectionList.add(Projections.property("answer2.answerId"), "answer2Id");
    projectionList.add(Projections.property("answer2.answerText"), "answer2Text");
    projectionList.add(Projections.property("answer3.answerId"), "answer3Id");
    projectionList.add(Projections.property("answer3.answerText"), "answer3Text");
    projectionList.add(Projections.property("answer4.answerId"), "answer4Id");
    projectionList.add(Projections.property("answer4.answerText"), "answer4Text");
    projectionList.add(
        Projections.property("examResultAnswer.examResultAnswerId"), "examResultAnswerId");
    projectionList.add(Projections.property("examResultAnswer.answerId"), "answerId");
    criteria.setProjection(projectionList);
    criteria.add(Restrictions.eq("examResultAnswer.examResultId", examResult.getExamResultId()));
    criteria.addOrder(Order.asc("examResultAnswer.ordinal"));
    criteria.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);

    return basicFinderService.findByCriteria(criteria);
  }
  public String execute() {
    int to = rows * page;
    int from = to - rows;
    DetachedCriteria criteria = DetachedCriteria.forClass(Cliente.class);

    // Si el campo de busqueda es diferente de nulo
    if (searchField != null) {
      if (searchField.equals("idcliente")) {
        if (searchOper.equals("eq")) {
          BigDecimal searchValue = new BigDecimal(searchString);
          criteria.add(Restrictions.eq("idcliente", searchValue));
        } else if (searchOper.equals("lt")) {
          BigDecimal searchValue = new BigDecimal(searchString);
          criteria.add(Restrictions.lt("idcliente", searchValue));

        } else if (searchOper.equals("gt")) {
          BigDecimal searchValue = new BigDecimal(searchString);
          criteria.add(Restrictions.gt("idcliente", searchValue));
        }
      } else if (searchField.equals("nombre")) {
        // contains
        if (searchOper.equals("cn")) {
          criteria.add(Restrictions.like("nombre", "%" + searchString + "%"));
        }
      } else if (searchField.equals("banco.nombre")) {
        criteria.createAlias("banco", "b");
        if (searchOper.equals("eq")) {
          criteria.add(Restrictions.eq("b.nombre", searchString));
        }
      }
    }

    // Count Customers
    records = clienteService.countByCriteria(criteria);

    // Reset count Projection
    criteria.setProjection(null);
    criteria.setResultTransformer(Criteria.ROOT_ENTITY);

    if (sidx != null && !sidx.equals("")) {
      if (sord.equals("asc")) {
        criteria.addOrder(Order.asc(sidx));
      } else {
        criteria.addOrder(Order.desc(sidx));
      }
    }

    gridModel = clienteService.findByCriteria(criteria, from, rows);

    if (to > records) to = records;

    total = (int) Math.ceil((double) records / (double) rows);

    return "success";
  }
 @SuppressWarnings("unchecked")
 @Override
 public List<CtSubmenus> getSubmenus(List<Integer> listOfMenus) throws Exception {
   DetachedCriteria criteria = DetachedCriteria.forClass(CtSubmenus.class);
   criteria.setResultTransformer(DetachedCriteria.DISTINCT_ROOT_ENTITY);
   criteria.setFetchMode("CtMenus", FetchMode.JOIN);
   criteria.add(Property.forName("CtMenus.idMenu").in(listOfMenus));
   List<CtSubmenus> listOfSubmenus = getHibernateTemplate().findByCriteria(criteria);
   log.debug("Se obtuvieron " + listOfSubmenus.size() + " registros de la tabla CtSubmenus.");
   return listOfSubmenus;
 }
Пример #7
0
  @SuppressWarnings("unchecked")
  public List<Team> getTeamList(TeamType type) {
    DetachedCriteria criteria = DetachedCriteria.forClass(Team.class);

    if (type == TeamType.Product) criteria.add(Restrictions.eq("isProduct", true));
    else if (type == TeamType.Sales) criteria.add(Restrictions.eq("isSales", true));
    else if (type == TeamType.Operator) criteria.add(Restrictions.eq("isOperator", true));

    criteria.setResultTransformer(CriteriaSpecification.ROOT_ENTITY);

    return getHibernateTemplate().findByCriteria(criteria);
  }
 @SuppressWarnings("unchecked")
 @Override
 public DHashes getUserHash(Integer idUsuario) throws Exception {
   DetachedCriteria criteria = DetachedCriteria.forClass(DHashes.class);
   criteria.setResultTransformer(DetachedCriteria.DISTINCT_ROOT_ENTITY);
   criteria.setFetchMode("CtUsuarios", FetchMode.JOIN);
   criteria.add(Property.forName("CtUsuarios.idUsuario").eq(idUsuario));
   List<DHashes> listOfHashes = getHibernateTemplate().findByCriteria(criteria);
   if (listOfHashes.size() > 0) {
     log.info("Se encontro hash asociado al usuario con id " + idUsuario);
     return listOfHashes.get(0);
   } else {
     return null;
   }
 }
  /* (non-Javadoc)
   * @see com.mg.framework.api.orm.DetachedCriteria#setResultTransformer(com.mg.framework.api.orm.ResultTransformer)
   */
  @Override
  public DetachedCriteria setResultTransformer(final ResultTransformer resultTransformer) {
    delegate.setResultTransformer(
        new org.hibernate.transform.ResultTransformer() {

          public List transformList(List collection) {
            return collection;
          }

          public Object transformTuple(Object[] tuple, String[] aliases) {
            return resultTransformer.transformTuple(tuple, aliases);
          }
        });
    return this;
  }
Пример #10
0
  public PaginatedList<Keyword> findKeywords(
      Keyword keyword,
      final boolean ignoreCase,
      final Order order,
      final Integer firstResult,
      final Integer maxResults)
      throws IllegalArgumentException {
    if (keyword == null) {
      throw new IllegalArgumentException("keyword cannot be null");
    }
    final MatchMode matchMode = MatchMode.ANYWHERE;
    Example criterionKeyword = Example.create(keyword);
    criterionKeyword.enableLike(matchMode);
    if (ignoreCase) {
      criterionKeyword.ignoreCase();
    }

    // Normally, Hibernate performs a left-outer join, when searching for
    // an object with collections using Criteria. This returns a ResultSet
    // that contains duplicate objects. In order to get a unique list of
    // Keywords with paginated support, we need to a nested query to find
    // distinct matching ids, then get the Keywords. The end result is a
    // subselect in the main query, but only one query is sent.
    DetachedCriteria dc = DetachedCriteria.forClass(Keyword.class);
    dc.add(criterionKeyword);
    dc.setResultTransformer(DISTINCT_ROOT_ENTITY);

    Conjunction conjunction =
        createTranslationConditions(keyword.getTranslations(), ignoreCase, matchMode);
    if (conjunction != null) dc.createCriteria(FIELD_TRANSLATIONS).add(conjunction);
    dc.setProjection(Projections.id());

    Criteria criteria = getSession().createCriteria(Keyword.class);
    criteria.add(Subqueries.propertyIn(FIELD_ID, dc));
    if (Order.desc == order) criteria.addOrder(desc(FIELD_KEYWORD));
    else criteria.addOrder(asc(FIELD_KEYWORD));
    if (firstResult != null) criteria.setFirstResult(firstResult);
    if (maxResults != null) criteria.setMaxResults(maxResults);

    final List<Keyword> criteriaList = criteria.list();
    int maxListSize = 0;
    if (criteriaList.size() > 0) {
      maxListSize = calculateMaxListSize(criterionKeyword, conjunction);
    }

    return new PaginatedList<Keyword>(criteriaList, maxListSize);
  }
Пример #11
0
  @Override
  public List<Deal> getCoordinatorActiveDeals(User user) {
    DetachedCriteria criteria = DetachedCriteria.forClass(Deal.class);

    DealStateType dealCloseState = workflowDAO.getDealStateType(DealStates.CLOSED_ID);
    DealStateType dealNewState = workflowDAO.getDealStateType(DealStates.NEW_ID);

    criteria
        .add(Restrictions.eq("isEnabled", true))
        .add(Restrictions.ne("dealStateType", dealCloseState))
        .add(Restrictions.ne("dealStateType", dealNewState))
        .add(Restrictions.eq("step", Deal.FINISHED));
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

    @SuppressWarnings("unchecked")
    List<Deal> deals = hibernateTemplate.findByCriteria(criteria);

    return deals;
  }
  private SampleComposition loadComposition(String sampleId) throws Exception {
    SampleComposition composition = null;

    CaNanoLabApplicationService appService =
        (CaNanoLabApplicationService) ApplicationServiceProvider.getApplicationService();
    DetachedCriteria crit = DetachedCriteria.forClass(SampleComposition.class);
    crit.createAlias("sample", "sample");
    crit.add(Property.forName("sample.id").eq(new Long(sampleId)));
    crit.setFetchMode("nanomaterialEntityCollection", FetchMode.JOIN);
    crit.setFetchMode("nanomaterialEntityCollection.fileCollection", FetchMode.JOIN);
    crit.setFetchMode(
        "nanomaterialEntityCollection.fileCollection.keywordCollection", FetchMode.JOIN);
    crit.setFetchMode("nanomaterialEntityCollection.composingElementCollection", FetchMode.JOIN);
    crit.setFetchMode(
        "nanomaterialEntityCollection.composingElementCollection.inherentFunctionCollection",
        FetchMode.JOIN);
    crit.setFetchMode(
        "nanomaterialEntityCollection.composingElementCollection.inherentFunctionCollection.targetCollection",
        FetchMode.JOIN);
    crit.setFetchMode("functionalizingEntityCollection", FetchMode.JOIN);
    crit.setFetchMode("functionalizingEntityCollection.fileCollection", FetchMode.JOIN);
    crit.setFetchMode(
        "functionalizingEntityCollection.fileCollection.keywordCollection", FetchMode.JOIN);
    crit.setFetchMode("functionalizingEntityCollection.functionCollection", FetchMode.JOIN);
    crit.setFetchMode(
        "functionalizingEntityCollection.functionCollection.targetCollection", FetchMode.JOIN);
    crit.setFetchMode("functionalizingEntityCollection.activationMethod", FetchMode.JOIN);
    crit.setFetchMode("chemicalAssociationCollection", FetchMode.JOIN);
    crit.setFetchMode("chemicalAssociationCollection.fileCollection", FetchMode.JOIN);
    crit.setFetchMode(
        "chemicalAssociationCollection.fileCollection.keywordCollection", FetchMode.JOIN);
    crit.setFetchMode("chemicalAssociationCollection.associatedElementA", FetchMode.JOIN);
    crit.setFetchMode("chemicalAssociationCollection.associatedElementB", FetchMode.JOIN);
    crit.setFetchMode("fileCollection", FetchMode.JOIN);
    crit.setFetchMode("fileCollection.keywordCollection", FetchMode.JOIN);
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    List result = appService.query(crit);

    if (!result.isEmpty()) {
      composition = (SampleComposition) result.get(0);
    }
    return composition;
  }
  private Sample findFullyLoadedSampleByName(String sampleName) throws Exception {
    CaNanoLabApplicationService appService =
        (CaNanoLabApplicationService) ApplicationServiceProvider.getApplicationService();
    // load composition and characterization separate because of Hibernate
    // join limitation
    DetachedCriteria crit =
        DetachedCriteria.forClass(Sample.class)
            .add(Property.forName("name").eq(sampleName).ignoreCase());
    Sample sample = null;

    // load composition and characterization separate because of
    // Hibernate join limitation
    crit.setFetchMode("primaryPointOfContact", FetchMode.JOIN);
    crit.setFetchMode("primaryPointOfContact.organization", FetchMode.JOIN);
    crit.setFetchMode("otherPointOfContactCollection", FetchMode.JOIN);
    crit.setFetchMode("otherPointOfContactCollection.organization", FetchMode.JOIN);
    crit.setFetchMode("keywordCollection", FetchMode.JOIN);
    crit.setFetchMode("publicationCollection", FetchMode.JOIN);
    crit.setFetchMode("publicationCollection.authorCollection", FetchMode.JOIN);
    crit.setFetchMode("publicationCollection.keywordCollection", FetchMode.JOIN);
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);

    List result = appService.query(crit);
    if (!result.isEmpty()) {
      sample = (Sample) result.get(0);
    }
    if (sample == null) {
      throw new NotExistException("Sample doesn't exist in the database");
    }

    // fully load composition
    SampleComposition comp = this.loadComposition(sample.getId().toString());
    sample.setSampleComposition(comp);

    // fully load characterizations
    List<Characterization> chars = this.loadCharacterizations(sample.getId().toString());
    if (chars != null && !chars.isEmpty()) {
      sample.setCharacterizationCollection(new HashSet<Characterization>(chars));
    } else {
      sample.setCharacterizationCollection(null);
    }
    return sample;
  }
Пример #14
0
  /**
   * 分页公共方法(非easyui)
   *
   * @author Alexander
   * @date 20131022
   */
  public List<?> pageBaseMethod(
      HttpServletRequest request, DetachedCriteria dc, CommonService commonService, int pageRow) {
    // 当前页
    // 总条数
    // 总页数

    int currentPage = 1;

    int totalRow = 0;
    int totalPage = 0;
    // 获取当前页
    String str_currentPage = request.getParameter("str_currentPage");
    currentPage =
        str_currentPage == null || "".equals(str_currentPage)
            ? 1
            : Integer.parseInt(str_currentPage);
    // 获取每页的条数
    String str_pageRow = request.getParameter("str_pageRow");
    pageRow =
        str_pageRow == null || "".equals(str_pageRow) ? pageRow : Integer.parseInt(str_pageRow);

    // 统计的总行数
    dc.setProjection(Projections.rowCount());

    totalRow = Integer.parseInt(commonService.findByDetached(dc).get(0).toString());
    totalPage = (totalRow + pageRow - 1) / pageRow;

    currentPage = currentPage < 1 ? 1 : currentPage;
    currentPage = currentPage > totalPage ? totalPage : currentPage;
    // 清空统计函数
    dc.setProjection(null);
    dc.setResultTransformer(dc.DISTINCT_ROOT_ENTITY);
    List<?> list = commonService.pageList(dc, (currentPage - 1) * pageRow, pageRow);

    request.setAttribute("currentPage", currentPage);
    request.setAttribute("pageRow", pageRow);
    request.setAttribute("totalRow", totalRow);
    request.setAttribute("totalPage", totalPage);
    return list;
  }
Пример #15
0
  @Override
  public List<Deal> getOperatorActiveDeals(User user) {
    DetachedCriteria criteria =
        DetachedCriteria.forClass(Deal.class)
            .createAlias("user", "user", CriteriaSpecification.LEFT_JOIN);
    criteria.add(Restrictions.eq("user", user)).add(Restrictions.eq("isEnabled", true));

    DealWorkflowSideType operatorWorkflowSideType =
        workflowDAO.getWorkflowSideType(DealWorkflowSideTypes.OPERATOR_SIDE_ID);

    DealStateType dealCloseState = workflowDAO.getDealStateType(DealStates.CLOSED_ID);

    criteria
        .add(Restrictions.eq("dealWorkflowSideType", operatorWorkflowSideType))
        .add(Restrictions.ne("dealStateType", dealCloseState))
        .add(Restrictions.eq("step", Deal.FINISHED));
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

    @SuppressWarnings("unchecked")
    List<Deal> deals = hibernateTemplate.findByCriteria(criteria);

    return deals;
  }
 public void updatePOCAssociatedWithCharacterizations(
     String sampleName, Long oldPOCId, Long newPOCId) throws SampleException {
   try {
     CaNanoLabApplicationService appService =
         (CaNanoLabApplicationService) ApplicationServiceProvider.getApplicationService();
     DetachedCriteria crit = DetachedCriteria.forClass(Characterization.class);
     crit.createAlias("sample", "sample");
     crit.createAlias("pointOfContact", "poc");
     crit.add(Property.forName("poc.id").eq(oldPOCId));
     crit.add(Property.forName("sample.name").eq(sampleName));
     crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
     List results = appService.query(crit);
     for (int i = 0; i < results.size(); i++) {
       Characterization achar = (Characterization) results.get(i);
       // update POC to the new ID
       achar.getPointOfContact().setId(newPOCId);
       appService.saveOrUpdate(achar);
     }
   } catch (Exception e) {
     String err = "Error in updating POC associated sample characterizations " + sampleName;
     logger.error(err, e);
     throw new SampleException(err, e);
   }
 }
Пример #17
0
  @Override
  public List<OnmsAssetRecord> getDistinctProperties() {
    DetachedCriteria criteria = DetachedCriteria.forClass(OnmsAssetRecord.class);
    ProjectionList projList = Projections.projectionList();

    projList.add(
        Projections.alias(Projections.property("additionalhardware"), "additionalhardware"));
    projList.add(Projections.alias(Projections.property("address1"), "address1"));
    projList.add(Projections.alias(Projections.property("address2"), "address2"));
    projList.add(Projections.alias(Projections.property("admin"), "admin"));
    projList.add(Projections.alias(Projections.property("assetNumber"), "assetNumber"));
    projList.add(Projections.alias(Projections.property("autoenable"), "autoenable"));
    projList.add(Projections.alias(Projections.property("building"), "building"));
    projList.add(Projections.alias(Projections.property("category"), "category"));
    projList.add(Projections.alias(Projections.property("circuitId"), "circuitId"));
    projList.add(Projections.alias(Projections.property("city"), "city"));
    projList.add(Projections.alias(Projections.property("comment"), "comment"));
    projList.add(Projections.alias(Projections.property("connection"), "connection"));
    projList.add(Projections.alias(Projections.property("cpu"), "cpu"));
    projList.add(Projections.alias(Projections.property("department"), "department"));
    projList.add(Projections.alias(Projections.property("description"), "description"));
    projList.add(Projections.alias(Projections.property("displayCategory"), "displayCategory"));
    projList.add(Projections.alias(Projections.property("division"), "division"));
    projList.add(Projections.alias(Projections.property("enable"), "enable"));
    projList.add(Projections.alias(Projections.property("floor"), "floor"));
    projList.add(Projections.alias(Projections.property("hdd1"), "hdd1"));
    projList.add(Projections.alias(Projections.property("hdd2"), "hdd2"));
    projList.add(Projections.alias(Projections.property("hdd3"), "hdd3"));
    projList.add(Projections.alias(Projections.property("hdd4"), "hdd4"));
    projList.add(Projections.alias(Projections.property("hdd5"), "hdd5"));
    projList.add(Projections.alias(Projections.property("hdd6"), "hdd6"));
    projList.add(Projections.alias(Projections.property("inputpower"), "inputpower"));
    projList.add(Projections.alias(Projections.property("lease"), "lease"));
    projList.add(Projections.alias(Projections.property("maintcontract"), "maintcontract"));
    projList.add(Projections.alias(Projections.property("manufacturer"), "manufacturer"));
    projList.add(Projections.alias(Projections.property("modelNumber"), "modelNumber"));
    projList.add(Projections.alias(Projections.property("notifyCategory"), "notifyCategory"));
    projList.add(Projections.alias(Projections.property("numpowersupplies"), "numpowersupplies"));
    projList.add(Projections.alias(Projections.property("operatingSystem"), "operatingSystem"));
    projList.add(Projections.alias(Projections.property("pollerCategory"), "pollerCategory"));
    projList.add(Projections.alias(Projections.property("port"), "port"));
    projList.add(Projections.alias(Projections.property("rack"), "rack"));
    projList.add(Projections.alias(Projections.property("ram"), "ram"));
    projList.add(Projections.alias(Projections.property("region"), "region"));
    projList.add(Projections.alias(Projections.property("room"), "room"));
    projList.add(Projections.alias(Projections.property("serialNumber"), "serialNumber"));
    projList.add(Projections.alias(Projections.property("slot"), "slot"));
    projList.add(Projections.alias(Projections.property("snmpcommunity"), "snmpcommunity"));
    projList.add(Projections.alias(Projections.property("state"), "state"));
    projList.add(Projections.alias(Projections.property("storagectrl"), "storagectrl"));
    projList.add(Projections.alias(Projections.property("supportPhone"), "supportPhone"));
    projList.add(Projections.alias(Projections.property("thresholdCategory"), "thresholdCategory"));
    projList.add(Projections.alias(Projections.property("username"), "username"));
    projList.add(Projections.alias(Projections.property("vendor"), "vendor"));
    projList.add(Projections.alias(Projections.property("vendorAssetNumber"), "vendorAssetNumber"));
    projList.add(Projections.alias(Projections.property("vendorFax"), "vendorFax"));
    projList.add(Projections.alias(Projections.property("vendorPhone"), "vendorPhone"));
    projList.add(Projections.alias(Projections.property("zip"), "zip"));

    criteria.setProjection(Projections.distinct(projList));
    criteria.setResultTransformer(Transformers.aliasToBean(OnmsAssetRecord.class));

    @SuppressWarnings("unchecked")
    List<OnmsAssetRecord> result = getHibernateTemplate().findByCriteria(criteria);
    return result;
  }
Пример #18
0
  /**
   * 条件查询
   *
   * @param detachedCriteria
   * @return
   * @throws com.prj.common.ServiceException
   */
  public List findByCriteria(final DetachedCriteria detachedCriteria) {

    detachedCriteria.setResultTransformer(DetachedCriteria.DISTINCT_ROOT_ENTITY);
    return basicDao.findByCriteria(detachedCriteria);
  }
Пример #19
0
  @Override
  public List<Deal> getDeals(DataTableHandler dataTableHandler, User userToGetDeals)
      throws UnsupportedEncodingException {
    DetachedCriteria criteria = DetachedCriteria.forClass(Deal.class);
    criteria =
        criteria
            .createAlias("customer", "customer", CriteriaSpecification.LEFT_JOIN)
            .createAlias(
                "customer.workingPlace.jobType", "jobType", CriteriaSpecification.LEFT_JOIN)
            .createAlias("credit", "credit", CriteriaSpecification.LEFT_JOIN);

    criteria.add(Restrictions.eq("isEnabled", true));

    if (userToGetDeals != null) {
      criteria.add(Restrictions.eq("user", userToGetDeals));
    }

    DataTableRequest request = dataTableHandler.getDataTableRequest();

    String direction = request.getsSortDirection();
    int index = request.getiSortColumnIndex();
    int start = request.getiDisplayStart();
    int maxResult = request.getiDisplayLength();

    if (index == 0) {
      if (direction.equals("asc")) {
        criteria.addOrder(Order.asc("id"));
      } else {
        criteria.addOrder(Order.desc("id"));
      }
    }

    if (index == 1) {
      if (direction.equals("asc")) {
        criteria.addOrder(Order.asc("customer.lastName"));
      } else {
        criteria.addOrder(Order.desc("customer.lastName"));
      }
    }

    if (index == 2) {
      if (direction.equals("asc")) {
        criteria.addOrder(Order.asc("jobType.code"));
      } else {
        criteria.addOrder(Order.desc("jobType.code"));
      }
    }

    if (index == 3) {
      if (direction.equals("asc")) {
        criteria.addOrder(Order.asc("credit.amount"));
      } else {
        criteria.addOrder(Order.desc("credit.amount"));
      }
    }

    if (index == 4) {
      if (direction.equals("asc")) {
        criteria.addOrder(Order.asc("credit.term"));
      } else {
        criteria.addOrder(Order.desc("credit.term"));
      }
    }

    if (index == 5) {
      if (direction.equals("asc")) {
        criteria.addOrder(Order.asc("creationDate"));
      } else {
        criteria.addOrder(Order.desc("creationDate"));
      }
    }

    String query = request.getsSearch();

    int totalRecordsNumber = getNumberOfDeals(userToGetDeals);
    dataTableHandler.setiTotalRecords(totalRecordsNumber);

    if (!query.equals("")) {
      Criterion criterion =
          Restrictions.disjunction().add(Restrictions.like("customer.lastName", query));

      if (Pattern.matches("^\\d*$", query)) {
        Integer iQuery = Integer.parseInt(query);
        criterion =
            Restrictions.disjunction()
                .add(Restrictions.like("customer.lastName", "%" + query + "%"))
                .add(Restrictions.eq("id", iQuery));
      } else {
        criterion =
            Restrictions.disjunction()
                .add(Restrictions.like("customer.lastName", "%" + query + "%"));
      }

      int totalDisplayRecordsNumber = getNumberOfDeals(criterion, userToGetDeals);
      dataTableHandler.setiTotalDisplayRecords(totalDisplayRecordsNumber);
      criteria.add(criterion);
    } else {
      dataTableHandler.setiTotalDisplayRecords(totalRecordsNumber);
    }

    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

    @SuppressWarnings("unchecked")
    List<Deal> deals = hibernateTemplate.findByCriteria(criteria, start, maxResult);

    return deals;
  }
Пример #20
0
 public void setResultTransformer(Class class1) {
   detachedCriteria.setResultTransformer(Transformers.aliasToBean(class1));
 }