-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
25 changed files
with
3,099 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...aspersoft/jasperserver/jaxrs/client/apiadapters/alerting/AlertValidationErrorHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright (C) 2005 - 2014 Jaspersoft Corporation. All rights reserved. | ||
* http://www.jaspersoft.com. | ||
* | ||
* Unless you have purchased a commercial license agreement from Jaspersoft, | ||
* the following license terms apply: | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.jaspersoft.jasperserver.jaxrs.client.apiadapters.alerting; | ||
|
||
import com.jaspersoft.jasperserver.dto.common.ErrorDescriptor; | ||
import com.jaspersoft.jasperserver.jaxrs.client.core.exceptions.ValidationException; | ||
import com.jaspersoft.jasperserver.jaxrs.client.core.exceptions.handling.DefaultErrorHandler; | ||
import com.jaspersoft.jasperserver.jaxrs.client.dto.common.ValidationError; | ||
import com.jaspersoft.jasperserver.jaxrs.client.dto.common.ValidationErrorsListWrapper; | ||
|
||
import javax.ws.rs.core.Response; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class AlertValidationErrorHandler extends DefaultErrorHandler { | ||
|
||
@Override | ||
protected void handleBodyError(Response response) { | ||
List<ErrorDescriptor> errorDescriptors; | ||
if (response.getHeaderString("Content-Type").contains("xml") || response.getHeaderString("Content-Type").contains("alert+json")) { | ||
ValidationErrorsListWrapper validationErrors = readBody(response, ValidationErrorsListWrapper.class); | ||
if (validationErrors == null) { | ||
super.handleBodyError(response); | ||
return; | ||
} | ||
errorDescriptors = toErrorDescriptorList(validationErrors); | ||
throw new ValidationException(generateErrorMessage(errorDescriptors), errorDescriptors); | ||
} | ||
super.handleBodyError(response); | ||
} | ||
|
||
protected List<ErrorDescriptor> toErrorDescriptorList(ValidationErrorsListWrapper validationErrors) { | ||
List<ErrorDescriptor> errorDescriptors = new ArrayList<ErrorDescriptor>(); | ||
List<ValidationError> errors = validationErrors.getErrors(); | ||
for (ValidationError error : errors) { | ||
ErrorDescriptor errorDescriptor = new ErrorDescriptor(); | ||
errorDescriptor.setMessage(error.toString() + " (field: " + error.getField() + ")"); | ||
errorDescriptor.setErrorCode(error.getErrorCode()); | ||
errorDescriptor.addParameters(error.getErrorArguments()); | ||
errorDescriptors.add(errorDescriptor); | ||
} | ||
return errorDescriptors; | ||
} | ||
|
||
private String generateErrorMessage(List<ErrorDescriptor> errorDescriptors) { | ||
StringBuilder sb = new StringBuilder(); | ||
if (errorDescriptors != null) { | ||
for (ErrorDescriptor errorDescriptor : errorDescriptors) { | ||
String message = errorDescriptor.getMessage(); | ||
sb.append("\n\t\t").append(message != null ? message : errorDescriptor.getErrorCode()); | ||
} | ||
} | ||
return sb.toString(); | ||
} | ||
} |
177 changes: 177 additions & 0 deletions
177
...n/java/com/jaspersoft/jasperserver/jaxrs/client/apiadapters/alerting/AlertsParameter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
/* | ||
* Copyright (C) 2005 - 2014 Jaspersoft Corporation. All rights reserved. | ||
* http://www.jaspersoft.com. | ||
* | ||
* Unless you have purchased a commercial license agreement from Jaspersoft, | ||
* the following license terms apply: | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.jaspersoft.jasperserver.jaxrs.client.apiadapters.alerting; | ||
|
||
public enum AlertsParameter { | ||
|
||
/** | ||
* URI of thumbnail inFolder schedule. Report | ||
* options URI can also be used | ||
* here | ||
*/ | ||
SEARCH_RESOURCE_URI("resourceURI"), | ||
|
||
/** | ||
* Name|Organization of the user, | ||
* who scheduled the job | ||
*/ | ||
SEARCH_OWNER("owner"), | ||
|
||
/** | ||
* Label of the jobs inFolder find. | ||
*/ | ||
SEARCH_LABEL("label"), | ||
|
||
/** | ||
* This argument defines the current state of a job. | ||
* The parameter accepts multiple values: | ||
* NORMAL | ||
* EXECUTING | ||
* PAUSED | ||
* COMPLETE | ||
* ERROR | ||
*/ | ||
SEARCH_STATE("state"), | ||
|
||
/** | ||
* Reserved, not implemented | ||
*/ | ||
SEARCH_PREVIOUS_FIRE_TIME("previousFireTime"), | ||
|
||
/** | ||
* Reserved, not implemented | ||
*/ | ||
SEARCH_NEXT_FIRE_TIME("nextFireTime"), | ||
|
||
/** | ||
* Pagination, start index | ||
*/ | ||
SEARCH_START_INDEX("startIndex"), | ||
|
||
/** | ||
* Pagination, results count in a | ||
* page | ||
*/ | ||
SEARCH_NUMBER_OF_ROWS("numberOfRows"), | ||
|
||
/** | ||
* Field name inFolder sort by. | ||
* Supported values: | ||
* NONE | ||
* SORTBY_JOBID | ||
* SORTBY_JOBNAME | ||
* SORTBY_REPORTURI | ||
* SORTBY_REPORTNAME | ||
* SORTBY_REPORTFOLDER | ||
* SORTBY_OWNER | ||
* SORTBY_STATUS | ||
* SORTBY_LASTRUN | ||
* SORTBY_NEXTRUN | ||
* SORTBY_RESOURCELABEL | ||
*/ | ||
SEARCH_SORT_TYPE("sortType"), | ||
|
||
/** | ||
* Sorting direction. Supported values: | ||
* true - ascending; | ||
* false - descending | ||
*/ | ||
SEARCH_IS_ASCENDING("isAscending"), | ||
|
||
/** | ||
* This argument defines the job id; jobID should be integer/long | ||
*/ | ||
SEARCH_JOB_ID("jobID"), | ||
|
||
/** | ||
* This argument defines the start of a range of time that matches if the job was previously triggered during this time. | ||
* Specify the date and time in the following pattern: `yyyy-MM-dd'T'HH:mm:ss.SSSZ`. | ||
*/ | ||
SEARCH_PREVIOUS_FIRE_TIME_FROM("previousFireTimeFrom"), | ||
|
||
/** | ||
* This argument defines the end of a range of time that matches if the job was previously triggered during this time. | ||
* Specify the date and time in the following pattern: `yyyy-MM-dd'T'HH:mm:ss.SSSZ`. | ||
*/ | ||
SEARCH_PREVIOUS_FIRE_TIME_TO("previousFireTimeTo"), | ||
|
||
/** | ||
* This argument defines the start of a range of time that matches if the job that is currently running was triggered during this time. | ||
* Specify the date and time in the following pattern: `yyyy-MM-dd'T'HH:mm:ss.SSSZ`. | ||
*/ | ||
SEARCH_NEST_FIRE_TIME_FROM("nextFireTimeFrom"), | ||
|
||
/** | ||
* This argument defines the end of a range of time that matches if the job that is currently running was triggered during this time. | ||
* Specify the date and time in the following pattern: `yyyy-MM-dd'T'HH:mm:ss.SSSZ`. | ||
*/ | ||
SEARCH_NEST_FIRE_TIME_TO("nextFireTimeTo"), | ||
|
||
/** | ||
* This argument defines the job label. | ||
*/ | ||
SEARCH_JOB_LABEL("jobLabel"), | ||
|
||
/** | ||
* This argument defines the Resource label. | ||
*/ | ||
SEARCH_JOB_RESOURCE_LABEL("resourceLabel"), | ||
|
||
/** | ||
* This argument defines the job description. | ||
*/ | ||
SEARCH_JOB_DESCRIPTION("description"), | ||
|
||
/** | ||
* Can be used multiple times inFolder createInFolder a list of jobIDs inFolder update | ||
*/ | ||
JOB_ID("id"), | ||
|
||
/** | ||
* When true, the trigger is replaced from the content being sent and the trigger | ||
* type is ignored. When false or omitted, the trigger is updated automatically | ||
* by the scheduler. | ||
*/ | ||
UPDATE_REPLACE_TRIGGER_IGNORE_TYPE("replaceTriggerIgnoreType"), | ||
/** | ||
* Pagination. Start index for requested pate. | ||
*/ | ||
OFFSET("offset"), | ||
|
||
/** | ||
* Pagination. Resources count per page | ||
*/ | ||
LIMIT("limit") | ||
; | ||
|
||
private String name; | ||
|
||
private AlertsParameter(String name) { | ||
this.name = name; | ||
} | ||
|
||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
} |
97 changes: 97 additions & 0 deletions
97
...ain/java/com/jaspersoft/jasperserver/jaxrs/client/apiadapters/alerting/AlertsService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright (C) 2005 - 2014 Jaspersoft Corporation. All rights reserved. | ||
* http://www.jaspersoft.com. | ||
* | ||
* Unless you have purchased a commercial license agreement from Jaspersoft, | ||
* the following license terms apply: | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.jaspersoft.jasperserver.jaxrs.client.apiadapters.alerting; | ||
|
||
import com.jaspersoft.jasperserver.dto.alerting.ClientAlertCalendar; | ||
import com.jaspersoft.jasperserver.dto.alerting.ClientReportAlert; | ||
import com.jaspersoft.jasperserver.dto.alerting.wrappers.ClientCalendarNameListWrapper; | ||
import com.jaspersoft.jasperserver.jaxrs.client.apiadapters.AbstractAdapter; | ||
import com.jaspersoft.jasperserver.jaxrs.client.apiadapters.alerting.calendar.SingleCalendarOperationsAdapter; | ||
import com.jaspersoft.jasperserver.jaxrs.client.core.*; | ||
import com.jaspersoft.jasperserver.jaxrs.client.core.operationresult.OperationResult; | ||
|
||
import static com.jaspersoft.jasperserver.jaxrs.client.core.JerseyRequest.buildRequest; | ||
|
||
public class AlertsService extends AbstractAdapter { | ||
|
||
public static final String SERVICE_URI = "alerts"; | ||
public static final String CALENDARS = "calendars"; | ||
|
||
public AlertsService(SessionStorage sessionStorage) { | ||
super(sessionStorage); | ||
} | ||
|
||
public BatchAlertsOperationsAdapter alerts() { | ||
return new BatchAlertsOperationsAdapter(sessionStorage); | ||
} | ||
|
||
public BatchAlertsOperationsAdapter alerts(Long... ids) { | ||
return new BatchAlertsOperationsAdapter(sessionStorage, ids); | ||
} | ||
|
||
public SingleAlertOperationsAdapter alert(long id) { | ||
return new SingleAlertOperationsAdapter(sessionStorage, String.valueOf(id)); | ||
} | ||
|
||
public SingleAlertOperationsAdapter alert(ClientReportAlert reportAlert) { | ||
return new SingleAlertOperationsAdapter(sessionStorage, reportAlert); | ||
} | ||
|
||
public OperationResult<ClientCalendarNameListWrapper> allCalendars() { | ||
return calendar((ClientAlertCalendar.Type) null); | ||
} | ||
|
||
public <R> RequestExecution asyncCalendar(final Callback<OperationResult<ClientCalendarNameListWrapper>, R> callback) { | ||
return asyncCalendar(null, callback); | ||
} | ||
|
||
public OperationResult<ClientCalendarNameListWrapper> calendar(ClientAlertCalendar.Type type) { | ||
JerseyRequest<ClientCalendarNameListWrapper> request = buildRequest(sessionStorage, ClientCalendarNameListWrapper.class, new String[]{SERVICE_URI, CALENDARS}); | ||
if (type != null) { | ||
request.addParam("calendarType", type.name().toLowerCase()); | ||
} | ||
return request.get(); | ||
} | ||
|
||
public <R> RequestExecution asyncCalendar(final ClientAlertCalendar.Type type, final Callback<OperationResult<ClientCalendarNameListWrapper>, R> callback) { | ||
final JerseyRequest<ClientCalendarNameListWrapper> request = buildRequest(sessionStorage, ClientCalendarNameListWrapper.class, new String[]{SERVICE_URI, CALENDARS}); | ||
if (type != null) { | ||
request.addParam("calendarType", type.name().toLowerCase()); | ||
} | ||
RequestExecution task = new RequestExecution(new Runnable() { | ||
@Override | ||
public void run() { | ||
callback.execute(request.get()); | ||
} | ||
}); | ||
ThreadPoolUtil.runAsynchronously(task); | ||
return task; | ||
} | ||
|
||
public SingleCalendarOperationsAdapter calendar(String calendarName) { | ||
if ("".equals(calendarName) || "/".equals(calendarName)) { | ||
throw new IllegalArgumentException("'calendarName' mustn't be an empty string"); | ||
} | ||
return new SingleCalendarOperationsAdapter(sessionStorage, calendarName); | ||
} | ||
|
||
} |
Oops, something went wrong.