MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-workbench / jsonParser

Function jsonParser

src/contexts/dbContext.tsx:287–381  ·  view source on GitHub ↗
(
    jsonFilePath: string,
    sqliteFilePath: string,
    preventNavigation?: boolean
  )

Source from the content-addressed store, hash-verified

285 }
286
287 function jsonParser(
288 jsonFilePath: string,
289 sqliteFilePath: string,
290 preventNavigation?: boolean
291 ) {
292 if (!sqliteFilePath || !jsonFilePath) {
293 console.error("Sqlite or json file path isn't valid:", sqliteFilePath);
294 return;
295 }
296
297 startImport();
298
299 // Create a new database when importing a json file (Delete any existing data in the sqlite file)
300 const newWorkbenchDB = new WorkbenchDB({
301 dbName: "workbench_db",
302 dbStoragePath: sqliteFilePath,
303 deleteExisting: true,
304 });
305
306 newWorkbenchDB.sync
307 .then(() =>
308 newWorkbenchDB.addFromJson(jsonFilePath, (progress: number) => {
309 updateLoadingStatus(progress);
310 })
311 )
312 .then(() => {
313 console.log("JSON parsing completed");
314
315 AddEntry({
316 json_path: jsonFilePath,
317 sqlite_path: sqliteFilePath,
318 opened_at: moment().format(),
319 });
320
321 newWorkbenchDB.sync
322 .then((db) => db.File.findOne({ where: { parent: "#" } }))
323 .then(async (root) => {
324 if (!root) {
325 console.error("Root:", root);
326 throw new Error("Root path not found !!!!");
327 }
328
329 const defaultPath = root.getDataValue("path");
330
331 await updateWorkbenchDB(newWorkbenchDB, sqliteFilePath);
332
333 if (defaultPath) {
334 updateCurrentPath(
335 defaultPath,
336 root.getDataValue("type") as PathType
337 );
338 }
339
340 // Update window title
341 const newlyImportedFileName = jsonFilePath
342 .split("\\")
343 .pop()
344 .split("/")

Callers 2

historyItemParserFunction · 0.85
WorkbenchDBProviderFunction · 0.85

Calls 10

addFromJsonMethod · 0.95
AddEntryFunction · 0.90
GetHistoryFunction · 0.90
RemoveEntryFunction · 0.90
startImportFunction · 0.85
updateWorkbenchDBFunction · 0.85
updateCurrentPathFunction · 0.85
changeRouteOnImportFunction · 0.85
abortImportFunction · 0.85
findOneMethod · 0.80

Tested by

no test coverage detected