예제 #1
0
파일: AuditTest.java 프로젝트: mindis/nuxeo
  @Test
  public void shouldFilterLogEntriesOnEventId() throws Exception {
    DocumentModel doc = RestServerInit.getFile(1, session);

    MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
    queryParams.putSingle("eventId", "documentModified");
    ClientResponse response =
        getResponse(
            BaseTest.RequestType.GET, "id/" + doc.getId() + "/@" + AuditAdapter.NAME, queryParams);

    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    JsonNode node = mapper.readTree(response.getEntityInputStream());
    List<JsonNode> nodes = getLogEntries(node);
    assertEquals(1, nodes.size());
    assertEquals("documentModified", nodes.get(0).get("eventId").getValueAsText());

    queryParams.putSingle("principalName", "bender");
    response =
        getResponse(
            BaseTest.RequestType.GET, "id/" + doc.getId() + "/@" + AuditAdapter.NAME, queryParams);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    node = mapper.readTree(response.getEntityInputStream());
    nodes = getLogEntries(node);
    assertEquals(0, nodes.size());
  }
예제 #2
0
  @Test
  @SuppressWarnings("unchecked")
  public void testGroupsPageProviderAllMode() {
    Map<String, Serializable> properties = new HashMap<String, Serializable>();
    properties.put(
        AbstractGroupsPageProvider.GROUPS_LISTING_MODE_PROPERTY,
        AbstractGroupsPageProvider.ALL_MODE);
    PageProvider<DocumentModel> groupsProvider =
        (PageProvider<DocumentModel>)
            ppService.getPageProvider(PROVIDER_NAME, null, null, null, properties, "");
    List<DocumentModel> groups = groupsProvider.getCurrentPage();
    assertNotNull(groups);
    assertEquals(5, groups.size());

    DocumentModel group = groups.get(0);
    assertEquals("administrators", group.getId());
    group = groups.get(1);
    assertEquals("group1", group.getId());
    group = groups.get(2);
    assertEquals("group2", group.getId());
    group = groups.get(3);
    assertEquals("members", group.getId());
    group = groups.get(4);
    assertEquals("powerusers", group.getId());
  }
예제 #3
0
  @Test
  @SuppressWarnings("unchecked")
  public void testGroupsPageProviderSearchMode() {
    Map<String, Serializable> properties = new HashMap<String, Serializable>();
    properties.put(
        AbstractGroupsPageProvider.GROUPS_LISTING_MODE_PROPERTY,
        AbstractGroupsPageProvider.SEARCH_ONLY_MODE);
    PageProvider<DocumentModel> groupsProvider =
        (PageProvider<DocumentModel>)
            ppService.getPageProvider(PROVIDER_NAME, null, null, null, properties, "gr");
    List<DocumentModel> groups = groupsProvider.getCurrentPage();
    assertNotNull(groups);
    assertEquals(2, groups.size());
    DocumentModel group = groups.get(0);
    assertEquals("group1", group.getId());
    group = groups.get(1);
    assertEquals("group2", group.getId());

    // check computed groups
    groupsProvider =
        (PageProvider<DocumentModel>)
            ppService.getPageProvider(PROVIDER_NAME, null, null, null, properties, "Grp");
    groups = groupsProvider.getCurrentPage();
    assertNotNull(groups);
    assertEquals(2, groups.size());
    group = groups.get(0);
    assertEquals("Grp1", group.getId());
    group = groups.get(1);
    assertEquals("Grp2", group.getId());
  }
  @Test
  public void testReadAclAfterSetACP() {
    DocumentModel folder = new DocumentModelImpl("/", "folder", "Folder");
    folder = session.createDocument(folder);
    DocumentModel doc = new DocumentModelImpl("/folder", "doc", "File");
    doc = session.createDocument(doc);
    session.save();

    // nothing can be seen by joe
    try (CoreSession joeSession = openSessionAs("joe")) {
      DocumentModelList list = joeSession.query("SELECT * FROM Folder");
      assertEquals(0, list.size());
      list = joeSession.query("SELECT * FROM File");
      assertEquals(0, list.size());
    }

    // set ACL on folder
    ACL acl = new ACLImpl();
    acl.add(new ACE("Everyone", "Read", true));
    ACP acp = new ACPImpl();
    acp.addACL(acl);
    folder.setACP(acp, true);
    session.save();

    // now joe sees things
    try (CoreSession joeSession = openSessionAs("joe")) {
      DocumentModelList list = joeSession.query("SELECT * FROM Folder");
      assertEquals(1, list.size());
      assertEquals(folder.getId(), list.get(0).getId());
      list = joeSession.query("SELECT * FROM File");
      assertEquals(1, list.size());
      assertEquals(doc.getId(), list.get(0).getId());
    }
  }
  @Override
  public DocumentModel getEntry(String id, boolean fetchReferences) throws DirectoryException {
    if (!isCurrentUserAllowed(SecurityConstants.READ)) {
      return null;
    }
    init();
    String entryId = id;
    source_loop:
    for (SourceInfo sourceInfo : sourceInfos) {
      boolean isReadOnlyEntry = true;
      final Map<String, Object> map = new HashMap<String, Object>();

      for (SubDirectoryInfo dirInfo : sourceInfo.subDirectoryInfos) {
        final DocumentModel entry = dirInfo.getSession().getEntry(id, fetchReferences);
        boolean isOptional = dirInfo.isOptional;
        if (entry == null && !isOptional) {
          // not in this source
          continue source_loop;
        }
        if (entry != null && !isReadOnlyEntry(entry)) {
          // set readonly to false if at least one source is writable
          isReadOnlyEntry = false;
        }
        if (entry == null && isOptional && !dirInfo.getSession().isReadOnly()) {
          // set readonly to false if null entry is from optional and writable directory
          isReadOnlyEntry = false;
        }
        if (entry != null && entry.getId() == null) {
          entryId = entry.getId();
        }
        for (Entry<String, String> e : dirInfo.toSource.entrySet()) {
          if (entry != null) {
            try {
              map.put(e.getValue(), entry.getProperty(dirInfo.dirSchemaName, e.getKey()));
            } catch (PropertyException e1) {
              throw new DirectoryException(e1);
            }
          } else {
            // fill with default values for this directory
            if (!map.containsKey(e.getValue())) {
              map.put(e.getValue(), dirInfo.defaultEntry.get(e.getKey()));
            }
          }
        }
      }
      // force the entry in readonly if it's defined on the multidirectory
      if (isReadOnly()) {
        isReadOnlyEntry = true;
      }
      // ok we have the data
      try {
        return BaseSession.createEntryModel(null, schemaName, entryId, map, isReadOnlyEntry);
      } catch (PropertyException e) {
        throw new DirectoryException(e);
      }
    }
    return null;
  }
예제 #6
0
 @Override
 public int compare(DocumentModel doc1, DocumentModel doc2) {
   String p1 = doc1.getPathAsString();
   String p2 = doc2.getPathAsString();
   if (p1 == null && p2 == null) {
     return sign * doc1.getId().compareTo(doc2.getId());
   } else if (p1 == null) {
     return sign;
   } else if (p2 == null) {
     return -1 * sign;
   }
   return sign * p1.compareTo(p2);
 }
  @Test
  public void testAddManyDocsToNewCollectionAndRemove() throws ClientException {
    DocumentModel testWorkspace =
        session.createDocumentModel("/default-domain/workspaces", "testWorkspace", "Workspace");
    testWorkspace = session.createDocument(testWorkspace);

    List<DocumentModel> files = createTestFiles(session, 3);

    collectionManager.addToNewCollection(COLLECTION_NAME, COLLECTION_DESCRIPTION, files, session);

    assertTrue(session.exists(new PathRef(COLLECTION_FOLDER_PATH)));

    final String newlyCreatedCollectionPath = COLLECTION_FOLDER_PATH + "/" + COLLECTION_NAME;

    DocumentRef newCollectionRef = new PathRef(newlyCreatedCollectionPath);
    assertTrue(session.exists(newCollectionRef));

    DocumentModel newlyCreatedCollection = session.getDocument(newCollectionRef);
    final String newlyCreatedCollectionId = newlyCreatedCollection.getId();

    assertEquals(COLLECTION_NAME, newlyCreatedCollection.getTitle());

    assertEquals(
        COLLECTION_DESCRIPTION, newlyCreatedCollection.getProperty("dc:description").getValue());

    for (DocumentModel file : files) {
      file = session.getDocument(file.getRef());

      Collection collectionAdapter = newlyCreatedCollection.getAdapter(Collection.class);

      assertTrue(collectionAdapter.getCollectedDocumentIds().contains(file.getId()));

      CollectionMember collectionMemberAdapter = file.getAdapter(CollectionMember.class);

      assertTrue(collectionMemberAdapter.getCollectionIds().contains(newlyCreatedCollectionId));
    }

    collectionManager.removeAllFromCollection(newlyCreatedCollection, files, session);

    for (DocumentModel file : files) {
      Collection collectionAdapter = newlyCreatedCollection.getAdapter(Collection.class);

      assertFalse(collectionAdapter.getCollectedDocumentIds().contains(file.getId()));

      CollectionMember collectionMemberAdapter = file.getAdapter(CollectionMember.class);

      assertFalse(collectionMemberAdapter.getCollectionIds().contains(newlyCreatedCollectionId));
    }
  }
 public static Suggestion fromDocumentModel(DocumentModel doc) {
   TypeInfo typeInfo = doc.getAdapter(TypeInfo.class);
   String description = doc.getProperty("dc:description").getValue(String.class);
   String icon = null;
   if (doc.hasSchema("common")) {
     icon = (String) doc.getProperty("common", "icon");
   }
   if (StringUtils.isEmpty(icon)) {
     icon = typeInfo.getIcon();
   }
   String thumbnailURL = String.format("api/v1/id/%s/@rendition/thumbnail", doc.getId());
   return new DocumentSuggestion(doc.getId(), new DocumentLocationImpl(doc), doc.getTitle(), icon)
       .withDescription(description)
       .withThumbnailURL(thumbnailURL);
 }
  @Test
  public void testReadAclAfterCreate() {
    DocumentModel folder = new DocumentModelImpl("/", "folder", "Folder");
    folder = session.createDocument(folder);
    session.save();

    // folder can be seen by a member
    UserPrincipal joeMember =
        new UserPrincipal("joe", Arrays.asList("Everyone", "members"), false, false);
    try (CoreSession joeSession = openSessionAs(joeMember)) {
      DocumentModelList list = joeSession.query("SELECT * FROM Folder");
      assertEquals(1, list.size());
      assertEquals(folder.getId(), list.get(0).getId());
    }

    // but not as a non-member
    try (CoreSession joeSession = openSessionAs("joe")) {
      DocumentModelList list = joeSession.query("SELECT * FROM Folder");
      assertEquals(0, list.size());
    }

    // set ACL on folder
    ACL acl = new ACLImpl();
    acl.add(new ACE("Everyone", "Read", true));
    ACP acp = new ACPImpl();
    acp.addACL(acl);
    folder.setACP(acp, true);
    session.save();

    // the folder can be seen by joe
    try (CoreSession joeSession = openSessionAs("joe")) {
      DocumentModelList list = joeSession.query("SELECT * FROM Folder");
      assertEquals(1, list.size());
      assertEquals(folder.getId(), list.get(0).getId());
    }

    // create a doc under the folder
    DocumentModel doc = new DocumentModelImpl("/folder", "doc", "File");
    doc = session.createDocument(doc);
    session.save();

    // the doc can be seen by joe
    try (CoreSession joeSession = openSessionAs("joe")) {
      DocumentModelList list = joeSession.query("SELECT * FROM File");
      assertEquals(1, list.size());
      assertEquals(doc.getId(), list.get(0).getId());
    }
  }
 @Override
 public void updateEntry(DocumentModel docModel) {
   if (!isCurrentUserAllowed(SecurityConstants.WRITE)) {
     return;
   }
   if (isReadOnly() || isReadOnlyEntry(docModel)) {
     return;
   }
   init();
   final String id = docModel.getId();
   Map<String, Object> fieldMap = docModel.getDataModel(schemaName).getMap();
   for (SourceInfo sourceInfo : sourceInfos) {
     // check if entry exists in this source, in case it can be created
     // in optional subdirectories
     boolean canCreateIfOptional = false;
     for (SubDirectoryInfo dirInfo : sourceInfo.requiredSubDirectoryInfos) {
       if (!canCreateIfOptional) {
         canCreateIfOptional = dirInfo.getSession().getEntry(id) != null;
       }
       updateSubDirectoryEntry(dirInfo, fieldMap, id, false);
     }
     for (SubDirectoryInfo dirInfo : sourceInfo.optionalSubDirectoryInfos) {
       updateSubDirectoryEntry(dirInfo, fieldMap, id, canCreateIfOptional);
     }
   }
 }
  /**
   * A&ntilde;ade un hijo al arbol.
   *
   * @param result XML resultado
   * @param parent Elemento padre del xml
   * @param root Documento ra&iacute;z.
   * @param depth profundidad
   * @return devuelve un elemento XML
   */
  private Element addChildren(DOMDocument result, Element parent, DocumentModel root, int depth) {
    try {

      List<DocumentModel> hijos = documentManager.getChildren(root.getRef());

      for (DocumentModel documento : hijos) {
        String estado = documento.getCurrentLifeCycleState();
        if (!"deleted".equals(estado) && documento.isFolder()) {
          Element hijo = result.createElement("document");

          hijo.setAttribute("title", documento.getTitle());
          hijo.setAttribute("type", documento.getType());
          hijo.setAttribute("id", documento.getId());

          parent.appendChild(hijo);

          if (depth > ArchivoConstantes.NUMERO_UNO) {
            addChildren(result, hijo, documento, depth - ArchivoConstantes.NUMERO_UNO);
          }
        }
      }
    } catch (ClientException e) {
      LOG.error("No se pudo a&ntilde;adir elementos al xml ", e);
    }
    return parent;
  }
예제 #12
0
  @Test
  public void testPublishing() {
    DocumentModel folder = session.createDocumentModel("/", "folder", "Folder");
    folder = session.createDocument(folder);
    DocumentModel doc = session.createDocumentModel("/", "file", "File");
    doc = session.createDocument(doc);
    checkVersions(doc);

    // publish
    DocumentModel proxy = session.publishDocument(doc, folder);
    session.save();
    String versionSeriesId = doc.getVersionSeriesId();
    assertFalse(proxy.isVersion());
    assertTrue(proxy.isProxy());
    assertTrue(proxy.hasFacet(FacetNames.IMMUTABLE));
    assertTrue(proxy.isImmutable());
    assertEquals(versionSeriesId, proxy.getVersionSeriesId());
    assertNotSame(versionSeriesId, proxy.getId());
    assertEquals("0.1", proxy.getVersionLabel());
    assertNull(proxy.getCheckinComment());
    assertFalse(proxy.isMajorVersion());
    assertTrue(proxy.isLatestVersion());
    assertFalse(proxy.isLatestMajorVersion());

    checkVersions(doc, "0.1");
    VersionModel lastVersion = session.getLastVersion(doc.getRef());
    assertNotNull(lastVersion);
    assertEquals("0.1", lastVersion.getLabel());
    DocumentModel lastVersionDocument = session.getLastDocumentVersion(doc.getRef());
    assertNotNull(lastVersionDocument);
    assertEquals("file", lastVersionDocument.getName());
  }
예제 #13
0
파일: AuditTest.java 프로젝트: mindis/nuxeo
  @Test
  public void shouldFilterLogEntriesOnEventCategories() throws Exception {
    DocumentModel doc = RestServerInit.getFile(1, session);

    List<LogEntry> logEntries = new ArrayList<>();
    LogEntry logEntry = auditLogger.newLogEntry();
    logEntry.setDocUUID(doc.getRef());
    logEntry.setCategory("One");
    logEntry.setEventId("firstEvent");
    logEntries.add(logEntry);
    logEntry = auditLogger.newLogEntry();
    logEntry.setDocUUID(doc.getRef());
    logEntry.setCategory("One");
    logEntry.setEventId("secondEvent");
    logEntries.add(logEntry);
    logEntry = auditLogger.newLogEntry();
    logEntry.setDocUUID(doc.getRef());
    logEntry.setCategory("Two");
    logEntry.setEventId("firstEvent");
    logEntries.add(logEntry);
    auditLogger.addLogEntries(logEntries);

    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();

    MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
    queryParams.add("category", "One");
    queryParams.add("category", "Two");
    ClientResponse response =
        getResponse(
            BaseTest.RequestType.GET, "id/" + doc.getId() + "/@" + AuditAdapter.NAME, queryParams);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    JsonNode node = mapper.readTree(response.getEntityInputStream());
    List<JsonNode> nodes = getLogEntries(node);
    assertEquals(3, nodes.size());

    queryParams = new MultivaluedMapImpl();
    queryParams.add("category", "Two");
    response =
        getResponse(
            BaseTest.RequestType.GET, "id/" + doc.getId() + "/@" + AuditAdapter.NAME, queryParams);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    node = mapper.readTree(response.getEntityInputStream());
    nodes = getLogEntries(node);
    assertEquals(1, nodes.size());
  }
 protected DocumentModel createRoute(String name, CoreSession session) throws PropertyException {
   DocumentModel route = session.createDocumentModel("/", name, DOCUMENT_ROUTE_DOCUMENT_TYPE);
   route.setPropertyValue(EXECUTION_TYPE_PROPERTY_NAME, graph.name());
   route.setPropertyValue("dc:title", name);
   route.setPropertyValue(
       ATTACHED_DOCUMENTS_PROPERTY_NAME, (Serializable) Collections.singletonList(doc.getId()));
   return session.createDocument(route);
 }
 @Override
 public List<Task> getTaskInstances(DocumentModel dm, NuxeoPrincipal user, CoreSession coreSession)
     throws ClientException {
   String query;
   if (user == null) {
     query = String.format(TaskQueryConstant.GET_TASKS_FOR_TARGET_DOCUMENT_QUERY, dm.getId());
   } else {
     List<String> actors = TaskActorsHelper.getTaskActors(user);
     String userNames = TaskQueryConstant.formatStringList(actors);
     query =
         String.format(
             TaskQueryConstant.GET_TASKS_FOR_TARGET_DOCUMENT_AND_ACTORS_QUERY,
             dm.getId(),
             userNames);
   }
   return queryTasksUnrestricted(query, coreSession);
 }
예제 #16
0
 public String getAction() {
   if (visible && documentModel != null) {
     String docId = documentModel.getId();
     String actionValue = String.format("#{navigationContext.navigateToId('%s')}", docId);
     return actionValue;
   }
   return null;
 }
 /** @deprecated this information is now held by content views */
 @Deprecated
 public void setLayoutForDocument(DocumentModel doc, String layoutName) {
   if (doc == null) {
     log.error("Cannot set listing layout for null document");
     return;
   }
   String id = doc.getId();
   docTolistings.put(id, layoutName);
 }
 // XXX AT: for BBB when repo name was not included in the resource uri
 @Deprecated
 private QNameResource getOldDocumentResource(DocumentModel document) {
   QNameResource documentResource = null;
   if (document != null) {
     documentResource =
         new QNameResourceImpl(RelationConstants.DOCUMENT_NAMESPACE, document.getId());
   }
   return documentResource;
 }
예제 #19
0
  /**
   * Check that a copied document does not belong to the collections of the original documents.
   *
   * @since 7.3
   */
  @Test
  public void testCopiedCollectionMember() {
    DocumentModel testWorkspace =
        session.createDocumentModel("/default-domain/workspaces", "testWorkspace", "Workspace");
    testWorkspace = session.createDocument(testWorkspace);
    DocumentModel testFile =
        session.createDocumentModel(testWorkspace.getPathAsString(), TEST_FILE_NAME, "File");
    testFile = session.createDocument(testFile);
    collectionManager.addToNewCollection(
        COLLECTION_NAME, COLLECTION_DESCRIPTION, testFile, session);
    testFile = session.getDocument(testFile.getRef());
    DocumentModel copiedTestFile =
        session.copy(testFile.getRef(), testFile.getParentRef(), TEST_FILE_NAME + "_BIS");

    assertFalse(collectionManager.isCollected(copiedTestFile));

    // Let's add to another collection and see it still does not belong to the original one.
    collectionManager.addToNewCollection(
        COLLECTION_NAME + "_BIS", COLLECTION_DESCRIPTION + "_BIS", copiedTestFile, session);

    copiedTestFile = session.getDocument(copiedTestFile.getRef());

    final String collectionPath = COLLECTION_FOLDER_PATH + "/" + COLLECTION_NAME;
    DocumentRef collectionPathRef = new PathRef(collectionPath);
    assertTrue(session.exists(collectionPathRef));
    final String collectionPathBis = COLLECTION_FOLDER_PATH + "/" + COLLECTION_NAME + "_BIS";
    DocumentRef collectionPathRefBis = new PathRef(collectionPathBis);
    assertTrue(session.exists(collectionPathRefBis));

    final DocumentModel collection = session.getDocument(collectionPathRef);
    final DocumentModel collectionBis = session.getDocument(collectionPathRefBis);

    assertFalse(
        copiedTestFile
            .getAdapter(CollectionMember.class)
            .getCollectionIds()
            .contains(collection.getId()));
    assertTrue(
        copiedTestFile
            .getAdapter(CollectionMember.class)
            .getCollectionIds()
            .contains(collectionBis.getId()));
  }
  @Test
  public void testAddOneDocToNewCollectionAndRemove() throws Exception {
    DocumentModel testWorkspace =
        session.createDocumentModel("/default-domain/workspaces", "testWorkspace", "Workspace");
    testWorkspace = session.createDocument(testWorkspace);
    DocumentModel testFile =
        session.createDocumentModel(testWorkspace.getPathAsString(), TEST_FILE_NAME, "File");
    testFile = session.createDocument(testFile);
    collectionManager.addToNewCollection(
        COLLECTION_NAME, COLLECTION_DESCRIPTION, testFile, session);

    assertTrue(session.exists(new PathRef(COLLECTION_FOLDER_PATH)));

    final String newlyCreatedCollectionPath = COLLECTION_FOLDER_PATH + "/" + COLLECTION_NAME;

    DocumentRef newCollectionRef = new PathRef(newlyCreatedCollectionPath);
    assertTrue(session.exists(newCollectionRef));

    DocumentModel newlyCreatedCollection = session.getDocument(newCollectionRef);
    final String newlyCreatedCollectionId = newlyCreatedCollection.getId();

    assertEquals(COLLECTION_NAME, newlyCreatedCollection.getTitle());

    assertEquals(
        COLLECTION_DESCRIPTION, newlyCreatedCollection.getProperty("dc:description").getValue());

    Collection collectionAdapter = newlyCreatedCollection.getAdapter(Collection.class);

    assertTrue(collectionAdapter.getCollectedDocumentIds().contains(testFile.getId()));

    testFile = session.getDocument(testFile.getRef());

    CollectionMember collectionMemberAdapter = testFile.getAdapter(CollectionMember.class);

    assertTrue(collectionMemberAdapter.getCollectionIds().contains(newlyCreatedCollectionId));

    collectionManager.removeFromCollection(newlyCreatedCollection, testFile, session);

    assertFalse(collectionAdapter.getCollectedDocumentIds().contains(testFile.getId()));
    assertFalse(collectionMemberAdapter.getCollectionIds().contains(newlyCreatedCollectionId));
  }
 @Override
 public Object getAdapter(DocumentModel doc, Class<?> itf) {
   try {
     return getService().getFileSystemItem(doc);
   } catch (ClientException e) {
     throw new ClientRuntimeException(
         String.format(
             "Error while trying to get adapter of class %s for doc %s.",
             itf.getName(), doc.getId()),
         e);
   }
 }
예제 #22
0
  @Test
  public void testGetLastVersion() {
    DocumentModel doc = session.createDocumentModel("/", "doc", "File");
    doc = session.createDocument(doc);
    session.save();
    DocumentRef v1ref = session.checkIn(doc.getRef(), VersioningOption.MAJOR, null);
    session.checkOut(doc.getRef());
    DocumentRef v2ref = session.checkIn(doc.getRef(), VersioningOption.MINOR, null);

    // last version on the doc
    DocumentModel last = session.getLastDocumentVersion(doc.getRef());
    assertEquals(v2ref.reference(), last.getId());
    DocumentRef lastRef = session.getLastDocumentVersionRef(doc.getRef());
    assertEquals(v2ref.reference(), lastRef.reference());

    // last version on any version
    last = session.getLastDocumentVersion(v2ref);
    assertEquals(v2ref.reference(), last.getId());
    lastRef = session.getLastDocumentVersionRef(v2ref);
    assertEquals(v2ref.reference(), lastRef.reference());
  }
 /** @deprecated this information is now held by content views */
 @Deprecated
 public String getLayoutForDocument(DocumentModel doc) {
   if (doc != null) {
     String id = doc.getId();
     if (docTolistings.containsKey(id)) {
       return docTolistings.get(id);
     }
     List<String> availableLayouts = getAvailableLayoutsForDocument(doc);
     if (availableLayouts != null && !availableLayouts.isEmpty()) {
       return availableLayouts.get(0);
     }
   }
   return DEFAULT_LISTING_LAYOUT;
 }
  private void createAndDeleteFile(String name) throws PropertyException {
    DocumentModel file = new DocumentModelImpl("/testfolder", name, "File");
    file.setPropertyValue("dc:title", "testfile Title");
    file = session.createDocument(file);
    session.save();
    nextTransaction();

    // at this point fulltext update is triggered async

    session.removeDocument(new IdRef(file.getId()));
    session.save();

    waitForAsyncCompletion();
  }
예제 #25
0
파일: AuditTest.java 프로젝트: mindis/nuxeo
  @Test
  public void shouldRetrieveAllLogEntries() throws Exception {
    DocumentModel doc = RestServerInit.getFile(1, session);

    ClientResponse response =
        getResponse(BaseTest.RequestType.GET, "id/" + doc.getId() + "/@" + AuditAdapter.NAME);

    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    JsonNode node = mapper.readTree(response.getEntityInputStream());
    List<JsonNode> nodes = getLogEntries(node);
    assertEquals(2, nodes.size());
    assertEquals("documentModified", nodes.get(0).get("eventId").getValueAsText());
    assertEquals("documentCreated", nodes.get(1).get("eventId").getValueAsText());
  }
 @Override
 public List<Task> getTaskInstances(DocumentModel dm, List<String> actors, CoreSession coreSession)
     throws ClientException {
   if (actors == null || actors.isEmpty()) {
     return new ArrayList<Task>();
   }
   String userNames = TaskQueryConstant.formatStringList(actors);
   String query =
       String.format(
           TaskQueryConstant.GET_TASKS_FOR_TARGET_DOCUMENT_AND_ACTORS_QUERY,
           dm.getId(),
           userNames);
   return queryTasksUnrestricted(query, coreSession);
 }
  protected void checkFileItem(
      FileItem fileItem,
      String fileItemIdPrefix,
      DocumentModel doc,
      String parentId,
      String parentPath,
      String name,
      String creator,
      String lastContributor) {

    String expectedFileItemId = fileItemIdPrefix + doc.getId();
    assertEquals(expectedFileItemId, fileItem.getId());
    assertEquals(parentId, fileItem.getParentId());
    assertEquals(parentPath + "/" + expectedFileItemId, fileItem.getPath());
    assertEquals(name, fileItem.getName());
    assertFalse(fileItem.isFolder());
    assertEquals(creator, fileItem.getCreator());
    assertEquals(lastContributor, fileItem.getLastContributor());
    assertEquals("nxfile/test/" + doc.getId() + "/blobholder:0/" + name, fileItem.getDownloadURL());
    assertEquals("MD5", fileItem.getDigestAlgorithm());
    assertEquals(
        ((org.nuxeo.ecm.core.api.Blob) doc.getPropertyValue("file:content")).getDigest(),
        fileItem.getDigest());
  }
예제 #28
0
 @Test
 public void testGetEntries() throws Exception {
   DocumentModelList l;
   l = dir.getEntries();
   assertEquals(4, l.size());
   DocumentModel entry = null;
   for (DocumentModel e : l) {
     if (e.getId().equals("1")) {
       entry = e;
       break;
     }
   }
   assertNotNull(entry);
   assertEquals("foo1", entry.getProperty("schema3", "thefoo"));
 }
  @OperationMethod
  public DocumentModelList run(DocumentModel context) throws Exception {

    DocumentModel favorites = favoritesManager.getFavorites(context, session);

    Map<String, Object> vars = ctx.getVars();
    vars.put("searchTerm", favorites.getId());
    vars.put("providerName", CollectionConstants.COLLECTION_CONTENT_PAGE_PROVIDER);

    OperationContext subctx = new OperationContext(ctx.getCoreSession(), vars);

    OperationChain chain = new OperationChain("operation");
    OperationParameters oparams = new OperationParameters(DocumentPageProviderOperation.ID, vars);
    chain.add(oparams);
    return (PaginableDocumentModelListImpl) service.run(subctx, chain);
  }
예제 #30
0
 protected String buildChildrenWhereClause(boolean queryDocuments) {
   String clause =
       String.format(
           "ecm:parentId = '%s' AND ecm:currentLifeCycleState != '%s'",
           folder.getId(), LifeCycleConstants.DELETED_STATE);
   if (queryDocuments) {
     clause +=
         String.format(
             " AND ecm:mixinType NOT IN ('%s', '%s')",
             FacetNames.PUBLISH_SPACE, FacetNames.HIDDEN_IN_NAVIGATION);
   } else {
     clause +=
         String.format(
             "AND ecm:mixinType IN ('%s') AND ecm:mixinType NOT IN ('%s')",
             FacetNames.PUBLISH_SPACE, FacetNames.HIDDEN_IN_NAVIGATION);
   }
   return clause;
 }