Skip to content

Commit 33f1f61

Browse files
committed
finished impl of facade
Signed-off-by: Maximilian Reisch <maximilian.reisch@soptim.de>
1 parent 764d8d6 commit 33f1f61

11 files changed

Lines changed: 778 additions & 22 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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 org.apache.jena.rdf.model.Model;
21+
import org.apache.jena.rdf.model.Resource;
22+
import org.apache.jena.vocabulary.RDFS;
23+
import org.rdfarchitect.models.cim.data.dto.relations.CIMSAssociationUsed;
24+
import org.rdfarchitect.models.cim.data.dto.relations.CIMSMultiplicity;
25+
import org.rdfarchitect.models.cim.rdf.resources.CIMS;
26+
import java.util.UUID;
27+
28+
public class CIMAssociation extends CIMResource implements ICIMAssociation {
29+
30+
public CIMAssociation(String graphUri, Model model, UUID uuid) {
31+
super(graphUri, model, uuid);
32+
}
33+
34+
public CIMAssociation(String graphUri, Model model, Resource resource) {
35+
super(graphUri, model, resource);
36+
}
37+
38+
@Override
39+
public CIMSMultiplicity getMultiplicity() {
40+
var multiplicity = getRequiredUniqueJenaProperty(CIMS.multiplicity);
41+
return new CIMSMultiplicity(multiplicity.getURI());
42+
}
43+
44+
@Override
45+
public ICIMClass getDomain() {
46+
var domain = getRequiredUniqueJenaProperty(RDFS.domain);
47+
return CIMClass.fromResource(getGraphUri(), getModel(), domain);
48+
}
49+
50+
@Override
51+
public ICIMClass getRange() {
52+
var range = getRequiredUniqueJenaProperty(RDFS.range);
53+
return CIMClass.fromResource(getGraphUri(), getModel(), range);
54+
}
55+
56+
@Override
57+
public ICIMAssociation getInverseAssociation() {
58+
var inverse = getRequiredUniqueJenaProperty(CIMS.inverseRoleName);
59+
return new CIMAssociation(getGraphUri(), getModel(), inverse);
60+
}
61+
62+
@Override
63+
public CIMSAssociationUsed getAssociationUsed() {
64+
var node = getUniqueJenaPropertyNode(CIMS.associationUsed);
65+
if(node == null){
66+
throw new IllegalStateException("Required property " + CIMS.associationUsed + " not found for association with UUID " + getUuid() + ".");
67+
}
68+
if(!node.isLiteral()){
69+
throw new IllegalStateException("AssociationUsed for association with UUID " + getUuid() + " is not a literal.");
70+
}
71+
return new CIMSAssociationUsed(node.asLiteral().getLexicalForm());
72+
}
73+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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 org.apache.jena.rdf.model.Literal;
21+
import org.apache.jena.rdf.model.Model;
22+
import org.apache.jena.rdf.model.Property;
23+
import org.apache.jena.rdf.model.Resource;
24+
import org.apache.jena.rdf.model.ResourceFactory;
25+
import org.apache.jena.vocabulary.RDFS;
26+
import org.rdfarchitect.models.cim.data.dto.relations.CIMSIsDefault;
27+
import org.rdfarchitect.models.cim.data.dto.relations.CIMSIsFixed;
28+
import org.rdfarchitect.models.cim.data.dto.relations.CIMSMultiplicity;
29+
import org.rdfarchitect.models.cim.data.dto.relations.CIMSStereotype;
30+
import org.rdfarchitect.models.cim.data.dto.relations.uri.URI;
31+
import org.rdfarchitect.models.cim.rdf.resources.CIMS;
32+
import java.util.UUID;
33+
34+
public class CIMAttribute extends CIMResource implements ICIMAttribute {
35+
36+
private static final Property LITERAL_WRAPPER_PROPERTY =
37+
ResourceFactory.createProperty(RDFS.Literal.getURI());
38+
39+
public CIMAttribute(String graphUri, Model model, UUID uuid) {
40+
super(graphUri, model, uuid);
41+
}
42+
43+
public CIMAttribute(String graphUri, Model model, Resource resource) {
44+
super(graphUri, model, resource);
45+
}
46+
47+
@Override
48+
public ICIMClass getDomain() {
49+
var domain = getRequiredUniqueJenaProperty(RDFS.domain);
50+
return CIMClass.fromResource(getGraphUri(), getModel(), domain);
51+
}
52+
53+
@Override
54+
public CIMSMultiplicity getMultiplicity() {
55+
var multiplicity = getRequiredUniqueJenaProperty(CIMS.multiplicity);
56+
return new CIMSMultiplicity(multiplicity.getURI());
57+
}
58+
59+
@Override
60+
public ICIMClass getDataType() {
61+
var dataType = getUniqueJenaProperty(CIMS.datatype);
62+
if(dataType == null){
63+
dataType = getUniqueJenaProperty(RDFS.range);
64+
}
65+
if(dataType == null){
66+
throw new IllegalStateException("No " + CIMS.datatype + " or " + RDFS.range + " found for attribute with UUID " + getUuid() + ".");
67+
}
68+
return CIMClass.fromResource(getGraphUri(), getModel(), dataType);
69+
}
70+
71+
@Override
72+
public CIMSStereotype getStereotype() {
73+
var stereotypes = getStereotypeList();
74+
if(stereotypes.isEmpty()){
75+
throw new IllegalStateException("Required property " + CIMS.stereotype + " not found for attribute with UUID " + getUuid() + ".");
76+
}
77+
return stereotypes.getFirst();
78+
}
79+
80+
@Override
81+
public CIMSIsFixed getFixed() {
82+
var valueNode = readValueNode(CIMS.isFixed);
83+
if(valueNode == null){
84+
return null;
85+
}
86+
return new CIMSIsFixed(valueNode.value(), valueNode.dataType(), valueNode.blankNode());
87+
}
88+
89+
@Override
90+
public CIMSIsDefault getDefault() {
91+
var valueNode = readValueNode(CIMS.isDefault);
92+
if(valueNode == null){
93+
return null;
94+
}
95+
return new CIMSIsDefault(valueNode.value(), valueNode.dataType(), valueNode.blankNode());
96+
}
97+
98+
private record ValueNode(String value, URI dataType, boolean blankNode) {}
99+
100+
private ValueNode readValueNode(Property property) {
101+
var node = getUniqueJenaPropertyNode(property);
102+
if(node == null){
103+
return null;
104+
}
105+
if(node.isLiteral()){
106+
return toValueNode(node.asLiteral(), false);
107+
}
108+
if(node.isAnon()){
109+
var inner = node.asResource().getProperty(LITERAL_WRAPPER_PROPERTY);
110+
if(inner != null && inner.getObject().isLiteral()){
111+
return toValueNode(inner.getObject().asLiteral(), true);
112+
}
113+
}
114+
return null;
115+
}
116+
117+
private static ValueNode toValueNode(Literal literal, boolean blankNode) {
118+
var dataTypeUri = literal.getDatatypeURI();
119+
var dataType = dataTypeUri == null || dataTypeUri.isEmpty() ? null : new URI(dataTypeUri);
120+
return new ValueNode(literal.getLexicalForm(), dataType, blankNode);
121+
}
122+
}

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

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@
1919

2020
import org.apache.jena.rdf.model.Model;
2121
import org.apache.jena.rdf.model.Resource;
22+
import org.apache.jena.vocabulary.RDF;
2223
import org.apache.jena.vocabulary.RDFS;
2324
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 org.rdfarchitect.models.cim.rdf.resources.RDFA;
28+
import org.rdfarchitect.models.cim.relations.model.properties.CIMPropertyUtils;
2429
import java.util.ArrayList;
2530
import java.util.List;
2631
import java.util.UUID;
@@ -35,37 +40,73 @@ public CIMClass(String graphUri, Model model, Resource resource) {
3540
super(graphUri, model, resource);
3641
}
3742

43+
public static ICIMClass fromResource(String graphUri, Model model, Resource resource) {
44+
if(model.contains(resource, RDFA.uuid)){
45+
return new CIMClass(graphUri, model, resource);
46+
}
47+
return new ExternalCIMClass(graphUri, model, resource);
48+
}
49+
3850
@Override
3951
public List<ICIMClass> getSuperClasses() {
4052
var resources = this.getJenaProperties(RDFS.subClassOf);
4153
var superClasses = new ArrayList<ICIMClass>();
4254
for(var res : resources){
43-
superClasses.add(new CIMClass(this.getGraphUri(), this.getModel(), res));
55+
superClasses.add(fromResource(this.getGraphUri(), this.getModel(), res));
4456
}
4557
return superClasses;
4658
}
4759

4860
@Override
4961
public ICIMClassCategory getBelongsToCategory() {
62+
var category = getUniqueJenaProperty(CIMS.belongsToCategory);
63+
if(category == null){
64+
return null;
65+
}
66+
return new CIMClassCategory(getGraphUri(), getModel(), category);
5067
}
5168

5269
@Override
5370
public List<CIMSStereotype> getStereotypes() {
54-
return List.of();
71+
return getStereotypeList();
5572
}
5673

5774
@Override
5875
public List<ICIMAttribute> getAttributes() {
59-
return List.of();
76+
var attributes = new ArrayList<ICIMAttribute>();
77+
for(var property : listDirectProperties()){
78+
if(CIMPropertyUtils.isAttribute(property)){
79+
attributes.add(new CIMAttribute(getGraphUri(), getModel(), property));
80+
}
81+
}
82+
return attributes;
6083
}
6184

6285
@Override
6386
public List<ICIMAssociation> getAssociations() {
64-
return List.of();
87+
var associations = new ArrayList<ICIMAssociation>();
88+
for(var property : listDirectProperties()){
89+
if(CIMPropertyUtils.isAssociation(property)){
90+
associations.add(new CIMAssociation(getGraphUri(), getModel(), property));
91+
}
92+
}
93+
return associations;
6594
}
6695

6796
@Override
6897
public List<ICIMEnumEntry> getEnumEntries() {
69-
return List.of();
98+
var jenaResource = getJenaResource();
99+
if(!jenaResource.hasProperty(CIMS.stereotype, CIMStereotypes.enumeration)){
100+
return List.of();
101+
}
102+
var entries = new ArrayList<ICIMEnumEntry>();
103+
for(var entry : getModel().listSubjectsWithProperty(RDF.type, jenaResource).toList()){
104+
entries.add(new CIMEnumEntry(getGraphUri(), getModel(), entry));
105+
}
106+
return entries;
107+
}
108+
109+
private List<Resource> listDirectProperties() {
110+
return getModel().listSubjectsWithProperty(RDFS.domain, getJenaResource()).toList();
70111
}
71112
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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 org.apache.jena.rdf.model.Model;
21+
import org.apache.jena.rdf.model.Resource;
22+
import java.util.UUID;
23+
24+
public class CIMClassCategory extends CIMResource implements ICIMClassCategory {
25+
26+
public CIMClassCategory(String graphUri, Model model, UUID uuid) {
27+
super(graphUri, model, uuid);
28+
}
29+
30+
public CIMClassCategory(String graphUri, Model model, Resource resource) {
31+
super(graphUri, model, resource);
32+
}
33+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 org.apache.jena.rdf.model.Model;
21+
import org.apache.jena.rdf.model.Resource;
22+
import org.apache.jena.vocabulary.RDF;
23+
import org.rdfarchitect.models.cim.data.dto.relations.CIMSStereotype;
24+
import java.util.UUID;
25+
26+
public class CIMEnumEntry extends CIMResource implements ICIMEnumEntry {
27+
28+
public CIMEnumEntry(String graphUri, Model model, UUID uuid) {
29+
super(graphUri, model, uuid);
30+
}
31+
32+
public CIMEnumEntry(String graphUri, Model model, Resource resource) {
33+
super(graphUri, model, resource);
34+
}
35+
36+
@Override
37+
public ICIMClass getDomain() {
38+
var domain = getRequiredUniqueJenaProperty(RDF.type);
39+
return CIMClass.fromResource(getGraphUri(), getModel(), domain);
40+
}
41+
42+
@Override
43+
public CIMSStereotype getStereotype() {
44+
var stereotypes = getStereotypeList();
45+
if(stereotypes.isEmpty()){
46+
return null;
47+
}
48+
return stereotypes.getFirst();
49+
}
50+
}

0 commit comments

Comments
 (0)