Search in sources :

Example 11 with NodeServiceTrait

use of org.alfresco.repo.node.db.traitextender.NodeServiceTrait in project alfresco-repository by Alfresco.

the class VirtualNodeServiceExtension method handleExistingFile.

private String handleExistingFile(NodeRef parentNodeRef, String fileName) {
    NodeServiceTrait actualNodeService = getTrait();
    NodeRef existingFile = actualNodeService.getChildByName(parentNodeRef, ContentModel.ASSOC_CONTAINS, fileName);
    if (existingFile != null) {
        int counter = 1;
        int dotIndex;
        String tmpFilename = "";
        final String dot = ".";
        final String hyphen = "-";
        while (existingFile != null) {
            int beforeCounter = fileName.lastIndexOf(hyphen);
            dotIndex = fileName.lastIndexOf(dot);
            if (dotIndex == 0) {
                // File didn't have a proper 'name' instead it had just a
                // suffix and
                // started with a ".", create "1.txt"
                tmpFilename = counter + fileName;
            } else if (dotIndex > 0) {
                if (beforeCounter > 0 && beforeCounter < dotIndex) {
                    // does file have counter in it's name or it just
                    // contains -1
                    String originalFileName = fileName.substring(0, beforeCounter) + fileName.substring(dotIndex);
                    boolean doesOriginalFileExist = actualNodeService.getChildByName(parentNodeRef, ContentModel.ASSOC_CONTAINS, originalFileName) != null;
                    if (doesOriginalFileExist) {
                        String counterStr = fileName.substring(beforeCounter + 1, dotIndex);
                        try {
                            int parseInt = DefaultTypeConverter.INSTANCE.intValue(counterStr);
                            counter = parseInt + 1;
                            fileName = fileName.substring(0, beforeCounter) + fileName.substring(dotIndex);
                            dotIndex = fileName.lastIndexOf(dot);
                        } catch (NumberFormatException ex) {
                        // "-" is not before counter
                        }
                    }
                }
                tmpFilename = fileName.substring(0, dotIndex) + hyphen + counter + fileName.substring(dotIndex);
            } else {
                // Filename didn't contain a dot at all, create "filename-1"
                tmpFilename = fileName + hyphen + counter;
            }
            existingFile = actualNodeService.getChildByName(parentNodeRef, ContentModel.ASSOC_CONTAINS, tmpFilename);
            counter++;
        }
        fileName = tmpFilename;
    }
    return fileName;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) NodeServiceTrait(org.alfresco.repo.node.db.traitextender.NodeServiceTrait)

Example 12 with NodeServiceTrait

use of org.alfresco.repo.node.db.traitextender.NodeServiceTrait in project alfresco-repository by Alfresco.

the class VirtualNodeServiceExtension method removeSeconaryChildAssociation.

@Override
public boolean removeSeconaryChildAssociation(ChildAssociationRef childAssocRef) {
    NodeServiceTrait theTrait = getTrait();
    NodeRef childRef = childAssocRef.getChildRef();
    if (Reference.fromNodeRef(childRef) != null) {
        List<ChildAssociationRef> assocsToRemove = revertVirtualAssociation(childAssocRef, theTrait, childRef);
        boolean removed = false;
        if (!assocsToRemove.isEmpty()) {
            for (ChildAssociationRef assoc : assocsToRemove) {
                removed = removed || theTrait.removeSeconaryChildAssociation(assoc);
            }
        }
        return removed;
    } else {
        return theTrait.removeSeconaryChildAssociation(childAssocRef);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) NodeServiceTrait(org.alfresco.repo.node.db.traitextender.NodeServiceTrait) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 13 with NodeServiceTrait

use of org.alfresco.repo.node.db.traitextender.NodeServiceTrait in project alfresco-repository by Alfresco.

the class VirtualNodeServiceExtension method getChildAssocsWithoutParentAssocsOfType.

@Override
public Collection<ChildAssociationRef> getChildAssocsWithoutParentAssocsOfType(NodeRef nodeRef, QName assocTypeQName) {
    NodeServiceTrait theTrait = getTrait();
    boolean canVirtualize = canVirtualizeAssocNodeRef(nodeRef);
    if (canVirtualize) {
        Reference reference = smartStore.virtualize(nodeRef);
        Collection<ChildAssociationRef> virtualAssociations = smartStore.getChildAssocsWithoutParentAssocsOfType(reference, assocTypeQName);
        List<ChildAssociationRef> associations = new LinkedList<>(virtualAssociations);
        if (smartStore.canMaterialize(reference)) {
            NodeRef materialReference = smartStore.materialize(reference);
            Collection<ChildAssociationRef> actualAssociations = theTrait.getChildAssocsWithoutParentAssocsOfType(materialReference, assocTypeQName);
            associations.addAll(actualAssociations);
        }
        return associations;
    } else {
        return theTrait.getChildAssocsWithoutParentAssocsOfType(nodeRef, assocTypeQName);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) NodeServiceTrait(org.alfresco.repo.node.db.traitextender.NodeServiceTrait) Reference(org.alfresco.repo.virtual.ref.Reference) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) LinkedList(java.util.LinkedList)

Example 14 with NodeServiceTrait

use of org.alfresco.repo.node.db.traitextender.NodeServiceTrait in project alfresco-repository by Alfresco.

the class VirtualNodeServiceExtension method removeChildAssociation.

@Override
public boolean removeChildAssociation(ChildAssociationRef childAssocRef) {
    NodeServiceTrait theTrait = getTrait();
    NodeRef childRef = childAssocRef.getChildRef();
    if (Reference.fromNodeRef(childRef) != null) {
        List<ChildAssociationRef> assocsToRemove = revertVirtualAssociation(childAssocRef, theTrait, childRef);
        boolean removed = false;
        if (!assocsToRemove.isEmpty()) {
            for (ChildAssociationRef assoc : assocsToRemove) {
                removed = removed || theTrait.removeChildAssociation(assoc);
            }
        }
        return removed;
    } else {
        return theTrait.removeChildAssociation(childAssocRef);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) NodeServiceTrait(org.alfresco.repo.node.db.traitextender.NodeServiceTrait) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 15 with NodeServiceTrait

use of org.alfresco.repo.node.db.traitextender.NodeServiceTrait in project alfresco-repository by Alfresco.

the class VirtualNodeServiceExtension method deleteNode.

@Override
public void deleteNode(NodeRef nodeRef) throws InvalidNodeRefException {
    NodeServiceTrait theTrait = getTrait();
    NodeRef materialNode = smartStore.materializeIfPossible(nodeRef);
    boolean isDownload = DownloadModel.TYPE_DOWNLOAD.equals(theTrait.getType(materialNode));
    theTrait.deleteNode(materialNode);
    if (isDownload) {
        cleanUpDownloadTargetAssocs(nodeRef);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) NodeServiceTrait(org.alfresco.repo.node.db.traitextender.NodeServiceTrait)

Aggregations

NodeServiceTrait (org.alfresco.repo.node.db.traitextender.NodeServiceTrait)17 NodeRef (org.alfresco.service.cmr.repository.NodeRef)16 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)14 Reference (org.alfresco.repo.virtual.ref.Reference)12 LinkedList (java.util.LinkedList)7 GetParentReferenceMethod (org.alfresco.repo.virtual.ref.GetParentReferenceMethod)3 Serializable (java.io.Serializable)2 AssociationRef (org.alfresco.service.cmr.repository.AssociationRef)2 QName (org.alfresco.service.namespace.QName)2 ArrayList (java.util.ArrayList)1 VirtualizationException (org.alfresco.repo.virtual.VirtualizationException)1 GetActualNodeRefMethod (org.alfresco.repo.virtual.ref.GetActualNodeRefMethod)1 GetAspectsMethod (org.alfresco.repo.virtual.ref.GetAspectsMethod)1 FilingData (org.alfresco.repo.virtual.template.FilingData)1 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)1