Afficher les derniers auteurs
1 {{groovy}}
2 import com.xpn.xwiki.doc.XWikiAttachment
3 import java.text.SimpleDateFormat
4 import java.util.Date
5
6 def count=200
7 def curdoc = doc
8 def TreeMap sortedEvents = new TreeMap()
9 def maxstrlenght = 150
10 def skinurl='http://r-wikiggs.gemalto.com/xwiki/bin/download/XWiki/GSESkin'
11
12 // Utility class for mail archive
13 def tools = xwiki.parseGroovyFromPage('MailArchiveCode.ToolsGroovyClass')
14
15 // Set loading user in context (for rights)
16 def settingsDoc = xwiki.getDocument("MailArchivePrefs.GlobalParameters")
17 settingsDoc.use("MailArchiveCode.AdminClass")
18 def loadingUser = settingsDoc.getValue("user");
19 xwiki.context.setUser(loadingUser)
20
21 if (!curdoc.hasAccessLevel('edit', loadingUser)) {
22 println "User ${loadingUser} doesn't have needed rights on ${curdoc}, exiting"
23 } else {
24
25 try {
26
27 // Add Topics durations
28 xwql = "select topic.name from Document doc, doc.object('MailArchiveCode.MailTopicClass') as topic order by topic.lastupdatedate desc"
29 result = services.get("query").xwql(xwql).setLimit(count).execute()
30
31 for (item in result) {
32 doc = xwiki.getDocument(item)
33 obj = doc.getObject("MailArchiveCode.MailTopicClass")
34 if (obj != null)
35 {
36 try {
37 author = obj.getProperty("author").value
38 subject = obj.getProperty("subject").value
39 docurl = doc.space+"."+doc.name
40 docshortname = subject
41
42 date = obj.getProperty("startdate").value
43 end = obj.getProperty("lastupdatedate").value
44 if (date == end) {
45 // Add 10 min just to see the tape
46 end.setTime(end.getTime()+600000)
47 }
48 //extract = doc.display("body", "view", obj).trim()
49 extract = getTopicMails(obj.topicid, subject)
50 type = obj.getProperty("type").value
51 tags = ""
52 if (doc.getTags().contains("GGS_WW_")) {
53 tags = "GGS_WW"
54 }
55 doc.getTagList().grep(~/^Community.*$/).each() {
56 if (tags == "GGS_WW") { tags = "" }
57 tags += "${it.value} "
58 }
59 if (type == "Mail") {
60 if (!xwiki.getDocument(doc.creator).isNew()) {
61 icon = "${xwiki.getDocument(doc.creator).getURL('download')}/ldapavatar.jpg"
62 } else {
63 icon = "${xwiki.getDocument('XWiki.XWikiUserSheet').getURL('download')}/noavatar.png"
64 }
65 action = 'Topic created'
66 sortedEvents.put(date.getTime(), '<event start="'+date.toLocaleString()+'" end="'+end.toLocaleString()+'" title="'+xwiki.getXMLEncoded(docshortname)+'" icon="'+icon+'" image="'+icon+'" classname="'+tags+'" durationEvent="true" link="'+doc.getURL()+'">'+xwiki.getXMLEncoded((tags!=""?'<span class="tape-'+tags+'">___</span> '+ tags + '<br/>':'')+'<br/> '+action+' by '+author+'<br/> '+extract)+'</event>')
67
68
69 } else {
70 if (type == "Newsletter") {
71 action = "Newsletter posted"
72 icon = "${xwiki.getDocument('XWiki.GSESkin').getURL('download')}/667%2D2_pupils_speech.png"
73 }
74 if (type == "Product Release") {
75 action = "Product Release published"
76 icon = "http://r-wikiggs.gemalto.com/xwiki/resources/icons/silk/cd.gif"
77 }
78 link = xwiki.getDocument("MailArchive.M${doc.name[1..-1]}").getURL()
79 sortedEvents.put(date.getTime(), '<event start="'+date.toLocaleString()+'" title="'+xwiki.getXMLEncoded(docshortname)+'" icon="'+icon+'" image="'+icon+'" link="'+link+'" >'+xwiki.getXMLEncoded((tags!=""?'<span class="tape-'+tags+'">___</span> '+tags+'<br/>':'')+'<br/>'+action+' by '+author+'<br/> '+extract)+'</event>')
80 }
81 } catch (Throwable t) {
82 println "Exception for ${doc}: ${t}"
83 println (t.getStackTrace())
84 }
85 }
86 }
87
88
89
90 } catch (Throwable e) {
91 e.printStackTrace()
92 println("could not compute timeline data because of " + e)
93 println(e.getStackTrace())
94 }
95
96
97 try {
98 StringBuffer content = new StringBuffer()
99 content.append('<data>')
100 for (event in sortedEvents.entrySet()) {
101 content.append(event.getValue()+'\n')
102 }
103 content.append('</data>')
104
105 curdoc.addAttachment("TimeLineFeed-MailArchiver.xml", content.toString().getBytes())
106 curdoc.save("update", true)
107
108 /* def fw = new FileWriter("../webapps/xwiki/TimeLineFeed-MailArchiver.xml", false)
109 fw.write(content.toString())
110 fw.close()*/
111
112 println("Loaded " + sortedEvents.size() + " into Timeline feed [[attach:TimeLineFeed-MailArchiver.xml]]")
113
114
115 } catch (Exception e) {
116 println ("Exception occured"+e+e.printStackTrace())
117 }
118
119 }
120
121 def getTopicMails(topicid, topicsubject) {
122 def returnVal = ""
123 def first = true
124 def xwql_topic = "select doc.fullName,doc.author,mail.date,mail.messagesubject,mail.from from Document doc, doc.object(MailArchiveCode.MailClass) as mail where mail.topicid='${topicid}' and doc.fullName<>'MailArchiveCode.MailClassTemplate' order by mail.date asc"
125 def msgs = services.get("query").xwql(xwql_topic).execute()
126 msgs.each { msg ->
127 // formatter for formatting dates for display
128 def formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm")
129 def userdoc = xwiki.getDocument(msg[1])
130 def user = ""
131 def link = null
132 if (!userdoc.isNew()) {
133 userobj = userdoc.getObject('XWiki.XWikiUsers')
134 if (userobj != null) {
135 user = userobj.first_name + ' ' + userobj.last_name
136 link = userdoc.getURL()
137 }
138 } else {
139 def start = msg[4].indexOf("<")
140 if (start != -1) { user = msg[4].substring(0,start) }
141 }
142 def subject = topicsubject
143 if (!first) {
144 subject = msg[3].replace("${topicsubject}", "...")
145 } else if (topicsubject.length()>20) {
146 subject = topicsubject[0..19] + "..."
147 }
148 returnVal += '<a href="javascript:centerTimeline('+msg[2].getTime()+');">' + formatter.format(msg[2]) + '</a> - <a href="' + xwiki.getDocument(msg[0]).getURL() + '">' + subject + '</a> - ' + (link!=null?'<a href="' + link + '">':'') + user + (link!=null?'</a> ':'') + '<br/>'
149 first = false
150 }
151
152 return returnVal
153
154 }
155 {{/groovy}}
This wiki is licensed under a Creative Commons 2.0 license
XWiki 11.8.1 - Documentation