Search in sources :

Example 6 with VirtualizationException

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

the class TemplateFilingRule method parentNodeRefFor.

private NodeRef parentNodeRefFor(Reference parentReference, boolean failIfNotFound) {
    NodeRef fParentRef;
    if (path == null || path.length() == 0) {
        fParentRef = parentReference.execute(new GetActualNodeRefMethod(env));
    } else {
        String[] pathElements = NodeRefPathExpression.splitAndNormalizePath(path);
        for (int i = 0; i < pathElements.length; i++) {
            pathElements[i] = ISO9075.decode(pathElements[i]);
        }
        fParentRef = env.findQNamePath(pathElements);
    }
    boolean noReadPermissions = false;
    if (fParentRef != null && !env.hasPermission(fParentRef, PermissionService.READ_PERMISSIONS)) {
        fParentRef = null;
        noReadPermissions = true;
    }
    if (logger.isDebugEnabled()) {
        if (fParentRef == null) {
            if (noReadPermissions) {
                logger.debug("Current user does not have READ_PERMISSIONS for filing path" + path + ".");
            } else {
                logger.debug("The filing path " + path + " doesn't exist.");
            }
        }
    }
    if (failIfNotFound && fParentRef == null) {
        throw new VirtualizationException("The filing path " + path + " could not be resolved.");
    }
    return fParentRef;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) GetActualNodeRefMethod(org.alfresco.repo.virtual.ref.GetActualNodeRefMethod) VirtualizationException(org.alfresco.repo.virtual.VirtualizationException)

Example 7 with VirtualizationException

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

the class VirtualNodeServiceExtension method getDownloadTargetAssocs.

private List<AssociationRef> getDownloadTargetAssocs(NodeRef sourceNodeRef) {
    try {
        List<AssociationRef> result = new ArrayList<AssociationRef>();
        NodeRef tempFolderNodeRef = downloadAssociationsFolder.resolve();
        if (tempFolderNodeRef == null) {
            return result;
        }
        String tempFileName = sourceNodeRef.getId();
        NodeRef tempFileNodeRef = environment.getChildByName(tempFolderNodeRef, ContentModel.ASSOC_CONTAINS, tempFileName);
        if (tempFileNodeRef == null) {
            return result;
        }
        List<String> readLines = IOUtils.readLines(environment.openContentStream(tempFileNodeRef), StandardCharsets.UTF_8);
        for (String line : readLines) {
            NodeRef targetRef = new NodeRef(line);
            AssociationRef assocRef = new AssociationRef(sourceNodeRef, DownloadModel.ASSOC_REQUESTED_NODES, targetRef);
            result.add(assocRef);
        }
        return result;
    } catch (IOException e) {
        throw new VirtualizationException(e);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ArrayList(java.util.ArrayList) IOException(java.io.IOException) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) VirtualizationException(org.alfresco.repo.virtual.VirtualizationException)

Example 8 with VirtualizationException

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

the class TemplateVirtualizationMethod method newVirtualReference.

/**
 * @param env the environment in which the virtualization takes place
 * @param actualNodeRef the node that is virtualized using the given
 *            template
 * @param templateSystemPath system path string of the template used in
 *            virtualizing the given NodeRef
 * @return a {@link Reference} correspondent of the given {@link NodeRef}
 *         according to the rules defined by the given template
 * @throws VirtualizationException
 * @deprecated all template system path functionality should be replaced by
 *             plain encoded references
 */
protected Reference newVirtualReference(ActualEnvironment env, NodeRef actualNodeRef, String templateSystemPath) throws VirtualizationException {
    final char systemToken = templateSystemPath.charAt(0);
    if (systemToken == VirtualProtocol.NODE_TEMPLATE_PATH_TOKEN) {
        // create node based reference
        return newVirtualReference(env, actualNodeRef, new NodeRef(templateSystemPath.substring(1)));
    }
    String templateName = retrieveTemplateContentName(env, templateSystemPath);
    if (!templateName.isEmpty()) {
        Protocol protocol = protocolFormName(templateName);
        return protocol.dispatch(new NewVirtualReferenceMethod(templateSystemPath, PATH_SEPARATOR, actualNodeRef, vanillaProcessorClasspath), null);
    } else {
        // default branch - invalid virtual node
        throw new VirtualizationException("Invalid virtualization : missing template name for " + templateSystemPath);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) NewVirtualReferenceMethod(org.alfresco.repo.virtual.ref.NewVirtualReferenceMethod) VirtualProtocol(org.alfresco.repo.virtual.ref.VirtualProtocol) Protocol(org.alfresco.repo.virtual.ref.Protocol) VirtualizationException(org.alfresco.repo.virtual.VirtualizationException)

Example 9 with VirtualizationException

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

the class VirtualStoreImpl method list.

@Override
public PagingResults<Reference> list(final Reference ref, boolean actual, boolean virtual, final boolean files, final boolean folders, final String pattern, final Set<QName> searchTypeQNames, final Set<QName> ignoreTypeQNames, final Set<QName> ignoreAspectQNames, final List<Pair<QName, Boolean>> sortProps, final PagingRequest pagingRequest) throws VirtualizationException {
    VirtualFolderDefinition structure = resolveVirtualFolderDefinition(ref);
    List<Reference> virtualRefs = null;
    // constraints should handle folder & file filtering
    if (virtual && folders) {
        virtualRefs = createChildReferences(ref, structure);
    } else {
        virtualRefs = Collections.emptyList();
    }
    if (actual) {
        final VirtualQuery query = structure.getQuery();
        if (query != null) {
            // we have a query we must collate results
            PagingResultsSource<Reference> querySourc = new PagingResultsSource<Reference>() {

                @Override
                public PagingResults<Reference> retrieve(PagingRequest pr) throws PageCollationException {
                    try {
                        return query.perform(environment, files, folders, pattern, searchTypeQNames, ignoreTypeQNames, ignoreAspectQNames, sortProps, pr, ref);
                    } catch (VirtualizationException e) {
                        throw new PageCollationException(e);
                    }
                }
            };
            PageCollator<Reference> collator = new PageCollator<>();
            try {
                return collator.collate(virtualRefs, querySourc, pagingRequest, new ReferenceComparator(this, sortProps));
            } catch (PageCollationException e) {
                throw new VirtualizationException(e);
            }
        }
    }
    return new ListBackedPagingResults<>(virtualRefs);
}
Also used : PermissionReference(org.alfresco.repo.security.permissions.PermissionReference) Reference(org.alfresco.repo.virtual.ref.Reference) PagingRequest(org.alfresco.query.PagingRequest) PageCollationException(org.alfresco.repo.virtual.page.PageCollationException) VirtualQuery(org.alfresco.repo.virtual.template.VirtualQuery) PageCollator(org.alfresco.repo.virtual.page.PageCollator) PagingResultsSource(org.alfresco.repo.virtual.page.PageCollator.PagingResultsSource) VirtualFolderDefinition(org.alfresco.repo.virtual.template.VirtualFolderDefinition) VirtualizationException(org.alfresco.repo.virtual.VirtualizationException) ListBackedPagingResults(org.alfresco.query.ListBackedPagingResults)

Example 10 with VirtualizationException

use of org.alfresco.repo.virtual.VirtualizationException 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;
}
Also used : GetParentReferenceMethod(org.alfresco.repo.virtual.ref.GetParentReferenceMethod) Path(org.alfresco.service.cmr.repository.Path) NodeRef(org.alfresco.service.cmr.repository.NodeRef) GetTemplatePathMethod(org.alfresco.repo.virtual.ref.GetTemplatePathMethod) ChildAssocElement(org.alfresco.service.cmr.repository.Path.ChildAssocElement) PermissionReference(org.alfresco.repo.security.permissions.PermissionReference) Reference(org.alfresco.repo.virtual.ref.Reference) QName(org.alfresco.service.namespace.QName) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NamePatternPropertyValueConstraint(org.alfresco.repo.virtual.template.NamePatternPropertyValueConstraint) PropertyValueConstraint(org.alfresco.repo.virtual.template.PropertyValueConstraint) FilesFoldersConstraint(org.alfresco.repo.virtual.template.FilesFoldersConstraint) VirtualQueryConstraint(org.alfresco.repo.virtual.template.VirtualQueryConstraint) BasicConstraint(org.alfresco.repo.virtual.template.BasicConstraint) VirtualFolderDefinition(org.alfresco.repo.virtual.template.VirtualFolderDefinition) VirtualizationException(org.alfresco.repo.virtual.VirtualizationException)

Aggregations

VirtualizationException (org.alfresco.repo.virtual.VirtualizationException)12 NodeRef (org.alfresco.service.cmr.repository.NodeRef)9 Reference (org.alfresco.repo.virtual.ref.Reference)5 PagingRequest (org.alfresco.query.PagingRequest)3 PageCollationException (org.alfresco.repo.virtual.page.PageCollationException)3 PagingResultsSource (org.alfresco.repo.virtual.page.PageCollator.PagingResultsSource)3 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)3 QName (org.alfresco.service.namespace.QName)3 PermissionReference (org.alfresco.repo.security.permissions.PermissionReference)2 VirtualizationIntegrationTest (org.alfresco.repo.virtual.VirtualizationIntegrationTest)2 VirtualFolderDefinition (org.alfresco.repo.virtual.template.VirtualFolderDefinition)2 FileInfo (org.alfresco.service.cmr.model.FileInfo)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 ListBackedPagingResults (org.alfresco.query.ListBackedPagingResults)1