<!-- Created with Jaspersoft Studio version 7.0.3.final using JasperReports Library version 7.0.3-41034ca841d452f3305ba55b9042260aaa1ab5dd  -->
<jasperReport name="Subscribed Documents" language="java" pageWidth="842" pageHeight="595" orientation="Landscape" whenNoDataType="AllSectionsNoDetail" columnWidth="782" leftMargin="30" rightMargin="30" topMargin="20" bottomMargin="20" whenResourceMissingType="Key" uuid="e88bbb51-9d6d-46f6-aa88-9e7f1aa03dc6">
	<property name="ireport.scriptlethandling" value="0"/>
	<property name="ireport.encoding" value="UTF-8"/>
	<property name="ireport.zoom" value="1.5"/>
	<property name="ireport.x" value="60"/>
	<property name="ireport.y" value="0"/>
	<import>net.sf.jasperreports.engine.*</import>
	<import>java.util.*</import>
	<import>net.sf.jasperreports.engine.data.*</import>
	<query language="sql"><![CDATA[import java.util.*;
import com.openkm.api.OKMDocument;
import com.openkm.api.OKMRepository;
import com.openkm.db.HibernateUtil;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.query.Query;
import com.openkm.db.bean.NodeDocument;
import org.hibernate.SessionFactory;
import com.openkm.util.ContextWrapper;
import org.springframework.web.context.WebApplicationContext;

int COLS = 10;

class PathSorter implements Comparator {
    public int compare(Object obj1, Object obj2) {
		String path1 = (String) obj1;
		String path2 = (String) obj2;
		String[] paths1 = path1.split("/");
		String[] paths2 = path2.split("/");
		for (int i=0; i<paths1.length-1; i++) {
			if (i<paths2.length) {
				if (!paths1[i].equals(paths2[i])) {
					return paths1[i].compareTo(paths2[i]);
				}
			} else {
				return 1;
			}
		}
		if (paths2.length == paths1.length) {
			return paths1[paths1.length-1].compareTo(paths2[paths2.length-1]);
		} else if (paths2.length > paths1.length) {
			return -1;
		} else {
			return 1;
		}
    }
}

List al = new ArrayList();
List pathList = new ArrayList();
String qs = "from NodeDocument";
WebApplicationContext cc = (WebApplicationContext) ContextWrapper.getContext();
SessionFactory sessionFactory = cc.getBean(SessionFactory.class);
OKMRepository okmRepository = cc.getBean(OKMRepository.class);
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
Query q = session.createQuery(qs);
List docVersionList = q.list();
tx.commit();

for (NodeDocument ndv : docVersionList) {
    String path = okmRepository.getNodePath(null,ndv.getUuid());
    if (path.startsWith("/okm:root/")) {
        pathList.add(path);
    }

}
session.close();

// Ordering by path
Collections.sort(pathList, new PathSorter());

// Initialize older map
Map older = new HashMap();
for (int i=1; i<COLS; i++) {
    older.put("path"+i,"");
}

// Iterating paths
for (String docPath : pathList) {
    Map dob = new HashMap();

    String[] paths = docPath.split("/");
    for (int i=1; i<paths.length; i++) {
        String path = paths[i];
        if (i<(paths.length-1)) {
            // Repeat info will not appearing
            if (!older.get("path"+i).equals((paths[i]+"/"))) {
                dob.put("path"+i, (paths[i]+"/"));
                older.put("path"+i, (paths[i]+"/"));
            } else {
                dob.put("path"+i, "");
            }

        } else {
            dob.put("path"+i, paths[i]);
        }
    }


    // Set empty path values
    for (int i=paths.length; i<COLS; i++) {
        dob.put("path"+i,"");
        older.put("path"+i,"");
    }


    // Preview
    for (int i=1; i<COLS; i++) {
        print("path"+i+">"+dob.get("path"+i));
    }
    print("<br/>");

    al.add(dob);

}

return al]]></query>
	<field name="path1" class="java.lang.String">
		<description><![CDATA[path]]></description>
	</field>
	<field name="path2" class="java.lang.String"/>
	<field name="path3" class="java.lang.String"/>
	<field name="path4" class="java.lang.String"/>
	<field name="path5" class="java.lang.String"/>
	<field name="path6" class="java.lang.String"/>
	<field name="path7" class="java.lang.String"/>
	<field name="path8" class="java.lang.String"/>
	<field name="path9" class="java.lang.String"/>
	<background splitType="Stretch"/>
	<title height="44" splitType="Stretch">
		<element kind="image" uuid="87c44f15-7f75-4418-87d8-30fb801cf9c4" key="image-1" x="631" y="0" width="150" height="35">
			<expression><![CDATA["http://localhost:8080/openkm/logo/report"]]></expression>
		</element>
		<element kind="textField" uuid="ab4fc399-48dc-4258-902f-b5ee286089d2" key="textField-13" x="0" y="0" width="65" height="10" forecolor="#010101" fontName="Arial" fontSize="8.0" pdfFontName="unicode.ttf" pdfEncoding="Identity-H" pattern="yyyy/MM/dd" blankWhenNull="false" underline="false" bold="true" vTextAlign="Middle">
			<expression><![CDATA[new Date()]]></expression>
			<box>
				<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
				<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
				<bottomPen lineWidth="0.0" lineColor="#000000"/>
				<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
			</box>
		</element>
		<element kind="textField" uuid="0eba2afa-d1de-453b-b872-7f67d6e9b8e7" key="textField-14" x="0" y="10" width="65" height="10" forecolor="#010101" fontName="Arial" fontSize="8.0" pdfFontName="unicode.ttf" pdfEncoding="Identity-H" pattern="h.mm.ss a" blankWhenNull="false" underline="false" bold="true" vTextAlign="Middle">
			<expression><![CDATA[new Date()]]></expression>
			<box>
				<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
				<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
				<bottomPen lineWidth="0.0" lineColor="#000000"/>
				<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
			</box>
		</element>
		<element kind="line" uuid="6139c2c9-4c35-4b99-98d4-569a86d72243" key="line-3" x="1" y="39" width="781" height="1" forecolor="#010101"/>
		<element kind="staticText" uuid="e110f65e-f745-4dcf-a787-bf2498ba3000" x="256" y="0" width="297" height="44" fontName="Arial" fontSize="22.0" pdfFontName="unicode.ttf" pdfEncoding="Identity-H" bold="true" pdfEmbedded="false" hTextAlign="Center" vTextAlign="Middle">
			<text><![CDATA[Accessible Documents]]></text>
		</element>
	</title>
	<pageHeader splitType="Stretch"/>
	<columnHeader height="30" splitType="Stretch">
		<element kind="line" uuid="f20b3b73-9ee1-4338-ab46-3be37d29751c" key="line-5" x="1" y="28" width="780" height="1" forecolor="#010101"/>
		<element kind="staticText" uuid="9663ed96-5bf9-464e-99e7-6c0fb58447e8" x="1" y="13" width="781" height="14" fontName="Arial" pdfFontName="unicode.ttf" pdfEncoding="Identity-H" bold="true" pdfEmbedded="false">
			<text><![CDATA[Document]]></text>
		</element>
	</columnHeader>
	<detail>
		<band height="18" splitType="Stretch">
			<element kind="textField" uuid="e85d27ad-e95e-42dc-b48e-d893b7eec399" key="textField" x="1" y="0" width="47" height="18" fontName="Arial" pdfFontName="unicode.ttf" pdfEncoding="Identity-H" textAdjust="StretchHeight" blankWhenNull="false">
				<expression><![CDATA[$F{path1}]]></expression>
			</element>
			<element kind="textField" uuid="31d9c628-ce10-4ef2-b6d6-063690caf752" key="textField" x="48" y="0" width="74" height="18" fontName="Arial" pdfFontName="unicode.ttf" pdfEncoding="Identity-H" textAdjust="StretchHeight" blankWhenNull="false">
				<expression><![CDATA[$F{path2}]]></expression>
			</element>
			<element kind="textField" uuid="cc5898a1-fd8f-4dee-ab41-e1967e40b75a" key="textField" x="122" y="0" width="67" height="18" fontName="Arial" pdfFontName="unicode.ttf" pdfEncoding="Identity-H" textAdjust="StretchHeight" blankWhenNull="false">
				<expression><![CDATA[$F{path3}]]></expression>
			</element>
			<element kind="textField" uuid="6f26b03d-29a0-48db-91d3-b23561cea385" key="textField" x="188" y="0" width="68" height="18" fontName="Arial" pdfFontName="unicode.ttf" pdfEncoding="Identity-H" textAdjust="StretchHeight" blankWhenNull="false">
				<expression><![CDATA[$F{path4}]]></expression>
			</element>
			<element kind="textField" uuid="7079a9ee-e1db-4743-a6ff-e590f4921760" key="textField" x="256" y="0" width="68" height="18" fontName="Arial" pdfFontName="unicode.ttf" pdfEncoding="Identity-H" textAdjust="StretchHeight" blankWhenNull="false">
				<expression><![CDATA[$F{path5}]]></expression>
			</element>
			<element kind="textField" uuid="e116ea46-da49-4c0c-881b-8b7f82c60f4a" key="textField" x="324" y="0" width="68" height="18" fontName="Arial" pdfFontName="unicode.ttf" pdfEncoding="Identity-H" textAdjust="StretchHeight" blankWhenNull="false">
				<expression><![CDATA[$F{path6}]]></expression>
			</element>
			<element kind="textField" uuid="708a9fd7-f00b-40be-bfe0-8d37a029b495" key="textField" x="392" y="0" width="68" height="18" fontName="Arial" pdfFontName="unicode.ttf" pdfEncoding="Identity-H" textAdjust="StretchHeight" blankWhenNull="false">
				<expression><![CDATA[$F{path7}]]></expression>
			</element>
			<element kind="textField" uuid="3e68ab04-9926-4e6c-9540-49d8d5c82682" key="textField" x="460" y="0" width="68" height="18" fontName="Arial" pdfFontName="unicode.ttf" pdfEncoding="Identity-H" textAdjust="StretchHeight" blankWhenNull="false">
				<expression><![CDATA[$F{path8}]]></expression>
			</element>
			<element kind="textField" uuid="ea24689f-bea1-454c-b2e8-030e7db789a7" key="textField" x="528" y="0" width="68" height="18" fontName="Arial" pdfFontName="unicode.ttf" pdfEncoding="Identity-H" textAdjust="StretchHeight" blankWhenNull="false">
				<expression><![CDATA[$F{path9}]]></expression>
			</element>
		</band>
	</detail>
	<columnFooter splitType="Stretch"/>
	<pageFooter height="30" splitType="Stretch">
		<element kind="line" uuid="3b86af30-ffb3-4933-bbd1-f88d438481eb" key="line-2" x="1" y="4" width="780" height="1" forecolor="#010101" backcolor="#FFFFFF"/>
	</pageFooter>
	<summary splitType="Stretch"/>
</jasperReport>
