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