PropertyGroupService.java 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package com.qmth.ops.biz.service;
  2. import com.fasterxml.jackson.databind.ObjectMapper;
  3. import com.fasterxml.jackson.databind.type.CollectionType;
  4. import com.qmth.ops.biz.domain.PropertyGroup;
  5. import org.slf4j.Logger;
  6. import org.slf4j.LoggerFactory;
  7. import org.springframework.stereotype.Service;
  8. import java.io.IOException;
  9. import java.util.ArrayList;
  10. import java.util.List;
  11. @Service
  12. public class PropertyGroupService {
  13. private static final Logger log = LoggerFactory.getLogger(PropertyGroupService.class);
  14. private static String[] FILE_PATH = { "property/qmth-boot.json", "property/spring.json" };
  15. private List<PropertyGroup> propertyGroupList = new ArrayList<>();
  16. public PropertyGroupService() throws IOException {
  17. loadGroupFile(propertyGroupList, FILE_PATH);
  18. }
  19. private void loadGroupFile(List<PropertyGroup> propertyGroupList, String... path) throws IOException {
  20. ObjectMapper mapper = new ObjectMapper();
  21. CollectionType collectionType = mapper.getTypeFactory()
  22. .constructCollectionType(ArrayList.class, PropertyGroup.class);
  23. for (String filePath : path) {
  24. List<PropertyGroup> list = mapper
  25. .readValue(this.getClass().getClassLoader().getResourceAsStream(filePath), collectionType);
  26. log.info(filePath + " size=" + list.size());
  27. propertyGroupList.addAll(list);
  28. }
  29. }
  30. public List<PropertyGroup> getPropertyGroupList() {
  31. return propertyGroupList;
  32. }
  33. public boolean accept(String key, String value) {
  34. for (PropertyGroup group : propertyGroupList) {
  35. if (group.accept(key, value)) {
  36. return true;
  37. }
  38. }
  39. return false;
  40. }
  41. }