source: TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/dal/providerinfodao.py @ 5240

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/dal/providerinfodao.py@5240
Revision 5240, 4.5 KB checked in by cbyrom, 11 years ago (diff)

Add data access methods to retrieve all provider information and add
tests to exercise these new methods.

Line 
1'''
2 Class representing the data access object for provider info data - with
3 methods to create, update, retrieve and delete data
4 
5 @author: C Byrom, Tessella Feb 2009
6'''
7import logging
8
9from oai_info_editor.dal.interfaceeditordbclient import InterfaceEditorDataClient
10from oai_info_editor.dal.editorfileclient import EditorFileClient
11from ndg.common.src.models.myconfig import myConfig
12
13PG_CLIENT_TYPE = 'postgres'
14FILE_CLIENT_TYPE = 'file'
15TEST_CLIENT_TYPE = 'test'
16
17def createDAOWithClient(client = FILE_CLIENT_TYPE, configFile = None):
18    '''
19    Factory method to create DAO with DB client as specified
20    @param client: Type of DB client to use with DAO.  Default (and only currently
21    supported value) = 'file'
22    @keyword configFile: config file to use to set up DB client
23    @return: ProviderInfoDAO with the specified data access client type
24    '''
25    logging.debug("Setting up DAO with '%s' editor client" %client)
26    if client == FILE_CLIENT_TYPE:
27       
28        # the file client is expecting the file in myConfig format
29        if not isinstance(configFile, myConfig):
30            configFile = myConfig(configFile)
31           
32        client = EditorFileClient(configFile = configFile)
33    else:
34        raise ValueError("Unrecognised editor client type, '%s'" %client)
35   
36    dao = ProviderInfoDAO(client)
37   
38    logging.debug("- returning DAO")
39    return dao
40
41
42class ProviderInfoDAO(object):
43
44    # define the expected object attributes
45    __slots__ = ['client']
46
47    def __init__(self, client):
48        '''
49        Constructor - initialise the DAO with a suitable data access client
50        @param client: DB client to use with DAO - must implement
51        vocabtermeditor.dal.InterfaceEditorDataClient interface
52        '''
53        logging.debug("Initialising ProviderInfoDAO object")
54
55        if not isinstance(client, InterfaceEditorDataClient):
56            raise ValueError("Input DB client does not implement InterfaceEditorDataClient")
57
58        self.client = client
59
60        logging.debug("ProviderInfoDAO initialised")
61   
62       
63    def createProviderInfo(self, providerInfo):
64        '''
65        Create new provider info data
66        @param providerInfo: ProviderInfo object with which to create the new
67        provider info record
68        @return ProviderInfo, fileName: object with any new data from the creation in + filename
69        '''
70        return self.client.createProviderInfo(providerInfo)
71   
72   
73    def updateProviderInfo(self, providerInfo):
74        '''
75        Update the input ProviderInfo
76        @param providerInfo: ProviderInfo object to update
77        @return ProviderInfo object with the updated data in
78        '''
79        return self.client.updateProviderInfo(providerInfo)
80
81       
82    def deleteProviderInfo(self, providerName):
83        '''
84        Delete the input providerInfo from the backend data file
85        @param providerName: Name of provider to delete
86        @return True if successful, False otherwise
87        '''
88        return self.client.deleteProviderInfo(providerName)
89       
90       
91    def getProviderInfo(self, providerInfoName):
92        '''
93        Get the provider info details for the specified name
94        @param providerInfoName: name of the provider info to retrieve
95        @raise ValueError: if provider info with name not found
96        @return ProviderInfo object with the requested data
97        '''
98        return self.client.getProviderInfo(providerInfoName)
99       
100
101    def getAllProviderInfo(self):
102        '''
103        Get all provider info
104        @return ProviderInfo list: list of ProviderInfo objects representing all provider info data
105        ''' 
106        return self.client.getAllProviderInfo()
107
108       
109    def getRepositoryInfo(self, providerInfoName, repositoryInfoName):
110        '''
111        Get the repository info object for the specified provider and repository name
112        @param providerInfoName: name of the provider info to retrieve
113        @param repositoryInfoName: name of the repository info to retrieve
114        @raise ValueError: if repository info with name not found
115        @return RepositoryInfo object with the requested data
116        '''
117        return self.client.getRepositoryInfo(providerInfoName, repositoryInfoName)
118
119
120    def getProviderInfoForUser(self, user):
121        '''
122        Return provider info records valid to the input user
123        @param user: a User object with user details
124        @return list of ProviderInfo objects which the user can update
125        '''
126        return self.client.getProviderInfoForUser(user)
Note: See TracBrowser for help on using the repository browser.