Search in sources :

Example 1 with ProtocolMethodException

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

the class GetPathMethod method execute.

@Override
public Path execute(VirtualProtocol virtualProtocol, Reference reference) throws ProtocolMethodException {
    try {
        NodeRef actualNodeRef = reference.execute(new GetActualNodeRefMethod(environment));
        Path path = null;
        if (actualNodeRef == null) {
            // Although not a feature yet, pure-virtual-references should
            // use an empty path as root since pure-virtual-references have
            // no actual peer to use.
            path = new Path();
        } else {
            path = environment.getPath(actualNodeRef);
        }
        Path virtualPath = smartStore.getPath(reference);
        return path.append(virtualPath);
    } catch (ReferenceEncodingException e) {
        throw new ProtocolMethodException(e);
    }
}
Also used : Path(org.alfresco.service.cmr.repository.Path) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ProtocolMethodException(org.alfresco.repo.virtual.ref.ProtocolMethodException) ReferenceEncodingException(org.alfresco.repo.virtual.ref.ReferenceEncodingException) GetActualNodeRefMethod(org.alfresco.repo.virtual.ref.GetActualNodeRefMethod)

Example 2 with ProtocolMethodException

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

the class ApplyTemplateMethod method execute.

@Override
public VirtualFolderDefinition execute(VanillaProtocol vanillaProtocol, Reference reference) throws ProtocolMethodException {
    InputStream vanillaIS = reference.execute(new GetVanillaScriptInputStreamMethod(environment));
    try {
        String vanillaJSON = IOUtils.toString(vanillaIS, StandardCharsets.UTF_8);
        VirtualContext context = createVirtualContext(reference);
        context.setParameter(VANILLA_JSON_PARAM_NAME, vanillaJSON);
        return execute(vanillaProtocol, reference, context);
    } catch (IOException e) {
        throw new ProtocolMethodException(e);
    } finally {
        try {
            if (vanillaIS != null)
                vanillaIS.close();
        } catch (IOException ioe) {
            logger.warn("Failed to close input stream : " + ioe);
        }
    }
}
Also used : ProtocolMethodException(org.alfresco.repo.virtual.ref.ProtocolMethodException) InputStream(java.io.InputStream) GetVanillaScriptInputStreamMethod(org.alfresco.repo.virtual.ref.GetVanillaScriptInputStreamMethod) IOException(java.io.IOException) VirtualContext(org.alfresco.repo.virtual.VirtualContext)

Example 3 with ProtocolMethodException

use of org.alfresco.repo.virtual.ref.ProtocolMethodException 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)

Aggregations

ProtocolMethodException (org.alfresco.repo.virtual.ref.ProtocolMethodException)3 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 VirtualContext (org.alfresco.repo.virtual.VirtualContext)1 GetActualNodeRefMethod (org.alfresco.repo.virtual.ref.GetActualNodeRefMethod)1 GetTemplatePathMethod (org.alfresco.repo.virtual.ref.GetTemplatePathMethod)1 GetVanillaScriptInputStreamMethod (org.alfresco.repo.virtual.ref.GetVanillaScriptInputStreamMethod)1 ReferenceEncodingException (org.alfresco.repo.virtual.ref.ReferenceEncodingException)1 Resource (org.alfresco.repo.virtual.ref.Resource)1 ResourceProcessingError (org.alfresco.repo.virtual.ref.ResourceProcessingError)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 Path (org.alfresco.service.cmr.repository.Path)1