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

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

Add delete functionality to front tier of oai editor. Include
message to confirm the data has been completed, as a pop up, when
the operation is done. Update tests and simplify model + dal layer.

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.info("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.info("- 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.info("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.info("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 or None if data not found
97        '''
98        return self.client.getProviderInfo(providerInfoName)
99
100
101    def getProviderInfoForUser(self, user):
102        '''
103        Return provider info records valid to the input user
104        @param user: a User object with user details
105        @return list of ProviderInfo objects which the user can update
106        '''
107        return self.client.getProviderInfoForUser(user)
Note: See TracBrowser for help on using the repository browser.