org.springframework.data.elasticsearch.repository.ElasticsearchRepository Java Examples

The following examples show how to use org.springframework.data.elasticsearch.repository.ElasticsearchRepository. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MetadataController.java    From youkefu with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/clean")
@Menu(type = "admin" , subtype = "metadata" , admin = true)
public ModelAndView clean(ModelMap map , HttpServletRequest request,@Valid String id) throws SQLException, BeansException, ClassNotFoundException {
	if(!StringUtils.isBlank(id)) {
		MetadataTable table = metadataRes.findById(id) ;
		if(table.isFromdb() && !StringUtils.isBlank(table.getListblocktemplet())) {
			SysDic dic = UKeFuDic.getInstance().getDicItem(table.getListblocktemplet()) ;
			if(dic!=null) {
 			Object bean = UKDataContext.getContext().getBean(Class.forName(dic.getCode())) ;
 			if(bean instanceof ElasticsearchRepository) {
 				ElasticsearchRepository<?, ?> jpa = (ElasticsearchRepository<?, ?>)bean ;
 				jpa.deleteAll(); 
 			}
			}
		}
	}
	return request(super.createRequestPageTempletResponse("redirect:/admin/metadata/index.html"));
}
 
Example #2
Source File: MetadataController.java    From youkefu with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "rawtypes"})
@RequestMapping("/synctodb")
   @Menu(type = "admin" , subtype = "metadata" , admin = true)
   public ModelAndView synctodb(ModelMap map , HttpServletRequest request,@Valid String id) throws SQLException, BeansException, ClassNotFoundException {
   	if(!StringUtils.isBlank(id)) {
   		MetadataTable table = metadataRes.findById(id) ;
   		if(table.isFromdb() && !StringUtils.isBlank(table.getListblocktemplet())) {
   			SysDic dic = UKeFuDic.getInstance().getDicItem(table.getListblocktemplet()) ;
   			
   			if(dic!=null) {
    			Object bean = UKDataContext.getContext().getBean(Class.forName(dic.getCode())) ;
    			if(bean instanceof ElasticsearchRepository) {
    				ElasticsearchRepository jpa = (ElasticsearchRepository)bean ;
    				if(!StringUtils.isBlank(table.getPreviewtemplet())) {
    					Iterable dataList = jpa.findAll();
    					for(Object object : dataList) {
    						service.delete(object);
    						service.save(object);
    					}
    				}
    			}
   			}
   		}
   	}
   	return request(super.createRequestPageTempletResponse("redirect:/admin/metadata/index.html"));
   }
 
Example #3
Source File: AclElasticsearchRepositoryFactoryBean.java    From strategy-spring-security-acl with Apache License 2.0 6 votes vote down vote up
@Override
protected Object getTargetRepository(RepositoryInformation metadata) {
  Class<?> domainType = metadata.getDomainType();
  ElasticsearchEntityInformation<?, Serializable> entityInformation =
      getEntityInformation(domainType);
  if (!hasAclStrategyAnnotation(domainType)) {
    return getTargetRepositoryViaReflection(metadata, entityInformation,
        elasticsearchOperations);
  }

  // invokes
  // com.github.lothar.security.acl.elasticsearch.repository.AclElasticsearchRepository.AclNumberKeyedRepository(ElasticsearchEntityInformation<T,
  // ID>, ElasticsearchOperations, AclFilterProvider)
  ElasticsearchRepository<?, ?> repository = getTargetRepositoryViaReflection(metadata,
      entityInformation, elasticsearchOperations, filterProvider);
  logger.debug("Created {}", repository);

  return repository;
}
 
Example #4
Source File: MetadataController.java    From youkefu with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked"})
@RequestMapping("/synctoes")
   @Menu(type = "admin" , subtype = "metadata" , admin = true)
   public ModelAndView synctoes(ModelMap map , HttpServletRequest request,@Valid String id) throws SQLException, BeansException, ClassNotFoundException {
   	if(!StringUtils.isBlank(id)) {
   		MetadataTable table = metadataRes.findById(id) ;
   		if(table.isFromdb() && !StringUtils.isBlank(table.getListblocktemplet())) {
   			SysDic dic = UKeFuDic.getInstance().getDicItem(table.getListblocktemplet()) ;
   			
   			if(dic!=null) {
    			Object bean = UKDataContext.getContext().getBean(Class.forName(dic.getCode())) ;
    			if(bean instanceof ElasticsearchRepository) {
    				ElasticsearchRepository jpa = (ElasticsearchRepository)bean ;
    				if(!StringUtils.isBlank(table.getPreviewtemplet())) {
    					SysDic jpaDic = UKeFuDic.getInstance().getDicItem(table.getPreviewtemplet()) ;
    					List dataList = service.list(jpaDic.getCode()) ;
    					List values = new UKeFuList();
    					for(Object object : dataList) {
    						values.add(object) ;
    					}
    					if(dataList.size() > 0) {
    						jpa.save(values) ;
    					}
    				}
    			}
   			}
   		}
   	}
   	return request(super.createRequestPageTempletResponse("redirect:/admin/metadata/index.html"));
   }
 
Example #5
Source File: ElasticSearchUtil.java    From spring-boot-tutorial with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
public static <T, ID extends Serializable> Page<T> pageSearch(final ElasticsearchRepository<T, ID> repository,
    final Object queryBean, final QueryLogicType logicType) throws IllegalAccessException, NoSuchFieldException {

    if (queryBean == null || repository == null) {
        throw new NullPointerException("repository and queryBean must not be null");
    }

    NativeSearchQueryBuilder nativeSearchQueryBuilder =
        ElasticSearchUtil.getNativeSearchQueryBuilder(queryBean, logicType);
    if (nativeSearchQueryBuilder == null) {
        System.out.println("查询条件为空");
    }

    return repository.search(nativeSearchQueryBuilder.build());
}
 
Example #6
Source File: ElasticSearchUtil.java    From spring-boot-tutorial with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
public static <T, ID extends Serializable> List<T> search(final ElasticsearchRepository<T, ID> repository,
    final Object queryBean, final QueryLogicType logicType) throws IllegalAccessException {

    if (queryBean == null || repository == null) {
        throw new NullPointerException("repository and queryBean must not be null");
    }

    QueryDocument document = queryBean.getClass().getAnnotation(QueryDocument.class);
    if (null == document) {
        throw new IllegalArgumentException("查询条件类定义必须使用 @QueryDocument 注解");
    }

    List<QueryBuilder> queryBuilders = ElasticSearchUtil.getQueryBuilders(queryBean);
    if (CollectionUtil.isEmpty(queryBuilders)) {
        return null;
    }

    QueryLogicType realLogicType;
    if (logicType == null) {
        realLogicType = document.logicType();
    } else {
        realLogicType = logicType;
    }
    BoolQueryBuilder boolQueryBuilder = getBoolQueryBuilder(realLogicType, queryBuilders);
    Iterable<T> iterable = repository.search(boolQueryBuilder);
    List<T> list = CollectionUtil.newArrayList(iterable);

    QueryDocument.Order[] orders = document.orders();
    ComparatorChain<T> comparatorChain = new ComparatorChain<>();
    for (QueryDocument.Order order : orders) {
        Comparator<T> propertyComparator = new PropertyComparator<>(order.value());
        if (order.type() == OrderType.ASC) {
            comparatorChain.addComparator(propertyComparator);
        } else {
            comparatorChain.addComparator(propertyComparator, true);
        }
    }

    return CollectionUtil.sort(list, comparatorChain);
}