in source/packages/services/assetlibrary/src/devices/devices.full.dao.ts [131:222]
public async create(n:Node, groups:DirectionStringToArrayMap, devices:DirectionStringToArrayMap, components:Node[]): Promise<string> {
logger.debug(`devices.full.dao create: in: n:${JSON.stringify(n)}, groups:${groups}, devices:${JSON.stringify(devices)}, components:${components}`);
const id = `device___${n.attributes['deviceId']}`;
const labels = n.types.join('::');
/* create the device */
const conn = super.getConnection();
try {
const traversal = conn.traversal.addV(labels).
property(process.t.id, id);
/* set all the device properties */
for (const key of Object.keys(n.attributes)) {
if (n.attributes[key]!==undefined) {
traversal.property(process.cardinality.single, key, n.attributes[key]);
}
}
traversal.as('device');
/* associate with the groups */
if (groups) {
if (groups.in) {
Object.keys(groups.in).forEach(rel=> {
groups.in[rel].forEach(v=> {
const groupId = `group___${v}`;
traversal.V(groupId).addE(rel).to('device');
});
});
}
if (groups.out) {
Object.keys(groups.out).forEach(rel=> {
groups.out[rel].forEach(v=> {
const groupId = `group___${v}`;
traversal.V(groupId).addE(rel).from_('device');
});
});
}
}
/* associate with the devices */
if (devices) {
if (devices.in) {
Object.keys(devices.in).forEach(rel=> {
devices.in[rel].forEach(v=> {
const deviceId = `device___${v}`;
traversal.V(deviceId).addE(rel).to('device');
});
});
}
if (devices.out) {
Object.keys(devices.out).forEach(rel=> {
devices.out[rel].forEach(v=> {
const deviceId = `device___${v}`;
traversal.V(deviceId).addE(rel).from_('device');
});
});
}
}
/* create the components */
if (components) {
components.forEach(c=> {
const componentId = (c.attributes['deviceId'] as string);
const componentDbId = `${id}___${componentId}`;
const componentLabels = c.types.join('::');
traversal.addV(componentLabels).
property(process.t.id, componentDbId);
for (const key of Object.keys(c.attributes)) {
if (c.attributes[key]!==undefined) {
traversal.property(process.cardinality.single, key, c.attributes[key]);
}
}
traversal.as(componentId).
addE('component_of').from_(componentId).to('device');
});
}
logger.debug(`devices.full.dao create: traversal:${traversal}`);
await traversal.iterate();
} finally {
await conn.close();
}
logger.debug(`devices.full.dao create: exit: id:${id}`);
return id;
}