Skip to content

Commit e463315

Browse files
committed
small cleanup of Scheduler class
1 parent c258a8f commit e463315

File tree

1 file changed

+64
-6
lines changed

1 file changed

+64
-6
lines changed

src/main/java/dev/le_app/mcss_api_java/Scheduler.java

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.le_app.mcss_api_java;
22

33
import dev.le_app.mcss_api_java.exceptions.APIInvalidTaskDetailsException;
4+
import dev.le_app.mcss_api_java.exceptions.APINoServerAccessException;
45
import dev.le_app.mcss_api_java.exceptions.APINotFoundException;
56
import dev.le_app.mcss_api_java.exceptions.APIUnauthorizedException;
67
import org.json.JSONArray;
@@ -34,8 +35,9 @@ protected Scheduler(MCSSApi api, String GUID) {
3435
* @throws APIUnauthorizedException if the API key is invalid
3536
* @throws APINotFoundException if the server is not found
3637
* @throws IOException if there is an IO error (e.g. server is offline)
38+
* @throws APINoServerAccessException if the API key does not have access to the server
3739
*/
38-
public int getTotalTaskAmount() throws APIUnauthorizedException, APINotFoundException, IOException {
40+
public int getTotalTaskAmount() throws APIUnauthorizedException, APINotFoundException, IOException, APINoServerAccessException {
3941

4042
//GET /api/v1/servers/{SERVER_ID}/scheduler/
4143
URL url = new URL(Endpoints.GET_SCHEDULER.getEndpoint().replace("{IP}", api.IP)
@@ -63,6 +65,8 @@ public int getTotalTaskAmount() throws APIUnauthorizedException, APINotFoundExce
6365
break;
6466
case 401:
6567
throw new APIUnauthorizedException(Errors.UNAUTHORIZED.getMessage());
68+
case 403:
69+
throw new APINoServerAccessException(Errors.NO_SERVER_ACCESS.getMessage());
6670
case 404:
6771
throw new APINotFoundException(Errors.NOT_FOUND.getMessage());
6872
default:
@@ -87,8 +91,9 @@ public int getTotalTaskAmount() throws APIUnauthorizedException, APINotFoundExce
8791
* @throws APIUnauthorizedException if the API key is invalid
8892
* @throws APINotFoundException if the server is not found
8993
* @throws IOException if there is an IO error (e.g. server is offline)
94+
* @throws APINoServerAccessException if the API key does not have access to the server
9095
*/
91-
public int getTotalTaskAmount(TaskType filter) throws APIUnauthorizedException, APINotFoundException, IOException {
96+
public int getTotalTaskAmount(TaskType filter) throws APIUnauthorizedException, APINotFoundException, IOException, APINoServerAccessException {
9297

9398
//GET /api/v1/servers/{SERVER_ID}/scheduler/
9499
URL url = new URL(Endpoints.GET_SCHEDULER.getEndpoint().replace("{IP}", api.IP)
@@ -118,6 +123,8 @@ public int getTotalTaskAmount(TaskType filter) throws APIUnauthorizedException,
118123
throw new APIUnauthorizedException(Errors.UNAUTHORIZED.getMessage());
119124
case 404:
120125
throw new APINotFoundException(Errors.NOT_FOUND.getMessage());
126+
case 403:
127+
throw new APINoServerAccessException(Errors.NO_SERVER_ACCESS.getMessage());
121128
default:
122129
throw new IOException(Errors.NOT_RECOGNIZED.getMessage() + responseCode);
123130
}
@@ -140,8 +147,9 @@ public int getTotalTaskAmount(TaskType filter) throws APIUnauthorizedException,
140147
* @throws APINotFoundException if the server is not found
141148
* @throws IOException if there is an IO error (e.g. server is offline)
142149
* @throws APIInvalidTaskDetailsException if the task details are invalid
150+
* @throws APINoServerAccessException if the API key does not have access to the server
143151
*/
144-
public ArrayList<Task> getTasks() throws APIUnauthorizedException, APINotFoundException, IOException, APIInvalidTaskDetailsException {
152+
public ArrayList<Task> getTasks() throws APIUnauthorizedException, APINotFoundException, IOException, APIInvalidTaskDetailsException, APINoServerAccessException {
145153
//GET /api/v1/servers/{SERVER_ID}/scheduler/
146154
URL url = new URL(Endpoints.GET_TASK_LIST.getEndpoint().replace("{IP}", api.IP)
147155
.replace("{SERVER_ID}", GUID));
@@ -168,6 +176,8 @@ public ArrayList<Task> getTasks() throws APIUnauthorizedException, APINotFoundEx
168176
break;
169177
case 401:
170178
throw new APIUnauthorizedException(Errors.UNAUTHORIZED.getMessage());
179+
case 403:
180+
throw new APINoServerAccessException(Errors.NO_SERVER_ACCESS.getMessage());
171181
case 404:
172182
throw new APINotFoundException(Errors.NOT_FOUND.getMessage());
173183
default:
@@ -191,7 +201,23 @@ public ArrayList<Task> getTasks() throws APIUnauthorizedException, APINotFoundEx
191201
return tasks;
192202
}
193203

194-
public Task createTimelessTask(String Name, Boolean Enabled, Boolean repeating, int interval, Job job) throws APIInvalidTaskDetailsException, APIUnauthorizedException, IOException, APINotFoundException {
204+
/**
205+
* Create a new Interval Task
206+
* @param Name Name of the task to create
207+
* @param Enabled Whether the task should be enabled or not
208+
* @param repeating Whether the task should repeat or not
209+
* @param interval The interval between each task
210+
* @param job The job to run
211+
* @return The created task
212+
* @throws APIInvalidTaskDetailsException if the task details are invalid
213+
* @throws APIUnauthorizedException if the API key is invalid/expired
214+
* @throws IOException if there is an IO error (e.g. server is offline)
215+
* @throws APINotFoundException if the server is not found
216+
* @throws APINoServerAccessException if the API key does not have access to the server
217+
*/
218+
public Task createIntervalTask(String Name, Boolean Enabled, Boolean repeating, int interval, Job job)
219+
throws APIInvalidTaskDetailsException, APIUnauthorizedException, IOException,
220+
APINotFoundException, APINoServerAccessException {
195221

196222

197223
//Check if the name contains special characters
@@ -264,6 +290,8 @@ public Task createTimelessTask(String Name, Boolean Enabled, Boolean repeating,
264290
throw new APIInvalidTaskDetailsException(Errors.INVALID_TASK_DETAILS.getMessage());
265291
case 401:
266292
throw new APIUnauthorizedException(Errors.UNAUTHORIZED.getMessage());
293+
case 403:
294+
throw new APINoServerAccessException(Errors.NO_SERVER_ACCESS.getMessage());
267295
case 404:
268296
throw new APINotFoundException(Errors.NOT_FOUND.getMessage());
269297
default:
@@ -277,7 +305,21 @@ public Task createTimelessTask(String Name, Boolean Enabled, Boolean repeating,
277305
return new Task(api, GUID, taskGUID, Name, Enabled);
278306
}
279307

280-
public Task createFixedTimeTask(String Name, Boolean Enabled, Boolean repeating, LocalTime time, Job job) throws APIInvalidTaskDetailsException, APIUnauthorizedException, IOException, APINotFoundException {
308+
/**
309+
* Create a new Fixed Time task
310+
* @param Name Name of the task to create
311+
* @param Enabled Whether the task should be enabled or not
312+
* @param repeating Whether the task should repeat or not
313+
* @param time The time to run the task
314+
* @param job The job to run
315+
* @return The created task
316+
* @throws APIInvalidTaskDetailsException if the task details are invalid
317+
* @throws APIUnauthorizedException if the API key is invalid/expired
318+
* @throws IOException if there is an IO error (e.g. server is offline)
319+
* @throws APINotFoundException if the server is not found
320+
* @throws APINoServerAccessException if the API key does not have access to the server
321+
*/
322+
public Task createFixedTimeTask(String Name, Boolean Enabled, Boolean repeating, LocalTime time, Job job) throws APIInvalidTaskDetailsException, APIUnauthorizedException, IOException, APINotFoundException, APINoServerAccessException {
281323

282324
//Check if the name contains special characters
283325
Pattern p = Pattern.compile("[^a-z0-9 ]", Pattern.CASE_INSENSITIVE);
@@ -349,6 +391,8 @@ public Task createFixedTimeTask(String Name, Boolean Enabled, Boolean repeating,
349391
throw new APIInvalidTaskDetailsException(Errors.INVALID_TASK_DETAILS.getMessage());
350392
case 401:
351393
throw new APIUnauthorizedException(Errors.UNAUTHORIZED.getMessage());
394+
case 403:
395+
throw new APINoServerAccessException(Errors.NO_SERVER_ACCESS.getMessage());
352396
case 404:
353397
throw new APINotFoundException(Errors.NOT_FOUND.getMessage());
354398
default:
@@ -362,7 +406,19 @@ public Task createFixedTimeTask(String Name, Boolean Enabled, Boolean repeating,
362406
return new Task(api, GUID, taskGUID, Name, Enabled);
363407
}
364408

365-
public Task createIntervalTask(String Name, Boolean Enabled, Job job) throws APIInvalidTaskDetailsException, APIUnauthorizedException, IOException, APINotFoundException {
409+
/**
410+
* Create a new Interval Task
411+
* @param Name Name of the task to create
412+
* @param Enabled Whether the task should be enabled or not
413+
* @param job The job to run
414+
* @return The created task
415+
* @throws APIInvalidTaskDetailsException if the task details are invalid
416+
* @throws APIUnauthorizedException if the API key is invalid/expired
417+
* @throws IOException if there is an IO error (e.g. server is offline)
418+
* @throws APINotFoundException if the server is not found
419+
* @throws APINoServerAccessException if the API key does not have access to the server
420+
*/
421+
public Task createTimelessTask(String Name, Boolean Enabled, Job job) throws APIInvalidTaskDetailsException, APIUnauthorizedException, IOException, APINotFoundException, APINoServerAccessException {
366422

367423
//Check if the name contains special characters
368424
Pattern p = Pattern.compile("[^a-z0-9 ]", Pattern.CASE_INSENSITIVE);
@@ -430,6 +486,8 @@ public Task createIntervalTask(String Name, Boolean Enabled, Job job) throws API
430486
throw new APIInvalidTaskDetailsException(Errors.INVALID_TASK_DETAILS.getMessage());
431487
case 401:
432488
throw new APIUnauthorizedException(Errors.UNAUTHORIZED.getMessage());
489+
case 403:
490+
throw new APINoServerAccessException(Errors.NO_SERVER_ACCESS.getMessage());
433491
case 404:
434492
throw new APINotFoundException(Errors.NOT_FOUND.getMessage());
435493
default:

0 commit comments

Comments
 (0)