Skip to content

Commit 547940e

Browse files
per305per305
per305
authored and
per305
committed
progress checkin
1 parent d928b7f commit 547940e

File tree

3 files changed

+324
-0
lines changed

3 files changed

+324
-0
lines changed

Diff for: scripts/RestClient/nesp/cleanNespDocuments.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
var projectIdArr = ['c713e4f1-c57f-4040-9093-24f9aed39ac5','17e82227-aee5-4fbf-adaa-50a0469847e7']
2+
3+
db.document.update({$and:[{"projectId": {$in: projectIdArr}},{"contentType": "application/pdf"}]},{$set:{"status": "deleted"}},{multi: true})
4+
5+
var documents = db.document.find({"projectId":{$in:projectIdArr}})
6+
7+
var document = ""
8+
var projectId = ""
9+
var documentId = ""
10+
var path = ""
11+
var record = ""
12+
13+
var rows = []
14+
15+
while (documents.hasNext()) {
16+
document = documents.next();
17+
18+
projectId = document.projectId;
19+
documentId = document.documentId;
20+
path = document.filepath;
21+
22+
record = projectId + "," + documentId + "," + path
23+
24+
rows.push(record)
25+
}
26+
27+
let csvContent = "data:text/csv;charset=utf-8,";
28+
29+
rows.forEach(function(row) {
30+
csvContent += row.join(',');
31+
csvContent += "\n";
32+
});
33+
34+
console.log(csvContent);
35+
36+
var encodedUri = encodeURI(csvContent);
37+
window.open(encodedUri);
38+
39+
print("documentResult"+documentResult)

Diff for: scripts/RestClient/nesp/twqArtefcats/document.js

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
//document js
2+
var document =
3+
{
4+
"labels" : [ ],
5+
"dateCreated" : "",
6+
"lastUpdated" : "",
7+
"isPrimaryProjectImage" : false,
8+
"documentId" : "",
9+
"filepath" : "2022-04",
10+
"thirdPartyConsentDeclarationMade" : false,
11+
"projectActivityId" : "",
12+
"role" : "",
13+
"name" : "",
14+
"type" : "application",
15+
"status" : "active",
16+
"filename" : "",
17+
"isSciStarter" : false,
18+
"projectId" : "",
19+
"description" : "",
20+
"readOnly" : false,
21+
"filesize" : "",
22+
"contentType" : "",
23+
"citation" : "",
24+
"doiLink" : "",
25+
"public": true,
26+
"embeddedVideo": ""
27+
}
28+
29+
30+
/*
31+
var document =
32+
{
33+
"documentId" : "",
34+
"filename" : "",
35+
"filepath" : "2021-02",
36+
"isPrimaryProjectImage" : true,
37+
"isSciStarter" : false,
38+
"labels" : [ ],
39+
"name" : "",
40+
"projectId" : "",
41+
"role" : "mainImage",
42+
"status" : "active",
43+
"thirdPartyConsentDeclarationMade" : false,
44+
"type" : "image",
45+
"lng" : "",
46+
"filesize" : 104117,
47+
"public" : true,
48+
"contentType" : "image/jpeg",
49+
"lat" : "",
50+
"projectActivityId" : "",
51+
"roles" : [
52+
{
53+
"name" : "Information",
54+
"id" : "information"
55+
},
56+
{
57+
"name" : "Embedded Video",
58+
"id" : "embeddedVideo"
59+
},
60+
{
61+
"name" : "Exceedance Report",
62+
"id" : "exceedanceReport"
63+
},
64+
{
65+
"name" : "Photo",
66+
"id" : "photo"
67+
},
68+
{
69+
"name" : "Project Plan / Work plan",
70+
"id" : "projectPlan"
71+
},
72+
{
73+
"name" : "Project Variation",
74+
"id" : "projectVariation"
75+
},
76+
{
77+
"name" : "Project Highlight Report",
78+
"id" : "projectHighlightReport"
79+
},
80+
{
81+
"name" : "Other Project document",
82+
"id" : "other"
83+
}
84+
],
85+
"fileReady" : true,
86+
"thirdPartyConsentDeclarationRequired" : true,
87+
"embeddedVideoVisible" : false,
88+
"settings" : {
89+
"thirdPartyDeclarationTextSelector" : "#thirdPartyDeclarationText",
90+
"roles" : [
91+
{
92+
"name" : "Information",
93+
"id" : "information"
94+
},
95+
{
96+
"name" : "Embedded Video",
97+
"id" : "embeddedVideo"
98+
},
99+
{
100+
"name" : "Exceedance Report",
101+
"id" : "exceedanceReport"
102+
},
103+
{
104+
"name" : "Photo",
105+
"id" : "photo"
106+
},
107+
{
108+
"name" : "Project Plan / Work plan",
109+
"id" : "projectPlan"
110+
},
111+
{
112+
"name" : "Project Variation",
113+
"id" : "projectVariation"
114+
},
115+
{
116+
"name" : "Project Highlight Report",
117+
"id" : "projectHighlightReport"
118+
},
119+
{
120+
"name" : "Other Project document",
121+
"id" : "other"
122+
}
123+
],
124+
"showSettings" : true,
125+
"imageLocation" : "/assets/"
126+
},
127+
"hasPreview" : false,
128+
"fileButtonText" : "Change file",
129+
"readOnly" : false,
130+
"saveHelp" : "You must accept the Privacy Declaration before an image can be made viewable by everyone",
131+
"fileLabel" : "",
132+
"progress" : 0,
133+
"complete" : false,
134+
"saveEnabled" : false
135+
};
136+
*/
+149
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
//document upload scripts
2+
var path = '';
3+
load(path + "document.js")
4+
load(path + 'uuid.js');
5+
6+
print("Loaded all dependent files...");
7+
8+
var hub_name = 0;
9+
var projectId = hub_name + 1;
10+
var title = projectId + 1;
11+
var description = title + 1;
12+
var documentUrl = description + 1;
13+
var doiLink = documentUrl + 1;
14+
var role = doiLink + 1;
15+
var citation = role + 1;
16+
var keywords = citation + 1;
17+
var embeddedVideo = keywords + 1;
18+
19+
var csvData = cat(path+'NESP_MARINE_ARTEFACTS_FOR_TEST.txt');
20+
print("Loaded csv file");
21+
var csvRows = csvData.split('\r');
22+
print("Total rows "+ csvRows.length);
23+
24+
for(var i = 1; i < csvRows.length; i++) {
25+
print("PRINT "+csvRows.length)
26+
27+
var row = csvRows[i];
28+
var fields = row.split('\t');
29+
30+
if(fields[projectId]) {
31+
document.projectId = fields[projectId]
32+
document.documentId = UUID.generate()
33+
document.description = ""
34+
document.name = ""
35+
document.filename = ""
36+
document.contentType = ""
37+
document.doiLink = ""
38+
document.role = ""
39+
document.citation = ""
40+
document.labels = []
41+
document.embeddedVideo = ""
42+
43+
//When there are commas/ double quotations, tsv adds double quotes in the beginning and end of text, following string
44+
//manipulations are done to avoid that
45+
46+
if (fields[title]) {
47+
if ((fields[title].indexOf(',') != -1) || (fields[title].indexOf('"') != -1)) {
48+
var tempTitle = fields[title].replace(/""/g, '"');
49+
document.name = tempTitle.substring(1, tempTitle.length - 1);
50+
}
51+
else {
52+
document.name = fields[title]
53+
}
54+
}
55+
56+
if (fields[description]) {
57+
if ((fields[description].indexOf(',') != -1) || (fields[description].indexOf('"') != -1)) {
58+
var tempDescription = fields[description].replace(/""/g, '"');
59+
document.description = tempDescription.substring(1, tempDescription.length - 1);
60+
}
61+
else {
62+
document.description = fields[description]
63+
}
64+
}
65+
66+
if (fields[documentUrl]) {
67+
var docUrl = fields[documentUrl]
68+
var urlSplitBySlash = docUrl.split('/')
69+
var fileName = urlSplitBySlash[urlSplitBySlash.length - 1]
70+
71+
var contentType = ""
72+
73+
if (fileName.endsWith(".pdf")) {
74+
contentType = "application/pdf"
75+
} else if (fileName.endsWith(".doc") || fileName.endsWith(".docx")) {
76+
contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
77+
}
78+
79+
document.filename = fileName
80+
document.contentType = contentType
81+
}
82+
83+
if (fields[doiLink]) {
84+
if ((fields[doiLink].indexOf(',') != -1) || (fields[doiLink].indexOf('"') != -1)) {
85+
var tempDoi = fields[doiLink].replace(/""/g, '"');
86+
document.doiLink = tempDoi.substring(1, tempDoi.length - 1);
87+
}
88+
else {
89+
document.doiLink = fields[doiLink]
90+
}
91+
}
92+
93+
if (fields[role]) {
94+
document.role = fields[role]
95+
}
96+
97+
if (fields[citation]) {
98+
if ((fields[citation].indexOf(',') != -1) || (fields[citation].indexOf('"') != -1)) {
99+
var tempCitation = fields[citation].replace(/""/g, '"');
100+
document.citation = tempCitation.substring(1, tempCitation.length - 1);
101+
}
102+
else {
103+
document.citation = fields[citation]
104+
}
105+
}
106+
107+
if (fields[keywords]) {
108+
if ((fields[keywords].indexOf(',') != -1) || (fields[keywords].indexOf('"') != -1)) {
109+
var tempKeywords = fields[keywords].replace(/""/g, '"');
110+
var tempKeywordsStr = tempKeywords.substring(1, tempKeywords.length - 1);
111+
var tempKeywordsArr = tempKeywordsStr.split(',');
112+
113+
document.labels = tempKeywordsArr;
114+
}
115+
else {
116+
document.labels.push(fields[keywords]);
117+
}
118+
}
119+
120+
if (fields[embeddedVideo]) {
121+
if ((fields[embeddedVideo].indexOf(',') != -1) || (fields[embeddedVideo].indexOf('"') != -1)) {
122+
var tempEmbeddedVideo = fields[embeddedVideo].replace(/""/g, '"');
123+
document.embeddedVideo = tempEmbeddedVideo.substring(1, tempEmbeddedVideo.length - 1);
124+
}
125+
else {
126+
document.embeddedVideo = fields[embeddedVideo]
127+
}
128+
}
129+
130+
var today = new ISODate();
131+
var dd = today.getDate();
132+
var mm = today.getMonth() + 1; //January is 0!
133+
var yyyy = today.getFullYear();
134+
var dateUTC = yyyy + "-" + ("0" + mm).slice(-2) + "-" + ("0" + dd).slice(-2) + "T00:00:00Z";
135+
136+
document.dateCreated = ISODate(dateUTC);
137+
document.lastUpdated = ISODate(dateUTC);
138+
139+
var documentResult = db.document.insert(document);
140+
141+
print("PROJECT ID: " + document.projectId)
142+
print("DOCUMENT ID: " + document.documentId)
143+
print("FILE NAME: " + document.filename)
144+
print("documentResult " + documentResult)
145+
}
146+
}
147+
148+
print("Created " + (i-1) + " documents");
149+
print("<<<<<<<<<<<<<<<<<<<")

0 commit comments

Comments
 (0)