use of org.alfresco.repo.virtual.ref.Resource in project alfresco-repository by Alfresco.
the class ApplyTemplateMethod method execute.
public VirtualFolderDefinition execute(VirtualProtocol virtualProtocol, Reference reference, VirtualContext context) throws ProtocolMethodException {
Resource resource = reference.getResource();
try {
VirtualFolderDefinition theStructure = resource.processWith(new TemplateResourceProcessor(context));
String path = reference.execute(new GetTemplatePathMethod());
if (!path.isEmpty()) {
String[] pathElements = path.split(PATH_SEPARATOR);
int startIndex = path.startsWith(PATH_SEPARATOR) ? 1 : 0;
for (int i = startIndex; i < pathElements.length; i++) {
theStructure = theStructure.findChildById(pathElements[i]);
if (theStructure == null) {
throw new ProtocolMethodException("Invalid template path in " + reference.toString());
}
}
}
return theStructure;
} catch (ResourceProcessingError e) {
throw new ProtocolMethodException(e);
}
}
use of org.alfresco.repo.virtual.ref.Resource 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