From c9d6308bf0322fdea5f2c74246cdc466cd4c3063 Mon Sep 17 00:00:00 2001 From: Samuel Lee Date: Wed, 18 Oct 2023 05:20:58 -0400 Subject: [PATCH] changes to non-app routes --- src/main/Config/AppConfig.java | 15 ++++++++-- src/main/File/File.java | 29 +++++++++++++------ src/main/PDF/PdfControllerV2.java | 2 +- .../V2Services/FilterPDFServiceV2.java | 5 +++- .../UploadAnnotatedPDFServiceV2.java | 7 +++-- 5 files changed, 42 insertions(+), 16 deletions(-) diff --git a/src/main/Config/AppConfig.java b/src/main/Config/AppConfig.java index 9c80f26c..252a5530 100644 --- a/src/main/Config/AppConfig.java +++ b/src/main/Config/AppConfig.java @@ -23,6 +23,7 @@ import Organization.Organization; import Organization.OrganizationController; import PDF.PdfController; +import PDF.PdfControllerV2; import Production.ProductionController; import Security.AccountSecurityController; import Security.EncryptionTools; @@ -34,10 +35,9 @@ import com.mongodb.client.MongoDatabase; import io.javalin.Javalin; import io.javalin.http.HttpResponseException; -import org.bson.types.ObjectId; - import java.util.HashMap; import java.util.Optional; +import org.bson.types.ObjectId; public class AppConfig { public static Long ASYNC_TIME_OUT = 10L; @@ -82,6 +82,7 @@ public static Javalin appFactory(DeploymentLevel deploymentLevel) { ProductionController productionController = new ProductionController(orgDao, userDao); UserControllerV2 userControllerV2 = new UserControllerV2(userV2Dao); BillingController billingController = new BillingController(); + PdfControllerV2 pdfControllerV2 = new PdfControllerV2(fileDao, formDao, userDao, db); // try { do not recomment this block of code, this will delete and regenerate our encryption // key // System.out.println("generating keyset"); @@ -116,6 +117,16 @@ public static Javalin appFactory(DeploymentLevel deploymentLevel) { app.post("/get-form", formController.formGet); app.post("/delete-form/", formController.formDelete); + /* -------------- PDF CONTROLLER v2 --------------------- */ + app.post("/delete-pdf-2", pdfControllerV2.deletePDF); + app.post("/download-pdf-2", pdfControllerV2.downloadPDF); + app.post("/filter-pdf-2", pdfControllerV2.filterPDF); + app.post("/upload-pdf-2", pdfControllerV2.uploadPDF); + app.post("/upload-annotated-pdf-2", pdfControllerV2.uploadAnnotatedPDF); + app.post("/upload-signed-pdf-2", pdfControllerV2.uploadSignedPDF); + app.post("/get-questions-2", pdfControllerV2.getQuestions); + app.post("/fill-pdf-2", pdfControllerV2.fillPDF); + /* -------------- USER AUTHENTICATION/USER RELATED ROUTES-------------- */ app.post("/login", userController.loginUser); app.post("/authenticate", userController.authenticateUser); diff --git a/src/main/File/File.java b/src/main/File/File.java index bce7ad78..57a7e409 100644 --- a/src/main/File/File.java +++ b/src/main/File/File.java @@ -1,15 +1,15 @@ package File; +import java.io.InputStream; +import java.util.Date; +import java.util.Objects; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.bson.codecs.pojo.annotations.BsonIgnore; import org.bson.codecs.pojo.annotations.BsonProperty; import org.bson.types.ObjectId; - -import java.io.InputStream; -import java.util.Date; -import java.util.Objects; +import org.json.JSONObject; @Slf4j public class File { @@ -27,9 +27,7 @@ public class File { @BsonProperty(value = "annotated") private boolean isAnnotated; - @Getter - @Setter - private IdCategoryType idCategory; + @Getter @Setter private IdCategoryType idCategory; @Getter @Setter private String contentType; @@ -110,9 +108,9 @@ public int hashCode() { public String toString() { return "File{" + "id=" - + id + + id.toString() + ", fileId=" - + fileId + + fileId.toString() + ", filename='" + filename + '\'' @@ -136,6 +134,19 @@ public String toString() { + '}'; } + public JSONObject toJsonView() { + JSONObject fileMetadata = + new JSONObject() + .put("uploader", this.username) + .put("organizationName", this.organizationName) + .put("id", this.getId().toString()) + .put("uploadDate", this.uploadedAt) + .put("idCategory", this.idCategory) + .put("filename", this.filename) + .put("annotated", this.isAnnotated); + return fileMetadata; + } + /* Metadata fields from database: filetype (str/enum) DONE diff --git a/src/main/PDF/PdfControllerV2.java b/src/main/PDF/PdfControllerV2.java index f7595019..c96327dd 100644 --- a/src/main/PDF/PdfControllerV2.java +++ b/src/main/PDF/PdfControllerV2.java @@ -465,7 +465,7 @@ public Message setFileParamsUploadAnnotatedPDF(Context ctx) { log.info("File is null"); return PdfMessage.INVALID_PDF; } - this.fileOrgName = ctx.formParam("fileOrgName"); + // this.fileOrgName = ctx.formParam("fileOrgName"); this.fileName = file.getFilename(); this.fileContentType = file.getContentType(); this.fileStream = file.getContent(); diff --git a/src/main/PDF/Services/V2Services/FilterPDFServiceV2.java b/src/main/PDF/Services/V2Services/FilterPDFServiceV2.java index 75b42dba..a5014f64 100644 --- a/src/main/PDF/Services/V2Services/FilterPDFServiceV2.java +++ b/src/main/PDF/Services/V2Services/FilterPDFServiceV2.java @@ -109,7 +109,10 @@ public Message setFilter() { public Message filter() { List filteredFiles = this.fileDao.getAll(this.filter); - this.files = new JSONArray(filteredFiles); + this.files = new JSONArray(); + for (File filteredFile : filteredFiles) { + this.files.put(filteredFile.toJsonView()); + } return PdfMessage.SUCCESS; } } diff --git a/src/main/PDF/Services/V2Services/UploadAnnotatedPDFServiceV2.java b/src/main/PDF/Services/V2Services/UploadAnnotatedPDFServiceV2.java index a88f81a1..a417d969 100644 --- a/src/main/PDF/Services/V2Services/UploadAnnotatedPDFServiceV2.java +++ b/src/main/PDF/Services/V2Services/UploadAnnotatedPDFServiceV2.java @@ -51,7 +51,7 @@ public class UploadAnnotatedPDFServiceV2 implements Service { private List formQuestions; private JSONObject userInfo; private ObjectId uploadedFileId; - private String fileOrganizationName; + // private String fileOrganizationName; public UploadAnnotatedPDFServiceV2( FileDao fileDao, @@ -69,7 +69,7 @@ public UploadAnnotatedPDFServiceV2( this.fileName = fileParams.getFileName(); this.fileContentType = fileParams.getFileContentType(); this.fileStream = fileParams.getFileStream(); - this.fileOrganizationName = fileParams.getFileOrgName(); + // this.fileOrganizationName = fileParams.getFileOrgName(); this.encryptionController = encryptionController; } @@ -347,7 +347,8 @@ public Message upload() { FileType.FORM, IdCategoryType.NONE, this.fileName, - this.fileOrganizationName, + this.organizationName, + // this.fileOrganizatiofileOrganizationNamenName, true, this.fileContentType); ObjectId fileId = file.getId();