Skip to content

Commit 73aadef

Browse files
Merge pull request #1523 from rocketstack-matt/tidy-up
Clean up most of the projects problem warnings
2 parents 2bfd921 + 6cde004 commit 73aadef

33 files changed

+702
-483
lines changed

calm-hub/src/main/java/org/finos/calm/config/NitriteDBConfig.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ void initialize() {
8484
* @throws JsonParseException
8585
*/
8686
private void initializeDatabase() throws IOException, JsonParseException {
87-
boolean scriptExists = false;
88-
String scriptContent = null;
89-
9087
// Create collections - just getting the collection creates it if it doesn't exist
9188
db.getCollection("architectures");
9289
db.getCollection("patterns");

calm-hub/src/main/java/org/finos/calm/store/mongo/MongoAdrStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ private List<Document> retrieveAdrsDocs(String namespace) throws NamespaceNotFou
175175
throw new AdrNotFoundException();
176176
}
177177

178-
return (List<Document>) result.get("adrs");
178+
return result.getList("adrs", Document.class);
179179
}
180180

181181
private Document retrieveAdrDoc(AdrMeta adrMeta) throws NamespaceNotFoundException, AdrNotFoundException {

calm-hub/src/main/java/org/finos/calm/store/mongo/MongoArchitectureStore.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public Architecture createArchitectureForNamespace(Architecture architecture) th
9393
public List<String> getArchitectureVersions(Architecture architecture) throws NamespaceNotFoundException, ArchitectureNotFoundException {
9494
Document result = retrieveArchitectureVersions(architecture);
9595

96-
List<Document> architectures = (List<Document>) result.get("architectures");
96+
List<Document> architectures = result.getList("architectures", Document.class);
9797
for (Document architectureDoc : architectures) {
9898
if (architecture.getId() == architectureDoc.getInteger("architectureId")) {
9999
// Extract the versions map from the matching pattern
@@ -133,7 +133,7 @@ private Document retrieveArchitectureVersions(Architecture architecture) throws
133133
public String getArchitectureForVersion(Architecture architecture) throws NamespaceNotFoundException, ArchitectureNotFoundException, ArchitectureVersionNotFoundException {
134134
Document result = retrieveArchitectureVersions(architecture);
135135

136-
List<Document> architectures = (List<Document>) result.get("architectures");
136+
List<Document> architectures = result.getList("architectures", Document.class);
137137
for (Document architectureDoc : architectures) {
138138
if (architecture.getId() == architectureDoc.getInteger("architectureId")) {
139139
// Retrieve the versions map from the matching pattern
@@ -198,7 +198,7 @@ private boolean versionExists(Architecture architecture) {
198198
Document result = architectureCollection.find(filter).projection(projection).first();
199199

200200
if (result != null) {
201-
List<Document> architectures = (List<Document>) result.get("architectures");
201+
List<Document> architectures = result.getList("architectures", Document.class);
202202
for (Document architectureDoc : architectures) {
203203
Document versions = (Document) architectureDoc.get("versions");
204204
if (versions != null && versions.containsKey(architecture.getMongoVersion())) {

calm-hub/src/main/java/org/finos/calm/store/mongo/MongoCoreSchemaStore.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.finos.calm.store.CoreSchemaStore;
1212

1313
import java.util.ArrayList;
14+
import java.util.HashMap;
1415
import java.util.List;
1516
import java.util.Map;
1617

@@ -40,7 +41,21 @@ public Map<String, Object> getSchemasForVersion(String version) {
4041
Document document = schemaCollection.find(filter).first();
4142

4243
if (document != null) {
43-
return document.get("schemas", Map.class); // Get the 'schemas' field as a map
44+
Map<?, ?> rawMap = document.get("schemas", Map.class);
45+
Map<String, Object> typedMap = new HashMap<>();
46+
if (rawMap != null) {
47+
// Convert entries ensuring keys are Strings. Values can be any Object (schemas themselves
48+
// are typically nested Maps representing JSON Schema documents). Previous implementation
49+
// incorrectly iterated over entrySet and attempted to cast Map.Entry to Map, producing
50+
// an always-empty result. This corrected logic simply copies the mapping.
51+
for (Map.Entry<?, ?> entry : rawMap.entrySet()) {
52+
Object key = entry.getKey();
53+
if (key instanceof String) {
54+
typedMap.put((String) key, entry.getValue());
55+
}
56+
}
57+
}
58+
return typedMap;
4459
}
4560

4661
return null;

calm-hub/src/main/java/org/finos/calm/store/mongo/MongoFlowStore.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public Flow createFlowForNamespace(Flow flow) throws NamespaceNotFoundException
9292
public List<String> getFlowVersions(Flow flow) throws NamespaceNotFoundException, FlowNotFoundException {
9393
Document result = retrieveFlowVersions(flow);
9494

95-
List<Document> flows = (List<Document>) result.get("flows");
95+
List<Document> flows = result.getList("flows", Document.class);
9696
for (Document flowDoc : flows) {
9797
if (flow.getId() == flowDoc.getInteger("flowId")) {
9898
// Extract the versions map from the matching flow
@@ -132,7 +132,7 @@ private Document retrieveFlowVersions(Flow flow) throws NamespaceNotFoundExcepti
132132
public String getFlowForVersion(Flow flow) throws NamespaceNotFoundException, FlowNotFoundException, FlowVersionNotFoundException {
133133
Document result = retrieveFlowVersions(flow);
134134

135-
List<Document> flows = (List<Document>) result.get("flows");
135+
List<Document> flows = result.getList("flows", Document.class);
136136
for (Document flowDoc : flows) {
137137
if (flow.getId() == flowDoc.getInteger("flowId")) {
138138
// Retrieve the versions map from the matching flow
@@ -197,7 +197,7 @@ private boolean versionExists(Flow flow) {
197197
Document result = flowCollection.find(filter).projection(projection).first();
198198

199199
if (result != null) {
200-
List<Document> flows = (List<Document>) result.get("flows");
200+
List<Document> flows = result.getList("flows", Document.class);
201201
for (Document flowDoc : flows) {
202202
Document versions = (Document) flowDoc.get("versions");
203203
if (versions != null && versions.containsKey(flow.getMongoVersion())) {

calm-hub/src/main/java/org/finos/calm/store/mongo/MongoPatternStore.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public Pattern createPatternForNamespace(Pattern pattern) throws NamespaceNotFou
9292
public List<String> getPatternVersions(Pattern pattern) throws NamespaceNotFoundException, PatternNotFoundException {
9393
Document result = retrievePatternVersions(pattern);
9494

95-
List<Document> patterns = (List<Document>) result.get("patterns");
95+
List<Document> patterns = result.getList("patterns", Document.class);
9696
for (Document patternDoc : patterns) {
9797
if (pattern.getId() == patternDoc.getInteger("patternId")) {
9898
// Extract the versions map from the matching pattern
@@ -132,7 +132,7 @@ private Document retrievePatternVersions(Pattern pattern) throws NamespaceNotFou
132132
public String getPatternForVersion(Pattern pattern) throws NamespaceNotFoundException, PatternNotFoundException, PatternVersionNotFoundException {
133133
Document result = retrievePatternVersions(pattern);
134134

135-
List<Document> patterns = (List<Document>) result.get("patterns");
135+
List<Document> patterns = result.getList("patterns", Document.class);
136136
for (Document patternDoc : patterns) {
137137
if (pattern.getId() == patternDoc.getInteger("patternId")) {
138138
// Retrieve the versions map from the matching pattern
@@ -197,7 +197,7 @@ private boolean versionExists(Pattern pattern) {
197197
Document result = patternCollection.find(filter).projection(projection).first();
198198

199199
if (result != null) {
200-
List<Document> patterns = (List<Document>) result.get("patterns");
200+
List<Document> patterns = result.getList("patterns", Document.class );
201201
for (Document patternDoc : patterns) {
202202
Document versions = (Document) patternDoc.get("versions");
203203
if (versions != null && versions.containsKey(pattern.getMongoVersion())) {

calm-hub/src/main/java/org/finos/calm/store/mongo/MongoStandardStore.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public Standard createStandardForNamespace(CreateStandardRequest standardRequest
9494
public List<String> getStandardVersions(String namespace, Integer standardId) throws NamespaceNotFoundException, StandardNotFoundException {
9595
Document result = retrieveStandardVersions(namespace);
9696

97-
List<Document> standards = (List<Document>) result.get("standards");
97+
List<Document> standards = result.getList("standards", Document.class);
9898
for (Document standardDoc : standards) {
9999
if (standardId.equals(standardDoc.getInteger("standardId"))) {
100100
// Extract the versions map from the matching standard
@@ -136,7 +136,7 @@ private Document retrieveStandardVersions(String namespace) throws NamespaceNotF
136136
@Override
137137
public String getStandardForVersion(String namespace, Integer standardId, String version) throws NamespaceNotFoundException, StandardNotFoundException, StandardVersionNotFoundException {
138138
Document result = retrieveStandardVersions(namespace);
139-
List<Document> standards = (List<Document>) result.get("standards");
139+
List<Document> standards = result.getList("standards", Document.class);
140140
for (Document standardDoc : standards) {
141141
if (standardId.equals(standardDoc.getInteger("standardId"))) {
142142
Document versions = (Document) standardDoc.get("versions");
@@ -192,7 +192,7 @@ private boolean versionExists(String namespace, Integer standardId, String versi
192192
Document result = standardCollection.find(filter).projection(projection).first();
193193

194194
if(result != null) {
195-
List<Document> standards = (List<Document>) result.get("standards");
195+
List<Document> standards = result.getList("standards", Document.class);
196196
for (Document standardDoc : standards) {
197197
Document versions = (Document) standardDoc.get("versions");
198198
if (versions != null && versions.containsKey(version.replace('.', '-'))) {

calm-hub/src/main/java/org/finos/calm/store/nitrite/NitriteAdrStore.java

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.finos.calm.domain.adr.Status;
1717
import org.finos.calm.domain.exception.*;
1818
import org.finos.calm.store.AdrStore;
19+
import org.finos.calm.store.util.TypeSafeNitriteDocument;
1920
import org.slf4j.Logger;
2021
import org.slf4j.LoggerFactory;
2122

@@ -62,14 +63,8 @@ public List<Integer> getAdrsForNamespace(String namespace) throws NamespaceNotFo
6263
throw new NamespaceNotFoundException();
6364
}
6465

65-
Document namespaceDocument = adrCollection.find(where(NAMESPACE_FIELD).eq(namespace)).firstOrNull();
66-
67-
// Protects from an unpopulated collection
68-
if (namespaceDocument == null) {
69-
return List.of();
70-
}
71-
72-
List<Document> adrs = namespaceDocument.get(ADRS_FIELD, List.class);
66+
TypeSafeNitriteDocument<Document> namespaceDocument = new TypeSafeNitriteDocument<>(adrCollection.find(where(NAMESPACE_FIELD).eq(namespace)).firstOrNull(), Document.class);
67+
List<Document> adrs = namespaceDocument.getList(ADRS_FIELD);
7368
if (adrs == null || adrs.isEmpty()) {
7469
return List.of();
7570
}
@@ -120,7 +115,8 @@ public AdrMeta createAdrForNamespace(AdrMeta adrMeta) throws NamespaceNotFoundEx
120115
adrCollection.insert(namespaceDoc);
121116
} else {
122117
// Add the ADR to the existing namespace document
123-
List<Document> adrs = namespaceDoc.get(ADRS_FIELD, List.class);
118+
TypeSafeNitriteDocument<Document> tsNamespaceDoc = new TypeSafeNitriteDocument<>(namespaceDoc, Document.class);
119+
List<Document> adrs = tsNamespaceDoc.getList(ADRS_FIELD);
124120
if (adrs == null) {
125121
adrs = new ArrayList<>();
126122
} else {
@@ -225,14 +221,9 @@ private List<Document> retrieveAdrsDocs(String namespace) throws NamespaceNotFou
225221
}
226222

227223
Filter filter = where(NAMESPACE_FIELD).eq(namespace);
228-
Document result = adrCollection.find(filter).firstOrNull();
229-
230-
if (result == null) {
231-
LOG.warn("No ADRs found for namespace '{}'", namespace);
232-
throw new AdrNotFoundException();
233-
}
224+
TypeSafeNitriteDocument<Document> result = new TypeSafeNitriteDocument<>(adrCollection.find(filter).firstOrNull(), Document.class);
234225

235-
List<Document> adrs = result.get(ADRS_FIELD, List.class);
226+
List<Document> adrs = result.getList(ADRS_FIELD);
236227
if (adrs == null || adrs.isEmpty()) {
237228
LOG.warn("Empty ADRs list for namespace '{}'", namespace);
238229
throw new AdrNotFoundException();
@@ -304,7 +295,7 @@ private void writeAdrToNitrite(AdrMeta adrMeta) throws AdrPersistenceException,
304295
Document namespaceDoc = adrCollection.find(filter).firstOrNull();
305296

306297
if (namespaceDoc != null) {
307-
List<Document> adrs = namespaceDoc.get(ADRS_FIELD, List.class);
298+
List<Document> adrs = new TypeSafeNitriteDocument<>(namespaceDoc, Document.class).getList(ADRS_FIELD);
308299
if (adrs != null) {
309300
// Create a mutable copy of the list
310301
adrs = new ArrayList<>(adrs);

calm-hub/src/main/java/org/finos/calm/store/nitrite/NitriteArchitectureStore.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.finos.calm.domain.exception.ArchitectureVersionNotFoundException;
1616
import org.finos.calm.domain.exception.NamespaceNotFoundException;
1717
import org.finos.calm.store.ArchitectureStore;
18+
import org.finos.calm.store.util.TypeSafeNitriteDocument;
1819
import org.slf4j.Logger;
1920
import org.slf4j.LoggerFactory;
2021

@@ -58,14 +59,8 @@ public List<Integer> getArchitecturesForNamespace(String namespace) throws Names
5859
throw new NamespaceNotFoundException();
5960
}
6061

61-
Document namespaceDocument = architectureCollection.find(where(NAMESPACE_FIELD).eq(namespace)).firstOrNull();
62-
63-
// Protects from an unpopulated collection
64-
if (namespaceDocument == null) {
65-
return List.of();
66-
}
67-
68-
List<Document> architectures = namespaceDocument.get(ARCHITECTURES_FIELD, List.class);
62+
TypeSafeNitriteDocument<Document> namespaceDocument = new TypeSafeNitriteDocument<>(architectureCollection.find(where(NAMESPACE_FIELD).eq(namespace)).firstOrNull(), Document.class);
63+
List<Document> architectures = namespaceDocument.getList(ARCHITECTURES_FIELD);
6964
if (architectures == null || architectures.isEmpty()) {
7065
return List.of();
7166
}
@@ -113,7 +108,7 @@ public Architecture createArchitectureForNamespace(Architecture architecture) th
113108
architectureCollection.insert(namespaceDoc);
114109
} else {
115110
// Add the architecture to the existing namespace document
116-
List<Document> architectures = namespaceDoc.get(ARCHITECTURES_FIELD, List.class);
111+
List<Document> architectures = new TypeSafeNitriteDocument<>(namespaceDoc, Document.class).getList(ARCHITECTURES_FIELD);
117112
if (architectures == null) {
118113
architectures = new ArrayList<>();
119114
} else {
@@ -137,7 +132,7 @@ public Architecture createArchitectureForNamespace(Architecture architecture) th
137132
public List<String> getArchitectureVersions(Architecture architecture) throws NamespaceNotFoundException, ArchitectureNotFoundException {
138133
Document result = retrieveArchitectureVersions(architecture);
139134

140-
List<Document> architectures = result.get(ARCHITECTURES_FIELD, List.class);
135+
List<Document> architectures = new TypeSafeNitriteDocument<>(result, Document.class).getList(ARCHITECTURES_FIELD);
141136
for (Document architectureDoc : architectures) {
142137
if (architecture.getId() == architectureDoc.get(ARCHITECTURE_ID_FIELD, Integer.class)) {
143138
// Extract the versions map from the matching architecture
@@ -180,7 +175,7 @@ private Document retrieveArchitectureVersions(Architecture architecture) throws
180175
public String getArchitectureForVersion(Architecture architecture) throws NamespaceNotFoundException, ArchitectureNotFoundException, ArchitectureVersionNotFoundException {
181176
Document result = retrieveArchitectureVersions(architecture);
182177

183-
List<Document> architectures = result.get(ARCHITECTURES_FIELD, List.class);
178+
List<Document> architectures = new TypeSafeNitriteDocument<>(result, Document.class).getList(ARCHITECTURES_FIELD);
184179
for (Document architectureDoc : architectures) {
185180
if (architecture.getId() == architectureDoc.get(ARCHITECTURE_ID_FIELD, Integer.class)) {
186181
// Retrieve the versions map from the matching architecture
@@ -250,7 +245,7 @@ private void writeArchitectureToNitrite(Architecture architecture) throws Archit
250245

251246
if (namespaceDoc != null) {
252247
// Find the architecture document
253-
List<Document> architectures = namespaceDoc.get(ARCHITECTURES_FIELD, List.class);
248+
List<Document> architectures = new TypeSafeNitriteDocument<>(namespaceDoc, Document.class).getList(ARCHITECTURES_FIELD);
254249
if (architectures != null) {
255250
// Create a mutable copy of the list
256251
architectures = new ArrayList<>(architectures);
@@ -291,7 +286,7 @@ private boolean versionExists(Architecture architecture) {
291286
try {
292287
Document result = retrieveArchitectureVersions(architecture);
293288

294-
List<Document> architectures = result.get(ARCHITECTURES_FIELD, List.class);
289+
List<Document> architectures = new TypeSafeNitriteDocument<>(result, Document.class).getList(ARCHITECTURES_FIELD);
295290
for (Document architectureDoc : architectures) {
296291
if (architecture.getId() == architectureDoc.get(ARCHITECTURE_ID_FIELD, Integer.class)) {
297292
Document versions = architectureDoc.get(VERSIONS_FIELD, Document.class);

calm-hub/src/main/java/org/finos/calm/store/nitrite/NitriteCoreSchemaStore.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.dizitart.no2.filters.Filter;
1010
import org.finos.calm.config.StandaloneQualifier;
1111
import org.finos.calm.store.CoreSchemaStore;
12+
import org.finos.calm.store.util.TypeSafeNitriteDocument;
1213
import org.slf4j.Logger;
1314
import org.slf4j.LoggerFactory;
1415

@@ -57,16 +58,15 @@ public List<String> getVersions() {
5758
@Override
5859
public Map<String, Object> getSchemasForVersion(String version) {
5960
Filter filter = where(VERSION_FIELD).eq(version);
60-
Document document = schemaCollection.find(filter).firstOrNull();
61+
TypeSafeNitriteDocument<Object> document = new TypeSafeNitriteDocument<>(schemaCollection.find(filter).firstOrNull(), Object.class);
6162

62-
if (document != null) {
63-
Map<String, Object> schemas = document.get(SCHEMAS_FIELD, Map.class);
63+
Map<String, Object> schemas = document.getMap(SCHEMAS_FIELD);
64+
if (schemas == null) {
65+
LOG.debug("No schemas found for version '{}'", version);
66+
} else {
6467
LOG.debug("Retrieved schemas for version '{}'", version);
65-
return schemas;
6668
}
67-
68-
LOG.debug("No schemas found for version '{}'", version);
69-
return null;
69+
return schemas;
7070
}
7171

7272
@Override

0 commit comments

Comments
 (0)