Search in sources :

Example 1 with JoinedProjectMessage

use of de.catma.ui.events.JoinedProjectMessage in project catma by forTEXT.

the class ProjectInvitationHandler method uiOnMessage.

@Override
public void uiOnMessage(Message<InvitationRequestMessage> message) {
    if (message.getMessageObject().getCode() == projectInvitation.getKey()) {
        try {
            Integer userId = Integer.valueOf(message.getMessageObject().getUserId());
            if (!assignedUsers.contains(userId)) {
                assignedUsers.add(userId);
                project.assignOnProject(() -> userId, RBACRole.forValue(projectInvitation.getDefaultRole()));
                if (projectInvitation.isCreateOwnCollection()) {
                    String color = userId2Color.get(userId);
                    if (color == null && !colors.isEmpty()) {
                        color = colors.iterator().next();
                        colors.remove(color);
                        userId2Color.put(userId, color);
                    }
                    for (String documentId : projectInvitation.getDocumentIds()) {
                        if (projectInvitation.getDefaultRole() < RBACRole.REPORTER.getAccessLevel()) {
                            // minimum role
                            project.assignOnResource(() -> userId, RBACRole.REPORTER, documentId);
                        }
                        DocumentResource docResource = (DocumentResource) documentResourceByUuid.get(documentId);
                        if (docResource != null) {
                            String collectionName = color + " " + message.getMessageObject().getName() + " " + docResource.getName();
                            // collection creation with minimum role assignment
                            project.createUserMarkupCollectionWithAssignment(collectionName, docResource.getDocument(), projectInvitation.getDefaultRole() < RBACRole.ASSISTANT.getAccessLevel() ? userId : null, RBACRole.ASSISTANT);
                        }
                    }
                }
                joinedTopic.publish(new JoinedProjectMessage(projectInvitation));
                joinedUsers.add(message.getMessageObject().getName());
                joinedUsersConsole.getDataProvider().refreshAll();
                joinedUsersConsole.setVisible(true);
                this.getUi().push();
            }
        } catch (IOException e) {
            ((ErrorHandler) getUi()).showAndLogError("Can't assign User " + message.getMessageObject().getName() + " to this Project", e);
        }
    }
}
Also used : IOException(java.io.IOException) JoinedProjectMessage(de.catma.ui.events.JoinedProjectMessage)

Aggregations

JoinedProjectMessage (de.catma.ui.events.JoinedProjectMessage)1 IOException (java.io.IOException)1