Search in sources :

Example 1 with ActualEnvironmentException

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

the class GetAspectsMethod method execute.

@Override
public Set<QName> execute(VirtualProtocol virtualProtocol, Reference reference) throws ProtocolMethodException {
    try {
        Set<QName> aspects = createVirtualAspects();
        String path = virtualProtocol.getTemplatePath(reference);
        if (PATH_SEPARATOR.equals(path.trim())) {
            NodeRef nodeRef;
            nodeRef = virtualProtocol.getActualNodeLocation(reference).asNodeRef(environment);
            Set<QName> nodeAspects = nodeServiceTrait.getAspects(nodeRef);
            aspects.addAll(nodeAspects);
        }
        return aspects;
    } catch (ActualEnvironmentException e) {
        throw new ProtocolMethodException(e);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) QName(org.alfresco.service.namespace.QName) ActualEnvironmentException(org.alfresco.repo.virtual.ActualEnvironmentException)

Example 2 with ActualEnvironmentException

use of org.alfresco.repo.virtual.ActualEnvironmentException 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 ActualEnvironmentException

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

the class VirtualNodeServiceExtension method createDownloadAssociation.

private void createDownloadAssociation(NodeRef sourceNodeRef, NodeRef targetRef) {
    NodeRef tempFolderNodeRef = downloadAssociationsFolder.resolve(true);
    String tempFileName = sourceNodeRef.getId();
    NodeRef tempFileNodeRef = environment.getChildByName(tempFolderNodeRef, ContentModel.ASSOC_CONTAINS, tempFileName);
    if (tempFileNodeRef == null) {
        FileInfo newTempFileInfo = environment.create(tempFolderNodeRef, tempFileName, ContentModel.TYPE_CONTENT);
        tempFileNodeRef = newTempFileInfo.getNodeRef();
        ContentWriter writer = environment.getWriter(tempFileNodeRef, ContentModel.PROP_CONTENT, true);
        writer.setMimetype("text/plain");
        writer.putContent(targetRef.toString());
    } else {
        ContentWriter writer = environment.getWriter(tempFileNodeRef, ContentModel.PROP_CONTENT, true);
        try {
            List<String> readLines = IOUtils.readLines(environment.openContentStream(tempFileNodeRef), StandardCharsets.UTF_8);
            String targetRefString = targetRef.toString();
            if (!readLines.contains(targetRefString)) {
                readLines.add(targetRefString);
            }
            String text = "";
            for (String line : readLines) {
                if (text.isEmpty()) {
                    text = line;
                } else {
                    text = text + IOUtils.LINE_SEPARATOR + line;
                }
            }
            writer.putContent(text);
        } catch (IOException e) {
            throw new ActualEnvironmentException(e);
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) FileInfo(org.alfresco.service.cmr.model.FileInfo) ActualEnvironmentException(org.alfresco.repo.virtual.ActualEnvironmentException) IOException(java.io.IOException)

Aggregations

ActualEnvironmentException (org.alfresco.repo.virtual.ActualEnvironmentException)3 NodeRef (org.alfresco.service.cmr.repository.NodeRef)3 IOException (java.io.IOException)1 ResourceProcessingError (org.alfresco.repo.virtual.ref.ResourceProcessingError)1 FileInfo (org.alfresco.service.cmr.model.FileInfo)1 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)1 QName (org.alfresco.service.namespace.QName)1