Search in sources :

Example 11 with User

use of org.activiti.engine.identity.User in project Activiti by Activiti.

the class TaskEventTextResolver method resolveText.

public Label resolveText(Event event) {
    IdentityService identityService = ProcessEngines.getDefaultProcessEngine().getIdentityService();
    User user = identityService.createUserQuery().userId(event.getUserId()).singleResult();
    String eventAuthor = "<span class='" + ExplorerLayout.STYLE_TASK_EVENT_AUTHOR + "'>" + user.getFirstName() + " " + user.getLastName() + "</span> ";
    String text = null;
    if (Event.ACTION_ADD_USER_LINK.equals(event.getAction())) {
        User involvedUser = identityService.createUserQuery().userId(event.getMessageParts().get(0)).singleResult();
        text = i18nManager.getMessage(Messages.EVENT_ADD_USER_LINK, eventAuthor, involvedUser.getFirstName() + " " + involvedUser.getLastName(), // second msg part = role
        event.getMessageParts().get(1));
    } else if (Event.ACTION_DELETE_USER_LINK.equals(event.getAction())) {
        User involvedUser = identityService.createUserQuery().userId(event.getMessageParts().get(0)).singleResult();
        text = i18nManager.getMessage(Messages.EVENT_DELETE_USER_LINK, eventAuthor, involvedUser.getFirstName() + " " + involvedUser.getLastName(), event.getMessageParts().get(1));
    } else if (Event.ACTION_ADD_GROUP_LINK.equals(event.getAction())) {
        text = i18nManager.getMessage(Messages.EVENT_ADD_GROUP_LINK, eventAuthor, event.getMessageParts().get(0), // second msg part = role
        event.getMessageParts().get(1));
    } else if (Event.ACTION_DELETE_GROUP_LINK.equals(event.getAction())) {
        text = i18nManager.getMessage(Messages.EVENT_DELETE_GROUP_LINK, eventAuthor, event.getMessageParts().get(0), // second msg part = role
        event.getMessageParts().get(1));
    } else if (Event.ACTION_ADD_ATTACHMENT.equals(event.getAction())) {
        text = i18nManager.getMessage(Messages.EVENT_ADD_ATTACHMENT, eventAuthor, event.getMessage());
    } else if (Event.ACTION_DELETE_ATTACHMENT.equals(event.getAction())) {
        text = i18nManager.getMessage(Messages.EVENT_DELETE_ATTACHMENT, eventAuthor, event.getMessage());
    } else if (Event.ACTION_ADD_COMMENT.equals(event.getAction())) {
        text = i18nManager.getMessage(Messages.EVENT_COMMENT, eventAuthor, event.getMessage());
    } else {
        // default: just show the message
        text += i18nManager.getMessage(Messages.EVENT_DEFAULT, eventAuthor, event.getMessage());
    }
    return new Label(text, Label.CONTENT_XHTML);
}
Also used : IdentityService(org.activiti.engine.IdentityService) User(org.activiti.engine.identity.User) Label(com.vaadin.ui.Label)

Example 12 with User

use of org.activiti.engine.identity.User in project Activiti by Activiti.

the class TaskTable method addTaskRow.

protected Object addTaskRow(Object previousTaskItemId, String taskName, String taskAssignee, String taskGroups, String taskDescription, Boolean startWithPrevious) {
    Object newItemId = null;
    if (previousTaskItemId == null) {
        // add at the end of list
        newItemId = addItem();
    } else {
        newItemId = addItemAfter(previousTaskItemId);
    }
    Item newItem = getItem(newItemId);
    // name
    newItem.getItemProperty(ID_NAME).setValue(taskName == null ? "my task" : taskName);
    // assignee
    ComboBox assigneeComboBox = new ComboBox();
    assigneeComboBox.setNullSelectionAllowed(true);
    try {
        for (User user : ProcessEngines.getDefaultProcessEngine().getIdentityService().createUserQuery().orderByUserFirstName().asc().list()) {
            assigneeComboBox.addItem(user.getId());
            assigneeComboBox.setItemCaption(user.getId(), user.getFirstName() + " " + user.getLastName());
        }
    } catch (Exception e) {
    // Don't do anything. Will be an empty dropdown.
    }
    if (taskAssignee != null) {
        assigneeComboBox.select(taskAssignee);
    }
    newItem.getItemProperty(ID_ASSIGNEE).setValue(assigneeComboBox);
    // groups
    ComboBox groupComboBox = new ComboBox();
    groupComboBox.setNullSelectionAllowed(true);
    try {
        for (Group group : ProcessEngines.getDefaultProcessEngine().getIdentityService().createGroupQuery().orderByGroupName().asc().list()) {
            groupComboBox.addItem(group.getId());
            groupComboBox.setItemCaption(group.getId(), group.getName());
        }
    } catch (Exception e) {
    // Don't do anything. Will be an empty dropdown.
    }
    if (taskGroups != null) {
        groupComboBox.select(taskGroups);
    }
    newItem.getItemProperty(ID_GROUPS).setValue(groupComboBox);
    // description
    TextField descriptionTextField = new TextField();
    descriptionTextField.setColumns(16);
    descriptionTextField.setRows(1);
    if (taskDescription != null) {
        descriptionTextField.setValue(taskDescription);
    }
    newItem.getItemProperty(ID_DESCRIPTION).setValue(descriptionTextField);
    // concurrency
    CheckBox startWithPreviousCheckBox = new CheckBox(i18nManager.getMessage(Messages.PROCESS_EDITOR_TASK_START_WITH_PREVIOUS));
    startWithPreviousCheckBox.setValue(startWithPrevious == null ? false : startWithPrevious);
    newItem.getItemProperty(ID_START_WITH_PREVIOUS).setValue(startWithPreviousCheckBox);
    // actions
    newItem.getItemProperty(ID_ACTIONS).setValue(generateActionButtons(newItemId));
    return newItemId;
}
Also used : Item(com.vaadin.data.Item) Group(org.activiti.engine.identity.Group) User(org.activiti.engine.identity.User) ComboBox(com.vaadin.ui.ComboBox) CheckBox(com.vaadin.ui.CheckBox) TextField(com.vaadin.ui.TextField)

Example 13 with User

use of org.activiti.engine.identity.User in project Activiti by Activiti.

the class DemoDataConfiguration method createUser.

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);
            }
        }
    }
    // 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));
        }
    }
}
Also used : User(org.activiti.engine.identity.User) Picture(org.activiti.engine.identity.Picture)

Example 14 with User

use of org.activiti.engine.identity.User in project Activiti by Activiti.

the class StartAuthorizationTest method testProcessDefinitionList.

// this test checks the list without user constraint
@Deployment
public void testProcessDefinitionList() throws Exception {
    setUpUsersAndGroups();
    try {
        // Process 1 has no potential starters
        ProcessDefinition latestProcessDef = repositoryService.createProcessDefinitionQuery().processDefinitionKey("process1").singleResult();
        List<User> authorizedUsers = identityService.createUserQuery().potentialStarter(latestProcessDef.getId()).list();
        assertEquals(0, authorizedUsers.size());
        // user1 and user2 are potential Startes of Process2
        latestProcessDef = repositoryService.createProcessDefinitionQuery().processDefinitionKey("process2").singleResult();
        authorizedUsers = identityService.createUserQuery().potentialStarter(latestProcessDef.getId()).orderByUserId().asc().list();
        assertEquals(2, authorizedUsers.size());
        assertEquals("user1", authorizedUsers.get(0).getId());
        assertEquals("user2", authorizedUsers.get(1).getId());
        // Process 2 has no potential starter groups
        latestProcessDef = repositoryService.createProcessDefinitionQuery().processDefinitionKey("process2").singleResult();
        List<Group> authorizedGroups = identityService.createGroupQuery().potentialStarter(latestProcessDef.getId()).list();
        assertEquals(0, authorizedGroups.size());
        // Process 3 has 3 groups as authorized starter groups
        latestProcessDef = repositoryService.createProcessDefinitionQuery().processDefinitionKey("process4").singleResult();
        authorizedGroups = identityService.createGroupQuery().potentialStarter(latestProcessDef.getId()).orderByGroupId().asc().list();
        assertEquals(3, authorizedGroups.size());
        assertEquals("group1", authorizedGroups.get(0).getId());
        assertEquals("group2", authorizedGroups.get(1).getId());
        assertEquals("group3", authorizedGroups.get(2).getId());
        // do not mention user, all processes should be selected
        List<ProcessDefinition> processDefinitions = repositoryService.createProcessDefinitionQuery().orderByProcessDefinitionName().asc().list();
        assertEquals(4, processDefinitions.size());
        assertEquals("process1", processDefinitions.get(0).getKey());
        assertEquals("process2", processDefinitions.get(1).getKey());
        assertEquals("process3", processDefinitions.get(2).getKey());
        assertEquals("process4", processDefinitions.get(3).getKey());
        // check user1, process3 has "user1" as only authorized starter, and
        // process2 has two authorized starters, of which one is "user1"
        processDefinitions = repositoryService.createProcessDefinitionQuery().orderByProcessDefinitionName().asc().startableByUser("user1").list();
        assertEquals(2, processDefinitions.size());
        assertEquals("process2", processDefinitions.get(0).getKey());
        assertEquals("process3", processDefinitions.get(1).getKey());
        // "user2" can only start process2
        processDefinitions = repositoryService.createProcessDefinitionQuery().startableByUser("user2").list();
        assertEquals(1, processDefinitions.size());
        assertEquals("process2", processDefinitions.get(0).getKey());
        // no process could be started with "user4"
        processDefinitions = repositoryService.createProcessDefinitionQuery().startableByUser("user4").list();
        assertEquals(0, processDefinitions.size());
        // "userInGroup3" is in "group3" and can start only process4 via group authorization
        processDefinitions = repositoryService.createProcessDefinitionQuery().startableByUser("userInGroup3").list();
        assertEquals(1, processDefinitions.size());
        assertEquals("process4", processDefinitions.get(0).getKey());
        // "userInGroup2" can start process4, via both user and group authorizations
        // but we have to be sure that process4 appears only once
        processDefinitions = repositoryService.createProcessDefinitionQuery().startableByUser("userInGroup2").list();
        assertEquals(1, processDefinitions.size());
        assertEquals("process4", processDefinitions.get(0).getKey());
    } finally {
        tearDownUsersAndGroups();
    }
}
Also used : Group(org.activiti.engine.identity.Group) User(org.activiti.engine.identity.User) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) Deployment(org.activiti.engine.test.Deployment)

Example 15 with User

use of org.activiti.engine.identity.User in project Activiti by Activiti.

the class TaskCandidateTest method setUp.

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");
}
Also used : Group(org.activiti.engine.identity.Group) User(org.activiti.engine.identity.User)

Aggregations

User (org.activiti.engine.identity.User)94 Group (org.activiti.engine.identity.Group)22 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)12 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)10 Task (org.activiti.engine.task.Task)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)9 Picture (org.activiti.engine.identity.Picture)9 StringEntity (org.apache.http.entity.StringEntity)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 ArrayList (java.util.ArrayList)7 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)7 HttpPut (org.apache.http.client.methods.HttpPut)7 HttpGet (org.apache.http.client.methods.HttpGet)6 UserQuery (org.activiti.engine.identity.UserQuery)5 HttpDelete (org.apache.http.client.methods.HttpDelete)5 HttpPost (org.apache.http.client.methods.HttpPost)4 Item (com.vaadin.data.Item)3 ActivitiException (org.activiti.engine.ActivitiException)3 IdentityService (org.activiti.engine.IdentityService)3