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

Feature/edan verifier utility #531

Draft
wants to merge 19 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export enum eVocabularyID {
eWorkflowTypeCookJob,
eWorkflowTypeIngestion,
eWorkflowTypeUpload,
eWorkflowTypeVerifier, // ADDED: EM (2023-01-28)
eWorkflowStepTypeStart,
eWorkflowEventIngestionUploadAssetVersion,
eWorkflowEventIngestionIngestObject,
Expand Down
1 change: 1 addition & 0 deletions server/cache/VocabularyCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ export class VocabularyCache {
case 'Cook Job': eVocabEnum = COMMON.eVocabularyID.eWorkflowTypeCookJob; break;
case 'Ingestion': eVocabEnum = COMMON.eVocabularyID.eWorkflowTypeIngestion; break;
case 'Upload': eVocabEnum = COMMON.eVocabularyID.eWorkflowTypeUpload; break;
case 'Verifier': eVocabEnum = COMMON.eVocabularyID.eWorkflowTypeVerifier; break;
}
} break;

Expand Down
7 changes: 5 additions & 2 deletions server/db/api/WorkflowReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export class WorkflowReport extends DBC.DBObject<WorkflowReportBase> implements
idWorkflow!: number;
MimeType!: string;
Data!: string;
Name!: string | null;
EMaslowskiQ marked this conversation as resolved.
Show resolved Hide resolved

constructor(input: WorkflowReportBase) {
super(input);
Expand All @@ -18,14 +19,15 @@ export class WorkflowReport extends DBC.DBObject<WorkflowReportBase> implements

protected async createWorker(): Promise<boolean> {
try {
const { idWorkflow, MimeType, Data } = this;
const { idWorkflow, MimeType, Data, Name } = this;
({ idWorkflowReport: this.idWorkflowReport, idWorkflow: this.idWorkflow, MimeType: this.MimeType,
Data: this.Data } =
await DBC.DBConnection.prisma.workflowReport.create({
data: {
Workflow: { connect: { idWorkflow }, },
MimeType,
Data,
Name,
},
}));
return true;
Expand All @@ -36,13 +38,14 @@ export class WorkflowReport extends DBC.DBObject<WorkflowReportBase> implements

protected async updateWorker(): Promise<boolean> {
try {
const { idWorkflowReport, idWorkflow, MimeType, Data } = this;
const { idWorkflowReport, idWorkflow, MimeType, Data, Name } = this;
return await DBC.DBConnection.prisma.workflowReport.update({
where: { idWorkflowReport, },
data: {
Workflow: { connect: { idWorkflow }, },
MimeType,
Data,
Name,
},
}) ? true : /* istanbul ignore next */ false;
} catch (error) /* istanbul ignore next */ {
Expand Down
1 change: 1 addition & 0 deletions server/db/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,7 @@ model WorkflowReport {
idWorkflow Int
MimeType String @mariasql.VarChar(256)
Data String @mariasql.LongText
Name String? @mariasql.VarChar(255)
Workflow Workflow @relation(fields: [idWorkflow], references: [idWorkflow], onDelete: NoAction, onUpdate: NoAction, map: "fk_workflowreport_workflow1")

@@index([idWorkflow], map: "fk_workflowreport_workflow1")
Expand Down
Binary file modified server/db/sql/models/Packrat.mwb
Binary file not shown.
6 changes: 5 additions & 1 deletion server/db/sql/scripts/Packrat.ALTER.sql
Original file line number Diff line number Diff line change
Expand Up @@ -483,4 +483,8 @@ UPDATE Unit SET ARKPrefix = 'uj5' WHERE Abbreviation = 'OCIO';
-- 2022-11-11 Jon
ALTER TABLE ModelSceneXref MODIFY COLUMN `NAME` varchar(512) DEFAULT NULL;

-- 2022-11-11 Deployed to Staging and Production
-- 2022-11-11 Deployed to Staging and Production

-- 2023-01-29 Eric
INSERT INTO Vocabulary (idVocabularySet, SortOrder, Term) VALUES (22, 4, 'Verifier');
ALTER TABLE WorkflowRecord ADD 'Name' varchar(255);
1 change: 1 addition & 0 deletions server/db/sql/scripts/Packrat.DATA.sql
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ INSERT INTO Vocabulary (idVocabularySet, SortOrder, Term) VALUES (23, 1, 'Ingest
INSERT INTO Vocabulary (idVocabularySet, SortOrder, Term) VALUES (23, 2, 'Ingestion: Ingest Object');
INSERT INTO Vocabulary (idVocabularySet, SortOrder, Term) VALUES (22, 2, 'Ingestion');
INSERT INTO Vocabulary (idVocabularySet, SortOrder, Term) VALUES (22, 3, 'Upload');
INSERT INTO Vocabulary (idVocabularySet, SortOrder, Term) VALUES (22, 4, 'Verifier');
INSERT INTO Vocabulary (idVocabularySet, SortOrder, Term) VALUES (18, 2, 'Image');
INSERT INTO Vocabulary (idVocabularySet, SortOrder, Term) VALUES (24, 1, 'mm');
INSERT INTO Vocabulary (idVocabularySet, SortOrder, Term) VALUES (24, 2, 'cm');
Expand Down
1 change: 1 addition & 0 deletions server/db/sql/scripts/Packrat.SCHEMA.sql
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ CREATE TABLE IF NOT EXISTS `WorkflowReport` (
`idWorkflow` int(11) NOT NULL,
`MimeType` varchar(256) NOT NULL,
`Data` longtext NOT NULL,
`Name` varchar(256) DEFAULT NULL,
PRIMARY KEY (`idWorkflowReport`)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;

Expand Down
6 changes: 6 additions & 0 deletions server/http/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { Downloader, download } from './routes/download';
import { errorhandler } from './routes/errorhandler';
import { WebDAVServer } from './routes/WebDAVServer';

import * as VERIFIERS from './routes/verifiers';

import express, { Request, Express, RequestHandler } from 'express';
import cors from 'cors';
import { ApolloServer } from 'apollo-server-express';
Expand Down Expand Up @@ -87,6 +89,10 @@ export class HttpServer {
this.app.get(`${Downloader.httpRoute}*`, HttpServer.idRequestMiddleware2);
this.app.get(`${Downloader.httpRoute}*`, download);

// endpoints for verifiers.
this.app.get('/verifier',VERIFIERS.routeRequest); // catch in case of misuse
this.app.get('/verifier/:id', VERIFIERS.routeRequest);

const WDSV: WebDAVServer | null = await WebDAVServer.server();
if (WDSV) {
this.app.use(WebDAVServer.httpRoute, HttpServer.idRequestMiddleware2);
Expand Down
100 changes: 100 additions & 0 deletions server/http/routes/dataQueries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/* eslint-disable @typescript-eslint/no-unused-vars */

import { Request, Response } from 'express';
import * as H from '../../utils/helpers';
import * as LOG from '../../utils/logger';
import * as DBAPI from '../../db';

import GraphQLApi from '../../graphql';
import { GetSystemObjectDetailsInput, GetSystemObjectDetailsResult } from '../../types/graphql';

export async function routeRequest(request: Request, response: Response): Promise<void> {

const detailsToReturn = request.params.id;
console.warn(detailsToReturn+'|'+JSON.stringify(request.params));

// if nothing then complain
if(detailsToReturn===undefined) {
LOG.error('HTTP request: incorrect usage of endpoint', LOG.LS.eHTTP);
response.send('Request failed. Incorrect use of endpoint. Be sure to include what you are looking for');
return;
}

// handle the proper type
switch(detailsToReturn){
case 'systemObject': {
return await getSystemObjectDetails(request,response);
} break;

default: {
LOG.error(`HTTP request: unsupported request (${detailsToReturn})`, LOG.LS.eHTTP);
response.send(`Request failed. Unsupported request/path (${detailsToReturn})`);
}
}
}

// convenience routine routine for getting system object details to be used with routes.
// NOTE: not connected as it should not be 'live' until an API is created and protected
async function getSystemObjectDetails(req: Request, response: Response): Promise<void> {
// TODO: update to use direct call to getSystemObjectDetails (db/api/schema/systemobject/resolvers/queries/...)

// grab our config options from query params
const subjectLimit: number = (req.query.limit)?parseInt(req.query.limit as string):10000;
const systemObjectId: number = (req.query.objectId)?parseInt(req.query.objectId as string):-1;

// fetch all subjects from Packrat DB to get list of IDs
const systemObjects: DBAPI.SystemObject[] | null = await DBAPI.SystemObject.fetchAll(); /* istanbul ignore if */
if (!systemObjects) {
sendResponseMessage(response,false,'could not get system objects from DB');
return;
}
if(systemObjects.length<=0) {
sendResponseMessage(response,false,'no system objects found in DB');
return;
}
LOG.info(`Getting SystemObject Details processing ${systemObjects.length} ids`,LOG.LS.eGQL);

// loop through subjects, extract name, query from EDAN
const output: string[] = [];
for(let i=0; i<systemObjects.length; i++) {

if(i>=subjectLimit) break;

const idSystemObject: number = systemObjects[i].fetchID();
if(systemObjectId>0 && idSystemObject!=systemObjectId) continue;

const input: GetSystemObjectDetailsInput = {
idSystemObject
};
const graphQLApi = new GraphQLApi(true);
EMaslowskiQ marked this conversation as resolved.
Show resolved Hide resolved
const results: GetSystemObjectDetailsResult = await graphQLApi.getSystemObjectDetails(input);

// TODO: get asset details and inject into above results on 'asset' field
// getAssetDetailsForSystemObject()

// store our results
output.push(H.Helpers.JSONStringify(results));

// break;
}

// if we return the file then do so, overwriting any message
if(output.length>0) {
const name = 'SystemObjectDetails_'+new Date().toISOString().split('T')[0];
response.setHeader('Content-disposition', `attachment; filename=${name}.json`);
response.set('Content-Type', 'text/json');
response.statusMessage = 'Gathering system object details SUCCEEDED!';
response.status(200).send(output.join('\n'));
return;
}

const message = 'Getting system object details succeeded, but nothing to return.';
LOG.info(message,LOG.LS.eGQL);
sendResponseMessage(response,true,message);
return;
}

function sendResponseMessage(response: Response, success: boolean, message: string) {
LOG.error(`Getting data from database ${(success)?'SUCCEEDED':'FAILED'}: ${message}`, LOG.LS.eGQL);
response.send(`Getting data from database ${(success)?'SUCCEEDED':'FAILED'}: ${message}`);
}
14 changes: 13 additions & 1 deletion server/http/routes/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,19 @@ export class Downloader {
const mimeType: string = WFReports[0].MimeType;
const idWorkflowReport: number = WFReports[0].idWorkflowReport;

this.response.setHeader('Content-disposition', `inline; filename=WorkflowReport.${idWorkflowReport}.htm`);
// get/set our filename depending on if it's present or not
let filename: string = `WorkflowReport.${idWorkflowReport}`;
if(WFReports[0].Name) filename = WFReports[0].Name;

// add our extension based on mimeType
switch(mimeType) {
case 'text/html': filename += '.htm'; break;
case 'text/csv': filename += '.csv'; break;
default: filename += '.htm'; break;
}

// set our properties and configure the response
this.response.setHeader('Content-disposition', `inline; filename=${filename}`);
if (mimeType)
this.response.setHeader('Content-type', mimeType);
let first: boolean = true;
Expand Down
Loading