use of org.alfresco.repo.virtual.ref.Reference in project alfresco-repository by Alfresco.
the class VirtualStoreImpl method getChildByName.
@Override
public Reference getChildByName(Reference reference, QName assocTypeQName, String childName) throws VirtualizationException {
VirtualFolderDefinition structure = resolveVirtualFolderDefinition(reference);
VirtualFolderDefinition theChild = structure.findChildByName(childName);
if (theChild != null) {
return reference.execute(new GetChildByIdMethod(theChild.getId()));
} else {
final VirtualQuery query = structure.getQuery();
if (query != null) {
PropertyValueConstraint constraint = new PropertyValueConstraint(new FilesFoldersConstraint(BasicConstraint.INSTANCE, true, true), ContentModel.PROP_NAME, childName, environment.getNamespacePrefixResolver());
PagingResults<Reference> result = query.perform(environment, constraint, null, reference);
List<Reference> page = result.getPage();
return page == null || page.isEmpty() ? null : page.get(0);
} else {
return null;
}
}
}
use of org.alfresco.repo.virtual.ref.Reference in project alfresco-repository by Alfresco.
the class VirtualStoreImpl method getPath.
@Override
public Path getPath(Reference reference) throws VirtualizationException {
Reference virtualPathElement = reference;
Reference virtualPathParent = reference.execute(new GetParentReferenceMethod());
Path virtualPath = new Path();
while (virtualPathElement != null && virtualPathParent != null) {
NodeRef parentNodeRef;
parentNodeRef = virtualPathParent.toNodeRef();
NodeRef parent = parentNodeRef;
NodeRef virtualPathNodeRef = virtualPathElement.toNodeRef();
// TODO: extract node reference name into protocol method in order
// to enforce path processing code reuse and consistency
String templatePath = virtualPathElement.execute(new GetTemplatePathMethod()).trim();
final String pathSeparator = "/";
if (pathSeparator.equals(templatePath)) {
// found root
break;
} else if (templatePath.endsWith(pathSeparator)) {
templatePath = templatePath.substring(0, templatePath.length() - 1);
}
int lastSeparator = templatePath.lastIndexOf(pathSeparator);
String childId = templatePath.substring(lastSeparator + 1);
VirtualFolderDefinition structure = resolveVirtualFolderDefinition(virtualPathParent);
VirtualFolderDefinition child = structure.findChildById(childId);
if (child == null) {
throw new VirtualizationException("Invalid reference: " + reference.encode());
}
String childName = child.getName();
QName childQName = QName.createQName(VirtualContentModel.VIRTUAL_CONTENT_MODEL_1_0_URI, childName);
ChildAssociationRef assocRef = new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, parent, childQName, virtualPathNodeRef, true, -1);
ChildAssocElement assocRefElement = new ChildAssocElement(assocRef);
virtualPath.prepend(assocRefElement);
virtualPathElement = virtualPathParent;
virtualPathParent = virtualPathParent.execute(new GetParentReferenceMethod());
}
return virtualPath;
}
use of org.alfresco.repo.virtual.ref.Reference in project alfresco-repository by Alfresco.
the class ApplyTemplateMethodTest method testExecute_vanillaISO9075ActualPath.
@Category(RedundantTests.class)
@Test
public void testExecute_vanillaISO9075ActualPath() throws Exception {
ChildAssociationRef iso9075FolderAssoc = createFolder(testRootFolder.getNodeRef(), "Acutal ISO9075 Node");
NodeRef iso9075Folder = iso9075FolderAssoc.getChildRef();
NewVirtualReferenceMethod newVirtualReferenceMethod = new NewVirtualReferenceMethod(TEST_TEMPLATE_5_JSON_SYS_PATH, "/", iso9075Folder, VANILLA_PROCESSOR_JS_CLASSPATH);
ApplyTemplateMethod applyTemplateMethod = new ApplyTemplateMethod(environment);
Reference ref = Protocols.VANILLA.protocol.dispatch(newVirtualReferenceMethod, null);
VirtualFolderDefinition structure = ref.execute(applyTemplateMethod);
VirtualFolderDefinition sfp5 = structure.findChildByName("SpecialFilingPath5");
VirtualQuery query = sfp5.getQuery();
assertEquals("(PATH:'/app:company_home/cm:TestFolder/cm:Acutal_x0020_ISO9075_x0020_Node/cm:Space_x0020_Sub_x0020_Folder/*') and =cm:description:'SpecialFilingPath_5'", query.getQueryString());
ChildAssociationRef iso9075SubFolderAssoc = createFolder(iso9075Folder, "Space Sub Folder");
ChildAssociationRef someContentAssoc = createContent(iso9075SubFolderAssoc.getChildRef(), "someContent");
nodeService.setProperty(someContentAssoc.getChildRef(), ContentModel.PROP_DESCRIPTION, "SpecialFilingPath_5");
// check query for validity
SearchParameters searchParameters = new SearchParameters();
searchParameters.setQuery(query.getQueryString());
searchParameters.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
searchParameters.setLanguage(query.getLanguage());
/* Code commented out as part of REPO-2028
* If this test needs to be reactivated, please refactor this to use the prepareMocks/resetMocks methods
*/
// ResultSet qresult = searchService.query(searchParameters);
// assertEquals(1, qresult.getNumberFound());
}
use of org.alfresco.repo.virtual.ref.Reference in project alfresco-repository by Alfresco.
the class ApplyTemplateMethodTest method testExecute_vanillaRepositoryJSON.
@Test
public void testExecute_vanillaRepositoryJSON() throws Exception {
ChildAssociationRef templateAssoc = createContent(testRootFolder.getNodeRef(), "template1.json", ApplyTemplateMethodTest.class.getResourceAsStream(TEST_TEMPLATE_1_JSON_NAME), MimetypeMap.MIMETYPE_JSON, StandardCharsets.UTF_8.name());
ApplyTemplateMethod applyTemplateMethod = new ApplyTemplateMethod(environment);
NewVirtualReferenceMethod newVirtualReferenceMethod = new NewVirtualReferenceMethod(templateAssoc.getChildRef(), "/", virtualFolder1NodeRef, VANILLA_PROCESSOR_JS_CLASSPATH);
Reference ref = Protocols.VANILLA.protocol.dispatch(newVirtualReferenceMethod, null);
VirtualFolderDefinition structure = ref.execute(applyTemplateMethod);
String templateName = structure.getName();
assertEquals("Test", templateName);
List<VirtualFolderDefinition> children = structure.getChildren();
assertEquals(2, children.size());
VirtualFolderDefinition child1 = structure.findChildByName("Node1");
assertTrue(child1 != null);
VirtualFolderDefinition child2 = structure.findChildByName("Node2");
assertTrue(child2 != null);
}
use of org.alfresco.repo.virtual.ref.Reference in project alfresco-repository by Alfresco.
the class TypeVirtualizationMethodIntegrationTest method virtualize.
private void virtualize(NodeRef expectedTemplateNodeRef, QName fodlerType, QName... aspects) throws Exception {
ChildAssociationRef typedNodeAssocRef = createTypedNode(testRootFolder.getNodeRef(), "TypeVirtualized", fodlerType);
NodeRef typeNode = typedNodeAssocRef.getChildRef();
for (QName aspect : aspects) {
nodeService.addAspect(typeNode, aspect, Collections.<QName, Serializable>emptyMap());
}
assertTrue(typeVirtualizationMethod.canVirtualize(environment, typeNode));
Reference theVirtualizedNode = typeVirtualizationMethod.virtualize(environment, typeNode);
assertEquals(Protocols.VANILLA.protocol, theVirtualizedNode.getProtocol());
List<Parameter> parameters = theVirtualizedNode.getParameters();
ResourceParameter vanillaResourceParameter = (ResourceParameter) parameters.get(VanillaProtocol.VANILLA_TEMPLATE_PARAM_INDEX);
Resource vanillaResource = vanillaResourceParameter.getValue();
NodeRef resourceNodeRef = vanillaResource.processWith(new ResourceProcessor<NodeRef>() {
@Override
public NodeRef process(Resource resource) throws ResourceProcessingError {
fail("Inavlid resource type");
return null;
}
@Override
public NodeRef process(ClasspathResource classpath) throws ResourceProcessingError {
fail("Inavlid resource type");
return null;
}
@Override
public NodeRef process(RepositoryResource repository) throws ResourceProcessingError {
RepositoryLocation location = repository.getLocation();
return location.asNodeRef(environment);
}
});
assertEquals(expectedTemplateNodeRef, resourceNodeRef);
}
Aggregations