Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,12 @@
<dependency>
<groupId>io.javalin</groupId>
<artifactId>javalin</artifactId>
<version>3.13.10</version>
<version>6.7.0</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>1.9.25</version> <!-- or 2.0.x -->
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
Expand Down Expand Up @@ -224,7 +229,7 @@
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.8.0</version>
<scope>compile</scope>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down Expand Up @@ -253,7 +258,13 @@
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.10.4</version>
<version>1.14.10</version>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-agent</artifactId>
<version>1.14.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
90 changes: 45 additions & 45 deletions src/main/Config/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
import java.util.Optional;
import lombok.SneakyThrows;
import org.bson.types.ObjectId;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.session.DefaultSessionIdManager;
import org.eclipse.jetty.server.session.SessionHandler;
import org.eclipse.jetty.servlet.ServletContextHandler;

public class AppConfig {
public static Long ASYNC_TIME_OUT = 10L;
Expand Down Expand Up @@ -220,7 +224,7 @@ public static Javalin appFactory(DeploymentLevel deploymentLevel) {
app.post("/organizations", productionController.createOrg);

app.before(
"/organizations/:orgId",
"/organizations/{orgId}",
ctx -> {
ObjectId objectId = new ObjectId(ctx.pathParam("orgId"));
Optional<Organization> organizationOptional = orgDao.get(objectId);
Expand All @@ -232,10 +236,10 @@ public static Javalin appFactory(DeploymentLevel deploymentLevel) {
new HashMap<>());
}
});
app.get("/organizations/:orgId", productionController.readOrg);
app.patch("/organizations/:orgId", productionController.updateOrg);
app.delete("/organizations/:orgId", productionController.deleteOrg);
app.get("/organizations/:orgId/users", productionController.getUsersFromOrg);
app.get("/organizations/{orgId}", productionController.readOrg);
app.patch("/organizations/{orgId}", productionController.updateOrg);
app.delete("/organizations/{orgId}", productionController.deleteOrg);
app.get("/organizations/{orgId}/users", productionController.getUsersFromOrg);

app.before(
"/users*",
Expand All @@ -258,7 +262,7 @@ public static Javalin appFactory(DeploymentLevel deploymentLevel) {
app.post("/users", productionController.createUser);

app.before(
"/users/:username",
"/users/{username}",
ctx -> {
String username = ctx.pathParam("username");
Optional<User> userOptional = userDao.get(username);
Expand All @@ -269,15 +273,15 @@ public static Javalin appFactory(DeploymentLevel deploymentLevel) {
}
});

app.get("/users/:username", productionController.readUser);
app.patch("/users/:username", productionController.updateUser);
app.delete("/users/:username", productionController.deleteUser);
app.get("/users/{username}", productionController.readUser);
app.patch("/users/{username}", productionController.updateUser);
app.delete("/users/{username}", productionController.deleteUser);

/* --------------- SEARCH FUNCTIONALITY ------------- */
app.patch("/change-optional-info/", optionalUserInformationController.updateInformation);
app.get("/get-optional-info/:username", optionalUserInformationController.getInformation);
app.get("/get-optional-info/{username}", optionalUserInformationController.getInformation);
app.delete(
"/delete-optional-info/:username", optionalUserInformationController.deleteInformation);
"/delete-optional-info/{username}", optionalUserInformationController.deleteInformation);
app.post("/save-optional-info/", optionalUserInformationController.saveInformation);

/* -------------- Billing ----------------- */
Expand Down Expand Up @@ -318,42 +322,38 @@ public static Javalin createJavalinApp(DeploymentLevel deploymentLevel) {
}
return Javalin.create(
config -> {
config.asyncRequestTimeout =
config.http.asyncTimeout=
ASYNC_TIME_OUT; // timeout for async requests (default is 0, no timeout)
config.autogenerateEtags = false; // auto generate etags (default is false)
config.contextPath = "/"; // context path for the http servlet (default is "/")
config.defaultContentType =
"text/plain"; // content type to use if no content type is set (default is
// "text/plain")

config.enableCorsForOrigin(
"https://keep.id",
"https://server.keep.id",
"http://localhost",
"http://localhost:3000",
"127.0.0.1:3000");

config.enableDevLogging(); // enable extensive development logging for
// http and
// websocket
config.enforceSsl = false;
// log a warning if user doesn't start javalin instance (default is true)
config.logIfServerNotStarted = true;
config.http.generateEtags = false; // auto generate etags (default is false)
config.http.defaultContentType = "text/plain";
config.router.contextPath = "/";
config.bundledPlugins.enableCors(cors -> {
cors.addRule(rule -> {
rule.allowHost(
"https://keep.id",
"https://server.keep.id",
"http://localhost",
"http://localhost:3000",
"http://127.0.0.1:3000",
"http://localhost:3001",
"https://staged.keep.id",
"https://staging.keep.id",
"http://staging.keep.id"
);
rule.allowCredentials = true;
rule.allowHeaders("Content-Type", "Authorization", "X-Requested-With");
rule.allowMethods("GET", "POST", "PUT", "PATCH", "DELETE");
});
});

config.showJavalinBanner = false;
config.prefer405over404 =
false; // send a 405 if handlers exist for different verb on the same path
// (default is false)
config.sessionHandler(
() -> {
try {
return SessionConfig.getSessionHandlerInstance(deploymentLevel);
} catch (Exception e) {
System.err.println("Unable to instantiate session handler.");
e.printStackTrace();
System.exit(1);
return null;
}
});
config.jetty.modifyServletContextHandler(ctx -> {
try {
ctx.setSessionHandler(SessionConfig.getSessionHandlerInstance(deploymentLevel));
} catch (Exception e) {
throw new RuntimeException(e);
}
});
})
.start(port);
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/Config/SessionConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public static SessionHandler getSessionHandlerInstance(DeploymentLevel deploymen
return sessionHandler;
}

public static void resetSessionHandler() {
sessionHandler = null;
}

private static MongoSessionDataStoreFactory mongoDataStoreFactory(
String dbName, String collectionName) {
MongoSessionDataStoreFactory mongoSessionDataStoreFactory = new MongoSessionDataStoreFactory();
Expand Down
25 changes: 13 additions & 12 deletions src/main/File/FileController.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,28 +122,29 @@ public FileController(
UploadedFile signature = null;
Date uploadDate =
Date.from(LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant());
InputStream filestreamToUpload = file.getContent();
String filenameToUpload = file.getFilename();
InputStream filestreamToUpload = file.content();
String filenameToUpload = file.filename();
switch (fileType) {
case APPLICATION_PDF:
case IDENTIFICATION_PDF:
case FORM:
log.info("Got PDF file to upload!");
if (file.getContentType().startsWith("image")) {
if (Objects.requireNonNull(file.contentType()).startsWith("image")) {
ImageToPDFService imageToPDFService = new ImageToPDFService(filestreamToUpload);
Message imageToPdfServiceResponse = imageToPDFService.executeAndGetResponse();
if (imageToPdfServiceResponse == PdfMessage.INVALID_PDF) {
ctx.result(imageToPdfServiceResponse.toResponseString());
return;
}
filestreamToUpload = imageToPDFService.getFileStream();
filenameToUpload =
file.getFilename().substring(0, file.getFilename().lastIndexOf("."))
file.filename().substring(0, file.filename().lastIndexOf("."))
+ ".pdf";
}
filestreamToUpload.reset();
// PDDocument pdfDocument = Loader.loadPDF(filestreamToUpload);
// title = getPDFTitle(file.getFilename(), pdfDocument);
// pdfDocument.close();

if (!Objects.requireNonNull(file.contentType()).startsWith("image")) {
filestreamToUpload = file.content();
}
Copy link

Copilot AI Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant file content retrieval. The condition checks if content type is not an image, then reassigns 'filestreamToUpload = file.content()' which was already assigned on line 125. This appears unnecessary.

Suggested change
}
// No need to reassign filestreamToUpload for non-image files; already set before switch.

Copilot uses AI. Check for mistakes.

if (toSign) {
signature = Objects.requireNonNull(ctx.uploadedFile("signature"));
Expand All @@ -162,7 +163,7 @@ public FileController(
filenameToUpload,
organizationName,
annotated,
file.getContentType());
file.contentType());
UploadFileService uploadService =
new UploadFileService(
fileDao,
Expand All @@ -172,7 +173,7 @@ public FileController(
toSign,
signature == null
? Optional.empty()
: Optional.of(signature.getContent()),
: Optional.of(signature.content()),
Optional.ofNullable(encryptionController));
response = uploadService.executeAndGetResponse();
break;
Expand All @@ -188,7 +189,7 @@ public FileController(
filenameToUpload,
organizationName,
annotated,
file.getContentType());
file.contentType());
uploadService =
new UploadFileService(
fileDao,
Expand All @@ -212,7 +213,7 @@ public FileController(
filenameToUpload,
organizationName,
annotated,
file.getContentType());
file.contentType());
uploadService =
new UploadFileService(
fileDao,
Expand Down
20 changes: 10 additions & 10 deletions src/main/PDF/PdfController.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,9 @@ public User userCheck(String req) {
organizationName,
privilegeLevel,
pdfType,
file.getFilename(),
file.getContentType(),
file.getContent(),
file.filename(),
file.contentType(),
file.content(),
encryptionController,
idCategory);
response = uploadService.executeAndGetResponse();
Expand Down Expand Up @@ -329,9 +329,9 @@ public User userCheck(String req) {
organizationName,
UserType.Developer,
fileIDStr,
file.getFilename(),
file.getContentType(),
file.getContent(),
Objects.requireNonNull(file).filename(),
file.contentType(),
file.content(),
encryptionController);
ctx.result(uploadService.executeAndGetResponse().toResponseString());
};
Expand Down Expand Up @@ -364,10 +364,10 @@ public User userCheck(String req) {
organizationName,
privilegeLevel,
pdfType,
file.getFilename(),
file.getContentType(),
file.getContent(),
signature.getContent(),
file.filename(),
file.contentType(),
file.content(),
signature.content(),
encryptionController);
ctx.result(uploadService.executeAndGetResponse().toResponseString());
};
Expand Down
14 changes: 7 additions & 7 deletions src/main/PDF/PdfControllerV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ public Message setFileParamsUploadSignedPDF(Context ctx) {
UploadedFile signature = Objects.requireNonNull(ctx.uploadedFile("signature"));
this.fileId = Objects.requireNonNull(ctx.formParam("applicationId"));
this.formAnswers = new JSONObject(Objects.requireNonNull(ctx.formParam("formAnswers")));
this.signatureStream = signature.getContent();
this.signatureStream = signature.content();
} catch (Exception e) {
return PdfMessage.INVALID_PARAMETER;
}
Expand Down Expand Up @@ -460,9 +460,9 @@ public Message setFileParamsUploadPDF(Context ctx) {
log.info("Client uploaded document missing category");
return PdfMessage.INVALID_ID_CATEGORY;
}
this.fileName = file.getFilename();
this.fileContentType = file.getContentType();
this.fileStream = file.getContent();
this.fileName = file.filename();
this.fileContentType = file.contentType();
this.fileStream = file.content();
return null;
}

Expand All @@ -473,9 +473,9 @@ public Message setFileParamsUploadAnnotatedPDF(Context ctx) {
return PdfMessage.INVALID_PDF;
}
// this.fileOrgName = ctx.formParam("fileOrgName");
this.fileName = file.getFilename();
this.fileContentType = file.getContentType();
this.fileStream = file.getContent();
this.fileName = file.filename();
this.fileContentType = file.contentType();
this.fileStream = file.content();
return null;
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/PDF/Services/V2Services/FillPDFServiceV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ public Message checkFillConditions() {
if (!ValidationUtils.isValidObjectId(fileId) || formAnswers == null) {
return PdfMessage.INVALID_PARAMETER;
}
// if (signatureStream == null) {
// return PdfMessage.SERVER_ERROR;
// }
// if (signatureStream == null) {
// return PdfMessage.SERVER_ERROR;
// }
if (privilegeLevel == null) {
return PdfMessage.INVALID_PRIVILEGE_TYPE;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/User/Services/UploadPfpService.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public UploadPfpService(MongoDatabase db, String username, UploadedFile pfp, Str

@Override
public Message executeAndGetResponse() {
InputStream content = pfp.getContent();
InputStream content = pfp.content();
Bson filter = Filters.eq("metadata.owner", username);
GridFSBucket gridBucket = GridFSBuckets.create(db, "pfp");
GridFSFile grid_out = gridBucket.find(filter).first();
Expand Down
Loading