1 | ''' |
---|
2 | Created on 15 Nov 2011 |
---|
3 | |
---|
4 | @author: mnagni |
---|
5 | ''' |
---|
6 | from libs.migration.processor.commons import findMolesLineage,\ |
---|
7 | createMO_ResponsiblePartyInfo,\ |
---|
8 | DO_BADC, DO_NEODC, findAuthorsInResource, CEDA,\ |
---|
9 | createMD_Identifier, extractSummary, extractQuality, \ |
---|
10 | hasAtomDocumentSameHash, getAtomDocumentHashByMO, extractTitle,\ |
---|
11 | createCEDA_Result,\ |
---|
12 | createEX_GeographicBoundingBox, extractGeographicExtentInMigrationDocument, findDownloadLinksInMigrationDocument,\ |
---|
13 | findDOIInMigrationDocument, extractContent, createCI_Citation, createCI_Date, createDate,\ |
---|
14 | createTM_Position, createTM_Instant, extractMolesCreationDate,\ |
---|
15 | createDateTime, isoDateTimeStringToTimeDate, extractMolesProviderID,\ |
---|
16 | DO_UKSSDC, createMO_Organization,\ |
---|
17 | createCI_Contact, createCI_Address, createCI_OnlineResource,\ |
---|
18 | createCI_Telephone, extractMolesTemporalRange, isoDateStringToTimeDate,\ |
---|
19 | createTM_Period, createCI_Individual, findAccessLinksInMigrationDocument,\ |
---|
20 | findLinksInDeployment, createMD_LegalConstraints,\ |
---|
21 | createDQ_Element, createDQ_ConformanceResult, findUpdatedDate,\ |
---|
22 | createMD_Metadata, createMO_OnlineResource, createCEDA_Review, calculateHash,\ |
---|
23 | createCI_ResponsibleParty, extractUpdateFrequency,\ |
---|
24 | findLinksInMigrationDocument, findSubTypeInDPT, extractMolesPublishedDate,\ |
---|
25 | createMD_Keywords |
---|
26 | from ea_model.moles3_4.utilities.mo_rolevalue import MO_RoleValue |
---|
27 | from ea_model.ceda_metadatamodel.ceda_observation.ceda_observation import CEDA_Observation |
---|
28 | from libs.migration.MigrationEPB import MigrationEPB |
---|
29 | from libs.epb import EPB |
---|
30 | from libs.migration.processor.deployment_data import DeploymentDataProcessor |
---|
31 | from ea_model.moles3_4.utilities.mo_publicationstatevalue import MO_PublicationStateValue |
---|
32 | from libs.migration.exception.exceptions import NoDataLineage,\ |
---|
33 | NoAssociatedAuthor |
---|
34 | from MolesManager.moles3epb import Moles3EPB |
---|
35 | from libs.migration.authors import authors |
---|
36 | from logging import StreamHandler |
---|
37 | import logging |
---|
38 | from datetime import date |
---|
39 | from ea_model.iso_19115_2006_metadata_corrigendum.citation_and_responsible_party_information.ci_onlinefunctioncode import CI_OnLineFunctionCode |
---|
40 | from ea_model.iso_19115_2006_metadata_corrigendum.citation_and_responsible_party_information.ci_datetypecode import CI_DateTypeCode |
---|
41 | from ea_model.iso_19115_2006_metadata_corrigendum.constraint_information.md_restrictioncode import MD_RestrictionCode |
---|
42 | from copy import deepcopy |
---|
43 | import datetime |
---|
44 | from libs.migration.InfodbEPB import InfodbEPB |
---|
45 | from ea_model.ceda_metadatamodel.ceda_result import ceda_curationvalue |
---|
46 | from ea_model.ceda_metadatamodel.ceda_utilities.ceda_reviewfrequencyvalue import CEDA_ReviewFrequencyValue |
---|
47 | from ea_model.ceda_metadatamodel.ceda_utilities.ceda_reviewstatusvalue import CEDA_ReviewStatusValue |
---|
48 | from MolesManager.ceda_guid import CedaGUID |
---|
49 | from ea_model.iso_19115_2006_metadata_corrigendum.citation_and_responsible_party_information.ci_rolecode import CI_RoleCode |
---|
50 | from ea_model.iso_19115_2006_metadata_corrigendum.maintenance_information.md_maintenancefrequencycode import MD_MaintenanceFrequencyCode |
---|
51 | from ea_model.ceda_metadatamodel.ceda_result.ceda_curationvalue import CEDA_CurationValue |
---|
52 | from libs.migration.processor.EPBRepo import EPBRepo |
---|
53 | |
---|
54 | class DeploymentProcessor(object): |
---|
55 | ''' |
---|
56 | Migrates a deployment element in a CEDA_Observation entity |
---|
57 | ''' |
---|
58 | publisherName = 'CEDA' |
---|
59 | |
---|
60 | log = logging.getLogger('DeploymentProcessor') |
---|
61 | log.addHandler(StreamHandler()) |
---|
62 | log.setLevel(logging.INFO) |
---|
63 | def __init__(self, dataEntityMigration, deploymentMigration): |
---|
64 | ''' |
---|
65 | Initializes the class |
---|
66 | @param dataEntityMigration: a DataEntityMigration instance |
---|
67 | @param deploymentMigration: the DeploymentMigration instance |
---|
68 | ''' |
---|
69 | self._dataEntityMigration = dataEntityMigration |
---|
70 | self._deploymentMigration = deploymentMigration |
---|
71 | self._dataEntityHasSameHash = hasAtomDocumentSameHash(self._dataEntityMigration) and self._dataEntityMigration.doc_hash is not None |
---|
72 | self._deploymentHasSameHash = hasAtomDocumentSameHash(self._deploymentMigration) and self._deploymentMigration.doc_hash is not None |
---|
73 | |
---|
74 | def _existsCEDAasPublisher(self): |
---|
75 | for rp in self._ceda_observation.relatedParty: |
---|
76 | if rp.role == MO_RoleValue.cl_publisher: |
---|
77 | for party in rp.parties: |
---|
78 | if party.name == DeploymentProcessor.publisherName: |
---|
79 | return True |
---|
80 | return False |
---|
81 | |
---|
82 | """ |
---|
83 | def _extractResponsiblePartyInfo(self, authors = None, parsedParties = []): |
---|
84 | ''' |
---|
85 | @param authors: the deployment's authors |
---|
86 | @param parsedParties: a list to fill with the created MO_ResponsiblePartyInfos |
---|
87 | ''' |
---|
88 | #First is assumend to be the author |
---|
89 | i_party = createMO_Organization(name = authors[:1]) |
---|
90 | parsedParties.append(createMO_ResponsiblePartyInfo(MO_RoleValue.cl_author, [i_party])) |
---|
91 | i_party = [] |
---|
92 | if len(authors) < 2: |
---|
93 | return |
---|
94 | |
---|
95 | for i_name in authors[:1]: |
---|
96 | i_party.append(createMO_Organization(name = i_name)) |
---|
97 | parsedParties.append(createMO_ResponsiblePartyInfo(MO_RoleValue.cl_coinvestigator, i_party)) |
---|
98 | """ |
---|
99 | |
---|
100 | def _addResponsiblePartyInfo(self, oldResponsiblePartyInfos, newResponsiblePartyInfo): |
---|
101 | opi = None |
---|
102 | for oldPartyInfo in oldResponsiblePartyInfos: |
---|
103 | if oldPartyInfo.role == newResponsiblePartyInfo.role: |
---|
104 | opi = oldPartyInfo |
---|
105 | break |
---|
106 | |
---|
107 | if len(oldResponsiblePartyInfos) == 0 or opi is None: |
---|
108 | oldResponsiblePartyInfos.append(newResponsiblePartyInfo) |
---|
109 | |
---|
110 | if opi is not None: |
---|
111 | for np in newResponsiblePartyInfo.party: |
---|
112 | opi.party.append(np) |
---|
113 | |
---|
114 | |
---|
115 | def _assignName(self, observation): |
---|
116 | ''' |
---|
117 | @param relatedPartyInfos: a MO_ResponsiblePartyInfo list |
---|
118 | @return True if the documents changed, False otherwise |
---|
119 | ''' |
---|
120 | whereAreAuthors = self._deploymentMigration |
---|
121 | doc_authors = findAuthorsInResource(self._deploymentMigration) |
---|
122 | if doc_authors['authors'] in [DO_BADC, DO_NEODC]: |
---|
123 | doc_authors = findAuthorsInResource(self._dataEntityMigration) |
---|
124 | whereAreAuthors = self._dataEntityMigration |
---|
125 | |
---|
126 | ind_names = [] |
---|
127 | org_names = [] |
---|
128 | if authors.has_key(doc_authors['authors']): |
---|
129 | tmp_auth = authors[doc_authors['authors']] |
---|
130 | ret = self._extractIndividualsAndOrganizations(tmp_auth, whereAreAuthors) |
---|
131 | |
---|
132 | if len(ret['ind']) > 0: |
---|
133 | i_party = createCI_Individual(name = ret['ind'][0]) |
---|
134 | observation.relatedParty.append(createMO_ResponsiblePartyInfo(MO_RoleValue.cl_author, [i_party])) |
---|
135 | if len(ret['org']) > 0: |
---|
136 | i_party = createMO_Organization(name = ret['org'][0]) |
---|
137 | observation.relatedParty.append(createMO_ResponsiblePartyInfo(MO_RoleValue.cl_author, [i_party])) |
---|
138 | |
---|
139 | if len(ret['ind']) > 1: |
---|
140 | ind_names.extend(ret['ind'][1:]) |
---|
141 | if len(ret['org']) > 1: |
---|
142 | org_names.extend(ret['org'][1:]) |
---|
143 | if len(ret['co_ind']) > 0: |
---|
144 | ind_names.extend(ret['co_ind']) |
---|
145 | if len(ret['co_org']) > 0: |
---|
146 | org_names.extend(ret['co_org']) |
---|
147 | |
---|
148 | else: |
---|
149 | raise NoAssociatedAuthor(doc_authors['authors'], migrationObject = whereAreAuthors) |
---|
150 | |
---|
151 | if doc_authors['contributors'] and authors.has_key(doc_authors['contributors']): |
---|
152 | tmp_auth = authors[doc_authors['contributors']] |
---|
153 | ret = self._extractIndividualsAndOrganizations(tmp_auth, whereAreAuthors) |
---|
154 | ind_names.extend(ret['ind']) |
---|
155 | ind_names.extend(ret['co_ind']) |
---|
156 | org_names.extend(ret['org']) |
---|
157 | org_names.extend(ret['co_org']) |
---|
158 | |
---|
159 | i_party = [] |
---|
160 | for nm in ind_names: |
---|
161 | i_party.append(createCI_Individual(name = nm)) |
---|
162 | |
---|
163 | for nm in org_names: |
---|
164 | i_party.append(createMO_Organization(name = nm)) |
---|
165 | |
---|
166 | if i_party: |
---|
167 | observation.relatedParty.append(createMO_ResponsiblePartyInfo(MO_RoleValue.cl_coinvestigator, i_party)) |
---|
168 | |
---|
169 | def _extractIndividualsAndOrganizations(self, tmp_auth, whereAreAuthors): |
---|
170 | if whereAreAuthors is None: |
---|
171 | raise Exception("migrationObject is None") |
---|
172 | try: |
---|
173 | if tmp_auth['author'] == 'unknown': |
---|
174 | doc_authors = findAuthorsInResource(self._dataEntityMigration) |
---|
175 | tmp_auth = authors[doc_authors['authors']] |
---|
176 | |
---|
177 | ret = {'ind': [], 'org': [], 'co_ind': [], 'co_org': []} |
---|
178 | if tmp_auth['type'] == 'ind': |
---|
179 | ret['ind'].append(tmp_auth['author']) |
---|
180 | elif tmp_auth['type'] == 'org': |
---|
181 | ret['org'].append(tmp_auth['author']) |
---|
182 | |
---|
183 | if tmp_auth['author'] == 'unknown': |
---|
184 | DeploymentProcessor.log.debug("%s %s %s has unknown author" \ |
---|
185 | % (whereAreAuthors.doc_status, whereAreAuthors.doc_owner, whereAreAuthors.doc_name)) |
---|
186 | |
---|
187 | for item in tmp_auth['co_author_type']: |
---|
188 | if (tmp_auth['co_author'][tmp_auth['co_author_type'].index(item)] == 'unknown'): |
---|
189 | doc_authors = findAuthorsInResource(self._dataEntityMigration) |
---|
190 | tmp_auth = authors[doc_authors['contributors']] |
---|
191 | break |
---|
192 | |
---|
193 | for index in range(len(tmp_auth['co_author_type'])): |
---|
194 | ptype = tmp_auth['co_author_type'][index] |
---|
195 | if ptype == 'ind': |
---|
196 | ret['co_ind'].append(tmp_auth['co_author'][index]) |
---|
197 | elif ptype == 'org': |
---|
198 | ret['co_org'].append(tmp_auth['co_author'][index]) |
---|
199 | |
---|
200 | if (tmp_auth['co_author'][index] == 'unknown'): |
---|
201 | DeploymentProcessor.log.info("%s %s %s has unknown author" \ |
---|
202 | % (whereAreAuthors.doc_status, whereAreAuthors.doc_owner, whereAreAuthors.doc_name)) |
---|
203 | except Exception as e: |
---|
204 | print e |
---|
205 | return ret |
---|
206 | |
---|
207 | def _assignLineage(self, observation): |
---|
208 | data_lineage = findMolesLineage(self._dataEntityMigration) |
---|
209 | if data_lineage is None: |
---|
210 | raise NoDataLineage(self._dataEntityMigration) |
---|
211 | observation.dataLineage = data_lineage |
---|
212 | |
---|
213 | def _assignTitle(self, observation): |
---|
214 | doc_title = extractTitle(self._deploymentMigration) |
---|
215 | if doc_title is None: |
---|
216 | doc_title = extractTitle(self._dataEntityMigration) |
---|
217 | |
---|
218 | if doc_title.startswith('deployment_') or doc_title.startswith('Deployment_'): |
---|
219 | links = findLinksInMigrationDocument(self._deploymentMigration) |
---|
220 | dptList = links['DPT'] |
---|
221 | if links.has_key('DPT'): |
---|
222 | doc_title = 'Data from ' + dptList[0]['title'] |
---|
223 | if len(dptList) > 2: |
---|
224 | for dpt in dptList[1:-2]: |
---|
225 | doc_title += ', ' + dpt['title'] |
---|
226 | if len(dptList) > 1: |
---|
227 | doc_title += ' and ' + dptList[-1] |
---|
228 | |
---|
229 | links = findLinksInDeployment(self._deploymentMigration) |
---|
230 | if links.has_key('OBS'): |
---|
231 | obsList = [] |
---|
232 | for obs in links['OBS']: |
---|
233 | observationStation = EPBRepo.migrationEPB.getDeploymentDataMigrationByName(self._deploymentMigration, obs + '.atom') |
---|
234 | obsList.append((extractTitle(observationStation), findSubTypeInDPT(observationStation))) |
---|
235 | |
---|
236 | if obsList[0][1] in ['stationary platform' ,'moving platform', 'ship','aircraft','satellite','computer']: |
---|
237 | doc_title += ' on ' |
---|
238 | else : |
---|
239 | doc_title += ' at ' |
---|
240 | doc_title += obsList[0][0] |
---|
241 | if len(obsList) > 2: |
---|
242 | for obs in obsList[1:-2]: |
---|
243 | doc_title += ', ' + obs[0] |
---|
244 | if len(obsList) > 1: |
---|
245 | doc_title += ' and ' + obsList[-1][0] |
---|
246 | |
---|
247 | if links.has_key('ACTIVITY'): |
---|
248 | for link in links['ACTIVITY']: |
---|
249 | activity = EPBRepo.migrationEPB.getDeploymentDataMigrationByName(self._deploymentMigration, link + '.atom') |
---|
250 | |
---|
251 | projSubType = findSubTypeInDPT(activity) |
---|
252 | doc_title += ' for the ' + extractTitle(activity) |
---|
253 | if projSubType[0:14] == 'dgActivityData': |
---|
254 | doc_title += ' ' + projSubType[14:] |
---|
255 | else : |
---|
256 | doc_title += ' ' + projSubType |
---|
257 | |
---|
258 | else: |
---|
259 | if doc_title[0:10] != 'Data from' : |
---|
260 | doc_title = "Data from " + doc_title |
---|
261 | auth = createCI_Citation(title = 'ceda_title') |
---|
262 | identifier = createMD_Identifier(code = doc_title, authority = auth) |
---|
263 | observation.identifier.append(identifier) |
---|
264 | |
---|
265 | def _assignDescription(self, observation): |
---|
266 | description = extractSummary(self._deploymentMigration, self._dataEntityMigration) |
---|
267 | if description: |
---|
268 | observation.description = description |
---|
269 | |
---|
270 | def _assignQuality(self, observation): |
---|
271 | doc_quality = extractQuality(self._dataEntityMigration) |
---|
272 | doc_date = findUpdatedDate(self._dataEntityMigration) |
---|
273 | ci_dates = [] |
---|
274 | if doc_date: |
---|
275 | i_date = createDate(isoDateTimeStringToTimeDate(doc_date)) |
---|
276 | ci_dates.append(createCI_Date(CI_DateTypeCode.cl_revision, date = i_date)) |
---|
277 | else: |
---|
278 | i_date = createDate(isoDateTimeStringToTimeDate(datetime.datetime.now())) |
---|
279 | ci_dates.append(createCI_Date(CI_DateTypeCode.cl_creation, date = i_date)) |
---|
280 | |
---|
281 | i_specification = createCI_Citation(title = "CEDA Data Quality Statement", date=ci_dates) |
---|
282 | i_dq_result = createDQ_ConformanceResult(doc_quality, True, i_specification) |
---|
283 | i_quality_element = createDQ_Element(i_dq_result) |
---|
284 | observation.resultQuality.append(i_quality_element) |
---|
285 | |
---|
286 | def updateObservation(self): |
---|
287 | return EPB.searchOrCreate(CEDA_Observation, self._deploymentMigration.ceda_observation_id) |
---|
288 | |
---|
289 | |
---|
290 | def _assignResult(self, observation): |
---|
291 | # TDB - Check that if is an update or not! |
---|
292 | download = findDownloadLinksInMigrationDocument(self._deploymentMigration) |
---|
293 | content = None |
---|
294 | if len(download) == 0: |
---|
295 | download = findDownloadLinksInMigrationDocument(self._dataEntityMigration) |
---|
296 | content = extractContent(self._dataEntityMigration) |
---|
297 | else: |
---|
298 | content = extractContent(self._deploymentMigration) |
---|
299 | for dwn in download: |
---|
300 | int_description = None |
---|
301 | int_applicationProfile = None |
---|
302 | if content.has_key('formats'): |
---|
303 | #int_applicationProfile = content['formats'] |
---|
304 | pass |
---|
305 | if dwn['href'].startswith('http://badc.nerc.ac.uk/browse') or dwn['href'].startswith('http://neodc.nerc.ac.uk/browse'): |
---|
306 | int_description = "download directly from archive" |
---|
307 | i_source = createMO_OnlineResource(linkage = dwn['href'], name = dwn['title'], \ |
---|
308 | function = CI_OnLineFunctionCode.cl_download, \ |
---|
309 | description = int_description, applicationProfile = int_applicationProfile) |
---|
310 | |
---|
311 | dataentity_id = '%s__ATOM__%s' % (self._dataEntityMigration.doc_owner, self._dataEntityMigration.doc_name) |
---|
312 | dataentity_id = dataentity_id.replace('.atom', '') |
---|
313 | infodb_de = EPBRepo.infodbEPB.getCedaInfoApp_dataentityByDE_ID(dataentity_id) |
---|
314 | i_logical_path = '/dummy' |
---|
315 | if infodb_de is None: |
---|
316 | i_logical_path = dwn['href'][dwn['href'].index('/browse/') + 7:] |
---|
317 | |
---|
318 | if infodb_de and infodb_de.has_key('logical_path'): |
---|
319 | i_logical_path = infodb_de['logical_path'] |
---|
320 | |
---|
321 | i_category = ceda_curationvalue.CEDA_CurationValue.cl_a |
---|
322 | if infodb_de and infodb_de.has_key('category') and infodb_de['category']: |
---|
323 | i_category = CEDA_CurationValue.from_string(infodb_de['category'].lower()) #self._getcurationcategory(infodb_de['category']) |
---|
324 | observation.result = createCEDA_Result(i_category, i_logical_path, source = [i_source]) |
---|
325 | |
---|
326 | |
---|
327 | def _assignGeographicExtent(self, observation): |
---|
328 | # TDB - Check that if is an update or not! |
---|
329 | ge = extractGeographicExtentInMigrationDocument(self._deploymentMigration) |
---|
330 | if not ge: |
---|
331 | ge = extractGeographicExtentInMigrationDocument(self._dataEntityMigration) |
---|
332 | if ge: |
---|
333 | observation.geographicExtent.append(createEX_GeographicBoundingBox(ge['east'], ge['north'], ge['west'], ge['south'])) |
---|
334 | |
---|
335 | def _assignCreationDate(self, observation): |
---|
336 | # TDB - Check that if is an update or not! |
---|
337 | creation_date = extractMolesPublishedDate(self._deploymentMigration) |
---|
338 | if creation_date is None: |
---|
339 | creation_date = extractMolesCreationDate(self._deploymentMigration) |
---|
340 | py_datetime = isoDateTimeStringToTimeDate(creation_date) |
---|
341 | date_time = createDateTime(py_datetime) |
---|
342 | tm_position = createTM_Position(dateTime8601 = date_time) |
---|
343 | observation.resultTime = createTM_Instant(tm_position) |
---|
344 | |
---|
345 | def assignDOI(self, observation, doi): |
---|
346 | if doi and doi.has_key('href'): |
---|
347 | doi = doi['href'][22:] |
---|
348 | |
---|
349 | #Check if a doi has been already assigned |
---|
350 | observation = EPBRepo.moles3EPB.loadAttributes(observation, 'identifier') |
---|
351 | obs_identifier = observation.identifier |
---|
352 | if obs_identifier: |
---|
353 | for ident in obs_identifier: |
---|
354 | if ident.code == doi: |
---|
355 | return |
---|
356 | |
---|
357 | py_date = None |
---|
358 | cited_responsible = createCI_ResponsibleParty(role=CI_RoleCode.cl_publisher, \ |
---|
359 | organizationName='NERC - British Atmospheric Data Centre') |
---|
360 | if doi.upper() == '10.5285/E8F43A51-0198-4323-A926-FE69225D57DD': |
---|
361 | py_date = date(2011, 4, 1) |
---|
362 | elif doi.upper() == '10.5285/78114093-E2BD-4601-8AE5-3551E62AEF2B': |
---|
363 | py_date = date(2011, 11, 29) |
---|
364 | elif doi.upper() == '10.5285/DB8D8981-1A51-4D6E-81C0-CCED9B921390': |
---|
365 | py_date = date(2012, 4, 16) |
---|
366 | elif doi.upper() == '10.5285/639A3714-BC74-46A6-9026-64931F355E07': |
---|
367 | py_date = date(2012, 4, 16) |
---|
368 | |
---|
369 | if py_date: |
---|
370 | dt = createDate(py_date) |
---|
371 | ci_date = createCI_Date(CI_DateTypeCode.cl_publication, date = dt) |
---|
372 | i_authority = createCI_Citation("DOI", date = ci_date) |
---|
373 | identifier = createMD_Identifier(code = doi, authority=i_authority) |
---|
374 | EPBRepo.moles3EPB.updateCedaObject(observation, {'identifier': identifier}) |
---|
375 | DeploymentProcessor.log.info("DOI: %s" % (doi)) |
---|
376 | |
---|
377 | def _assignPublisherCurator(self, observation): |
---|
378 | provider_id = extractMolesProviderID(self._deploymentMigration) |
---|
379 | party = None |
---|
380 | if provider_id == DO_BADC: |
---|
381 | i_linkage = 'http://badc.rl.ac.uk' |
---|
382 | i_onlineResources = createCI_OnlineResource(linkage = i_linkage, name = 'British Atmospheric Data Centre Website') |
---|
383 | i_address = createCI_Address(deliveryPoint = ['British Atmospheric Data Centre, STFC Rutherford Appleton Laboratory'], \ |
---|
384 | electronicMailAddress=['badc@rl.ac.uk'], postalCode='OX11 0QX', country='UK', city='Harwell Oxford') |
---|
385 | i_phone = createCI_Telephone(voice=['+44(0)1235 446432']) |
---|
386 | contact = createCI_Contact(phone=i_phone, address=i_address, onlineResource=i_onlineResources) |
---|
387 | party = createMO_Organization(name = "NERC - British Atmospheric Data Centre", contactInfo = [contact]) |
---|
388 | elif provider_id == DO_NEODC: |
---|
389 | i_linkage = 'http://www.neodc.rl.ac.uk' |
---|
390 | i_onlineResources = createCI_OnlineResource(linkage = i_linkage, name = 'NERC Earth Observation Data Centre website') |
---|
391 | i_address = createCI_Address(deliveryPoint = ['NERC - Earth Observation Data Centre, STFC Rutherford Appleton Laboratory'], \ |
---|
392 | electronicMailAddress=['neodc@rl.ac.uk'], postalCode='OX11 0QX', country='UK', city='Harwell Oxford') |
---|
393 | i_phone = createCI_Telephone(voice=['+44(0)1235 446432']) |
---|
394 | contact = createCI_Contact(phone=i_phone, address=i_address, onlineResource=i_onlineResources) |
---|
395 | party = createMO_Organization(name = 'NERC - Earth Observation Data Centre', contactInfo = [contact]) |
---|
396 | elif provider_id == DO_UKSSDC: |
---|
397 | i_linkage = 'http://www.ukssdc.rl.ac.uk' |
---|
398 | i_onlineResources = createCI_OnlineResource(linkage = i_linkage, name = 'UK Solar System Data Centre website') |
---|
399 | i_address = createCI_Address(deliveryPoint = ['UK Solar System Data Centre, STFC Rutherford Appleton Laboratory'], \ |
---|
400 | electronicMailAddress=['support@rl.ac.uk'], postalCode='OX11 0QX', country='UK', city='Harwell Oxford') |
---|
401 | i_phone = createCI_Telephone(voice=['+44(0)1235 445173']) |
---|
402 | contact = createCI_Contact(phone=i_phone, address=i_address, onlineResource=i_onlineResources) |
---|
403 | party = createMO_Organization(name = 'NERC - UK Solar System Data Centre', contactInfo = [contact]) |
---|
404 | |
---|
405 | if party: |
---|
406 | observation.relatedParty.append(createMO_ResponsiblePartyInfo(MO_RoleValue.cl_publisher, [party])) |
---|
407 | observation.relatedParty.append(createMO_ResponsiblePartyInfo(MO_RoleValue.cl_custodian, deepcopy([party]))) |
---|
408 | observation.relatedParty.append(createMO_ResponsiblePartyInfo(MO_RoleValue.cl_distributor, deepcopy([party]))) |
---|
409 | observation.relatedParty.append(createMO_ResponsiblePartyInfo(MO_RoleValue.cl_pointofcontact, deepcopy([party]))) |
---|
410 | observation.relatedParty.append(createMO_ResponsiblePartyInfo(MO_RoleValue.cl_metadataowner, deepcopy([party]))) |
---|
411 | observation.relatedParty.append(createMO_ResponsiblePartyInfo(MO_RoleValue.cl_curator, deepcopy([party]))) |
---|
412 | |
---|
413 | def _assignPhenomenonTime(self, observation): |
---|
414 | doc_phenomenon_time = extractMolesTemporalRange(self._deploymentMigration) |
---|
415 | |
---|
416 | if doc_phenomenon_time: |
---|
417 | if '/' in doc_phenomenon_time: |
---|
418 | period = doc_phenomenon_time.split('/') |
---|
419 | begin_date = createDate(isoDateStringToTimeDate(period[0])) |
---|
420 | begin_position = createTM_Position(date8601 = begin_date) |
---|
421 | begin_tm_instant = createTM_Instant(begin_position) |
---|
422 | |
---|
423 | end_date = createDate(isoDateStringToTimeDate(period[1])) |
---|
424 | end_position = createTM_Position(date8601 = end_date) |
---|
425 | end_tm_instant = createTM_Instant(end_position) |
---|
426 | |
---|
427 | observation.phenomenonTime = createTM_Period(begin_tm_instant, end_tm_instant) |
---|
428 | else: |
---|
429 | observation.phenomenonTime = createTM_Position(date8601 = createDate(isoDateStringToTimeDate(doc_phenomenon_time))) |
---|
430 | |
---|
431 | def _assignPermission(self, observation): |
---|
432 | access_link = findAccessLinksInMigrationDocument(self._deploymentMigration) |
---|
433 | dwn_link = findDownloadLinksInMigrationDocument(self._deploymentMigration) |
---|
434 | if len(access_link) == 0: |
---|
435 | access_link = findAccessLinksInMigrationDocument(self._dataEntityMigration) |
---|
436 | |
---|
437 | i_accessConstraints = [] |
---|
438 | i_use_limitation = [] |
---|
439 | |
---|
440 | if len(access_link) == 0: |
---|
441 | if len(dwn_link) == 0: |
---|
442 | dwn_link = findDownloadLinksInMigrationDocument(self._dataEntityMigration) |
---|
443 | if dwn_link and len(dwn_link) == 1: |
---|
444 | i_use_limitation.append("These data are open access and available through %s." % (dwn_link[0]['href']) ) |
---|
445 | #i_accessConstraints.append(MD_RestrictionCode.cl_) |
---|
446 | observation.permission = createMD_LegalConstraints(useLimitation = i_use_limitation, accessConstrains = i_accessConstraints) |
---|
447 | else: |
---|
448 | if access_link and len(access_link) == 1: |
---|
449 | i_use_limitation.append("Access to these data is restricted. To obtain access please apply for access at: %s" % (access_link[0]['href'])) |
---|
450 | i_accessConstraints.append(MD_RestrictionCode.cl_restricted) |
---|
451 | observation.permission = createMD_LegalConstraints(useLimitation = i_use_limitation, accessConstrains = i_accessConstraints) |
---|
452 | |
---|
453 | ''' |
---|
454 | contentDict = extractContent(self._deploymentMigration) |
---|
455 | if not contentDict.has_key('access-restricted'): |
---|
456 | contentDict = extractContent(self._dataEntityMigration) |
---|
457 | ''' |
---|
458 | |
---|
459 | def _assignMoles2Link(self, ceda_observation): |
---|
460 | i_code = 'http://badc.nerc.ac.uk/view/%s__ATOM__%s' % (self._deploymentMigration.doc_owner, self._deploymentMigration.doc_name) |
---|
461 | i_code = i_code.replace('.atom', '') |
---|
462 | #i_code = buildExistDocPath(self._deploymentMigration.doc_status, DT_DEPLOYMENTS, self._deploymentMigration.doc_owner, self._deploymentMigration.doc_name) |
---|
463 | i_authority = createCI_Citation('moles2url') |
---|
464 | identifier = createMD_Identifier(code = i_code, authority = i_authority) |
---|
465 | ceda_observation.identifier.append(identifier) |
---|
466 | |
---|
467 | def _assignLanguage(self, ceda_observation): |
---|
468 | i_date_stamp = createDate(datetime.datetime.now()) |
---|
469 | #i_contact = createCI_Citation("", date = i_date_stamp) |
---|
470 | i_contact = createCI_ResponsibleParty(CI_RoleCode.cl_user) |
---|
471 | ceda_observation.metadata = createMD_Metadata(date_stamp=i_date_stamp, contact = [i_contact], language = "English") |
---|
472 | |
---|
473 | def _assignInternalReview(self, ceda_observation): |
---|
474 | i_party = createCI_Individual(name = 'Graham Parton') |
---|
475 | i_reviewer = createMO_ResponsiblePartyInfo(MO_RoleValue.cl_processor, [i_party]) |
---|
476 | ceda_observation.internalReview.append( \ |
---|
477 | createCEDA_Review(reviewer=i_reviewer, reviewFrequency=CEDA_ReviewFrequencyValue.cl_yearly, \ |
---|
478 | reviewStatus=CEDA_ReviewStatusValue.cl_required)) |
---|
479 | |
---|
480 | def _assignUpdateFrequency(self, ceda_observation): |
---|
481 | updateFrequency = extractUpdateFrequency(self._deploymentMigration) |
---|
482 | if updateFrequency: |
---|
483 | ceda_observation.resultAccumulation = MD_MaintenanceFrequencyCode.from_string(updateFrequency) |
---|
484 | |
---|
485 | def _assignKeywords(self, ceda_observation): |
---|
486 | provider_id = extractMolesProviderID(self._deploymentMigration) |
---|
487 | i_keywords = [] |
---|
488 | if provider_id == DO_BADC: |
---|
489 | i_keywords.append('Meteorological geographical features') |
---|
490 | if provider_id == DO_NEODC: |
---|
491 | i_keywords.append('Orthoimagery') |
---|
492 | if len(i_keywords) > 0: |
---|
493 | ceda_observation.keywords.append(createMD_Keywords(i_keywords)) |
---|
494 | |
---|
495 | def _create(self): |
---|
496 | ceda_observation = CEDA_Observation() |
---|
497 | self._assignKeywords(ceda_observation) |
---|
498 | self._assignLineage(ceda_observation) |
---|
499 | self._assignResult(ceda_observation) |
---|
500 | self._assignPublisherCurator(ceda_observation) |
---|
501 | |
---|
502 | ceda_observation.publicationState = MO_PublicationStateValue.cl_working |
---|
503 | self._assignQuality(ceda_observation) |
---|
504 | self._assignDescription(ceda_observation) |
---|
505 | self._assignTitle(ceda_observation) |
---|
506 | self._assignGeographicExtent(ceda_observation) |
---|
507 | #self._assignDOI(ceda_observation) |
---|
508 | self._assignCreationDate(ceda_observation) |
---|
509 | self._assignPhenomenonTime(ceda_observation) |
---|
510 | self._assignPermission(ceda_observation) |
---|
511 | self._assignMoles2Link(ceda_observation) |
---|
512 | self._assignInternalReview(ceda_observation) |
---|
513 | self._assignLanguage(ceda_observation) |
---|
514 | self._assignUpdateFrequency(ceda_observation) |
---|
515 | self._assignName(ceda_observation) |
---|
516 | EPBRepo.moles3EPB.persistInstance(ceda_observation) |
---|
517 | EPBRepo.migrationEPB.updateMigrationObject(self._deploymentMigration, {'ceda_observation_id': ceda_observation.id}) |
---|
518 | |
---|
519 | #Adds the CedaGUID |
---|
520 | ceda_guid = CedaGUID() |
---|
521 | ceda_guid.id = calculateHash(self._deploymentMigration.depl_id) |
---|
522 | ceda_guid.ceda_observation = ceda_observation.id |
---|
523 | EPBRepo.moles3EPB.persistInstance(ceda_guid) |
---|
524 | DeploymentProcessor.log.info("GUID for this Observation: %s" % (ceda_guid.id)) |
---|
525 | |
---|
526 | #process the CEDA_Observation.procedure |
---|
527 | deploymentDataProcessor = DeploymentDataProcessor(self._deploymentMigration) |
---|
528 | |
---|
529 | links = findLinksInDeployment(self._deploymentMigration) |
---|
530 | procedure = deploymentDataProcessor.createProcess(links) |
---|
531 | |
---|
532 | #Temporary commented because CEDA_Project.subProject is not correctly mapped to the DB |
---|
533 | project = deploymentDataProcessor.createProject(links) |
---|
534 | EPBRepo.moles3EPB.updateCedaObject(ceda_observation, {'procedure': procedure, 'inSupportOf': project}) |
---|
535 | |
---|
536 | return ceda_observation |
---|
537 | |
---|
538 | def _getObservation(self): |
---|
539 | return EPBRepo.moles3EPB.search(CEDA_Observation, self._deploymentMigration.ceda_observation_id) |
---|
540 | |
---|
541 | def _update(self): |
---|
542 | if hasAtomDocumentSameHash(self._deploymentMigration): |
---|
543 | return self._getObservation() |
---|
544 | else: |
---|
545 | return self.updateObservation() |
---|
546 | |
---|
547 | def process(self): |
---|
548 | ceda_observation = None |
---|
549 | #Moles3 object exists... |
---|
550 | if self._deploymentMigration.ceda_observation_id: |
---|
551 | ceda_observation = self._update() |
---|
552 | else: |
---|
553 | #... does not exist so create it |
---|
554 | ceda_observation = self._create() |
---|
555 | |
---|
556 | if not self._deploymentHasSameHash: |
---|
557 | self._deploymentMigration.doc_hash = getAtomDocumentHashByMO(self._deploymentMigration) |
---|
558 | self._commitMigration() |
---|
559 | |
---|
560 | return ceda_observation |
---|