]> git.argeo.org Git - gpl/argeo-slc.git/blob - src/site/apt/howtos/howto-attachments.apt
Improve provisioning via OSGiBoot
[gpl/argeo-slc.git] / src / site / apt / howtos / howto-attachments.apt
1 Upload of attachments to a test result
2
3 This allows to attach ANY Spring resource (for example the one created above but not only, since it can also be classpath: or osgibundle: Resources or ANY file on the file system where the agent is running (e.g. Mx *.mxres files on a server...))
4
5 In order to use it:
6
7 [[1]] First reference an attachment uploader service via OSGi (it is provided by the standard agent):
8
9 +-------------------------------+
10 <reference id="attachmentUploader" interface="org.argeo.slc.core.attachment.AttachmentUploader" />
11 +-------------------------------+
12
13 [[1]] Then use an UploadAttachment task:
14
15 +-------------------------------+
16 <bean parent="task.uploadAttachments">
17 <property name="attachmentUploader" ref="attachmentUploader" />
18 <property name="attachment">
19 <bean parent="taskArg.attachment">
20 <property name="name" value="myAttachment.txt" />
21 </bean>
22 </property>
23 <property name="resource" ref="basic.writeTo" />
24 <property name="attachTo">
25 <list>
26 <ref bean="basic.testResult" />
27 </list>
28 </property>
29 </bean>
30 +-------------------------------+
31
32 You have to specify an Attachment object with at least a 'name', you can also specify a 'contentType', but the server will recognize common extension of the name.
33 You have to specify a (Spring) Resource, for example the one that you created before (the name of the attachment doesn't have to be the name of the file).
34 Just doing this will already upload a file to the server, but if you want to access it you need to bind it to some object, typically a TreeTestResult. You can provide a list of AttachmentEnabled objects (only TreeTestResult implements it so far).
35
36 You could use directly Spring Resource URL, e.g.:
37
38 +-------------------------------+
39 <property name="resource" value="osgibundle:/conf/main.xml" />
40 +-------------------------------+
41
42 You can also upload and attach many attachments in one shot. In that case provide a Map with the keys being Attachment objects and the values Resource objects. E.g.:
43
44 +-------------------------------+
45 <bean parent="task.uploadAttachments">
46 <property name="attachmentUploader" ref="attachmentUploader" />
47 <property name="attachments">
48 <map>
49 <entry>
50 <key>
51 <bean parent="taskArg.attachment">
52 <property name="name" value="Reached.csv" />
53 </bean>
54 </key>
55 <bean factory-bean="fileDiff.testData" factory-method="getReached"
56 scope="execution">
57 <aop:scoped-proxy />
58 </bean>
59 </entry>
60 <entry>
61 <key>
62 <bean parent="taskArg.attachment">
63 <property name="name" value="Expected.csv" />
64 </bean>
65 </key>
66 <bean factory-bean="fileDiff.testData" factory-method="getExpected"
67 scope="execution">
68 <aop:scoped-proxy />
69 </bean>
70 </entry>
71 </map>
72 </property>
73 <property name="attachTo">
74 <list>
75 <ref bean="fileDiff.testResult" />
76 </list>
77 </property>
78 </bean>
79 +-------------------------------+
80
81 Retrieving the resources from this bean:
82
83 +-------------------------------+
84 <bean id="fileDiff.testData" parent="testData.reachedExpected"
85 scope="execution">
86 <aop:scoped-proxy />
87 <property name="expected" value="osgibundle:/inputs/csvdiff/@{fileName}.csv" />
88 <property name="reached"
89 value="osgibundle:/inputs/csvdiff/@{fileName}_mod.csv" />
90 </bean>
91 +-------------------------------+
92
93 [[1]] You can access the attachments from the Web UI by selecting a result in the list in the results perspective.
94 You will see that a new button 'Attachment' in the toolbar get activated (if there are any attachments).