diff --git a/backend/src/main/java/org/rdfarchitect/database/GraphIdentifier.java b/backend/src/main/java/org/rdfarchitect/database/GraphIdentifier.java index 29ba5849..729664c5 100644 --- a/backend/src/main/java/org/rdfarchitect/database/GraphIdentifier.java +++ b/backend/src/main/java/org/rdfarchitect/database/GraphIdentifier.java @@ -17,12 +17,4 @@ package org.rdfarchitect.database; -import lombok.Data; - -@Data -public class GraphIdentifier { - - private final String datasetName; - - private final String graphUri; -} +public record GraphIdentifier(String datasetName, String graphUri) {} diff --git a/backend/src/main/java/org/rdfarchitect/database/inmemory/InMemoryDatabaseAdapter.java b/backend/src/main/java/org/rdfarchitect/database/inmemory/InMemoryDatabaseAdapter.java index 7e67b432..7f19fe92 100644 --- a/backend/src/main/java/org/rdfarchitect/database/inmemory/InMemoryDatabaseAdapter.java +++ b/backend/src/main/java/org/rdfarchitect/database/inmemory/InMemoryDatabaseAdapter.java @@ -60,14 +60,14 @@ public void createGraph(GraphIdentifier graphIdentifier, Graph graph) { database.create(graphIdentifier, graph); var currentPrefixMapping = new PrefixMappingImpl() - .setNsPrefixes(database.getPrefixMapping(graphIdentifier.getDatasetName())) + .setNsPrefixes(database.getPrefixMapping(graphIdentifier.datasetName())) .setNsPrefixes(graph.getPrefixMapping()); - database.setPrefixMapping(graphIdentifier.getDatasetName(), currentPrefixMapping); + database.setPrefixMapping(graphIdentifier.datasetName(), currentPrefixMapping); } @Override public void createEmptyGraph(GraphIdentifier graphIdentifier) { - var datasetName = graphIdentifier.getDatasetName(); + var datasetName = graphIdentifier.datasetName(); var isNewDataset = !database.listDatasets().contains(datasetName); database.create(graphIdentifier, GraphFactory.createDefaultGraph()); if (isNewDataset) { @@ -77,7 +77,7 @@ public void createEmptyGraph(GraphIdentifier graphIdentifier) { .setNsPrefixes(PrefixMapping.Standard) .setNsPrefix(CIM_PREFIX, CIM.namespace) .setNsPrefix(CIMS_PREFIX, CIMS.namespace); - database.setPrefixMapping(graphIdentifier.getDatasetName(), prefixMapping); + database.setPrefixMapping(graphIdentifier.datasetName(), prefixMapping); } } diff --git a/backend/src/main/java/org/rdfarchitect/database/inmemory/SessionDataStoreImpl.java b/backend/src/main/java/org/rdfarchitect/database/inmemory/SessionDataStoreImpl.java index 34dd1707..fda29603 100644 --- a/backend/src/main/java/org/rdfarchitect/database/inmemory/SessionDataStoreImpl.java +++ b/backend/src/main/java/org/rdfarchitect/database/inmemory/SessionDataStoreImpl.java @@ -91,8 +91,8 @@ public List listDatasets() { @Override public GraphRewindableWithUUIDs begin(GraphIdentifier graphIdentifier, TxnType txnType) { - final String datasetName = graphIdentifier.getDatasetName(); - final String graphUri = graphIdentifier.getGraphUri(); + final String datasetName = graphIdentifier.datasetName(); + final String graphUri = graphIdentifier.graphUri(); lock.lock(); try { createDataset(datasetName); @@ -106,10 +106,10 @@ public GraphRewindableWithUUIDs begin(GraphIdentifier graphIdentifier, TxnType t public GraphWithContext getGraphWithContext(GraphIdentifier graphIdentifier) { lock.lock(); try { - createDataset(graphIdentifier.getDatasetName()); + createDataset(graphIdentifier.datasetName()); return graphCollections - .get(graphIdentifier.getDatasetName()) - .getGraphWithContext(graphIdentifier.getGraphUri()); + .get(graphIdentifier.datasetName()) + .getGraphWithContext(graphIdentifier.graphUri()); } finally { lock.unlock(); } @@ -119,10 +119,10 @@ public GraphWithContext getGraphWithContext(GraphIdentifier graphIdentifier) { public void create(GraphIdentifier graphIdentifier, Graph newGraph) { lock.lock(); try { - createDataset(graphIdentifier.getDatasetName()); + createDataset(graphIdentifier.datasetName()); graphCollections - .get(graphIdentifier.getDatasetName()) - .create(graphIdentifier.getGraphUri(), newGraph); + .get(graphIdentifier.datasetName()) + .create(graphIdentifier.graphUri(), newGraph); } finally { lock.unlock(); } @@ -130,8 +130,8 @@ public void create(GraphIdentifier graphIdentifier, Graph newGraph) { @Override public void remove(GraphIdentifier graphIdentifier) { - final String datasetName = graphIdentifier.getDatasetName(); - final String graphUri = graphIdentifier.getGraphUri(); + final String datasetName = graphIdentifier.datasetName(); + final String graphUri = graphIdentifier.graphUri(); lock.lock(); try { if (!graphCollections.containsKey(datasetName)) { @@ -148,8 +148,8 @@ public void remove(GraphIdentifier graphIdentifier) { @Override public boolean containsGraph(GraphIdentifier graphIdentifier) { - final String datasetName = graphIdentifier.getDatasetName(); - final String graphUri = graphIdentifier.getGraphUri(); + final String datasetName = graphIdentifier.datasetName(); + final String graphUri = graphIdentifier.graphUri(); lock.lock(); try { return graphCollections.containsKey(datasetName) @@ -197,8 +197,8 @@ public void setPrefixMapping(String datasetName, PrefixMapping newPrefixes) { @Override public void writeToDatabase( DatabaseConnection databaseConnection, GraphIdentifier graphIdentifier) { - final String datasetName = graphIdentifier.getDatasetName(); - final String graphUri = graphIdentifier.getGraphUri(); + final String datasetName = graphIdentifier.datasetName(); + final String graphUri = graphIdentifier.graphUri(); lock.lock(); GraphRewindableWithUUIDs graph = null; try { @@ -327,8 +327,8 @@ private Graph fetchGraph( @Override public void undo(GraphIdentifier graphIdentifier) { - final String datasetName = graphIdentifier.getDatasetName(); - final String graphUri = graphIdentifier.getGraphUri(); + final String datasetName = graphIdentifier.datasetName(); + final String graphUri = graphIdentifier.graphUri(); lock.lock(); try { assertThatDatasetExists(datasetName); @@ -340,8 +340,8 @@ public void undo(GraphIdentifier graphIdentifier) { @Override public void redo(GraphIdentifier graphIdentifier) { - final String datasetName = graphIdentifier.getDatasetName(); - final String graphUri = graphIdentifier.getGraphUri(); + final String datasetName = graphIdentifier.datasetName(); + final String graphUri = graphIdentifier.graphUri(); lock.lock(); try { assertThatDatasetExists(datasetName); @@ -353,8 +353,8 @@ public void redo(GraphIdentifier graphIdentifier) { @Override public boolean canUndo(GraphIdentifier graphIdentifier) { - final String datasetName = graphIdentifier.getDatasetName(); - final String graphUri = graphIdentifier.getGraphUri(); + final String datasetName = graphIdentifier.datasetName(); + final String graphUri = graphIdentifier.graphUri(); lock.lock(); try { assertThatDatasetExists(datasetName); @@ -366,8 +366,8 @@ public boolean canUndo(GraphIdentifier graphIdentifier) { @Override public boolean canRedo(GraphIdentifier graphIdentifier) { - final String datasetName = graphIdentifier.getDatasetName(); - final String graphUri = graphIdentifier.getGraphUri(); + final String datasetName = graphIdentifier.datasetName(); + final String graphUri = graphIdentifier.graphUri(); lock.lock(); try { assertThatDatasetExists(datasetName); @@ -379,8 +379,8 @@ public boolean canRedo(GraphIdentifier graphIdentifier) { @Override public void restore(GraphIdentifier graphIdentifier, UUID versionId) { - final String datasetName = graphIdentifier.getDatasetName(); - final String graphUri = graphIdentifier.getGraphUri(); + final String datasetName = graphIdentifier.datasetName(); + final String graphUri = graphIdentifier.graphUri(); lock.lock(); try { assertThatGraphExists(graphIdentifier); @@ -443,8 +443,8 @@ private void assertThatDatasetExists(String datasetName) { * @throws DataAccessException if the dataset or graph does not exist. */ private void assertThatGraphExists(GraphIdentifier graphIdentifier) { - final String datasetName = graphIdentifier.getDatasetName(); - final String graphUri = graphIdentifier.getGraphUri(); + final String datasetName = graphIdentifier.datasetName(); + final String graphUri = graphIdentifier.graphUri(); assertThatDatasetExists(datasetName); if (!graphCollections.get(datasetName).containsGraph(graphUri)) { throw new DataAccessException( diff --git a/backend/src/main/java/org/rdfarchitect/database/snapshots/FusekiSnapshotAdapter.java b/backend/src/main/java/org/rdfarchitect/database/snapshots/FusekiSnapshotAdapter.java index 4fa4fd1b..0400755e 100644 --- a/backend/src/main/java/org/rdfarchitect/database/snapshots/FusekiSnapshotAdapter.java +++ b/backend/src/main/java/org/rdfarchitect/database/snapshots/FusekiSnapshotAdapter.java @@ -110,11 +110,11 @@ private void transferGraph(RDFConnection conn, GraphIdentifier graphIdentifier) var copiedGraph = GraphUtils.deepCopy(graph); copiedGraph .getPrefixMapping() - .setNsPrefixes(databasePort.getPrefixMapping(graphIdentifier.getDatasetName())); + .setNsPrefixes(databasePort.getPrefixMapping(graphIdentifier.datasetName())); removeUUIDs(copiedGraph); - conn.put(graphIdentifier.getGraphUri(), ModelFactory.createModelForGraph(copiedGraph)); + conn.put(graphIdentifier.graphUri(), ModelFactory.createModelForGraph(copiedGraph)); } catch (Exception e) { throw new FusekiServerException(e.getMessage()); } finally { diff --git a/backend/src/main/java/org/rdfarchitect/models/cim/data/CIMObjectFactory.java b/backend/src/main/java/org/rdfarchitect/models/cim/data/CIMObjectFactory.java index be4c1388..2cfe22db 100644 --- a/backend/src/main/java/org/rdfarchitect/models/cim/data/CIMObjectFactory.java +++ b/backend/src/main/java/org/rdfarchitect/models/cim/data/CIMObjectFactory.java @@ -158,7 +158,7 @@ public static CIMAssociation createInverseCIMAssociation( QuerySolution associationQuerySolution) { var parser = new CIMQuerySolutionParser(associationQuerySolution); return CIMAssociation.builder() - .uuid(parser.getUUID(CIMQueryVars.UUID)) + .uuid(parser.getUUID(CIMQueryVars.Inverse.UUID)) .uri(parser.getURI(CIMQueryVars.INVERSE_ROLE_NAME)) .label(parser.getLabel(CIMQueryVars.Inverse.LABEL)) .multiplicity(parser.getMultiplicity(CIMQueryVars.Inverse.MULTIPLICITY)) diff --git a/backend/src/main/java/org/rdfarchitect/models/cim/queries/select/CIMQueries.java b/backend/src/main/java/org/rdfarchitect/models/cim/queries/select/CIMQueries.java index 9a5842fd..379c2c1a 100644 --- a/backend/src/main/java/org/rdfarchitect/models/cim/queries/select/CIMQueries.java +++ b/backend/src/main/java/org/rdfarchitect/models/cim/queries/select/CIMQueries.java @@ -127,6 +127,7 @@ public SelectBuilder getAssociationPairsQuery( .appendDomainQuery(REQUIRED) .appendCommentQuery(OPTIONAL) // inverse + .appendInverseUuidQuery(REQUIRED) .appendInverseLabelQuery(REQUIRED) .appendInverseMultiplicityQuery(REQUIRED) .appendInverseAssociationUsedQuery(REQUIRED) diff --git a/backend/src/main/java/org/rdfarchitect/models/cim/queries/select/CIMQueryBuilder.java b/backend/src/main/java/org/rdfarchitect/models/cim/queries/select/CIMQueryBuilder.java index f65ae50d..6353e77c 100644 --- a/backend/src/main/java/org/rdfarchitect/models/cim/queries/select/CIMQueryBuilder.java +++ b/backend/src/main/java/org/rdfarchitect/models/cim/queries/select/CIMQueryBuilder.java @@ -334,6 +334,17 @@ public CIMQueryBuilder appendPackageQuery(Mode mode) { // inverse + /** + * Appends query for the uuid of objects connected via "cims:inverseRoleName" as {@link + * CIMQueryVars Inverse.UUID}. + * + * @param mode Whether the result of this is mode. + * @return {@link CIMQueryBuilder this} + */ + public CIMQueryBuilder appendInverseUuidQuery(Mode mode) { + return appendInverseSingleQuery(RDFA.uuid, CIMQueryVars.Inverse.UUID, mode); + } + /** * Appends query for the label of objects connected via "cims:inverseRoleName" as {@link * CIMQueryVars Inverse.LABEL}. diff --git a/backend/src/main/java/org/rdfarchitect/models/search/SearchResultObjectFactory.java b/backend/src/main/java/org/rdfarchitect/models/search/SearchResultObjectFactory.java index 3859ec17..ea61b7be 100644 --- a/backend/src/main/java/org/rdfarchitect/models/search/SearchResultObjectFactory.java +++ b/backend/src/main/java/org/rdfarchitect/models/search/SearchResultObjectFactory.java @@ -131,8 +131,8 @@ public static SearchResult createSearchResult( } return SearchResult.builder() - .datasetName(graphIdentifier.getDatasetName()) - .graphUri(graphIdentifier.getGraphUri()) + .datasetName(graphIdentifier.datasetName()) + .graphUri(graphIdentifier.graphUri()) .uri(parser.getURI(CIMQueryVars.URI)) .uuid(parser.getUUID(CIMQueryVars.UUID)) .label(parser.getLabel(CIMQueryVars.LABEL)) diff --git a/backend/src/main/java/org/rdfarchitect/services/ChangeLogService.java b/backend/src/main/java/org/rdfarchitect/services/ChangeLogService.java index f23a2e20..c40136cb 100644 --- a/backend/src/main/java/org/rdfarchitect/services/ChangeLogService.java +++ b/backend/src/main/java/org/rdfarchitect/services/ChangeLogService.java @@ -45,8 +45,8 @@ public class ChangeLogService implements ChangeLogUseCase { private GraphChangeLog getChangeLog(GraphIdentifier graphIdentifier) { return changeLogs .getOrDefault(SessionContext.getSessionId(), Collections.emptyMap()) - .getOrDefault(graphIdentifier.getDatasetName(), Collections.emptyMap()) - .getOrDefault(graphIdentifier.getGraphUri(), new GraphChangeLog()); + .getOrDefault(graphIdentifier.datasetName(), Collections.emptyMap()) + .getOrDefault(graphIdentifier.graphUri(), new GraphChangeLog()); } @Override @@ -56,8 +56,8 @@ public void recordChange(GraphIdentifier graphIdentifier, ChangeLogEntry entry) .computeIfAbsent( SessionContext.getSessionId(), _ -> new ConcurrentHashMap<>()) .computeIfAbsent( - graphIdentifier.getDatasetName(), _ -> new ConcurrentHashMap<>()) - .computeIfAbsent(graphIdentifier.getGraphUri(), _ -> new GraphChangeLog()); + graphIdentifier.datasetName(), _ -> new ConcurrentHashMap<>()) + .computeIfAbsent(graphIdentifier.graphUri(), _ -> new GraphChangeLog()); graphChangeLog.addEntry(entry); } diff --git a/backend/src/main/java/org/rdfarchitect/services/GraphToCIMCollectionConverterService.java b/backend/src/main/java/org/rdfarchitect/services/GraphToCIMCollectionConverterService.java index 8bc23d44..0e95f947 100644 --- a/backend/src/main/java/org/rdfarchitect/services/GraphToCIMCollectionConverterService.java +++ b/backend/src/main/java/org/rdfarchitect/services/GraphToCIMCollectionConverterService.java @@ -85,10 +85,10 @@ public CIMCollection convert(GraphIdentifier graphIdentifier, GraphFilter filter private CIMBaseQueryBuilder buildBaseQuery(GraphIdentifier graphIdentifier) { return new CIMBaseQueryBuilder() - .setGraph(graphIdentifier.getGraphUri()) + .setGraph(graphIdentifier.graphUri()) .setDistinct() .setOrder() - .addPrefixes(databasePort.getPrefixMapping(graphIdentifier.getDatasetName())); + .addPrefixes(databasePort.getPrefixMapping(graphIdentifier.datasetName())); } private void fetchAllPackages( @@ -109,7 +109,7 @@ private void fetchInternalPackages( .build(); // execute query - var dataset = SessionDataStore.wrapGraphInDataset(graph, graphIdentifier.getGraphUri()); + var dataset = SessionDataStore.wrapGraphInDataset(graph, graphIdentifier.graphUri()); try (var qexec = QueryExecutionFactory.create(internalPackagesQuery, dataset)) { var resultset = qexec.execSelect(); while (resultset.hasNext()) { @@ -141,7 +141,7 @@ private void fetchExternalPackages( .build(); // execute query - var dataset = SessionDataStore.wrapGraphInDataset(graph, graphIdentifier.getGraphUri()); + var dataset = SessionDataStore.wrapGraphInDataset(graph, graphIdentifier.graphUri()); try (var qexec = QueryExecutionFactory.create(externalPackagesQuery, dataset)) { var resultset = qexec.execSelect(); while (resultset.hasNext()) { @@ -247,8 +247,8 @@ private void fetchClasses( var classList = new CIMObjectFetcher( graph, - graphIdentifier.getGraphUri(), - databasePort.getPrefixMapping(graphIdentifier.getDatasetName())) + graphIdentifier.graphUri(), + databasePort.getPrefixMapping(graphIdentifier.datasetName())) .fetchCIMClassList(query.build()); var classUUIDList = new ArrayList(); classList.forEach( @@ -272,8 +272,8 @@ private void fetchClassesInPackage( // classQuery var classesInPackageQueryBuilder = CIMQueries.getClassQuery( - databasePort.getPrefixMapping(graphIdentifier.getDatasetName()), - graphIdentifier.getGraphUri(), + databasePort.getPrefixMapping(graphIdentifier.datasetName()), + graphIdentifier.graphUri(), null); appendPackageConstraint(filter, classesInPackageQueryBuilder, CIMQueryVars.URI, true); fetchClasses(graph, graphIdentifier, filter, cimCollection, classesInPackageQueryBuilder); @@ -292,8 +292,8 @@ private void fetchExternalAssociatedClasses( var associationUri = "?associationUri"; var associatedClassesQueryBuilder = CIMQueries.getClassQuery( - databasePort.getPrefixMapping(graphIdentifier.getDatasetName()), - graphIdentifier.getGraphUri(), + databasePort.getPrefixMapping(graphIdentifier.datasetName()), + graphIdentifier.graphUri(), null) .addWhere(inPackageClassUri, RDF.type, RDFS.Class) .addWhere(associationUri, RDF.type, RDF.Property) @@ -320,8 +320,8 @@ private void fetchExternallyInheritanceRelatedClasses( var inPackageClassUri = "?inPackageClassUri"; var associatedClassesQueryBuilder = CIMQueries.getClassQuery( - databasePort.getPrefixMapping(graphIdentifier.getDatasetName()), - graphIdentifier.getGraphUri(), + databasePort.getPrefixMapping(graphIdentifier.datasetName()), + graphIdentifier.graphUri(), null) .addWhere(inPackageClassUri, RDF.type, RDFS.Class) .addWhere( @@ -354,16 +354,16 @@ private void fetchAttributes( for (String classUUID : classUUIDList) { var attributeQuery = CIMQueries.getAttributesQuery( - databasePort.getPrefixMapping(graphIdentifier.getDatasetName()), + databasePort.getPrefixMapping(graphIdentifier.datasetName()), classUUID, - graphIdentifier.getGraphUri()); + graphIdentifier.graphUri()); attributesQuery.addUnion(attributeQuery); } var attributeList = new CIMObjectFetcher( graph, - graphIdentifier.getGraphUri(), - databasePort.getPrefixMapping(graphIdentifier.getDatasetName())) + graphIdentifier.graphUri(), + databasePort.getPrefixMapping(graphIdentifier.datasetName())) .fetchCIMAttributeList(attributesQuery.build()); attributeList.forEach(cimAttribute -> cimCollection.getAttributes().add(cimAttribute)); @@ -377,15 +377,15 @@ private void fetchEnums( CIMCollection cimCollection) { var enumsInPackageQueryBuilder = CIMQueries.getEnumClassesQuery( - databasePort.getPrefixMapping(graphIdentifier.getDatasetName()), - graphIdentifier.getGraphUri(), + databasePort.getPrefixMapping(graphIdentifier.datasetName()), + graphIdentifier.graphUri(), null); appendPackageConstraint(filter, enumsInPackageQueryBuilder, CIMQueryVars.URI, true); var enumList = new CIMObjectFetcher( graph, - graphIdentifier.getGraphUri(), - databasePort.getPrefixMapping(graphIdentifier.getDatasetName())) + graphIdentifier.graphUri(), + databasePort.getPrefixMapping(graphIdentifier.datasetName())) .fetchCIMClassList(enumsInPackageQueryBuilder.build()); enumList.forEach(cimEnum -> cimCollection.getEnums().add(cimEnum)); // fetch enum entries @@ -407,8 +407,8 @@ private void fetchEnumEntries( for (String enumUUID : enumUUIDList) { var enumEntryQuery = CIMQueries.getEnumEntriesQuery( - databasePort.getPrefixMapping(graphIdentifier.getDatasetName()), - graphIdentifier.getGraphUri(), + databasePort.getPrefixMapping(graphIdentifier.datasetName()), + graphIdentifier.graphUri(), enumUUID); enumEntriesQuery.addUnion(enumEntryQuery); } @@ -416,8 +416,8 @@ private void fetchEnumEntries( var enumEntryList = new CIMObjectFetcher( graph, - graphIdentifier.getGraphUri(), - databasePort.getPrefixMapping(graphIdentifier.getDatasetName())) + graphIdentifier.graphUri(), + databasePort.getPrefixMapping(graphIdentifier.datasetName())) .fetchCIMEnumEntryList(enumEntriesQuery.build()); enumEntryList.forEach(cimEnumEntry -> cimCollection.getEnumEntries().add(cimEnumEntry)); @@ -435,8 +435,8 @@ private void fetchAssociations( for (CIMClass cimClass : cimCollection.getClasses()) { var associationPairQuery = CIMQueries.getAssociationsQuery( - databasePort.getPrefixMapping(graphIdentifier.getDatasetName()), - graphIdentifier.getGraphUri(), + databasePort.getPrefixMapping(graphIdentifier.datasetName()), + graphIdentifier.graphUri(), cimClass.getUuid().toString()); associationsQuery.addUnion(associationPairQuery); } @@ -444,8 +444,8 @@ private void fetchAssociations( for (CIMClass cimEnum : cimCollection.getEnums()) { var associationPairQuery = CIMQueries.getAssociationsQuery( - databasePort.getPrefixMapping(graphIdentifier.getDatasetName()), - graphIdentifier.getGraphUri(), + databasePort.getPrefixMapping(graphIdentifier.datasetName()), + graphIdentifier.graphUri(), cimEnum.getUuid().toString()); associationsQuery.addUnion(associationPairQuery); } @@ -453,8 +453,8 @@ private void fetchAssociations( var associationList = new CIMObjectFetcher( graph, - graphIdentifier.getGraphUri(), - databasePort.getPrefixMapping(graphIdentifier.getDatasetName())) + graphIdentifier.graphUri(), + databasePort.getPrefixMapping(graphIdentifier.datasetName())) .fetchCIMAssociationList(associationsQuery.build()); associationList.forEach( diff --git a/backend/src/main/java/org/rdfarchitect/services/SearchService.java b/backend/src/main/java/org/rdfarchitect/services/SearchService.java index 09e1251e..a3b1aca8 100644 --- a/backend/src/main/java/org/rdfarchitect/services/SearchService.java +++ b/backend/src/main/java/org/rdfarchitect/services/SearchService.java @@ -253,16 +253,16 @@ public void searchGraph( List externalSearchResults) { String specificInternalQuery; String specificExternalQuery; - if (Objects.equals(graphIdentifier.getGraphUri(), "default")) { + if (Objects.equals(graphIdentifier.graphUri(), "default")) { specificInternalQuery = SPARQL_INTERNAL_QUERY.replace(GRAPH, ""); specificExternalQuery = SPARQL_EXTERNAL_QUERY.replace(GRAPH, ""); } else { specificInternalQuery = SPARQL_INTERNAL_QUERY.replace( - GRAPH, "FROM <" + graphIdentifier.getGraphUri() + ">"); + GRAPH, "FROM <" + graphIdentifier.graphUri() + ">"); specificExternalQuery = SPARQL_EXTERNAL_QUERY.replace( - GRAPH, "FROM <" + graphIdentifier.getGraphUri() + ">"); + GRAPH, "FROM <" + graphIdentifier.graphUri() + ">"); } specificInternalQuery = specificInternalQuery.replace("searchQuery", query); specificExternalQuery = specificExternalQuery.replace("searchQuery", query); @@ -276,12 +276,12 @@ public void searchGraph( InMemorySparqlExecutor.executeSingleQuery( databasePort.getGraphWithContext(graphIdentifier).getRdfGraph(), internalQueryObject, - graphIdentifier.getGraphUri()); + graphIdentifier.graphUri()); var externalResultSet = InMemorySparqlExecutor.executeSingleQuery( databasePort.getGraphWithContext(graphIdentifier).getRdfGraph(), externalQueryObject, - graphIdentifier.getGraphUri()); + graphIdentifier.graphUri()); searchResults.addAll( SearchResultObjectFactory.createSearchResultObjectList( diff --git a/backend/src/main/java/org/rdfarchitect/services/dl/update/UpdateDiagramLayoutService.java b/backend/src/main/java/org/rdfarchitect/services/dl/update/UpdateDiagramLayoutService.java index 5c4e7a56..0a6e7c8e 100644 --- a/backend/src/main/java/org/rdfarchitect/services/dl/update/UpdateDiagramLayoutService.java +++ b/backend/src/main/java/org/rdfarchitect/services/dl/update/UpdateDiagramLayoutService.java @@ -66,7 +66,7 @@ public void createDiagramLayout(GraphIdentifier graphIdentifier) { diagramLayoutModel, Diagram.builder() .mRID(diagramLayout.getDefaultPackageMRID()) - .name(graphIdentifier.getGraphUri() + "/" + DEFAULT_PACKAGE_NAME) + .name(graphIdentifier.graphUri() + "/" + DEFAULT_PACKAGE_NAME) .orientation(OrientationKind.NEGATIVE) .build()); // create DOs and DOPs for the default package @@ -121,7 +121,7 @@ public void ensureDiagramLayoutExists( // finds the package name for the DL diagram to be added if (resolvedPackageUUID == diagramLayout.getDefaultPackageMRID().getUuid()) { - packageName = graphIdentifier.getGraphUri() + "/" + DEFAULT_PACKAGE_NAME; + packageName = graphIdentifier.graphUri() + "/" + DEFAULT_PACKAGE_NAME; } else { for (var cimPackage : cimCollection.getPackages()) { if (cimPackage.getUuid().equals(resolvedPackageUUID)) { diff --git a/backend/src/main/java/org/rdfarchitect/services/select/QueryClassService.java b/backend/src/main/java/org/rdfarchitect/services/select/QueryClassService.java index 54167f8a..ab678cd7 100644 --- a/backend/src/main/java/org/rdfarchitect/services/select/QueryClassService.java +++ b/backend/src/main/java/org/rdfarchitect/services/select/QueryClassService.java @@ -61,8 +61,8 @@ public ClassUMLAdaptedDTO getClassInformation( var cimClass = CIMUMLObjectFactory.createCIMClassUMLAdapted( graph, - graphIdentifier.getGraphUri(), - databasePort.getPrefixMapping(graphIdentifier.getDatasetName()), + graphIdentifier.graphUri(), + databasePort.getPrefixMapping(graphIdentifier.datasetName()), classUUID); return umlAdaptedClassMapper.toDTO(cimClass); } finally { @@ -83,8 +83,8 @@ public List listSuperClasses(GraphIdentifier graphIdentifier, UUID cla var cimObjectFetcher = new CIMObjectFetcher( graph, - graphIdentifier.getGraphUri(), - databasePort.getPrefixMapping(graphIdentifier.getDatasetName())); + graphIdentifier.graphUri(), + databasePort.getPrefixMapping(graphIdentifier.datasetName())); var baseClass = cimObjectFetcher.fetchCIMClass(classUUID.toString()); superClassList.add( cimObjectFetcher.fetchCIMClass(baseClass.getSuperClass().getUri().toString())); diff --git a/backend/src/main/java/org/rdfarchitect/services/select/QueryGraphService.java b/backend/src/main/java/org/rdfarchitect/services/select/QueryGraphService.java index 051737be..cc8238b3 100644 --- a/backend/src/main/java/org/rdfarchitect/services/select/QueryGraphService.java +++ b/backend/src/main/java/org/rdfarchitect/services/select/QueryGraphService.java @@ -89,9 +89,8 @@ public List getClassList(GraphIdentifier graphIdentifier) { // build query var baseQuery = new CIMBaseQueryBuilder() - .setGraph(graphIdentifier.getGraphUri()) - .addPrefixes( - databasePort.getPrefixMapping(graphIdentifier.getDatasetName())) + .setGraph(graphIdentifier.graphUri()) + .addPrefixes(databasePort.getPrefixMapping(graphIdentifier.datasetName())) .setOrder() .setDistinct() .setType(RDFS.Class) @@ -110,7 +109,7 @@ public List getClassList(GraphIdentifier graphIdentifier) { InMemorySparqlExecutor.executeSingleQuery( databasePort.getGraphWithContext(graphIdentifier).getRdfGraph(), query, - graphIdentifier.getGraphUri()); + graphIdentifier.graphUri()); // format results var cimClassList = CIMUMLObjectFactory.createCIMClassUMLAdaptedList(queryResultSet); @@ -144,7 +143,7 @@ private List getReferencedClassList(GraphIdentifier graphIde InMemorySparqlExecutor.executeSingleQuery( databasePort.getGraphWithContext(graphIdentifier).getRdfGraph(), query, - graphIdentifier.getGraphUri()); + graphIdentifier.graphUri()); // format results return CIMUMLObjectFactory.createCIMClassUMLAdaptedList(queryResultSet); @@ -155,9 +154,8 @@ public List listDatatypes(GraphIdentifier graphIdentifier) { // build query var baseQuery = new CIMBaseQueryBuilder() - .addPrefixes( - databasePort.getPrefixMapping(graphIdentifier.getDatasetName())) - .setGraph(graphIdentifier.getGraphUri()) + .addPrefixes(databasePort.getPrefixMapping(graphIdentifier.datasetName())) + .setGraph(graphIdentifier.graphUri()) .setOrder() .setDistinct() .setType(RDFS.Class) @@ -176,7 +174,7 @@ public List listDatatypes(GraphIdentifier graphIdentifier) { InMemorySparqlExecutor.executeSingleQuery( databasePort.getGraphWithContext(graphIdentifier).getRdfGraph(), query, - graphIdentifier.getGraphUri()); + graphIdentifier.graphUri()); // format results var cimClassList = CIMUMLObjectFactory.createCIMClassUMLAdaptedList(queryResultSet); @@ -194,7 +192,7 @@ public ByteArrayOutputStream getSchema(GraphIdentifier graphIdentifier, RDFForma var copiedGraph = GraphUtils.deepCopy(graph); copiedGraph .getPrefixMapping() - .setNsPrefixes(databasePort.getPrefixMapping(graphIdentifier.getDatasetName())); + .setNsPrefixes(databasePort.getPrefixMapping(graphIdentifier.datasetName())); removeUUIDs(copiedGraph); var sortedModel = new CimSortedModel(ModelFactory.createModelForGraph(copiedGraph)); sortedModel.write(out, format.getLang().getName()); @@ -214,9 +212,8 @@ public List listInternalPackages(GraphIdentifier graphIdentifier) { var internalPackageBaseQuery = new CIMBaseQueryBuilder() .setDistinct() - .addPrefixes( - databasePort.getPrefixMapping(graphIdentifier.getDatasetName())) - .setGraph(graphIdentifier.getGraphUri()) + .addPrefixes(databasePort.getPrefixMapping(graphIdentifier.datasetName())) + .setGraph(graphIdentifier.graphUri()) .setType(CIMS.classCategory) .build(); @@ -233,7 +230,7 @@ public List listInternalPackages(GraphIdentifier graphIdentifier) { InMemorySparqlExecutor.executeSingleQuery( databasePort.getGraphWithContext(graphIdentifier).getRdfGraph(), internalPackageQuery, - graphIdentifier.getGraphUri()); + graphIdentifier.graphUri()); // format results var cimPackageList = CIMObjectFactory.createCIMPackageList(internalPackageQueryResultSet); @@ -256,9 +253,8 @@ public List listExternalPackages(GraphIdentifier graphIdentifier) { var externalPackageBaseQuery = new CIMBaseQueryBuilder() .setDistinct() - .addPrefixes( - databasePort.getPrefixMapping(graphIdentifier.getDatasetName())) - .setGraph(graphIdentifier.getGraphUri()) + .addPrefixes(databasePort.getPrefixMapping(graphIdentifier.datasetName())) + .setGraph(graphIdentifier.graphUri()) .addWhereThisNotExists(RDF.type.getURI(), CIMS.classCategory.getURI()) .build() .addWhere(Node.ANY, CIMS.belongsToCategory.asNode(), CIMQueryVars.URI); @@ -271,7 +267,7 @@ public List listExternalPackages(GraphIdentifier graphIdentifier) { InMemorySparqlExecutor.executeSingleQuery( databasePort.getGraphWithContext(graphIdentifier).getRdfGraph(), externalPackageQuery, - graphIdentifier.getGraphUri()); + graphIdentifier.graphUri()); var cimExternalPackageList = CIMObjectFactory.createExternalCIMPackageList(externalPackageQueryResultSet); @@ -285,10 +281,10 @@ public List listPrimitives(GraphIdentifier graphIdentifier) new CIMBaseQueryBuilder() .setOrder() .setDistinct() - .addPrefixes(databasePort.getPrefixMapping(graphIdentifier.getGraphUri())) + .addPrefixes(databasePort.getPrefixMapping(graphIdentifier.graphUri())) .filterStereotypes( CIMStereotypes.primitiveString, CIMStereotypes.cimDatatypeString) - .setGraph(graphIdentifier.getGraphUri()) + .setGraph(graphIdentifier.graphUri()) .setType(RDFS.Class) .build(); var query = @@ -304,7 +300,7 @@ public List listPrimitives(GraphIdentifier graphIdentifier) InMemorySparqlExecutor.executeSingleQuery( databasePort.getGraphWithContext(graphIdentifier).getRdfGraph(), query, - graphIdentifier.getGraphUri()); + graphIdentifier.graphUri()); // format results var cimClassList = CIMUMLObjectFactory.createCIMClassUMLAdaptedList(queryResultSet); @@ -319,9 +315,8 @@ public List listStereotypes(GraphIdentifier graphIdentifier) { new CIMBaseQueryBuilder() .setOrder() .setDistinct() - .addPrefixes( - databasePort.getPrefixMapping(graphIdentifier.getDatasetName())) - .setGraph(graphIdentifier.getGraphUri()) + .addPrefixes(databasePort.getPrefixMapping(graphIdentifier.datasetName())) + .setGraph(graphIdentifier.graphUri()) .buildWithoutUriVar(); var query = new CIMQueryBuilder(baseQuery).appendStereotypeQuery(REQUIRED).build(); @@ -331,7 +326,7 @@ public List listStereotypes(GraphIdentifier graphIdentifier) { InMemorySparqlExecutor.executeSingleQuery( databasePort.getGraphWithContext(graphIdentifier).getRdfGraph(), query, - graphIdentifier.getGraphUri()); + graphIdentifier.graphUri()); // format results List resultList = new ArrayList<>(); diff --git a/backend/src/main/java/org/rdfarchitect/services/select/ontology/GenerateOntologyEntriesService.java b/backend/src/main/java/org/rdfarchitect/services/select/ontology/GenerateOntologyEntriesService.java index ece0453b..2cb689bf 100644 --- a/backend/src/main/java/org/rdfarchitect/services/select/ontology/GenerateOntologyEntriesService.java +++ b/backend/src/main/java/org/rdfarchitect/services/select/ontology/GenerateOntologyEntriesService.java @@ -45,7 +45,7 @@ public List generateOntologyEntries(GraphIdentifier graphIdentifi graph = databasePort.getGraphWithContext(graphIdentifier).getRdfGraph(); graph.begin(TxnType.READ); var model = ModelFactory.createModelForGraph(graph); - model.setNsPrefixes(databasePort.getPrefixMapping(graphIdentifier.getDatasetName())); + model.setNsPrefixes(databasePort.getPrefixMapping(graphIdentifier.datasetName())); return new OntologyGeneratableEntriesBuilder(model) .generateDCTModified(changeLogUseCase.listChanges(graphIdentifier)) .generateDCTIssued() diff --git a/backend/src/main/java/org/rdfarchitect/services/select/ontology/ReadOntologyService.java b/backend/src/main/java/org/rdfarchitect/services/select/ontology/ReadOntologyService.java index 9022df3f..adabb49f 100644 --- a/backend/src/main/java/org/rdfarchitect/services/select/ontology/ReadOntologyService.java +++ b/backend/src/main/java/org/rdfarchitect/services/select/ontology/ReadOntologyService.java @@ -46,7 +46,7 @@ public OntologyDTO getCurrentOntology(GraphIdentifier graphIdentifier) { graph = databasePort.getGraphWithContext(graphIdentifier).getRdfGraph(); graph.begin(TxnType.READ); var model = ModelFactory.createModelForGraph(graph); - model.setNsPrefixes(databasePort.getPrefixMapping(graphIdentifier.getDatasetName())); + model.setNsPrefixes(databasePort.getPrefixMapping(graphIdentifier.datasetName())); var ontology = new OntologyFacade(model); return ontology.getOntology(); diff --git a/backend/src/main/java/org/rdfarchitect/services/shacl/SHACLGenerateService.java b/backend/src/main/java/org/rdfarchitect/services/shacl/SHACLGenerateService.java index 536d6ddb..c17427e2 100644 --- a/backend/src/main/java/org/rdfarchitect/services/shacl/SHACLGenerateService.java +++ b/backend/src/main/java/org/rdfarchitect/services/shacl/SHACLGenerateService.java @@ -42,7 +42,7 @@ public class SHACLGenerateService implements SHACLGenerateUseCase { public String exportGeneratedSHACLGraph( GraphIdentifier graphIdentifier, PrefixEntry shaclPrefix) { GraphRewindable ontologyGraph = null; - var prefixes = databasePort.getPrefixMapping(graphIdentifier.getDatasetName()); + var prefixes = databasePort.getPrefixMapping(graphIdentifier.datasetName()); try (var outStream = new ByteArrayOutputStream()) { ontologyGraph = databasePort.getGraphWithContext(graphIdentifier).getRdfGraph(); ontologyGraph.begin(TxnType.READ); diff --git a/backend/src/main/java/org/rdfarchitect/services/shacl/SingletonPrimitiveSHACLStoringService.java b/backend/src/main/java/org/rdfarchitect/services/shacl/SingletonPrimitiveSHACLStoringService.java index 90ffa376..d1d5f79e 100644 --- a/backend/src/main/java/org/rdfarchitect/services/shacl/SingletonPrimitiveSHACLStoringService.java +++ b/backend/src/main/java/org/rdfarchitect/services/shacl/SingletonPrimitiveSHACLStoringService.java @@ -101,7 +101,7 @@ public ByteArrayOutputStream exportGeneratedSHACLGraph( ontologyGraph.begin(TxnType.READ); var ontologyModel = ModelFactory.createModelForGraph(ontologyGraph); ontologyModel.setNsPrefixes( - databasePort.getPrefixMapping(graphIdentifier.getDatasetName())); + databasePort.getPrefixMapping(graphIdentifier.datasetName())); var generatedShacl = new SHACLFromCIMGenerator(ontologyModel, SHACL_NAMESPACE, true).generate(); @@ -138,7 +138,7 @@ public ByteArrayOutputStream exportCombinedSHACLGraph( ontologyGraph.begin(TxnType.READ); var ontologyModel = ModelFactory.createModelForGraph(ontologyGraph); ontologyModel.setNsPrefixes( - databasePort.getPrefixMapping(graphIdentifier.getDatasetName())); + databasePort.getPrefixMapping(graphIdentifier.datasetName())); var generatedShacl = new SHACLFromCIMGenerator(ontologyModel, SHACL_NAMESPACE, true).generate(); @@ -176,8 +176,7 @@ public ByteArrayOutputStream exportGeneratedSHACLPrefixes( GraphIdentifier graphIdentifier, RDFFormat format) { try (var outStream = new ByteArrayOutputStream()) { var prefixModel = ModelFactory.createDefaultModel(); - prefixModel.setNsPrefixes( - databasePort.getPrefixMapping(graphIdentifier.getDatasetName())); + prefixModel.setNsPrefixes(databasePort.getPrefixMapping(graphIdentifier.datasetName())); prefixModel.setNsPrefix(SHACL_NAMESPACE.getPrefix(), SHACL_NAMESPACE.getUri()); prefixModel.write(outStream, format.getLang().getName()); return outStream; @@ -195,7 +194,7 @@ public CustomAndGeneratedTuple getSHACLToClassRelations( ontologyGraph.begin(TxnType.READ); var ontologyModel = ModelFactory.createModelForGraph(ontologyGraph); ontologyModel.setNsPrefixes( - databasePort.getPrefixMapping(graphIdentifier.getDatasetName())); + databasePort.getPrefixMapping(graphIdentifier.datasetName())); var generatedSHACL = new SHACLFromCIMGenerator(ontologyModel, SHACL_NAMESPACE, true) .generateForClassOnly(classUUID); diff --git a/backend/src/main/java/org/rdfarchitect/services/update/classes/UpdateClassService.java b/backend/src/main/java/org/rdfarchitect/services/update/classes/UpdateClassService.java index 44876f20..0d5d2bbe 100644 --- a/backend/src/main/java/org/rdfarchitect/services/update/classes/UpdateClassService.java +++ b/backend/src/main/java/org/rdfarchitect/services/update/classes/UpdateClassService.java @@ -64,9 +64,7 @@ public void replaceClass(GraphIdentifier graphIdentifier, ClassUMLAdaptedDTO new graph.begin(TxnType.WRITE); var cimClass = classMapper.toCIMObject(newClass); CIMUpdates.replaceClass( - graph, - databasePort.getPrefixMapping(graphIdentifier.getDatasetName()), - cimClass); + graph, databasePort.getPrefixMapping(graphIdentifier.datasetName()), cimClass); graph.commit(); } finally { if (graph != null) { @@ -99,7 +97,7 @@ public void addClass( newClassUUID = CIMUpdates.insertClass( graph, - databasePort.getPrefixMapping(graphIdentifier.getDatasetName()), + databasePort.getPrefixMapping(graphIdentifier.datasetName()), newClass); graph.commit(); } finally { @@ -139,9 +137,7 @@ public void deleteClass(GraphIdentifier graphIdentifier, String classUUID) { graph = databasePort.getGraphWithContext(graphIdentifier).getRdfGraph(); graph.begin(TxnType.WRITE); CIMUpdates.deleteClass( - graph, - databasePort.getPrefixMapping(graphIdentifier.getDatasetName()), - classUUID); + graph, databasePort.getPrefixMapping(graphIdentifier.datasetName()), classUUID); graph.commit(); } finally { if (graph != null) { diff --git a/backend/src/main/java/org/rdfarchitect/services/update/classes/associations/AssociationsService.java b/backend/src/main/java/org/rdfarchitect/services/update/classes/associations/AssociationsService.java index 072ba764..84dcfd36 100644 --- a/backend/src/main/java/org/rdfarchitect/services/update/classes/associations/AssociationsService.java +++ b/backend/src/main/java/org/rdfarchitect/services/update/classes/associations/AssociationsService.java @@ -56,13 +56,13 @@ public AssociationUUIDs createAssociation( } var update = CIMUpdates.insertAssociation( - databasePort.getPrefixMapping(graphIdentifier.getDatasetName()), - graphIdentifier.getGraphUri(), + databasePort.getPrefixMapping(graphIdentifier.datasetName()), + graphIdentifier.graphUri(), cimAssociationPair); var graph = databasePort.getGraphWithContext(graphIdentifier).getRdfGraph(); InMemorySparqlExecutor.executeSingleUpdate( - graph, update.build(), graphIdentifier.getGraphUri()); + graph, update.build(), graphIdentifier.graphUri()); changeLogUseCase.recordChange( graphIdentifier, new ChangeLogEntry( @@ -77,15 +77,15 @@ public AssociationUUIDs replaceAssociation( var cimAssociationPair = associationPairMapper.toCIMObject(associationPair); var update = CIMUpdates.replaceAssociation( - databasePort.getPrefixMapping(graphIdentifier.getDatasetName()), - graphIdentifier.getGraphUri(), + databasePort.getPrefixMapping(graphIdentifier.datasetName()), + graphIdentifier.graphUri(), cimAssociationPair); var fromUUID = cimAssociationPair.getFrom().getUuid(); var toUUID = cimAssociationPair.getTo().getUuid(); var graph = databasePort.getGraphWithContext(graphIdentifier).getRdfGraph(); InMemorySparqlExecutor.executeSingleUpdate( - graph, update.build(), graphIdentifier.getGraphUri()); + graph, update.build(), graphIdentifier.graphUri()); changeLogUseCase.recordChange( graphIdentifier, new ChangeLogEntry( @@ -102,13 +102,13 @@ public void replaceAllAssociations( var cimAssociationPairs = associationPairMapper.toCIMObjectList(associationPairList); var update = CIMUpdates.replaceAssociations( - databasePort.getPrefixMapping(graphIdentifier.getDatasetName()), - graphIdentifier.getGraphUri(), + databasePort.getPrefixMapping(graphIdentifier.datasetName()), + graphIdentifier.graphUri(), classUUID, cimAssociationPairs); var graph = databasePort.getGraphWithContext(graphIdentifier).getRdfGraph(); InMemorySparqlExecutor.executeSingleUpdate( - graph, update.build(), graphIdentifier.getGraphUri()); + graph, update.build(), graphIdentifier.graphUri()); changeLogUseCase.recordChange( graphIdentifier, new ChangeLogEntry( diff --git a/backend/src/main/java/org/rdfarchitect/services/update/classes/attributes/AttributesService.java b/backend/src/main/java/org/rdfarchitect/services/update/classes/attributes/AttributesService.java index 4b9b34b9..fc5a53a3 100644 --- a/backend/src/main/java/org/rdfarchitect/services/update/classes/attributes/AttributesService.java +++ b/backend/src/main/java/org/rdfarchitect/services/update/classes/attributes/AttributesService.java @@ -48,13 +48,13 @@ public UUID createAttribute(GraphIdentifier graphIdentifier, AttributeDTO attrib } var update = CIMUpdates.insertAttribute( - databasePort.getPrefixMapping(graphIdentifier.getDatasetName()), - graphIdentifier.getGraphUri(), + databasePort.getPrefixMapping(graphIdentifier.datasetName()), + graphIdentifier.graphUri(), cimAttribute); var graph = databasePort.getGraphWithContext(graphIdentifier).getRdfGraph(); InMemorySparqlExecutor.executeSingleUpdate( - graph, update.build(), graphIdentifier.getGraphUri()); + graph, update.build(), graphIdentifier.graphUri()); changeLogUseCase.recordChange( graphIdentifier, new ChangeLogEntry( @@ -67,12 +67,12 @@ public UUID replaceAttribute(GraphIdentifier graphIdentifier, AttributeDTO attri var cimAttribute = attributeMapper.toCIMObject(attributeDTO); var update = CIMUpdates.replaceAttribute( - databasePort.getPrefixMapping(graphIdentifier.getDatasetName()), - graphIdentifier.getGraphUri(), + databasePort.getPrefixMapping(graphIdentifier.datasetName()), + graphIdentifier.graphUri(), cimAttribute); var graph = databasePort.getGraphWithContext(graphIdentifier).getRdfGraph(); InMemorySparqlExecutor.executeSingleUpdate( - graph, update.build(), graphIdentifier.getGraphUri()); + graph, update.build(), graphIdentifier.graphUri()); changeLogUseCase.recordChange( graphIdentifier, new ChangeLogEntry( @@ -86,13 +86,13 @@ public void replaceAllAttributes( var attributeCIMObjects = attributeMapper.toCIMObjectList(attributeList); var update = CIMUpdates.replaceAttributes( - databasePort.getPrefixMapping(graphIdentifier.getDatasetName()), - graphIdentifier.getGraphUri(), + databasePort.getPrefixMapping(graphIdentifier.datasetName()), + graphIdentifier.graphUri(), classUUID, attributeCIMObjects); var graph = databasePort.getGraphWithContext(graphIdentifier).getRdfGraph(); InMemorySparqlExecutor.executeSingleUpdate( - graph, update.build(), graphIdentifier.getGraphUri()); + graph, update.build(), graphIdentifier.graphUri()); changeLogUseCase.recordChange( graphIdentifier, new ChangeLogEntry( diff --git a/backend/src/main/java/org/rdfarchitect/services/update/classes/enumentries/UpdateEnumEntriesService.java b/backend/src/main/java/org/rdfarchitect/services/update/classes/enumentries/UpdateEnumEntriesService.java index 2e4ac052..c5d53e61 100644 --- a/backend/src/main/java/org/rdfarchitect/services/update/classes/enumentries/UpdateEnumEntriesService.java +++ b/backend/src/main/java/org/rdfarchitect/services/update/classes/enumentries/UpdateEnumEntriesService.java @@ -61,14 +61,14 @@ public UUID replaceOrCreateEnumEntry( cimEnumEntry.setUuid(uuid); CIMUpdates.insertEnumEntry( graph, - databasePort.getPrefixMapping(graphIdentifier.getDatasetName()), + databasePort.getPrefixMapping(graphIdentifier.datasetName()), cimEnumEntry); message = "Enum entry " + uuid + " created"; } else { uuid = enumEntryDTO.getUuid(); CIMUpdates.replaceEnumEntry( graph, - databasePort.getPrefixMapping(graphIdentifier.getDatasetName()), + databasePort.getPrefixMapping(graphIdentifier.datasetName()), cimEnumEntry); message = "Enum entry " + uuid + " replaced"; } diff --git a/backend/src/main/java/org/rdfarchitect/services/update/graph/DeleteGraphService.java b/backend/src/main/java/org/rdfarchitect/services/update/graph/DeleteGraphService.java index 84a488e0..d58c5e7a 100644 --- a/backend/src/main/java/org/rdfarchitect/services/update/graph/DeleteGraphService.java +++ b/backend/src/main/java/org/rdfarchitect/services/update/graph/DeleteGraphService.java @@ -47,7 +47,7 @@ public void replaceGraph(GraphIdentifier graphIdentifier, MultipartFile file) { var graph = new GraphFileSourceBuilderImpl() .setFile(file) - .setGraphName(graphIdentifier.getGraphUri()) + .setGraphName(graphIdentifier.graphUri()) .build() .graph(); databasePort.createGraph(graphIdentifier, graph); diff --git a/backend/src/main/java/org/rdfarchitect/services/update/graph/ImportGraphsService.java b/backend/src/main/java/org/rdfarchitect/services/update/graph/ImportGraphsService.java index 717b656a..b0154cd9 100644 --- a/backend/src/main/java/org/rdfarchitect/services/update/graph/ImportGraphsService.java +++ b/backend/src/main/java/org/rdfarchitect/services/update/graph/ImportGraphsService.java @@ -130,7 +130,7 @@ private void recordChange(GraphIdentifier graphIdentifier, String datasetName) { "Imported graph into dataset '" + datasetName + "' with graph URI '" - + graphIdentifier.getGraphUri() + + graphIdentifier.graphUri() + "'.", databasePort .getGraphWithContext(graphIdentifier) diff --git a/backend/src/main/java/org/rdfarchitect/services/update/ontology/UpdateOntologyService.java b/backend/src/main/java/org/rdfarchitect/services/update/ontology/UpdateOntologyService.java index d4f6d945..ea14f57f 100644 --- a/backend/src/main/java/org/rdfarchitect/services/update/ontology/UpdateOntologyService.java +++ b/backend/src/main/java/org/rdfarchitect/services/update/ontology/UpdateOntologyService.java @@ -45,13 +45,13 @@ public class UpdateOntologyService // CREATE @Override public void createOntology(GraphIdentifier graphIdentifier, OntologyDTO ontologyDTO) { - expandOntologyIris(graphIdentifier.getDatasetName(), ontologyDTO); + expandOntologyIris(graphIdentifier.datasetName(), ontologyDTO); GraphRewindableWithUUIDs graph = null; try { graph = databasePort.getGraphWithContext(graphIdentifier).getRdfGraph(); graph.begin(TxnType.WRITE); var model = ModelFactory.createModelForGraph(graph); - model.setNsPrefixes(databasePort.getPrefixMapping(graphIdentifier.getDatasetName())); + model.setNsPrefixes(databasePort.getPrefixMapping(graphIdentifier.datasetName())); if (ontologyDTO.getUuid() == null) { ontologyDTO.setUuid(UUID.randomUUID().toString()); @@ -77,13 +77,13 @@ public void createOntology(GraphIdentifier graphIdentifier, OntologyDTO ontology // UPDATE @Override public void replaceOntology(GraphIdentifier graphIdentifier, OntologyDTO ontologyDTO) { - expandOntologyIris(graphIdentifier.getDatasetName(), ontologyDTO); + expandOntologyIris(graphIdentifier.datasetName(), ontologyDTO); GraphRewindableWithUUIDs graph = null; try { graph = databasePort.getGraphWithContext(graphIdentifier).getRdfGraph(); graph.begin(TxnType.WRITE); var model = ModelFactory.createModelForGraph(graph); - model.setNsPrefixes(databasePort.getPrefixMapping(graphIdentifier.getDatasetName())); + model.setNsPrefixes(databasePort.getPrefixMapping(graphIdentifier.datasetName())); if (ontologyDTO.getUuid() == null) { ontologyDTO.setUuid(UUID.randomUUID().toString()); @@ -114,7 +114,7 @@ public void deleteOntology(GraphIdentifier graphIdentifier) { graph = databasePort.getGraphWithContext(graphIdentifier).getRdfGraph(); graph.begin(TxnType.WRITE); var model = ModelFactory.createModelForGraph(graph); - model.setNsPrefixes(databasePort.getPrefixMapping(graphIdentifier.getDatasetName())); + model.setNsPrefixes(databasePort.getPrefixMapping(graphIdentifier.datasetName())); var ontology = new OntologyFacade(model); ontology.deleteOntology(); diff --git a/backend/src/main/java/org/rdfarchitect/services/update/packages/UpdatePackageService.java b/backend/src/main/java/org/rdfarchitect/services/update/packages/UpdatePackageService.java index 0dcd3695..2a5b3682 100644 --- a/backend/src/main/java/org/rdfarchitect/services/update/packages/UpdatePackageService.java +++ b/backend/src/main/java/org/rdfarchitect/services/update/packages/UpdatePackageService.java @@ -59,7 +59,7 @@ public UUID addPackage(GraphIdentifier graphIdentifier, PackageDTO packageDTO) { var newPackage = packageMapper.toCIMObject(packageDTO); CIMUpdates.insertPackage( graph, - databasePort.getPrefixMapping(graphIdentifier.getDatasetName()), + databasePort.getPrefixMapping(graphIdentifier.datasetName()), newPackage); graph.commit(); } finally { @@ -86,7 +86,7 @@ public void replacePackage(GraphIdentifier graphIdentifier, PackageDTO packageDT var newPackage = packageMapper.toCIMObject(packageDTO); CIMUpdates.replacePackage( graph, - databasePort.getPrefixMapping(graphIdentifier.getDatasetName()), + databasePort.getPrefixMapping(graphIdentifier.datasetName()), newPackage); graph.commit(); } finally { @@ -112,7 +112,7 @@ public void deletePackage(GraphIdentifier graphIdentifier, UUID packageUUID) { graph.begin(TxnType.WRITE); CIMUpdates.deletePackage( graph, - databasePort.getPrefixMapping(graphIdentifier.getDatasetName()), + databasePort.getPrefixMapping(graphIdentifier.datasetName()), packageUUID.toString()); graph.commit(); } finally { diff --git a/backend/src/test/java/org/rdfarchitect/cim/data/queries/update/cimupdates/CIMUpdatesTestBase.java b/backend/src/test/java/org/rdfarchitect/cim/data/queries/update/cimupdates/CIMUpdatesTestBase.java index 2f5a2372..d3644ced 100644 --- a/backend/src/test/java/org/rdfarchitect/cim/data/queries/update/cimupdates/CIMUpdatesTestBase.java +++ b/backend/src/test/java/org/rdfarchitect/cim/data/queries/update/cimupdates/CIMUpdatesTestBase.java @@ -125,7 +125,7 @@ protected static void addGraphFromFile(String fileName) { var graph = new GraphFileSourceBuilderImpl() .setFile(file) - .setGraphName(graphIdentifier.getGraphUri()) + .setGraphName(graphIdentifier.graphUri()) .build() .graph(); databasePort.createGraph(graphIdentifier, graph); @@ -148,7 +148,7 @@ protected void executeUpdateOnTestGraph(Update update) { InMemorySparqlExecutor.executeSingleUpdate( databasePort.getGraphWithContext(graphIdentifier).getRdfGraph(), update, - graphIdentifier.getGraphUri()); + graphIdentifier.graphUri()); } /** Use this method to execute write actions in a transaction using lambda expression */ diff --git a/backend/src/test/java/org/rdfarchitect/services/dl/DiagramLayoutServicesTestBase.java b/backend/src/test/java/org/rdfarchitect/services/dl/DiagramLayoutServicesTestBase.java index 032042ff..6f881d3e 100644 --- a/backend/src/test/java/org/rdfarchitect/services/dl/DiagramLayoutServicesTestBase.java +++ b/backend/src/test/java/org/rdfarchitect/services/dl/DiagramLayoutServicesTestBase.java @@ -17,7 +17,7 @@ package org.rdfarchitect.services.dl; -import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; import org.apache.jena.rdf.model.ResourceFactory; import org.apache.jena.vocabulary.RDF; @@ -92,7 +92,7 @@ public static void addGraphFromFile(String fileName) { var graph = new GraphFileSourceBuilderImpl() .setFile(file) - .setGraphName(graphIdentifier.getGraphUri()) + .setGraphName(graphIdentifier.graphUri()) .build() .graph(); databasePort.createGraph(graphIdentifier, graph); diff --git a/backend/src/test/java/org/rdfarchitect/services/schemaComparison/SchemaComparisonServiceTest.java b/backend/src/test/java/org/rdfarchitect/services/schemaComparison/SchemaComparisonServiceTest.java index 012056a5..cccb89bb 100644 --- a/backend/src/test/java/org/rdfarchitect/services/schemaComparison/SchemaComparisonServiceTest.java +++ b/backend/src/test/java/org/rdfarchitect/services/schemaComparison/SchemaComparisonServiceTest.java @@ -17,9 +17,9 @@ package org.rdfarchitect.services.schemaComparison; -import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; -import static utils.TestUtils.*; +import static utils.TestUtils.readMultipartFileFromFile; import org.apache.jena.vocabulary.RDF; import org.apache.jena.vocabulary.RDFS; @@ -63,7 +63,7 @@ void setUp() { var graphSource = new GraphFileSourceBuilderImpl() .setFile(file) - .setGraphName(GRAPH_IDENTIFIER.getGraphUri()) + .setGraphName(GRAPH_IDENTIFIER.graphUri()) .build(); databasePort.createGraph(GRAPH_IDENTIFIER, graphSource.graph()); } @@ -426,7 +426,7 @@ void compareSchemas_dbDb_noChanges_returnsEmptyList() { var graphSource = new GraphFileSourceBuilderImpl() .setFile(otherGraphFile) - .setGraphName(OTHER_GRAPH_IDENTIFIER.getGraphUri()) + .setGraphName(OTHER_GRAPH_IDENTIFIER.graphUri()) .build(); databasePort.createGraph(OTHER_GRAPH_IDENTIFIER, graphSource.graph()); diff --git a/backend/src/test/java/org/rdfarchitect/services/update/UpdateClassServiceTest.java b/backend/src/test/java/org/rdfarchitect/services/update/UpdateClassServiceTest.java index 6d12b5b2..52bc3706 100644 --- a/backend/src/test/java/org/rdfarchitect/services/update/UpdateClassServiceTest.java +++ b/backend/src/test/java/org/rdfarchitect/services/update/UpdateClassServiceTest.java @@ -17,10 +17,10 @@ package org.rdfarchitect.services.update; -import static org.assertj.core.api.Assertions.*; -import static org.mockito.Mockito.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; -import static utils.TestUtils.*; +import static utils.TestUtils.readMultipartFileFromFile; import org.apache.jena.graph.Node; import org.apache.jena.graph.NodeFactory; @@ -84,7 +84,7 @@ void setUp() { var graphSource = new GraphFileSourceBuilderImpl() .setFile(file) - .setGraphName(graphIdentifier.getGraphUri()) + .setGraphName(graphIdentifier.graphUri()) .build(); databasePort.createGraph(graphIdentifier, graphSource.graph()); } diff --git a/backend/src/test/java/org/rdfarchitect/services/update/graph/GraphBulkImportServiceTest.java b/backend/src/test/java/org/rdfarchitect/services/update/graph/GraphBulkImportServiceTest.java index 98a5c64a..10c7ed37 100644 --- a/backend/src/test/java/org/rdfarchitect/services/update/graph/GraphBulkImportServiceTest.java +++ b/backend/src/test/java/org/rdfarchitect/services/update/graph/GraphBulkImportServiceTest.java @@ -17,8 +17,12 @@ package org.rdfarchitect.services.update.graph; -import static org.assertj.core.api.Assertions.*; -import static org.mockito.Mockito.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -64,7 +68,7 @@ void importGraphs_sameFileNameTwice_autoGeneratesUniqueGraphUris() { .replaceGraph(captor.capture(), any(MultipartFile.class)); assertThat(captor.getAllValues()) - .extracting(GraphIdentifier::getGraphUri) + .extracting(GraphIdentifier::graphUri) .containsExactly(RDFA.GRAPH_URI + "graph", RDFA.GRAPH_URI + "graph_1"); } } diff --git a/backend/src/test/java/org/rdfarchitect/services/update/graph/ImportGraphsServiceTest.java b/backend/src/test/java/org/rdfarchitect/services/update/graph/ImportGraphsServiceTest.java index 34d51187..f696a514 100644 --- a/backend/src/test/java/org/rdfarchitect/services/update/graph/ImportGraphsServiceTest.java +++ b/backend/src/test/java/org/rdfarchitect/services/update/graph/ImportGraphsServiceTest.java @@ -17,9 +17,13 @@ package org.rdfarchitect.services.update.graph; -import static org.assertj.core.api.Assertions.*; -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.RETURNS_DEEP_STUBS; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import org.apache.jena.graph.Graph; import org.junit.jupiter.api.BeforeEach; @@ -92,7 +96,7 @@ void importGraphs_sameFileNameTwice_autoGeneratesUniqueGraphUris() { verify(databasePortMock, times(2)).createGraph(captor.capture(), any(Graph.class)); assertThat(captor.getAllValues()) - .extracting(GraphIdentifier::getGraphUri) + .extracting(GraphIdentifier::graphUri) .containsExactly(RDFA.GRAPH_URI + "graph", RDFA.GRAPH_URI + "graph_1"); verify(changeLogUseCaseMock, times(2)).recordChange(any(GraphIdentifier.class), any()); diff --git a/frontend/src/lib/models/reactive/mapper/map-dto-to-reactive-object.js b/frontend/src/lib/models/reactive/mapper/map-dto-to-reactive-object.js index d9c564b0..4e663b99 100644 --- a/frontend/src/lib/models/reactive/mapper/map-dto-to-reactive-object.js +++ b/frontend/src/lib/models/reactive/mapper/map-dto-to-reactive-object.js @@ -21,9 +21,10 @@ import { ReactiveClass } from "$lib/models/reactive/models/reactive-class.svelte * Maps a class DTO to a ReactiveClass instance * @param {Object} classDto - The class data transfer object from the API * @param {Array} classes - Array of existing classes for resolving references + * @param {function} getClassByUuid - A function that returns the class with the given uuid * @returns {ReactiveClass} The reactive class instance */ -export function mapClassDtoToReactiveClass(classDto, classes) { +export function mapClassDtoToReactiveClass(classDto, classes, getClassByUuid) { let superClass = null; if (classDto.superClass) { superClass = classes.find( @@ -55,6 +56,7 @@ export function mapClassDtoToReactiveClass(classDto, classes) { attributes, associations, enumEntries, + getClassByUuid, classes, ); } diff --git a/frontend/src/lib/models/reactive/models/reactive-association.svelte.js b/frontend/src/lib/models/reactive/models/reactive-association.svelte.js index 7274b49c..97c61450 100644 --- a/frontend/src/lib/models/reactive/models/reactive-association.svelte.js +++ b/frontend/src/lib/models/reactive/models/reactive-association.svelte.js @@ -16,7 +16,6 @@ */ import { ReactiveValueWrapper } from "$lib/models/reactive/reactive-wrappers/reactive-value-wrapper.svelte.js"; import { - isInvalidLabel, isInvalidMultiplicityLowerBound, isInvalidMultiplicityUpperBound, isInvalidNamespace, @@ -50,7 +49,7 @@ export class ReactiveAssociation { // Set top-level properties this.uuid = new ReactiveValueWrapper(uuid, isInvalidUuid); - this.label = new ReactiveValueWrapper(label, isInvalidLabel); + this.label = new ReactiveValueWrapper(label); this.namespace = new ReactiveValueWrapper( namespace, isInvalidNamespace, @@ -79,7 +78,7 @@ export class ReactiveAssociation { // Set inverse properties this.inverse = { uuid: new ReactiveValueWrapper(inverseUuid, isInvalidUuid), - label: new ReactiveValueWrapper(inverseLabel, isInvalidLabel), + label: new ReactiveValueWrapper(inverseLabel), namespace: new ReactiveValueWrapper( inverseNamespace, isInvalidNamespace, diff --git a/frontend/src/lib/models/reactive/models/reactive-class.svelte.js b/frontend/src/lib/models/reactive/models/reactive-class.svelte.js index 66341ccf..af73b1d0 100644 --- a/frontend/src/lib/models/reactive/models/reactive-class.svelte.js +++ b/frontend/src/lib/models/reactive/models/reactive-class.svelte.js @@ -23,6 +23,8 @@ import { ReactiveValueWrapper } from "$lib/models/reactive/reactive-wrappers/rea import { hasUniqueIRI, hasUniqueLabel, + isInvalidAssociationLabel, + isInvalidInverseAssociationLabel, isInvalidClassLabel, isInvalidNamespace, isInvalidStereotype, @@ -35,6 +37,19 @@ function initializeStereotypeViolationChecks(stereotype, stereotypesArray) { ); } +function initializeAssociationViolationChecks( + association, + associationsArray, + getClassByUuid, +) { + association.label.violationChecks.push(() => + isInvalidAssociationLabel(association, associationsArray), + ); + association.inverse.label.violationChecks.push(() => + isInvalidInverseAssociationLabel(association, getClassByUuid), + ); +} + function initializeUniqueLabelChecks(reactiveObject, enumEntriesArray) { reactiveObject.label.violationChecks.push(label => hasUniqueLabel(label, enumEntriesArray), @@ -53,6 +68,7 @@ export class ReactiveClass { attributes = [], associations = [], enumEntries = [], + getClassByUuid = () => undefined, compareClasses = [], ) { compareClasses = compareClasses.filter(c => c.uuid !== uuid); @@ -89,7 +105,12 @@ export class ReactiveClass { this.associations = new ReactiveObjectsArrayWrapper( associations, ReactiveAssociation, - initializeUniqueLabelChecks, + (association, associationsArray) => + initializeAssociationViolationChecks( + association, + associationsArray, + getClassByUuid, + ), ); this.enumEntries = new ReactiveObjectsArrayWrapper( enumEntries, diff --git a/frontend/src/lib/models/reactive/validity-rules/validityFunctions.js b/frontend/src/lib/models/reactive/validity-rules/validityFunctions.js index d5d82488..cea3ceed 100644 --- a/frontend/src/lib/models/reactive/validity-rules/validityFunctions.js +++ b/frontend/src/lib/models/reactive/validity-rules/validityFunctions.js @@ -50,6 +50,71 @@ export function isInvalidClassLabel(label, namespace, compareClasses) { return violations; } +export function isInvalidAssociationLabel(association, associations) { + const violations = isNotEmptyValidation(association?.label?.value); + const assocList = Array.isArray(associations) + ? associations + : (associations?.values ?? []); + if (violations.length === 0) { + if ( + assocList.filter( + a => + a.label.value === association?.label?.value && + a.namespace.value === association.namespace?.value && + a !== association, + ).length > 0 + ) { + violations.push("must be unique"); + } else if ( + association && + association.domain && + association.target && + association.inverse && + association.label + ) { + if ( + association.domain?.value === association.target?.value && + association.inverse?.label?.value === association.label?.value + ) { + violations.push("must be unique"); + } + } + } + return violations; +} + +export function isInvalidInverseAssociationLabel(association, getClassByUuid) { + const violations = isNotEmptyValidation(association?.inverse?.label?.value); + const targetClassDto = getClassByUuid(association.target?.value); + const assocList = targetClassDto?.associationPairs?.map(pair => pair) ?? []; + if (violations.length === 0) { + if ( + assocList.filter( + a => + a.from.label === association?.inverse?.label?.value && + a.from.prefix === association.inverse?.namespace?.value && + a.from.uuid !== association.inverse?.uuid?.value, + ).length > 0 + ) { + violations.push("must be unique"); + } else if ( + association && + association.domain && + association.target && + association.inverse && + association.label + ) { + if ( + association.domain?.value === association.target?.value && + association.inverse?.label?.value === association.label?.value + ) { + violations.push("must be unique"); + } + } + } + return violations; +} + export function isInvalidNamespace(namespace) { return isNotEmptyValidation(namespace); } diff --git a/frontend/src/routes/mainpage/classEditor/classEditor.svelte b/frontend/src/routes/mainpage/classEditor/classEditor.svelte index 4f7bc908..7243983b 100644 --- a/frontend/src/routes/mainpage/classEditor/classEditor.svelte +++ b/frontend/src/routes/mainpage/classEditor/classEditor.svelte @@ -63,6 +63,7 @@ datatypes: [], packages: [], classes: [], + targetClassInfos: [], }; let isDatasetReadOnly = $state(false); @@ -88,15 +89,22 @@ reactiveClass?.stereotypes.contains(enumerationStereotype), ); - $effect(async () => { + $effect(() => { editorState.selectedClassUUID.subscribe(); forceReloadTrigger.subscribe(); + + const cancellation = { cancelled: false }; loadingContext = true; loadingClass = true; + (async () => { + isDatasetReadOnly = await isReadOnly(datasetName); + await loadContext(); + await loadReactiveClass(cancellation); + })(); - isDatasetReadOnly = await isReadOnly(datasetName); - await loadContext(); - await loadReactiveClass(); + return () => { + cancellation.cancelled = true; + }; }); $effect(async () => { @@ -146,20 +154,38 @@ editorState.selectedContext.trigger(); } - async function loadReactiveClass() { + async function loadReactiveClass(cancelled) { const classDto = await ( await bec.getClassInfo(datasetName, graphUri, classUuid) ).json(); + if (cancelled.cancelled) return; const newReactiveClass = mapClassDtoToReactiveClass( classDto, context.classes, + uuid => context.targetClassInfos.find(cls => cls.uuid === uuid), ); reactiveClass = adoptUnsavedClassChanges( newReactiveClass, reactiveClass, ); loadingClass = false; - console.log({ reactiveClass }); + + const targetUuids = [ + ...new Set( + reactiveClass.associations.values + .map(assoc => assoc.target.value) + .filter(uuid => uuid != null), + ), + ]; + + let targetClassInfos = await Promise.all( + targetUuids.map(async uuid => { + const res = await bec.getClassInfo(datasetName, graphUri, uuid); + return res.json(); + }), + ); + if (cancelled.cancelled) return; + context.targetClassInfos = targetClassInfos; } function openPropertySHACLRulesDialog(property) { @@ -195,12 +221,23 @@ get reactiveClass() { return reactiveClass; }, + get targetClassInfos() { + return context.targetClassInfos; + }, + get backendConnection() { + return bec; + }, // get Objects by identifier functions get getClassByUuid() { return function (uuid) { return context.classes.find(cls => cls.uuid === uuid); }; }, + get getTargetClassInfoByUuid() { + return function (uuid) { + return context.targetClassInfos.find(cls => cls.uuid === uuid); + }; + }, get getSubstitutedNamespace() { return function (namespace) { const namespaceObj = context.namespaces.find( @@ -227,6 +264,9 @@ return context.packages.find(pkg => pkg.uuid === uuid); }; }, + addTargetClassInfo(classInfo) { + context.targetClassInfos = [...context.targetClassInfos, classInfo]; + }, }); diff --git a/frontend/src/routes/mainpage/classEditor/components/associations/associationEditorDialog/AssociationEditorDialog.svelte b/frontend/src/routes/mainpage/classEditor/components/associations/associationEditorDialog/AssociationEditorDialog.svelte index 4ea0b02b..f18786e5 100644 --- a/frontend/src/routes/mainpage/classEditor/components/associations/associationEditorDialog/AssociationEditorDialog.svelte +++ b/frontend/src/routes/mainpage/classEditor/components/associations/associationEditorDialog/AssociationEditorDialog.svelte @@ -37,6 +37,34 @@ let isNewAssociation = $state(true); let readonly = $derived(classEditorContext?.readonly); + let bec = $derived(classEditorContext?.backendConnection); + + $effect(() => { + (async () => { + const targetValue = association?.target?.value; + const ctx = classEditorContext; + + if (!ctx || !targetValue) return; + + const existingClassInfo = ctx.getTargetClassInfoByUuid(targetValue); + if (!existingClassInfo) { + const res = await bec.getClassInfo( + ctx.datasetName, + ctx.graphUri, + targetValue, + ); + const classInfo = await res.json(); + ctx.addTargetClassInfo(classInfo); + } + + // Trigger violation checks + if (association?.inverse?.label) { + association.inverse.label.value = + association.inverse.label.value; + } + })(); + }); + function onOpen() { classEditorContext = getContext("classEditor"); if (!associations.contains(association)) { @@ -48,16 +76,12 @@ namespace: classEditorContext.reactiveClass.namespace.value, }, }); + associations.appendClass(association); } else { isNewAssociation = false; } } - function onClose() { - association = null; - isNewAssociation = true; - } - async function saveAssociation() { const apiAssociation = mapReactiveAssociationToAssociationDto( association, @@ -79,12 +103,18 @@ association.inverse.uuid.value = result.associationUUIDs.toUUID; association.save(); if (isNewAssociation) { - associations.append(association); isNewAssociation = false; } association.save(); forceReloadTrigger.trigger(); } + + function onClose() { + if (isNewAssociation) { + associations.remove(association, true); + } + association = null; + }