Search in sources :

Example 1 with VirtualizationException

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

the class VirtualFileFolderServiceExtension method list.

@Override
public PagingResults<FileInfo> list(final NodeRef contextNodeRef, final boolean files, final boolean folders, final String pattern, final Set<QName> ignoreQNames, final List<Pair<QName, Boolean>> sortProps, final PagingRequest pagingRequest) {
    final FileFolderServiceTrait theTrait = getTrait();
    if (canVirtualize(contextNodeRef)) {
        final Reference reference = smartStore.virtualize(contextNodeRef);
        Set<QName>[] searchAndIgnore = buildSearchAndIgnore(files, folders, ignoreQNames);
        if (mergeActualNode(reference)) {
            PagingResults<Reference> virtualChildren = smartStore.list(reference, false, true, files, folders, pattern, searchAndIgnore[1], searchAndIgnore[2], sortProps, new PagingRequest(0));
            PagingResultsSource<FileInfo> superSource = new PagingResultsSource<FileInfo>() {

                @Override
                public PagingResults<FileInfo> retrieve(PagingRequest pr) throws PageCollationException {
                    try {
                        PagingResults<FileInfo> result = theTrait.list(actualNodeFrom(reference), files, folders, pattern, ignoreQNames, sortProps, pr);
                        return result;
                    } catch (VirtualizationException e) {
                        throw new PageCollationException(e);
                    }
                }
            };
            FileInfoPropsComparator comparator = (sortProps != null && !sortProps.isEmpty()) ? new FileInfoPropsComparator(sortProps) : null;
            try {
                return new PageCollator<FileInfo>().collate(asFileInfoResults(environment, virtualChildren, smartStore).getPage(), superSource, pagingRequest, comparator);
            } catch (PageCollationException error) {
                throw new VirtualizationException(error);
            }
        } else {
            PagingResults<Reference> children = smartStore.list(reference, true, true, files, folders, pattern, searchAndIgnore[1], searchAndIgnore[2], sortProps, pagingRequest);
            return asFileInfoResults(environment, children, smartStore);
        }
    } else {
        return theTrait.list(contextNodeRef, files, folders, pattern, ignoreQNames, sortProps, pagingRequest);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Reference(org.alfresco.repo.virtual.ref.Reference) PagingRequest(org.alfresco.query.PagingRequest) PageCollationException(org.alfresco.repo.virtual.page.PageCollationException) FileInfo(org.alfresco.service.cmr.model.FileInfo) FileFolderServiceTrait(org.alfresco.repo.model.filefolder.traitextender.FileFolderServiceTrait) PagingResultsSource(org.alfresco.repo.virtual.page.PageCollator.PagingResultsSource) VirtualizationException(org.alfresco.repo.virtual.VirtualizationException)

Example 2 with VirtualizationException

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

the class VirtualNodeServiceExtension method createNode.

@Override
public ChildAssociationRef createNode(NodeRef parentRef, QName assocTypeQName, QName assocQName, QName nodeTypeQName, Map<QName, Serializable> properties) {
    NodeServiceTrait theTrait = getTrait();
    if ((Reference.fromNodeRef(parentRef) != null) && !isVirtualContextFolder(parentRef, environment)) {
        // (repo)
        if (environment.isSubClass(nodeTypeQName, ContentModel.TYPE_FOLDER)) {
            throw new VirtualizationException("The creation of folders within virtual folders is disabled.");
        }
        try {
            Reference parentReference = Reference.fromNodeRef(parentRef);
            FilingData filingData = smartStore.createFilingData(parentReference, assocTypeQName, assocQName, nodeTypeQName, properties);
            NodeRef childParentNodeRef = filingData.getFilingNodeRef();
            if (childParentNodeRef != null) {
                Map<QName, Serializable> filingDataProperties = filingData.getProperties();
                QName changedAssocQName = assocQName;
                if (filingDataProperties.containsKey(ContentModel.PROP_NAME)) {
                    String fileName = (String) filingDataProperties.get(ContentModel.PROP_NAME);
                    String changedFileName = handleExistingFile(childParentNodeRef, fileName);
                    if (!changedFileName.equals(fileName)) {
                        filingDataProperties.put(ContentModel.PROP_NAME, changedFileName);
                        QName filingDataAssocQName = filingData.getAssocQName();
                        changedAssocQName = QName.createQName(filingDataAssocQName.getNamespaceURI(), QName.createValidLocalName(changedFileName));
                    }
                }
                ChildAssociationRef actualChildAssocRef = theTrait.createNode(childParentNodeRef, filingData.getAssocTypeQName(), changedAssocQName == null ? filingData.getAssocQName() : changedAssocQName, filingData.getNodeTypeQName(), filingDataProperties);
                Reference nodeProtocolChildRef = NodeProtocol.newReference(actualChildAssocRef.getChildRef(), parentReference);
                QName vChildAssocQName = QName.createQNameWithValidLocalName(VirtualContentModel.VIRTUAL_CONTENT_MODEL_1_0_URI, actualChildAssocRef.getQName().getLocalName());
                ChildAssociationRef childAssocRef = new ChildAssociationRef(actualChildAssocRef.getTypeQName(), parentRef, vChildAssocQName, nodeProtocolChildRef.toNodeRef());
                Set<QName> aspects = filingData.getAspects();
                for (QName aspect : aspects) {
                    theTrait.addAspect(actualChildAssocRef.getChildRef(), aspect, filingDataProperties);
                }
                return childAssocRef;
            } else {
                throw new InvalidNodeRefException("Can not create node using parent ", parentRef);
            }
        } catch (VirtualizationException e) {
            throw new InvalidNodeRefException("Could not create node in virtual context.", parentRef, e);
        }
    } else {
        QName materialAssocQName = materializeAssocQName(assocQName);
        if (isVirtualContextFolder(parentRef, environment)) {
            parentRef = smartStore.materializeIfPossible(parentRef);
        }
        return theTrait.createNode(parentRef, assocTypeQName, materialAssocQName, nodeTypeQName, properties);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) NodeServiceTrait(org.alfresco.repo.node.db.traitextender.NodeServiceTrait) Reference(org.alfresco.repo.virtual.ref.Reference) QName(org.alfresco.service.namespace.QName) FilingData(org.alfresco.repo.virtual.template.FilingData) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) VirtualizationException(org.alfresco.repo.virtual.VirtualizationException)

Example 3 with VirtualizationException

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

the class VirtualNodeServiceExtension method materializeAssocQName.

private QName materializeAssocQName(QName assocQName) {
    // replace the assocQNames with material correspondents.
    try {
        String lName = assocQName.getLocalName();
        NodeRef nrAssocQName = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, lName);
        if (Reference.fromNodeRef(nrAssocQName) != null) {
            nrAssocQName = smartStore.materializeIfPossible(nrAssocQName);
            QName materialAssocQName = QName.createQName(assocQName.getNamespaceURI(), nrAssocQName.getId());
            return materialAssocQName;
        } else {
            return assocQName;
        }
    } catch (VirtualizationException e) {
        // isReference-virtualize-materialize.
        if (logger.isDebugEnabled()) {
            logger.debug("Defaulting on materializeAssocQName due to error.", e);
        }
        return assocQName;
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) QName(org.alfresco.service.namespace.QName) VirtualizationException(org.alfresco.repo.virtual.VirtualizationException)

Example 4 with VirtualizationException

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

the class VirtualFileFolderServiceExtension method list.

@Override
public PagingResults<FileInfo> list(final NodeRef rootNodeRef, final Set<QName> searchTypeQNames, final Set<QName> ignoreAspectQNames, final List<Pair<QName, Boolean>> sortProps, final PagingRequest pagingRequest) {
    if (canVirtualize(rootNodeRef)) {
        final Reference reference = smartStore.virtualize(rootNodeRef);
        List<Pair<QName, Boolean>> sortingPropoerties = sortProps;
        if (sortingPropoerties == null || sortingPropoerties.isEmpty()) {
            sortingPropoerties = Arrays.asList(new Pair<QName, Boolean>(ContentModel.PROP_NAME, true));
        }
        if (mergeActualNode(reference)) {
            PagingResults<Reference> virtualChildren = smartStore.list(reference, false, true, searchTypeQNames, Collections.<QName>emptySet(), ignoreAspectQNames, sortProps, new PagingRequest(0));
            PagingResultsSource<FileInfo> superSource = new PagingResultsSource<FileInfo>() {

                @Override
                public PagingResults<FileInfo> retrieve(PagingRequest pr) throws PageCollationException {
                    try {
                        PagingResults<FileInfo> result = getTrait().list(actualNodeFrom(reference), searchTypeQNames, ignoreAspectQNames, sortProps, pr);
                        return result;
                    } catch (VirtualizationException e) {
                        throw new PageCollationException(e);
                    }
                }
            };
            FileInfoPropsComparator comparator = new FileInfoPropsComparator(sortingPropoerties);
            try {
                return new PageCollator<FileInfo>().collate(asFileInfoResults(environment, virtualChildren, smartStore).getPage(), superSource, pagingRequest, comparator);
            } catch (PageCollationException error) {
                throw new VirtualizationException(error);
            }
        } else {
            PagingResults<Reference> children = smartStore.list(reference, true, true, searchTypeQNames, Collections.<QName>emptySet(), ignoreAspectQNames, sortingPropoerties, pagingRequest);
            return asFileInfoResults(environment, children, smartStore);
        }
    }
    return getTrait().list(rootNodeRef, searchTypeQNames, ignoreAspectQNames, sortProps, pagingRequest);
}
Also used : Reference(org.alfresco.repo.virtual.ref.Reference) PagingRequest(org.alfresco.query.PagingRequest) PageCollationException(org.alfresco.repo.virtual.page.PageCollationException) FileInfo(org.alfresco.service.cmr.model.FileInfo) PagingResultsSource(org.alfresco.repo.virtual.page.PageCollator.PagingResultsSource) VirtualizationException(org.alfresco.repo.virtual.VirtualizationException) Pair(org.alfresco.util.Pair)

Example 5 with VirtualizationException

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

the class TypeVirtualizationMethod method virtualize.

@Override
public Reference virtualize(ActualEnvironment env, NodeRef nodeRef) throws VirtualizationException {
    if (solvingTemplate.get()) {
        throw new VirtualizationException("Concurrent virtualization!");
    }
    try {
        solvingTemplate.set(true);
        NodeRef templateNode = templateNodeFor(env, nodeRef);
        return newVirtualReference(Protocols.VANILLA.protocol, templateNode, nodeRef);
    } catch (VirtualizationException e) {
        throw e;
    } catch (Exception e) {
        throw new VirtualizationException(e);
    } finally {
        solvingTemplate.set(false);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) VirtualizationException(org.alfresco.repo.virtual.VirtualizationException) PatternSyntaxException(java.util.regex.PatternSyntaxException) NamespaceException(org.alfresco.service.namespace.NamespaceException) ActualEnvironmentException(org.alfresco.repo.virtual.ActualEnvironmentException) 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