use of de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException in project FAAAST-Service by FraunhoferIOSB.
the class ReferablePersistenceManager method remove.
/**
* Remove a {@link io.adminshell.aas.v3.model.Referable}
*
* @param reference of the referable which should be removed
*/
public void remove(Reference reference) throws ResourceNotFoundException {
if (reference == null) {
return;
}
if (reference.getKeys() != null && reference.getKeys().size() > 0) {
KeyElements lastKeyElementOfReference = reference.getKeys().get(reference.getKeys().size() - 1).getType();
Class clazz = AasUtils.keyTypeToClass(lastKeyElementOfReference);
if (Identifiable.class.isAssignableFrom(clazz)) {
// TODO: Build Identifier and forward remove reuquest to remove(Identifier id)
return;
}
if (SubmodelElement.class.isAssignableFrom(clazz)) {
clazz = SubmodelElement.class;
}
Referable referable = AasUtils.resolve(reference, this.aasEnvironment);
if (referable == null) {
throw new ResourceNotFoundException(String.format("Resource not found with reference {}", AasUtils.asString(reference)));
}
if (reference.getKeys().size() > 1) {
Reference parent = new DefaultReference.Builder().keys(reference.getKeys().subList(0, reference.getKeys().size() - 1)).build();
Referable parentReferable = AasUtils.resolve(parent, this.aasEnvironment);
Method method = EnvironmentHelper.getGetReferableListMethod(clazz, parentReferable);
if (method != null) {
try {
List<Referable> referableList = (List<Referable>) method.invoke(parentReferable);
referableList.remove(referable);
} catch (InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
}
}
}
}
}
use of de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException in project FAAAST-Service by FraunhoferIOSB.
the class PersistenceInMemoryTest method getSubmodelElementTestWithBlob.
@Test
public void getSubmodelElementTestWithBlob() 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";
String SUBMODEL_ELEMENT_IDSHORT = "ExampleBlob";
Reference reference = Util.createReference(AAS_IDENTIFIER, SUBMODEL_IDENTIFIER, SUBMODEL_ELEMENT_COLLECTION_IDSHORT, SUBMODEL_ELEMENT_IDSHORT);
QueryModifier queryModifier = new QueryModifier.Builder().extend(Extend.WithBLOBValue).build();
SubmodelElement actualSubmodelElement = persistence.get(reference, queryModifier);
SubmodelElement expectedSubmodelElementExpected = ((SubmodelElementCollection) environment.getSubmodels().stream().filter(x -> x.getIdentification().getIdentifier().equalsIgnoreCase(SUBMODEL_IDENTIFIER)).findFirst().get().getSubmodelElements().stream().filter(x -> x.getIdShort().equalsIgnoreCase(SUBMODEL_ELEMENT_COLLECTION_IDSHORT)).findFirst().get()).getValues().stream().filter(x -> x.getIdShort().equalsIgnoreCase(SUBMODEL_ELEMENT_IDSHORT)).findFirst().get();
Assert.assertEquals(expectedSubmodelElementExpected, actualSubmodelElement);
}
use of de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException in project FAAAST-Service by FraunhoferIOSB.
the class PersistenceInMemoryTest method testQueryModifierExtend.
@Test
public void testQueryModifierExtend() 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";
String SUBMODEL_ELEMENT_IDSHORT = "ExampleBlob";
Reference reference = Util.createReference(AAS_IDENTIFIER, SUBMODEL_IDENTIFIER, SUBMODEL_ELEMENT_COLLECTION_IDSHORT, SUBMODEL_ELEMENT_IDSHORT);
QueryModifier queryModifier = new QueryModifier.Builder().extend(Extend.WithBLOBValue).build();
Identifier submodelId = new DefaultIdentifier.Builder().idType(IdentifierType.IRI).identifier(SUBMODEL_IDENTIFIER).build();
SubmodelElement actual = this.persistence.get(reference, queryModifier);
SubmodelElement expected = ((SubmodelElementCollection) this.environment.getSubmodels().stream().filter(x -> x.getIdentification().equals(submodelId)).findFirst().get().getSubmodelElements().stream().filter(y -> y.getIdShort().equalsIgnoreCase(SUBMODEL_ELEMENT_COLLECTION_IDSHORT)).findFirst().get()).getValues().stream().filter(z -> z.getIdShort().equalsIgnoreCase(SUBMODEL_ELEMENT_IDSHORT)).findFirst().get();
Assert.assertEquals(expected, actual);
queryModifier = new QueryModifier.Builder().extend(Extend.WithoutBLOBValue).build();
actual = this.persistence.get(reference, queryModifier);
expected = null;
Assert.assertEquals(expected, actual);
}
use of de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException in project FAAAST-Service by FraunhoferIOSB.
the class PersistenceInMemoryTest method putSubmodelElementNewInSubmodelElementCollectionTest.
@Test
public void putSubmodelElementNewInSubmodelElementCollectionTest() throws ResourceNotFoundException {
SubmodelElement newSubmodelElement = DeepCopyHelper.deepCopy(this.environment.getSubmodels().get(0).getSubmodelElements().get(0), this.environment.getSubmodels().get(0).getSubmodelElements().get(0).getClass());
String idShort = "NewIdShort";
newSubmodelElement.setIdShort(idShort);
String AAS_IDENTIFIER = "https://acplt.org/Test_AssetAdministrationShell_Mandatory";
String SUBMODEL_IDENTIFIER = "https://acplt.org/Test_Submodel_Mandatory";
String SUBMODEL_ELEMENT_COLLECTION_IDSHORT = "ExampleSubmodelCollectionUnordered";
Reference parent = Util.createReference(AAS_IDENTIFIER, SUBMODEL_IDENTIFIER, SUBMODEL_ELEMENT_COLLECTION_IDSHORT);
Assert.assertEquals(((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().filter(x -> x.getIdShort().equalsIgnoreCase(idShort)).findFirst().orElse(null), null);
this.persistence.put(parent, null, newSubmodelElement);
SubmodelElement actualSubmodelelement = this.persistence.get(Util.createReference(AAS_IDENTIFIER, SUBMODEL_IDENTIFIER, SUBMODEL_ELEMENT_COLLECTION_IDSHORT, idShort), new QueryModifier());
Assert.assertEquals(newSubmodelElement, actualSubmodelelement);
}
use of de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException in project FAAAST-Service by FraunhoferIOSB.
the class PersistenceInMemoryTest method getSubmodelElementsFromSubmodelElementCollectionTest.
@Test
public void getSubmodelElementsFromSubmodelElementCollectionTest() 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";
Reference reference = Util.createReference(AAS_IDENTIFIER, SUBMODEL_IDENTIFIER, SUBMODEL_ELEMENT_COLLECTION_IDSHORT);
List<SubmodelElement> actualSubmodelElements = persistence.getSubmodelElements(reference, null, new QueryModifier());
List<SubmodelElement> expectedSubmodelElements = (List<SubmodelElement>) ((SubmodelElementCollection) this.environment.getSubmodels().stream().filter(x -> x.getIdentification().getIdentifier().equalsIgnoreCase(SUBMODEL_IDENTIFIER)).findFirst().get().getSubmodelElements().stream().filter(x -> x.getIdShort().equalsIgnoreCase(SUBMODEL_ELEMENT_COLLECTION_IDSHORT)).findFirst().get()).getValues();
Assert.assertEquals(expectedSubmodelElements, actualSubmodelElements);
}
Aggregations