Skip to content

Commit

Permalink
progress checkin
Browse files Browse the repository at this point in the history
  • Loading branch information
per305 authored and per305 committed Apr 29, 2022
1 parent d928b7f commit 547940e
Show file tree
Hide file tree
Showing 3 changed files with 324 additions and 0 deletions.
39 changes: 39 additions & 0 deletions scripts/RestClient/nesp/cleanNespDocuments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
var projectIdArr = ['c713e4f1-c57f-4040-9093-24f9aed39ac5','17e82227-aee5-4fbf-adaa-50a0469847e7']

db.document.update({$and:[{"projectId": {$in: projectIdArr}},{"contentType": "application/pdf"}]},{$set:{"status": "deleted"}},{multi: true})

var documents = db.document.find({"projectId":{$in:projectIdArr}})

var document = ""
var projectId = ""
var documentId = ""
var path = ""
var record = ""

var rows = []

while (documents.hasNext()) {
document = documents.next();

projectId = document.projectId;
documentId = document.documentId;
path = document.filepath;

record = projectId + "," + documentId + "," + path

rows.push(record)
}

let csvContent = "data:text/csv;charset=utf-8,";

rows.forEach(function(row) {
csvContent += row.join(',');
csvContent += "\n";
});

console.log(csvContent);

var encodedUri = encodeURI(csvContent);
window.open(encodedUri);

print("documentResult"+documentResult)
136 changes: 136 additions & 0 deletions scripts/RestClient/nesp/twqArtefcats/document.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
//document js
var document =
{
"labels" : [ ],
"dateCreated" : "",
"lastUpdated" : "",
"isPrimaryProjectImage" : false,
"documentId" : "",
"filepath" : "2022-04",
"thirdPartyConsentDeclarationMade" : false,
"projectActivityId" : "",
"role" : "",
"name" : "",
"type" : "application",
"status" : "active",
"filename" : "",
"isSciStarter" : false,
"projectId" : "",
"description" : "",
"readOnly" : false,
"filesize" : "",
"contentType" : "",
"citation" : "",
"doiLink" : "",
"public": true,
"embeddedVideo": ""
}


/*
var document =
{
"documentId" : "",
"filename" : "",
"filepath" : "2021-02",
"isPrimaryProjectImage" : true,
"isSciStarter" : false,
"labels" : [ ],
"name" : "",
"projectId" : "",
"role" : "mainImage",
"status" : "active",
"thirdPartyConsentDeclarationMade" : false,
"type" : "image",
"lng" : "",
"filesize" : 104117,
"public" : true,
"contentType" : "image/jpeg",
"lat" : "",
"projectActivityId" : "",
"roles" : [
{
"name" : "Information",
"id" : "information"
},
{
"name" : "Embedded Video",
"id" : "embeddedVideo"
},
{
"name" : "Exceedance Report",
"id" : "exceedanceReport"
},
{
"name" : "Photo",
"id" : "photo"
},
{
"name" : "Project Plan / Work plan",
"id" : "projectPlan"
},
{
"name" : "Project Variation",
"id" : "projectVariation"
},
{
"name" : "Project Highlight Report",
"id" : "projectHighlightReport"
},
{
"name" : "Other Project document",
"id" : "other"
}
],
"fileReady" : true,
"thirdPartyConsentDeclarationRequired" : true,
"embeddedVideoVisible" : false,
"settings" : {
"thirdPartyDeclarationTextSelector" : "#thirdPartyDeclarationText",
"roles" : [
{
"name" : "Information",
"id" : "information"
},
{
"name" : "Embedded Video",
"id" : "embeddedVideo"
},
{
"name" : "Exceedance Report",
"id" : "exceedanceReport"
},
{
"name" : "Photo",
"id" : "photo"
},
{
"name" : "Project Plan / Work plan",
"id" : "projectPlan"
},
{
"name" : "Project Variation",
"id" : "projectVariation"
},
{
"name" : "Project Highlight Report",
"id" : "projectHighlightReport"
},
{
"name" : "Other Project document",
"id" : "other"
}
],
"showSettings" : true,
"imageLocation" : "/assets/"
},
"hasPreview" : false,
"fileButtonText" : "Change file",
"readOnly" : false,
"saveHelp" : "You must accept the Privacy Declaration before an image can be made viewable by everyone",
"fileLabel" : "",
"progress" : 0,
"complete" : false,
"saveEnabled" : false
};
*/
149 changes: 149 additions & 0 deletions scripts/RestClient/nesp/twqArtefcats/documentImport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
//document upload scripts
var path = '';
load(path + "document.js")
load(path + 'uuid.js');

print("Loaded all dependent files...");

var hub_name = 0;
var projectId = hub_name + 1;
var title = projectId + 1;
var description = title + 1;
var documentUrl = description + 1;
var doiLink = documentUrl + 1;
var role = doiLink + 1;
var citation = role + 1;
var keywords = citation + 1;
var embeddedVideo = keywords + 1;

var csvData = cat(path+'NESP_MARINE_ARTEFACTS_FOR_TEST.txt');
print("Loaded csv file");
var csvRows = csvData.split('\r');
print("Total rows "+ csvRows.length);

for(var i = 1; i < csvRows.length; i++) {
print("PRINT "+csvRows.length)

var row = csvRows[i];
var fields = row.split('\t');

if(fields[projectId]) {
document.projectId = fields[projectId]
document.documentId = UUID.generate()
document.description = ""
document.name = ""
document.filename = ""
document.contentType = ""
document.doiLink = ""
document.role = ""
document.citation = ""
document.labels = []
document.embeddedVideo = ""

//When there are commas/ double quotations, tsv adds double quotes in the beginning and end of text, following string
//manipulations are done to avoid that

if (fields[title]) {
if ((fields[title].indexOf(',') != -1) || (fields[title].indexOf('"') != -1)) {
var tempTitle = fields[title].replace(/""/g, '"');
document.name = tempTitle.substring(1, tempTitle.length - 1);
}
else {
document.name = fields[title]
}
}

if (fields[description]) {
if ((fields[description].indexOf(',') != -1) || (fields[description].indexOf('"') != -1)) {
var tempDescription = fields[description].replace(/""/g, '"');
document.description = tempDescription.substring(1, tempDescription.length - 1);
}
else {
document.description = fields[description]
}
}

if (fields[documentUrl]) {
var docUrl = fields[documentUrl]
var urlSplitBySlash = docUrl.split('/')
var fileName = urlSplitBySlash[urlSplitBySlash.length - 1]

var contentType = ""

if (fileName.endsWith(".pdf")) {
contentType = "application/pdf"
} else if (fileName.endsWith(".doc") || fileName.endsWith(".docx")) {
contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
}

document.filename = fileName
document.contentType = contentType
}

if (fields[doiLink]) {
if ((fields[doiLink].indexOf(',') != -1) || (fields[doiLink].indexOf('"') != -1)) {
var tempDoi = fields[doiLink].replace(/""/g, '"');
document.doiLink = tempDoi.substring(1, tempDoi.length - 1);
}
else {
document.doiLink = fields[doiLink]
}
}

if (fields[role]) {
document.role = fields[role]
}

if (fields[citation]) {
if ((fields[citation].indexOf(',') != -1) || (fields[citation].indexOf('"') != -1)) {
var tempCitation = fields[citation].replace(/""/g, '"');
document.citation = tempCitation.substring(1, tempCitation.length - 1);
}
else {
document.citation = fields[citation]
}
}

if (fields[keywords]) {
if ((fields[keywords].indexOf(',') != -1) || (fields[keywords].indexOf('"') != -1)) {
var tempKeywords = fields[keywords].replace(/""/g, '"');
var tempKeywordsStr = tempKeywords.substring(1, tempKeywords.length - 1);
var tempKeywordsArr = tempKeywordsStr.split(',');

document.labels = tempKeywordsArr;
}
else {
document.labels.push(fields[keywords]);
}
}

if (fields[embeddedVideo]) {
if ((fields[embeddedVideo].indexOf(',') != -1) || (fields[embeddedVideo].indexOf('"') != -1)) {
var tempEmbeddedVideo = fields[embeddedVideo].replace(/""/g, '"');
document.embeddedVideo = tempEmbeddedVideo.substring(1, tempEmbeddedVideo.length - 1);
}
else {
document.embeddedVideo = fields[embeddedVideo]
}
}

var today = new ISODate();
var dd = today.getDate();
var mm = today.getMonth() + 1; //January is 0!
var yyyy = today.getFullYear();
var dateUTC = yyyy + "-" + ("0" + mm).slice(-2) + "-" + ("0" + dd).slice(-2) + "T00:00:00Z";

document.dateCreated = ISODate(dateUTC);
document.lastUpdated = ISODate(dateUTC);

var documentResult = db.document.insert(document);

print("PROJECT ID: " + document.projectId)
print("DOCUMENT ID: " + document.documentId)
print("FILE NAME: " + document.filename)
print("documentResult " + documentResult)
}
}

print("Created " + (i-1) + " documents");
print("<<<<<<<<<<<<<<<<<<<")

0 comments on commit 547940e

Please sign in to comment.