|
2 | 2 |
|
3 | 3 | import java.io.File;
|
4 | 4 | import java.io.IOException;
|
5 |
| -import java.nio.charset.StandardCharsets; |
6 | 5 | import java.util.Date;
|
7 | 6 | import java.util.List;
|
8 | 7 | import java.util.ListIterator;
|
|
20 | 19 | import com.genexus.common.interfaces.SpecificImplementation;
|
21 | 20 | import com.genexus.util.GXDirectory;
|
22 | 21 | import com.genexus.util.GXFileCollection;
|
| 22 | +import org.springframework.core.io.ClassPathResource; |
| 23 | +import org.springframework.core.io.FileSystemResource; |
23 | 24 | import org.springframework.core.io.Resource;
|
24 | 25 | import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
25 | 26 |
|
@@ -53,76 +54,65 @@ private void loadQueryTables()
|
53 | 54 | {
|
54 | 55 | String path = SpecificImplementation.Application.getModelContext().getHttpContext().getDefaultPath();
|
55 | 56 | String configurationDirectoryPath = path + File.separatorChar + "Metadata" + File.separatorChar + "TableAccess";
|
56 |
| - |
57 |
| - ConcurrentHashMap<String, Vector<String>> qTables = new ConcurrentHashMap(); |
58 |
| - loadQueryTablesPlatform(configurationDirectoryPath, qTables); |
| 57 | + ConcurrentHashMap<String, Vector<String>> qTables = new ConcurrentHashMap<String, Vector<String>>(); |
| 58 | + if (ApplicationContext.getInstance().isSpringBootApp()) |
| 59 | + loadQueryTablesSpringBoot(configurationDirectoryPath, qTables); |
| 60 | + else |
| 61 | + loadQueryTablesFileSystem(configurationDirectoryPath, qTables); |
59 | 62 | startupDate = CommonUtil.now(false,false);
|
60 | 63 | queryTables = qTables;
|
61 | 64 | }
|
62 | 65 | }
|
63 | 66 |
|
64 |
| - public void loadQueryTablesPlatform(String configurationDirectoryPath, ConcurrentHashMap<String, Vector<String>> qTables) { |
65 |
| - if (ApplicationContext.getInstance().isSpringBootApp()) |
66 |
| - loadQueryTablesSpringBoot(configurationDirectoryPath, qTables); |
67 |
| - else |
68 |
| - loadQueryTablesNone(configurationDirectoryPath, qTables); |
69 |
| - |
70 |
| - } |
71 |
| - |
72 |
| - public void loadQueryTablesNone(String configurationDirectoryPath, ConcurrentHashMap<String, Vector<String>> qTables) { |
| 67 | + private void loadQueryTablesFileSystem(String configurationDirectoryPath, ConcurrentHashMap<String, Vector<String>> qTables){ |
73 | 68 | GXDirectory configurationDirectory = new GXDirectory(configurationDirectoryPath);
|
74 | 69 | GXFileCollection files = configurationDirectory.getFiles();
|
75 | 70 | XMLReader reader = new XMLReader();
|
76 |
| - short ok; |
77 |
| - boolean anyTable=false; |
78 |
| - for(int i=1; i <= files.getItemCount(); i++) { |
79 |
| - Vector<String> lst = new Vector<String>(); |
80 |
| - lst.add(FORCED_INVALIDATE); // Caso en que se invalido el cache manualmente |
| 71 | + boolean anyTables=false; |
| 72 | + for(int i=1; i <= files.getItemCount(); i++) |
| 73 | + { |
81 | 74 | AbstractGXFile xmlFile = files.item(i);
|
82 |
| - reader.open(xmlFile.getAbsoluteName()); |
83 |
| - ok = reader.readType(1, "Table"); |
84 |
| - while (ok == 1) { |
85 |
| - anyTable=true; |
86 |
| - lst.add(normalizeKey(reader.getAttributeByName("name"))); |
87 |
| - ok = reader.readType(1, "Table"); |
88 |
| - } |
89 |
| - reader.close(); |
90 |
| - if (anyTable) { |
91 |
| - qTables.put(normalizeKey(xmlFile.getNameNoExt()), lst); |
92 |
| - } |
| 75 | + String xmlFileName = xmlFile.getAbsoluteName(); |
| 76 | + String xmlFileNameNoExt = xmlFile.getNameNoExt(); |
| 77 | + anyTables = processXMLFile(reader, anyTables, xmlFileName, xmlFileNameNoExt, qTables); |
93 | 78 | }
|
94 | 79 | }
|
95 | 80 |
|
96 |
| - public void loadQueryTablesSpringBoot(String configurationDirectoryPath, ConcurrentHashMap<String, Vector<String>> qTables) { |
| 81 | + private void loadQueryTablesSpringBoot(String configurationDirectoryPath, ConcurrentHashMap<String, Vector<String>> qTables){ |
| 82 | + PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); |
97 | 83 | try {
|
98 |
| - Resource[] resources = new PathMatchingResourcePatternResolver().getResources(configurationDirectoryPath + "/*.xml"); |
| 84 | + Resource[] resources = resolver.getResources("classpath:" + configurationDirectoryPath + "/*"); |
99 | 85 | XMLReader reader = new XMLReader();
|
100 |
| - reader.setDocEncoding("UTF8"); |
101 |
| - short ok; |
102 |
| - boolean anyTable=false; |
103 |
| - String xmlContent; |
104 |
| - for (int i = 0; i < resources.length; i++) { |
105 |
| - Vector<String> lst = new Vector<String>(); |
106 |
| - lst.add(FORCED_INVALIDATE); |
107 |
| - xmlContent = resources[i].getContentAsString(StandardCharsets.UTF_8); |
108 |
| - if (!xmlContent.startsWith("<")) |
109 |
| - xmlContent = xmlContent.substring(1); //Avoid BOM |
110 |
| - reader.openFromString(xmlContent); |
111 |
| - ok = reader.readType(1, "Table"); |
112 |
| - while (ok == 1) { |
113 |
| - anyTable=true; |
114 |
| - lst.add(normalizeKey(reader.getAttributeByName("name"))); |
115 |
| - ok = reader.readType(1, "Table"); |
116 |
| - } |
117 |
| - reader.close(); |
118 |
| - if (anyTable) { |
119 |
| - qTables.put(normalizeKey(resources[i].getFilename().substring(0, resources[i].getFilename().lastIndexOf("."))), lst); |
120 |
| - } |
| 86 | + boolean anyTables=false; |
| 87 | + for (Resource resource : resources) { |
| 88 | + String xmlFileName = resource.getFilename(); |
| 89 | + String xmlFileNameNoExt = xmlFileName.substring(0, xmlFileName.lastIndexOf('.')); |
| 90 | + xmlFileName = resource instanceof FileSystemResource? ((FileSystemResource) resource).getPath() : ((ClassPathResource) resource).getPath(); |
| 91 | + anyTables = processXMLFile(reader, anyTables, xmlFileName, xmlFileNameNoExt, qTables); |
121 | 92 | }
|
122 | 93 | }
|
123 |
| - catch (IOException e) { |
124 |
| - logger.error("Error reading Table Access metadata", e); |
| 94 | + catch (IOException e){ |
| 95 | + logger.error("Error loading Query Tables ", e); |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + private boolean processXMLFile(XMLReader reader, boolean anyTables, String xmlFileName, String xmlFileNameNoExt, ConcurrentHashMap<String, Vector<String>> qTables) { |
| 100 | + Vector<String> lst = new Vector<>(); |
| 101 | + lst.add(FORCED_INVALIDATE); // Caso en que se invalido el cache manualmente |
| 102 | + reader.open(xmlFileName); |
| 103 | + short ok = reader.readType(1, "Table"); |
| 104 | + boolean anyLocalTables = false; |
| 105 | + while (ok == 1) |
| 106 | + { |
| 107 | + anyLocalTables = true; |
| 108 | + lst.add(normalizeKey(reader.getAttributeByName("name"))); |
| 109 | + ok = reader.readType(1, "Table"); |
| 110 | + } |
| 111 | + reader.close(); |
| 112 | + if (anyTables || anyLocalTables) { |
| 113 | + qTables.put(normalizeKey(xmlFileNameNoExt), lst); |
125 | 114 | }
|
| 115 | + return anyTables || anyLocalTables; |
126 | 116 | }
|
127 | 117 |
|
128 | 118 | public ConcurrentHashMap<String, Vector<String>> queryTables() {
|
|
0 commit comments