-
Notifications
You must be signed in to change notification settings - Fork 142
Expand file tree
/
Copy pathBaseController.java
More file actions
84 lines (62 loc) · 2.52 KB
/
Copy pathBaseController.java
File metadata and controls
84 lines (62 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package org.cellocad.api;
import org.apache.tools.ant.DirectoryScanner;
import org.cellocad.authenticate.Authenticator;
import org.json.simple.JSONObject;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
@RestController
public class BaseController {
private static final String USER_DB_NAME = "CELLO";
public Authenticator auth = new Authenticator(USER_DB_NAME);
public final String _resultPath;
public final String _srcPath;
public BaseController() {
String _filepath = FileController.class.getClassLoader().getResource(".").getPath();
if (_filepath.contains("/target/")) {
_filepath = _filepath.substring(0, _filepath.lastIndexOf("/target/"));
}
else if(_filepath.contains("/build/")) {
_filepath = _filepath.substring(0, _filepath.lastIndexOf("/build/"));
}
else if(_filepath.contains("/src/")) {
_filepath = _filepath.substring(0, _filepath.lastIndexOf("/src/"));
}
String[] split_rootPath = _filepath.split("/");
String rootPath = "";
for(int i=0; i< split_rootPath.length - 1; ++i ) {
if(!split_rootPath[i].isEmpty()) {
rootPath += "/" + split_rootPath[i];
}
}
String projectName = split_rootPath[split_rootPath.length-1];
_resultPath = rootPath + "/" + projectName + "_results";
_srcPath = rootPath + "/" + projectName;
}
@ExceptionHandler(CelloUnauthorizedException.class)
@ResponseStatus(HttpStatus.UNAUTHORIZED)
public ErrorResponse handle(CelloUnauthorizedException e) {
return new ErrorResponse(e.getMessage()); // use message from the original exception
}
public static class CelloUnauthorizedException extends RuntimeException {
public CelloUnauthorizedException(String message) {
super(message);
}
}
@ExceptionHandler(CelloNotFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
public ErrorResponse handle(CelloNotFoundException e) {
return new ErrorResponse(e.getMessage()); // use message from the original exception
}
public static class CelloNotFoundException extends RuntimeException {
public CelloNotFoundException(String message) {
super(message);
}
}
public static class ErrorResponse {
public String message;
public ErrorResponse(String message) {
this.message = message;
}
}
}