source: mauRepo/MolesManager/trunk/tests/moles2gui/creationFactory.py @ 8477

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/mauRepo/MolesManager/trunk/tests/moles2gui/creationFactory.py@8477
Revision 8477, 4.2 KB checked in by mnagni, 8 years ago (diff)

Implemented adapters for TM_Instant, TM_Period and partially for CEDA_Observation

Added a Sphinx documentation folder

Line 
1'''
2BSD Licence
3Copyright (c) 2012, Science & Technology Facilities Council (STFC)
4All rights reserved.
5
6Redistribution and use in source and binary forms, with or without modification,
7are permitted provided that the following conditions are met:
8
9    * Redistributions of source code must retain the above copyright notice,
10        this list of conditions and the following disclaimer.
11    * Redistributions in binary form must reproduce the above copyright notice,
12        this list of conditions and the following disclaimer in the documentation
13        and/or other materials provided with the distribution.
14    * Neither the name of the Science & Technology Facilities Council (STFC)
15        nor the names of its contributors may be used to endorse or promote
16        products derived from this software without specific prior written permission.
17
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29Created on 24 Jul 2012
30
31@author: mnagni
32'''
33from libs.migration.processor.commons import createCI_OnlineResource,\
34    createCI_Address, createCI_Telephone, createCI_Contact,\
35    createMO_Organization, createMO_Individual, createMO_ResponsiblePartyInfo,\
36    isoDateTimeStringToTimeDate, createDateTime, createTM_Position,\
37    createTM_Instant, fromDateStringToPhenomenonTime
38from MolesManager.codelist import getCLValue, MM_RoleValue
39from ea_model.ceda_metadatamodel.ceda_observation.ceda_observation import CEDA_Observation
40
41def assembleMO_Individual(name = 'CedaTest', iid = 1):
42    ret = createMO_Individual(name = name)
43    ret.id = iid
44    return ret
45
46def assembleMO_Organization(name = 'UK Solar System Data Centre website', iid = 1):
47    i_linkage = 'http://www.ukssdc.rl.ac.uk'
48    i_onlineResources = createCI_OnlineResource(linkage = i_linkage, name = name)
49    i_address = createCI_Address(deliveryPoint = ['UK Solar System Data Centre, STFC Rutherford Appleton Laboratory'], \
50                                 electronicMailAddress=['support@rl.ac.uk'], postalCode='OX11 0QX', country='UK', city='Harwell Oxford')                                   
51    i_phone = createCI_Telephone(voice=['+44(0)1235 445173'])                                 
52    contact = createCI_Contact(phone=i_phone, address=i_address, onlineResource=i_onlineResources)                       
53    ret = createMO_Organization(name = 'NERC - UK Solar System Data Centre', contactInfo = [contact])
54    ret.id = iid
55    return ret
56
57def assembleMO_ResponsiblePartyInfo(role = getCLValue(MM_RoleValue.cl_author), iid = 1):
58    """
59        Returns a MO_ResponsiblePartyInfo owning two parties (one MO_Individual and one MO_Organization)
60    """
61    party = [assembleMO_Individual(iid = 1), assembleMO_Organization(iid = 2)]
62    rp = createMO_ResponsiblePartyInfo(role, party)
63    rp.id =iid
64    return rp
65
66def assembleTM_Instant(timestring = '2012-01-01T01:01:01Z'):
67    """
68    Returns a TM_Instant instance
69       
70    **Parameters**
71        * timestring: a time string formatted as '%Y-%m-%dT%H:%M:%SZ'
72    """
73    py_datetime = isoDateTimeStringToTimeDate(timestring)
74    date_time = createDateTime(py_datetime)   
75    tm_position = createTM_Position(dateTime8601 = date_time)
76    return createTM_Instant(tm_position)
77
78def assembleObservation(phenomenonTime = '2002-07-22/2011-08-06'):
79    ceda_observation = CEDA_Observation()
80    ceda_observation.relatedParty = assembleMO_ResponsiblePartyInfo()
81    ceda_observation.resultTime = assembleTM_Instant()
82    ceda_observation.phenomenonTime = fromDateStringToPhenomenonTime(phenomenonTime)
83    return ceda_observation
Note: See TracBrowser for help on using the repository browser.