Search in sources :

Example 1 with FilingData

use of org.alfresco.repo.virtual.template.FilingData 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 2 with FilingData

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

the class VirtualStoreImpl method createFilingData.

@Override
public FilingData createFilingData(Reference parentReference, QName assocTypeQName, QName assocQName, QName nodeTypeQName, Map<QName, Serializable> properties) throws VirtualizationException {
    VirtualFolderDefinition structure = resolveVirtualFolderDefinition(parentReference);
    FilingRule filingRule = structure.getFilingRule();
    if (filingRule == null) {
        filingRule = new NullFilingRule(environment);
    }
    FilingParameters filingParameters = new FilingParameters(parentReference, assocTypeQName, assocQName, nodeTypeQName, properties);
    FilingData filingData = filingRule.createFilingData(filingParameters);
    return filingData;
}
Also used : NullFilingRule(org.alfresco.repo.virtual.template.NullFilingRule) FilingParameters(org.alfresco.repo.virtual.template.FilingParameters) FilingData(org.alfresco.repo.virtual.template.FilingData) VirtualFolderDefinition(org.alfresco.repo.virtual.template.VirtualFolderDefinition) FilingRule(org.alfresco.repo.virtual.template.FilingRule) NullFilingRule(org.alfresco.repo.virtual.template.NullFilingRule)

Aggregations

FilingData (org.alfresco.repo.virtual.template.FilingData)2 Serializable (java.io.Serializable)1 NodeServiceTrait (org.alfresco.repo.node.db.traitextender.NodeServiceTrait)1 VirtualizationException (org.alfresco.repo.virtual.VirtualizationException)1 Reference (org.alfresco.repo.virtual.ref.Reference)1 FilingParameters (org.alfresco.repo.virtual.template.FilingParameters)1 FilingRule (org.alfresco.repo.virtual.template.FilingRule)1 NullFilingRule (org.alfresco.repo.virtual.template.NullFilingRule)1 VirtualFolderDefinition (org.alfresco.repo.virtual.template.VirtualFolderDefinition)1 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)1 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 QName (org.alfresco.service.namespace.QName)1