Rev 1599 | Rev 1814 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
808 | jmachado | 1 | package pt.estgp.estgweb.services.assessments; |
2 | |||
3 | import com.itextpdf.text.*; |
||
4 | import com.itextpdf.text.Image; |
||
5 | import com.itextpdf.text.pdf.PdfPCell; |
||
6 | import com.itextpdf.text.pdf.PdfPTable; |
||
7 | import com.itextpdf.text.pdf.PdfWriter; |
||
8 | import com.itextpdf.text.pdf.draw.LineSeparator; |
||
9 | import jomm.utils.FilesUtils; |
||
10 | import org.apache.log4j.Logger; |
||
11 | import pt.estgp.estgweb.Globals; |
||
12 | import pt.estgp.estgweb.domain.*; |
||
13 | import pt.estgp.estgweb.domain.dao.DaoFactory; |
||
14 | import pt.estgp.estgweb.domain.views.AssessmentView; |
||
15 | import pt.estgp.estgweb.filters.chains.ResourceAccessControlEnum; |
||
16 | import pt.estgp.estgweb.services.data.RepositoryService; |
||
17 | import pt.estgp.estgweb.web.utils.DatesUtils; |
||
18 | import pt.utl.ist.berserk.logic.serviceManager.IService; |
||
19 | |||
20 | import java.io.*; |
||
21 | import java.util.List; |
||
22 | |||
23 | /** |
||
24 | * Created by IntelliJ IDEA. |
||
25 | * User: Filipe Matos |
||
26 | * Date: 6/Ago/2013 |
||
27 | * Time: 2:20:23 |
||
28 | * To change this template use File | Settings | File Templates. |
||
29 | */ |
||
30 | public class GeneratePdfService implements IService { |
||
31 | |||
32 | private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(GeneratePdfService.class); |
||
33 | |||
34 | private RepositoryService repositoryService = new RepositoryService(); |
||
35 | |||
36 | public void generateAssessmentPdf(long assessmentId,UserSession userSession) throws 1.5.0/docs/api/java/io/IOException.html">IOException, DocumentException { |
||
37 | Assessment assessment = DaoFactory.getAssessmentDaoImpl().get(assessmentId); |
||
38 | //////////////////////////////////////////////// |
||
39 | 5+0%2Fdocs%2Fapi+Document">Document doc = null; |
||
40 | 5+0%2Fdocs%2Fapi+OutputStream">OutputStream os = null; |
||
41 | |||
42 | try { |
||
43 | //cria o documento tamanho A4, margens de 2,54cm |
||
44 | doc = new 5+0%2Fdocs%2Fapi+Document">Document(PageSize.A4, 72, 72, 72, 72); |
||
1599 | jmachado | 45 | //cria a stream de sa�da |
808 | jmachado | 46 | os = new 1.5.0/docs/api/java/io/FileOutputStream.html">FileOutputStream(Globals.TMP_DIR+"Enunciado"+assessment.getTitle()+".pdf"); |
1599 | jmachado | 47 | //associa a stream de sa�da ao |
808 | jmachado | 48 | PdfWriter.getInstance(doc, os); |
49 | //abre o documento |
||
50 | doc.open(); |
||
1599 | jmachado | 51 | //imagem do cabe�alho |
808 | jmachado | 52 | 1.5.0/docs/api/java/awt/Image.html">Image img = 1.5.0/docs/api/java/awt/Image.html">Image.getInstance(Globals.SITE_URL+"/imgs/logoestg.gif"); |
53 | img.setAlignment(5+0%2Fdocs%2Fapi+Element">Element.ALIGN_LEFT); |
||
54 | doc.add(img); |
||
55 | |||
56 | //paragrafo em branco |
||
57 | doc.add(new Phrase(" ")); |
||
58 | |||
59 | //fonts |
||
60 | //primeira linha para o caracteres especiais |
||
61 | // BaseFont specialCharacter = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); |
||
62 | 1.5.0/docs/api/java/awt/Font.html">Font fontHeader = new 1.5.0/docs/api/java/awt/Font.html">Font(1.5.0/docs/api/java/awt/Font.html">Font.FontFamily.TIMES_ROMAN,14,1.5.0/docs/api/java/awt/Font.html">Font.BOLD); |
||
63 | 1.5.0/docs/api/java/awt/Font.html">Font fontBold = new 1.5.0/docs/api/java/awt/Font.html">Font(1.5.0/docs/api/java/awt/Font.html">Font.FontFamily.TIMES_ROMAN,10,1.5.0/docs/api/java/awt/Font.html">Font.BOLD); |
||
64 | 1.5.0/docs/api/java/awt/Font.html">Font fontNormal = new 1.5.0/docs/api/java/awt/Font.html">Font(1.5.0/docs/api/java/awt/Font.html">Font.FontFamily.TIMES_ROMAN,10,1.5.0/docs/api/java/awt/Font.html">Font.NORMAL); |
||
65 | 1.5.0/docs/api/java/awt/Font.html">Font fontTextBold = new 1.5.0/docs/api/java/awt/Font.html">Font(1.5.0/docs/api/java/awt/Font.html">Font.FontFamily.TIMES_ROMAN,12,1.5.0/docs/api/java/awt/Font.html">Font.BOLD); |
||
66 | 1.5.0/docs/api/java/awt/Font.html">Font fontTextNormal = new 1.5.0/docs/api/java/awt/Font.html">Font(1.5.0/docs/api/java/awt/Font.html">Font.FontFamily.TIMES_ROMAN,12,1.5.0/docs/api/java/awt/Font.html">Font.NORMAL); |
||
67 | |||
68 | |||
1599 | jmachado | 69 | //cabe�alho |
808 | jmachado | 70 | //unidade curricular |
71 | Paragraph courseUnit = new Paragraph(assessment.getCourseUnit().getName(),fontHeader); |
||
72 | courseUnit.setAlignment(5+0%2Fdocs%2Fapi+Element">Element.ALIGN_CENTER); |
||
73 | doc.add(courseUnit); |
||
74 | |||
1599 | jmachado | 75 | //primeira linha cabe�alho |
808 | jmachado | 76 | 1.5.0/docs/api/java/lang/String.html">String evaluationTime = ""; |
77 | if(assessment.getEvaluationTime().equals(Globals.ASSESSMENT_EVALUATION_TIME_CONTINUOUS)) |
||
1599 | jmachado | 78 | evaluationTime="Avalia��o Cont�nua"; |
808 | jmachado | 79 | if(assessment.getEvaluationTime().equals(Globals.ASSESSMENT_EVALUATION_TIME_FIRSTEXAM)) |
80 | evaluationTime="Exame Normal"; |
||
81 | if(assessment.getEvaluationTime().equals(Globals.ASSESSMENT_EVALUATION_TIME_SECONDEXAM)) |
||
82 | evaluationTime="Exame Recurso"; |
||
83 | if(assessment.getEvaluationTime().equals(Globals.ASSESSMENT_EVALUATION_TIME_THIRDEXAM)) |
||
84 | evaluationTime="Exame Especial"; |
||
85 | |||
86 | 1.5.0/docs/api/java/lang/String.html">String yearText = " - Ano lectivo"; |
||
87 | 1.5.0/docs/api/java/lang/String.html">String year = " - "+assessment.getYear(); |
||
88 | 1.5.0/docs/api/java/lang/String.html">String course = " - "+assessment.getCourseUnit().getCourseName(); |
||
89 | Paragraph firstLine = new Paragraph(); |
||
90 | firstLine.add(new Chunk(evaluationTime,fontBold)); |
||
91 | firstLine.add(new Chunk(yearText,fontNormal)); |
||
92 | firstLine.add(new Chunk(year,fontNormal)); |
||
93 | firstLine.add(new Chunk(course,fontNormal)); |
||
94 | firstLine.setAlignment(5+0%2Fdocs%2Fapi+Element">Element.ALIGN_CENTER); |
||
95 | doc.add(firstLine); |
||
96 | |||
1599 | jmachado | 97 | //segunda linha cabe�alho |
808 | jmachado | 98 | 1.5.0/docs/api/java/lang/String.html">String dateText = "Data:"; |
99 | 1.5.0/docs/api/java/lang/String.html">String date = " "+ DatesUtils.getStringFromDate(assessment.getStartDate()); |
||
1599 | jmachado | 100 | 1.5.0/docs/api/java/lang/String.html">String timeText = " - Dura��o:"; |
808 | jmachado | 101 | 1.5.0/docs/api/java/lang/String.html">String time = " "+1.5.0/docs/api/java/lang/String.html">String.valueOf(assessment.getTime().getHours())+":"+1.5.0/docs/api/java/lang/String.html">String.valueOf(assessment.getTime().getMinutes()); |
102 | 1.5.0/docs/api/java/lang/String.html">String ownerText = " - Docente:"; |
||
103 | 1.5.0/docs/api/java/lang/String.html">String owner = " "+assessment.getOwner().getName(); |
||
104 | Paragraph secondLine = new Paragraph(); |
||
105 | secondLine.add(new Chunk(dateText,fontBold)); |
||
106 | secondLine.add(new Chunk(date,fontNormal)); |
||
107 | secondLine.add(new Chunk(timeText,fontBold)); |
||
108 | secondLine.add(new Chunk(time,fontNormal)); |
||
109 | secondLine.add(new Chunk(ownerText,fontBold)); |
||
110 | secondLine.add(new Chunk(owner,fontNormal)); |
||
111 | secondLine.setAlignment(5+0%2Fdocs%2Fapi+Element">Element.ALIGN_CENTER); |
||
112 | doc.add(secondLine); |
||
113 | |||
114 | //paragrafo em branco |
||
115 | //doc.add(new Paragraph("Barra pah",fontNormal)); |
||
116 | doc.add(Chunk.NEWLINE); |
||
117 | //Barra horizontal |
||
118 | LineSeparator objectName = new LineSeparator(); |
||
119 | doc.add(objectName); |
||
120 | doc.add(Chunk.NEWLINE); |
||
121 | |||
1599 | jmachado | 122 | //quest�es |
808 | jmachado | 123 | int numberQ=0; |
124 | for(AssessmentQuestion question : assessment.getQuestions()) |
||
125 | { |
||
126 | numberQ++; |
||
127 | 1.5.0/docs/api/java/lang/String.html">String numberQuotation = 1.5.0/docs/api/java/lang/String.html">String.valueOf(numberQ) + ". ("+1.5.0/docs/api/java/lang/String.html">String.valueOf(question.getQuotation())+") "; |
||
128 | 1.5.0/docs/api/java/lang/String.html">String questionText = question.getTextpt(); |
||
129 | Paragraph questionP = new Paragraph(); |
||
130 | questionP.add(new Chunk(numberQuotation,fontTextBold)); |
||
131 | questionP.add(new Chunk(questionText,fontTextNormal)); |
||
132 | questionP.setAlignment(5+0%2Fdocs%2Fapi+Element">Element.ALIGN_JUSTIFIED); |
||
133 | doc.add(questionP); |
||
134 | if(question.getImage()!=null) |
||
135 | { |
||
136 | 1.5.0/docs/api/java/awt/Image.html">Image image = 1.5.0/docs/api/java/awt/Image.html">Image.getInstance(Globals.SITE_URL+"/imageStream/"+question.getImage().getId()); |
||
137 | image.setAlignment(5+0%2Fdocs%2Fapi+Element">Element.ALIGN_LEFT); |
||
138 | doc.add(image); |
||
139 | } |
||
140 | if(question.getType().equals(Globals.ASSESSMENT_QUESTION_TYPE_RADIO) || question.getType().equals(Globals.ASSESSMENT_QUESTION_TYPE_CHECK)) |
||
141 | { |
||
142 | for(AssessmentQuestionItem item : question.getQuestionItems()) |
||
143 | { |
||
144 | for(AssessmentQuestionPossibleAnswer pA : item.getPossibleAnswers()) |
||
145 | { |
||
146 | 1.5.0/docs/api/java/awt/Image.html">Image imagePa=null; |
||
147 | if(question.getType().equals(Globals.ASSESSMENT_QUESTION_TYPE_RADIO)) |
||
148 | imagePa = 1.5.0/docs/api/java/awt/Image.html">Image.getInstance(Globals.SITE_URL+"/imgs/radiobox.png"); |
||
149 | else |
||
150 | imagePa = 1.5.0/docs/api/java/awt/Image.html">Image.getInstance(Globals.SITE_URL+"/imgs/checkbox.png"); |
||
151 | imagePa.setAlignment(5+0%2Fdocs%2Fapi+Element">Element.PARAGRAPH); |
||
152 | Paragraph pAP = new Paragraph(); |
||
153 | pAP.add(new Chunk(imagePa, -1.00f, -2.00f)); |
||
154 | pAP.add(new Chunk(" "+pA.getTextpt(),fontTextNormal)); |
||
155 | pAP.setAlignment(5+0%2Fdocs%2Fapi+Element">Element.ALIGN_JUSTIFIED); |
||
156 | doc.add(pAP); |
||
157 | } |
||
158 | } |
||
159 | } |
||
160 | |||
161 | if(question.getType().equals(Globals.ASSESSMENT_QUESTION_TYPE_MATRIX)) |
||
162 | { |
||
163 | PdfPTable table = null; |
||
164 | int numPossibles=0; |
||
165 | //construir tabela |
||
166 | //para saber o numero de respostas possiveis |
||
167 | for(AssessmentQuestionItem itemTam : question.getQuestionItems()) |
||
168 | { |
||
169 | numPossibles = itemTam.getPossibleAnswers().size()+1; |
||
170 | table = new PdfPTable(numPossibles); |
||
171 | PdfPCell colunaVazia = new PdfPCell(new Paragraph()); |
||
172 | colunaVazia.setBorder(0); |
||
173 | table.addCell(colunaVazia); |
||
174 | for(AssessmentQuestionPossibleAnswer possibleTam : itemTam.getPossibleAnswers()) |
||
175 | { |
||
176 | PdfPCell possible = new PdfPCell(new Paragraph(possibleTam.getTextpt(),fontTextNormal)); |
||
177 | possible.setBorder(0); |
||
178 | table.addCell(possible); |
||
179 | } |
||
180 | break; |
||
181 | } |
||
182 | |||
183 | for(AssessmentQuestionItem item : question.getQuestionItems()) |
||
184 | { |
||
185 | PdfPCell item1 = new PdfPCell(new Paragraph(item.getTextpt(),fontTextNormal)); |
||
186 | item1.setBorder(0); |
||
187 | table.addCell(item1); |
||
188 | for(AssessmentQuestionPossibleAnswer pA : item.getPossibleAnswers()) |
||
189 | { |
||
190 | 1.5.0/docs/api/java/awt/Image.html">Image imagePa= 1.5.0/docs/api/java/awt/Image.html">Image.getInstance(Globals.SITE_URL+"/imgs/radiobox.png"); |
||
191 | PdfPCell imageCell = new PdfPCell(imagePa); |
||
192 | imageCell.setBorder(0); |
||
193 | table.addCell(imageCell); |
||
194 | } |
||
195 | } |
||
196 | float splitWidth = 1.0f / (float)numPossibles; |
||
197 | float[] tams = new float[numPossibles]; |
||
198 | for(int i=0;i<numPossibles;i++) |
||
199 | { |
||
200 | tams[i] = splitWidth; |
||
201 | } |
||
202 | table.setWidths(tams); |
||
203 | table.setWidthPercentage(100.0f); |
||
204 | doc.add(table); |
||
205 | } |
||
206 | doc.add(Chunk.NEWLINE); |
||
207 | } |
||
208 | |||
209 | } finally { |
||
210 | if (doc != null) { |
||
211 | //fechamento do documento |
||
212 | doc.close(); |
||
213 | } |
||
214 | if (os != null) { |
||
1599 | jmachado | 215 | //fechamento da stream de sa�da |
808 | jmachado | 216 | os.close(); |
217 | } |
||
218 | } |
||
219 | |||
220 | //repositoryStream |
||
221 | 1.5.0/docs/api/java/lang/String.html">String fileName = Globals.TMP_DIR+"Enunciado"+assessment.getTitle()+".pdf"; |
||
222 | 1.5.0/docs/api/java/io/File.html">File file = new 1.5.0/docs/api/java/io/File.html">File(fileName); |
||
223 | 1.5.0/docs/api/java/lang/String.html">String extension = FilesUtils.getExtension(fileName); |
||
224 | 1.5.0/docs/api/java/lang/String.html">String description = "assessment.file "+assessment.getCourseUnit().getName(); |
||
225 | 1.5.0/docs/api/java/io/FileInputStream.html">FileInputStream inputStream = new 1.5.0/docs/api/java/io/FileInputStream.html">FileInputStream(file); |
||
226 | 1.5.0/docs/api/java/lang/String.html">String identifier = assessment.getIdentifier(); |
||
227 | |||
228 | if(identifier==null) |
||
1703 | jmachado | 229 | identifier = repositoryService.storeRepositoryFile(inputStream,"application/pdf",extension,(int)file.length(),file.getName(),description, ResourceAccessControlEnum.publicDomain, null, userSession); |
808 | jmachado | 230 | else |
231 | repositoryService.updateRepositoryFile(identifier,inputStream, "application/pdf",extension,(int)file.length(),file.getName(),description, ResourceAccessControlEnum.publicDomain); |
||
232 | |||
233 | assessment.setIdentifier(identifier); |
||
234 | |||
235 | // return new AssessmentView(assessment); |
||
236 | } |
||
237 | |||
238 | public void generateAssessmentResponsePdf(long assessmentResponseId,long assessmentId,UserSession userSession) throws 1.5.0/docs/api/java/io/IOException.html">IOException, DocumentException { |
||
239 | AssessmentResponse assessmentResponse = DaoFactory.getAssessmentResponseDaoImpl().get(assessmentResponseId); |
||
240 | Assessment assessment = DaoFactory.getAssessmentDaoImpl().get(assessmentId); |
||
241 | //////////////////////////////////////////////// |
||
242 | 5+0%2Fdocs%2Fapi+Document">Document doc = null; |
||
243 | 5+0%2Fdocs%2Fapi+OutputStream">OutputStream os = null; |
||
244 | |||
245 | try { |
||
246 | //cria o documento tamanho A4, margens de 2,54cm |
||
247 | doc = new 5+0%2Fdocs%2Fapi+Document">Document(PageSize.A4, 72, 72, 72, 72); |
||
1599 | jmachado | 248 | //cria a stream de sa�da |
808 | jmachado | 249 | os = new 1.5.0/docs/api/java/io/FileOutputStream.html">FileOutputStream(Globals.TMP_DIR+"Resposta"+assessment.getTitle()+1.5.0/docs/api/java/lang/String.html">String.valueOf(assessmentResponse.getId())+".pdf"); |
1599 | jmachado | 250 | //associa a stream de sa�da ao |
808 | jmachado | 251 | PdfWriter.getInstance(doc, os); |
252 | //abre o documento |
||
253 | doc.open(); |
||
1599 | jmachado | 254 | //imagem do cabe�alho |
808 | jmachado | 255 | 1.5.0/docs/api/java/awt/Image.html">Image img = 1.5.0/docs/api/java/awt/Image.html">Image.getInstance(Globals.SITE_URL+"/imgs/logoestg.gif"); |
256 | img.setAlignment(5+0%2Fdocs%2Fapi+Element">Element.ALIGN_LEFT); |
||
257 | doc.add(img); |
||
258 | |||
259 | //paragrafo em branco |
||
260 | doc.add(new Phrase(" ")); |
||
261 | |||
262 | //fonts |
||
263 | //primeira linha para o caracteres especiais |
||
264 | // BaseFont specialCharacter = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); |
||
265 | 1.5.0/docs/api/java/awt/Font.html">Font fontHeader = new 1.5.0/docs/api/java/awt/Font.html">Font(1.5.0/docs/api/java/awt/Font.html">Font.FontFamily.TIMES_ROMAN,14,1.5.0/docs/api/java/awt/Font.html">Font.BOLD); |
||
266 | 1.5.0/docs/api/java/awt/Font.html">Font fontBold = new 1.5.0/docs/api/java/awt/Font.html">Font(1.5.0/docs/api/java/awt/Font.html">Font.FontFamily.TIMES_ROMAN,10,1.5.0/docs/api/java/awt/Font.html">Font.BOLD); |
||
267 | 1.5.0/docs/api/java/awt/Font.html">Font fontNormal = new 1.5.0/docs/api/java/awt/Font.html">Font(1.5.0/docs/api/java/awt/Font.html">Font.FontFamily.TIMES_ROMAN,10,1.5.0/docs/api/java/awt/Font.html">Font.NORMAL); |
||
268 | 1.5.0/docs/api/java/awt/Font.html">Font fontTextBold = new 1.5.0/docs/api/java/awt/Font.html">Font(1.5.0/docs/api/java/awt/Font.html">Font.FontFamily.TIMES_ROMAN,12,1.5.0/docs/api/java/awt/Font.html">Font.BOLD); |
||
269 | 1.5.0/docs/api/java/awt/Font.html">Font fontTextNormal = new 1.5.0/docs/api/java/awt/Font.html">Font(1.5.0/docs/api/java/awt/Font.html">Font.FontFamily.TIMES_ROMAN,12,1.5.0/docs/api/java/awt/Font.html">Font.NORMAL); |
||
270 | 1.5.0/docs/api/java/awt/Font.html">Font fontTextEvaluate = new 1.5.0/docs/api/java/awt/Font.html">Font(1.5.0/docs/api/java/awt/Font.html">Font.FontFamily.TIMES_ROMAN,12,1.5.0/docs/api/java/awt/Font.html">Font.NORMAL,BaseColor.RED); |
||
271 | |||
272 | |||
1599 | jmachado | 273 | //cabe�alho |
808 | jmachado | 274 | //unidade curricular |
275 | Paragraph courseUnit = new Paragraph(assessment.getCourseUnit().getName(),fontHeader); |
||
276 | courseUnit.setAlignment(5+0%2Fdocs%2Fapi+Element">Element.ALIGN_CENTER); |
||
277 | doc.add(courseUnit); |
||
278 | |||
1599 | jmachado | 279 | //primeira linha cabe�alho |
808 | jmachado | 280 | 1.5.0/docs/api/java/lang/String.html">String evaluationTime = ""; |
281 | if(assessment.getEvaluationTime().equals(Globals.ASSESSMENT_EVALUATION_TIME_CONTINUOUS)) |
||
1599 | jmachado | 282 | evaluationTime="Avalia��o Cont�nua"; |
808 | jmachado | 283 | if(assessment.getEvaluationTime().equals(Globals.ASSESSMENT_EVALUATION_TIME_FIRSTEXAM)) |
284 | evaluationTime="Exame Normal"; |
||
285 | if(assessment.getEvaluationTime().equals(Globals.ASSESSMENT_EVALUATION_TIME_SECONDEXAM)) |
||
286 | evaluationTime="Exame Recurso"; |
||
287 | if(assessment.getEvaluationTime().equals(Globals.ASSESSMENT_EVALUATION_TIME_THIRDEXAM)) |
||
288 | evaluationTime="Exame Especial"; |
||
289 | |||
290 | 1.5.0/docs/api/java/lang/String.html">String yearText = " - Ano lectivo"; |
||
291 | 1.5.0/docs/api/java/lang/String.html">String year = " - "+assessment.getYear(); |
||
292 | 1.5.0/docs/api/java/lang/String.html">String course = " - "+assessment.getCourseUnit().getCourseName(); |
||
293 | Paragraph firstLine = new Paragraph(); |
||
294 | firstLine.add(new Chunk(evaluationTime,fontBold)); |
||
295 | firstLine.add(new Chunk(yearText,fontNormal)); |
||
296 | firstLine.add(new Chunk(year,fontNormal)); |
||
297 | firstLine.add(new Chunk(course,fontNormal)); |
||
298 | firstLine.setAlignment(5+0%2Fdocs%2Fapi+Element">Element.ALIGN_CENTER); |
||
299 | doc.add(firstLine); |
||
300 | |||
1599 | jmachado | 301 | //segunda linha cabe�alho |
808 | jmachado | 302 | 1.5.0/docs/api/java/lang/String.html">String dateText = "Data:"; |
303 | 1.5.0/docs/api/java/lang/String.html">String date = " "+ DatesUtils.getStringFromDate(assessment.getStartDate()); |
||
1599 | jmachado | 304 | 1.5.0/docs/api/java/lang/String.html">String timeText = " - Dura��o:"; |
808 | jmachado | 305 | 1.5.0/docs/api/java/lang/String.html">String time = " "+1.5.0/docs/api/java/lang/String.html">String.valueOf(assessment.getTime().getHours())+":"+1.5.0/docs/api/java/lang/String.html">String.valueOf(assessment.getTime().getMinutes()); |
306 | 1.5.0/docs/api/java/lang/String.html">String ownerText = " - Docente:"; |
||
307 | 1.5.0/docs/api/java/lang/String.html">String owner = " "+assessment.getOwner().getName(); |
||
308 | 1.5.0/docs/api/java/lang/String.html">String quotationText = " - Nota:"; |
||
309 | 1.5.0/docs/api/java/lang/String.html">String quotation = " "+1.5.0/docs/api/java/lang/String.html">String.valueOf(assessmentResponse.getQuotation()); |
||
310 | Paragraph secondLine = new Paragraph(); |
||
311 | secondLine.add(new Chunk(dateText,fontBold)); |
||
312 | secondLine.add(new Chunk(date,fontNormal)); |
||
313 | secondLine.add(new Chunk(timeText,fontBold)); |
||
314 | secondLine.add(new Chunk(time,fontNormal)); |
||
315 | secondLine.add(new Chunk(ownerText,fontBold)); |
||
316 | secondLine.add(new Chunk(owner,fontNormal)); |
||
317 | if(assessmentResponse.isEvaluated()) |
||
318 | { |
||
319 | secondLine.add(new Chunk(quotationText,fontBold)); |
||
320 | secondLine.add(new Chunk(quotation,fontNormal)); |
||
321 | } |
||
322 | secondLine.setAlignment(5+0%2Fdocs%2Fapi+Element">Element.ALIGN_CENTER); |
||
323 | doc.add(secondLine); |
||
324 | |||
325 | //paragrafo em branco |
||
326 | //doc.add(new Paragraph("Barra pah",fontNormal)); |
||
327 | doc.add(Chunk.NEWLINE); |
||
328 | //Barra horizontal |
||
329 | LineSeparator objectName = new LineSeparator(); |
||
330 | doc.add(objectName); |
||
331 | doc.add(Chunk.NEWLINE); |
||
332 | |||
1599 | jmachado | 333 | //quest�es |
808 | jmachado | 334 | int numberQ=0; |
335 | for(AssessmentQuestion question : assessment.getQuestions()) |
||
336 | { |
||
337 | numberQ++; |
||
338 | 1.5.0/docs/api/java/lang/String.html">String numberQuotation = 1.5.0/docs/api/java/lang/String.html">String.valueOf(numberQ) + ". ("+1.5.0/docs/api/java/lang/String.html">String.valueOf(question.getQuotation())+") "; |
||
339 | 1.5.0/docs/api/java/lang/String.html">String questionText = question.getTextpt(); |
||
340 | Paragraph questionP = new Paragraph(); |
||
341 | questionP.add(new Chunk(numberQuotation,fontTextBold)); |
||
342 | questionP.add(new Chunk(questionText,fontTextNormal)); |
||
343 | questionP.setAlignment(5+0%2Fdocs%2Fapi+Element">Element.ALIGN_JUSTIFIED); |
||
344 | doc.add(questionP); |
||
345 | if(question.getImage()!=null) |
||
346 | { |
||
347 | 1.5.0/docs/api/java/awt/Image.html">Image image = 1.5.0/docs/api/java/awt/Image.html">Image.getInstance(Globals.SITE_URL+"/imageStream/"+question.getImage().getId()); |
||
348 | image.setAlignment(5+0%2Fdocs%2Fapi+Element">Element.ALIGN_LEFT); |
||
349 | doc.add(image); |
||
350 | } |
||
351 | if(question.getType().equals(Globals.ASSESSMENT_QUESTION_TYPE_TEXT)) |
||
352 | { |
||
353 | for(AssessmentQuestionAnswer answer : assessmentResponse.getAnswers()) |
||
354 | { |
||
355 | if(answer.getPossibleAnswer().getQuestionItem().getQuestion()== question) |
||
356 | { |
||
357 | Paragraph answerP = new Paragraph(); |
||
358 | answerP.add(new Chunk("Resposta: ",fontTextBold)); |
||
359 | answerP.add(new Chunk(answer.getTextAnswer(), fontTextNormal)); |
||
360 | |||
361 | if(assessmentResponse.isEvaluated()) |
||
1599 | jmachado | 362 | { //verifica se est� correcta |
808 | jmachado | 363 | if(question.getQuotation()==answer.getQuotation()) |
364 | { |
||
365 | answerP.add(new Chunk(" Correcta",fontTextEvaluate)); |
||
366 | if(answer.getNote() != null && answer.getNote().trim().length() !=0) |
||
367 | answerP.add(new Chunk(" Obs:"+answer.getNote(),fontTextEvaluate)); |
||
368 | } |
||
369 | else if(answer.getQuotation()==0) |
||
370 | { |
||
371 | answerP.add(new Chunk(" Errada",fontTextEvaluate)); |
||
372 | if(answer.getNote() != null && answer.getNote().trim().length() !=0) |
||
373 | answerP.add(new Chunk(" Obs:"+answer.getNote(),fontTextEvaluate)); |
||
374 | } |
||
375 | else |
||
376 | { |
||
377 | // double quotationA = (answer.getQuotation()*100)/question.getQuotation(); |
||
378 | double quotationA = answer.getQuotation(); |
||
379 | answerP.add(new Chunk(" Incompleta("+quotationA+")",fontTextEvaluate)); |
||
380 | if(answer.getNote() != null && answer.getNote().trim().length() !=0) |
||
381 | answerP.add(new Chunk(" Obs:"+answer.getNote(),fontTextEvaluate)); |
||
382 | } |
||
383 | } |
||
384 | doc.add(answerP); |
||
385 | break; |
||
386 | } |
||
387 | } |
||
388 | } |
||
389 | if(question.getType().equals(Globals.ASSESSMENT_QUESTION_TYPE_PRACTICAL)) |
||
390 | { |
||
391 | for(AssessmentQuestionAnswer answer : assessmentResponse.getAnswers()) |
||
392 | { |
||
393 | if(answer.getPossibleAnswer().getQuestionItem().getQuestion()== question) |
||
394 | { |
||
395 | if(answer.getIdentifier()!= null && answer.getIdentifier().trim().length() !=0) |
||
396 | { |
||
397 | Paragraph answerP = new Paragraph("Foi entregue um ficheiro", fontTextBold); |
||
398 | if(assessmentResponse.isEvaluated()) |
||
1599 | jmachado | 399 | { //verifica se est� correcta |
808 | jmachado | 400 | if(question.getQuotation()==answer.getQuotation()) |
401 | { |
||
402 | answerP.add(new Chunk(" Correcta",fontTextEvaluate)); |
||
403 | if(answer.getNote() != null && answer.getNote().trim().length() !=0) |
||
404 | answerP.add(new Chunk(" Obs:"+answer.getNote(),fontTextEvaluate)); |
||
405 | } |
||
406 | else if(answer.getQuotation()==0) |
||
407 | { |
||
408 | answerP.add(new Chunk(" Errada",fontTextEvaluate)); |
||
409 | if(answer.getNote() != null && answer.getNote().trim().length() !=0) |
||
410 | answerP.add(new Chunk(" Obs:"+answer.getNote(),fontTextEvaluate)); |
||
411 | } |
||
412 | else |
||
413 | { |
||
414 | // double quotationA = (answer.getQuotation()*100)/question.getQuotation(); |
||
415 | double quotationA = answer.getQuotation(); |
||
416 | answerP.add(new Chunk(" Incompleta("+quotationA+")",fontTextEvaluate)); |
||
417 | if(answer.getNote() != null && answer.getNote().trim().length() !=0) |
||
418 | answerP.add(new Chunk(" Obs:"+answer.getNote(),fontTextEvaluate)); |
||
419 | } |
||
420 | } |
||
421 | doc.add(answerP); |
||
422 | break; |
||
423 | } |
||
424 | } |
||
425 | } |
||
426 | } |
||
427 | |||
428 | if(question.getType().equals(Globals.ASSESSMENT_QUESTION_TYPE_RADIO) || question.getType().equals(Globals.ASSESSMENT_QUESTION_TYPE_CHECK)) |
||
429 | { |
||
430 | for(AssessmentQuestionItem item : question.getQuestionItems()) |
||
431 | { |
||
432 | for(AssessmentQuestionPossibleAnswer pA : item.getPossibleAnswers()) |
||
433 | { |
||
434 | 1.5.0/docs/api/java/lang/String.html">String evaluated=null; |
||
435 | 1.5.0/docs/api/java/awt/Image.html">Image imagePa=null; |
||
436 | if(question.getType().equals(Globals.ASSESSMENT_QUESTION_TYPE_RADIO)) |
||
437 | { |
||
438 | boolean isRadioAnswered = false; |
||
439 | for(AssessmentQuestionAnswer answer : assessmentResponse.getAnswers()) |
||
440 | { |
||
441 | if(answer.getPossibleAnswer() == pA) |
||
442 | { |
||
443 | imagePa = 1.5.0/docs/api/java/awt/Image.html">Image.getInstance(Globals.SITE_URL+"/imgs/radioboxselected.png"); |
||
444 | isRadioAnswered = true; |
||
445 | if(assessmentResponse.isEvaluated()) |
||
1599 | jmachado | 446 | { //verifica se est� correcta |
808 | jmachado | 447 | if(pA.getQuotation()>0) |
448 | { |
||
449 | evaluated = " Correcta"; |
||
450 | } |
||
451 | else if(pA.getQuotation()==0) |
||
452 | { |
||
453 | evaluated = " Errada"; |
||
454 | } |
||
455 | } |
||
456 | break; |
||
457 | } |
||
458 | } |
||
459 | if(!isRadioAnswered) |
||
460 | imagePa = 1.5.0/docs/api/java/awt/Image.html">Image.getInstance(Globals.SITE_URL+"/imgs/radiobox.png"); |
||
461 | } |
||
462 | |||
463 | else |
||
464 | { |
||
465 | boolean isCheckAnswered = false; |
||
466 | for(AssessmentQuestionAnswer answer : assessmentResponse.getAnswers()) |
||
467 | { |
||
468 | if(answer.getPossibleAnswer() == pA) |
||
469 | { |
||
470 | imagePa = 1.5.0/docs/api/java/awt/Image.html">Image.getInstance(Globals.SITE_URL+"/imgs/checkboxselected.jpg"); |
||
471 | isCheckAnswered = true; |
||
472 | if(assessmentResponse.isEvaluated()) |
||
1599 | jmachado | 473 | { //verifica se est� correcta |
808 | jmachado | 474 | if(pA.getQuotation()>0) |
475 | { |
||
476 | evaluated = " Correcta"; |
||
477 | } |
||
478 | else if(pA.getQuotation()==0) |
||
479 | { |
||
480 | evaluated = " Errada"; |
||
481 | } |
||
482 | } |
||
483 | break; |
||
484 | } |
||
485 | } |
||
486 | if(!isCheckAnswered) |
||
487 | imagePa = 1.5.0/docs/api/java/awt/Image.html">Image.getInstance(Globals.SITE_URL+"/imgs/checkbox.png"); |
||
488 | } |
||
489 | |||
490 | imagePa.setAlignment(5+0%2Fdocs%2Fapi+Element">Element.PARAGRAPH); |
||
491 | Paragraph pAP = new Paragraph(); |
||
492 | pAP.add(new Chunk(imagePa, -1.00f, -2.00f)); |
||
493 | pAP.add(new Chunk(" "+pA.getTextpt(),fontTextNormal)); |
||
494 | if(evaluated!=null) |
||
495 | { |
||
496 | pAP.add(new Chunk(evaluated,fontTextEvaluate)); |
||
497 | evaluated=null; |
||
498 | } |
||
499 | pAP.setAlignment(5+0%2Fdocs%2Fapi+Element">Element.ALIGN_JUSTIFIED); |
||
500 | doc.add(pAP); |
||
501 | } |
||
502 | } |
||
503 | } |
||
504 | |||
505 | if(question.getType().equals(Globals.ASSESSMENT_QUESTION_TYPE_MATRIX)) |
||
506 | { |
||
507 | PdfPTable table = null; |
||
508 | int numPossibles=0; |
||
509 | //construir tabela |
||
510 | //para saber o numero de respostas possiveis |
||
511 | for(AssessmentQuestionItem itemTam : question.getQuestionItems()) |
||
512 | { |
||
1599 | jmachado | 513 | numPossibles = itemTam.getPossibleAnswers().size()+2; //mais um para items e para correcções |
808 | jmachado | 514 | table = new PdfPTable(numPossibles); |
515 | PdfPCell colunaVazia = new PdfPCell(new Paragraph()); |
||
516 | colunaVazia.setBorder(0); |
||
517 | table.addCell(colunaVazia); |
||
518 | for(AssessmentQuestionPossibleAnswer possibleTam : itemTam.getPossibleAnswers()) |
||
519 | { |
||
520 | PdfPCell possible = new PdfPCell(new Paragraph(possibleTam.getTextpt(),fontTextNormal)); |
||
521 | possible.setBorder(0); |
||
522 | table.addCell(possible); |
||
523 | } |
||
524 | table.addCell(colunaVazia); //para fechar a primeira linha da tabela |
||
525 | break; |
||
526 | } |
||
527 | |||
528 | for(AssessmentQuestionItem item : question.getQuestionItems()) |
||
529 | { |
||
530 | 1.5.0/docs/api/java/lang/String.html">String evaluated=null; |
||
531 | PdfPCell item1 = new PdfPCell(new Paragraph(item.getTextpt(),fontTextNormal)); |
||
532 | item1.setBorder(0); |
||
533 | table.addCell(item1); |
||
534 | 1.5.0/docs/api/java/awt/Image.html">Image imagePa=null; |
||
535 | for(AssessmentQuestionPossibleAnswer pA : item.getPossibleAnswers()) |
||
536 | { |
||
537 | boolean isRadioAnswered = false; |
||
538 | for(AssessmentQuestionAnswer answer : assessmentResponse.getAnswers()) |
||
539 | { |
||
540 | if(answer.getPossibleAnswer() == pA) |
||
541 | { |
||
542 | imagePa = 1.5.0/docs/api/java/awt/Image.html">Image.getInstance(Globals.SITE_URL+"/imgs/radioboxselected.png"); |
||
543 | isRadioAnswered = true; |
||
544 | if(assessmentResponse.isEvaluated()) |
||
1599 | jmachado | 545 | { //verifica se esta correcta |
808 | jmachado | 546 | if(pA.getQuotation()>0) |
547 | { |
||
548 | evaluated = " Correcta"; |
||
549 | } |
||
550 | else if(pA.getQuotation()==0) |
||
551 | { |
||
552 | evaluated = " Errada"; |
||
553 | } |
||
554 | } |
||
555 | break; |
||
556 | } |
||
557 | } |
||
558 | |||
559 | if(!isRadioAnswered) |
||
560 | imagePa= 1.5.0/docs/api/java/awt/Image.html">Image.getInstance(Globals.SITE_URL+"/imgs/radiobox.png"); |
||
561 | |||
562 | PdfPCell imageCell = new PdfPCell(imagePa); |
||
563 | imageCell.setBorder(0); |
||
564 | table.addCell(imageCell); |
||
565 | } |
||
566 | if(evaluated != null) |
||
567 | { |
||
568 | PdfPCell evaluatedCell = new PdfPCell(new Paragraph(evaluated,fontTextEvaluate)); |
||
569 | evaluatedCell.setBorder(0); |
||
570 | table.addCell(evaluatedCell); |
||
571 | evaluated=null; |
||
572 | } |
||
573 | else |
||
574 | { |
||
575 | PdfPCell evaluatedCell = new PdfPCell(new Paragraph()); |
||
576 | evaluatedCell.setBorder(0); |
||
577 | table.addCell(evaluatedCell); |
||
578 | } |
||
579 | } |
||
580 | float splitWidth = 1.0f / (float)numPossibles; |
||
581 | float[] tams = new float[numPossibles]; |
||
582 | for(int i=0;i<numPossibles;i++) |
||
583 | { |
||
584 | tams[i] = splitWidth; |
||
585 | } |
||
586 | table.setWidths(tams); |
||
587 | table.setWidthPercentage(100.0f); |
||
588 | doc.add(table); |
||
589 | } |
||
590 | doc.add(Chunk.NEWLINE); |
||
591 | } |
||
592 | |||
593 | } finally { |
||
594 | if (doc != null) { |
||
595 | //fechamento do documento |
||
596 | doc.close(); |
||
597 | } |
||
598 | if (os != null) { |
||
1599 | jmachado | 599 | //fechamento da stream de saida |
808 | jmachado | 600 | os.close(); |
601 | } |
||
602 | } |
||
603 | |||
604 | //repositoryStream |
||
605 | 1.5.0/docs/api/java/lang/String.html">String fileName = Globals.TMP_DIR+"Resposta"+assessment.getTitle()+1.5.0/docs/api/java/lang/String.html">String.valueOf(assessmentResponse.getId())+".pdf"; |
||
606 | 1.5.0/docs/api/java/io/File.html">File file = new 1.5.0/docs/api/java/io/File.html">File(fileName); |
||
607 | 1.5.0/docs/api/java/lang/String.html">String extension = FilesUtils.getExtension(fileName); |
||
608 | 1.5.0/docs/api/java/lang/String.html">String description = "assessmentResponse.file "+assessment.getCourseUnit().getName()+assessmentResponse.getOwner().getName(); |
||
609 | 1.5.0/docs/api/java/io/FileInputStream.html">FileInputStream inputStream = new 1.5.0/docs/api/java/io/FileInputStream.html">FileInputStream(file); |
||
610 | 1.5.0/docs/api/java/lang/String.html">String identifierResponse = assessmentResponse.getIdentifier(); |
||
611 | |||
612 | if(identifierResponse==null) |
||
1703 | jmachado | 613 | identifierResponse = repositoryService.storeRepositoryFile(inputStream,"application/pdf",extension,(int)file.length(),file.getName(),description, ResourceAccessControlEnum.publicDomain, null, userSession); |
808 | jmachado | 614 | else |
615 | repositoryService.updateRepositoryFile(identifierResponse,inputStream, "application/pdf",extension,(int)file.length(),file.getName(),description, ResourceAccessControlEnum.publicDomain); |
||
616 | |||
617 | assessmentResponse.setIdentifier(identifierResponse); |
||
618 | } |
||
619 | |||
620 | |||
621 | |||
622 | |||
623 | public AssessmentView generateEvaluationsPdf(long assessmentId,UserSession userSession) throws 1.5.0/docs/api/java/io/IOException.html">IOException, DocumentException { |
||
624 | AssessmentImpl assessment = DaoFactory.getAssessmentDaoImpl().get(assessmentId); |
||
625 | List<AssessmentResponse> responses = DaoFactory.getAssessmentResponseDaoImpl().loadResponsesByAssessmentId(assessmentId); |
||
626 | |||
627 | //////////////////////////////////////////////// |
||
628 | 5+0%2Fdocs%2Fapi+Document">Document doc = null; |
||
629 | 5+0%2Fdocs%2Fapi+OutputStream">OutputStream os = null; |
||
630 | |||
631 | try { |
||
632 | //cria o documento tamanho A4, margens de 2,54cm |
||
633 | doc = new 5+0%2Fdocs%2Fapi+Document">Document(PageSize.A4, 72, 72, 72, 72); |
||
1599 | jmachado | 634 | //cria a stream de saida |
808 | jmachado | 635 | os = new 1.5.0/docs/api/java/io/FileOutputStream.html">FileOutputStream(Globals.TMP_DIR+ assessment.getTitle()+".pdf"); |
1599 | jmachado | 636 | //associa a stream de saida ao |
808 | jmachado | 637 | PdfWriter.getInstance(doc, os); |
638 | //abre o documento |
||
639 | doc.open(); |
||
1599 | jmachado | 640 | //imagem do cabecalho |
808 | jmachado | 641 | 1.5.0/docs/api/java/awt/Image.html">Image img = 1.5.0/docs/api/java/awt/Image.html">Image.getInstance(Globals.SITE_URL+"/imgs/logoestg.gif"); |
642 | img.setAlignment(5+0%2Fdocs%2Fapi+Element">Element.ALIGN_LEFT); |
||
643 | doc.add(img); |
||
644 | |||
645 | //Barra horizontal |
||
646 | LineSeparator objectName = new LineSeparator(); |
||
647 | doc.add(objectName); |
||
648 | |||
1599 | jmachado | 649 | //adiciona um paragrafo para dar espaco |
808 | jmachado | 650 | // Paragraph p = new Paragraph(""); |
651 | // Paragraph paragrafo = new Paragraph(); |
||
652 | // paragrafo.setSpacingBefore(10); |
||
653 | // paragrafo.setIndentationLeft(58); |
||
654 | // paragrafo.setSpacingBefore(20); |
||
655 | // paragrafo.setLeading(20); |
||
656 | // paragrafo.add(new Chunk()); |
||
657 | // doc.add(paragrafo); |
||
658 | //doc.add(p); |
||
659 | |||
660 | |||
661 | //doc.add(Chunk.NEWLINE); |
||
1599 | jmachado | 662 | //Informacoes sobre a prova |
808 | jmachado | 663 | |
664 | Phrase anoCurso = new Phrase("\nAno Lectivo: "+1.5.0/docs/api/java/lang/String.html">String.valueOf(assessment.getYear())+ |
||
665 | " / Curso: "+assessment.getCourseUnit().getCourseName()+"\n"); |
||
666 | Phrase courseUnit = new Phrase("Unidade Curricular: "+assessment.getCourseUnit().getName()+ |
||
667 | "\nDocente: "+assessment.getOwner().getName()+"\n"); |
||
668 | doc.add(anoCurso); |
||
669 | doc.add(courseUnit); |
||
670 | |||
671 | doc.add(new Phrase(" ")); |
||
672 | |||
673 | |||
674 | ////tabela |
||
675 | PdfPTable table = new PdfPTable(assessment.getQuestions().size()+3); |
||
676 | 1.5.0/docs/api/java/awt/Font.html">Font fontHeader = new 1.5.0/docs/api/java/awt/Font.html">Font(1.5.0/docs/api/java/awt/Font.html">Font.FontFamily.TIMES_ROMAN,10,1.5.0/docs/api/java/awt/Font.html">Font.BOLD); |
||
1599 | jmachado | 677 | //primeira linha para as cotacoes |
808 | jmachado | 678 | PdfPCell colunaVazia = new PdfPCell(new Paragraph()); |
679 | colunaVazia.setBackgroundColor(new BaseColor(0Xc0, 0Xc0,0Xc0)); |
||
680 | colunaVazia.setColspan(2); |
||
681 | PdfPCell cotacaoMaxima = new PdfPCell(new Paragraph("20",fontHeader)); |
||
682 | cotacaoMaxima.setBackgroundColor(new BaseColor(0Xc0, 0Xc0,0Xc0)); |
||
683 | table.addCell(colunaVazia); |
||
684 | //table.addCell(colunaVazia); |
||
685 | table.addCell(cotacaoMaxima); |
||
686 | |||
687 | for(AssessmentQuestion question : assessment.getQuestions()) |
||
688 | { |
||
689 | PdfPCell coluna = new PdfPCell(new Paragraph(1.5.0/docs/api/java/lang/String.html">String.valueOf(question.getQuotation()),fontHeader)); |
||
690 | coluna.setBackgroundColor(new BaseColor(0Xc0, 0Xc0,0Xc0)); |
||
691 | table.addCell(coluna); |
||
692 | } |
||
693 | |||
694 | //segunda linha |
||
1599 | jmachado | 695 | PdfPCell col1 = new PdfPCell(new Paragraph("N�",fontHeader)); |
808 | jmachado | 696 | col1.setBackgroundColor(new BaseColor(0Xc0, 0Xc0,0Xc0)); |
697 | PdfPCell col2 = new PdfPCell(new Paragraph("Nome",fontHeader)); |
||
698 | col2.setBackgroundColor(new BaseColor(0Xc0, 0Xc0,0Xc0)); |
||
699 | PdfPCell col3 = new PdfPCell(new Paragraph("Nota",fontHeader)); |
||
700 | col3.setBackgroundColor(new BaseColor(0Xc0, 0Xc0,0Xc0)); |
||
701 | table.addCell(col1); |
||
702 | table.addCell(col2); |
||
703 | table.addCell(col3); |
||
704 | int numberQ=0; |
||
705 | for(AssessmentQuestion question : assessment.getQuestions()) |
||
706 | { |
||
707 | numberQ++; |
||
708 | PdfPCell coluna = new PdfPCell(new Paragraph("P"+1.5.0/docs/api/java/lang/String.html">String.valueOf(numberQ),fontHeader)); |
||
709 | coluna.setBackgroundColor(new BaseColor(0Xc0, 0Xc0,0Xc0)); |
||
710 | table.addCell(coluna); |
||
711 | } |
||
712 | |||
713 | 1.5.0/docs/api/java/awt/Font.html">Font fontText = new 1.5.0/docs/api/java/awt/Font.html">Font(1.5.0/docs/api/java/awt/Font.html">Font.FontFamily.TIMES_ROMAN,10,1.5.0/docs/api/java/awt/Font.html">Font.NORMAL); |
||
1599 | jmachado | 714 | //cotacoes das respostas |
808 | jmachado | 715 | for(AssessmentResponse response : responses) |
716 | { |
||
717 | 1.5.0/docs/api/java/lang/String.html">String code=""; |
||
718 | if(response.getOwner() instanceof Student) |
||
719 | { |
||
720 | code = 1.5.0/docs/api/java/lang/String.html">String.valueOf(((Student)response.getOwner()).getSigesCode()); |
||
721 | } |
||
722 | PdfPCell colunaNumero = new PdfPCell(new Paragraph(code,fontText)); |
||
723 | PdfPCell colunaNome = new PdfPCell(new Paragraph(response.getOwner().getName(),fontText)); |
||
724 | PdfPCell colunaNota = new PdfPCell(new Paragraph(1.5.0/docs/api/java/lang/String.html">String.valueOf(response.getQuotation()),fontText)); |
||
725 | table.addCell(colunaNumero); |
||
726 | table.addCell(colunaNome); |
||
727 | table.addCell(colunaNota); |
||
728 | //numero nome e nota adicionados |
||
1599 | jmachado | 729 | //percorrer as questoes |
808 | jmachado | 730 | for(AssessmentQuestion question : assessment.getQuestions()) |
731 | { |
||
732 | 1.5.0/docs/api/java/lang/String.html">String semResposta=" "; |
||
733 | double percentagemF=0; |
||
734 | boolean respondida = false; |
||
735 | for(AssessmentQuestionAnswer answer : response.getAnswers()) |
||
736 | { |
||
737 | if(answer.getPossibleAnswer().getQuestionItem().getQuestion()==question) |
||
738 | { |
||
739 | // percentagemF += (answer.getQuotation()*100) / question.getQuotation(); |
||
740 | percentagemF += answer.getQuotation(); |
||
741 | respondida=true; |
||
742 | } |
||
743 | } |
||
744 | if(respondida){ |
||
745 | // int percentagemI = (int)percentagemF; |
||
746 | // PdfPCell colunaPercentagem = new PdfPCell(new Paragraph(String.valueOf(percentagemI)+"%",fontText)); |
||
747 | PdfPCell colunaPercentagem = new PdfPCell(new Paragraph(1.5.0/docs/api/java/lang/String.html">String.valueOf(percentagemF),fontText)); |
||
748 | table.addCell(colunaPercentagem); |
||
749 | } |
||
750 | else{ |
||
751 | PdfPCell colunaPercentagem = new PdfPCell(new Paragraph(semResposta,fontText)); |
||
752 | table.addCell(colunaPercentagem); |
||
753 | } |
||
754 | } |
||
755 | } |
||
756 | float splitWidth = 0.65f / (float)(assessment.getQuestions().size()+1); |
||
757 | float[] tams = new float[assessment.getQuestions().size()+3]; |
||
758 | tams[0]=0.10f; |
||
759 | tams[1]=0.25f; |
||
760 | for(int i=2;i<assessment.getQuestions().size()+3;i++) |
||
761 | { |
||
762 | tams[i] = splitWidth; |
||
763 | } |
||
764 | // float[] tams = {0.10f,0.25f,0.10f,0.10f,0.10f,0.03f,0.04f,0.04f}; |
||
765 | |||
766 | table.setWidths(tams); |
||
767 | |||
768 | table.setWidthPercentage(100.0f); |
||
769 | table.setHorizontalAlignment(5+0%2Fdocs%2Fapi+Element">Element.ALIGN_LEFT); |
||
770 | doc.add(table); |
||
771 | |||
772 | } finally { |
||
773 | if (doc != null) { |
||
774 | //fechamento do documento |
||
775 | doc.close(); |
||
776 | } |
||
777 | if (os != null) { |
||
1599 | jmachado | 778 | //fechamento da stream de saida |
808 | jmachado | 779 | os.close(); |
780 | } |
||
781 | } |
||
782 | |||
783 | //repositoryStream |
||
784 | 1.5.0/docs/api/java/lang/String.html">String fileName = Globals.TMP_DIR+ assessment.getTitle()+".pdf"; |
||
785 | 1.5.0/docs/api/java/io/File.html">File file = new 1.5.0/docs/api/java/io/File.html">File(fileName); |
||
786 | 1.5.0/docs/api/java/lang/String.html">String extension = FilesUtils.getExtension(fileName); |
||
787 | 1.5.0/docs/api/java/lang/String.html">String description = "assessment.evaluations.file "+assessment.getCourseUnit().getName(); |
||
788 | 1.5.0/docs/api/java/io/FileInputStream.html">FileInputStream inputStream = new 1.5.0/docs/api/java/io/FileInputStream.html">FileInputStream(file); |
||
789 | 1.5.0/docs/api/java/lang/String.html">String identifierEvaluations = assessment.getEvaluationsIdentifier(); |
||
790 | |||
791 | if(identifierEvaluations==null) |
||
1703 | jmachado | 792 | identifierEvaluations = repositoryService.storeRepositoryFile(inputStream,"application/pdf",extension,(int)file.length(),file.getName(),description, ResourceAccessControlEnum.publicDomain, null, userSession); |
808 | jmachado | 793 | else |
794 | repositoryService.updateRepositoryFile(identifierEvaluations,inputStream, "application/pdf",extension,(int)file.length(),file.getName(),description, ResourceAccessControlEnum.publicDomain); |
||
795 | |||
796 | assessment.setEvaluationsIdentifier(identifierEvaluations); |
||
797 | |||
798 | return new AssessmentView(assessment); |
||
799 | // return new AssessmentView(); |
||
800 | } |
||
801 | |||
802 | } |