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);
}
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);
}
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);
}
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"));
}
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;
}
};
}
Aggregations