Search in sources :

Example 96 with InvalidRequestException

use of org.camunda.bpm.engine.rest.exception.InvalidRequestException in project camunda-bpm-platform by camunda.

the class IdentityRestServiceImpl method getGroupInfo.

@Override
public GroupInfoDto getGroupInfo(String userId) {
    if (userId == null) {
        throw new InvalidRequestException(Status.BAD_REQUEST, "No user id was supplied");
    }
    IdentityService identityService = getProcessEngine().getIdentityService();
    GroupQuery query = identityService.createGroupQuery();
    List<Group> userGroups = query.groupMember(userId).orderByGroupName().asc().list();
    Set<UserDto> allGroupUsers = new HashSet<UserDto>();
    List<GroupDto> allGroups = new ArrayList<GroupDto>();
    for (Group group : userGroups) {
        List<User> groupUsers = identityService.createUserQuery().memberOfGroup(group.getId()).list();
        for (User user : groupUsers) {
            if (!user.getId().equals(userId)) {
                allGroupUsers.add(new UserDto(user.getId(), user.getFirstName(), user.getLastName()));
            }
        }
        allGroups.add(new GroupDto(group.getId(), group.getName()));
    }
    return new GroupInfoDto(allGroups, allGroupUsers);
}
Also used : Group(org.camunda.bpm.engine.identity.Group) User(org.camunda.bpm.engine.identity.User) UserDto(org.camunda.bpm.engine.rest.dto.task.UserDto) GroupDto(org.camunda.bpm.engine.rest.dto.task.GroupDto) ArrayList(java.util.ArrayList) IdentityService(org.camunda.bpm.engine.IdentityService) GroupQuery(org.camunda.bpm.engine.identity.GroupQuery) GroupInfoDto(org.camunda.bpm.engine.rest.dto.task.GroupInfoDto) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) HashSet(java.util.HashSet)

Example 97 with InvalidRequestException

use of org.camunda.bpm.engine.rest.exception.InvalidRequestException in project camunda-bpm-platform by camunda.

the class IdentityRestServiceImpl method verifyUser.

@Override
public AuthenticationResult verifyUser(BasicUserCredentialsDto credentialsDto) {
    if (credentialsDto.getUsername() == null || credentialsDto.getPassword() == null) {
        throw new InvalidRequestException(Status.BAD_REQUEST, "Username and password are required");
    }
    IdentityService identityService = getProcessEngine().getIdentityService();
    boolean valid = identityService.checkPassword(credentialsDto.getUsername(), credentialsDto.getPassword());
    if (valid) {
        return AuthenticationResult.successful(credentialsDto.getUsername());
    } else {
        return AuthenticationResult.unsuccessful(credentialsDto.getUsername());
    }
}
Also used : IdentityService(org.camunda.bpm.engine.IdentityService) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException)

Example 98 with InvalidRequestException

use of org.camunda.bpm.engine.rest.exception.InvalidRequestException in project camunda-bpm-platform by camunda.

the class JobRestServiceImpl method setRetries.

@Override
public BatchDto setRetries(SetJobRetriesDto setJobRetriesDto) {
    try {
        EnsureUtil.ensureNotNull("setJobRetriesDto", setJobRetriesDto);
        EnsureUtil.ensureNotNull("retries", setJobRetriesDto.getRetries());
    } catch (NullValueException e) {
        throw new InvalidRequestException(Status.BAD_REQUEST, e.getMessage());
    }
    JobQuery jobQuery = null;
    if (setJobRetriesDto.getJobQuery() != null) {
        jobQuery = setJobRetriesDto.getJobQuery().toQuery(getProcessEngine());
    }
    try {
        Batch batch = getProcessEngine().getManagementService().setJobRetriesAsync(setJobRetriesDto.getJobIds(), jobQuery, setJobRetriesDto.getRetries().intValue());
        return BatchDto.fromBatch(batch);
    } catch (BadUserRequestException e) {
        throw new InvalidRequestException(Status.BAD_REQUEST, e.getMessage());
    }
}
Also used : Batch(org.camunda.bpm.engine.batch.Batch) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) JobQuery(org.camunda.bpm.engine.runtime.JobQuery) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException) NullValueException(org.camunda.bpm.engine.exception.NullValueException)

Example 99 with InvalidRequestException

use of org.camunda.bpm.engine.rest.exception.InvalidRequestException in project camunda-bpm-platform by camunda.

the class HistoricProcessInstanceRestServiceImpl method deleteAsync.

@Override
public BatchDto deleteAsync(DeleteHistoricProcessInstancesDto dto) {
    HistoryService historyService = processEngine.getHistoryService();
    HistoricProcessInstanceQuery historicProcessInstanceQuery = null;
    if (dto.getHistoricProcessInstanceQuery() != null) {
        historicProcessInstanceQuery = dto.getHistoricProcessInstanceQuery().toQuery(processEngine);
    }
    try {
        Batch batch = historyService.deleteHistoricProcessInstancesAsync(dto.getHistoricProcessInstanceIds(), historicProcessInstanceQuery, dto.getDeleteReason());
        return BatchDto.fromBatch(batch);
    } catch (BadUserRequestException e) {
        throw new InvalidRequestException(Status.BAD_REQUEST, e.getMessage());
    }
}
Also used : HistoricProcessInstanceQuery(org.camunda.bpm.engine.history.HistoricProcessInstanceQuery) Batch(org.camunda.bpm.engine.batch.Batch) HistoryService(org.camunda.bpm.engine.HistoryService) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException)

Example 100 with InvalidRequestException

use of org.camunda.bpm.engine.rest.exception.InvalidRequestException in project camunda-bpm-platform by camunda.

the class HistoricTaskInstanceRestServiceImpl method getHistoricTaskInstanceReport.

@Override
public Response getHistoricTaskInstanceReport(UriInfo uriInfo) {
    HistoricTaskInstanceReportQueryDto queryDto = new HistoricTaskInstanceReportQueryDto(objectMapper, uriInfo.getQueryParameters());
    Response response;
    if (AbstractReportDto.REPORT_TYPE_DURATION.equals(queryDto.getReportType())) {
        List<? extends ReportResult> reportResults = queryDto.executeReport(processEngine);
        response = Response.ok(generateDurationDto(reportResults)).build();
    } else if (AbstractReportDto.REPORT_TYPE_COUNT.equals(queryDto.getReportType())) {
        List<HistoricTaskInstanceReportResult> reportResults = queryDto.executeCompletedReport(processEngine);
        response = Response.ok(generateCountDto(reportResults)).build();
    } else {
        throw new InvalidRequestException(Response.Status.BAD_REQUEST, "Parameter reportType is not set.");
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) ArrayList(java.util.ArrayList) List(java.util.List) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) HistoricTaskInstanceReportQueryDto(org.camunda.bpm.engine.rest.dto.history.HistoricTaskInstanceReportQueryDto)

Aggregations

InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)116 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)30 RestException (org.camunda.bpm.engine.rest.exception.RestException)25 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)20 NotValidException (org.camunda.bpm.engine.exception.NotValidException)12 ArrayList (java.util.ArrayList)11 BadUserRequestException (org.camunda.bpm.engine.BadUserRequestException)11 ManagementService (org.camunda.bpm.engine.ManagementService)11 NotFoundException (org.camunda.bpm.engine.exception.NotFoundException)11 VariableQueryParameterDto (org.camunda.bpm.engine.rest.dto.VariableQueryParameterDto)10 HistoryService (org.camunda.bpm.engine.HistoryService)9 RuntimeService (org.camunda.bpm.engine.RuntimeService)9 InputStream (java.io.InputStream)8 RepositoryService (org.camunda.bpm.engine.RepositoryService)8 Batch (org.camunda.bpm.engine.batch.Batch)8 URI (java.net.URI)6 VariableMap (org.camunda.bpm.engine.variable.VariableMap)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 FormService (org.camunda.bpm.engine.FormService)5 HistoricProcessInstanceQuery (org.camunda.bpm.engine.history.HistoricProcessInstanceQuery)5