예제 #1
0
 protected void getAllTasks() {
   error = null;
   errorMessage = null;
   userTasks = new ArrayList<>();
   CoreSession coreSession = getCoreSession();
   boolean filterTrashDocs = getFilterDocumentsInTrash();
   NuxeoPrincipal pal = (NuxeoPrincipal) coreSession.getPrincipal();
   TaskService taskService = Framework.getService(TaskService.class);
   List<Task> tasks = taskService.getAllCurrentTaskInstances(coreSession, getSortInfos());
   if (tasks != null) {
     for (Task task : tasks) {
       List<String> targetDocumentsIds = task.getTargetDocumentsIds();
       boolean hasTargetDocuments = targetDocumentsIds != null && !targetDocumentsIds.isEmpty();
       if (task.hasEnded() || task.isCancelled() || !hasTargetDocuments) {
         continue;
       }
       DocumentModel doc = taskService.getTargetDocumentModel(task, coreSession);
       if (doc != null) {
         if (filterTrashDocs
             && LifeCycleConstants.DELETED_STATE.equals(doc.getCurrentLifeCycleState())) {
           continue;
         } else {
           userTasks.add(new DashBoardItemImpl(task, doc, getLocale()));
         }
       } else {
         log.warn(
             String.format(
                 "User '%s' has a task of type '%s' on a missing or deleted document",
                 pal.getName(), task.getName()));
       }
     }
   }
 }
  @Override
  public String endTask(
      CoreSession coreSession,
      NuxeoPrincipal principal,
      Task task,
      String comment,
      String eventName,
      boolean isValidated)
      throws ClientException {

    // put user comment on the task
    if (!StringUtils.isEmpty(comment)) {
      task.addComment(principal.getName(), comment);
    }

    // end the task, adding boolean marker that task was validated or
    // rejected
    task.setVariable(TaskService.VariableName.validated.name(), String.valueOf(isValidated));
    task.end(coreSession);
    coreSession.saveDocument(task.getDocument());
    // notify
    Map<String, Serializable> eventProperties = new HashMap<String, Serializable>();
    ArrayList<String> notificationRecipients = new ArrayList<String>();
    notificationRecipients.add(task.getInitiator());
    notificationRecipients.addAll(task.getActors());
    eventProperties.put(NotificationConstants.RECIPIENTS_KEY, notificationRecipients);
    // try to resolve document when notifying
    DocumentModel document = null;
    String docId = task.getVariable(TaskService.VariableName.documentId.name());
    String docRepo = task.getVariable(TaskService.VariableName.documentRepositoryName.name());
    if (coreSession.getRepositoryName().equals(docRepo)) {
      try {
        document = coreSession.getDocument(new IdRef(docId));
      } catch (Exception e) {
        log.error(
            String.format(
                "Could not fetch document with id '%s:%s' for notification", docRepo, docId),
            e);
      }
    } else {
      log.error(
          String.format(
              "Could not resolve document for notification: "
                  + "document is on repository '%s' and given session is on "
                  + "repository '%s'",
              docRepo, coreSession.getRepositoryName()));
    }

    TaskEventNotificationHelper.notifyEvent(
        coreSession, document, principal, task, eventName, eventProperties, comment, null);

    String seamEventName =
        isValidated
            ? TaskEventNames.WORKFLOW_TASK_COMPLETED
            : TaskEventNames.WORKFLOW_TASK_REJECTED;
    return seamEventName;
  }
 @Override
 public String findOrCreateNuxeoUser(OpenIDUserInfo userInfo) {
   NuxeoPrincipal principal =
       Framework.getService(UserMapper.class).getOrCreateAndUpdateNuxeoPrincipal(userInfo);
   if (principal != null) {
     return principal.getName();
   } else {
     return null;
   }
 }
  @Override
  public void handle(Request req, Response res) {
    UserManager userMgr = null;
    String user = null;
    try {

      userMgr = Framework.getService(UserManager.class);
      if (userMgr == null) {
        handleError(res, "User Manager can't be loaded");
        return;
      }

      user = (String) req.getAttributes().get("username");
      if (user == null) {
        handleError(res, "you must specify an user to search");
        return;
      }
    } catch (ClientException e) {
      handleError(res, e);
      return;
    } catch (Exception e) {
      handleError(res, "User Manager can't be loaded");
      return;
    }

    try {
      DocumentModel userModel = null;
      if (user != null && !user.isEmpty()) {
        userModel = userMgr.getUserModel(user);
      }

      // build the XML response document holding the ref
      DOMDocumentFactory domfactory = new DOMDocumentFactory();
      DOMDocument resultDocument = (DOMDocument) domfactory.createDocument();

      if (userModel == null) {
        handleError(res, "User is not found");
        return;
      }

      NuxeoPrincipal principal =
          userMgr.getPrincipal((String) userModel.getProperty("user", "username"));
      Element userElement = resultDocument.addElement("user");
      userElement.addAttribute("username", principal.getName());
      userElement.addAttribute("firstName", principal.getFirstName());
      userElement.addAttribute("lastName", principal.getLastName());
      userElement.addAttribute("email", (String) userModel.getProperty("user", "email"));
      userElement.addAttribute("company", principal.getCompany());

      List<String> groups = principal.getAllGroups();
      if (groups != null && groups.size() > 0) {
        for (String groupName : groups) {
          Element groupElement = userElement.addElement("group");
          groupElement.addAttribute("name", groupName);
        }
      }

      Representation rep =
          new StringRepresentation(resultDocument.asXML(), MediaType.APPLICATION_XML);
      rep.setCharacterSet(CharacterSet.UTF_8);
      res.setEntity(rep);
    } catch (ClientException e) {
      handleError(res, e);
    }
  }
예제 #5
0
파일: UserObject.java 프로젝트: ramey/nuxeo
 @Override
 protected NuxeoPrincipal updateArtifact(NuxeoPrincipal principal) {
   um.updateUser(principal.getModel());
   return um.getPrincipal(principal.getName());
 }
예제 #6
0
 protected static String newSessionId(String repositoryName, NuxeoPrincipal principal) {
   return repositoryName + '/' + principal.getName() + '#' + SID_COUNTER.incrementAndGet();
 }