Search in sources :

Example 1 with ResourceProcessingError

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

the class TemplateResourceProcessor method asVirtualStructure.

/**
 * Creates a {@link VirtualFolderDefinition} that represents the structure
 * of the virtual folder.
 *
 * @param context The context in which the virtualization process takes
 *            place.
 * @param result A map containing the details that define the virtual
 *            entries.
 * @return a {@link VirtualFolderDefinition} reference.
 * @throws ResourceProcessingError
 */
protected VirtualFolderDefinition asVirtualStructure(VirtualContext context, Map<String, Object> result) throws ResourceProcessingError {
    try {
        Map<String, Object> mapResult = result;
        VirtualFolderDefinition virtualStructure = new VirtualFolderDefinition();
        String id = (String) mapResult.get(ID_KEY);
        virtualStructure.setId(id);
        String name = (String) mapResult.get(NAME_KEY);
        virtualStructure.setName(name);
        String description = (String) mapResult.get(DESCRIPTION_KEY);
        virtualStructure.setDescription(description);
        @SuppressWarnings("unchecked") VirtualQuery virtualQuery = asVirtualQuery(context, (Map<String, Object>) mapResult.get(SEARCH_KEY));
        virtualStructure.setQuery(virtualQuery);
        FilingRule filingRule = asFilingRule(context, mapResult.get(FILING_KEY));
        if (filingRule == null) {
            filingRule = new NullFilingRule(context.getActualEnviroment());
        }
        virtualStructure.setFilingRule(filingRule);
        @SuppressWarnings("unchecked") Map<String, String> properties = (Map<String, String>) mapResult.get(PROPERTIES_KEY);
        if (properties == null) {
            properties = Collections.emptyMap();
        }
        virtualStructure.setProperties(properties);
        @SuppressWarnings("unchecked") List<Map<String, Object>> nodes = (List<Map<String, Object>>) mapResult.get(NODES_KEY);
        if (nodes != null) {
            for (Map<String, Object> node : nodes) {
                VirtualFolderDefinition child = asVirtualStructure(context, node);
                virtualStructure.addChild(child);
            }
        }
        return virtualStructure;
    } catch (ClassCastException e) {
        throw new ResourceProcessingError(e);
    }
}
Also used : ResourceProcessingError(org.alfresco.repo.virtual.ref.ResourceProcessingError) List(java.util.List) Map(java.util.Map)

Example 2 with ResourceProcessingError

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

the class TemplateResourceProcessor method process.

/**
 * Processes the JavaScript template given by the {@link RepositoryResource}
 * and creates a {@link VirtualFolderDefinition} (composite) structure that
 * represents the virtual folder.
 *
 * @param A {@link RepositoryResource} reference.
 * @return A {@link VirtualFolderDefinition} reference that represents the
 *         structure (tree of nodes) of the virtual folder.
 */
@SuppressWarnings("unchecked")
@Override
public VirtualFolderDefinition process(RepositoryResource repositoryResource) throws ResourceProcessingError {
    Object result;
    try {
        NodeRef templateNodeRef = repositoryResource.getLocation().asNodeRef(context.getActualEnviroment());
        result = context.getActualEnviroment().executeScript(templateNodeRef, createScriptParameters(context));
        return asVirtualStructure(context, (Map<String, Object>) result);
    } catch (ActualEnvironmentException e) {
        throw new ResourceProcessingError(e);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ResourceProcessingError(org.alfresco.repo.virtual.ref.ResourceProcessingError) ActualEnvironmentException(org.alfresco.repo.virtual.ActualEnvironmentException)

Example 3 with ResourceProcessingError

use of org.alfresco.repo.virtual.ref.ResourceProcessingError 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);
    }
}
Also used : ResourceProcessingError(org.alfresco.repo.virtual.ref.ResourceProcessingError) ProtocolMethodException(org.alfresco.repo.virtual.ref.ProtocolMethodException) GetTemplatePathMethod(org.alfresco.repo.virtual.ref.GetTemplatePathMethod) Resource(org.alfresco.repo.virtual.ref.Resource)

Example 4 with ResourceProcessingError

use of org.alfresco.repo.virtual.ref.ResourceProcessingError 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);
}
Also used : QName(org.alfresco.service.namespace.QName) Reference(org.alfresco.repo.virtual.ref.Reference) Resource(org.alfresco.repo.virtual.ref.Resource) ClasspathResource(org.alfresco.repo.virtual.ref.ClasspathResource) RepositoryResource(org.alfresco.repo.virtual.ref.RepositoryResource) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) RepositoryLocation(org.alfresco.repo.virtual.ref.RepositoryLocation) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ResourceProcessingError(org.alfresco.repo.virtual.ref.ResourceProcessingError) ClasspathResource(org.alfresco.repo.virtual.ref.ClasspathResource) ResourceParameter(org.alfresco.repo.virtual.ref.ResourceParameter) RepositoryResource(org.alfresco.repo.virtual.ref.RepositoryResource) ResourceParameter(org.alfresco.repo.virtual.ref.ResourceParameter) Parameter(org.alfresco.repo.virtual.ref.Parameter)

Aggregations

ResourceProcessingError (org.alfresco.repo.virtual.ref.ResourceProcessingError)4 Resource (org.alfresco.repo.virtual.ref.Resource)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 List (java.util.List)1 Map (java.util.Map)1 ActualEnvironmentException (org.alfresco.repo.virtual.ActualEnvironmentException)1 ClasspathResource (org.alfresco.repo.virtual.ref.ClasspathResource)1 GetTemplatePathMethod (org.alfresco.repo.virtual.ref.GetTemplatePathMethod)1 Parameter (org.alfresco.repo.virtual.ref.Parameter)1 ProtocolMethodException (org.alfresco.repo.virtual.ref.ProtocolMethodException)1 Reference (org.alfresco.repo.virtual.ref.Reference)1 RepositoryLocation (org.alfresco.repo.virtual.ref.RepositoryLocation)1 RepositoryResource (org.alfresco.repo.virtual.ref.RepositoryResource)1 ResourceParameter (org.alfresco.repo.virtual.ref.ResourceParameter)1 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)1 QName (org.alfresco.service.namespace.QName)1