Skip to content

Commit 5166f03

Browse files
author
aquality-automation
authored
Merge pull request #11 from aquality-automation/feature/SwaggerUpdate
Fix swagger documentation
2 parents 7ca6bc9 + 5f10c79 commit 5166f03

File tree

9 files changed

+798
-657
lines changed

9 files changed

+798
-657
lines changed

src/main/java/main/exceptions/AqualityException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package main.exceptions;
22

3+
import lombok.Getter;
4+
35
public class AqualityException extends Exception {
6+
@Getter
7+
protected Integer responseCode = 500;
48
public AqualityException(String error) {
59
super(error);
610
}

src/main/java/main/exceptions/AqualityPermissionsException.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
public class AqualityPermissionsException extends AqualityException {
66
public AqualityPermissionsException(String error, UserDto user) {
77
super(String.format("[Permissions %s]: " + error, user != null ? user.getUser_name() : "anonymous"));
8+
this.responseCode = 403;
89
}
910
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package main.exceptions;
2+
3+
public class AqualitySQLException extends AqualityException {
4+
5+
public AqualitySQLException(String sqlcode) {
6+
super(getErrorMessage(sqlcode));
7+
this.responseCode = getErrorCode(sqlcode);
8+
}
9+
10+
11+
12+
private static String getErrorMessage(String sqlcode){
13+
switch (sqlcode){
14+
case "23516":
15+
case "45000":
16+
case "23505":
17+
return "You are trying to create duplicate entity.";
18+
default:
19+
return String.format("Unknown SQL Error: %s", sqlcode);
20+
}
21+
}
22+
23+
private static Integer getErrorCode(String sqlcode){
24+
switch (sqlcode){
25+
case "23516":
26+
case "45000":
27+
case "23505":
28+
return 409;
29+
default:
30+
return 500;
31+
}
32+
}
33+
}

src/main/java/main/model/db/dao/DAO.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main.model.db.dao;
22

33
import com.mysql.cj.core.conf.url.ConnectionUrlParser.Pair;
4+
import main.exceptions.AqualitySQLException;
45
import main.exceptions.AqualityException;
56
import main.model.db.RS_Converter;
67
import main.model.dto.BaseDto;
@@ -156,7 +157,7 @@ protected JSONArray CallStoredProcedure(String sql, List<Pair<String, String>> p
156157
rs.close();
157158
}
158159
} catch (SQLException e) {
159-
throw new AqualityException(String.format("Cannot execute statement for '%s'", getSqlName(sql)));
160+
throw new AqualitySQLException(e.getSQLState());
160161
} finally {
161162
closeCallableStatement(callableStatement);
162163
}
@@ -210,7 +211,7 @@ private CallableStatement executeCallableStatement(String sql, List<Pair<String,
210211
try {
211212
callableStatement.execute();
212213
} catch (SQLException e) {
213-
throw new AqualityException(String.format("Cannot execute query '%s': %s", getSqlName(sql), e.getMessage()));
214+
throw new AqualitySQLException(e.getSQLState());
214215
}
215216

216217
return callableStatement;

src/main/java/main/model/email/AuditEmails.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import main.model.db.dao.project.UserDao;
77
import main.model.dto.*;
88
import main.utils.AppProperties;
9+
910
import java.util.ArrayList;
1011
import java.util.Date;
1112
import java.util.List;

src/main/java/main/utils/PropertyUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package main.utils;
22

3-
import main.exceptions.RPException;
3+
import main.exceptions.AqualityException;
44

55
import java.io.IOException;
66
import java.io.InputStream;
@@ -15,10 +15,10 @@ class PropertyUtils {
1515
prop = new Properties();
1616

1717
if (input == null) {
18-
throw new RPException(String.format("Sorry, unable to find %s.", property.getName()));
18+
throw new AqualityException(String.format("Sorry, unable to find %s.", property.getName()));
1919
}
2020
prop.load(input);
21-
}catch (RPException | IOException e) {
21+
}catch (AqualityException | IOException e) {
2222
e.printStackTrace();
2323
}
2424
}

src/main/java/main/view/BaseServlet.java

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -134,27 +134,6 @@ protected void setAuthorizationProblem(@NotNull HttpServletResponse resp){
134134
resp.addHeader("ErrorMessage", "Are you sure you logged in?");
135135
}
136136

137-
private void handleSQLException(@NotNull SQLException e, HttpServletResponse resp){
138-
String sqlState = e.getSQLState();
139-
if(sqlState == null) sqlState = "";
140-
switch (sqlState){
141-
case "23515":
142-
resp.setStatus(403);
143-
resp.addHeader("ErrorMessage", "You have no permissions for this action.");
144-
break;
145-
case "23516":
146-
case "45000":
147-
case "23505":
148-
resp.setStatus(409);
149-
resp.addHeader("ErrorMessage", "You are trying to create duplicate entity.");
150-
break;
151-
default:
152-
resp.setStatus(500);
153-
resp.addHeader("ErrorMessage", e.getMessage());
154-
break;
155-
}
156-
}
157-
158137
protected void setErrorHeader(@NotNull HttpServletResponse resp, String errorMessage){
159138
resp.addHeader("ErrorMessage", errorMessage);
160139
}
@@ -207,23 +186,15 @@ protected void handleException(HttpServletResponse resp, @NotNull Exception e){
207186
case "AuthenticationException":
208187
setAuthorizationProblem(resp,e);
209188
return;
210-
case "SQLException":
211-
case "SQLIntegrityConstraintViolationException":
212-
handleSQLException((SQLException) e, resp);
213-
return;
214189
case "AqualityPermissionsException":
215-
resp.setStatus(403);
216-
resp.addHeader("ErrorMessage", e.getMessage());
217-
return;
218190
case "AqualityException":
219-
resp.setStatus(500);
220-
resp.addHeader("ErrorMessage", e.getMessage());
221-
return;
222191
case "InvalidFormatException":
223192
case "AqualityQueryParameterException":
224-
resp.setStatus(422);
225-
resp.addHeader("ErrorMessage", e.getMessage());
226-
193+
case "AqualitySQLException":
194+
AqualityException exception = (AqualityException) e;
195+
resp.setStatus(exception.getResponseCode());
196+
resp.addHeader("ErrorMessage", exception.getMessage());
197+
return;
227198
default:
228199
setUnknownIssue(resp);
229200
}

src/main/java/main/view/Project/FinalResultServlet.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import main.Session;
44
import main.view.BaseServlet;
55
import main.view.IGet;
6-
import main.view.IPost;
76
import main.model.dto.FinalResultDto;
87

98
import javax.servlet.annotation.WebServlet;

0 commit comments

Comments
 (0)