def _getNewContent(self, itemid, contenttype): timestamp = parseDateTime() isfolder = self.User.Provider.isFolder(contenttype) isdocument = self.User.Provider.isDocument(contenttype) isroot = itemid == self.User.RootId data = KeyMap() data.insertValue('Id', itemid) data.insertValue('ObjectId', itemid) data.insertValue('Title', '') data.insertValue('TitleOnServer', '') data.insertValue('DateCreated', timestamp) data.insertValue('DateModified', timestamp) data.insertValue('ContentType', contenttype) mediatype = '' if isdocument else contenttype data.insertValue('MediaType', mediatype) data.insertValue('Size', 0) data.insertValue('Trashed', False) data.insertValue('IsRoot', isroot) data.insertValue('IsFolder', isfolder) data.insertValue('IsDocument', isdocument) data.insertValue('CanAddChild', isfolder) data.insertValue('CanRename', True) data.insertValue('IsReadOnly', False) data.insertValue('IsVersionable', isdocument) data.insertValue('Loaded', True) data.insertValue('BaseURI', self.getContentIdentifier()) return data
def _getMetaData(self, contenttype): metadata = KeyMap() if not self.User.isValid(): # Uri with Scheme but without a Path generate invalid user but we need # to return an Identifier, and raise an 'IllegalIdentifierException' # when ContentProvider try to get the Content... # (ie: ContentProvider.queryContent() -> Identifier.getContent()) return metadata uripath = self._uri.getPath().strip('/.') itemid, parentid, path = self.User.DataBase.getIdentifier( self.User.Id, self.User.RootId, uripath) if itemid is not None: if self.IsNew: # New Identifier are created by the parent folder... metadata.setValue('ParentId', itemid) itemid = self._getNewIdentifier() parenturi = self._uri.getUriReference() data = self._getNewContent(itemid, contenttype) else: metadata.setValue('ParentId', parentid) parenturi = '%s://%s/%s' % (self._uri.getScheme(), self._uri.getAuthority(), path) data = self.User.DataBase.getItem(self.User.Id, itemid, parentid) metadata.setValue('Id', itemid) metadata.setValue('ParentURI', parenturi) if data is not None: metadata += data self._propertySetInfo = self._getPropertySetInfo() return metadata
def __init__(self, ctx): msg = "User loading" self.ctx = ctx self.MetaData = KeyMap() self._Error = '' self.Request = self._getRequest() msg += " ... Done" logMessage(self.ctx, INFO, msg, "User", "__init__()")
def MetaData(self): metadata = KeyMap() metadata.insertValue('AccessToken', self.AccessToken) metadata.insertValue('RefreshToken', self.RefreshToken) metadata.insertValue('NeverExpires', self.NeverExpires) metadata.insertValue('TimeStamp', self._TimeStamp) metadata.insertValue('Scopes', self.Scopes) return metadata
def __init__(self, ctx): self.ctx = ctx self.configuration = getConfiguration(self.ctx, g_identifier, True) self.Setting = OAuth2Setting(self.ctx) version = self._getSSLVersion() self.Session = self._getSession(version) self._Url = '' self._Provider = KeyMap() self._Users = None self._UserName = '' self._User = KeyMap() self._parent = None self._Warnings = [] self._Error = None self.Error = '' self.stringResource = getStringResource(self.ctx, g_identifier, 'OAuth2OOo') self._SessionMode = OFFLINE
def selectItem(self, user, identifier): item = None select = self._getDataSourceCall('getItem') select.setString(1, user.getValue('UserId')) select.setString(2, identifier.getValue('Id')) result = select.executeQuery() if result.next(): item = getKeyMapFromResult(result, KeyMap()) select.close() return item
def _parseResponse(response): try: content = response.headers.get('Content-Type', '') if content.startswith('application/json'): result = response.json(object_pairs_hook=_jsonParser) else: result = KeyMap(**response.headers) return result except Exception as e: print("request._parseResponse() ERROR: %s - %s" % (e, traceback.print_exc()))
def getRoot(self, request, user): id = user.getValue('root_info').getValue('root_namespace_id') root = KeyMap() root.insertValue('id', id) root.insertValue('name', 'Homework') response = uno.createUnoStruct( 'com.sun.star.beans.Optional<com.sun.star.auth.XRestKeyMap>') response.IsPresent = True response.Value = root return response
def getKeyMapFromResult(result, keymap=KeyMap(), provider=None): for i in range(1, result.MetaData.ColumnCount + 1): name = result.MetaData.getColumnName(i) value = getValueFromResult(result, i) if value is None: continue if result.wasNull(): value = None if provider: value = provider.transform(name, value) keymap.insertValue(name, value) return keymap
def __init__(self, ctx, datasource, url, contenttype=''): level = INFO msg = "Identifier loading" self.ctx = ctx self.DataSource = datasource self.User = None self._Url = self._getUrl(url) self._ContentType = contenttype self._Error = '' self.MetaData = KeyMap() msg += " ... Done" logMessage(self.ctx, level, msg, "Identifier", "__init__()")
def insertItem(self, user, item): timestamp = parseDateTime() rootid = user.getValue('RootId') c1 = self._getDataSourceCall('deleteParent') c2 = self._getDataSourceCall('insertParent') if not self._prepareItemCall('update', c1, c2, user, item, timestamp): self._prepareItemCall('insert', c1, c2, user, item, timestamp) c1.close() c2.close() id = self.Provider.getItemId(item) identifier = KeyMap() identifier.insertValue('Id', id) return self.selectItem(user, identifier)
def _getMetaData(self, id): metadata = None providers = self.configuration.getByName('Providers') if providers.hasByName(id): provider = providers.getByName(id) metadata = KeyMap() metadata.insertValue('ClientSecret', provider.getByName('ClientSecret')) metadata.insertValue('ClientId', provider.getByName('ClientId')) metadata.insertValue('TokenUrl', provider.getByName('TokenUrl')) metadata.insertValue('TokenParameters', provider.getByName('TokenParameters')) return metadata
def getTokenFromResponse(response, token): token.Value = KeyMap() refresh = response.get('refresh_token', None) expires = response.get('expires_in', None) access = response.get('access_token', None) if refresh: token.Value.insertValue('RefreshToken', refresh) if expires: timestamp = int(time.time()) + expires token.Value.insertValue('ExpiresIn', expires) token.Value.insertValue('TimeStamp', timestamp) if access: token.Value.insertValue('AccessToken', access) token.Value.insertValue('NeverExpires', expires is None) token.IsPresent = any((refresh, expires, access)) return token
def getKeyMapSequenceFromResult(result, provider=None): sequence = [] count = result.MetaData.ColumnCount + 1 while result.next(): keymap = KeyMap() for i in range(1, count): name = result.MetaData.getColumnName(i) value = getValueFromResult(result, i) if value is None: continue if result.wasNull(): value = None if provider: value = provider.transform(name, value) keymap.insertValue(name, value) sequence.append(keymap) return sequence
def __init__(self, ctx, source=None, name=None, database=None): self.ctx = ctx self.DataBase = database # Uri with Scheme but without a Path generate invalid user but we need # to return an Identifier, and raise an 'IllegalIdentifierException' # when ContentProvider try to get the Content... # (ie: ContentProvider.queryContent() -> Identifier.getContent()) if source is None: self.Provider = None self.Request = None self.MetaData = KeyMap() else: self.Provider = source.Provider self.Request = getRequest(self.ctx, self.Provider.Scheme, name) self.MetaData = source.DataBase.selectUser(name) self.CanAddChild = not self.Provider.GenerateIds msg = getMessage(self.ctx, g_message, 101) logMessage(self.ctx, INFO, msg, "User", "__init__()")
def insertUser(self, user, root): userid = self.Provider.getUserId(user) username = self.Provider.getUserName(user) displayname = self.Provider.getUserDisplayName(user) rootid = self.Provider.getRootId(root) timestamp = parseDateTime() insert = self._getDataSourceCall('insertUser') insert.setString(1, username) insert.setString(2, displayname) insert.setString(3, rootid) insert.setTimestamp(4, timestamp) insert.setString(5, userid) insert.execute() insert.close() if not self._executeRootCall('update', userid, root, timestamp): self._executeRootCall('insert', userid, root, timestamp) data = KeyMap() data.insertValue('UserId', userid) data.insertValue('UserName', username) data.insertValue('RootId', rootid) data.insertValue('RootName', self.Provider.getRootTitle(root)) return data
def insertUser(self, provider, user, root): userid = provider.getUserId(user) username = provider.getUserName(user) displayname = provider.getUserDisplayName(user) rootid = provider.getRootId(root) rootname = provider.getRootTitle(root) timestamp = parseDateTime() insert = self._getCall('insertUser') insert.setString(1, username) insert.setString(2, displayname) insert.setString(3, rootid) insert.setTimestamp(4, timestamp) insert.setString(5, userid) insert.execute() insert.close() self._mergeRoot(provider, userid, rootid, rootname, root, timestamp) data = KeyMap() data.insertValue('UserId', userid) data.insertValue('UserName', username) data.insertValue('RootId', rootid) data.insertValue('RootName', rootname) data.insertValue('Token', '') return data
def getContent(self): try: if self.IsNew: timestamp = parseDateTime() isfolder = self.DataSource.Provider.isFolder(self._ContentType) isdocument = self.DataSource.Provider.isDocument( self._ContentType) data = KeyMap() data.insertValue('Id', self.Id) data.insertValue('ObjectId', self.Id) data.insertValue('Title', '') data.insertValue('TitleOnServer', '') data.insertValue('DateCreated', timestamp) data.insertValue('DateModified', timestamp) data.insertValue('ContentType', self._ContentType) mediatype = self._ContentType if isfolder else '' data.insertValue('MediaType', mediatype) data.insertValue('Size', 0) data.insertValue('Trashed', False) data.insertValue('IsRoot', self.IsRoot) data.insertValue('IsFolder', isfolder) data.insertValue('IsDocument', isdocument) data.insertValue('CanAddChild', True) data.insertValue('CanRename', True) data.insertValue('IsReadOnly', False) data.insertValue('IsVersionable', isdocument) data.insertValue('Loaded', True) else: data = self.User.getItem(self.DataSource, self.MetaData) data.insertValue('BaseURI', self.MetaData.getValue('BaseURI')) content = Content(self.ctx, self, data) #content.initialize() return content except Exception as e: print("Identifier.getContent() ERROR: %s - %s" % (e, traceback.print_exc()))
def getItemParent(self, item, rootid): ref = item.getDefaultValue('parentReference', KeyMap()) parent = ref.getDefaultValue('id', rootid) return (parent, )
def getUser(self, request, name): data = KeyMap() data.insertValue('Id', name) parameter = self.getRequestParameter('getUser', data) return request.execute(parameter)
def Json(self): if self._parser is not None and self._parser.DataType.lower() == 'json': keymap = KeyMap(self._response.json(object_pairs_hook=self._parser.parseResponse)) else: keymap = KeyMap(self._response.json()) return keymap
def getKeyMap(self): return KeyMap()
def getResponseTitle(self, response, default): title = response.getDefaultValue('metadata', KeyMap()).getDefaultValue( 'name', None) if title is None: title = default return title
def _getTablesAndStatements(statement, version=g_version): tables = [] statements = [] call = getDataSourceCall(statement.getConnection(), 'getTables') for table in getSequenceFromResult(statement.executeQuery(getSqlQuery('getTableName'))): view = False versioned = False columns = [] primary = [] unique = [] constraint = [] call.setString(1, table) result = call.executeQuery() while result.next(): data = getKeyMapFromResult(result, KeyMap()) view = data.getValue('View') versioned = data.getValue('Versioned') column = data.getValue('Column') definition = '"%s"' % column definition += ' %s' % data.getValue('Type') lenght = data.getValue('Lenght') definition += '(%s)' % lenght if lenght else '' default = data.getValue('Default') definition += ' DEFAULT %s' % default if default else '' options = data.getValue('Options') definition += ' %s' % options if options else '' columns.append(definition) if data.getValue('Primary'): primary.append('"%s"' % column) if data.getValue('Unique'): unique.append({'Table': table, 'Column': column}) if data.getValue('ForeignTable') and data.getValue('ForeignColumn'): constraint.append({'Table': table, 'Column': column, 'ForeignTable': data.getValue('ForeignTable'), 'ForeignColumn': data.getValue('ForeignColumn')}) if primary: columns.append(getSqlQuery('getPrimayKey', primary)) for format in unique: columns.append(getSqlQuery('getUniqueConstraint', format)) for format in constraint: columns.append(getSqlQuery('getForeignConstraint', format)) if version >= '2.5.0' and versioned: columns.append(getSqlQuery('getPeriodColumns')) format = (table, ','.join(columns)) query = getSqlQuery('createTable', format) if version >= '2.5.0' and versioned: query += getSqlQuery('getSystemVersioning') tables.append(query) if view: typed = False for format in constraint: if format['Column'] == 'Type': typed = True break format = {'Table': table} if typed: merge = getSqlQuery('createTypedDataMerge', format) else: merge = getSqlQuery('createUnTypedDataMerge', format) statements.append(merge) call.close() return tables, statements
def getResponseId(self, response, default): id = response.getDefaultValue('metadata', KeyMap()).getDefaultValue('id', None) if id is None: id = default return id