| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | ## |
|---|
| 3 | ## |
|---|
| 4 | ## This file is part of CDS Indico. |
|---|
| 5 | ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 CERN. |
|---|
| 6 | ## |
|---|
| 7 | ## CDS Indico is free software; you can redistribute it and/or |
|---|
| 8 | ## modify it under the terms of the GNU General Public License as |
|---|
| 9 | ## published by the Free Software Foundation; either version 2 of the |
|---|
| 10 | ## License, or (at your option) any later version. |
|---|
| 11 | ## |
|---|
| 12 | ## CDS Indico is distributed in the hope that it will be useful, but |
|---|
| 13 | ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 15 | ## General Public License for more details. |
|---|
| 16 | ## |
|---|
| 17 | ## You should have received a copy of the GNU General Public License |
|---|
| 18 | ## along with CDS Indico; if not, write to the Free Software Foundation, Inc., |
|---|
| 19 | ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 20 | |
|---|
| 21 | from MaKaC.services.implementation.collaboration import CollaborationPluginServiceBase |
|---|
| 22 | from MaKaC.plugins.Collaboration.RecordingManager.exceptions import RecordingManagerException |
|---|
| 23 | from MaKaC.plugins.Collaboration.RecordingManager.common import createIndicoLink, createCDSRecord, submitMicalaMetadata |
|---|
| 24 | from MaKaC.plugins.Collaboration.RecordingManager.micala import MicalaCommunication |
|---|
| 25 | |
|---|
| 26 | class RMCreateCDSRecordService(CollaborationPluginServiceBase): |
|---|
| 27 | |
|---|
| 28 | def _checkParams(self): |
|---|
| 29 | CollaborationPluginServiceBase._checkParams(self) #puts the Conference in self._conf |
|---|
| 30 | self._IndicoID = self._params.get('IndicoID', None) |
|---|
| 31 | self._LOID = self._params.get('LOID', None) |
|---|
| 32 | self._LODBID = self._params.get('LODBID', None) |
|---|
| 33 | self._lectureTitle = self._params.get('lectureTitle', None) |
|---|
| 34 | self._lectureSpeakers = self._params.get('lectureSpeakers', None) |
|---|
| 35 | self._confId = self._params.get('conference', None) |
|---|
| 36 | self._videoFormat = self._params.get('videoFormat', None) |
|---|
| 37 | self._contentType = self._params.get('contentType', None) |
|---|
| 38 | self._languages = self._params.get('languages', None) |
|---|
| 39 | |
|---|
| 40 | if not self._contentType: |
|---|
| 41 | raise RecordingManagerException(_("No content type supplied (plain video or web lecture)")) |
|---|
| 42 | if not self._IndicoID: |
|---|
| 43 | raise RecordingManagerException(_("No IndicoID supplied")) |
|---|
| 44 | |
|---|
| 45 | if self._contentType == 'web_lecture': |
|---|
| 46 | if not self._LODBID: |
|---|
| 47 | raise RecordingManagerException(_("No LODBID supplied")) |
|---|
| 48 | elif self._contentType == 'plain_video': |
|---|
| 49 | if not self._videoFormat: |
|---|
| 50 | raise RecordingManagerException(_("No video format supplied")) |
|---|
| 51 | |
|---|
| 52 | if not self._confId: |
|---|
| 53 | raise RecordingManagerException(_("No conference ID supplied")) |
|---|
| 54 | |
|---|
| 55 | if not self._languages: |
|---|
| 56 | raise RecordingManagerException(_("No languages supplied")) |
|---|
| 57 | |
|---|
| 58 | def _getAnswer(self): |
|---|
| 59 | """This method does everything necessary to create a CDS record and also update the micala database. |
|---|
| 60 | For plain_video talks, it does the following: |
|---|
| 61 | - calls createCDSRecord(), |
|---|
| 62 | which generates the MARC XML, |
|---|
| 63 | submits it to CDS, |
|---|
| 64 | and makes sure a record for this talk exists in micala DB |
|---|
| 65 | For web_lecture talks, it does the following: |
|---|
| 66 | - calls createCDSRecord(), |
|---|
| 67 | which generates the MARC XML and submits it to CDS |
|---|
| 68 | - calls associateIndicoIDToLOID(), |
|---|
| 69 | which associates the chosen IndicoID to the existing record of the LOID in micala DB |
|---|
| 70 | (no need to create a new record, because the user is only allowed to choose LOID's that are already in the micala DB) |
|---|
| 71 | - calls submitMicalaMetadata(), which generates the micala lecture.xml and submits it to micala DB. |
|---|
| 72 | All of these methods update their status to micala DB. |
|---|
| 73 | """ |
|---|
| 74 | |
|---|
| 75 | # Get the MARC XML and submit it to CDS, |
|---|
| 76 | # then update micala database Status table showing task completed. |
|---|
| 77 | # do this for both plain_video and web_lecture talks |
|---|
| 78 | resultCreateCDSRecord = createCDSRecord(self._aw, |
|---|
| 79 | self._IndicoID, |
|---|
| 80 | self._LODBID, |
|---|
| 81 | self._lectureTitle, |
|---|
| 82 | self._lectureSpeakers, |
|---|
| 83 | self._contentType, |
|---|
| 84 | self._videoFormat, |
|---|
| 85 | self._languages) |
|---|
| 86 | if resultCreateCDSRecord["success"] == False: |
|---|
| 87 | raise RecordingManagerException(_("CDS record creation failed.\n%s") % resultCreateCDSRecord["result"]) |
|---|
| 88 | return _("CDS record creation aborted.") |
|---|
| 89 | |
|---|
| 90 | if self._contentType == 'web_lecture': |
|---|
| 91 | # Update the micala database to match the LODBID with the IndicoID |
|---|
| 92 | # This only makes sense for web_lecture talks |
|---|
| 93 | # (for plain_video, a record in Lectures should already have been created by createCDSRecord() ) |
|---|
| 94 | resultAssociateIndicoIDToLOID = MicalaCommunication.associateIndicoIDToLOID(self._IndicoID, |
|---|
| 95 | self._params.get('LODBID', None)) |
|---|
| 96 | if resultAssociateIndicoIDToLOID["success"] == False: |
|---|
| 97 | raise RecordingManagerException(_("micala database update failed.\n%s") % resultAssociateIndicoIDToLOID["result"]) |
|---|
| 98 | return _("CDS record creation aborted.") |
|---|
| 99 | |
|---|
| 100 | # Create lecture.xml and submit to micala server, |
|---|
| 101 | # then update micala database Status table showing task completed |
|---|
| 102 | # (this only makes sense if it is a web_lecture) |
|---|
| 103 | resultSubmitMicalaMetadata = submitMicalaMetadata(self._aw, |
|---|
| 104 | self._IndicoID, |
|---|
| 105 | self._contentType, |
|---|
| 106 | self._LODBID, |
|---|
| 107 | self._params.get('LOID', None), |
|---|
| 108 | self._videoFormat, |
|---|
| 109 | self._languages) |
|---|
| 110 | if resultSubmitMicalaMetadata["success"] == False: |
|---|
| 111 | raise RecordingManagerException(_("CDS record creation failed.\n%s") % resultSubmitMicalaMetadata["result"]) |
|---|
| 112 | return _("micala metadata creation aborted.") |
|---|
| 113 | |
|---|
| 114 | return _("Successfully updated micala database and submitted CDS record for creation.") |
|---|
| 115 | |
|---|
| 116 | class RMCreateIndicoLinkService(CollaborationPluginServiceBase): |
|---|
| 117 | |
|---|
| 118 | def _checkParams(self): |
|---|
| 119 | CollaborationPluginServiceBase._checkParams(self) #puts the Conference in self._conf |
|---|
| 120 | self._IndicoID = self._params.get('IndicoID', None) |
|---|
| 121 | self._confId = self._params.get('conference', None) |
|---|
| 122 | self._CDSID = self._params.get('CDSID', None) |
|---|
| 123 | |
|---|
| 124 | if not self._IndicoID: |
|---|
| 125 | raise RecordingManagerException(_("No IndicoID supplied")) |
|---|
| 126 | if not self._confId: |
|---|
| 127 | raise RecordingManagerException(_("No conference ID supplied")) |
|---|
| 128 | if not self._CDSID: |
|---|
| 129 | raise RecordingManagerException(_("No CDS record ID supplied")) |
|---|
| 130 | |
|---|
| 131 | def _getAnswer(self): |
|---|
| 132 | # Create the Indico link |
|---|
| 133 | createIndicoLink(self._IndicoID, self._CDSID) |
|---|
| 134 | |
|---|
| 135 | return 'None' # wtf, but let's keep the return value there used to be before.. |
|---|
| 136 | |
|---|
| 137 | # In case we want to update list of orphans after page has loaded... |
|---|
| 138 | class RMOrphansService(CollaborationPluginServiceBase): |
|---|
| 139 | |
|---|
| 140 | def _getAnswer(self): |
|---|
| 141 | pass |
|---|
| 142 | #orphans = getOrphans() |
|---|