Java Code Examples for org.activiti.engine.identity.User#setLastName()
The following examples show how to use
org.activiti.engine.identity.User#setLastName() .
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: UserAndGroupInUserTaskTest.java From activiti-in-action-codes with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { // 初始化7大Service实例 super.setUp(); // 创建并保存组对象 Group group = identityService.newGroup("deptLeader"); group.setName("部门领导"); group.setType("assignment"); identityService.saveGroup(group); // 创建并保存用户对象 User user = identityService.newUser("henryyan"); user.setFirstName("Henry"); user.setLastName("Yan"); user.setEmail("[email protected]"); identityService.saveUser(user); // 把用户henryyan加入到组deptLeader中 identityService.createMembership("henryyan", "deptLeader"); }
Example 2
Source File: UserInfoResourceTest.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
/** * Test deleting the info for a user who doesn't have that info set */ public void testUpdateUnexistingInfo() 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 requestNode = objectMapper.createObjectNode(); requestNode.put("value", "Updated value"); HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO, "testuser", "key1")); httpPut.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPut, HttpStatus.SC_NOT_FOUND)); } finally { // Delete user after test passes or fails if (savedUser != null) { identityService.deleteUser(savedUser.getId()); } } }
Example 3
Source File: IdentityController.java From activiti-in-action-codes with Apache License 2.0 | 6 votes |
/** * 保存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 4
Source File: IdentityController.java From activiti-in-action-codes with Apache License 2.0 | 6 votes |
/** * 保存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 5
Source File: UserPictureResourceTest.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
/** * Test getting the picture for a user who doesn't have a îcture set */ public void testGetPictureForUserWithoutPicture() 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; CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_PICTURE, newUser.getId())), HttpStatus.SC_NOT_FOUND); // response content type application/json;charset=UTF-8 assertEquals("application/json", response.getEntity().getContentType().getValue().split(";")[0]); closeResponse(response); } finally { // Delete user after test passes or fails if (savedUser != null) { identityService.deleteUser(savedUser.getId()); } } }
Example 6
Source File: IdmProfileResource.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
@RequestMapping(value = "/profile", method = RequestMethod.POST, produces = "application/json") public UserRepresentation updateProfile(@RequestBody UserRepresentation userRepresentation) { User currentUser = SecurityUtils.getCurrentUserObject(); // If user is not externally managed, we need the email address for login, so an empty email is not allowed if (StringUtils.isEmpty(userRepresentation.getEmail())) { throw new BadRequestException("Empty email is not allowed"); } User user = identityService.createUserQuery().userId(currentUser.getId()).singleResult(); user.setFirstName(userRepresentation.getFirstName()); user.setLastName(userRepresentation.getLastName()); user.setEmail(userRepresentation.getEmail()); identityService.saveUser(user); return new UserRepresentation(user); }
Example 7
Source File: IdmUsersResource.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
@RequestMapping(value = "/rest/admin/users", method = RequestMethod.POST) public User createNewUser(@RequestBody CreateUserRepresentation userRepresentation) { validateAdminRole(); if(StringUtils.isBlank(userRepresentation.getId()) || StringUtils.isBlank(userRepresentation.getPassword()) || StringUtils.isBlank(userRepresentation.getFirstName())) { throw new BadRequestException("Id, password and first name are required"); } if (userRepresentation.getEmail() != null && identityService.createUserQuery().userEmail(userRepresentation.getEmail()).count() > 0) { throw new ConflictingRequestException("User already registered", "ACCOUNT.SIGNUP.ERROR.ALREADY-REGISTERED"); } User user = identityService.newUser(userRepresentation.getId() != null ? userRepresentation.getId() : userRepresentation.getEmail()); user.setFirstName(userRepresentation.getFirstName()); user.setLastName(userRepresentation.getLastName()); user.setEmail(userRepresentation.getEmail()); user.setPassword(userRepresentation.getPassword()); identityService.saveUser(user); return user; }
Example 8
Source File: IdentityServiceTest.java From activiti-in-action-codes with Apache License 2.0 | 6 votes |
/** * 用户管理API演示 */ @Test public void testUser() throws Exception { // 创建一个用户 User user = identityService.newUser("henryyan"); user.setFirstName("Henry"); user.setLastName("Yan"); user.setEmail("[email protected]"); // 保存用户到数据库 identityService.saveUser(user); // 验证用户是否保存成功 User userInDb = identityService.createUserQuery().userId("henryyan").singleResult(); assertNotNull(userInDb); // 删除用户 identityService.deleteUser("henryyan"); // 验证是否删除成功 userInDb = identityService.createUserQuery().userId("henryyan").singleResult(); assertNull(userInDb); }
Example 9
Source File: IdmUsersResource.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@ResponseStatus(value = HttpStatus.OK) @RequestMapping(value = "/rest/admin/users/{userId}", method = RequestMethod.PUT) public void updateUserDetails(@PathVariable String userId, @RequestBody UpdateUsersRepresentation updateUsersRepresentation) { User user = identityService.createUserQuery().userId(userId).singleResult(); if (user != null) { user.setId(updateUsersRepresentation.getId()); user.setFirstName(updateUsersRepresentation.getFirstName()); user.setLastName(updateUsersRepresentation.getLastName()); user.setEmail(updateUsersRepresentation.getEmail()); identityService.saveUser(user); } }
Example 10
Source File: Bootstrapper.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
protected User initializeSuperUser() { String adminPassword = env.getRequiredProperty("admin.password"); String adminLastname = env.getRequiredProperty("admin.lastname"); String adminEmail = env.getRequiredProperty("admin.email"); User admin = identityService.newUser(adminEmail); admin.setLastName(adminLastname); admin.setEmail(adminEmail); admin.setPassword(adminPassword); identityService.saveUser(admin); return admin; }
Example 11
Source File: Application.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@Bean InitializingBean usersAndGroupsInitializer(final IdentityService identityService) { return new InitializingBean() { @Override public void afterPropertiesSet() throws Exception { // install groups & users Group group = identityService.newGroup("user"); group.setName("users"); group.setType("security-role"); identityService.saveGroup(group); User joram = identityService.newUser("jbarrez"); joram.setFirstName("Joram"); joram.setLastName("Barrez"); joram.setPassword("password"); identityService.saveUser(joram); User josh = identityService.newUser("jlong"); josh.setFirstName("Josh"); josh.setLastName("Long"); josh.setPassword("password"); identityService.saveUser(josh); identityService.createMembership("jbarrez", "user"); identityService.createMembership("jlong", "user"); } }; }
Example 12
Source File: UserInfoResourceTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public void testCreateUserInfo() 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 requestNode = objectMapper.createObjectNode(); requestNode.put("value", "Value 1"); requestNode.put("key", "key1"); HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO_COLLECTION, "testuser")); httpPost.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertEquals("key1", responseNode.get("key").textValue()); assertEquals("Value 1", responseNode.get("value").textValue()); assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO, newUser.getId(), "key1"))); } finally { // Delete user after test passes or fails if (savedUser != null) { identityService.deleteUser(savedUser.getId()); } } }
Example 13
Source File: SecurityAutoConfigurationTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
protected User user(String userName, String f, String l) { User u = identityService.newUser(userName); u.setFirstName(f); u.setLastName(l); u.setPassword("password"); identityService.saveUser(u); return u; }
Example 14
Source File: Application.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@Bean CommandLineRunner seedUsersAndGroups(final IdentityService identityService) { return new CommandLineRunner() { @Override public void run(String... strings) throws Exception { // install groups & users Group group = identityService.newGroup("user"); group.setName("users"); group.setType("security-role"); identityService.saveGroup(group); User joram = identityService.newUser("jbarrez"); joram.setFirstName("Joram"); joram.setLastName("Barrez"); joram.setPassword("password"); identityService.saveUser(joram); User josh = identityService.newUser("jlong"); josh.setFirstName("Josh"); josh.setLastName("Long"); josh.setPassword("password"); identityService.saveUser(josh); identityService.createMembership("jbarrez", "user"); identityService.createMembership("jlong", "user"); } }; }
Example 15
Source File: UserPictureResourceTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
/** * Test getting the picture for a user. */ public void testGetUserPicture() 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; // Create picture for user Picture thePicture = new Picture("this is the picture raw byte stream".getBytes(), "image/png"); identityService.setUserPicture(newUser.getId(), thePicture); CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_PICTURE, newUser.getId())), HttpStatus.SC_OK); assertEquals("this is the picture raw byte stream", IOUtils.toString(response.getEntity().getContent())); // Check if media-type is correct assertEquals("image/png", response.getEntity().getContentType().getValue()); closeResponse(response); } finally { // Delete user after test passes or fails if (savedUser != null) { identityService.deleteUser(savedUser.getId()); } } }
Example 16
Source File: UserQueryTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
private User createUser(String id, String firstName, String lastName, String email) { User user = identityService.newUser(id); user.setFirstName(firstName); user.setLastName(lastName); user.setEmail(email); identityService.saveUser(user); return user; }
Example 17
Source File: CandidateUserInUserTaskTest.java From activiti-in-action-codes with Apache License 2.0 | 5 votes |
/** * 学习一个用户任务有多个候选人 */ @Test @Deployment(resources = {"chapter5/candidateUserInUserTask.bpmn"}) public void testMultiCadiateUserInUserTask() throws Exception { // 添加用户jackchen User userJackChen = identityService.newUser("jackchen"); userJackChen.setFirstName("Jack"); userJackChen.setLastName("Chen"); userJackChen.setEmail("[email protected]"); identityService.saveUser(userJackChen); // 添加用户henryyan User userHenryyan = identityService.newUser("henryyan"); userHenryyan.setFirstName("Henry"); userHenryyan.setLastName("Yan"); userHenryyan.setEmail("[email protected]"); identityService.saveUser(userHenryyan); // 启动流程 ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("candidateUserInUserTask"); assertNotNull(processInstance); // jackchen作为候选人的任务 Task jackchenTask = taskService.createTaskQuery().taskCandidateUser("jackchen").singleResult(); assertNotNull(jackchenTask); // henryyan作为候选人的任务 Task henryyanTask = taskService.createTaskQuery().taskCandidateUser("henryyan").singleResult(); assertNotNull(henryyanTask); // jackchen签收任务 taskService.claim(jackchenTask.getId(), "jackchen"); // 再次查询用户henryyan是否拥有刚刚的候选任务 henryyanTask = taskService.createTaskQuery().taskCandidateUser("henryyan").singleResult(); assertNull(henryyanTask); }
Example 18
Source File: DemoDataGenerator.java From maven-framework-project with MIT License | 5 votes |
protected void createUser(String userId, String firstName, String lastName, String password, String email, String imageResource, List<String> groups, List<String> userInfo) { if (identityService.createUserQuery().userId(userId).count() == 0) { // Following data can already be set by demo setup script User user = identityService.newUser(userId); user.setFirstName(firstName); user.setLastName(lastName); user.setPassword(password); user.setEmail(email); identityService.saveUser(user); if (groups != null) { for (String group : groups) { identityService.createMembership(userId, group); } } } // Following data is not set by demo setup script // image if (imageResource != null) { byte[] pictureBytes = IoUtil.readInputStream(this.getClass().getClassLoader().getResourceAsStream(imageResource), null); Picture picture = new Picture(pictureBytes, "image/jpeg"); identityService.setUserPicture(userId, picture); } // user info if (userInfo != null) { for (int i = 0; i < userInfo.size(); i += 2) { identityService.setUserInfo(userId, userInfo.get(i), userInfo.get(i + 1)); } } }
Example 19
Source File: SpringIdentityServiceTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@Override public void notify(DelegateTask delegateTask) { User user = identityService.newUser("User1"); user.setFirstName("User1"); user.setLastName("Created"); user.setEmail("[email protected]"); user.setPassword("User1"); identityService.saveUser(user); }
Example 20
Source File: UserResourceTest.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
/** * Test updating a single user passing in no fields in the json, user should remain unchanged. */ public void testUpdateUserNullFields() 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(); taskUpdateRequest.putNull("firstName"); taskUpdateRequest.putNull("lastName"); taskUpdateRequest.putNull("email"); taskUpdateRequest.putNull("password"); 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()); assertTrue(responseNode.get("firstName").isNull()); assertTrue(responseNode.get("lastName").isNull()); assertTrue(responseNode.get("email").isNull()); 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(); assertNull(newUser.getLastName()); assertNull(newUser.getFirstName()); assertNull(newUser.getEmail()); } finally { // Delete user after test fails if (savedUser != null) { identityService.deleteUser(savedUser.getId()); } } }