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;
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations