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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ public class NodeDataDTO {
private List<String> stereotypes;
private List<AttributeDTO> attributes;
private List<EnumEntryDTO> enumEntries;
private List<SuperClassDTO> superClasses;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2024-2026 SOPTIM AG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.rdfarchitect.api.dto.rendering.svelteflow.sub;

import lombok.Builder;
import lombok.Data;

import java.util.List;
import java.util.UUID;

/** DTO representing a super class of a SvelteFlow class node including its inherited members. */
@Data
@Builder
public class SuperClassDTO {

private UUID uuid;
private String label;
private List<AttributeDTO> attributes;
private List<EnumEntryDTO> enumEntries;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright (c) 2024-2026 SOPTIM AG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

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

import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.vocabulary.RDFS;
import org.rdfarchitect.models.cim.data.dto.relations.CIMSAssociationUsed;
import org.rdfarchitect.models.cim.data.dto.relations.CIMSMultiplicity;
import org.rdfarchitect.models.cim.rdf.resources.CIMS;

import java.util.UUID;

public class CIMAssociation extends CIMResource implements ICIMAssociation {

public CIMAssociation(String graphUri, Model model, UUID uuid) {
super(graphUri, model, uuid);
}

public CIMAssociation(String graphUri, Model model, Resource resource) {
super(graphUri, model, resource);
}

@Override
public CIMSMultiplicity getMultiplicity() {
var multiplicity = getRequiredUniqueJenaProperty(CIMS.multiplicity);
return new CIMSMultiplicity(multiplicity.getURI());
}

@Override
public ICIMClass getDomain() {
var domain = getRequiredUniqueJenaProperty(RDFS.domain);
return CIMClass.fromResource(getGraphUri(), getModel(), domain);
}

@Override
public ICIMClass getRange() {
var range = getRequiredUniqueJenaProperty(RDFS.range);
return CIMClass.fromResource(getGraphUri(), getModel(), range);
}

@Override
public ICIMAssociation getInverseAssociation() {
var inverse = getRequiredUniqueJenaProperty(CIMS.inverseRoleName);
return new CIMAssociation(getGraphUri(), getModel(), inverse);
}

@Override
public CIMSAssociationUsed getAssociationUsed() {
var node = getUniqueJenaPropertyNode(CIMS.associationUsed);
if (node == null) {
throw new IllegalStateException(
"Required property "
+ CIMS.associationUsed
+ " not found for association with UUID "
+ getUuid()
+ ".");
}
if (!node.isLiteral()) {
throw new IllegalStateException(
"AssociationUsed for association with UUID "
+ getUuid()
+ " is not a literal.");
}
return new CIMSAssociationUsed(node.asLiteral().getLexicalForm());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* Copyright (c) 2024-2026 SOPTIM AG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

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

import org.apache.jena.rdf.model.Literal;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.Property;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdf.model.ResourceFactory;
import org.apache.jena.vocabulary.RDFS;
import org.rdfarchitect.models.cim.data.dto.relations.CIMSIsDefault;
import org.rdfarchitect.models.cim.data.dto.relations.CIMSIsFixed;
import org.rdfarchitect.models.cim.data.dto.relations.CIMSMultiplicity;
import org.rdfarchitect.models.cim.data.dto.relations.CIMSStereotype;
import org.rdfarchitect.models.cim.data.dto.relations.uri.URI;
import org.rdfarchitect.models.cim.rdf.resources.CIMS;

import java.util.UUID;

public class CIMAttribute extends CIMResource implements ICIMAttribute {

private static final Property LITERAL_WRAPPER_PROPERTY =
ResourceFactory.createProperty(RDFS.Literal.getURI());

public CIMAttribute(String graphUri, Model model, UUID uuid) {
super(graphUri, model, uuid);
}

public CIMAttribute(String graphUri, Model model, Resource resource) {
super(graphUri, model, resource);
}

@Override
public ICIMClass getDomain() {
var domain = getRequiredUniqueJenaProperty(RDFS.domain);
return CIMClass.fromResource(getGraphUri(), getModel(), domain);
}

@Override
public CIMSMultiplicity getMultiplicity() {
var multiplicity = getRequiredUniqueJenaProperty(CIMS.multiplicity);
return new CIMSMultiplicity(multiplicity.getURI());
}

@Override
public ICIMClass getDataType() {
var dataType = getUniqueJenaProperty(CIMS.datatype);
if (dataType == null) {
dataType = getUniqueJenaProperty(RDFS.range);
}
if (dataType == null) {
throw new IllegalStateException(
"No "
+ CIMS.datatype
+ " or "
+ RDFS.range
+ " found for attribute with UUID "
+ getUuid()
+ ".");
}
return CIMClass.fromResource(getGraphUri(), getModel(), dataType);
}

@Override
public CIMSStereotype getStereotype() {
var stereotypes = getStereotypeList();
if (stereotypes.isEmpty()) {
throw new IllegalStateException(
"Required property "
+ CIMS.stereotype
+ " not found for attribute with UUID "
+ getUuid()
+ ".");
}
return stereotypes.getFirst();
}

@Override
public CIMSIsFixed getFixed() {
var valueNode = readValueNode(CIMS.isFixed);
if (valueNode == null) {
return null;
}
return new CIMSIsFixed(valueNode.value(), valueNode.dataType(), valueNode.blankNode());
}

@Override
public CIMSIsDefault getDefault() {
var valueNode = readValueNode(CIMS.isDefault);
if (valueNode == null) {
return null;
}
return new CIMSIsDefault(valueNode.value(), valueNode.dataType(), valueNode.blankNode());
}

private record ValueNode(String value, URI dataType, boolean blankNode) {}

private ValueNode readValueNode(Property property) {
var node = getUniqueJenaPropertyNode(property);
if (node == null) {
return null;
}
if (node.isLiteral()) {
return toValueNode(node.asLiteral(), false);
}
if (node.isAnon()) {
var inner = node.asResource().getProperty(LITERAL_WRAPPER_PROPERTY);
if (inner != null && inner.getObject().isLiteral()) {
return toValueNode(inner.getObject().asLiteral(), true);
}
}
return null;
}

private static ValueNode toValueNode(Literal literal, boolean blankNode) {
var dataTypeUri = literal.getDatatypeURI();
var dataType = dataTypeUri == null || dataTypeUri.isEmpty() ? null : new URI(dataTypeUri);
return new ValueNode(literal.getLexicalForm(), dataType, blankNode);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* Copyright (c) 2024-2026 SOPTIM AG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

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

import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.vocabulary.RDF;
import org.apache.jena.vocabulary.RDFS;
import org.rdfarchitect.models.cim.data.dto.relations.CIMSStereotype;
import org.rdfarchitect.models.cim.data.dto.relations.RDFSLabel;
import org.rdfarchitect.models.cim.rdf.resources.CIMS;
import org.rdfarchitect.models.cim.rdf.resources.CIMStereotypes;
import org.rdfarchitect.models.cim.rdf.resources.RDFA;
import org.rdfarchitect.models.cim.relations.model.properties.CIMPropertyUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class CIMClass extends CIMResource implements ICIMClass {

public CIMClass(String graphUri, Model model, UUID uuid) {
super(graphUri, model, uuid);
}

public CIMClass(String graphUri, Model model, Resource resource) {
super(graphUri, model, resource);
}

public static ICIMClass fromResource(String graphUri, Model model, Resource resource) {
if (model.contains(resource, RDFA.uuid)) {
return new CIMClass(graphUri, model, resource);
}
return new ExternalCIMClass(graphUri, model, resource);
}

@Override
public RDFSLabel getLabel() {
if (getUniqueJenaPropertyNode(RDFS.label) == null) {
return new RDFSLabel(getUri().getSuffix());
}
return super.getLabel();
}

@Override
public List<ICIMClass> getSuperClasses() {
var resources = this.getJenaProperties(RDFS.subClassOf);
var superClasses = new ArrayList<ICIMClass>();
for (var res : resources) {
superClasses.add(fromResource(this.getGraphUri(), this.getModel(), res));
}
return superClasses;
}

@Override
public ICIMClassCategory getBelongsToCategory() {
var category = getUniqueJenaProperty(CIMS.belongsToCategory);
if (category == null) {
return null;
}
return CIMClassCategory.fromResource(getGraphUri(), getModel(), category);
}

@Override
public List<CIMSStereotype> getStereotypes() {
return getStereotypeList();
}

@Override
public List<ICIMAttribute> getAttributes() {
var attributes = new ArrayList<ICIMAttribute>();
for (var property : listDirectProperties()) {
if (CIMPropertyUtils.isAttribute(property)) {
attributes.add(new CIMAttribute(getGraphUri(), getModel(), property));
}
}
return attributes;
}

@Override
public List<ICIMAssociation> getAssociations() {
var associations = new ArrayList<ICIMAssociation>();
for (var property : listDirectProperties()) {
if (CIMPropertyUtils.isAssociation(property)) {
associations.add(new CIMAssociation(getGraphUri(), getModel(), property));
}
}
return associations;
}

@Override
public List<ICIMEnumEntry> getEnumEntries() {
var jenaResource = getJenaResource();
if (!jenaResource.hasProperty(CIMS.stereotype, CIMStereotypes.enumeration)) {
return List.of();
}
var entries = new ArrayList<ICIMEnumEntry>();
for (var entry : getModel().listSubjectsWithProperty(RDF.type, jenaResource).toList()) {
entries.add(new CIMEnumEntry(getGraphUri(), getModel(), entry));
}
return entries;
}

private List<Resource> listDirectProperties() {
return getModel().listSubjectsWithProperty(RDFS.domain, getJenaResource()).toList();
}
}
Loading