Esempio n. 1
0
  @Override
  public List<Privilege> search(final ImmutablePair<String, ?>... constraints) {
    final Specification<Privilege> firstSpec =
        SearchSecUtil.resolveConstraint(constraints[0], Privilege.class);
    Specifications<Privilege> specifications = Specifications.where(firstSpec);
    for (int i = 1; i < constraints.length; i++) {
      specifications =
          specifications.and(SearchSecUtil.resolveConstraint(constraints[i], Privilege.class));
    }
    if (firstSpec == null) {
      return Lists.newArrayList();
    }

    return getDao().findAll(specifications);
  }
 @Override
 public T findOneByExample(final T entity, final SearchParameters sp) {
   Assert.notNull(sp, "Search parameters required");
   Specifications<T> spec =
       Specifications.where(byExampleEnhancedSpecification.byExampleOnEntity(entity, sp));
   return super.findOne(spec);
 }
 @Override
 public Page<T> findByExample(
     final T example, final List<Range<T, ?>> ranges, final Pageable pageable) {
   Specifications<T> spec = Specifications.where(byExampleSpecification.byExample(example));
   spec = RangeSpecification.andRangeIfSet(spec, ranges);
   return findAll(spec, pageable);
 }
  public List<T> findAll(UserInfo userInfo, F form) {
    logger.infoCode("I0001");

    // 必須
    Specification<T> whereUserKey =
        new Specification<T>() {
          @Override
          public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
            return cb.equal(root.get("usUserTbl").get("userKey"), userInfo.getTargetUserKey());
          }
        };
    // 言語
    Specification<T> whereLanguage =
        StringUtil.isNull(form.getLanguage())
            ? null
            : new Specification<T>() {
              @Override
              public Predicate toPredicate(
                  Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                return cb.equal(root.get("paperLanguage"), form.getLanguage());
              }
            };

    List<T> list =
        (List<T>)
            repository.findAll(
                (Specification<T>) Specifications.where(whereUserKey).and(whereLanguage));

    logger.infoCode("I0002");
    return list;
  }
Esempio n. 5
0
  @Test
  public void testUser() {
    User user = new User();
    user.setUserName("MyName1");
    user.setEmail("*****@*****.**");
    user.setCreatedUser(getUser("user"));
    user.setCreatedDate(new Date());
    user.setUserId("hello");
    user.setRole(Role.USER);
    user = userRepository.save(user);
    User user2 = new User();
    user2.setUserId("hello2");
    user2.setUserName("MyName2");
    user2.setEmail("*****@*****.**");
    user2.setCreatedUser(getUser("user"));
    user2.setCreatedDate(new Date());
    user2.setRole(Role.USER);
    userRepository.save(user2);

    assertThat(userRepository.count(), is(2L));

    assertThat(userRepository.findAll(UserSpecification.emailLike("gmail")).size(), is(1));

    assertThat(
        userRepository
            .findAll(
                Specifications.where(UserSpecification.emailLike("@paran"))
                    .and(UserSpecification.nameLike("MyName2")))
            .size(),
        is(1));
  }
 public T findOne(String gyosekiKey, String userKey, Timestamp updDate) {
   // 必須
   Specification<T> whereGyosekiKey =
       new Specification<T>() {
         @Override
         public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
           return cb.equal(root.get("gyosekiKey"), gyosekiKey);
         }
       };
   // 必須
   Specification<T> whereUserKey =
       new Specification<T>() {
         @Override
         public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
           return cb.equal(root.get("usUserTbl").get("userKey"), userKey);
         }
       };
   // 更新日
   Specification<T> whereUpdDate =
       updDate == null
           ? null
           : new Specification<T>() {
             @Override
             public Predicate toPredicate(
                 Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
               return cb.equal(root.get("updDate"), updDate);
             }
           };
   return (T)
       repository.findOne(
           (Specification<T>)
               Specifications.where(whereGyosekiKey).and(whereUserKey).and(whereUpdDate));
 }
  /**
   * 支援制度キーとデータ更新日指定取得
   *
   * @param supportKey
   * @param updDate
   * @return
   */
  public SpSupportTbl findOne(final String supportKey, final Timestamp updDate) {
    logger.infoCode("I0001"); // I0001=メソッド開始:{0}

    // キー
    Specification<SpSupportTbl> whereSupportKey =
        StringUtil.isNull(supportKey)
            ? null
            : new Specification<SpSupportTbl>() {
              @Override
              public Predicate toPredicate(
                  Root<SpSupportTbl> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                return cb.equal(root.get("supportKey"), supportKey);
              }
            };
    // データ更新日
    Specification<SpSupportTbl> whereUpdDate =
        DateUtil.isNull(updDate)
            ? null
            : new Specification<SpSupportTbl>() {
              @Override
              public Predicate toPredicate(
                  Root<SpSupportTbl> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                return cb.equal(root.get("updDate"), updDate);
              }
            };

    logger.infoCode("I0002"); // I0002=メソッド終了:{0}
    return spSupportTblRepository.findOne(Specifications.where(whereSupportKey).and(whereUpdDate));
  }
  public EvEventTbl findOne(UserInfo userInfo, EventForm form) {
    logger.infoCode("I0001"); // I0001=メソッド開始:{0}

    // 定数区分
    Specification<EvEventTbl> whereEventKey =
        StringUtil.isNull(form.getEventKey())
            ? null
            : new Specification<EvEventTbl>() {
              @Override
              public Predicate toPredicate(
                  Root<EvEventTbl> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                return cb.equal(root.get("eventKey"), form.getEventKey());
              }
            };
    Specification<EvEventTbl> whereUpdDate =
        DateUtil.isNull(form.getUpdDate())
            ? null
            : new Specification<EvEventTbl>() {
              @Override
              public Predicate toPredicate(
                  Root<EvEventTbl> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                return cb.equal(root.get("updDate"), form.getUpdDate());
              }
            };

    logger.infoCode("I0002"); // I0002=メソッド終了:{0}
    return evEventTblRepository.findOne(Specifications.where(whereEventKey).and(whereUpdDate));
  }
Esempio n. 9
0
 public List<Railway> findAll(Railway criteria) {
   PlainSpecification<Railway> spec1 =
       new PlainSpecification<Railway>(new SearchCriteria("id", "=", criteria.getId()));
   PlainSpecification<Railway> spec2 =
       new PlainSpecification<Railway>(
           new SearchCriteria("railwayCode", "like", criteria.getRailwayCode()));
   return railwayRepository.findAll(Specifications.where(spec1).and(spec2));
 }
 @Transactional(readOnly = true)
 public Page<Map<String, Object>> findAll(
     CustomRepositorySelector<Usuario> customRepositorySelector,
     Specification<Usuario> specification,
     Pageable pageable) {
   return usuarioRepository.findAll(
       customRepositorySelector, Specifications.where(specification), pageable);
 }
 @Override
 public List<T> findByExample(final T entity, final SearchParameters sp) {
   Assert.notNull(sp, "Search parameters required");
   if (sp.hasNamedQuery()) {
     return getNamedQueryUtil().findByNamedQuery(sp);
   }
   Specifications<T> spec =
       Specifications.where(byExampleEnhancedSpecification.byExampleOnEntity(entity, sp));
   return findAll(spec);
 }
  @Override
  public long countByExample(final T entity, final SearchParameters sp) {
    Validate.notNull(entity, "The entity cannot be null");
    if (sp.hasNamedQuery()) {
      return getNamedQueryUtil().numberByNamedQuery(sp).intValue();
    }
    Specifications<T> spec =
        Specifications.where(byExampleEnhancedSpecification.byExampleOnEntity(entity, sp));

    return super.count(spec);
  }
  @Transactional(readOnly = true)
  private Specification<Usuario> childrenBelongsToPessoaId(final Long pessoaId) {
    Pessoa pessoa = pessoaService.findOne(pessoaId);

    if (pessoa instanceof Estabelecimento) {
      Estabelecimento pai = null;

      Specifications<Usuario> pessoaIdEqualsSpecifications =
          Specifications.where(pessoaIdEquals(pessoaId));

      while ((pai = pai == null ? ((Estabelecimento) pessoa).getPai() : pai.getPai()) != null) {
        pessoaIdEqualsSpecifications =
            pessoaIdEqualsSpecifications.or(pessoaIdEquals(pai.getPessoaId()));
      }

      return pessoaIdEqualsSpecifications;
    } else {
      return Specifications.where(pessoaIdEquals(pessoaId));
    }
  }
 @Transactional(readOnly = true)
 public Page<Map<String, Object>> findAll(
     CustomRepositorySelector<Usuario> customRepositorySelector,
     Specification<Usuario> specification,
     Pageable pageable,
     Long pessoaId,
     Long paiPessoaId) {
   return usuarioRepository.findAll(
       customRepositorySelector,
       Specifications.where(specification)
           .and(pessoaIdEqualsOrPaiPessoaIdEquals(pessoaId, paiPessoaId)),
       pageable);
 }
  /**
   * 一覧取得
   *
   * @param form
   * @param locale
   * @return
   */
  public List<SpSupportDto> findSupportBatchTarget(SupportForm form, Locale locale) {
    logger.infoCode("I0001"); // I0001=メソッド開始:{0}

    Date today = DateUtil.toDate(DateUtil.getSysdate("yyyyMMdd"));

    // 取得条件:公開
    Specification<SpSupportTbl> wherePublicFlag =
        StringUtil.isNull(form.getSearchPublicFlag())
            ? null
            : new Specification<SpSupportTbl>() {
              @Override
              public Predicate toPredicate(
                  Root<SpSupportTbl> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                return cb.equal(root.get("publicFlag"), form.getSearchPublicFlag());
              }
            };

    // 取得条件:日付
    Specification<SpSupportTbl> whereEnDay =
        StringUtil.isNull(form.getSearchDateType())
            ? null
            : new Specification<SpSupportTbl>() {
              @Override
              public Predicate toPredicate(
                  Root<SpSupportTbl> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                // batch処理
                if (SEARCH_DATE_TYPE_BATCH.equals(form.getSearchDateType().toLowerCase())) {
                  Predicate predicate = cb.conjunction();
                  Predicate predicate2 = cb.conjunction();
                  predicate2 =
                      cb.and(predicate2, cb.equal(root.get("updDate").as(Date.class), today));
                  predicate2 =
                      cb.and(
                          predicate2, cb.lessThan(root.get("eventSendDate").as(Date.class), today));

                  predicate =
                      cb.and(predicate, cb.equal(root.get("eventSendDate").as(Date.class), today));
                  predicate = cb.or(predicate2);
                  return predicate;
                }
                return null;
              }
            };

    List<SpSupportTbl> list =
        spSupportTblRepository.findAll(Specifications.where(wherePublicFlag).and(whereEnDay));

    logger.infoCode("I0002"); // I0002=メソッド終了:{0}
    return getDtoList(list, locale);
  }
  public List<F> findAllProfileView(UserInfo userInfo, String[] publicFlags) {
    logger.infoCode("I0001");

    //
    Specification<T> whereUserKey =
        new Specification<T>() {
          @Override
          public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
            return cb.equal(root.get("usUserTbl").get("userKey"), userInfo.getTargetUserKey());
          }
        };

    // 取得条件:
    Specification<T> wherePublicFlags =
        publicFlags == null
            ? null
            : new Specification<T>() {
              @Override
              public Predicate toPredicate(
                  Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                Predicate predicate = cb.conjunction();
                for (int i = 0; i < publicFlags.length; i++) {
                  String keyword = publicFlags[i];
                  if (i == 0) {
                    predicate = cb.and(predicate, cb.equal(root.get("publicFlag"), keyword));
                  } else {
                    predicate = cb.or(predicate, cb.equal(root.get("publicFlag"), keyword));
                  }
                }
                return predicate;
              }
            };

    List<T> list =
        (List<T>)
            repository.findAll(
                (Specification<T>) Specifications.where(whereUserKey).and(wherePublicFlags));

    logger.infoCode("I0002");
    return getDtoList(list);
  }
  @Transactional(readOnly = true)
  private Specification<Usuario> pessoaIdEqualsOrPaiPessoaIdEquals(
      final Long pessoaId, final Long paiPessoaId) {
    Specification<Usuario> pessoaIdEqualsSpecification = pessoaIdEquals(pessoaId);

    Specification<Usuario> paiPessoaIdEqualsSpecification =
        new Specification<Usuario>() {
          @Override
          public Predicate toPredicate(
              Root<Usuario> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
            Subquery<Long> estabelecimentoQuery = criteriaQuery.subquery(Long.class);
            Root<Estabelecimento> estabelecimentoRoot =
                estabelecimentoQuery.from(Estabelecimento.class);
            Join<Estabelecimento, Usuario> usuarios = estabelecimentoRoot.join("usuarios");
            estabelecimentoQuery.select(usuarios.get("usuarioId").as(Long.class));
            estabelecimentoQuery.where(
                criteriaBuilder.equal(estabelecimentoRoot.get("pai").get("pessoaId"), paiPessoaId));

            return criteriaBuilder.in(root.get("usuarioId")).value(estabelecimentoQuery);
          }
        };

    return Specifications.where(pessoaIdEqualsSpecification).or(paiPessoaIdEqualsSpecification);
  }
 @Override
 public Page<T> findByExample(final T example, final Pageable pageable) {
   Specifications<T> spec = Specifications.where(byExampleSpecification.byExample(example));
   return findAll(spec, pageable);
 }
 @Override
 public List<T> find(final String pattern) {
   Specifications<T> spec =
       Specifications.where(byExampleSpecification.byPatternOnStringAttributes(pattern, type));
   return findAll(spec, new PageRequest(0, MAX_VALUES_RETREIVED)).getContent();
 }
 @Transactional(readOnly = true)
 public Page<Usuario> findAll(Specification<Usuario> specification, Pageable pageable) {
   return usuarioRepository.findAll(Specifications.where(specification), pageable);
 }
  /**
   * 一覧取得
   *
   * @param form
   * @param locale
   * @return
   */
  public List<SpSupportDto> findAllLikeKeyWords(SupportForm form, Locale locale) {
    logger.infoCode("I0001"); // I0001=メソッド開始:{0}

    Date today = DateUtil.toDate(DateUtil.getSysdate("yyyyMMdd"));

    // 取得条件:区分
    Specification<SpSupportTbl> whereSupportSpkikiKbn =
        StringUtil.isNull(form.getSearchSpkikiKbn())
            ? null
            : new Specification<SpSupportTbl>() {
              @Override
              public Predicate toPredicate(
                  Root<SpSupportTbl> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                return cb.equal(root.get("supportSpkikiKbn"), form.getSearchSpkikiKbn());
              }
            };

    // 取得条件:公開
    Specification<SpSupportTbl> wherePublicFlag =
        StringUtil.isNull(form.getSearchPublicFlag())
            ? null
            : new Specification<SpSupportTbl>() {
              @Override
              public Predicate toPredicate(
                  Root<SpSupportTbl> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                return cb.equal(root.get("publicFlag"), form.getSearchPublicFlag());
              }
            };

    // 取得条件:HIRAKUリンク区分
    Specification<SpSupportTbl> whereSupportHirakuKbn =
        StringUtil.isNull(form.getSearchHirakuKbn())
            ? null
            : new Specification<SpSupportTbl>() {
              @Override
              public Predicate toPredicate(
                  Root<SpSupportTbl> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                return cb.equal(root.get("supportHirakuKbn"), form.getSearchHirakuKbn());
              }
            };

    // 取得条件:地域区分
    Specification<SpSupportTbl> whereSupportAreaKbn =
        StringUtil.isNull(form.getSearchAreaKbn())
            ? null
            : new Specification<SpSupportTbl>() {
              @Override
              public Predicate toPredicate(
                  Root<SpSupportTbl> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                return cb.equal(root.get("supportAreaKbn"), form.getSearchAreaKbn());
              }
            };

    // 取得条件:組織コード
    Specification<SpSupportTbl> wherePartyCode =
        StringUtil.isNull(form.getSearchPartyCode())
            ? null
            : new Specification<SpSupportTbl>() {
              @Override
              public Predicate toPredicate(
                  Root<SpSupportTbl> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                return cb.equal(root.get("partyCode"), form.getSearchPartyCode());
              }
            };

    // 取得条件:キーワード
    Specification<SpSupportTbl> whereKeywords =
        StringUtil.isNull(form.getSearchKeyword())
            ? null
            : new Specification<SpSupportTbl>() {
              @Override
              public Predicate toPredicate(
                  Root<SpSupportTbl> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                String[] keywords = form.getSearchKeyword().split(",");
                Predicate predicate = cb.conjunction();
                for (int i = 0; i < keywords.length; i++) {
                  String keyword = keywords[i];
                  predicate =
                      cb.and(predicate, cb.like(root.get("supportKeyword"), "%" + keyword + "%"));
                }
                return predicate;
              }
            };

    // 取得条件:支援制度種別コード
    Specification<SpSupportTbl> whereSyb =
        StringUtil.isNull(form.getSearchSybCode())
            ? null
            : new Specification<SpSupportTbl>() {
              @Override
              public Predicate toPredicate(
                  Root<SpSupportTbl> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                String[] sybcodes = form.getSearchSybCodeArray();
                Predicate predicate = cb.conjunction();
                for (int i = 0; i < sybcodes.length; i++) {
                  String sybcode = sybcodes[i];
                  predicate =
                      cb.and(predicate, cb.like(root.get("supportSybCode"), "%" + sybcode + "%"));
                }
                return predicate;
              }
            };

    // 取得条件:日付(期間)
    Specification<SpSupportTbl> whereDate =
        StringUtil.isNull(form.getSearchDateType())
            ? null
            : new Specification<SpSupportTbl>() {
              @Override
              public Predicate toPredicate(
                  Root<SpSupportTbl> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                // batch処理
                if (SEARCH_DATE_TYPE_BATCH.equals(form.getSearchDateType().toLowerCase())) {
                  Predicate predicate = cb.conjunction();
                  Predicate predicate2 = cb.conjunction();
                  predicate2 =
                      cb.and(predicate2, cb.equal(root.get("updDate").as(Date.class), today));
                  predicate2 =
                      cb.and(
                          predicate2,
                          cb.lessThan(root.get("supportStartDate").as(Date.class), today));
                  predicate =
                      cb.and(
                          predicate, cb.equal(root.get("supportStartDate").as(Date.class), today));
                  predicate = cb.or(predicate2);
                  return predicate;
                }
                // 期間中
                if (SEARCH_DATE_TYPE_CURRENT.equals(form.getSearchDateType())) {
                  Predicate predicate = cb.conjunction();
                  predicate =
                      cb.and(
                          predicate,
                          cb.lessThanOrEqualTo(root.get("supportStartDate").as(Date.class), today));
                  predicate =
                      cb.and(
                          predicate,
                          cb.greaterThanOrEqualTo(
                              root.get("supportEndDate").as(Date.class), today));
                  return predicate;
                }
                // 過去情報
                if (SEARCH_DATE_TYPE_PAST.equals(form.getSearchDateType())) {
                  return cb.lessThan(root.get("supportEndDate").as(Date.class), today);
                }
                // 終了前
                if (SEARCH_DATE_TYPE_PRESENT.equals(form.getSearchDateType())) {
                  return cb.greaterThanOrEqualTo(root.get("supportEndDate").as(Date.class), today);
                }
                return null;
              }
            };

    List<SpSupportTbl> list =
        spSupportTblRepository.findAll(
            Specifications.where(whereSupportSpkikiKbn)
                .and(whereSupportHirakuKbn)
                .and(whereSupportAreaKbn)
                .and(wherePublicFlag)
                .and(wherePartyCode)
                .and(whereKeywords)
                .and(whereSyb)
                .and(whereDate),
            orderBy());

    logger.infoCode("I0002"); // I0002=メソッド終了:{0}
    return getDtoList(list, locale);
  }