Skip to content

Commit 5fbb6e9

Browse files
committed
LL-1089
1 parent cfa66f5 commit 5fbb6e9

File tree

9 files changed

+1513
-1377
lines changed

9 files changed

+1513
-1377
lines changed

serv/jobs/ss-dataimport/ss-dataimport-impl/src/main/java/at/kc/tugraz/ss/serv/dataimport/impl/evernote/SSDataImportEvernoteNoteContentHandler.java

Lines changed: 150 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,14 @@ private String downnloadNoteResourcesAndFillXHTMLWithLocalImageLinks(
291291

292292
BufferedReader lineReader = null;
293293
String result = SSStrU.empty;
294-
Resource resource;
295-
SSUri fileURI;
296-
String fileID;
294+
SSUri fileURI = null;
295+
String fileID = null;
296+
Resource resource = null;
297+
SSUri thumbnailURI;
297298
String line;
298299
String tmpLine;
299300
String hash;
301+
String mimeType;
300302
int startIndex;
301303
int endIndex1;
302304
int endIndex2;
@@ -331,25 +333,80 @@ private String downnloadNoteResourcesAndFillXHTMLWithLocalImageLinks(
331333
break;
332334
}
333335

334-
endIndex1 = tmpLine.indexOf("</en-media>");
335-
endIndex2 = tmpLine.indexOf("/>");
336+
endIndex1 = tmpLine.indexOf("</en-media>", startIndex);
337+
endIndex2 = tmpLine.indexOf("/>", startIndex);
336338

337339
if(endIndex1 != -1){
338340
endIndex = endIndex1;
339341
}else{
340342
endIndex = endIndex2;
341343
}
342344

343-
if(//application/pdf //application/vnd.openxmlformats-officedocument.presentationml.presentation //application/msword //application/vnd.openxmlformats-officedocument.wordprocessingml.document
344-
!(tmpLine.contains("type=\"" + SSMimeTypeU.imagePng + "\"") &&
345-
endIndex > tmpLine.indexOf("type=\"" + SSMimeTypeU.imagePng + "\"")
346-
) &&
347-
!(tmpLine.contains("type=\"" + SSMimeTypeU.imageJpeg + "\"") &&
348-
endIndex > tmpLine.indexOf("type=\"" + SSMimeTypeU.imageJpeg + "\"")
349-
) &&
350-
!(tmpLine.contains("type=\"" + SSMimeTypeU.imageGif + "\"") &&
351-
endIndex > tmpLine.indexOf("type=\"" + SSMimeTypeU.imageGif + "\"")
352-
)){
345+
mimeType = null;
346+
347+
if(
348+
tmpLine.contains("type=\"" + SSMimeTypeU.imageJpeg + "\"") &&
349+
endIndex > tmpLine.indexOf("type=\"" + SSMimeTypeU.imageJpeg + "\"")){
350+
mimeType = SSMimeTypeU.imageJpeg;
351+
}
352+
353+
if(
354+
tmpLine.contains("type=\"" + SSMimeTypeU.imagePng + "\"") &&
355+
endIndex > tmpLine.indexOf("type=\"" + SSMimeTypeU.imagePng + "\"")){
356+
mimeType = SSMimeTypeU.imagePng;
357+
}
358+
359+
if(
360+
tmpLine.contains("type=\"" + SSMimeTypeU.imageGif + "\"") &&
361+
endIndex > tmpLine.indexOf("type=\"" + SSMimeTypeU.imageGif + "\"")){
362+
mimeType = SSMimeTypeU.imageGif;
363+
}
364+
365+
if(
366+
tmpLine.contains("type=\"" + SSMimeTypeU.applicationPdf + "\"") &&
367+
endIndex > tmpLine.indexOf("type=\"" + SSMimeTypeU.applicationPdf + "\"")){
368+
mimeType = SSMimeTypeU.applicationPdf;
369+
}
370+
371+
if(
372+
tmpLine.contains("type=\"" + SSMimeTypeU.applicationMsword2007 + "\"") &&
373+
endIndex > tmpLine.indexOf("type=\"" + SSMimeTypeU.applicationMsword2007 + "\"")){
374+
mimeType = SSMimeTypeU.applicationMsword2007;
375+
}
376+
377+
if(
378+
tmpLine.contains("type=\"" + SSMimeTypeU.applicationMsword + "\"") &&
379+
endIndex > tmpLine.indexOf("type=\"" + SSMimeTypeU.applicationMsword + "\"")){
380+
mimeType = SSMimeTypeU.applicationMsword;
381+
}
382+
383+
if(
384+
tmpLine.contains("type=\"" + SSMimeTypeU.applicationMspowerpoint2007 + "\"") &&
385+
endIndex > tmpLine.indexOf("type=\"" + SSMimeTypeU.applicationMspowerpoint2007 + "\"")){
386+
mimeType = SSMimeTypeU.applicationMspowerpoint2007;
387+
}
388+
389+
if(
390+
tmpLine.contains("type=\"" + SSMimeTypeU.applicationMspowerpoint + "\"") &&
391+
endIndex > tmpLine.indexOf("type=\"" + SSMimeTypeU.applicationMspowerpoint + "\"")){
392+
mimeType = SSMimeTypeU.applicationMspowerpoint;
393+
}
394+
395+
if(
396+
tmpLine.contains("type=\"" + SSMimeTypeU.applicationMsexcel2007 + "\"") &&
397+
endIndex > tmpLine.indexOf("type=\"" + SSMimeTypeU.applicationMsexcel2007 + "\"")){
398+
mimeType = SSMimeTypeU.applicationMsexcel2007;
399+
}
400+
401+
if(
402+
tmpLine.contains("type=\"" + SSMimeTypeU.applicationMsexcel + "\"") &&
403+
endIndex > tmpLine.indexOf("type=\"" + SSMimeTypeU.applicationMsexcel + "\"")){
404+
mimeType = SSMimeTypeU.applicationMsexcel;
405+
}
406+
407+
if(mimeType == null){
408+
409+
SSLogU.warn("no / unknown mime type set in:" + tmpLine);
353410

354411
if(endIndex == endIndex1){
355412
result += tmpLine.substring(0, endIndex + 11);
@@ -378,33 +435,89 @@ private String downnloadNoteResourcesAndFillXHTMLWithLocalImageLinks(
378435
continue;
379436
}
380437

381-
hashEndIndex = tmpLine.indexOf("\"", hashIndex + 6);
382-
hash = tmpLine.substring(hashIndex + 6, hashEndIndex);
438+
if(
439+
!SSStrU.equals(mimeType, SSMimeTypeU.applicationMsword2007) &&
440+
!SSStrU.equals(mimeType, SSMimeTypeU.applicationMsword) &&
441+
!SSStrU.equals(mimeType, SSMimeTypeU.applicationMspowerpoint2007) &&
442+
!SSStrU.equals(mimeType, SSMimeTypeU.applicationMspowerpoint) &&
443+
!SSStrU.equals(mimeType, SSMimeTypeU.applicationMsexcel2007) &&
444+
!SSStrU.equals(mimeType, SSMimeTypeU.applicationMsexcel)){
445+
446+
hashEndIndex = tmpLine.indexOf("\"", hashIndex + 6);
447+
hash = tmpLine.substring(hashIndex + 6, hashEndIndex);
448+
fileURI = SSServCaller.vocURICreate(SSFileExtE.valueOf(SSMimeTypeU.fileExtForMimeType(mimeType)));
449+
fileID = SSServCaller.fileIDFromURI(user, fileURI);
450+
451+
resource =
452+
SSServCaller.evernoteResourceByHashGet(
453+
user,
454+
noteStore,
455+
note.getGuid(),
456+
hash);
457+
458+
SSFileU.writeFileBytes(
459+
new FileOutputStream(localWorkPath + fileID),
460+
resource.getData().getBody(),
461+
resource.getData().getSize());
462+
}
383463

384-
// if(hashsPerFileURIs.containsKey(hash)){
385-
// fileURI = hashsPerFileURIs.get(hash);
464+
result += tmpLine.substring(0, startIndex);
386465

387-
// fileID = SSServCaller.fileIDFromURI(user, fileURI);
388-
// }else{
389-
fileURI = SSServCaller.vocURICreate(SSFileExtE.png);
390-
fileID = SSServCaller.fileIDFromURI(user, fileURI);
466+
if(SSStrU.equals(mimeType, SSMimeTypeU.applicationPdf)){
467+
thumbnailURI = SSDataImportEvernoteThumbHelper.createThumbnail(user, localWorkPath, fileURI, 500, 500);
468+
fileID = SSServCaller.fileIDFromURI(user, thumbnailURI);
469+
470+
result +=
471+
"<div>Included PDF (preview):</div>" +
472+
"<img width=\"" +
473+
500 +
474+
"\" height=\"" +
475+
500 +
476+
"\" class=\"xmyImagex\" src=\"" +
477+
localWorkPath + fileID +
478+
"\"/>";
479+
}
391480

392-
// hashsPerFileURIs.put(hash, fileURI);
481+
if(
482+
resource != null &&
483+
!SSStrU.equals(mimeType, SSMimeTypeU.applicationPdf) &&
484+
!SSStrU.equals(mimeType, SSMimeTypeU.applicationMsword2007) &&
485+
!SSStrU.equals(mimeType, SSMimeTypeU.applicationMsword) &&
486+
!SSStrU.equals(mimeType, SSMimeTypeU.applicationMspowerpoint2007) &&
487+
!SSStrU.equals(mimeType, SSMimeTypeU.applicationMspowerpoint) &&
488+
!SSStrU.equals(mimeType, SSMimeTypeU.applicationMsexcel2007) &&
489+
!SSStrU.equals(mimeType, SSMimeTypeU.applicationMsexcel)){
393490

394-
resource =
395-
SSServCaller.evernoteResourceByHashGet(
396-
user,
397-
noteStore,
398-
note.getGuid(),
399-
hash);
491+
result +=
492+
"<img width=\"" +
493+
resource.getWidth() +
494+
"\" height=\"" +
495+
resource.getHeight() +
496+
"\" class=\"xmyImagex\" src=\"" +
497+
localWorkPath + fileID +
498+
"\"/>";
499+
}
400500

401-
SSFileU.writeFileBytes(
402-
new FileOutputStream(localWorkPath + fileID),
403-
resource.getData().getBody(),
404-
resource.getData().getSize());
405-
// }
501+
if(
502+
SSStrU.equals(mimeType, SSMimeTypeU.applicationMsword) ||
503+
SSStrU.equals(mimeType, SSMimeTypeU.applicationMsword2007)){
504+
505+
result += "<div>Includes Microsoft Office Document (no preview available)</div>";
506+
}
507+
508+
if(
509+
SSStrU.equals(mimeType, SSMimeTypeU.applicationMspowerpoint) ||
510+
SSStrU.equals(mimeType, SSMimeTypeU.applicationMspowerpoint2007)){
511+
512+
result += "<div>Includes Microsoft Office Powerpoint Document (no preview available)</div>";
513+
}
406514

407-
result += tmpLine.substring(0, startIndex) + "<img width=\"" + resource.getWidth() + "\" height=\"" + resource.getHeight() + "\" class=\"xmyImagex\" src=\"" + localWorkPath + fileID + "\"/>";
515+
if(
516+
SSStrU.equals(mimeType, SSMimeTypeU.applicationMsexcel) ||
517+
SSStrU.equals(mimeType, SSMimeTypeU.applicationMsexcel2007)){
518+
519+
result += "<div>Includes Microsoft Office Excel Document (no preview available)</div>";
520+
}
408521

409522
if(endIndex == endIndex1){
410523
tmpLine = tmpLine.substring(endIndex + 11, tmpLine.length());
@@ -414,7 +527,7 @@ private String downnloadNoteResourcesAndFillXHTMLWithLocalImageLinks(
414527
}
415528

416529
result += tmpLine;
417-
result += SSStrU.backslashN;
530+
result += SSStrU.backslashRBackslashN;
418531
}
419532

420533
return result.replace("&amp;nbsp;", SSStrU.empty).replace("Â", SSStrU.empty).trim();

serv/jobs/ss-dataimport/ss-dataimport-impl/src/main/java/at/kc/tugraz/ss/serv/dataimport/impl/evernote/SSDataImportEvernoteThumbHelper.java

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -42,47 +42,21 @@ public static void addThumbFromFile(
4242
final SSUri fileUri,
4343
final Boolean shouldCommit) throws Exception{
4444

45-
Boolean thumbCreated = false;
46-
String fileId;
47-
String fileExt;
48-
String filePath;
49-
SSUri pngFileUri;
50-
String pngFilePath;
45+
SSUri pngFileUri;
5146

5247
try{
5348

5449
try{
55-
fileId = SSServCaller.fileIDFromURI (user, fileUri);
56-
fileExt = SSServCaller.fileExtGet (user, fileUri);
57-
filePath = localWorkPath + fileId;
58-
pngFileUri = SSServCaller.vocURICreate(SSFileExtE.png);
59-
pngFilePath = localWorkPath + SSServCaller.fileIDFromURI (user, pngFileUri);
60-
//pptx //docx
61-
if(SSFileExtU.imageFileExts.contains(fileExt)){
62-
SSFileU.scalePNGAndWrite(ImageIO.read(new File(filePath)), pngFilePath, 500, 500);
63-
thumbCreated = true;
64-
}
65-
66-
if(SSStrU.equals(SSFileExtE.pdf, fileExt)){
67-
SSFileU.writeScaledPNGFromPDF(filePath, pngFilePath, 500, 500, false);
68-
thumbCreated = true;
69-
}
7050

71-
if(SSStrU.equals(SSFileExtE.doc, fileExt)){
72-
73-
final String pdfFilePath = localWorkPath + SSServCaller.fileIDFromURI (user, SSServCaller.vocURICreate (SSFileExtE.pdf));
74-
75-
SSFileU.writePDFFromDoc (filePath, pdfFilePath);
76-
SSFileU.writeScaledPNGFromPDF (pdfFilePath, pngFilePath, 500, 500, false);
77-
thumbCreated = true;
78-
}
51+
pngFileUri = createThumbnail(user, localWorkPath, fileUri, 500, 500);
7952

80-
if(!thumbCreated){
81-
SSLogU.warn("thumb creation for fileExt " + fileExt + " not supported");
53+
if(pngFileUri == null){
8254
return;
8355
}
8456

8557
}catch(Exception error){
58+
59+
SSServErrReg.reset();
8660
SSLogU.warn("thumb couldnt be created from file");
8761
return;
8862
}
@@ -117,4 +91,46 @@ public static void addThumbFromFile(
11791
SSServErrReg.regErrThrow(error);
11892
}
11993
}
94+
95+
public static SSUri createThumbnail(
96+
final SSUri user,
97+
final String localWorkPath,
98+
final SSUri fileURI,
99+
final Integer width,
100+
final Integer height) throws Exception{
101+
102+
try{
103+
104+
final String filePath = localWorkPath + SSServCaller.fileIDFromURI (user, fileURI);
105+
final String fileExt = SSServCaller.fileExtGet (user, fileURI);
106+
final SSUri thumbnailFileURI = SSServCaller.vocURICreate(SSFileExtE.png);
107+
final String thumbnailPath = localWorkPath + SSServCaller.fileIDFromURI (user, thumbnailFileURI);
108+
109+
if(SSFileExtU.imageFileExts.contains(fileExt)){
110+
SSFileU.scalePNGAndWrite(ImageIO.read(new File(filePath)), thumbnailPath, width, width);
111+
return thumbnailFileURI;
112+
}
113+
114+
if(SSStrU.equals(SSFileExtE.pdf, fileExt)){
115+
SSFileU.writeScaledPNGFromPDF(filePath, thumbnailPath, width, width, false);
116+
return thumbnailFileURI;
117+
}
118+
119+
if(SSStrU.equals(SSFileExtE.doc, fileExt)){
120+
121+
final String pdfFilePath = localWorkPath + SSServCaller.fileIDFromURI (user, SSServCaller.vocURICreate (SSFileExtE.pdf));
122+
123+
SSFileU.writePDFFromDoc (filePath, pdfFilePath);
124+
SSFileU.writeScaledPNGFromPDF (pdfFilePath, thumbnailPath, width, width, false);
125+
return thumbnailFileURI;
126+
}
127+
128+
SSLogU.warn("thumb creation for fileExt " + fileExt + " not supported");
129+
130+
return null;
131+
}catch(Exception error){
132+
SSServErrReg.regErrThrow(error);
133+
return null;
134+
}
135+
}
120136
}

ss-adapter/ss-adapter-rest-v1/src/main/webapp/api-docs/SSAdapterRESTFile.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,13 @@
115115
"id" : "SSFileGetEditingFilesRet",
116116
"required" : [ "op" ],
117117
"properties" : {
118-
"labels" : {
118+
"files" : {
119119
"type" : "array",
120120
"items" : {
121121
"type" : "string"
122122
}
123123
},
124-
"files" : {
124+
"labels" : {
125125
"type" : "array",
126126
"items" : {
127127
"type" : "string"

ss-adapter/ss-adapter-rest-v1/src/main/webapp/api-docs/SSAdapterRESTFileDownload.json

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,6 @@
44
"basePath" : "http://localhost:8080/ss-adapter-rest",
55
"resourcePath" : "/SSAdapterRESTFileDownload",
66
"apis" : [ {
7-
"path" : "/fileDownload",
8-
"operations" : [ {
9-
"method" : "POST",
10-
"summary" : "download a file via POST request",
11-
"notes" : "",
12-
"type" : "string",
13-
"format" : "byte",
14-
"nickname" : "fileDownload",
15-
"produces" : [ "application/octet-stream" ],
16-
"consumes" : [ "application/json" ],
17-
"parameters" : [ {
18-
"name" : "body",
19-
"required" : false,
20-
"type" : "SSFileDownloadPar",
21-
"paramType" : "body",
22-
"allowMultiple" : false
23-
} ]
24-
} ]
25-
}, {
267
"path" : "/fileDownloadGET",
278
"operations" : [ {
289
"method" : "GET",
@@ -53,6 +34,25 @@
5334
"allowMultiple" : false
5435
} ]
5536
} ]
37+
}, {
38+
"path" : "/fileDownload",
39+
"operations" : [ {
40+
"method" : "POST",
41+
"summary" : "download a file via POST request",
42+
"notes" : "",
43+
"type" : "string",
44+
"format" : "byte",
45+
"nickname" : "fileDownload",
46+
"produces" : [ "application/octet-stream" ],
47+
"consumes" : [ "application/json" ],
48+
"parameters" : [ {
49+
"name" : "body",
50+
"required" : false,
51+
"type" : "SSFileDownloadPar",
52+
"paramType" : "body",
53+
"allowMultiple" : false
54+
} ]
55+
} ]
5656
} ],
5757
"models" : {
5858
"SSFileDownloadPar" : {

0 commit comments

Comments
 (0)