use of io.adminshell.aas.v3.model.Submodel in project FAAAST-Service by FraunhoferIOSB.
the class ReferablePersistenceManager method getSubmodelElements.
/**
* Get the submodel elements associated to the reference.
* Supported are two possible parents of submodel elements:
* <ul>
* <li>{@link io.adminshell.aas.v3.model.Submodel}
* <li>{@link io.adminshell.aas.v3.model.SubmodelElementCollection}
* </ul>
*
* @param reference to the submodel or submodel element collection
* @param semanticId of the submodel elements
*/
public List<SubmodelElement> getSubmodelElements(Reference reference, Reference semanticId) throws ResourceNotFoundException {
if (reference == null) {
return null;
}
if (reference.getKeys() != null && !reference.getKeys().isEmpty()) {
List<SubmodelElement> submodelElements = null;
KeyElements lastKeyElementOfReference = reference.getKeys().get(reference.getKeys().size() - 1).getType();
if (lastKeyElementOfReference == KeyElements.SUBMODEL) {
Submodel submodel = AasUtils.resolve(reference, this.aasEnvironment, Submodel.class);
if (submodel == null) {
throw new ResourceNotFoundException(String.format(ERROR_MSG_RESOURCE_NOT_FOUND_BY_REF, AasUtils.asString(reference)));
}
Submodel deepCopiedSubmodel = DeepCopyHelper.deepCopy(submodel, submodel.getClass());
submodelElements = deepCopiedSubmodel.getSubmodelElements();
} else if (lastKeyElementOfReference == KeyElements.SUBMODEL_ELEMENT_COLLECTION) {
SubmodelElementCollection submodelElementCollection = AasUtils.resolve(reference, this.aasEnvironment, SubmodelElementCollection.class);
if (submodelElementCollection == null) {
throw new ResourceNotFoundException(String.format(ERROR_MSG_RESOURCE_NOT_FOUND_BY_REF, AasUtils.asString(reference)));
}
SubmodelElementCollection deepCopiedSubmodelElementCollection = DeepCopyHelper.deepCopy(submodelElementCollection, submodelElementCollection.getClass());
submodelElements = new ArrayList<>(deepCopiedSubmodelElementCollection.getValues());
}
if (semanticId != null) {
assert submodelElements != null;
submodelElements = submodelElements.stream().filter(x -> x.getSemanticId() != null && x.getSemanticId().equals(semanticId)).collect(Collectors.toList());
}
return submodelElements;
}
return null;
}
use of io.adminshell.aas.v3.model.Submodel in project FAAAST-Service by FraunhoferIOSB.
the class PersistenceInMemoryTest method testQueryModifierLevel.
@Test
public void testQueryModifierLevel() throws ResourceNotFoundException {
String SUBMODEL_IDENTIFIER = "https://acplt.org/Test_Submodel_Mandatory";
QueryModifier queryModifier = new QueryModifier.Builder().level(Level.DEEP).build();
Identifier submodelId = new DefaultIdentifier.Builder().idType(IdentifierType.IRI).identifier(SUBMODEL_IDENTIFIER).build();
Submodel expected = this.environment.getSubmodels().stream().filter(x -> x.getIdentification().equals(submodelId)).findFirst().get();
Submodel actual = (Submodel) this.persistence.get(submodelId, queryModifier);
Assert.assertEquals(expected, actual);
queryModifier = new QueryModifier.Builder().level(Level.CORE).build();
actual = (Submodel) this.persistence.get(submodelId, queryModifier);
List<SubmodelElement> submodelElementCollections = actual.getSubmodelElements().stream().filter(x -> SubmodelElementCollection.class.isAssignableFrom(x.getClass())).collect(Collectors.toList());
Assert.assertTrue(submodelElementCollections.stream().allMatch(x -> ((SubmodelElementCollection) x).getValues().isEmpty()));
}
use of io.adminshell.aas.v3.model.Submodel in project FAAAST-Service by FraunhoferIOSB.
the class PersistenceInMemoryTest method putIdentifiableNewTest.
@Test
public void putIdentifiableNewTest() throws ResourceNotFoundException {
Submodel newSubmodel = DeepCopyHelper.deepCopy(this.environment.getSubmodels().get(0), this.environment.getSubmodels().get(0).getClass());
String idShort = "NewIdShort";
newSubmodel.setIdShort(idShort);
Identifier newIdentifier = new DefaultIdentifier.Builder().identifier("http://newIdentifier.org").idType(IdentifierType.IRI).build();
newSubmodel.setIdentification(newIdentifier);
this.persistence.put(newSubmodel);
Submodel expected = this.environment.getSubmodels().stream().filter(x -> x.getIdentification().equals(newIdentifier)).findFirst().orElse(null);
Assert.assertEquals(expected, newSubmodel);
}
use of io.adminshell.aas.v3.model.Submodel in project FAAAST-Service by FraunhoferIOSB.
the class HttpEndpointIT method testSubmodelInterfaceCreateSubmodelElement.
@Test
public void testSubmodelInterfaceCreateSubmodelElement() throws InterruptedException, MessageBusException, IOException, URISyntaxException, SerializationException, DeserializationException {
Submodel submodel = environment.getSubmodels().get(0);
SubmodelElement expected = new DefaultProperty.Builder().idShort("newProperty").build();
assertEvent(messageBus, ElementCreateEventMessage.class, expected, LambdaExceptionHelper.wrap(x -> executeAndAssertSingleEntity(HttpMethod.POST, API_PATHS.submodelRepository().submodelInterface(submodel).submodelElements(), StatusCode.SUCCESS_CREATED, expected, expected, SubmodelElement.class)));
List<SubmodelElement> after = HttpHelper.getWithMultipleResult(API_PATHS.submodelRepository().submodelInterface(submodel).submodelElements(), SubmodelElement.class);
Assert.assertTrue(after.contains(expected));
}
use of io.adminshell.aas.v3.model.Submodel in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method elementCreated.
/**
* Handles an elementCreated event.
*
* @param element Reference to the created element.
* @param value The element that was added.
* @throws StatusException If the operation fails
* @throws ServiceResultException If the operation fails
* @throws ServiceException If the operation fails
* @throws AddressSpaceException If the operation fails
*/
@SuppressWarnings("java:S2629")
private void elementCreated(Reference element, Referable value) throws StatusException, ServiceResultException, ServiceException, AddressSpaceException {
if (element == null) {
throw new IllegalArgumentException(ELEMENT_NULL);
} else if (value == null) {
throw new IllegalArgumentException(VALUE_NULL);
}
try {
LOG.debug("elementCreated called. Reference {}", AasUtils.asString(element));
// The element is the parent object where the value is added
ObjectData parent = null;
if (referableMap.containsKey(element)) {
parent = referableMap.get(element);
} else {
LOG.info("elementCreated: element not found in referableMap: {}", AasUtils.asString(element));
}
if (value instanceof ConceptDescription) {
addConceptDescriptions(List.of((ConceptDescription) value));
} else if (value instanceof Asset) {
addAsset(aasEnvironmentNode, (Asset) value);
} else if (value instanceof Submodel) {
addSubmodel(aasEnvironmentNode, (Submodel) value);
} else if (value instanceof AssetAdministrationShell) {
addAssetAdministrationShell((AssetAdministrationShell) value);
} else if (parent != null) {
if (value instanceof EmbeddedDataSpecification) {
if (parent.getNode() instanceof AASAssetAdministrationShellType) {
addEmbeddedDataSpecifications((AASAssetAdministrationShellType) parent.getNode(), List.of((EmbeddedDataSpecification) value));
} else if (parent.getNode() instanceof AASSubmodelType) {
addEmbeddedDataSpecifications((AASSubmodelType) parent.getNode(), List.of((EmbeddedDataSpecification) value));
} else if (parent.getNode() instanceof AASSubmodelElementType) {
addEmbeddedDataSpecifications((AASSubmodelElementType) parent.getNode(), List.of((EmbeddedDataSpecification) value));
} else if (parent.getNode() instanceof AASAssetType) {
addEmbeddedDataSpecifications((AASAssetType) parent.getNode(), List.of((EmbeddedDataSpecification) value));
} else {
LOG.warn("elementCreated: EmbeddedDataSpecification parent class not found");
}
} else if (value instanceof Constraint) {
if (parent.getNode() instanceof AASSubmodelType) {
addQualifiers(((AASSubmodelType) parent.getNode()).getQualifierNode(), List.of((Constraint) value));
} else if (parent.getNode() instanceof AASSubmodelElementType) {
addQualifiers(((AASSubmodelElementType) parent.getNode()).getQualifierNode(), List.of((Constraint) value));
} else {
LOG.warn("elementCreated: Constraint parent class not found");
}
} else if (value instanceof SubmodelElement) {
if (parent.getNode() instanceof AASSubmodelType) {
LOG.info("elementCreated: call addSubmodelElements");
addSubmodelElements(parent.getNode(), List.of((SubmodelElement) value), (Submodel) parent.getReferable(), element);
} else if (parent.getNode() instanceof AASSubmodelElementType) {
LOG.info("elementCreated: call addSubmodelElements");
addSubmodelElements(parent.getNode(), List.of((SubmodelElement) value), parent.getSubmodel(), element);
} else {
LOG.warn("elementCreated: SubmodelElement parent class not found: {}; {}", parent.getNode().getNodeId(), parent.getNode());
}
}
} else {
LOG.warn("elementCreated: element not found: {}", AasUtils.asString(element));
}
} catch (Exception ex) {
LOG.error("elementCreated Exception", ex);
throw ex;
}
}
Aggregations