source: ndgCommon/trunk/ndg/common/src/models/Deployment.py @ 5211

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/ndgCommon/trunk/ndg/common/src/models/Deployment.py
Revision 5211, 2.8 KB checked in by cbyrom, 11 years ago (diff)

Extend Deployment data model to include values to simplify the lookup
of the associated data - for use when updating changed atom references.

Line 
1'''
2 Class representing data in  atom format - allowing moles data to be stored and accessed in a web feed compatible way
3 
4 @author: C Byrom, Tessella Jun 2008
5'''
6import logging
7from ndg.common.src.models.vocabtermdata import VocabTermData as VTD
8
9
10class Deployment(object):
11    '''
12    Class representing deployment data - used to simplify the display of
13    deployments data in the genshi templates
14    '''
15   
16    def __init__(self, deploymentAtom):
17        '''
18        Constructor - initialise the deployment object
19        '''
20        logging.debug("Creating Deployment object")
21        self.activities = []
22        self.obs = []
23        self.dpts = []
24       
25        # add the deployment info appropriately
26        for link in deploymentAtom.relatedLinks:
27            self.__processDeploymentLink(link)
28
29        self.startDate = deploymentAtom.t1
30        self.endDate = deploymentAtom.t2
31        self.browseURL = deploymentAtom.atomBrowseURL
32        self.title = deploymentAtom.title
33       
34        # include id so the deployment can be retrieved easily
35        self.id = deploymentAtom.datasetID
36        self.providerID = deploymentAtom.ME.providerID
37        logging.debug("Deployment created")
38
39       
40    def __processDeploymentLink(self, deploymentLink):
41        '''
42        Given a Link object, add the data to the correct collection
43        @param deploymentLink: a Link object with deployment data
44        '''
45        logging.debug("Adding deployment link info")
46        deploymentType = None
47        # first, determine type of deployment - NB, ignore the data if it is
48        # not an activity/observation station/deployment tool
49        if deploymentLink.rel.startswith(VTD.TERM_DATA[VTD.ACTIVITY_TERM].vocabURL):
50            deploymentType = self.activities
51        elif deploymentLink.rel.startswith(VTD.TERM_DATA[VTD.OBS_TERM].vocabURL):
52            deploymentType = self.obs
53        elif deploymentLink.rel.startswith(VTD.TERM_DATA[VTD.DPT_TERM].vocabURL):
54            deploymentType = self.dpts
55        else:
56            logging.debug("Not a valid deployment type (%s) - ignoring" \
57                          %deploymentLink.rel)
58            return
59
60        # Now check if this has already been added; return if so
61        for link in deploymentType:
62            if link == deploymentLink:
63                logging.debug("- info already included - ignoring")
64                return
65
66        deploymentType.append(deploymentLink)
67        logging.debug("- deployment link info added")
68
69   
70    def getAllLinks(self):
71        '''
72        Utility method to return all link data in one call
73        @return list: with all activity, obs and dpt links
74        '''
75        data = []
76        data.extend(self.activities)
77        data.extend(self.obs)
78        data.extend(self.dpts)
79        return data
80       
Note: See TracBrowser for help on using the repository browser.