Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion calm-hub-ui/src/service/calm-service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export async function fetchNamespaces(setNamespaces: (namespaces: string[]) => v
headers,
});
const data = await res.json();
setNamespaces(data.values);
const values = Array.isArray(data?.values) ? data.values : [];
const namespaces = values.map((v: { name?: string }) => v?.name);
setNamespaces(namespaces);
} catch (error) {
console.error('Error fetching namespaces:', error);
}
Expand Down
6 changes: 3 additions & 3 deletions calm-hub/mongo/init-mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -908,9 +908,9 @@ db.schemas.insertMany([ // Insert initial documents into the schem
// Insert namespaces if they don't exist
if (db.namespaces.countDocuments() === 0) {
db.namespaces.insertMany([
{ namespace: "finos" },
{ namespace: "workshop" },
{ namespace: "traderx" }
{ name: "finos", description: "FINOS namespace" },
{ name: "workshop", description: "Workshop namespace" },
{ name: "traderx", description: "TraderX namespace" }
]);
print("Initialized namespaces: finos, workshop, traderx");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ void end_to_end_confirmation_of_namespaces() {
.when().get("/calm/namespaces")
.then()
.statusCode(200)
.body("values", hasItem("finos"));
.body("values.name", hasItem("finos"))
.body("values.description", hasItem("FINOS namespace"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static void namespaceSetup(MongoDatabase database) {
database.createCollection("namespaces");
// Insert multiple documents into 'namespaces'
database.getCollection("namespaces").insertMany(Arrays.asList(
new Document("namespace", "finos")
new Document("name", "finos").append("description", "FINOS namespace")
));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ void end_to_end_get_namespaces_with_valid_access_token(String scope) {
.when().get("/calm/namespaces")
.then()
.statusCode(200)
.body("values", hasItem("finos"));
.body("values.name", hasItem("finos"))
.body("values.description", hasItem("FINOS namespace"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,25 @@

public class NamespaceRequest {
@Pattern(regexp= NAMESPACE_REGEX, message = NAMESPACE_MESSAGE)
@NotNull(message = "Namespace must not be null")
@NotBlank(message = "Namespace must not be blank")
private String namespace;
@NotNull(message = "Name must not be null")
@NotBlank(message = "Name must not be blank")
private String name;

public String getNamespace() {
return namespace;
private String description;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getDescription() {
return description;
}

public void setNamespace(String namespace) {
this.namespace = namespace;
public void setDescription(String description) {
this.description = description;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.finos.calm.domain.namespaces;

import jakarta.json.bind.annotation.JsonbPropertyOrder;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

@JsonbPropertyOrder({"name", "description"})
public class NamespaceInfo {
@NotNull(message = "Name must not be null")
@NotBlank(message = "Name must not be blank")
private final String name;
private final String description;

public NamespaceInfo(String name, String description) {
this.name = name;
this.description = description;
}

public String getName() {
return name;
}

public String getDescription() {
return description;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.finos.calm.domain.NamespaceRequest;
import org.finos.calm.domain.ValueWrapper;
import org.finos.calm.domain.namespaces.NamespaceInfo;
import org.finos.calm.security.CalmHubScopes;
import org.finos.calm.security.PermittedScopes;
import org.finos.calm.store.NamespaceStore;
Expand All @@ -37,7 +38,7 @@ public NamespaceResource(NamespaceStore store) {
)
@PermittedScopes({CalmHubScopes.ARCHITECTURES_ALL,
CalmHubScopes.ARCHITECTURES_READ, CalmHubScopes.ADRS_ALL, CalmHubScopes.ADRS_READ})
public ValueWrapper<String> namespaces() {
public ValueWrapper<NamespaceInfo> namespaces() {
return new ValueWrapper<>(namespaceStore.getNamespaces());
}

Expand All @@ -51,16 +52,17 @@ public ValueWrapper<String> namespaces() {
@PermittedScopes({CalmHubScopes.ARCHITECTURES_ALL})
public Response createNamespace(@Valid @NotNull(message = "Request must not be null") NamespaceRequest request) throws URISyntaxException {

String namespace = request.getNamespace().trim();
String name = request.getName().trim();
String description = request.getDescription();

if (namespaceStore.namespaceExists(namespace)) {
if (namespaceStore.namespaceExists(name)) {
return Response.status(Response.Status.CONFLICT)
.entity("{\"error\":\"Namespace already exists\"}")
.build();
}

namespaceStore.createNamespace(namespace);
return Response.created(new URI("/calm/namespaces/" + namespace)).build();
namespaceStore.createNamespace(name, description);
return Response.created(new URI("/calm/namespaces/" + name)).build();
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.finos.calm.store;

import org.finos.calm.domain.namespaces.NamespaceInfo;

import java.util.List;

public interface NamespaceStore {
List<String> getNamespaces();
boolean namespaceExists(String namespace);
void createNamespace(String namespace);
List<NamespaceInfo> getNamespaces();
boolean namespaceExists(String namespaceName);
void createNamespace(String name, String description);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Typed;
import org.bson.Document;
import org.finos.calm.domain.namespaces.NamespaceInfo;
import org.finos.calm.store.NamespaceStore;

import java.util.ArrayList;
Expand All @@ -21,24 +22,25 @@ public MongoNamespaceStore(MongoDatabase database) {
}

@Override
public List<String> getNamespaces() {
List<String> namespaces = new ArrayList<>();
public List<NamespaceInfo> getNamespaces() {
List<NamespaceInfo> namespaces = new ArrayList<>();
for (Document doc : namespaceCollection.find()) {
namespaces.add(doc.getString("namespace"));
namespaces.add(new NamespaceInfo(doc.getString("name"), doc.getString("description")));
}
return namespaces;
}

@Override
public boolean namespaceExists(String namespace) {
Document query = new Document("namespace", namespace);
public boolean namespaceExists(String namespaceName) {
Document query = new Document("name", namespaceName);
return namespaceCollection.find(query).first() != null;
}

@Override
public void createNamespace(String namespace) {
if (!namespaceExists(namespace)) {
Document namespaceDoc = new Document("namespace", namespace);
public void createNamespace(String name, String description) {
if (!namespaceExists(name)) {
Document namespaceDoc = new Document("name", name)
.append("description", description);
namespaceCollection.insertOne(namespaceDoc);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.dizitart.no2.collection.NitriteCollection;
import org.dizitart.no2.filters.Filter;
import org.finos.calm.config.StandaloneQualifier;
import org.finos.calm.domain.namespaces.NamespaceInfo;
import org.finos.calm.store.NamespaceStore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -27,7 +28,8 @@ public class NitriteNamespaceStore implements NamespaceStore {

private static final Logger LOG = LoggerFactory.getLogger(NitriteNamespaceStore.class);
private static final String COLLECTION_NAME = "namespaces";
private static final String NAMESPACE_FIELD = "namespace";
private static final String NAME_FIELD = "name";
private static final String DESCRIPTION_FIELD = "description";

private final NitriteCollection namespaceCollection;

Expand All @@ -38,33 +40,34 @@ public NitriteNamespaceStore(@StandaloneQualifier Nitrite db) {
}

@Override
public List<String> getNamespaces() {
List<String> namespaces = new ArrayList<>();
public List<NamespaceInfo> getNamespaces() {
List<NamespaceInfo> namespaces = new ArrayList<>();
for (Document doc : namespaceCollection.find()) {
namespaces.add(doc.get(NAMESPACE_FIELD, String.class));
namespaces.add(new NamespaceInfo(doc.get(NAME_FIELD, String.class), doc.get(DESCRIPTION_FIELD, String.class)));
}
LOG.debug("Retrieved {} namespaces from NitriteDB", namespaces.size());
return namespaces;
}

@Override
public boolean namespaceExists(String namespace) {
Filter filter = where(NAMESPACE_FIELD).eq(namespace);
public boolean namespaceExists(String namespaceName) {
Filter filter = where(NAME_FIELD).eq(namespaceName);
Document doc = namespaceCollection.find(filter).firstOrNull();
boolean exists = doc != null;
LOG.debug("Namespace '{}' exists: {}", namespace, exists);
LOG.debug("Namespace '{}' exists: {}", namespaceName, exists);
return exists;
}

@Override
public void createNamespace(String namespace) {
if (!namespaceExists(namespace)) {
public void createNamespace(String name, String description) {
if (!namespaceExists(name)) {
Document namespaceDoc = Document.createDocument()
.put(NAMESPACE_FIELD, namespace);
.put(NAME_FIELD, name)
.put(DESCRIPTION_FIELD, description);
namespaceCollection.insert(namespaceDoc);
LOG.info("Created namespace: {}", namespace);
LOG.info("Created namespace: {}", name);
} else {
LOG.debug("Namespace '{}' already exists, skipping creation", namespace);
LOG.debug("Namespace '{}' already exists, skipping creation", name);
}
}
}
Loading
Loading