use of org.camunda.bpm.engine.rest.exception.InvalidRequestException in project camunda-bpm-platform by camunda.
the class JobResourceImpl method setJobPriority.
@Override
public void setJobPriority(PriorityDto dto) {
if (dto.getPriority() == null) {
throw new RestException(Status.BAD_REQUEST, "Priority for job '" + jobId + "' cannot be null.");
}
try {
ManagementService managementService = engine.getManagementService();
managementService.setJobPriority(jobId, dto.getPriority());
} catch (AuthorizationException e) {
throw e;
} catch (NotFoundException e) {
throw new InvalidRequestException(Status.NOT_FOUND, e.getMessage());
} catch (ProcessEngineException e) {
throw new RestException(Status.INTERNAL_SERVER_ERROR, e.getMessage());
}
}
use of org.camunda.bpm.engine.rest.exception.InvalidRequestException in project camunda-bpm-platform by camunda.
the class TaskAttachmentResourceImpl method addAttachment.
@Override
public AttachmentDto addAttachment(UriInfo uriInfo, MultipartFormData payload) {
ensureHistoryEnabled(Status.FORBIDDEN);
ensureTaskExists(Status.BAD_REQUEST);
FormPart attachmentNamePart = payload.getNamedPart("attachment-name");
FormPart attachmentTypePart = payload.getNamedPart("attachment-type");
FormPart attachmentDescriptionPart = payload.getNamedPart("attachment-description");
FormPart contentPart = payload.getNamedPart("content");
FormPart urlPart = payload.getNamedPart("url");
if (urlPart == null && contentPart == null) {
throw new InvalidRequestException(Status.BAD_REQUEST, "No content or url to remote content exists to create the task attachment.");
}
String attachmentName = null;
String attachmentDescription = null;
String attachmentType = null;
if (attachmentNamePart != null) {
attachmentName = attachmentNamePart.getTextContent();
}
if (attachmentDescriptionPart != null) {
attachmentDescription = attachmentDescriptionPart.getTextContent();
}
if (attachmentTypePart != null) {
attachmentType = attachmentTypePart.getTextContent();
}
Attachment attachment = null;
try {
if (contentPart != null) {
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(contentPart.getBinaryContent());
attachment = engine.getTaskService().createAttachment(attachmentType, taskId, null, attachmentName, attachmentDescription, byteArrayInputStream);
} else if (urlPart != null) {
attachment = engine.getTaskService().createAttachment(attachmentType, taskId, null, attachmentName, attachmentDescription, urlPart.getTextContent());
}
} catch (ProcessEngineException e) {
throw new InvalidRequestException(Status.BAD_REQUEST, e, "Task id is null");
}
URI uri = uriInfo.getBaseUriBuilder().path(rootResourcePath).path(TaskRestService.PATH).path(taskId + "/attachment/" + attachment.getId()).build();
AttachmentDto attachmentDto = AttachmentDto.fromAttachment(attachment);
// GET /
attachmentDto.addReflexiveLink(uri, HttpMethod.GET, "self");
return attachmentDto;
}
use of org.camunda.bpm.engine.rest.exception.InvalidRequestException in project camunda-bpm-platform by camunda.
the class ProcessDefinitionRestServiceImpl method getStatistics.
@Override
public List<StatisticsResultDto> getStatistics(Boolean includeFailedJobs, Boolean includeRootIncidents, Boolean includeIncidents, String includeIncidentsForType) {
if (includeIncidents != null && includeIncidentsForType != null) {
throw new InvalidRequestException(Status.BAD_REQUEST, "Only one of the query parameter includeIncidents or includeIncidentsForType can be set.");
}
if (includeIncidents != null && includeRootIncidents != null) {
throw new InvalidRequestException(Status.BAD_REQUEST, "Only one of the query parameter includeIncidents or includeRootIncidents can be set.");
}
if (includeRootIncidents != null && includeIncidentsForType != null) {
throw new InvalidRequestException(Status.BAD_REQUEST, "Only one of the query parameter includeRootIncidents or includeIncidentsForType can be set.");
}
ManagementService mgmtService = getProcessEngine().getManagementService();
ProcessDefinitionStatisticsQuery query = mgmtService.createProcessDefinitionStatisticsQuery();
if (includeFailedJobs != null && includeFailedJobs) {
query.includeFailedJobs();
}
if (includeIncidents != null && includeIncidents) {
query.includeIncidents();
} else if (includeIncidentsForType != null) {
query.includeIncidentsForType(includeIncidentsForType);
} else if (includeRootIncidents != null && includeRootIncidents) {
query.includeRootIncidents();
}
List<ProcessDefinitionStatistics> queryResults = query.list();
List<StatisticsResultDto> results = new ArrayList<StatisticsResultDto>();
for (ProcessDefinitionStatistics queryResult : queryResults) {
StatisticsResultDto dto = ProcessDefinitionStatisticsResultDto.fromProcessDefinitionStatistics(queryResult);
results.add(dto);
}
return results;
}
use of org.camunda.bpm.engine.rest.exception.InvalidRequestException in project camunda-bpm-platform by camunda.
the class ProcessInstanceRestServiceImpl method setRetriesByProcessHistoricQueryBased.
@Override
public BatchDto setRetriesByProcessHistoricQueryBased(SetJobRetriesByProcessDto setJobRetriesDto) {
List<String> processInstanceIds = new ArrayList<String>();
HistoricProcessInstanceQueryDto queryDto = setJobRetriesDto.getHistoricProcessInstanceQuery();
if (queryDto != null) {
HistoricProcessInstanceQuery query = queryDto.toQuery(getProcessEngine());
List<HistoricProcessInstance> historicProcessInstances = query.list();
for (HistoricProcessInstance historicProcessInstance : historicProcessInstances) {
processInstanceIds.add(historicProcessInstance.getId());
}
}
if (setJobRetriesDto.getProcessInstances() != null) {
processInstanceIds.addAll(setJobRetriesDto.getProcessInstances());
}
try {
ManagementService managementService = getProcessEngine().getManagementService();
Batch batch = managementService.setJobRetriesAsync(processInstanceIds, (ProcessInstanceQuery) null, setJobRetriesDto.getRetries());
return BatchDto.fromBatch(batch);
} catch (BadUserRequestException e) {
throw new InvalidRequestException(Status.BAD_REQUEST, e.getMessage());
}
}
use of org.camunda.bpm.engine.rest.exception.InvalidRequestException in project camunda-bpm-platform by camunda.
the class ProcessInstanceRestServiceImpl method setRetriesByProcess.
@Override
public BatchDto setRetriesByProcess(SetJobRetriesByProcessDto setJobRetriesDto) {
try {
EnsureUtil.ensureNotNull("setJobRetriesDto", setJobRetriesDto);
EnsureUtil.ensureNotNull("retries", setJobRetriesDto.getRetries());
} catch (NullValueException e) {
throw new InvalidRequestException(Status.BAD_REQUEST, e.getMessage());
}
ProcessInstanceQuery processInstanceQuery = null;
if (setJobRetriesDto.getProcessInstanceQuery() != null) {
processInstanceQuery = setJobRetriesDto.getProcessInstanceQuery().toQuery(getProcessEngine());
}
try {
Batch batch = getProcessEngine().getManagementService().setJobRetriesAsync(setJobRetriesDto.getProcessInstances(), processInstanceQuery, setJobRetriesDto.getRetries().intValue());
return BatchDto.fromBatch(batch);
} catch (BadUserRequestException e) {
throw new InvalidRequestException(Status.BAD_REQUEST, e.getMessage());
}
}
Aggregations