use of io.adminshell.aas.v3.model.IdentifierKeyValuePair in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method addAasEntity.
/**
* Adds an AAS entity to the given node.
*
* @param node The desired UA node
* @param aasEntity The AAS entity to add
* @param submodel The corresponding Submodel
* @param parentRef The AAS reference to the parent object
* @param ordered Specifies whether the entity should be added ordered
* (true) or unordered (false)
* @throws StatusException If the operation fails
* @throws ServiceException If the operation fails
* @throws AddressSpaceException If the operation fails
* @throws ServiceResultException If the operation fails
*/
private void addAasEntity(UaNode node, Entity aasEntity, Submodel submodel, Reference parentRef, boolean ordered) throws StatusException, ServiceException, AddressSpaceException, ServiceResultException {
try {
if ((node != null) && (aasEntity != null)) {
String name = aasEntity.getIdShort();
QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASEntityType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
NodeId nid = getDefaultNodeId();
AASEntityType entityNode = createInstance(AASEntityType.class, nid, browseName, LocalizedText.english(name));
addSubmodelElementBaseData(entityNode, aasEntity);
Reference entityRef = AasUtils.toReference(parentRef, aasEntity);
// EntityType
entityNode.setEntityType(ValueConverter.getAasEntityType(aasEntity.getEntityType()));
submodelElementAasMap.put(entityNode.getEntityTypeNode().getNodeId(), new SubmodelElementData(aasEntity, submodel, SubmodelElementData.Type.ENTITY_TYPE, entityRef));
// GlobalAssetId
if (aasEntity.getGlobalAssetId() != null) {
if (entityNode.getGlobalAssetIdNode() == null) {
addAasReferenceAasNS(entityNode, aasEntity.getGlobalAssetId(), AASEntityType.GLOBAL_ASSET_ID, false);
} else {
setAasReferenceData(aasEntity.getGlobalAssetId(), entityNode.getGlobalAssetIdNode(), false);
}
submodelElementAasMap.put(entityNode.getGlobalAssetIdNode().getKeysNode().getNodeId(), new SubmodelElementData(aasEntity, submodel, SubmodelElementData.Type.ENTITY_GLOBAL_ASSET_ID, entityRef));
}
// SpecificAssetIds
IdentifierKeyValuePair specificAssetId = aasEntity.getSpecificAssetId();
if (specificAssetId != null) {
if (entityNode.getSpecificAssetIdNode() == null) {
addIdentifierKeyValuePair(entityNode, specificAssetId, AASEntityType.SPECIFIC_ASSET_ID);
} else {
setIdentifierKeyValuePairData(entityNode.getSpecificAssetIdNode(), specificAssetId);
}
}
// Statements
addSubmodelElements(entityNode.getStatementNode(), aasEntity.getStatements(), submodel, entityRef);
submodelElementOpcUAMap.put(entityRef, entityNode);
if (ordered) {
node.addReference(entityNode, Identifiers.HasOrderedComponent, false);
} else {
node.addComponent(entityNode);
}
referableMap.put(entityRef, new ObjectData(aasEntity, entityNode, submodel));
}
} catch (Throwable ex) {
logger.error("addAasEntity Exception", ex);
throw ex;
}
}
use of io.adminshell.aas.v3.model.IdentifierKeyValuePair in project FAAAST-Service by FraunhoferIOSB.
the class GetAllAssetAdministrationShellsByAssetIdRequestHandler method process.
@Override
public GetAllAssetAdministrationShellsByAssetIdResponse process(GetAllAssetAdministrationShellsByAssetIdRequest request) {
GetAllAssetAdministrationShellsByAssetIdResponse response = new GetAllAssetAdministrationShellsByAssetIdResponse();
try {
List<AssetIdentification> assetIdentifications = new ArrayList<>();
List<IdentifierKeyValuePair> identifierKeyValuePairs = request.getAssetIds();
for (IdentifierKeyValuePair pair : identifierKeyValuePairs) {
AssetIdentification id = null;
if (pair.getKey().equalsIgnoreCase("globalAssetId")) {
id = new GlobalAssetIdentification.Builder().reference(new DefaultReference.Builder().key(new DefaultKey.Builder().idType(KeyType.IRI).type(KeyElements.GLOBAL_REFERENCE).value(pair.getValue()).build()).build()).build();
} else {
id = new SpecificAssetIdentification.Builder().value(pair.getValue()).key(pair.getKey()).build();
}
assetIdentifications.add(id);
}
List<AssetAdministrationShell> shells = new ArrayList<>(persistence.get(null, assetIdentifications, request.getOutputModifier()));
response.setPayload(shells);
response.setStatusCode(StatusCode.Success);
shells.forEach(x -> publishElementReadEventMessage(AasUtils.toReference(x), x));
} catch (Exception ex) {
response.setStatusCode(StatusCode.ServerInternalError);
}
return response;
}
use of io.adminshell.aas.v3.model.IdentifierKeyValuePair in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method addAssetInformation.
/**
* Adds an AssetInformation object to the given Node.
*
* @param aasNode The AAS node where the AssetInformation should be added
* @param assetInformation The desired AssetInformation object
* @throws StatusException If the operation fails
*/
private void addAssetInformation(AASAssetAdministrationShellType aasNode, AssetInformation assetInformation) throws StatusException, ServiceException, AddressSpaceException, ServiceResultException {
if (aasNode == null) {
throw new IllegalArgumentException("aasNode = null");
} else if (assetInformation == null) {
throw new IllegalArgumentException("assetInformation = null");
}
try {
boolean created = false;
AASAssetInformationType assetInfoNode;
assetInfoNode = aasNode.getAssetInformationNode();
if (assetInfoNode == null) {
String displayName = "AssetInformation";
QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASSubmodelType.getNamespaceUri(), displayName).toQualifiedName(getNamespaceTable());
NodeId nid = createNodeId(aasNode, browseName);
assetInfoNode = createInstance(AASAssetInformationType.class, nid, browseName, LocalizedText.english(displayName));
created = true;
}
if (assetInfoNode != null) {
// AssetKind
AssetKind assetKind = assetInformation.getAssetKind();
assetInfoNode.setAssetKind(ValueConverter.convertAssetKind(assetKind));
// BillOfMaterials
List<Reference> assetBills = assetInformation.getBillOfMaterials();
if ((assetBills != null) && (!assetBills.isEmpty())) {
AASReferenceList assetBillsNode = assetInfoNode.getBillOfMaterialNode();
addBillOfMaterials(assetBillsNode, assetBills);
}
// DefaultThumbnail
File thumbnail = assetInformation.getDefaultThumbnail();
if (thumbnail != null) {
addAasFile(assetInfoNode, thumbnail, null, null, false, AASAssetInformationType.DEFAULT_THUMBNAIL);
}
// GlobalAssetId
Reference globalAssetId = assetInformation.getGlobalAssetId();
if (globalAssetId != null) {
addAasReferenceAasNS(assetInfoNode, globalAssetId, AASAssetInformationType.GLOBAL_ASSET_ID);
}
// SpecificAssetIds
List<IdentifierKeyValuePair> specificAssetIds = assetInformation.getSpecificAssetIds();
if ((specificAssetIds != null) && (!specificAssetIds.isEmpty())) {
addSpecificAssetIds(assetInfoNode, specificAssetIds, "SpecificAssetIds");
}
if (created) {
aasNode.addComponent(assetInfoNode);
}
}
} catch (Throwable ex) {
logger.error("addAssetInformation Exception", ex);
throw ex;
}
}
use of io.adminshell.aas.v3.model.IdentifierKeyValuePair in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method addSpecificAssetIds.
/**
* Adds a list of IdentifierKeyValuePairs to the given Node.
*
* @param assetInfoNode The AssetInformation node in which the
* IdentifierKeyValuePairs should be created or added
* @param list The desired list of IdentifierKeyValuePairs
* @param name The desired name of the Node
* @throws StatusException If the operation fails
*/
private void addSpecificAssetIds(AASAssetInformationType assetInfoNode, List<IdentifierKeyValuePair> list, String name) throws StatusException {
if (assetInfoNode == null) {
throw new IllegalArgumentException("assetInfoNode = null");
} else if (list == null) {
throw new IllegalArgumentException("list = null");
}
try {
logger.info("addSpecificAssetIds " + name + "; to Node: " + assetInfoNode.toString());
AASIdentifierKeyValuePairList listNode = assetInfoNode.getSpecificAssetIdNode();
boolean created = false;
if (listNode == null) {
QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASIdentifierKeyValuePairList.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
NodeId nid = createNodeId(assetInfoNode, browseName);
listNode = createInstance(AASIdentifierKeyValuePairList.class, nid, browseName, LocalizedText.english(name));
created = true;
}
for (IdentifierKeyValuePair ikv : list) {
if (ikv != null) {
addIdentifierKeyValuePair(listNode, ikv, ikv.getKey());
}
}
if (created) {
assetInfoNode.addComponent(listNode);
}
} catch (Throwable ex) {
logger.error("addSpecificAssetIds Exception", ex);
throw ex;
}
}
use of io.adminshell.aas.v3.model.IdentifierKeyValuePair in project FAAAST-Service by FraunhoferIOSB.
the class RequestMappingManagerTest method testGetAllAssetAdministrationShellsByAssetId.
@Test
public void testGetAllAssetAdministrationShellsByAssetId() throws SerializationException, InvalidRequestException {
List<IdentifierKeyValuePair> assetIds = Arrays.asList(new DefaultIdentifierKeyValuePair.Builder().key(GLOBAL_ASSET_ID).value(AAS.getAssetInformation().getGlobalAssetId().getKeys().get(0).getValue()).build());
Request expected = GetAllAssetAdministrationShellsByAssetIdRequest.builder().outputModifier(OutputModifier.DEFAULT).assetIds(assetIds).build();
Request actual = mappingManager.map(HttpRequest.builder().method(HttpMethod.GET).path("shells").query("assetIds=" + EncodingHelper.base64UrlEncode(serializer.write(assetIds))).build());
Assert.assertEquals(expected, actual);
}
Aggregations