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 propertyGroupList = new ArrayList<>(); public PropertyGroupService() throws IOException { loadGroupFile(propertyGroupList, FILE_PATH); } private void loadGroupFile(List propertyGroupList, String... path) throws IOException { ObjectMapper mapper = new ObjectMapper(); CollectionType collectionType = mapper.getTypeFactory() .constructCollectionType(ArrayList.class, PropertyGroup.class); for (String filePath : path) { List list = mapper .readValue(this.getClass().getClassLoader().getResourceAsStream(filePath), collectionType); log.info(filePath + " size=" + list.size()); propertyGroupList.addAll(list); } } public List getPropertyGroupList() { return propertyGroupList; } public boolean accept(String key, String value) { for (PropertyGroup group : propertyGroupList) { if (group.accept(key, value)) { return true; } } return false; } }