Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ void initialize() {
* @throws JsonParseException
*/
private void initializeDatabase() throws IOException, JsonParseException {
boolean scriptExists = false;
String scriptContent = null;

// Create collections - just getting the collection creates it if it doesn't exist
db.getCollection("architectures");
db.getCollection("patterns");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private List<Document> retrieveAdrsDocs(String namespace) throws NamespaceNotFou
throw new AdrNotFoundException();
}

return (List<Document>) result.get("adrs");
return result.getList("adrs", Document.class);
}

private Document retrieveAdrDoc(AdrMeta adrMeta) throws NamespaceNotFoundException, AdrNotFoundException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public Architecture createArchitectureForNamespace(Architecture architecture) th
public List<String> getArchitectureVersions(Architecture architecture) throws NamespaceNotFoundException, ArchitectureNotFoundException {
Document result = retrieveArchitectureVersions(architecture);

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

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

if (result != null) {
List<Document> architectures = (List<Document>) result.get("architectures");
List<Document> architectures = result.getList("architectures", Document.class);
for (Document architectureDoc : architectures) {
Document versions = (Document) architectureDoc.get("versions");
if (versions != null && versions.containsKey(architecture.getMongoVersion())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.finos.calm.store.CoreSchemaStore;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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

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

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public Flow createFlowForNamespace(Flow flow) throws NamespaceNotFoundException
public List<String> getFlowVersions(Flow flow) throws NamespaceNotFoundException, FlowNotFoundException {
Document result = retrieveFlowVersions(flow);

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

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

if (result != null) {
List<Document> flows = (List<Document>) result.get("flows");
List<Document> flows = result.getList("flows", Document.class);
for (Document flowDoc : flows) {
Document versions = (Document) flowDoc.get("versions");
if (versions != null && versions.containsKey(flow.getMongoVersion())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public Pattern createPatternForNamespace(Pattern pattern) throws NamespaceNotFou
public List<String> getPatternVersions(Pattern pattern) throws NamespaceNotFoundException, PatternNotFoundException {
Document result = retrievePatternVersions(pattern);

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

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

if (result != null) {
List<Document> patterns = (List<Document>) result.get("patterns");
List<Document> patterns = result.getList("patterns", Document.class );
for (Document patternDoc : patterns) {
Document versions = (Document) patternDoc.get("versions");
if (versions != null && versions.containsKey(pattern.getMongoVersion())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public Standard createStandardForNamespace(CreateStandardRequest standardRequest
public List<String> getStandardVersions(String namespace, Integer standardId) throws NamespaceNotFoundException, StandardNotFoundException {
Document result = retrieveStandardVersions(namespace);

List<Document> standards = (List<Document>) result.get("standards");
List<Document> standards = result.getList("standards", Document.class);
for (Document standardDoc : standards) {
if (standardId.equals(standardDoc.getInteger("standardId"))) {
// Extract the versions map from the matching standard
Expand Down Expand Up @@ -136,7 +136,7 @@ private Document retrieveStandardVersions(String namespace) throws NamespaceNotF
@Override
public String getStandardForVersion(String namespace, Integer standardId, String version) throws NamespaceNotFoundException, StandardNotFoundException, StandardVersionNotFoundException {
Document result = retrieveStandardVersions(namespace);
List<Document> standards = (List<Document>) result.get("standards");
List<Document> standards = result.getList("standards", Document.class);
for (Document standardDoc : standards) {
if (standardId.equals(standardDoc.getInteger("standardId"))) {
Document versions = (Document) standardDoc.get("versions");
Expand Down Expand Up @@ -192,7 +192,7 @@ private boolean versionExists(String namespace, Integer standardId, String versi
Document result = standardCollection.find(filter).projection(projection).first();

if(result != null) {
List<Document> standards = (List<Document>) result.get("standards");
List<Document> standards = result.getList("standards", Document.class);
for (Document standardDoc : standards) {
Document versions = (Document) standardDoc.get("versions");
if (versions != null && versions.containsKey(version.replace('.', '-'))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.finos.calm.domain.adr.Status;
import org.finos.calm.domain.exception.*;
import org.finos.calm.store.AdrStore;
import org.finos.calm.store.util.TypeSafeNitriteDocument;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

Document namespaceDocument = adrCollection.find(where(NAMESPACE_FIELD).eq(namespace)).firstOrNull();

// Protects from an unpopulated collection
if (namespaceDocument == null) {
return List.of();
}

List<Document> adrs = namespaceDocument.get(ADRS_FIELD, List.class);
TypeSafeNitriteDocument<Document> namespaceDocument = new TypeSafeNitriteDocument<>(adrCollection.find(where(NAMESPACE_FIELD).eq(namespace)).firstOrNull(), Document.class);
List<Document> adrs = namespaceDocument.getList(ADRS_FIELD);
if (adrs == null || adrs.isEmpty()) {
return List.of();
}
Expand Down Expand Up @@ -120,7 +115,8 @@ public AdrMeta createAdrForNamespace(AdrMeta adrMeta) throws NamespaceNotFoundEx
adrCollection.insert(namespaceDoc);
} else {
// Add the ADR to the existing namespace document
List<Document> adrs = namespaceDoc.get(ADRS_FIELD, List.class);
TypeSafeNitriteDocument<Document> tsNamespaceDoc = new TypeSafeNitriteDocument<>(namespaceDoc, Document.class);
List<Document> adrs = tsNamespaceDoc.getList(ADRS_FIELD);
if (adrs == null) {
adrs = new ArrayList<>();
} else {
Expand Down Expand Up @@ -225,14 +221,9 @@ private List<Document> retrieveAdrsDocs(String namespace) throws NamespaceNotFou
}

Filter filter = where(NAMESPACE_FIELD).eq(namespace);
Document result = adrCollection.find(filter).firstOrNull();

if (result == null) {
LOG.warn("No ADRs found for namespace '{}'", namespace);
throw new AdrNotFoundException();
}
TypeSafeNitriteDocument<Document> result = new TypeSafeNitriteDocument<>(adrCollection.find(filter).firstOrNull(), Document.class);

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

if (namespaceDoc != null) {
List<Document> adrs = namespaceDoc.get(ADRS_FIELD, List.class);
List<Document> adrs = new TypeSafeNitriteDocument<>(namespaceDoc, Document.class).getList(ADRS_FIELD);
if (adrs != null) {
// Create a mutable copy of the list
adrs = new ArrayList<>(adrs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.finos.calm.domain.exception.ArchitectureVersionNotFoundException;
import org.finos.calm.domain.exception.NamespaceNotFoundException;
import org.finos.calm.store.ArchitectureStore;
import org.finos.calm.store.util.TypeSafeNitriteDocument;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

Document namespaceDocument = architectureCollection.find(where(NAMESPACE_FIELD).eq(namespace)).firstOrNull();

// Protects from an unpopulated collection
if (namespaceDocument == null) {
return List.of();
}

List<Document> architectures = namespaceDocument.get(ARCHITECTURES_FIELD, List.class);
TypeSafeNitriteDocument<Document> namespaceDocument = new TypeSafeNitriteDocument<>(architectureCollection.find(where(NAMESPACE_FIELD).eq(namespace)).firstOrNull(), Document.class);
List<Document> architectures = namespaceDocument.getList(ARCHITECTURES_FIELD);
if (architectures == null || architectures.isEmpty()) {
return List.of();
}
Expand Down Expand Up @@ -113,7 +108,7 @@ public Architecture createArchitectureForNamespace(Architecture architecture) th
architectureCollection.insert(namespaceDoc);
} else {
// Add the architecture to the existing namespace document
List<Document> architectures = namespaceDoc.get(ARCHITECTURES_FIELD, List.class);
List<Document> architectures = new TypeSafeNitriteDocument<>(namespaceDoc, Document.class).getList(ARCHITECTURES_FIELD);
if (architectures == null) {
architectures = new ArrayList<>();
} else {
Expand All @@ -137,7 +132,7 @@ public Architecture createArchitectureForNamespace(Architecture architecture) th
public List<String> getArchitectureVersions(Architecture architecture) throws NamespaceNotFoundException, ArchitectureNotFoundException {
Document result = retrieveArchitectureVersions(architecture);

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

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

if (namespaceDoc != null) {
// Find the architecture document
List<Document> architectures = namespaceDoc.get(ARCHITECTURES_FIELD, List.class);
List<Document> architectures = new TypeSafeNitriteDocument<>(namespaceDoc, Document.class).getList(ARCHITECTURES_FIELD);
if (architectures != null) {
// Create a mutable copy of the list
architectures = new ArrayList<>(architectures);
Expand Down Expand Up @@ -291,7 +286,7 @@ private boolean versionExists(Architecture architecture) {
try {
Document result = retrieveArchitectureVersions(architecture);

List<Document> architectures = result.get(ARCHITECTURES_FIELD, List.class);
List<Document> architectures = new TypeSafeNitriteDocument<>(result, Document.class).getList(ARCHITECTURES_FIELD);
for (Document architectureDoc : architectures) {
if (architecture.getId() == architectureDoc.get(ARCHITECTURE_ID_FIELD, Integer.class)) {
Document versions = architectureDoc.get(VERSIONS_FIELD, Document.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.dizitart.no2.filters.Filter;
import org.finos.calm.config.StandaloneQualifier;
import org.finos.calm.store.CoreSchemaStore;
import org.finos.calm.store.util.TypeSafeNitriteDocument;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

if (document != null) {
Map<String, Object> schemas = document.get(SCHEMAS_FIELD, Map.class);
Map<String, Object> schemas = document.getMap(SCHEMAS_FIELD);
if (schemas == null) {
LOG.debug("No schemas found for version '{}'", version);
} else {
LOG.debug("Retrieved schemas for version '{}'", version);
return schemas;
}

LOG.debug("No schemas found for version '{}'", version);
return null;
return schemas;
}

@Override
Expand Down
Loading
Loading