Skip to content

Commit

Permalink
fix: Update field validation (#73)
Browse files Browse the repository at this point in the history
* feat: Update field validation on SOAP request types

* style: simplify field validation error messages

* style: update error format
  • Loading branch information
Woynert authored Oct 13, 2023
1 parent 6ff4d9c commit d90a999
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/gateway/controller/CtrlFileUpload.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static ResFileNew file_upload (ReqFileUpload args)
if (args.fileContent.length == 0) {
s.code = 400;
s.error = true;
s.msg = "{\"fileContent: must not be empty\"}";
s.msg = "\"fileContent must not be empty\"";
return s;
} else if (args.fileContent.length > Config.MAX_FILE_SIZE) {
s.code = 413; // payload too large
Expand Down
6 changes: 2 additions & 4 deletions app/src/main/java/gateway/services/UtilValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ public static <T> ResStatus validate (T obj)
Validation.buildDefaultValidatorFactory ().getValidator ().validate (obj);

if (val.size () > 0) {
s.msg += "{";
for (ConstraintViolation<T> violation : val) {
s.msg += String.format (
"\"%s: %s\",", violation.getPropertyPath ().toString (),
"\"%s %s\",", violation.getPropertyPath ().toString (),
violation.getMessage ());
}
s.msg = s.msg.substring (0, s.msg.length () - 1);
s.msg += "}";

s.msg = s.msg.substring (0, s.msg.length () - 1);
s.code = 400;
s.error = true;
return s;
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/gateway/soap/request/Credentials.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package gateway.soap.request;

import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.NotEmpty;

public class Credentials
{
@NotNull public String username;
@NotNull public String password;
@NotEmpty public String username;
@NotEmpty public String password;

public Credentials () {}
public Credentials (String username, String password)
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/gateway/soap/request/ReqAccPassword.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package gateway.soap.request;

import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;

public class ReqAccPassword extends Authorization
{
@NotNull public String oldpassword;
@NotNull public String newpassword;
@NotEmpty public String newpassword;
}
3 changes: 2 additions & 1 deletion app/src/main/java/gateway/soap/request/ReqFileDelete.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package gateway.soap.request;

import jakarta.validation.constraints.NotNull;
import java.util.UUID;

public class ReqFileDelete extends Authorization
{
public UUID[] fileUUID; // 1+
@NotNull public UUID[] fileUUID; // 1+
}
3 changes: 2 additions & 1 deletion app/src/main/java/gateway/soap/request/ReqFileMove.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package gateway.soap.request;

import jakarta.validation.constraints.NotNull;
import java.util.UUID;

public class ReqFileMove extends Authorization
{
public UUID fileUUID;
@NotNull public UUID fileUUID;
public UUID targetDirectoryUUID; // always a directory
}
4 changes: 2 additions & 2 deletions app/src/main/java/gateway/soap/request/ReqFileNewDir.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package gateway.soap.request;

import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.NotEmpty;
import java.util.UUID;

public class ReqFileNewDir extends Authorization
{
@NotNull public String directoryName;
@NotEmpty public String directoryName;
public UUID location;
}
3 changes: 2 additions & 1 deletion app/src/main/java/gateway/soap/request/ReqFileRename.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package gateway.soap.request;

import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import java.util.UUID;

public class ReqFileRename extends Authorization
{
@NotNull public UUID fileUUID;
@NotNull public String newName;
@NotEmpty public String newName;
}
5 changes: 2 additions & 3 deletions app/src/main/java/gateway/soap/request/ReqFileUpload.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package gateway.soap.request;

import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import java.util.UUID;

public class ReqFileUpload extends Authorization
{
@NotNull public String fileName;

@NotEmpty public String fileName;
@NotNull public byte[] fileContent;

public UUID location;
}
3 changes: 2 additions & 1 deletion app/src/main/java/gateway/soap/request/ReqShareFile.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package gateway.soap.request;

import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import java.util.UUID;

public class ReqShareFile extends Authorization
{
@NotNull public UUID fileUUID;
@NotNull public String otherUsername;
@NotEmpty public String otherUsername;
}
6 changes: 4 additions & 2 deletions app/src/main/java/gateway/soap/request/ReqShareRemove.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package gateway.soap.request;

import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import java.util.UUID;

public class ReqShareRemove
{
public UUID fileUUID;
public String otherUsername;
@NotNull public UUID fileUUID;
@NotEmpty public String otherUsername;
}

0 comments on commit d90a999

Please sign in to comment.