Search in sources :

Example 11 with ResourceNotFoundException

use of de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException in project FAAAST-Service by FraunhoferIOSB.

the class PersistenceInMemoryTest method getSubmodelElementsWithSemanticIdTest.

@Test
public void getSubmodelElementsWithSemanticIdTest() throws ResourceNotFoundException {
    String AAS_IDSHORT = "TestAssetAdministrationShell";
    String SUBMODEL_IRI = "http://acplt.org/Submodels/Assets/TestAsset/Identification";
    Reference submodelReference = Util.createReference(AAS_IDSHORT, SUBMODEL_IRI);
    Reference semanticIdReference = new DefaultReference.Builder().key(new DefaultKey.Builder().type(KeyElements.GLOBAL_REFERENCE).value("0173-1#02-AAO677#002").idType(KeyType.IRI).build()).build();
    List<SubmodelElement> actualSubmodelElements = persistence.getSubmodelElements(submodelReference, semanticIdReference, new QueryModifier());
    List<SubmodelElement> expectedSubmodelElements = this.environment.getSubmodels().stream().filter(x -> x.getIdentification().getIdentifier().equalsIgnoreCase(SUBMODEL_IRI)).findFirst().get().getSubmodelElements().stream().filter(x -> x.getSemanticId().equals(semanticIdReference)).collect(Collectors.toList());
    Assert.assertEquals(expectedSubmodelElements, actualSubmodelElements);
}
Also used : KeyElements(io.adminshell.aas.v3.model.KeyElements) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) ConceptDescription(io.adminshell.aas.v3.model.ConceptDescription) OutputModifier(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.OutputModifier) AASFull(de.fraunhofer.iosb.ilt.faaast.service.model.AASFull) AssetAdministrationShellEnvironment(io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment) SubmodelElementCollection(io.adminshell.aas.v3.model.SubmodelElementCollection) Extend(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.Extend) Identifier(io.adminshell.aas.v3.model.Identifier) DefaultIdentifier(io.adminshell.aas.v3.model.impl.DefaultIdentifier) AssetIdentification(de.fraunhofer.iosb.ilt.faaast.service.model.asset.AssetIdentification) Identifiable(io.adminshell.aas.v3.model.Identifiable) Message(de.fraunhofer.iosb.ilt.faaast.service.model.api.Message) DeepCopyHelper(de.fraunhofer.iosb.ilt.faaast.service.util.DeepCopyHelper) KeyType(io.adminshell.aas.v3.model.KeyType) QueryModifier(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.QueryModifier) DefaultKey(io.adminshell.aas.v3.model.impl.DefaultKey) Level(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.Level) Before(org.junit.Before) GlobalAssetIdentification(de.fraunhofer.iosb.ilt.faaast.service.model.asset.GlobalAssetIdentification) IdentifierType(io.adminshell.aas.v3.model.IdentifierType) Reference(io.adminshell.aas.v3.model.Reference) Test(org.junit.Test) Persistence(de.fraunhofer.iosb.ilt.faaast.service.persistence.Persistence) Collectors(java.util.stream.Collectors) Result(de.fraunhofer.iosb.ilt.faaast.service.model.api.Result) OperationHandle(de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationHandle) List(java.util.List) ExecutionState(de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.ExecutionState) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) AssetAdministrationShell(io.adminshell.aas.v3.model.AssetAdministrationShell) OperationResult(de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationResult) Assert(org.junit.Assert) Submodel(io.adminshell.aas.v3.model.Submodel) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) Reference(io.adminshell.aas.v3.model.Reference) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) QueryModifier(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.QueryModifier) Test(org.junit.Test)

Example 12 with ResourceNotFoundException

use of de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException 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() == null));
}
Also used : Submodel(io.adminshell.aas.v3.model.Submodel) KeyElements(io.adminshell.aas.v3.model.KeyElements) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) ConceptDescription(io.adminshell.aas.v3.model.ConceptDescription) OutputModifier(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.OutputModifier) AASFull(de.fraunhofer.iosb.ilt.faaast.service.model.AASFull) AssetAdministrationShellEnvironment(io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment) SubmodelElementCollection(io.adminshell.aas.v3.model.SubmodelElementCollection) Extend(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.Extend) Identifier(io.adminshell.aas.v3.model.Identifier) DefaultIdentifier(io.adminshell.aas.v3.model.impl.DefaultIdentifier) AssetIdentification(de.fraunhofer.iosb.ilt.faaast.service.model.asset.AssetIdentification) Identifiable(io.adminshell.aas.v3.model.Identifiable) Message(de.fraunhofer.iosb.ilt.faaast.service.model.api.Message) DeepCopyHelper(de.fraunhofer.iosb.ilt.faaast.service.util.DeepCopyHelper) KeyType(io.adminshell.aas.v3.model.KeyType) QueryModifier(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.QueryModifier) DefaultKey(io.adminshell.aas.v3.model.impl.DefaultKey) Level(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.Level) Before(org.junit.Before) GlobalAssetIdentification(de.fraunhofer.iosb.ilt.faaast.service.model.asset.GlobalAssetIdentification) IdentifierType(io.adminshell.aas.v3.model.IdentifierType) Reference(io.adminshell.aas.v3.model.Reference) Test(org.junit.Test) Persistence(de.fraunhofer.iosb.ilt.faaast.service.persistence.Persistence) Collectors(java.util.stream.Collectors) Result(de.fraunhofer.iosb.ilt.faaast.service.model.api.Result) OperationHandle(de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationHandle) List(java.util.List) ExecutionState(de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.ExecutionState) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) AssetAdministrationShell(io.adminshell.aas.v3.model.AssetAdministrationShell) OperationResult(de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationResult) Assert(org.junit.Assert) Submodel(io.adminshell.aas.v3.model.Submodel) Identifier(io.adminshell.aas.v3.model.Identifier) DefaultIdentifier(io.adminshell.aas.v3.model.impl.DefaultIdentifier) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) QueryModifier(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.QueryModifier) DefaultIdentifier(io.adminshell.aas.v3.model.impl.DefaultIdentifier) Test(org.junit.Test)

Example 13 with ResourceNotFoundException

use of de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException 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:
 * <p>
 * <ul>
 * <li>{@link io.adminshell.aas.v3.model.Submodel}
 * <li>{@link io.adminshell.aas.v3.model.SubmodelElementCollection}
 * </ul>
 * <p>
 * If the semanticId is not null the submodel element list filtered by the semantic id
 *
 * @param reference to the submodel or submodel element collection
 * @param semanticId of the submodel elements
 * @return a list of the submodel elements associated to the parent reference
 */
public List<SubmodelElement> getSubmodelElements(Reference reference, Reference semanticId) throws ResourceNotFoundException {
    if (reference == null) {
        return null;
    }
    if (reference.getKeys() != null && reference.getKeys().size() > 0) {
        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("Resource not found with reference {}", 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("Resource not found with reference {}", 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;
}
Also used : Submodel(io.adminshell.aas.v3.model.Submodel) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) ArrayList(java.util.ArrayList) SubmodelElementCollection(io.adminshell.aas.v3.model.SubmodelElementCollection) KeyElements(io.adminshell.aas.v3.model.KeyElements) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)

Example 14 with ResourceNotFoundException

use of de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException in project FAAAST-Service by FraunhoferIOSB.

the class GetSubmodelElementByPathRequestHandler method process.

@Override
public GetSubmodelElementByPathResponse process(GetSubmodelElementByPathRequest request) {
    GetSubmodelElementByPathResponse response = new GetSubmodelElementByPathResponse();
    try {
        Reference reference = ReferenceHelper.toReference(request.getPath(), request.getId(), Submodel.class);
        SubmodelElement submodelElement = persistence.get(reference, request.getOutputModifier());
        ElementValue oldValue = ElementValueMapper.toValue(submodelElement);
        // read value from AssetConnection if one exist
        // and update value in persistence if differs
        ElementValue valueFromAssetConnection = readDataElementValueFromAssetConnection(reference);
        if (valueFromAssetConnection != null && !Objects.equals(valueFromAssetConnection, oldValue)) {
            submodelElement = ElementValueMapper.setValue(submodelElement, valueFromAssetConnection);
            persistence.put(null, reference, submodelElement);
            // TODO @Jens
            // better publishValueChangeEventMessage(reference, oldValue, oldValue) ???
            publishElementUpdateEventMessage(reference, submodelElement);
        }
        response.setPayload(submodelElement);
        response.setStatusCode(StatusCode.Success);
        publishElementReadEventMessage(reference, submodelElement);
    } catch (ResourceNotFoundException ex) {
        response.setStatusCode(StatusCode.ClientErrorResourceNotFound);
    } catch (Exception ex) {
        response.setStatusCode(StatusCode.ServerInternalError);
    }
    return response;
}
Also used : SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) Reference(io.adminshell.aas.v3.model.Reference) GetSubmodelElementByPathResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetSubmodelElementByPathResponse) ElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)

Example 15 with ResourceNotFoundException

use of de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException in project FAAAST-Service by FraunhoferIOSB.

the class GetAllSubmodelElementsRequestHandler method process.

@Override
public GetAllSubmodelElementsResponse process(GetAllSubmodelElementsRequest request) {
    GetAllSubmodelElementsResponse response = new GetAllSubmodelElementsResponse();
    try {
        Reference reference = ReferenceHelper.toReference(request.getId(), Submodel.class);
        List<SubmodelElement> submodelElements = persistence.getSubmodelElements(reference, null, request.getOutputModifier());
        readValueFromAssetConnectionAndUpdatePersistence(reference, submodelElements);
        response.setPayload(submodelElements);
        response.setStatusCode(StatusCode.Success);
        if (submodelElements != null) {
            submodelElements.forEach(x -> publishElementReadEventMessage(AasUtils.toReference(reference, x), x));
        }
    } catch (ResourceNotFoundException ex) {
        response.setStatusCode(StatusCode.ClientErrorResourceNotFound);
    } catch (Exception ex) {
        response.setStatusCode(StatusCode.ServerInternalError);
    }
    return response;
}
Also used : SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) Reference(io.adminshell.aas.v3.model.Reference) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException) GetAllSubmodelElementsResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllSubmodelElementsResponse) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)

Aggregations

ResourceNotFoundException (de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)40 Reference (io.adminshell.aas.v3.model.Reference)28 SubmodelElement (io.adminshell.aas.v3.model.SubmodelElement)20 QueryModifier (de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.QueryModifier)18 AssetAdministrationShell (io.adminshell.aas.v3.model.AssetAdministrationShell)18 Submodel (io.adminshell.aas.v3.model.Submodel)18 OutputModifier (de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.OutputModifier)15 ConceptDescription (io.adminshell.aas.v3.model.ConceptDescription)13 KeyElements (io.adminshell.aas.v3.model.KeyElements)13 SubmodelElementCollection (io.adminshell.aas.v3.model.SubmodelElementCollection)13 List (java.util.List)13 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)12 Collectors (java.util.stream.Collectors)12 DeepCopyHelper (de.fraunhofer.iosb.ilt.faaast.service.util.DeepCopyHelper)11 Identifiable (io.adminshell.aas.v3.model.Identifiable)11 Identifier (io.adminshell.aas.v3.model.Identifier)11 Extend (de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.Extend)10 OperationHandle (de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationHandle)10 OperationResult (de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationResult)10 AssetIdentification (de.fraunhofer.iosb.ilt.faaast.service.model.asset.AssetIdentification)10