From 48bc2df0347463c17b3ae41453745d9bc4653bac Mon Sep 17 00:00:00 2001 From: Eric Maslowski Date: Mon, 9 Sep 2024 00:14:01 -0400 Subject: [PATCH] FixingSVX version info when generating scenes (manual) (new) AssetVersion.fetchActiveVoyagerSceneFromScene gets SVX scene attached to current version (fix) using latest Voyager release (fix) removed obsolete Asset.fetchVoyagerSceneFromScene --- .../DetailsView/DetailsThumbnail.tsx | 2 +- server/db/api/Asset.ts | 14 ------ server/db/api/AssetVersion.ts | 24 +++++++++ .../workflow/impl/Packrat/WorkflowEngine.ts | 49 ++++++++----------- 4 files changed, 45 insertions(+), 44 deletions(-) diff --git a/client/src/pages/Repository/components/DetailsView/DetailsThumbnail.tsx b/client/src/pages/Repository/components/DetailsView/DetailsThumbnail.tsx index 9d014c33d..542bbe8d0 100644 --- a/client/src/pages/Repository/components/DetailsView/DetailsThumbnail.tsx +++ b/client/src/pages/Repository/components/DetailsView/DetailsThumbnail.tsx @@ -80,7 +80,7 @@ function DetailsThumbnail(props: DetailsThumbnailProps): React.ReactElement { document.head.appendChild(css); const script = document.createElement('script'); - script.src = 'https://www.egofarms.com/temp/voyager-story-test.min.js'; //TODO: replace with config once bug fix applied: Config.voyager.storyJS; + script.src = Config.voyager.storyJS; script.async = true; document.body.appendChild(script); diff --git a/server/db/api/Asset.ts b/server/db/api/Asset.ts index 8436504de..074b51a29 100644 --- a/server/db/api/Asset.ts +++ b/server/db/api/Asset.ts @@ -171,20 +171,6 @@ export class Asset extends DBC.DBObject implements AssetBase, SystemO `,Asset); } - static async fetchVoyagerSceneFromScene(idScene: number): Promise { - // get the voyager scene asset associated with the Packrat scene (if any) - // TODO: get asset type id from VocabularyID - const idvAssetType: number = 137; - - return DBC.CopyArray( - await DBC.DBConnection.prisma.$queryRaw` - SELECT a.* FROM Scene AS scn - JOIN SystemObject AS scnSO ON scn.idScene = scnSO.idScene - JOIN Asset AS a ON a.idSystemObject = scnSO.idSystemObject - WHERE scn.idScene = ${idScene} AND a.idVAssetType = ${idvAssetType}; - `,Asset); - } - /** Fetches assets that are connected to the specified idSystemObject (via that object's last SystemObjectVersion, * and that SystemObjectVersionAssetVersionXref's records). For those assets, we look for a match on FileName, idVAssetType */ static async fetchMatching(idSystemObject: number, FileName: string, idVAssetType: number): Promise { diff --git a/server/db/api/AssetVersion.ts b/server/db/api/AssetVersion.ts index 1e2e7b7c6..b7e25f99c 100644 --- a/server/db/api/AssetVersion.ts +++ b/server/db/api/AssetVersion.ts @@ -356,6 +356,30 @@ export class AssetVersion extends DBC.DBObject implements Asse } } + /** Fetches the the active asset version that is being used by the given scene for Voyager SVX scene */ + static async fetchActiveVoyagerSceneFromScene(idScene: number): Promise { + try { + // get the (active) voyager scene asset associated with the Packrat scene (if any) + // TODO: get asset type id from VocabularyID + const idvAssetType: number = 137; + const assetVersion: AssetVersion[] | null = DBC.CopyArray( + await DBC.DBConnection.prisma.$queryRaw` + SELECT * FROM Scene AS scn + JOIN SystemObject AS scnSO ON (scnSO.idScene=scn.idScene) + JOIN SystemObjectVersion AS scnSOV ON (scnSOV.idSystemObject=scnSO.idSystemObject) + JOIN SystemObjectVersionAssetVersionXref as sovAssetXref ON (sovAssetXref.idSystemObjectVersion=scnSOV.idSystemObjectVersion) + JOIN AssetVersion AS av ON (av.idAssetVersion=sovAssetXref.idAssetVersion) + JOIN Asset AS a ON (a.idAsset=av.idAsset AND a.idVAssetType=${idvAssetType}) + WHERE scn.idScene=${idScene} + ORDER BY scnSOV.DateCreated DESC + LIMIT 1`,AssetVersion); + return (!assetVersion || assetVersion.length===0) ? null : assetVersion[0]; + } catch (error) /* istanbul ignore next */ { + LOG.error('DBAPI.AssetVersion.fetchVoyagerSceneFromScene', LOG.LS.eDB, error); + return null; + } + } + static async fetchFromUser(idUserCreator: number): Promise { if (!idUserCreator) return null; diff --git a/server/workflow/impl/Packrat/WorkflowEngine.ts b/server/workflow/impl/Packrat/WorkflowEngine.ts index a55608d9b..3e4de37ac 100644 --- a/server/workflow/impl/Packrat/WorkflowEngine.ts +++ b/server/workflow/impl/Packrat/WorkflowEngine.ts @@ -324,6 +324,12 @@ export class WorkflowEngine implements WF.IWorkflowEngine { async generateScene(idModel: number, idScene: number | null, workflowParams: WF.WorkflowParameters): Promise { LOG.info(`WorkflowEngine.generateScene (idModel: ${idModel} | idScene: ${idScene} | params: ${H.Helpers.JSONStringify(workflowParams)})`,LOG.LS.eDEBUG); + // making sure we didn't make it here but user wanted to skip generation + // if (workflowParams.parameters.skipSceneGenerate===true) { + // LOG.info(`WorkflowEngine.eventIngestionIngestObjectModel skipping si-voyager-scene per user instruction (idModel: ${idModel} | idSO: ${workflowParams.idSystemObject})`, LOG.LS.eWF); + // return { success: false, message: 'skipped generating scene per user request', data: { isValid: false } }; + // } + //#region check for duplicate jobs // make sure we don't have any jobs running. >0 if a running job was found. const activeJobs: DBAPI.JobRun[] | null = await DBAPI.JobRun.fetchActiveByModel(8,idModel); @@ -378,20 +384,12 @@ export class WorkflowEngine implements WF.IWorkflowEngine { return { success: false, message: 'cannot get model Asset', data: { isValid: false } }; const modelAsset: DBAPI.Asset = modelAssets[0]; - // get our asset and version used by the model - // const { success, asset, assetVersion } = await this.computeAssetAndVersion(modelSO.idSystemObject); - // if (!success || !asset || !assetVersion || !asset.idSystemObject) { - // LOG.error(`WorkflowEngine.generateScene cannot get model asset and version (idModel: ${idModel} | idSystemObject: ${modelSO.idSystemObject})`, LOG.LS.eDB); - // return { success: false, message: 'cannot get model asset and version', data: { isValid: false } }; - // } - // get model info const CMIR: ComputeModelInfoResult | undefined = await this.computeModelInfo(idModel, modelAsset.idSystemObject ?? -1); if (!CMIR || CMIR.exitEarly || CMIR.assetVersionGeometry === undefined) { LOG.error(`WorkflowEngine.generateScene cannot compute model info (idModel: ${idModel} | CMIR: ${H.Helpers.JSONStringify(CMIR)})`, LOG.LS.eWF); return { success: false, message: 'cannot get model info', data: { isValid: false } }; } - // console.log(H.Helpers.JSONStringify(CMIR)); // bail if no units defined if(CMIR.units ===undefined) { @@ -423,9 +421,6 @@ export class WorkflowEngine implements WF.IWorkflowEngine { //#region scene // if we have a scene get it and a reference to the SVX so it can be fed in as a parameter - // TODO: if no scene then we need to create one for this Model and hook it up - // TODO: determine if we have an SVX file that is of different basename and bail/fix it - // so it passes validation when returned from Cook. let scene: DBAPI.Scene | null = null; // if we received an id for the scene, use it @@ -452,27 +447,23 @@ export class WorkflowEngine implements WF.IWorkflowEngine { // if we don't have a scene then the model may have just been ingested const svxFilename: string = sceneBaseName + '.svx.json'; if(scene) { - // get SVX from the scene - const svxAsset: DBAPI.Asset[] | null = await DBAPI.Asset.fetchVoyagerSceneFromScene(scene.idScene); - if(!svxAsset || svxAsset.length===0) - console.log(`No SVX found for scene ${scene.idScene} (idModel: ${idModel})`); + // get the asset version for the active voyager scene. only returns the most recent and does not support + // multiple SVX files for a single scene + const svxAssetVersion: DBAPI.AssetVersion | null = await DBAPI.AssetVersion.fetchActiveVoyagerSceneFromScene(scene.idScene); + if(!svxAssetVersion) + LOG.info(`WorkflowEngine.generateScene no active SVX file found for scene ${scene.idScene} (idModel: ${idModel})`,LOG.LS.eWF); else { // compare filenames. if a match then add it to staged resources. otherwise, fail - if(svxAsset[0].FileName !== svxFilename) - console.log(`basenames do not match. (${svxAsset[0].FileName} -> ${svxFilename})`); + // TODO: fix the naming? + if(svxAssetVersion.FileName !== svxFilename) + LOG.info(`WorkflowEngine.generateScene basenames do not match. (${svxAssetVersion.FileName} -> ${svxFilename})`,LOG.LS.eWF); else { - // get our last version - const svxAssetVersion: DBAPI.AssetVersion | null = await DBAPI.AssetVersion.fetchLatestFromAsset(svxAsset[0].idAsset); - if(!svxAssetVersion) - console.log(`cannot get AssetVersion. (${svxAsset[0].idAsset})`); - else { - // grab our SystemObject since we need to feed it to the list of staged files - const svxAssetVersionSO: DBAPI.SystemObject | null = await svxAssetVersion.fetchSystemObject(); - if(!svxAssetVersionSO) - console.log(`cannot get SystemObject for asset version. (idAssetVersion: ${svxAssetVersion.idAssetVersion})`); - else - idSystemObjects.push(svxAssetVersionSO.idSystemObject); - } + // grab our SystemObject since we need to feed it to the list of staged files + const svxAssetVersionSO: DBAPI.SystemObject | null = await svxAssetVersion.fetchSystemObject(); + if(!svxAssetVersionSO) + LOG.info(`WorkflowEngine.generateScene cannot get SystemObject for asset version. (idAssetVersion: ${svxAssetVersion.idAssetVersion})`,LOG.LS.eWF); + else + idSystemObjects.push(svxAssetVersionSO.idSystemObject); } } }