Search in sources :

Example 31 with Reference

use of org.alfresco.repo.virtual.ref.Reference in project alfresco-repository by Alfresco.

the class VirtualRatingServiceExtensionTest method testApplyRatings.

@Test
public void testApplyRatings() throws Exception {
    Reference reference = Reference.fromNodeRef(virtualContent);
    assertNotNull(reference);
    NodeRef actualNodeRef = reference.execute(new GetActualNodeRefMethod(environment));
    applyRatingAs(virtualContent, 1f, LIKES_RATING_SCHEME, user1);
    applyRatingAs(virtualContent, 1f, LIKES_RATING_SCHEME, user2);
    double delta = 0.0000001;
    assertEquals(1f, ratingService.getAverageRating(virtualContent, LIKES_RATING_SCHEME), delta);
    assertEquals(1f, ratingService.getAverageRating(actualNodeRef, LIKES_RATING_SCHEME), delta);
    applyRatingAs(virtualContent, 1f, FIVE_STAR_RATING_SCHEME, user1);
    applyRatingAs(virtualContent, 3f, FIVE_STAR_RATING_SCHEME, user2);
    assertEquals(2f, ratingService.getAverageRating(virtualContent, FIVE_STAR_RATING_SCHEME), delta);
    assertEquals(2f, ratingService.getAverageRating(actualNodeRef, FIVE_STAR_RATING_SCHEME), delta);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Reference(org.alfresco.repo.virtual.ref.Reference) GetActualNodeRefMethod(org.alfresco.repo.virtual.ref.GetActualNodeRefMethod) VirtualizationIntegrationTest(org.alfresco.repo.virtual.VirtualizationIntegrationTest) Test(org.junit.Test)

Example 32 with Reference

use of org.alfresco.repo.virtual.ref.Reference in project alfresco-repository by Alfresco.

the class VirtualNodeServiceExtensionTest method testGetChildByName.

@Test
public void testGetChildByName() {
    NodeRef virtualFolder = createVirtualizedFolder(testRootFolder.getNodeRef(), VIRTUAL_FOLDER_2_NAME, TEST_TEMPLATE_4_JSON_SYS_PATH);
    assertTrue(smartStore.canVirtualize(virtualFolder));
    Reference semiVirtualFolder = smartStore.virtualize(virtualFolder);
    assertNotNull(semiVirtualFolder);
    // access virtual entry
    NodeRef virtualChild = nodeService.getChildByName(semiVirtualFolder.toNodeRef(), ContentModel.ASSOC_CONTAINS, "All My Content");
    assertNotNull(virtualChild);
    assertVirtualNode(virtualChild);
    // access physical child on first level
    NodeRef phys1 = nodeService.getChildByName(virtualChild, ContentModel.ASSOC_CONTAINS, "Company Home");
    assertNotNull(phys1);
    assertVirtualNode(virtualChild);
    // access physical child on second level
    NodeRef phys2 = nodeService.getChildByName(phys1, ContentModel.ASSOC_CONTAINS, "Data Dictionary");
    assertNotNull(phys2);
    assertVirtualNode(virtualChild);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Reference(org.alfresco.repo.virtual.ref.Reference) Test(org.junit.Test) VirtualizationIntegrationTest(org.alfresco.repo.virtual.VirtualizationIntegrationTest)

Example 33 with Reference

use of org.alfresco.repo.virtual.ref.Reference in project alfresco-repository by Alfresco.

the class VirtualNodeServiceExtensionTest method assertNewVirtualChildAssocRef.

/**
 * Assets that the given {@link ChildAssociationRef} was created within the
 * given virtualizable nodeRef container reference.
 *
 * @param nodeRef
 * @param childAssocsRef
 */
private void assertNewVirtualChildAssocRef(NodeRef nodeRef, ChildAssociationRef childAssocsRef) {
    Reference reference = Reference.fromNodeRef(nodeRef);
    assertNotNull(reference);
    assertNewVirtualChildAssocRef(reference, childAssocsRef);
}
Also used : Reference(org.alfresco.repo.virtual.ref.Reference)

Example 34 with Reference

use of org.alfresco.repo.virtual.ref.Reference in project alfresco-repository by Alfresco.

the class SystemVirtualizationMethodTest method testTemplateFromRepository.

@Test
public void testTemplateFromRepository() throws Exception {
    InputStream openContentStream = environment.openContentStream(TEST_TEMPLATE_1_JSON_CLASSPATH);
    NodeRef repositoryTemplate = fileAndFolderService.create(testRootFolder.getNodeRef(), "test1.json", VirtualContentModel.TYPE_VIRTUAL_FOLDER_TEMPLATE).getNodeRef();
    ContentWriter writer = contentService.getWriter(repositoryTemplate, ContentModel.PROP_CONTENT, true);
    writer.setMimetype("application/json");
    writer.putContent(openContentStream);
    NodeRef vf = createVirtualizedFolder(testRootFolder.getNodeRef(), "repositoryVirtualizedFolder", "N" + repositoryTemplate.toString());
    assertTrue(systemVirtualizationMethod.canVirtualize(environment, vf));
    Reference ref = systemVirtualizationMethod.virtualize(environment, vf);
    assertNotNull(ref);
    assertNotNull(nodeService.getChildByName(ref.toNodeRef(), ContentModel.ASSOC_CONTAINS, "Node1"));
    assertNotNull(nodeService.getChildByName(ref.toNodeRef(), ContentModel.ASSOC_CONTAINS, "Node2"));
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) InputStream(java.io.InputStream) Reference(org.alfresco.repo.virtual.ref.Reference) Test(org.junit.Test) VirtualizationIntegrationTest(org.alfresco.repo.virtual.VirtualizationIntegrationTest)

Example 35 with Reference

use of org.alfresco.repo.virtual.ref.Reference in project alfresco-repository by Alfresco.

the class VirtualQueryImpl method asPagingResults.

private PagingResults<Reference> asPagingResults(ActualEnvironment environment, PagingRequest pagingRequest, ResultSet result, Reference parentReference) throws ActualEnvironmentException {
    final List<Reference> page = new LinkedList<Reference>();
    for (ResultSetRow row : result) {
        page.add(NodeProtocol.newReference(row.getNodeRef(), parentReference));
    }
    final boolean hasMore = result.hasMore();
    final int totalFirst = (int) result.getNumberFound();
    int start;
    try {
        start = result.getStart();
    } catch (UnsupportedOperationException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Unsupported ResultSet.getStart() when trying to create query paging result");
        }
        if (pagingRequest != null) {
            start = pagingRequest.getSkipCount();
        } else {
            start = 0;
        }
    }
    final int totlaSecond = !hasMore ? (int) result.getNumberFound() : (int) (start + result.getNumberFound() + 1);
    final Pair<Integer, Integer> total = new Pair<Integer, Integer>(totalFirst, totlaSecond);
    return new PagingResults<Reference>() {

        @Override
        public List<Reference> getPage() {
            return page;
        }

        @Override
        public boolean hasMoreItems() {
            return hasMore;
        }

        @Override
        public Pair<Integer, Integer> getTotalResultCount() {
            return total;
        }

        @Override
        public String getQueryExecutionId() {
            return null;
        }
    };
}
Also used : PagingResults(org.alfresco.query.PagingResults) Reference(org.alfresco.repo.virtual.ref.Reference) ResultSetRow(org.alfresco.service.cmr.search.ResultSetRow) LinkedList(java.util.LinkedList) Pair(org.alfresco.util.Pair)

Aggregations

Reference (org.alfresco.repo.virtual.ref.Reference)81 NodeRef (org.alfresco.service.cmr.repository.NodeRef)59 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)23 VersionServiceTrait (org.alfresco.repo.version.traitextender.VersionServiceTrait)16 LinkedList (java.util.LinkedList)15 VirtualizationIntegrationTest (org.alfresco.repo.virtual.VirtualizationIntegrationTest)15 Test (org.junit.Test)15 PermissionReference (org.alfresco.repo.security.permissions.PermissionReference)13 NodeServiceTrait (org.alfresco.repo.node.db.traitextender.NodeServiceTrait)12 QName (org.alfresco.service.namespace.QName)10 Serializable (java.io.Serializable)9 GetParentReferenceMethod (org.alfresco.repo.virtual.ref.GetParentReferenceMethod)9 Version (org.alfresco.service.cmr.version.Version)9 GetActualNodeRefMethod (org.alfresco.repo.virtual.ref.GetActualNodeRefMethod)8 VirtualFolderDefinition (org.alfresco.repo.virtual.template.VirtualFolderDefinition)6 FileInfo (org.alfresco.service.cmr.model.FileInfo)6 PermissionServiceTrait (org.alfresco.repo.security.permissions.impl.traitextender.PermissionServiceTrait)5 VirtualizationException (org.alfresco.repo.virtual.VirtualizationException)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4