852135a80edd822cae276485dd8d457909b19a60
[smartapi.git] / Common / Python / SmartAPI / model / Authorization.py
1 from SmartAPI.common.PROPERTY import PROPERTY
2 from SmartAPI.common.RESOURCE import RESOURCE
3 from SmartAPI.model.Obj import Obj
4 from SmartAPI.rdf.Variant import Variant
5
6
7 class Authorization(Obj):
8
9         def __init__(self, uri = None):
10                 Obj.__init__(self, uri)
11                 self.setType(RESOURCE.AUTHORIZATION)
12                 self.init_property(PROPERTY.PERSON, 'person', self.hasPerson, self.getPerson)
13                 self.init_property(PROPERTY.METHOD, 'methods', self.hasMethod, self.getMethods, islist = True)
14                 
15         def hasPerson(self):
16                 return self.person is not None
17         
18         def getPerson(self):
19                 return self.person
20
21         def setPerson(self, p):
22                 if isinstance(p, str):
23                         _p = Person()
24                         _p.setUsername(p)
25                 else:
26                         _p = p
27                 self.person = _p
28
29         def hasMethod(self):
30                 return len(self.methods) > 0
31         
32         def getMethods(self):
33                 return self.methods
34
35         def addMethod(self, m):
36                 if isinstance(m, str):
37                         m = Variant(m)
38                 self.methods.append(m)
39                 
40         def _parseStatement(self, statement, custom_classes = None):
41                 self.parse_property(statement, PROPERTY.PERSON, self.setPerson, Person, custom_classes = custom_classes)
42                 self.parse_property(statement, PROPERTY.METHOD, self.addMethod, Variant, custom_classes = custom_classes)
43                 super(Authorization, self)._parseStatement(statement, custom_classes = custom_classes)
44