Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event System Overhaul & Cleanup #539

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
413 changes: 206 additions & 207 deletions client/src/store/vocabulary.ts

Large diffs are not rendered by default.

853 changes: 425 additions & 428 deletions common/constants.ts

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions server/audit/impl/AuditEventGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class AuditEventGenerator {
case EVENT.eEventKey.eDBDelete: AuditType = eAuditType.eDBDelete; eventTopic = EVENT.eEventTopic.eDB; break;
case EVENT.eEventKey.eAuthLogin: AuditType = eAuditType.eAuthLogin; eventTopic = EVENT.eEventTopic.eAuth; break;
case EVENT.eEventKey.eAuthFailed: AuditType = eAuditType.eAuthFailed; eventTopic = EVENT.eEventTopic.eAuth; break;
case EVENT.eEventKey.eSceneQCd: AuditType = eAuditType.eSceneQCd; eventTopic = EVENT.eEventTopic.ePublish; break;
case EVENT.eEventKey.ePubSceneQCd: AuditType = eAuditType.ePubSceneQCd; eventTopic = EVENT.eEventTopic.ePublish; break;
case EVENT.eEventKey.eHTTPDownload: AuditType = eAuditType.eHTTPDownload; eventTopic = EVENT.eEventTopic.eHTTP; break;
case EVENT.eEventKey.eHTTPUpload: AuditType = eAuditType.eHTTPUpload; eventTopic = EVENT.eEventTopic.eHTTP; break;
}
Expand All @@ -62,7 +62,7 @@ export class AuditEventGenerator {
idAudit: 0
};

const data: EVENT.IEventData<EVENT.eEventKey, Audit> = {
const data: EVENT.IEventData<Audit> = {
eventDate,
key,
value,
Expand Down
6 changes: 3 additions & 3 deletions server/auth/framework/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import passport from './passport';

export { passport };
import passport from './passportImpl';
export { passport };
3 changes: 3 additions & 0 deletions server/cache/BaseCache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export class BaseCache {
protected static cacheBuildTries: number = 3;
}
8 changes: 4 additions & 4 deletions server/cache/LicenseCache.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as LOG from '../utils/logger';
// import * as H from '../utils/helpers';
import * as DBAPI from '../db';
import { CacheControl } from './CacheControl';
import { BaseCache } from './BaseCache';
import * as COMMON from '@dpo-packrat/common';

export class LicenseCache {
export class LicenseCache extends BaseCache {
private static singleton: LicenseCache | null = null;
private licenseMap: Map<number, DBAPI.License> = new Map<number, DBAPI.License>(); // map of idLicense -> License
private licenseEnumMap: Map<COMMON.eLicense, DBAPI.License> = new Map<COMMON.eLicense, DBAPI.License>(); // map of COMMON.eLicense -> License
Expand All @@ -13,10 +13,10 @@ export class LicenseCache {
// **************************
// Boilerplate Implementation
// **************************
private constructor() { }
private constructor() { super(); }

private async flushInternal(): Promise<void> {
for (let nTry: number = 1; nTry <= CacheControl.cacheBuildTries; nTry++) {
for (let nTry: number = 1; nTry <= BaseCache.cacheBuildTries; nTry++) {
/* istanbul ignore else */
if (await this.flushInternalWorker())
break;
Expand Down
8 changes: 4 additions & 4 deletions server/cache/SystemObjectCache.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as LOG from '../utils/logger';
import * as DBAPI from '../db';
import { CacheControl } from './CacheControl';
import { BaseCache } from './BaseCache';
import { SystemObject } from '../db';
import * as COMMON from '@dpo-packrat/common';

export class SystemObjectCache {
export class SystemObjectCache extends BaseCache {
private static singleton: SystemObjectCache | null = null;

private objectIDToSystemMap: Map<string, DBAPI.SystemObjectInfo> = new Map<string, DBAPI.SystemObjectInfo>(); // map of `${idObject}|${eDBObjectType}` -> { idSystemObject, Retired }
Expand All @@ -14,10 +14,10 @@ export class SystemObjectCache {
// **************************
// Boilerplate Implementation
// **************************
private constructor() { }
private constructor() { super(); }

private async flushInternal(): Promise<void> {
for (let nTry: number = 1; nTry <= CacheControl.cacheBuildTries; nTry++) {
for (let nTry: number = 1; nTry <= BaseCache.cacheBuildTries; nTry++) {
/* istanbul ignore else */
if (await this.flushInternalWorker())
break;
Expand Down
8 changes: 4 additions & 4 deletions server/cache/UserCache.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import * as LOG from '../utils/logger';
import * as DBAPI from '../db';
import { CacheControl } from './CacheControl';
import { BaseCache } from './BaseCache';
import { User } from '../db';

export class UserCache {
export class UserCache extends BaseCache {
private static singleton: UserCache | null = null;
private userMap: Map<number, DBAPI.User> = new Map<number, DBAPI.User>(); // map of { idUser, User }

// **************************
// Boilerplate Implementation
// **************************
private constructor() { }
private constructor() { super(); }

private async flushInternal(): Promise<void> {
for (let nTry: number = 1; nTry <= CacheControl.cacheBuildTries; nTry++) {
for (let nTry: number = 1; nTry <= BaseCache.cacheBuildTries; nTry++) {
/* istanbul ignore else */
if (await this.flushInternalWorker())
break;
Expand Down
16 changes: 4 additions & 12 deletions server/cache/VocabularyCache.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as LOG from '../utils/logger';
import { CacheControl } from './CacheControl';
import { BaseCache } from './BaseCache';
import { Vocabulary, VocabularySet, SystemObject } from '../db';
import * as COMMON from '@dpo-packrat/common';
import * as path from 'path';

export class VocabularyCache {
export class VocabularyCache extends BaseCache {
private static singleton: VocabularyCache | null = null;

private vocabMap: Map<number, Vocabulary> = new Map<number, Vocabulary>(); // map of Vocab ID -> Vocabulary object
Expand All @@ -21,10 +21,10 @@ export class VocabularyCache {
// **************************
// Boilerplate Implementation
// **************************
private constructor() { }
private constructor() { super(); }

private async flushInternal(): Promise<void> {
for (let nTry: number = 1; nTry <= CacheControl.cacheBuildTries; nTry++) {
for (let nTry: number = 1; nTry <= BaseCache.cacheBuildTries; nTry++) {
/* istanbul ignore else */
if (await this.flushInternalWorker())
break;
Expand Down Expand Up @@ -81,7 +81,6 @@ export class VocabularyCache {
case 'Asset.AssetType': eVocabSetEnum = COMMON.eVocabularySetID.eAssetAssetType; break;
case 'Job.JobType': eVocabSetEnum = COMMON.eVocabularySetID.eJobJobType; break;
case 'Workflow.Type': eVocabSetEnum = COMMON.eVocabularySetID.eWorkflowType; break;
case 'Workflow.Event': eVocabSetEnum = COMMON.eVocabularySetID.eWorkflowEvent; break;
case 'Edan.3DResourceAttributeUnits': eVocabSetEnum = COMMON.eVocabularySetID.eEdan3DResourceAttributeUnits; break;
case 'Edan.3DResourceAttributeModelFileType': eVocabSetEnum = COMMON.eVocabularySetID.eEdan3DResourceAttributeModelFileType; break;
case 'Edan.3DResourceAttributeFileType': eVocabSetEnum = COMMON.eVocabularySetID.eEdan3DResourceAttributeFileType; break;
Expand Down Expand Up @@ -315,13 +314,6 @@ export class VocabularyCache {
}
} break;

case COMMON.eVocabularySetID.eWorkflowEvent: {
switch (vocabulary.Term) {
case 'Ingestion: Upload Asset Version': eVocabEnum = COMMON.eVocabularyID.eWorkflowEventIngestionUploadAssetVersion; break;
case 'Ingestion: Ingest Object': eVocabEnum = COMMON.eVocabularyID.eWorkflowEventIngestionIngestObject; break;
}
} break;

case COMMON.eVocabularySetID.eEdan3DResourceAttributeUnits: {
switch (vocabulary.Term) {
case 'mm': eVocabEnum = COMMON.eVocabularyID.eEdan3DResourceAttributeUnitsmm; break;
Expand Down
10 changes: 0 additions & 10 deletions server/collections/impl/EdanCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import * as CACHE from '../../cache';
import * as LOG from '../../utils/logger';
import * as H from '../../utils/helpers';
import * as COMMON from '@dpo-packrat/common';
import { EdanLicenseInfo } from '../interface';

interface HttpRequestResult {
output: string;
Expand Down Expand Up @@ -370,14 +369,5 @@ export class EdanCollection implements COL.ICollection {
};
}
}

static computeLicenseInfo(licenseText?: string | undefined, licenseCodes?: string | undefined, usageText?: string | undefined): EdanLicenseInfo {
const access: string = (licenseText && licenseText.toLowerCase() === 'cc0, publishable w/ downloads') ? 'CC0' : 'Usage conditions apply';
return {
access,
codes: licenseCodes ?? '',
text: usageText ?? '',
};
}
// #endregion
}
28 changes: 22 additions & 6 deletions server/collections/impl/PublishScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import * as H from '../../utils/helpers';
import * as ZIP from '../../utils/zipStream';
import * as STORE from '../../storage/interface';
import * as WF from '../../workflow/interface';
import * as EVENT from '../../event/interface';
import { SvxReader } from '../../utils/parser';
import { IDocument } from '../../types/voyager';
import * as COMMON from '@dpo-packrat/common';
import { EdanCollection } from './EdanCollection';
import { EdanLicenseInfo } from '../interface';

import { v4 as uuidv4 } from 'uuid';
import path from 'path';
Expand Down Expand Up @@ -110,7 +111,7 @@ export class PublishScene {
const LR: DBAPI.LicenseResolver | undefined = await CACHE.LicenseCache.getLicenseResolver(this.idSystemObject);
if (!await this.updatePublishedState(LR, ePublishedStateIntended))
return false;
const media_usage: COL.EdanLicenseInfo = EdanCollection.computeLicenseInfo(LR?.License?.Name); // eslint-disable-line camelcase
const media_usage: COL.EdanLicenseInfo = PublishScene.computeLicenseInfo(LR?.License?.Name); // eslint-disable-line camelcase

const { status, publicSearch, downloads } = this.computeEdanSearchFlags(edanRecord, ePublishedStateIntended);
const haveDownloads: boolean = (this.edan3DResourceList.length > 0);
Expand Down Expand Up @@ -305,10 +306,16 @@ export class PublishScene {
if (newDownloadState) {
LOG.info(`PublishScene.handleSceneUpdates generating downloads for scene ${idScene}`, LOG.LS.eGQL);
// Generate downloads
const workflowEngine: WF.IWorkflowEngine | null = await WF.WorkflowFactory.getInstance();
if (!workflowEngine)
return PublishScene.sendResult(false, `Unable to fetch workflow engine for download generation for scene ${idScene}`);
workflowEngine.generateSceneDownloads(idScene, { idUserInitiator: idUser }); // don't await
const eventEngine: EVENT.IEventEngine | null = await EVENT.EventFactory.getInstance();
if (!eventEngine)
return PublishScene.sendResult(false, `Unable to fetch event engine for download generation for scene ${idScene}`);
const data: EVENT.IEventData<{ idScene: number, workflowParams: WF.WorkflowParameters }> = {
eventDate: new Date(),
key: EVENT.eEventKey.eWFGenerateSceneDownloads,
value: { idScene, workflowParams: { idUserInitiator: idUser } }
};

eventEngine.send(EVENT.eEventTopic.eWF, [data]);
return { success: true, downloadsGenerated: true, downloadsRemoved: false };
} else { // Remove downloads
LOG.info(`PublishScene.handleSceneUpdates removing downloads for scene ${idScene}`, LOG.LS.eGQL);
Expand Down Expand Up @@ -748,4 +755,13 @@ export class PublishScene {
LOG.info(`PublishScene.computeEdanSearchFlags(${COMMON.ePublishedState[eState]}) = { status ${status}, publicSearch ${publicSearch}, downloads ${downloads} }`, LOG.LS.eCOLL);
return { status, publicSearch, downloads };
}

static computeLicenseInfo(licenseText?: string | undefined, licenseCodes?: string | undefined, usageText?: string | undefined): EdanLicenseInfo {
const access: string = (licenseText && licenseText.toLowerCase() === 'cc0, publishable w/ downloads') ? 'CC0' : 'Usage conditions apply';
return {
access,
codes: licenseCodes ?? '',
text: usageText ?? '',
};
}
}
2 changes: 1 addition & 1 deletion server/db/api/Audit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class Audit extends DBC.DBObject<AuditBase> implements AuditBase {
case eAuditType.eDBDelete:
case eAuditType.eAuthLogin:
case eAuditType.eAuthFailed:
case eAuditType.eSceneQCd:
case eAuditType.ePubSceneQCd:
case eAuditType.eHTTPDownload:
case eAuditType.eHTTPUpload:
return this.AuditType; /* istanbul ignore next */
Expand Down
16 changes: 10 additions & 6 deletions server/db/api/JobRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class JobRun extends DBC.DBObject<JobRunBase> implements JobRunBase {
Parameters!: string | null;
Output!: string | null;
Error!: string | null;
Step!: string | null;

constructor(input: JobRunBase) {
super(input);
Expand All @@ -36,7 +37,8 @@ export class JobRun extends DBC.DBObject<JobRunBase> implements JobRunBase {
Configuration: jobRunBase.Configuration,
Parameters: jobRunBase.Parameters,
Output: jobRunBase.Output,
Error: jobRunBase.Error
Error: jobRunBase.Error,
Step: jobRunBase.Step,
});
}

Expand All @@ -45,9 +47,9 @@ export class JobRun extends DBC.DBObject<JobRunBase> implements JobRunBase {

protected async createWorker(): Promise<boolean> {
try {
const { idJob, Status, Result, DateStart, DateEnd, Configuration, Parameters, Output, Error } = this;
const { idJob, Status, Result, DateStart, DateEnd, Configuration, Parameters, Output, Error, Step } = this;
({ idJobRun: this.idJobRun, idJob: this.idJob, Status: this.Status, Result: this.Result, DateStart: this.DateStart, DateEnd: this.DateEnd,
Configuration: this.Configuration, Parameters: this.Parameters, Output: this.Output, Error: this.Error } =
Configuration: this.Configuration, Parameters: this.Parameters, Output: this.Output, Error: this.Error, Step: this.Step } =
await DBC.DBConnection.prisma.jobRun.create({
data: {
Job: { connect: { idJob }, },
Expand All @@ -58,7 +60,8 @@ export class JobRun extends DBC.DBObject<JobRunBase> implements JobRunBase {
Configuration,
Parameters,
Output,
Error
Error,
Step
}
}));
return true;
Expand All @@ -70,7 +73,7 @@ export class JobRun extends DBC.DBObject<JobRunBase> implements JobRunBase {

protected async updateWorker(): Promise<boolean> {
try {
const { idJobRun, idJob, Status, Result, DateStart, DateEnd, Configuration, Parameters, Output, Error } = this;
const { idJobRun, idJob, Status, Result, DateStart, DateEnd, Configuration, Parameters, Output, Error, Step } = this;
return await DBC.DBConnection.prisma.jobRun.update({
where: { idJobRun, },
data: {
Expand All @@ -82,7 +85,8 @@ export class JobRun extends DBC.DBObject<JobRunBase> implements JobRunBase {
Configuration,
Parameters,
Output,
Error
Error,
Step
}
}) ? true : /* istanbul ignore next */ false;
} catch (error) /* istanbul ignore next */ {
Expand Down
2 changes: 1 addition & 1 deletion server/db/api/ObjectType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ export enum eAuditType {
eDBUpdate = 2,
eDBDelete = 3,
eAuthLogin = 4,
eSceneQCd = 5,
ePubSceneQCd = 5,
eHTTPDownload = 6,
eHTTPUpload = 7,
eAuthFailed = 8,
Expand Down
4 changes: 2 additions & 2 deletions server/db/api/Scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class Scene extends DBC.DBObject<SceneBase> implements SceneBase, SystemO

// Audit if someone marks this scene as QC'd
if (ApprovedForPublication)
this.audit(eEventKey.eSceneQCd); // don't await, allow this to continue asynchronously
this.audit(eEventKey.ePubSceneQCd); // don't await, allow this to continue asynchronously
return true;
} catch (error) /* istanbul ignore next */ {
return this.logError('create', error);
Expand All @@ -82,7 +82,7 @@ export class Scene extends DBC.DBObject<SceneBase> implements SceneBase, SystemO

// Audit if someone marks this scene as QC'd
if (ApprovedForPublication && !ApprovedForPublicationOrig)
this.audit(eEventKey.eSceneQCd); // don't await, allow this to continue asynchronously
this.audit(eEventKey.ePubSceneQCd); // don't await, allow this to continue asynchronously
return retValue;
} catch (error) /* istanbul ignore next */ {
return this.logError('update', error);
Expand Down
3 changes: 2 additions & 1 deletion server/db/api/composite/LicenseResolver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { License, LicenseAssignment } from '../..';
import { eObjectGraphMode, ObjectGraph } from './ObjectGraph';
import { ObjectGraph } from './ObjectGraph';
import { eObjectGraphMode } from './ObjectGraphMode';
import { ObjectGraphDatabase } from './ObjectGraphDatabase';
import { ObjectGraphDataEntry } from './ObjectGraphDataEntry';
import * as LOG from '../../../utils/logger';
Expand Down
3 changes: 2 additions & 1 deletion server/db/api/composite/ObjectAncestors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import * as CACHE from '../../../cache';
import * as LOG from '../../../utils/logger';
import * as H from '../../../utils/helpers';

import { ObjectGraph, eObjectGraphMode } from './ObjectGraph';
import { ObjectGraph } from './ObjectGraph';
import { eObjectGraphMode } from './ObjectGraphMode';
import { ObjectGraphDatabase } from './ObjectGraphDatabase';
import { RepositoryPath } from '../../../types/graphql';
import * as COMMON from '@dpo-packrat/common';
Expand Down
13 changes: 4 additions & 9 deletions server/db/api/composite/ObjectGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { Actor, Asset, AssetVersion, CaptureData, Identifier, IntermediaryFile,
SystemObjectPairs, Unit } from '../..';
import * as LOG from '../../../utils/logger';
import * as L from 'lodash';
import { ObjectGraphDatabase } from './ObjectGraphDatabase';
import { ObjectGraphDatabaseBase } from './ObjectGraphDatabaseBase';
import { eObjectGraphMode } from './ObjectGraphMode';
import * as COMMON from '@dpo-packrat/common';

export type SystemObjectIDType = {
Expand All @@ -12,12 +13,6 @@ export type SystemObjectIDType = {
eObjectType: COMMON.eSystemObjectType;
};

export enum eObjectGraphMode {
eAncestors,
eDescendents,
eAll
}

export type ObjectGraphSubjectIdentifier = {
idSubject: number;
idAssetThumbnail: number | null;
Expand Down Expand Up @@ -73,9 +68,9 @@ export class ObjectGraph {
systemObjectList: number[] = []; // array of idSystemObjects to be processed
systemObjectProcessed: Map<number, SystemObjectIDType> = new Map<number, SystemObjectIDType>(); // map from idSystemObject -> { idSystemObject, id of database object, type of database object}
systemObjectAdded: Map<number, SystemObjectIDType> = new Map<number, SystemObjectIDType>(); // map from idSystemObject -> { idSystemObject, id of database object, type of database object}
objectGraphDatabase: ObjectGraphDatabase | null = null; // non-null means we'll record relationship and hierarchy data in this object
objectGraphDatabase: ObjectGraphDatabaseBase | null = null; // non-null means we'll record relationship and hierarchy data in this object

constructor(idSystemObject: number, eMode: eObjectGraphMode, depth: number = 32, objectGraphDatabase: ObjectGraphDatabase | null = null) {
constructor(idSystemObject: number, eMode: eObjectGraphMode, depth: number = 32, objectGraphDatabase: ObjectGraphDatabaseBase | null = null) {
this.idSystemObject = idSystemObject;
this.eMode = eMode;
this.depth = depth;
Expand Down
Loading