org.activiti.engine.identity.User Java Examples

The following examples show how to use org.activiti.engine.identity.User. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IdentityController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 保存User
 *
 * @param redirectAttributes
 * @return
 */
@RequestMapping(value = "user/save", method = RequestMethod.POST)
public String saveUser(@RequestParam("userId") String userId,
                       @RequestParam("firstName") String firstName,
                       @RequestParam("lastName") String lastName,
                       @RequestParam(value = "password", required = false) String password,
                       @RequestParam(value = "email", required = false) String email,
                       RedirectAttributes redirectAttributes) {
    User user = identityService.createUserQuery().userId(userId).singleResult();
    if (user == null) {
        user = identityService.newUser(userId);
    }
    user.setFirstName(firstName);
    user.setLastName(lastName);
    user.setEmail(email);
    if (StringUtils.isNotBlank(password)) {
        user.setPassword(password);
    }
    identityService.saveUser(user);
    redirectAttributes.addFlashAttribute("message", "成功添加用户[" + firstName + " " + lastName + "]");
    return "redirect:/chapter14/identity/user/list";
}
 
Example #2
Source File: TraceProcessController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 获取当前节点信息
 *
 * @return
 */
private void setCurrentTaskInfo(String executionId, String activityId, Map<String, Object> vars) {
    Task currentTask = taskService.createTaskQuery().executionId(executionId)
            .taskDefinitionKey(activityId).singleResult();
    logger.debug("current task for processInstance: {}", ToStringBuilder.reflectionToString(currentTask));

    if (currentTask == null) return;

    String assignee = currentTask.getAssignee();
    if (assignee != null) {
        User assigneeUser = identityService.createUserQuery().userId(assignee).singleResult();
        String userInfo = assigneeUser.getFirstName() + " " + assigneeUser.getLastName() + "/" + assigneeUser.getId();
        vars.put("当前处理人", userInfo);
        vars.put("创建时间", new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(currentTask.getCreateTime()));
    } else {
        vars.put("任务状态", "未签收");
    }

}
 
Example #3
Source File: TraceProcessController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 获取当前节点信息
 *
 * @return
 */
private void setCurrentTaskInfo(String executionId, String activityId, Map<String, Object> vars) {
    Task currentTask = taskService.createTaskQuery().executionId(executionId)
            .taskDefinitionKey(activityId).singleResult();
    logger.debug("current task for processInstance: {}", ToStringBuilder.reflectionToString(currentTask));

    if (currentTask == null) return;

    String assignee = currentTask.getAssignee();
    if (assignee != null) {
        User assigneeUser = identityService.createUserQuery().userId(assignee).singleResult();
        String userInfo = assigneeUser.getFirstName() + " " + assigneeUser.getLastName() + "/" + assigneeUser.getId();
        vars.put("当前处理人", userInfo);
        vars.put("创建时间", new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(currentTask.getCreateTime()));
    } else {
        vars.put("任务状态", "未签收");
    }

}
 
Example #4
Source File: AbstractProcessInstanceQueryResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected List<ProcessInstanceRepresentation> convertInstanceList(List<HistoricProcessInstance> instances) {
  List<ProcessInstanceRepresentation> result = new ArrayList<ProcessInstanceRepresentation>();
  if (CollectionUtils.isNotEmpty(instances)) {

    for (HistoricProcessInstance processInstance : instances) {
      User userRep = null;
      if (processInstance.getStartUserId() != null) {
        CachedUser user = userCache.getUser(processInstance.getStartUserId());
        if (user != null && user.getUser() != null) {
          userRep = user.getUser();
        }
      }

      ProcessDefinitionEntity procDef = (ProcessDefinitionEntity) repositoryService.getProcessDefinition(processInstance.getProcessDefinitionId());
      ProcessInstanceRepresentation instanceRepresentation = new ProcessInstanceRepresentation(processInstance, procDef, procDef.isGraphicalNotationDefined(), userRep);
      result.add(instanceRepresentation);
    }

  }
  return result;
}
 
Example #5
Source File: PersistentTokenServiceImpl.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
public PersistentToken createToken(User user, String remoteAddress, String userAgent) {

  PersistentToken token = new PersistentToken();
  token.setSeries(generateSeriesData());
  token.setUser(user.getId());
  token.setTokenValue(generateTokenData());
  token.setTokenDate(new Date());
  token.setIpAddress(remoteAddress);
  token.setUserAgent(userAgent);
  try {
    saveAndFlush(token);
    return token;
  } catch (DataAccessException e) {
    logger.error("Failed to save persistent token ", e);
    return token;
  }
}
 
Example #6
Source File: IdentityServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testCreateMembershipAlreadyExisting() {
  Group sales = identityService.newGroup("sales");
  identityService.saveGroup(sales);
  User johndoe = identityService.newUser("johndoe");
  identityService.saveUser(johndoe);

  // Create the membership
  identityService.createMembership(johndoe.getId(), sales.getId());

  try {
    identityService.createMembership(johndoe.getId(), sales.getId());
  } catch (RuntimeException re) {
    // Expected exception, membership already exists
  }

  identityService.deleteGroup(sales.getId());
  identityService.deleteUser(johndoe.getId());
}
 
Example #7
Source File: TaskServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testClaimAlreadyClaimedTaskBySameUser() {
  Task task = taskService.newTask();
  taskService.saveTask(task);
  User user = identityService.newUser("user");
  identityService.saveUser(user);

  // Claim task the first time
  taskService.claim(task.getId(), user.getId());
  task = taskService.createTaskQuery().taskId(task.getId()).singleResult();

  // Claim the task again with the same user. No exception should be
  // thrown
  taskService.claim(task.getId(), user.getId());

  taskService.deleteTask(task.getId(), true);
  identityService.deleteUser(user.getId());
}
 
Example #8
Source File: TraceProcessController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 获取当前节点信息
 *
 * @return
 */
private void setCurrentTaskInfo(String executionId, String activityId, Map<String, Object> vars) {
    Task currentTask = taskService.createTaskQuery().executionId(executionId)
            .taskDefinitionKey(activityId).singleResult();
    logger.debug("current task for processInstance: {}", ToStringBuilder.reflectionToString(currentTask));

    if (currentTask == null) return;

    String assignee = currentTask.getAssignee();
    if (assignee != null) {
        User assigneeUser = identityService.createUserQuery().userId(assignee).singleResult();
        String userInfo = assigneeUser.getFirstName() + " " + assigneeUser.getLastName() + "/" + assigneeUser.getId();
        vars.put("当前处理人", userInfo);
        vars.put("创建时间", new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(currentTask.getCreateTime()));
    } else {
        vars.put("任务状态", "未签收");
    }

}
 
Example #9
Source File: AbstractModelsResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public ResultListDataRepresentation getModelsToIncludeInAppDefinition() {

    List<ModelRepresentation> resultList = new ArrayList<ModelRepresentation>();

    User user = SecurityUtils.getCurrentUserObject();

    List<String> addedModelIds = new ArrayList<String>();

    List<Model> models = modelRepository.findModelsCreatedBy(user.getId(), 0, getSort(null, false));

    if (CollectionUtils.isNotEmpty(models)) {
      for (Model model : models) {
        if (addedModelIds.contains(model.getId()) == false) {
          addedModelIds.add(model.getId());
          ModelRepresentation representation = createModelRepresentation(model);
          resultList.add(representation);
        }
      }
    }

    ResultListDataRepresentation result = new ResultListDataRepresentation(resultList);
    return result;
  }
 
Example #10
Source File: ActivitiTaskActionService.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void assignTask(User currentUser, Task task, String assigneeIdString) {
  try {
    String oldAssignee = task.getAssignee();
    taskService.setAssignee(task.getId(), assigneeIdString);

    // If the old assignee user wasn't part of the involved users yet, make it so
    addIdentiyLinkForUser(task, oldAssignee, IdentityLinkType.PARTICIPANT);

    // If the current user wasn't part of the involved users yet, make it so
    String currentUserIdString = String.valueOf(currentUser.getId());
    addIdentiyLinkForUser(task, currentUserIdString, IdentityLinkType.PARTICIPANT);

  } catch (ActivitiException e) {
    throw new BadRequestException("Task " + task.getId() + " can't be assigned", e);
  }
}
 
Example #11
Source File: AbstractRelatedContentResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected RelatedContentRepresentation uploadFile(User user, MultipartFile file, String taskId, String processInstanceId) {
    if (file != null && file.getName() != null) {
        try {
            String contentType = file.getContentType();
            
            // temp additional content type check for IE9 flash uploads
            if (StringUtils.equals(file.getContentType(), "application/octet-stream")) {
                contentType = getContentTypeForFileExtension(file);
            }
            
            RelatedContent relatedContent = contentService.createRelatedContent(user, getFileName(file), null, null, taskId, processInstanceId, 
                    contentType, file.getInputStream(), file.getSize(), true, false);
            return new RelatedContentRepresentation(relatedContent, simpleTypeMapper);
        } catch (IOException e) {
            throw new BadRequestException("Error while reading file data", e);
        }
    } else {
        throw new BadRequestException("File to upload is missing");
    }
}
 
Example #12
Source File: IdmGroupsResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@ResponseStatus(value = HttpStatus.OK)
@RequestMapping(value = "/{groupId}/members/{userId}", method = RequestMethod.POST)
public void addGroupMember(@PathVariable String groupId, @PathVariable String userId) {
  validateAdminRole();
  verifyGroupMemberExists(groupId, userId);
  Group group = identityService.createGroupQuery().groupId(groupId).singleResult();
  if (group == null) {
    throw new NotFoundException();
  }
  
  User user = identityService.createUserQuery().userId(userId).singleResult();
  if (user == null) {
    throw new NotFoundException();
  }
  
  identityService.createMembership(userId, groupId);
}
 
Example #13
Source File: TaskCandidateTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void setUp() throws Exception {
  super.setUp();
  
  Group accountants = identityService.newGroup("accountancy");
  identityService.saveGroup(accountants);
  Group managers = identityService.newGroup("management");
  identityService.saveGroup(managers);
  Group sales = identityService.newGroup("sales");
  identityService.saveGroup(sales);

  User kermit = identityService.newUser(KERMIT);
  identityService.saveUser(kermit);
  identityService.createMembership(KERMIT, "accountancy");

  User gonzo = identityService.newUser(GONZO);
  identityService.saveUser(gonzo);
  identityService.createMembership(GONZO, "management");
  identityService.createMembership(GONZO, "accountancy");
  identityService.createMembership(GONZO, "sales");
}
 
Example #14
Source File: ModelServiceImpl.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
@Transactional
public Model createModel(ModelRepresentation model, String editorJson, User createdBy) {
  Model newModel = new Model();
  newModel.setVersion(1);
  newModel.setName(model.getName());
  newModel.setKey(model.getKey());
  newModel.setModelType(model.getModelType());
  newModel.setCreated(Calendar.getInstance().getTime());
  newModel.setCreatedBy(createdBy.getId());
  newModel.setDescription(model.getDescription());
  newModel.setModelEditorJson(editorJson);
  newModel.setLastUpdated(Calendar.getInstance().getTime());
  newModel.setLastUpdatedBy(createdBy.getId());

  persistModel(newModel);
  return newModel;
}
 
Example #15
Source File: AppDefinitionPublishService.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void publishAppDefinition(String comment, Model appDefinitionModel, User user) {

    // Create new version of the app model
    modelService.createNewModelVersion(appDefinitionModel, comment, user);

    // Deploy the app model to be executable
    deploymentService.updateAppDefinition(appDefinitionModel, user);
  }
 
Example #16
Source File: UserResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "Update a user", tags = {"Users"},
    notes="All request values are optional. "
        + "For example, you can only include the firstName attribute in the request body JSON-object, only updating the firstName of the user, leaving all other fields unaffected. "
        + "When an attribute is explicitly included and is set to null, the user-value will be updated to null. "
        + "Example: {\"firstName\" : null} will clear the firstName of the user).")
@ApiResponses(value = {
    @ApiResponse(code = 200, message = "Indicates the user was updated."),
    @ApiResponse(code = 404, message = "Indicates the requested user was not found."),
    @ApiResponse(code = 409, message = "Indicates the requested user was updated simultaneously.")
})
@RequestMapping(value = "/identity/users/{userId}", method = RequestMethod.PUT, produces = "application/json")
public UserResponse updateUser(@ApiParam(name = "userId") @PathVariable String userId, @RequestBody UserRequest userRequest, HttpServletRequest request) {
  User user = getUserFromRequest(userId);
  if (userRequest.isEmailChanged()) {
    user.setEmail(userRequest.getEmail());
  }
  if (userRequest.isFirstNameChanged()) {
    user.setFirstName(userRequest.getFirstName());
  }
  if (userRequest.isLastNameChanged()) {
    user.setLastName(userRequest.getLastName());
  }
  if (userRequest.isPasswordChanged()) {
    user.setPassword(userRequest.getPassword());
  }

  identityService.saveUser(user);

  return restResponseFactory.createUserResponse(user, false);
}
 
Example #17
Source File: SerializableVariablesDiabledTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Before
public void setupServer() {
	if (serverUrlPrefix == null) {
		TestServer testServer = TestServerUtil.createAndStartServer(ObjectVariableSerializationDisabledApplicationConfiguration.class);
		serverUrlPrefix = testServer.getServerUrlPrefix();
		
		this.repositoryService = testServer.getApplicationContext().getBean(RepositoryService.class);
		this.runtimeService = testServer.getApplicationContext().getBean(RuntimeService.class);
		this.identityService = testServer.getApplicationContext().getBean(IdentityService.class);
		this.taskService = testServer.getApplicationContext().getBean(TaskService.class);
		
    User user = identityService.newUser("kermit");
    user.setFirstName("Kermit");
    user.setLastName("the Frog");
    user.setPassword("kermit");
    identityService.saveUser(user);
    
    Group group = identityService.newGroup("admin");
    group.setName("Administrators");
    identityService.saveGroup(group);
    
    identityService.createMembership(user.getId(), group.getId());
    
    this.testUserId = user.getId();
    this.testGroupId = group.getId();
	}
}
 
Example #18
Source File: IdentityServiceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testDeleteMembershipUnexistingGroup() {
  User johndoe = identityService.newUser("johndoe");
  identityService.saveUser(johndoe);
  // No exception should be thrown when group doesn't exist
  identityService.deleteMembership(johndoe.getId(), "unexistinggroup");
  identityService.deleteUser(johndoe.getId());
}
 
Example #19
Source File: UserResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "/rest/users/{userId}", method = RequestMethod.GET, produces = "application/json")
public UserRepresentation getUser(@PathVariable String userId, HttpServletResponse response) {
  User user = identityService.createUserQuery().userId(userId).singleResult();

  if (user == null) {
    throw new NotFoundException("User with id: " + userId + " does not exist or is inactive");
  }

  if (!user.getId().equals(SecurityUtils.getCurrentUserId())) {
    throw new NotPermittedException("Can only get user details for authenticated user");
  }

  return new UserRepresentation(user);
}
 
Example #20
Source File: UserPictureResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "Get a user’s picture", tags = {"Users"},
    notes = "The response body contains the raw picture data, representing the user’s picture. The Content-type of the response corresponds to the mimeType that was set when creating the picture.")
@ApiResponses(value = {
    @ApiResponse(code = 200, message = "Indicates the user was found and has a picture, which is returned in the body."),
    @ApiResponse(code = 404, message = "Indicates the requested user was not found or the user does not have a profile picture. Status-description contains additional information about the error.")
})
@RequestMapping(value = "/identity/users/{userId}/picture", method = RequestMethod.GET)
public ResponseEntity<byte[]> getUserPicture(@ApiParam(name = "userId", value="The id of the user to get the picture for.") @PathVariable String userId, HttpServletRequest request, HttpServletResponse response) {
  User user = getUserFromRequest(userId);
  Picture userPicture = identityService.getUserPicture(user.getId());

  if (userPicture == null) {
    throw new ActivitiObjectNotFoundException("The user with id '" + user.getId() + "' does not have a picture.", Picture.class);
  }


  HttpHeaders responseHeaders = new HttpHeaders();
  if (userPicture.getMimeType() != null) {
    responseHeaders.set("Content-Type", userPicture.getMimeType());
  } else {
    responseHeaders.set("Content-Type", "image/jpeg");
  }

  try {
    return new ResponseEntity<byte[]>(IOUtils.toByteArray(userPicture.getInputStream()), responseHeaders, HttpStatus.OK);
  } catch (Exception e) {
    throw new ActivitiException("Error exporting picture: " + e.getMessage(), e);
  }
}
 
Example #21
Source File: CommentService.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public Comment createComment(String message, User createdBy, String taskId, String processInstanceId) {
    Comment newComment = new Comment();
    newComment.setMessage(message);
    newComment.setCreatedBy(createdBy.getId());
    newComment.setCreated(clock.getCurrentTime());
    newComment.setTaskId(taskId);
    newComment.setProcessInstanceId(processInstanceId);

    commentRepository.save(newComment);
    return newComment;
}
 
Example #22
Source File: ActUserEntityService.java    From Shop-for-JavaWeb with MIT License 5 votes vote down vote up
public List<Group> findGroupsByUser(String userId) {
//		return getDbSqlSession().selectList("selectGroupsByUserId", userId);
		List<Group> list = Lists.newArrayList();
		for (Role role : getSystemService().findRole(new Role(new com.iwc.shop.modules.sys.entity.User(null, userId)))){
			list.add(ActUtils.toActivitiGroup(role));
		}
		return list;
	}
 
Example #23
Source File: UserResourceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Test updating a single user passing in no fields in the json, user should remain unchanged.
 */
public void testUpdateUserNoFields() throws Exception {
  User savedUser = null;
  try {
    User newUser = identityService.newUser("testuser");
    newUser.setFirstName("Fred");
    newUser.setLastName("McDonald");
    newUser.setEmail("[email protected]");
    identityService.saveUser(newUser);
    savedUser = newUser;

    ObjectNode taskUpdateRequest = objectMapper.createObjectNode();

    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER, newUser.getId()));
    httpPut.setEntity(new StringEntity(taskUpdateRequest.toString()));
    CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals("testuser", responseNode.get("id").textValue());
    assertEquals("Fred", responseNode.get("firstName").textValue());
    assertEquals("McDonald", responseNode.get("lastName").textValue());
    assertEquals("[email protected]", responseNode.get("email").textValue());
    assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_USER, newUser.getId())));

    // Check user is updated in activiti
    newUser = identityService.createUserQuery().userId(newUser.getId()).singleResult();
    assertEquals("McDonald", newUser.getLastName());
    assertEquals("Fred", newUser.getFirstName());
    assertEquals("[email protected]", newUser.getEmail());
    assertNull(newUser.getPassword());

  } finally {

    // Delete user after test fails
    if (savedUser != null) {
      identityService.deleteUser(savedUser.getId());
    }
  }
}
 
Example #24
Source File: SetMailInfo.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
@Override
public void notify(DelegateExecution execution) throws Exception {
    IdentityService identityService = execution.getEngineServices().getIdentityService();
    String applyUserId = (String) execution.getVariable("applyUserId");
    User user = identityService.createUserQuery().userId(applyUserId).singleResult();
    execution.setVariableLocal("to", user.getEmail());
    execution.setVariableLocal("name", user.getFirstName() + " " + user.getLastName());

    // 超时提醒时间设置,请假结束时间+1天
    Date endDate = (Date) execution.getVariable("endDate");
    Calendar ca = Calendar.getInstance();
    ca.setTime(endDate);
    ca.add(Calendar.DAY_OF_MONTH, 1);
    execution.setVariableLocal("reportBackTimeout", ca.getTime());
}
 
Example #25
Source File: AiaUserManagerImpl.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
@Override
public AiaUser save(AiaUser user) {
    dao.save(user);
    User activitiUser = null;
    if (user.getId() == null) {
        activitiUser = identityService.newUser(user.getId().toString());
    } else {
        activitiUser = identityService.createUserQuery()
                .userId(user.getId().toString()).singleResult();
        /** 省略代码 -> 复制user的属性到activitiUser */
        identityService.saveUser(activitiUser);
    }
    return user;
}
 
Example #26
Source File: AccountController.java    From maven-framework-project with MIT License 5 votes vote down vote up
/**
 * 查看用户列表
 * @param request
 * @param response
 * @return
 */
@RequestMapping(value="/userlist",method={RequestMethod.POST,RequestMethod.GET})
public ModelAndView userlist(HttpServletRequest request, HttpServletResponse response){
	List<org.activiti.engine.identity.User> listuser = accountService.createUserQuery().list();
	ModelAndView modelAndView=new ModelAndView();
	modelAndView.setViewName("user/listuser");
	modelAndView.addObject("listuser", listuser);
	return modelAndView;
}
 
Example #27
Source File: UserCollectionResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "Create a user", tags = {"Users"})
@ApiResponses(value = {
    @ApiResponse(code = 201, message = "Indicates the user was created."),
    @ApiResponse(code = 400, message = "Indicates the id of the user was missing.")
})
@RequestMapping(value = "/identity/users", method = RequestMethod.POST, produces = "application/json")
public UserResponse createUser(@RequestBody UserRequest userRequest, HttpServletRequest request, HttpServletResponse response) {
  if (userRequest.getId() == null) {
    throw new ActivitiIllegalArgumentException("Id cannot be null.");
  }

  // Check if a user with the given ID already exists so we return a
  // CONFLICT
  if (identityService.createUserQuery().userId(userRequest.getId()).count() > 0) {
    throw new ActivitiConflictException("A user with id '" + userRequest.getId() + "' already exists.");
  }

  User created = identityService.newUser(userRequest.getId());
  created.setEmail(userRequest.getEmail());
  created.setFirstName(userRequest.getFirstName());
  created.setLastName(userRequest.getLastName());
  created.setPassword(userRequest.getPassword());
  identityService.saveUser(created);

  response.setStatus(HttpStatus.CREATED.value());

  return restResponseFactory.createUserResponse(created, true);
}
 
Example #28
Source File: AbstractRelatedContentResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public RelatedContentRepresentation createRelatedContentOnTask(String taskId, MultipartFile file) {
    User user = SecurityUtils.getCurrentUserObject();
    
    Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
    if(task == null) {
        throw new NotFoundException("Task not found or already completed: " + taskId);
    }
    
    if(!permissionService.canAddRelatedContentToTask(user, taskId)) {
        throw new NotPermittedException("You are not allowed to read the task with id: " + taskId);
    }
    return uploadFile(user, file, taskId, task.getProcessInstanceId());
}
 
Example #29
Source File: GetUserPictureCmd.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public Picture execute(CommandContext commandContext) {
  if (userId == null) {
    throw new ActivitiIllegalArgumentException("userId is null");
  }
  User user = commandContext.getUserEntityManager().findById(userId);
  if (user == null) {
    throw new ActivitiObjectNotFoundException("user " + userId + " doesn't exist", User.class);
  }
  return commandContext.getUserEntityManager().getUserPicture(userId);
}
 
Example #30
Source File: UseController.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 登录系统
 *
 * @param userName
 * @param password
 * @param session
 * @return
 */
@RequestMapping(value = "/logon")
public String logon(@RequestParam("username") String userName, @RequestParam("password") String password, HttpSession session) {
    logger.debug("logon request: {username={}, password={}}", userName, password);
    boolean checkPassword = identityService.checkPassword(userName, password);
    if (checkPassword) {

        // 查看用户是否存在
        User user = identityService.createUserQuery().userId(userName).singleResult();
        UserUtil.saveUserToSession(session, user);

  /*
   * 读取角色
   */
        List<Group> groupList = identityService.createGroupQuery().groupMember(user.getId()).list();
        session.setAttribute("groups", groupList);

        String[] groupNames = new String[groupList.size()];
        for (int i = 0; i < groupNames.length; i++) {
            groupNames[i] = groupList.get(i).getName();
        }
        session.setAttribute("groupNames", ArrayUtils.toString(groupNames));

        return "redirect:/main/index";
    } else {
        return "redirect:/login.jsp?error=true";
    }
}