use of io.adminshell.aas.v3.model.Submodel in project FAAAST-Service by FraunhoferIOSB.
the class PersistenceInMemoryTest method getSubmodelsWithSemanticIdTest.
@Test
public void getSubmodelsWithSemanticIdTest() {
Reference semanticId = new DefaultReference.Builder().key(new DefaultKey.Builder().type(KeyElements.GLOBAL_REFERENCE).idType(KeyType.IRI).value("http://acplt.org/SubmodelTemplates/ExampleSubmodel").build()).build();
List<Submodel> actualSubmodels = persistence.get("", semanticId, new QueryModifier());
List<Submodel> expectedSubmodels = this.environment.getSubmodels().stream().filter(x -> x.getSemanticId() != null && x.getSemanticId().equals(semanticId)).collect(Collectors.toList());
Assert.assertEquals(expectedSubmodels, actualSubmodels);
}
use of io.adminshell.aas.v3.model.Submodel in project FAAAST-Service by FraunhoferIOSB.
the class PersistenceInMemoryTest method getSubmodelsAllTest.
@Test
public void getSubmodelsAllTest() {
List<Submodel> actualSubmodelList = persistence.get(null, (Reference) null, new QueryModifier());
List<Submodel> expectedSubmodelList = this.environment.getSubmodels();
Assert.assertEquals(expectedSubmodelList, actualSubmodelList);
}
use of io.adminshell.aas.v3.model.Submodel in project FAAAST-Service by FraunhoferIOSB.
the class IdentifiablePersistenceManager method remove.
/**
* Remove an identifiable by its identifier.
* Following identifiables are supported:
* <ul>
* <li>{@link io.adminshell.aas.v3.model.AssetAdministrationShell}
* <li>{@link io.adminshell.aas.v3.model.Submodel}
* <li>{@link io.adminshell.aas.v3.model.ConceptDescription}
* <li>{@link io.adminshell.aas.v3.model.Asset}
* </ul>
*
* @param id of the indetifiable which should be removed
* @throws ResourceNotFoundException if there is no identifiable with such an identifer
*/
public void remove(Identifier id) throws ResourceNotFoundException {
if (id == null || this.aasEnvironment == null) {
return;
}
Predicate<Identifiable> removeFilter = x -> !x.getIdentification().getIdentifier().equalsIgnoreCase(id.getIdentifier());
Identifiable identifiable = getIdentifiableById(id);
if (identifiable == null) {
throw new ResourceNotFoundException(String.format(ERROR_MSG_RESOURCE_NOT_FOUND_BY_ID, IdentifierHelper.asString(id)));
}
// TODO: use reflection?
if (AssetAdministrationShell.class.isAssignableFrom(identifiable.getClass())) {
List<AssetAdministrationShell> newAASList;
newAASList = this.aasEnvironment.getAssetAdministrationShells().stream().filter(removeFilter).collect(Collectors.toList());
this.aasEnvironment.setAssetAdministrationShells(newAASList);
} else if (Submodel.class.isAssignableFrom(identifiable.getClass())) {
List<Submodel> newSubmodelList;
newSubmodelList = this.aasEnvironment.getSubmodels().stream().filter(removeFilter).collect(Collectors.toList());
this.aasEnvironment.setSubmodels(newSubmodelList);
Reference referenceOfIdentifiable = AasUtils.toReference(identifiable);
this.aasEnvironment.getAssetAdministrationShells().forEach(x -> x.getSubmodels().remove(referenceOfIdentifiable));
} else if (ConceptDescription.class.isAssignableFrom(identifiable.getClass())) {
List<ConceptDescription> newConceptDescriptionList;
newConceptDescriptionList = this.aasEnvironment.getConceptDescriptions().stream().filter(removeFilter).collect(Collectors.toList());
this.aasEnvironment.setConceptDescriptions(newConceptDescriptionList);
} else if (Asset.class.isAssignableFrom(identifiable.getClass())) {
List<Asset> newAssetList;
newAssetList = this.aasEnvironment.getAssets().stream().filter(removeFilter).collect(Collectors.toList());
this.aasEnvironment.setAssets(newAssetList);
}
}
use of io.adminshell.aas.v3.model.Submodel in project FAAAST-Service by FraunhoferIOSB.
the class GetSubmodelByIdRequestHandler method process.
@Override
public GetSubmodelByIdResponse process(GetSubmodelByIdRequest request) throws ResourceNotFoundException, AssetConnectionException, ValueMappingException, MessageBusException {
GetSubmodelByIdResponse response = new GetSubmodelByIdResponse();
Submodel submodel = (Submodel) persistence.get(request.getId(), request.getOutputModifier());
response.setPayload(submodel);
response.setStatusCode(StatusCode.SUCCESS);
Reference reference = AasUtils.toReference(submodel);
syncWithAsset(reference, submodel.getSubmodelElements());
messageBus.publish(ElementReadEventMessage.builder().element(reference).value(submodel).build());
return response;
}
use of io.adminshell.aas.v3.model.Submodel in project FAAAST-Service by FraunhoferIOSB.
the class GetSubmodelRequestHandler method process.
@Override
public GetSubmodelResponse process(GetSubmodelRequest request) throws ResourceNotFoundException, AssetConnectionException, ValueMappingException, MessageBusException {
GetSubmodelResponse response = new GetSubmodelResponse();
Submodel submodel = (Submodel) persistence.get(request.getId(), request.getOutputModifier());
response.setPayload(submodel);
response.setStatusCode(StatusCode.SUCCESS);
Reference reference = AasUtils.toReference(submodel);
syncWithAsset(reference, submodel.getSubmodelElements());
messageBus.publish(ElementReadEventMessage.builder().element(reference).value(submodel).build());
return response;
}
Aggregations