use of org.alfresco.repo.virtual.VirtualizationException in project alfresco-repository by Alfresco.
the class TemplateFilingRule method parentNodeRefFor.
private NodeRef parentNodeRefFor(Reference parentReference, boolean failIfNotFound) {
NodeRef fParentRef;
if (path == null || path.length() == 0) {
fParentRef = parentReference.execute(new GetActualNodeRefMethod(env));
} else {
String[] pathElements = NodeRefPathExpression.splitAndNormalizePath(path);
for (int i = 0; i < pathElements.length; i++) {
pathElements[i] = ISO9075.decode(pathElements[i]);
}
fParentRef = env.findQNamePath(pathElements);
}
boolean noReadPermissions = false;
if (fParentRef != null && !env.hasPermission(fParentRef, PermissionService.READ_PERMISSIONS)) {
fParentRef = null;
noReadPermissions = true;
}
if (logger.isDebugEnabled()) {
if (fParentRef == null) {
if (noReadPermissions) {
logger.debug("Current user does not have READ_PERMISSIONS for filing path" + path + ".");
} else {
logger.debug("The filing path " + path + " doesn't exist.");
}
}
}
if (failIfNotFound && fParentRef == null) {
throw new VirtualizationException("The filing path " + path + " could not be resolved.");
}
return fParentRef;
}
use of org.alfresco.repo.virtual.VirtualizationException in project alfresco-repository by Alfresco.
the class VirtualNodeServiceExtension method getDownloadTargetAssocs.
private List<AssociationRef> getDownloadTargetAssocs(NodeRef sourceNodeRef) {
try {
List<AssociationRef> result = new ArrayList<AssociationRef>();
NodeRef tempFolderNodeRef = downloadAssociationsFolder.resolve();
if (tempFolderNodeRef == null) {
return result;
}
String tempFileName = sourceNodeRef.getId();
NodeRef tempFileNodeRef = environment.getChildByName(tempFolderNodeRef, ContentModel.ASSOC_CONTAINS, tempFileName);
if (tempFileNodeRef == null) {
return result;
}
List<String> readLines = IOUtils.readLines(environment.openContentStream(tempFileNodeRef), StandardCharsets.UTF_8);
for (String line : readLines) {
NodeRef targetRef = new NodeRef(line);
AssociationRef assocRef = new AssociationRef(sourceNodeRef, DownloadModel.ASSOC_REQUESTED_NODES, targetRef);
result.add(assocRef);
}
return result;
} catch (IOException e) {
throw new VirtualizationException(e);
}
}
use of org.alfresco.repo.virtual.VirtualizationException in project alfresco-repository by Alfresco.
the class TemplateVirtualizationMethod method newVirtualReference.
/**
* @param env the environment in which the virtualization takes place
* @param actualNodeRef the node that is virtualized using the given
* template
* @param templateSystemPath system path string of the template used in
* virtualizing the given NodeRef
* @return a {@link Reference} correspondent of the given {@link NodeRef}
* according to the rules defined by the given template
* @throws VirtualizationException
* @deprecated all template system path functionality should be replaced by
* plain encoded references
*/
protected Reference newVirtualReference(ActualEnvironment env, NodeRef actualNodeRef, String templateSystemPath) throws VirtualizationException {
final char systemToken = templateSystemPath.charAt(0);
if (systemToken == VirtualProtocol.NODE_TEMPLATE_PATH_TOKEN) {
// create node based reference
return newVirtualReference(env, actualNodeRef, new NodeRef(templateSystemPath.substring(1)));
}
String templateName = retrieveTemplateContentName(env, templateSystemPath);
if (!templateName.isEmpty()) {
Protocol protocol = protocolFormName(templateName);
return protocol.dispatch(new NewVirtualReferenceMethod(templateSystemPath, PATH_SEPARATOR, actualNodeRef, vanillaProcessorClasspath), null);
} else {
// default branch - invalid virtual node
throw new VirtualizationException("Invalid virtualization : missing template name for " + templateSystemPath);
}
}
use of org.alfresco.repo.virtual.VirtualizationException in project alfresco-repository by Alfresco.
the class VirtualStoreImpl method list.
@Override
public PagingResults<Reference> list(final Reference ref, boolean actual, boolean virtual, final boolean files, final boolean folders, final String pattern, final Set<QName> searchTypeQNames, final Set<QName> ignoreTypeQNames, final Set<QName> ignoreAspectQNames, final List<Pair<QName, Boolean>> sortProps, final PagingRequest pagingRequest) throws VirtualizationException {
VirtualFolderDefinition structure = resolveVirtualFolderDefinition(ref);
List<Reference> virtualRefs = null;
// constraints should handle folder & file filtering
if (virtual && folders) {
virtualRefs = createChildReferences(ref, structure);
} else {
virtualRefs = Collections.emptyList();
}
if (actual) {
final VirtualQuery query = structure.getQuery();
if (query != null) {
// we have a query we must collate results
PagingResultsSource<Reference> querySourc = new PagingResultsSource<Reference>() {
@Override
public PagingResults<Reference> retrieve(PagingRequest pr) throws PageCollationException {
try {
return query.perform(environment, files, folders, pattern, searchTypeQNames, ignoreTypeQNames, ignoreAspectQNames, sortProps, pr, ref);
} catch (VirtualizationException e) {
throw new PageCollationException(e);
}
}
};
PageCollator<Reference> collator = new PageCollator<>();
try {
return collator.collate(virtualRefs, querySourc, pagingRequest, new ReferenceComparator(this, sortProps));
} catch (PageCollationException e) {
throw new VirtualizationException(e);
}
}
}
return new ListBackedPagingResults<>(virtualRefs);
}
use of org.alfresco.repo.virtual.VirtualizationException in project alfresco-repository by Alfresco.
the class VirtualStoreImpl method getPath.
@Override
public Path getPath(Reference reference) throws VirtualizationException {
Reference virtualPathElement = reference;
Reference virtualPathParent = reference.execute(new GetParentReferenceMethod());
Path virtualPath = new Path();
while (virtualPathElement != null && virtualPathParent != null) {
NodeRef parentNodeRef;
parentNodeRef = virtualPathParent.toNodeRef();
NodeRef parent = parentNodeRef;
NodeRef virtualPathNodeRef = virtualPathElement.toNodeRef();
// TODO: extract node reference name into protocol method in order
// to enforce path processing code reuse and consistency
String templatePath = virtualPathElement.execute(new GetTemplatePathMethod()).trim();
final String pathSeparator = "/";
if (pathSeparator.equals(templatePath)) {
// found root
break;
} else if (templatePath.endsWith(pathSeparator)) {
templatePath = templatePath.substring(0, templatePath.length() - 1);
}
int lastSeparator = templatePath.lastIndexOf(pathSeparator);
String childId = templatePath.substring(lastSeparator + 1);
VirtualFolderDefinition structure = resolveVirtualFolderDefinition(virtualPathParent);
VirtualFolderDefinition child = structure.findChildById(childId);
if (child == null) {
throw new VirtualizationException("Invalid reference: " + reference.encode());
}
String childName = child.getName();
QName childQName = QName.createQName(VirtualContentModel.VIRTUAL_CONTENT_MODEL_1_0_URI, childName);
ChildAssociationRef assocRef = new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, parent, childQName, virtualPathNodeRef, true, -1);
ChildAssocElement assocRefElement = new ChildAssocElement(assocRef);
virtualPath.prepend(assocRefElement);
virtualPathElement = virtualPathParent;
virtualPathParent = virtualPathParent.execute(new GetParentReferenceMethod());
}
return virtualPath;
}
Aggregations