Search in sources :

Example 6 with User

use of cern.modesti.user.User in project modesti by jlsalmon.

the class TaskServiceImpl method assignTask.

/**
 * Assign a task inside a workflow process instance associated to a request
 * to the specified user.
 *
 * @param requestId the id of the request
 * @param taskName  the name of the task to assign
 * @param username  the username to assign the task to
 * @return the updated task info
 */
private TaskInfo assignTask(String requestId, String taskName, String username) {
    Task task = getTaskForRequest(requestId, taskName);
    User user = userService.findOneByUsername(username);
    if (user == null) {
        throw new IllegalArgumentException("No user with username " + username + " was found");
    }
    task.setAssignee(username);
    // This will trigger an "assignment" event on the task, and also cause the assignee to be saved to the request object.
    taskService.setAssignee(task.getId(), username);
    task = getTaskForRequest(requestId, taskName);
    return new TaskInfoImpl(task.getName(), task.getDescription(), task.getOwner(), task.getAssignee(), task.getDelegationState(), getCandidateGroups(task));
}
Also used : Task(org.activiti.engine.task.Task) User(cern.modesti.user.User)

Example 7 with User

use of cern.modesti.user.User in project modesti by jlsalmon.

the class BaseIntegrationTest method doAction.

public void doAction(String requestId, TaskInfo task, TaskAction.Action action) {
    assertNotNull(task);
    User user = userService.getCurrentUser();
    taskService.execute(requestId, task.getName(), new TaskAction(action, user.getUsername()), user);
}
Also used : User(cern.modesti.user.User) TaskAction(cern.modesti.workflow.task.TaskAction)

Example 8 with User

use of cern.modesti.user.User in project modesti by jlsalmon.

the class RequestServiceImpl method assignCreator.

private Request assignCreator(String requestId, String newCreator, String originalCreator) {
    Request request = findOneByRequestId(requestId);
    if (request == null) {
        throw new IllegalArgumentException("No request with id " + requestId + " was found");
    }
    User newCreatorUser = userService.findOneByUsername(newCreator);
    if (newCreatorUser == null) {
        throw new IllegalArgumentException("No user with username " + newCreator + " was found");
    }
    if (!request.getCreator().equals(originalCreator)) {
        throw new NotAuthorisedException(format("User %s is not authorized to change the request creator", originalCreator));
    }
    request.setCreator(newCreator);
    save(request);
    return request;
}
Also used : User(cern.modesti.user.User) NotAuthorisedException(cern.modesti.workflow.task.NotAuthorisedException)

Example 9 with User

use of cern.modesti.user.User in project modesti by jlsalmon.

the class RequestServiceImpl method insert.

/**
 * Insert (create) a new request.
 * <p>
 * Creating a new request performs the following actions:
 * <ul>
 * <li>
 * Asserts that the currently logged-in user is authorised to create a
 * request for the domain of the request
 * </li>
 * <li>
 * Sets the currently logged-in user as the creator of the request
 * </li>
 * <li>Generates a request id</li>
 * <li>Adds some empty points to the request if none were specified</li>
 * <li>Starts a new workflow process instance using the workflow key of the
 * plugin associated with the request domain</li>
 * </ul>
 *
 * @param request the request to create
 * @return the newly created request with all properties set
 */
@Override
public Request insert(Request request) {
    // Do not create a request if there is no appropriate domain
    RequestProvider plugin = requestProviderRegistry.getPluginFor(request, new UnsupportedRequestException(request));
    User user = userService.getCurrentUser();
    // Assert that the current user is allowed to create a request for this domain
    if (!authService.canCreate(plugin, request, user)) {
        throw new NotAuthorisedException(format("User \"%s\" is not authorised to create requests for domain \"%s\". " + "Authorisation group is \"%s\".", user.getUsername(), request.getDomain(), plugin.getMetadata().getAuthorisationGroup(request)));
    }
    // Set the creator as the current logged in user
    request.setCreator(user.getUsername());
    ((RequestImpl) request).setRequestId(counterService.getNextSequence(CounterService.REQUEST_ID_SEQUENCE).toString());
    log.trace(format("generated request id: %s", request.getRequestId()));
    ((RequestImpl) request).setCreatedAt(new DateTime());
    if (request.getPoints() == null) {
        request.setPoints(new ArrayList<>());
    }
    // Apply formatting to the request points
    requestFormatter.format(request);
    // Add some empty points if there aren't any yet
    if (request.getPoints().isEmpty()) {
        for (int i = 0; i < 50; i++) {
            Point point = new PointImpl((long) (i + 1));
            request.addPoint(point);
        }
    }
    for (Point point : request.getPoints()) {
        if (point.getLineNo() == null) {
            point.setLineNo((long) (request.getPoints().indexOf(point) + 1));
        }
    }
    request = repository.save((RequestImpl) request);
    if (request.getType().equals(RequestType.UPDATE)) {
        // Store an initial, empty change history
        ((RequestHistoryServiceImpl) historyService).initialiseChangeHistory(request);
    }
    // Kick off the workflow process
    workflowService.startProcessInstance(request);
    return request;
}
Also used : User(cern.modesti.user.User) NotAuthorisedException(cern.modesti.workflow.task.NotAuthorisedException) RequestProvider(cern.modesti.plugin.RequestProvider) Point(cern.modesti.point.Point) UnsupportedRequestException(cern.modesti.plugin.UnsupportedRequestException) DateTime(org.joda.time.DateTime) Point(cern.modesti.point.Point) PointImpl(cern.modesti.point.PointImpl) RequestHistoryServiceImpl(cern.modesti.request.history.RequestHistoryServiceImpl)

Example 10 with User

use of cern.modesti.user.User in project modesti by jlsalmon.

the class RequestController method action.

@RequestMapping(path = "/requests/{id}", value = "/requests/{id}", method = POST, produces = "application/hal+json")
@PreAuthorize("permitAll")
public HttpEntity<Resource<Request>> action(@PathVariable("id") String requestId, @RequestBody RequestAction action, Principal principal) {
    User user = (User) ((UsernamePasswordAuthenticationToken) principal).getPrincipal();
    Request request = requestService.execute(requestId, action, user);
    if (request != null) {
        Resource<Request> resource = new Resource<>(request);
        resource.add(linkTo(methodOn(RequestController.class).action(requestId, action, principal)).withSelfRel());
        return new ResponseEntity<>(resource, HttpStatus.OK);
    }
    return new ResponseEntity<>(HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) User(cern.modesti.user.User) Request(cern.modesti.request.Request) Resource(org.springframework.hateoas.Resource) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

User (cern.modesti.user.User)11 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)3 Request (cern.modesti.request.Request)2 NotAuthorisedException (cern.modesti.workflow.task.NotAuthorisedException)2 TaskAction (cern.modesti.workflow.task.TaskAction)2 Resource (org.springframework.hateoas.Resource)2 ResponseEntity (org.springframework.http.ResponseEntity)2 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)2 Authentication (org.springframework.security.core.Authentication)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 RequestProvider (cern.modesti.plugin.RequestProvider)1 UnsupportedRequestException (cern.modesti.plugin.UnsupportedRequestException)1 Point (cern.modesti.point.Point)1 PointImpl (cern.modesti.point.PointImpl)1 RequestHistoryServiceImpl (cern.modesti.request.history.RequestHistoryServiceImpl)1 UserImpl (cern.modesti.user.UserImpl)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 Task (org.activiti.engine.task.Task)1 DateTime (org.joda.time.DateTime)1