Skip to content

Commit a0bb047

Browse files
committed
continued impl
1 parent 33f1f61 commit a0bb047

8 files changed

Lines changed: 306 additions & 2 deletions

File tree

backend/src/main/java/org/rdfarchitect/models/cim/data/dto/facade/CIMClass.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public ICIMClassCategory getBelongsToCategory() {
6363
if(category == null){
6464
return null;
6565
}
66-
return new CIMClassCategory(getGraphUri(), getModel(), category);
66+
return CIMClassCategory.fromResource(getGraphUri(), getModel(), category);
6767
}
6868

6969
@Override

backend/src/main/java/org/rdfarchitect/models/cim/data/dto/facade/CIMClassCategory.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@
1717

1818
package org.rdfarchitect.models.cim.data.dto.facade;
1919

20+
import org.apache.jena.graph.NodeFactory;
2021
import org.apache.jena.rdf.model.Model;
2122
import org.apache.jena.rdf.model.Resource;
23+
import org.rdfarchitect.models.cim.rdf.resources.CIMS;
24+
import org.rdfarchitect.models.cim.rdf.resources.RDFA;
25+
import java.util.ArrayList;
26+
import java.util.List;
2227
import java.util.UUID;
2328

2429
public class CIMClassCategory extends CIMResource implements ICIMClassCategory {
@@ -30,4 +35,21 @@ public CIMClassCategory(String graphUri, Model model, UUID uuid) {
3035
public CIMClassCategory(String graphUri, Model model, Resource resource) {
3136
super(graphUri, model, resource);
3237
}
38+
39+
public static ICIMClassCategory fromResource(String graphUri, Model model, Resource resource) {
40+
if(resource == null){
41+
return new DefaultCIMClassCategory(graphUri, model);
42+
}
43+
return new CIMClassCategory(graphUri, model, resource);
44+
}
45+
46+
@Override
47+
public List<ICIMClass> getClasses() {
48+
var resourcesInPackage = getModel().listSubjectsWithProperty(CIMS.belongsToCategory, this.getJenaResource()).toList();
49+
var classes = new ArrayList<ICIMClass>();
50+
for(var resource : resourcesInPackage){
51+
classes.add(CIMClass.fromResource(getGraphUri(), getModel(), resource));
52+
}
53+
return classes;
54+
}
3355
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright (c) 2024-2026 SOPTIM AG
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package org.rdfarchitect.models.cim.data.dto.facade;
19+
20+
import lombok.RequiredArgsConstructor;
21+
import org.apache.jena.rdf.model.Model;
22+
import org.apache.jena.vocabulary.RDF;
23+
import org.apache.jena.vocabulary.RDFS;
24+
import org.rdfarchitect.models.cim.data.dto.relations.CIMSStereotype;
25+
import org.rdfarchitect.models.cim.rdf.resources.CIMS;
26+
import org.rdfarchitect.models.cim.rdf.resources.CIMStereotypes;
27+
import java.util.ArrayList;
28+
import java.util.List;
29+
import java.util.UUID;
30+
31+
@RequiredArgsConstructor
32+
public class CIMModelFacade implements ICIMModelFacade {
33+
34+
private final String graphUri;
35+
36+
private final Model model;
37+
38+
@Override
39+
public String getGraphUri() {
40+
return this.graphUri;
41+
}
42+
43+
@Override
44+
public List<ICIMClass> getCIMClasses() {
45+
var classResources = model.listSubjectsWithProperty(RDF.type, RDFS.Class).toList();
46+
var classes = new ArrayList<ICIMClass>();
47+
for (var classResource : classResources) {
48+
classes.add(new CIMClass(this.graphUri, this.model, classResource));
49+
}
50+
return classes;
51+
}
52+
53+
@Override
54+
public List<ICIMClassCategory> getCIMClassCategories() {
55+
var packageResources = model.listSubjectsWithProperty(RDF.type, CIMS.classCategory).toList();
56+
var packages = new ArrayList<ICIMClassCategory>();
57+
for (var packageResource : packageResources) {
58+
packages.add(CIMClassCategory.fromResource(this.graphUri, this.model, packageResource));
59+
}
60+
packages.add(new DefaultCIMClassCategory(this.graphUri, this.model));
61+
return packages;
62+
}
63+
64+
public List<ICIMAttribute> getCIMAttributes() {
65+
var attributeResources = model.listSubjectsWithProperty(CIMS.stereotype, CIMStereotypes.attribute).toList();
66+
var attributes = new ArrayList<ICIMAttribute>();
67+
for (var attributeResource : attributeResources) {
68+
attributes.add(new CIMAttribute(this.graphUri, this.model, attributeResource));
69+
}
70+
return attributes;
71+
}
72+
73+
public List<ICIMAssociation> getCIMAssociations() {
74+
var associationResources = model.listSubjectsWithProperty(CIMS.inverseRoleName).toList();
75+
var associations = new ArrayList<ICIMAssociation>();
76+
for (var associationResource : associationResources) {
77+
associations.add(new CIMAssociation(this.graphUri, this.model, associationResource));
78+
}
79+
return associations;
80+
}
81+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright (c) 2024-2026 SOPTIM AG
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package org.rdfarchitect.models.cim.data.dto.facade;
19+
20+
import java.util.ArrayList;
21+
import java.util.List;
22+
import java.util.UUID;
23+
import org.apache.jena.rdf.model.Model;
24+
import org.apache.jena.vocabulary.RDF;
25+
import org.apache.jena.vocabulary.RDFS;
26+
import org.rdfarchitect.models.cim.data.dto.relations.RDFSComment;
27+
import org.rdfarchitect.models.cim.data.dto.relations.RDFSLabel;
28+
import org.rdfarchitect.models.cim.data.dto.relations.uri.URI;
29+
30+
public class DefaultCIMClassCategory implements ICIMClassCategory {
31+
32+
private final String graphUri;
33+
34+
private final Model model;
35+
36+
public DefaultCIMClassCategory(String graphUri, Model model) {
37+
this.graphUri = graphUri;
38+
this.model = model;
39+
}
40+
41+
@Override
42+
public UUID getUuid() {
43+
return null;
44+
}
45+
46+
@Override
47+
public String getGraphUri() {
48+
return graphUri;
49+
}
50+
51+
@Override
52+
public URI getUri() {
53+
return null;
54+
}
55+
56+
@Override
57+
public RDFSLabel getLabel() {
58+
return new RDFSLabel("default");
59+
}
60+
61+
@Override
62+
public RDFSComment getComment() {
63+
return null;
64+
}
65+
66+
67+
@Override
68+
public List<ICIMClass> getClasses() {
69+
var classResources = model.listSubjectsWithProperty(RDF.type, RDFS.Class).filterDrop(resource -> resource.hasProperty(RDFS.subClassOf)).toList();
70+
var classes = new ArrayList<ICIMClass>();
71+
for (var classResource : classResources){
72+
classes.add(new CIMClass(graphUri, model, classResource));
73+
}
74+
return classes;
75+
}
76+
}

backend/src/main/java/org/rdfarchitect/models/cim/data/dto/facade/ExternalCIMClass.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.rdfarchitect.models.cim.data.dto.relations.RDFSComment;
2525
import org.rdfarchitect.models.cim.data.dto.relations.RDFSLabel;
2626
import org.rdfarchitect.models.cim.data.dto.relations.uri.URI;
27+
import org.rdfarchitect.models.cim.rdf.resources.RDFA;
2728
import java.util.List;
2829
import java.util.UUID;
2930

@@ -46,7 +47,10 @@ public ExternalCIMClass(String graphUri, Model model, Resource resource) {
4647

4748
@Override
4849
public UUID getUuid() {
49-
return null;
50+
if(!this.resource.hasProperty(RDFA.uuid)){
51+
return null;
52+
}
53+
return UUID.fromString(this.resource.getProperty(RDFA.uuid).getObject().toString());
5054
}
5155

5256
@Override

backend/src/main/java/org/rdfarchitect/models/cim/data/dto/facade/ICIMClassCategory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
package org.rdfarchitect.models.cim.data.dto.facade;
1919

20+
import java.util.List;
21+
2022
public interface ICIMClassCategory extends ICIMResource{
2123

24+
List<ICIMClass> getClasses();
2225
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2024-2026 SOPTIM AG
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package org.rdfarchitect.models.cim.data.dto.facade;
19+
20+
import java.util.List;
21+
import java.util.UUID;
22+
23+
public interface ICIMModelFacade {
24+
25+
String getGraphUri();
26+
27+
List<ICIMClass> getCIMClasses();
28+
29+
List<ICIMClassCategory> getCIMClassCategories();
30+
31+
ICIMClassCategory getCIMClassCategory(UUID uuid);
32+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright (c) 2024-2026 SOPTIM AG
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package org.rdfarchitect.services.rendering.svelteflow;
19+
20+
import java.util.ArrayList;
21+
import java.util.HashSet;
22+
import java.util.List;
23+
import java.util.Map;
24+
import java.util.UUID;
25+
import lombok.RequiredArgsConstructor;
26+
import org.apache.jena.rdf.model.Model;
27+
import org.rdfarchitect.api.dto.dl.RenderingLayoutData;
28+
import org.rdfarchitect.api.dto.rendering.RenderingDataDTO;
29+
import org.rdfarchitect.api.dto.rendering.svelteflow.SvelteFlowDTO;
30+
import org.rdfarchitect.api.dto.rendering.svelteflow.sub.AttributeDTO;
31+
import org.rdfarchitect.api.dto.rendering.svelteflow.sub.EdgeDTO;
32+
import org.rdfarchitect.api.dto.rendering.svelteflow.sub.EdgeDataDTO;
33+
import org.rdfarchitect.api.dto.rendering.svelteflow.sub.EnumEntryDTO;
34+
import org.rdfarchitect.api.dto.rendering.svelteflow.sub.NodeDTO;
35+
import org.rdfarchitect.api.dto.rendering.svelteflow.sub.NodeDataDTO;
36+
import org.rdfarchitect.api.dto.rendering.svelteflow.sub.PositionDTO;
37+
import org.rdfarchitect.models.cim.data.dto.CIMAssociation;
38+
import org.rdfarchitect.models.cim.data.dto.CIMClass;
39+
import org.rdfarchitect.models.cim.data.dto.CIMCollection;
40+
import org.rdfarchitect.models.cim.data.dto.facade.CIMModelFacade;
41+
import org.rdfarchitect.models.cim.data.dto.facade.DefaultCIMClassCategory;
42+
import org.rdfarchitect.models.cim.data.dto.facade.ICIMClass;
43+
import org.rdfarchitect.models.cim.data.dto.facade.ICIMClassCategory;
44+
import org.rdfarchitect.models.cim.data.dto.facade.ICIMModelFacade;
45+
import org.rdfarchitect.models.cim.data.dto.relations.CIMSAssociationUsed;
46+
import org.rdfarchitect.models.cim.data.dto.relations.CIMSMultiplicity;
47+
import org.rdfarchitect.models.cim.data.dto.relations.CIMSStereotype;
48+
import org.rdfarchitect.models.cim.data.dto.relations.uri.URI;
49+
import org.rdfarchitect.models.cim.rdf.resources.CIMStereotypes;
50+
import org.rdfarchitect.models.cim.rendering.GraphFilter;
51+
import org.rdfarchitect.models.cim.rendering.RenderingUtils;
52+
import org.rdfarchitect.services.dl.select.FetchRenderingLayoutDataUseCase;
53+
import org.rdfarchitect.services.rendering.DiagramToCIMCollectionConverterUseCase;
54+
import org.rdfarchitect.services.rendering.RenderCIMCollectionUseCase;
55+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
56+
import org.springframework.stereotype.Service;
57+
import org.springframework.util.CollectionUtils;
58+
59+
/**
60+
* Converts a {@link CIMCollection} to a DTO Record that contains two JSON arrays with nodes and
61+
* edges used to render a UML diagram using the JavaScript library SvelteFlow.
62+
*/
63+
@RequiredArgsConstructor
64+
@Service
65+
@ConditionalOnProperty(
66+
name = "rendering.renderer",
67+
havingValue = "svelteflow",
68+
matchIfMissing = true)
69+
public class RenderCIMFacadeCollectionSvelteFlowService {
70+
71+
private final FetchRenderingLayoutDataUseCase fetchRenderingLayoutDataUseCase;
72+
73+
private final DiagramToCIMCollectionConverterUseCase converter;
74+
75+
// CONSTANTS FOR SVELTEFLOW CUSTOM NODE/EDGE TYPES
76+
private static final String CLASS_NODE_TYPE = "class";
77+
private static final String INHERITANCE_EDGE_TYPE = "inheritance";
78+
private static final String ASSOCIATION_EDGE_TYPE = "association";
79+
80+
public RenderingDataDTO renderUML(ICIMModelFacade cimModel, GraphFilter filter, RenderingLayoutData layoutData) {
81+
var pack = cimModel.getCIMClassCategory(filter.getPackageUUID() == null ? null : UUID.fromString(filter.getPackageUUID()));
82+
var classes = pack.getClasses();
83+
84+
return null;
85+
}
86+
}

0 commit comments

Comments
 (0)