public void setFavoriteAssociations(NodeRef person, QName associtation, String type) {
   logger.debug("InFavoriteAssociationSpider.setFavoriteAssociations");
   if (null
       != preferenceService.getPreference(
           (String) nodeService.getProperty(person, ContentModel.PROP_USERNAME), type)) {
     String favorite_documents =
         preferenceService
             .getPreference(
                 (String) nodeService.getProperty(person, ContentModel.PROP_USERNAME), type)
             .toString();
     if (!favorite_documents.isEmpty()) {
       List<NodeRef> favoriteRefs = new ArrayList<>();
       for (String favorite : favorite_documents.split(",")) {
         try {
           NodeRef favoriteRef = new NodeRef(favorite);
           nodeService.getProperties(favoriteRef);
           favoriteRefs.add(favoriteRef); // new NodeRef(favorite));
         } catch (InvalidNodeRefException e) {
           // Got bad node, skipping.
         }
       }
       nodeService.setAssociations(person, associtation, favoriteRefs);
     } else {
       nodeService.setAssociations(person, associtation, new ArrayList<NodeRef>());
     }
   }
 }
  private void setFlags(FileInfo messageFileInfo) throws Exception {
    imapService.setFlags(messageFileInfo, flags, true);
    NodeRef messageNodeRef = messageFileInfo.getNodeRef();
    Map<QName, Serializable> props = nodeService.getProperties(messageNodeRef);

    assertTrue("Can't set SEEN flag", props.containsKey(ImapModel.PROP_FLAG_SEEN));
    assertTrue("Can't set FLAGGED flag", props.containsKey(ImapModel.PROP_FLAG_FLAGGED));
    assertTrue("Can't set ANSWERED flag", props.containsKey(ImapModel.PROP_FLAG_ANSWERED));
    assertTrue("Can't set DELETED flag", props.containsKey(ImapModel.PROP_FLAG_DELETED));
  }
Exemplo n.º 3
0
  public DownloadRequest getDownloadRequest(NodeRef downloadNodeRef) {
    validateNode(downloadNodeRef);
    Map<QName, Serializable> properties = nodeService.getProperties(downloadNodeRef);

    List<AssociationRef> requestedNodes =
        nodeService.getTargetAssocs(downloadNodeRef, DownloadModel.ASSOC_REQUESTED_NODES);

    return new DownloadRequest(
        (Boolean) properties.get(DownloadModel.PROP_RECURSIVE),
        requestedNodes,
        (String) properties.get(ContentModel.PROP_CREATOR));
  }
  /** @return Returns true if the pattern is present, otherwise false. */
  public boolean contains(
      NodeRef nodeRef,
      QName propertyQName,
      String googleLikePattern,
      SearchParameters.Operator defaultOperator) {
    ResultSet resultSet = null;
    try {
      // build Lucene search string specific to the node
      StringBuilder sb = new StringBuilder();
      sb.append("+ID:\"")
          .append(nodeRef.toString())
          .append("\" +(TEXT:(")
          .append(googleLikePattern.toLowerCase())
          .append(") ");
      if (propertyQName != null) {
        sb.append(" OR @")
            .append(
                SearchLanguageConversion.escapeLuceneQuery(
                    QName.createQName(
                            propertyQName.getNamespaceURI(),
                            ISO9075.encode(propertyQName.getLocalName()))
                        .toString()));
        sb.append(":(").append(googleLikePattern.toLowerCase()).append(")");
      } else {
        for (QName key : nodeService.getProperties(nodeRef).keySet()) {
          sb.append(" OR @")
              .append(
                  SearchLanguageConversion.escapeLuceneQuery(
                      QName.createQName(key.getNamespaceURI(), ISO9075.encode(key.getLocalName()))
                          .toString()));
          sb.append(":(").append(googleLikePattern.toLowerCase()).append(")");
        }
      }
      sb.append(")");

      SearchParameters sp = new SearchParameters();
      sp.setLanguage(SearchService.LANGUAGE_LUCENE);
      sp.setQuery(sb.toString());
      sp.setDefaultOperator(defaultOperator);
      sp.addStore(nodeRef.getStoreRef());

      resultSet = this.query(sp);
      boolean answer = resultSet.length() > 0;
      return answer;
    } finally {
      if (resultSet != null) {
        resultSet.close();
      }
    }
  }
  private Map<QName, Serializable> getAndAssertProperties(NodeRef nodeRef, String versionLabel) {
    assertNotNull("NodeRef of document is NULL!", nodeRef);

    Map<QName, Serializable> properties = nodeService.getProperties(nodeRef);

    assertNotNull(
        ("Properties must not be NULL! NodeRef = '" + nodeRef.toString() + "'"), properties);
    assertFalse(
        ("Version specific properties can't be found! NodeRef = '" + nodeRef.toString() + "'"),
        properties.isEmpty());
    assertEquals(versionLabel, properties.get(ContentModel.PROP_VERSION_LABEL));

    return properties;
  }
Exemplo n.º 6
0
  public DownloadStatus getDownloadStatus(NodeRef downloadNodeRef) {
    validateNode(downloadNodeRef);
    Map<QName, Serializable> properties = nodeService.getProperties(downloadNodeRef);

    Long done = (Long) properties.get(DownloadModel.PROP_DONE);
    Long total = (Long) properties.get(DownloadModel.PROP_TOTAL);
    Long filesAdded = (Long) properties.get(DownloadModel.PROP_FILES_ADDED);
    Long totalFiles = (Long) properties.get(DownloadModel.PROP_TOTAL_FILES);

    return new DownloadStatus(
        DownloadStatus.Status.valueOf((String) properties.get(DownloadModel.PROP_STATUS)),
        done != null ? done.longValue() : 0l,
        total != null ? total.longValue() : 0l,
        filesAdded != null ? filesAdded.longValue() : 0l,
        totalFiles != null ? totalFiles.longValue() : 0l);
  }
Exemplo n.º 7
0
 public Node getNode(NodeRef nodeRef) {
   return new Node(nodeRef, nodeService.getProperties(nodeRef));
 }
Exemplo n.º 8
0
  public Node getNode(String nodeId) {
    NodeRef nodeRef = validateNode(nodeId);

    return new Node(nodeRef, nodeService.getProperties(nodeRef));
  }
  /**
   * @see
   *     org.alfresco.repo.version.operations.VersionOperationsService#checkin(org.alfresco.repo.ref.NodeRef,
   *     Map<String,Serializable>, java.lang.String, boolean)
   */
  public NodeRef checkin(
      NodeRef workingCopyNodeRef,
      Map<String, Serializable> versionProperties,
      String contentUrl,
      boolean keepCheckedOut) {
    NodeRef nodeRef = null;

    // Check that we have been handed a working copy
    if (this.nodeService.hasAspect(workingCopyNodeRef, ContentModel.ASPECT_WORKING_COPY) == false) {
      // Error since we have not been passed a working copy
      throw new AspectMissingException(ContentModel.ASPECT_WORKING_COPY, workingCopyNodeRef);
    }

    // Check that the working node still has the copy aspect applied
    if (this.nodeService.hasAspect(workingCopyNodeRef, ContentModel.ASPECT_COPIEDFROM) == true) {
      // Invoke policy
      invokeBeforeCheckIn(workingCopyNodeRef, versionProperties, contentUrl, keepCheckedOut);

      Map<QName, Serializable> workingCopyProperties =
          nodeService.getProperties(workingCopyNodeRef);
      // Try and get the original node reference
      nodeRef = (NodeRef) workingCopyProperties.get(ContentModel.PROP_COPY_REFERENCE);
      if (nodeRef == null) {
        // Error since the original node can not be found
        throw new CheckOutCheckInServiceException(MSG_ERR_BAD_COPY);
      }

      try {
        // Release the lock
        this.lockService.unlock(nodeRef);
      } catch (UnableToReleaseLockException exception) {
        throw new CheckOutCheckInServiceException(MSG_ERR_NOT_OWNER, exception);
      }

      if (contentUrl != null) {
        ContentData contentData =
            (ContentData) workingCopyProperties.get(ContentModel.PROP_CONTENT);
        if (contentData == null) {
          throw new AlfrescoRuntimeException(
              MSG_ERR_WORKINGCOPY_HAS_NO_MIMETYPE, new Object[] {workingCopyNodeRef});
        } else {
          contentData =
              new ContentData(
                  contentUrl,
                  contentData.getMimetype(),
                  contentData.getSize(),
                  contentData.getEncoding());
        }
        // Set the content url value onto the working copy
        this.nodeService.setProperty(workingCopyNodeRef, ContentModel.PROP_CONTENT, contentData);
      }

      // Copy the contents of the working copy onto the original
      this.copyService.copy(workingCopyNodeRef, nodeRef);

      // Handle name change on working copy (only for folders/files)
      if (fileFolderService.getFileInfo(workingCopyNodeRef) != null) {
        String origName = (String) this.nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
        String name =
            (String) this.nodeService.getProperty(workingCopyNodeRef, ContentModel.PROP_NAME);
        if (hasWorkingCopyNameChanged(name, origName)) {
          // ensure working copy has working copy label in its name to avoid name clash
          if (!name.contains(" " + getWorkingCopyLabel())) {
            try {
              fileFolderService.rename(workingCopyNodeRef, createWorkingCopyName(name));
            } catch (FileExistsException e) {
              throw new CheckOutCheckInServiceException(
                  e, MSG_ERR_CANNOT_RENAME, name, createWorkingCopyName(name));
            } catch (FileNotFoundException e) {
              throw new CheckOutCheckInServiceException(
                  e, MSG_ERR_CANNOT_RENAME, name, createWorkingCopyName(name));
            }
          }
          try {
            // rename original to changed working name
            fileFolderService.rename(nodeRef, getNameFromWorkingCopyName(name));
          } catch (FileExistsException e) {
            throw new CheckOutCheckInServiceException(
                e, MSG_ERR_CANNOT_RENAME, origName, getNameFromWorkingCopyName(name));
          } catch (FileNotFoundException e) {
            throw new CheckOutCheckInServiceException(
                e, MSG_ERR_CANNOT_RENAME, name, getNameFromWorkingCopyName(name));
          }
        }
      }

      if (versionProperties != null
          && this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE) == true) {
        // Create the new version
        this.versionService.createVersion(nodeRef, versionProperties);
      }

      if (keepCheckedOut == false) {
        // Delete the working copy
        this.nodeService.deleteNode(workingCopyNodeRef);
      } else {
        // Re-lock the original node
        this.lockService.lock(nodeRef, LockType.READ_ONLY_LOCK);
      }

      // Invoke policy
      invokeOnCheckIn(nodeRef);
    } else {
      // Error since the copy aspect is missing
      throw new AspectMissingException(ContentModel.ASPECT_COPIEDFROM, workingCopyNodeRef);
    }

    return nodeRef;
  }