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;
}
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;
}
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);
}
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);
}
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);
}
Aggregations