Search in sources :

Example 6 with ResourceNotFoundException

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

the class PostSubmodelElementByPathRequestHandler method process.

@Override
public PostSubmodelElementByPathResponse process(PostSubmodelElementByPathRequest request) {
    PostSubmodelElementByPathResponse response = new PostSubmodelElementByPathResponse();
    try {
        Reference parentReference = ReferenceHelper.toReference(request.getId(), Submodel.class);
        Reference childReference = AasUtils.toReference(parentReference, request.getSubmodelElement());
        SubmodelElement submodelElement = persistence.put(parentReference, null, request.getSubmodelElement());
        response.setPayload(submodelElement);
        response.setStatusCode(StatusCode.SuccessCreated);
        writeValueToAssetConnection(childReference, ElementValueMapper.toValue(submodelElement));
        publishElementCreateEventMessage(parentReference, submodelElement);
    } catch (ResourceNotFoundException ex) {
        response.setStatusCode(StatusCode.ClientErrorResourceNotFound);
    } catch (Exception ex) {
        response.setStatusCode(StatusCode.ServerInternalError);
    }
    return response;
}
Also used : PostSubmodelElementByPathResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PostSubmodelElementByPathResponse) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) Reference(io.adminshell.aas.v3.model.Reference) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)

Example 7 with ResourceNotFoundException

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

the class PutSubmodelRequestHandler method process.

@Override
public PutSubmodelResponse process(PutSubmodelRequest request) {
    PutSubmodelResponse response = new PutSubmodelResponse();
    try {
        // check if resource does exist
        Submodel submodel = (Submodel) persistence.get(request.getSubmodel().getIdentification(), new QueryModifier.Builder().extend(Extend.WithoutBLOBValue).level(Level.Core).build());
        submodel = (Submodel) persistence.put(request.getSubmodel());
        response.setPayload(submodel);
        response.setStatusCode(StatusCode.Success);
        Reference reference = AasUtils.toReference(submodel);
        readValueFromAssetConnectionAndUpdatePersistence(reference, submodel.getSubmodelElements());
        publishElementUpdateEventMessage(reference, submodel);
    } catch (ResourceNotFoundException ex) {
        response.setStatusCode(StatusCode.ClientErrorResourceNotFound);
    } catch (Exception ex) {
        response.setStatusCode(StatusCode.ServerInternalError);
    }
    return response;
}
Also used : Submodel(io.adminshell.aas.v3.model.Submodel) PutSubmodelResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PutSubmodelResponse) Reference(io.adminshell.aas.v3.model.Reference) QueryModifier(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.QueryModifier) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)

Example 8 with ResourceNotFoundException

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

the class PersistenceInMemoryTest method putSubmodelElementChangeInSubmodelElementCollectionTest.

@Test
public void putSubmodelElementChangeInSubmodelElementCollectionTest() throws ResourceNotFoundException {
    String AAS_IDENTIFIER = "https://acplt.org/Test_AssetAdministrationShell_Mandatory";
    String SUBMODEL_IDENTIFIER = "https://acplt.org/Test_Submodel_Mandatory";
    String SUBMODEL_ELEMENT_COLLECTION_IDSHORT = "ExampleSubmodelCollectionUnordered";
    SubmodelElement submodelElement = ((SubmodelElementCollection) this.environment.getSubmodels().stream().filter(x -> x.getIdentification().getIdentifier().equalsIgnoreCase(SUBMODEL_IDENTIFIER)).findFirst().get().getSubmodelElements().stream().filter(y -> y.getIdShort().equalsIgnoreCase(SUBMODEL_ELEMENT_COLLECTION_IDSHORT)).findFirst().orElse(null)).getValues().stream().findFirst().orElse(null);
    SubmodelElement changedSubmodelElement = DeepCopyHelper.deepCopy(submodelElement, submodelElement.getClass());
    String category = "NewCategory";
    changedSubmodelElement.setCategory(category);
    Reference reference = Util.createReference(AAS_IDENTIFIER, SUBMODEL_IDENTIFIER, SUBMODEL_ELEMENT_COLLECTION_IDSHORT, submodelElement.getIdShort());
    this.persistence.put(null, reference, changedSubmodelElement);
    SubmodelElement actualSubmodelelement = this.persistence.get(reference, new QueryModifier.Builder().extend(Extend.WithBLOBValue).build());
    Assert.assertEquals(changedSubmodelElement, actualSubmodelelement);
}
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 9 with ResourceNotFoundException

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

the class PersistenceInMemoryTest method getSubmodelElementsTest.

@Test
public void getSubmodelElementsTest() throws ResourceNotFoundException {
    String AAS_IDSHORT = "TestAssetAdministrationShell";
    String SUBMODEL_IRI = "http://acplt.org/Submodels/Assets/TestAsset/Identification";
    Reference submodelReference = Util.createReference(AAS_IDSHORT, SUBMODEL_IRI);
    List<SubmodelElement> actualSubmodelElements = persistence.getSubmodelElements(submodelReference, null, new QueryModifier());
    List<SubmodelElement> expectedSubmodelElements = this.environment.getSubmodels().stream().filter(x -> x.getIdentification().getIdentifier().equalsIgnoreCase(SUBMODEL_IRI)).findFirst().get().getSubmodelElements();
    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 10 with ResourceNotFoundException

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

the class PersistenceInMemoryTest method getSubmodelElementTest.

@Test
public void getSubmodelElementTest() throws ResourceNotFoundException {
    String AAS_IDENTIFIER = "https://acplt.org/Test_AssetAdministrationShell";
    String SUBMODEL_IDENTIFIER = "http://acplt.org/Submodels/Assets/TestAsset/BillOfMaterial";
    String SUBMODEL_ELEMENT_IDSHORT = "ExampleEntity2";
    Reference reference = Util.createReference(AAS_IDENTIFIER, SUBMODEL_IDENTIFIER, SUBMODEL_ELEMENT_IDSHORT);
    SubmodelElement actualSubmodelElement = persistence.get(reference, new QueryModifier());
    SubmodelElement expectedSubmodelElement = environment.getSubmodels().stream().filter(x -> x.getIdentification().getIdentifier().equalsIgnoreCase(SUBMODEL_IDENTIFIER)).findFirst().get().getSubmodelElements().stream().filter(x -> x.getIdShort().equalsIgnoreCase(SUBMODEL_ELEMENT_IDSHORT)).findFirst().get();
    Assert.assertEquals(expectedSubmodelElement, actualSubmodelElement);
}
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)

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