Skip to content

Commit b322d68

Browse files
committed
Add download query list feature via webscript
1 parent 330289e commit b322d68

8 files changed

+165
-2
lines changed

README.md

+33
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ Alfresco shell scripts for extracting user, groups, sites, data and metadata inf
1616
- [getSiteMemberships.sh](#getsitemembershipssh)
1717
- [getUserGroups.sh](#getusergroupssh)
1818
- [getAuthority.sh](#getauthoritysh)
19+
- [More Download Scripts](#more-download-scripts)
20+
- [downloadDoc.sh](#downloaddocsh)
21+
- [downloadList.sh](#downloadlistsh)
1922
- [Tested on](#tested-on)
2023
- [Author](#author)
2124
- [Links](#links)
@@ -312,6 +315,36 @@ $ ./getAuthority.sh -g ALFRESCO_ADMINISTRATORS -f
312315
admin,Administrator,Administrator,USER
313316
```
314317

318+
## More Download Scripts
319+
320+
### downloadDoc.sh
321+
322+
It provides a download script for a given Alfresco uuid and filename
323+
```
324+
$ ./downloadDoc.sh -h
325+
Usage: ./downloadDoc.sh [-d uuid] [-n name]
326+
```
327+
328+
### downloadList.sh
329+
330+
Download files selected from a webscript list resultset.
331+
```
332+
$ ./downloadList.sh
333+
```
334+
335+
A second webscript is necessary to deploy in Alfresco in net/zylk:
336+
337+
* get-download-list.get.desc.xml
338+
* get-download-list.get.js
339+
* get-download-list.get.text.ftl
340+
341+
The webscript obtains a list for the files tagged with "critical", but may be customized for any alfresco-fts query:
342+
343+
```
344+
workspace://SpacesStore/5515d3e1-bb2a-42ed-833c-52802a367033;Sitios/swsdp/documentLibrary/Presentations;Project Objectives.ppt
345+
workspace://SpacesStore/99cb2789-f67e-41ff-bea9-505c138a6b23;Sitios/swsdp/documentLibrary/Presentations;Project Overview.ppt
346+
```
347+
315348
## Tested on
316349

317350
* Alfresco Enterprise 4.1.1

downloadDoc.sh

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
3+
###
4+
### Script for downloading an Alfresco document
5+
###
6+
7+
# Usage functions
8+
usage() { echo "Usage: $0 [-d uuid] [-n name]" 1>&2; exit 1; }
9+
10+
# Command line options
11+
while getopts "u:p:hd:n:" o; do
12+
case "${o}" in
13+
u)
14+
MYUSER=${OPTARG}
15+
;;
16+
p)
17+
MYPASS=${OPTARG}
18+
;;
19+
d)
20+
MYUUID=${OPTARG}
21+
;;
22+
n)
23+
MYNAME=${OPTARG}
24+
;;
25+
\?)
26+
echo "Invalid Option: -$OPTARG" 1>&2
27+
exit 1
28+
;;
29+
h)
30+
usage
31+
;;
32+
*)
33+
usage
34+
;;
35+
esac
36+
done
37+
shift $((OPTIND-1))
38+
39+
# Exports ALFALFURL,MYUSER,MYPASS
40+
source ./exportENVARS.sh
41+
42+
if [ -z "${ALFURL}" ] || [ -z "${MYUSER}" ] || [ -z "${MYPASS}" ]; then
43+
usage
44+
fi
45+
46+
# Needs at least site as parameter
47+
if [ -z "${MYUUID}" ] && [ -z "${MYNAME}" ] ; then
48+
usage
49+
fi
50+
51+
# Default parameters
52+
#ALFURL=${ALFURL:-http://localhost:8080/alfresco}
53+
#MYUSER=${MYUSER:-admin}
54+
#MYPASS=${MYPASS:-admin}
55+
56+
curl -s -u "$MYUSER:$MYPASS" "$ALFURL/api/-default-/public/cmis/versions/1.1/atom/content/zz?id=$MYUUID" -o "$MYNAME"

downloadList.sh

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
INPUT=$1
4+
OLDIFS=$IFS
5+
IFS=';'
6+
7+
#if [ -z "$INPUT" ]; then
8+
# echo "Usage: downloadList.sh <listfile>"
9+
# exit 1;
10+
#fi
11+
12+
#if [ ! -f $INPUT ]; then
13+
# echo "Usage: downloadList.sh <listfile>"
14+
# echo "ERROR: $INPUT file not found";
15+
# exit 1;
16+
#fi
17+
18+
# Exports ALFALFURL,MYUSER,MYPASS
19+
source ./exportENVARS.sh
20+
curl -s -u "$MYUSER:$MYPASS" "$ALFURL/s/net/zylk/get-download-list" > /tmp/alflist
21+
INPUT=/tmp/alflist
22+
23+
while read aux1 aux2 aux3
24+
do
25+
echo "Downloading document... $aux1 ($aux3)"
26+
./downloadDoc.sh -d $aux1 -n "$aux3"
27+
mkdir -p "$aux2"
28+
mv "$aux3" "$aux2"
29+
done < $INPUT
30+
IFS=$OLDIFS

exportENVARS.sh

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
#! /bin/bash
2-
export ALFURL=http://localhost:8080/alfresco
2+
#export ALFURL=http://localhost:8080/alfresco
3+
#export MYUSER=admin
4+
#export MYPASS=secret
5+
6+
export ALFURL=http://melmac.zylk.net:8080/alfresco
37
export MYUSER=admin
4-
export MYPASS=secret
8+
export MYPASS=zylk
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<webscript>
2+
<shortname>Get download list</shortname>
3+
<description>Get download list</description>
4+
<url>/net/zylk/get-download-list</url>
5+
<format default="text"></format>
6+
<authentication>admin</authentication>
7+
<transaction>required</transaction>
8+
</webscript>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<#list nodes as node>
2+
${node}
3+
</#list>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
var q = 'TAG:"critical"';
2+
3+
var mynodes = new Array();
4+
5+
var pageSize = 1000; // no more than 1000!!!
6+
var currentPage = 0;
7+
var currentPageSize = -1;
8+
9+
var paging = { maxItems: pageSize, skipCount: 0 };
10+
var def = { query: q, store: 'workspace://SpacesStore', language: 'fts-alfresco', page: paging };
11+
12+
var i = 0;
13+
14+
while (currentPageSize != 0) {
15+
paging.skipCount = currentPage * pageSize;
16+
var nodes = search.query(def);
17+
currentPage = currentPage + 1;
18+
currentPageSize = (null != nodes ? nodes.length : 0);
19+
if (currentPageSize > 0) {
20+
for each(var node in nodes) {
21+
mynodes.push(node.nodeRef + ';' + decodeURI(node.parent.webdavUrl.replace("/webdav/","")) + ';' + node.name);
22+
}
23+
}
24+
}
25+
26+
model.nodes = mynodes;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<#list nodes as node>
2+
${node}
3+
</#list>

0 commit comments

Comments
 (0)