Rev 1310 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
204 | jmachado | 1 | package pt.estgp.estgweb.services.courseunits; |
2 | |||
730 | jmachado | 3 | import jomm.utils.FilesUtils; |
4 | import org.apache.log4j.Logger; |
||
204 | jmachado | 5 | import pt.estgp.estgweb.domain.CourseUnit; |
6 | import pt.estgp.estgweb.domain.RepositoryFileImpl; |
||
730 | jmachado | 7 | import pt.estgp.estgweb.domain.UserSession; |
204 | jmachado | 8 | import pt.estgp.estgweb.domain.dao.DaoFactory; |
730 | jmachado | 9 | import pt.estgp.estgweb.domain.views.CourseUnitView; |
10 | import pt.estgp.estgweb.filters.chains.ResourceAccessControlEnum; |
||
11 | import pt.estgp.estgweb.services.data.RepositoryService; |
||
204 | jmachado | 12 | import pt.estgp.estgweb.services.expceptions.ServiceException; |
730 | jmachado | 13 | import pt.utl.ist.berserk.logic.serviceManager.IService; |
204 | jmachado | 14 | |
15 | import java.io.InputStream; |
||
16 | |||
17 | /* |
||
18 | * @author Goncalo Luiz gedl [AT] rnl [DOT] ist [DOT] utl [DOT] pt |
||
19 | * |
||
20 | * |
||
21 | * Created at 17/Out/2003 , 23:45:24 |
||
22 | * |
||
23 | */ |
||
24 | /** |
||
25 | * @author Jorge Machado |
||
26 | * |
||
27 | * |
||
28 | * Created at 17/Out/2003 , 23:45:24 |
||
29 | * |
||
30 | */ |
||
31 | public class UpdateCourseUnitService implements IService |
||
32 | { |
||
33 | |||
34 | RepositoryService repositoryService = new RepositoryService(); |
||
214 | jmachado | 35 | LoadCourseUnitService loadCourseUnitService = new LoadCourseUnitService(); |
204 | jmachado | 36 | |
37 | 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(UpdateCourseUnitService.class); |
||
38 | |||
39 | public CourseUnitView run(CourseUnitView courseUnitView, |
||
40 | 5+0%2Fdocs%2Fapi+InputStream">InputStream stream, |
||
41 | 1.5.0/docs/api/java/lang/String.html">String name, |
||
42 | int size, |
||
43 | 1.5.0/docs/api/java/lang/String.html">String contentType, |
||
44 | UserSession userSession) |
||
45 | throws ServiceException |
||
46 | { |
||
47 | |||
48 | |||
49 | CourseUnit c = DaoFactory.getCourseUnitDaoImpl().get(courseUnitView.getId()); |
||
50 | |||
51 | courseUnitView.persistViewInObject(c); |
||
52 | RepositoryFileImpl repositoryFile = null; |
||
53 | if(stream != null && size > 0) |
||
54 | { |
||
207 | jmachado | 55 | 1.5.0/docs/api/java/lang/String.html">String extension = FilesUtils.getExtension(name); |
204 | jmachado | 56 | if(c.getProgramStreamId() == null) |
57 | { |
||
1703 | jmachado | 58 | 1.5.0/docs/api/java/lang/String.html">String identifier = repositoryService.storeRepositoryFile(stream, contentType, extension, size, name, "courseunit.program.description" + c.getName(), ResourceAccessControlEnum.publicDomain, null, userSession); |
204 | jmachado | 59 | c.setProgramStreamId(identifier); |
60 | } |
||
61 | else |
||
62 | { |
||
63 | repositoryService.updateRepositoryFile(c.getProgramStreamId(), stream, contentType, extension, size, name, "courseunit.program.description " + c.getName(), ResourceAccessControlEnum.publicDomain); |
||
64 | } |
||
65 | |||
66 | } |
||
67 | if(c.getProgramStreamId() != null) |
||
68 | { |
||
69 | repositoryFile = repositoryService.loadView(c.getProgramStreamId()); |
||
70 | } |
||
71 | CourseUnitView cV = new CourseUnitView(c); |
||
72 | if(repositoryFile != null) |
||
73 | { |
||
74 | cV.setProgramSize(repositoryFile.getLastVersion().getSize()/1024); |
||
75 | cV.setExtension(repositoryFile.getLastVersion().getExtension()); |
||
76 | } |
||
214 | jmachado | 77 | return loadCourseUnitService.run(cV.getId(),true,false,false,userSession); |
204 | jmachado | 78 | } |
730 | jmachado | 79 | |
80 | |||
81 | public void delete(long id, |
||
82 | UserSession userSession) |
||
83 | throws ServiceException |
||
84 | { |
||
85 | CourseUnit c = DaoFactory.getCourseUnitDaoImpl().get(id); |
||
86 | c.setStatus(false); |
||
87 | } |
||
88 | |||
89 | |||
90 | |||
204 | jmachado | 91 | } |