Skip to content

Commit

Permalink
bug fix: import parent endpoints (#1265)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulr34 authored Feb 14, 2024
1 parent 108fb3e commit 8faab07
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 20 deletions.
34 changes: 22 additions & 12 deletions src-electron/db/query-impexp.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,8 @@ const queryUpgrade = require('../matter/matter.js')
* @param {*} sessionId
* @param {*} endpoint
* @param {*} endpointTypeRef
* @param {*} parentRef
*/
async function importEndpoint(
db,
sessionId,
endpoint,
endpointTypeRef,
parentRef
) {
async function importEndpoint(db, sessionId, endpoint, endpointTypeRef) {
return dbApi.dbInsert(
db,
`
Expand All @@ -47,14 +40,12 @@ INSERT INTO ENDPOINT (
ENDPOINT_TYPE_REF,
PROFILE,
ENDPOINT_IDENTIFIER,
NETWORK_IDENTIFIER,
PARENT_ENDPOINT_REF
NETWORK_IDENTIFIER
) VALUES (
?,
?,
?,
?,
?,
?
)
`,
Expand All @@ -64,11 +55,29 @@ INSERT INTO ENDPOINT (
endpoint.profileId,
endpoint.endpointId,
endpoint.networkId,
parentRef,
]
)
}

/**
* Imports the parent endpoint
* @param {} db
* @param {*} sessionId
* @param {*} endpointId
* @param {*} parentRef
*/
async function importParentEndpoint(db, sessionRef, endpointId, parentRef) {
return dbApi.dbAll(
db,
`
UPDATE ENDPOINT
SET PARENT_ENDPOINT_REF = ?
WHERE ENDPOINT_IDENTIFIER = ? AND SESSION_REF = ?
`,
[parentRef, endpointId, sessionRef]
)
}

/**
* Extracts endpoints.
*
Expand Down Expand Up @@ -885,6 +894,7 @@ VALUES

exports.exportEndpointTypes = exportEndpointTypes
exports.importEndpointType = importEndpointType
exports.importParentEndpoint = importParentEndpoint

exports.exportClustersFromEndpointType = exportClustersFromEndpointType
exports.importClusterForEndpointType = importClusterForEndpointType
Expand Down
30 changes: 22 additions & 8 deletions src-electron/importexport/import-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,7 @@ async function importEndpointTypes(
const sortedEndpoints = sortEndpoints(endpoints)

if (endpointTypes != null) {
let parentRef
env.logDebug(`Loading ${endpointTypes.length} endpoint types`)
let deviceTypeSpecCheckComplianceMessage = ''
let clusterSpecCheckComplianceMessage = ''
Expand All @@ -1171,21 +1172,14 @@ async function importEndpointTypes(
endpointTypes[i]
)
let endpointId = ''
let parentRef
if (sortedEndpoints[i]) {
for (let j = 0; j < sortedEndpoints[i].length; j++) {
endpointId = sortedEndpoints[i][j].endpointId
parentRef = await queryEndpoint.getParentEndpointRef(
db,
sortedEndpoints[i][j].parentEndpointIdentifier,
sessionId
)
await queryImpexp.importEndpoint(
db,
sessionId,
sortedEndpoints[i][j],
endpointTypeId,
parentRef
endpointTypeId
)
}
}
Expand Down Expand Up @@ -1342,6 +1336,26 @@ async function importEndpointTypes(
specMessageIndent
)
}

//post processing - import parent endpoints
for (let i = 0; i < endpointTypes.length; i++) {
if (sortedEndpoints[i]) {
for (let j = 0; j < sortedEndpoints[i].length; j++) {
parentRef = await queryEndpoint.getParentEndpointRef(
db,
sortedEndpoints[i][j].parentEndpointIdentifier,
sessionId
)
await queryImpexp.importParentEndpoint(
db,
sessionId,
sortedEndpoints[i][j].endpointId,
parentRef
)
}
}
}

if (deviceTypeSpecCheckComplianceMessage.length > 0) {
deviceTypeSpecCheckComplianceMessage = dottedLine.concat(
deviceTypeSpecCheckComplianceFailureTitle,
Expand Down

0 comments on commit 8faab07

Please sign in to comment.