123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- package com.qmth.ops.biz.service;
- import com.fasterxml.jackson.databind.ObjectMapper;
- import com.fasterxml.jackson.databind.type.CollectionType;
- import com.qmth.ops.biz.domain.PropertyGroup;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.stereotype.Service;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.List;
- @Service
- public class PropertyGroupService {
- private static final Logger log = LoggerFactory.getLogger(PropertyGroupService.class);
- private static String[] FILE_PATH = { "property/qmth-boot.json", "property/spring.json" };
- private List<PropertyGroup> propertyGroupList = new ArrayList<>();
- public PropertyGroupService() throws IOException {
- loadGroupFile(propertyGroupList, FILE_PATH);
- }
- private void loadGroupFile(List<PropertyGroup> propertyGroupList, String... path) throws IOException {
- ObjectMapper mapper = new ObjectMapper();
- CollectionType collectionType = mapper.getTypeFactory()
- .constructCollectionType(ArrayList.class, PropertyGroup.class);
- for (String filePath : path) {
- List<PropertyGroup> list = mapper
- .readValue(this.getClass().getClassLoader().getResourceAsStream(filePath), collectionType);
- log.info(filePath + " size=" + list.size());
- propertyGroupList.addAll(list);
- }
- }
- public List<PropertyGroup> getPropertyGroupList() {
- return propertyGroupList;
- }
- public boolean accept(String key, String value) {
- for (PropertyGroup group : propertyGroupList) {
- if (group.accept(key, value)) {
- return true;
- }
- }
- return false;
- }
- }
|