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