mirror of
https://github.com/sismics/docs.git
synced 2025-12-13 01:36:18 +00:00
@@ -51,7 +51,6 @@ import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.StreamingOutput;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.text.MessageFormat;
|
||||
@@ -296,14 +295,11 @@ public class DocumentResource extends BaseResource {
|
||||
}
|
||||
|
||||
// Convert to PDF
|
||||
StreamingOutput stream = new StreamingOutput() {
|
||||
@Override
|
||||
public void write(OutputStream outputStream) throws IOException, WebApplicationException {
|
||||
try {
|
||||
PdfUtil.convertToPdf(documentDto, fileList, fitImageToPage, metadata, margin, outputStream);
|
||||
} catch (Exception e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
StreamingOutput stream = outputStream -> {
|
||||
try {
|
||||
PdfUtil.convertToPdf(documentDto, fileList, fitImageToPage, metadata, margin, outputStream);
|
||||
} catch (Exception e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -452,7 +448,7 @@ public class DocumentResource extends BaseResource {
|
||||
// New tag criteria
|
||||
List<TagDto> tagDtoList = TagUtil.findByName(params[1], allTagDtoList);
|
||||
if (documentCriteria.getTagIdList() == null) {
|
||||
documentCriteria.setTagIdList(new ArrayList<String>());
|
||||
documentCriteria.setTagIdList(new ArrayList<>());
|
||||
}
|
||||
if (tagDtoList.isEmpty()) {
|
||||
// No tag found, the request must returns nothing
|
||||
@@ -492,32 +488,39 @@ public class DocumentResource extends BaseResource {
|
||||
// New specific date criteria
|
||||
try {
|
||||
boolean isUpdated = params[0].startsWith("u");
|
||||
if (params[1].length() == 10) {
|
||||
DateTime date = dayFormatter.parseDateTime(params[1]);
|
||||
if (isUpdated) {
|
||||
documentCriteria.setUpdateDateMin(date.toDate());
|
||||
documentCriteria.setUpdateDateMax(date.plusDays(1).minusSeconds(1).toDate());
|
||||
} else {
|
||||
documentCriteria.setCreateDateMin(date.toDate());
|
||||
documentCriteria.setCreateDateMax(date.plusDays(1).minusSeconds(1).toDate());
|
||||
switch (params[1].length()) {
|
||||
case 10: {
|
||||
DateTime date = dayFormatter.parseDateTime(params[1]);
|
||||
if (isUpdated) {
|
||||
documentCriteria.setUpdateDateMin(date.toDate());
|
||||
documentCriteria.setUpdateDateMax(date.plusDays(1).minusSeconds(1).toDate());
|
||||
} else {
|
||||
documentCriteria.setCreateDateMin(date.toDate());
|
||||
documentCriteria.setCreateDateMax(date.plusDays(1).minusSeconds(1).toDate());
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else if (params[1].length() == 7) {
|
||||
DateTime date = monthFormatter.parseDateTime(params[1]);
|
||||
if (isUpdated) {
|
||||
documentCriteria.setUpdateDateMin(date.toDate());
|
||||
documentCriteria.setUpdateDateMax(date.plusMonths(1).minusSeconds(1).toDate());
|
||||
} else {
|
||||
documentCriteria.setCreateDateMin(date.toDate());
|
||||
documentCriteria.setCreateDateMax(date.plusMonths(1).minusSeconds(1).toDate());
|
||||
case 7: {
|
||||
DateTime date = monthFormatter.parseDateTime(params[1]);
|
||||
if (isUpdated) {
|
||||
documentCriteria.setUpdateDateMin(date.toDate());
|
||||
documentCriteria.setUpdateDateMax(date.plusMonths(1).minusSeconds(1).toDate());
|
||||
} else {
|
||||
documentCriteria.setCreateDateMin(date.toDate());
|
||||
documentCriteria.setCreateDateMax(date.plusMonths(1).minusSeconds(1).toDate());
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else if (params[1].length() == 4) {
|
||||
DateTime date = yearFormatter.parseDateTime(params[1]);
|
||||
if (isUpdated) {
|
||||
documentCriteria.setUpdateDateMin(date.toDate());
|
||||
documentCriteria.setUpdateDateMax(date.plusYears(1).minusSeconds(1).toDate());
|
||||
} else {
|
||||
documentCriteria.setCreateDateMin(date.toDate());
|
||||
documentCriteria.setCreateDateMax(date.plusYears(1).minusSeconds(1).toDate());
|
||||
case 4: {
|
||||
DateTime date = yearFormatter.parseDateTime(params[1]);
|
||||
if (isUpdated) {
|
||||
documentCriteria.setUpdateDateMin(date.toDate());
|
||||
documentCriteria.setUpdateDateMax(date.plusYears(1).minusSeconds(1).toDate());
|
||||
} else {
|
||||
documentCriteria.setCreateDateMin(date.toDate());
|
||||
documentCriteria.setCreateDateMax(date.plusYears(1).minusSeconds(1).toDate());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
||||
@@ -39,7 +39,6 @@ import javax.ws.rs.core.Response.Status;
|
||||
import javax.ws.rs.core.StreamingOutput;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
@@ -506,18 +505,15 @@ public class FileResource extends BaseResource {
|
||||
final InputStream responseInputStream = decrypt ?
|
||||
EncryptionUtil.decryptInputStream(fileInputStream, user.getPrivateKey()) : fileInputStream;
|
||||
|
||||
stream = new StreamingOutput() {
|
||||
@Override
|
||||
public void write(OutputStream outputStream) throws IOException, WebApplicationException {
|
||||
stream = outputStream -> {
|
||||
try {
|
||||
ByteStreams.copy(responseInputStream, outputStream);
|
||||
} finally {
|
||||
try {
|
||||
ByteStreams.copy(responseInputStream, outputStream);
|
||||
} finally {
|
||||
try {
|
||||
responseInputStream.close();
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
// Ignore
|
||||
}
|
||||
responseInputStream.close();
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -578,32 +574,29 @@ public class FileResource extends BaseResource {
|
||||
final List<File> fileList = fileDao.getByDocumentId(principal.getId(), documentId);
|
||||
|
||||
// Create the ZIP stream
|
||||
StreamingOutput stream = new StreamingOutput() {
|
||||
@Override
|
||||
public void write(OutputStream outputStream) throws IOException, WebApplicationException {
|
||||
try (ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream)) {
|
||||
// Add each file to the ZIP stream
|
||||
int index = 0;
|
||||
for (File file : fileList) {
|
||||
java.nio.file.Path storedfile = DirectoryUtil.getStorageDirectory().resolve(file.getId());
|
||||
InputStream fileInputStream = Files.newInputStream(storedfile);
|
||||
|
||||
// Add the decrypted file to the ZIP stream
|
||||
// Files are encrypted by the creator of them
|
||||
User user = userDao.getById(file.getUserId());
|
||||
try (InputStream decryptedStream = EncryptionUtil.decryptInputStream(fileInputStream, user.getPrivateKey())) {
|
||||
ZipEntry zipEntry = new ZipEntry(index + "-" + file.getFullName(Integer.toString(index)));
|
||||
zipOutputStream.putNextEntry(zipEntry);
|
||||
ByteStreams.copy(decryptedStream, zipOutputStream);
|
||||
zipOutputStream.closeEntry();
|
||||
} catch (Exception e) {
|
||||
throw new WebApplicationException(e);
|
||||
}
|
||||
index++;
|
||||
StreamingOutput stream = outputStream -> {
|
||||
try (ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream)) {
|
||||
// Add each file to the ZIP stream
|
||||
int index = 0;
|
||||
for (File file : fileList) {
|
||||
java.nio.file.Path storedfile = DirectoryUtil.getStorageDirectory().resolve(file.getId());
|
||||
InputStream fileInputStream = Files.newInputStream(storedfile);
|
||||
|
||||
// Add the decrypted file to the ZIP stream
|
||||
// Files are encrypted by the creator of them
|
||||
User user = userDao.getById(file.getUserId());
|
||||
try (InputStream decryptedStream = EncryptionUtil.decryptInputStream(fileInputStream, user.getPrivateKey())) {
|
||||
ZipEntry zipEntry = new ZipEntry(index + "-" + file.getFullName(Integer.toString(index)));
|
||||
zipOutputStream.putNextEntry(zipEntry);
|
||||
ByteStreams.copy(decryptedStream, zipOutputStream);
|
||||
zipOutputStream.closeEntry();
|
||||
} catch (Exception e) {
|
||||
throw new WebApplicationException(e);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
outputStream.close();
|
||||
}
|
||||
outputStream.close();
|
||||
};
|
||||
|
||||
// Write to the output
|
||||
|
||||
Reference in New Issue
Block a user