Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • DM/dm-docs
  • hammonds/dm-docs
  • hparraga/dm-docs
3 results
Show changes
Showing
with 706 additions and 0 deletions
#!/usr/bin/env python
#
# DB error class.
#
#######################################################################
from dm.common.constants import dmStatus
from dm.common.exceptions.dmException import DmException
#######################################################################
class DbError(DmException):
def __init__ (self, error='', **kwargs):
DmException.__init__(self, error, dmStatus.DM_DB_ERROR, **kwargs)
#!/usr/bin/env python
#
# Base DM exception class.
#
#######################################################################
import exceptions
import json
from dm.common.constants import dmStatus
#######################################################################
class DmException(exceptions.Exception):
"""
Base DM exception class.
Usage:
DmException(errorMessage, errorCode)
DmException(args=errorMessage)
DmException(exception=exceptionObject)
"""
def __init__(self, error='', code=dmStatus.DM_ERROR, **kwargs):
args = error
if args == '':
args = kwargs.get('args', '')
ex = kwargs.get('exception', None)
if ex != None:
if isinstance(ex, exceptions.Exception):
exArgs = '%s' % (ex)
if args == '':
args = exArgs
else:
args = "%s (%s)" % (args, exArgs)
exceptions.Exception.__init__(self, args)
self.code = code
def getArgs(self):
return self.args
def getErrorCode(self):
return self.code
def getErrorMessage(self):
return '%s' % (self.args)
def getClassName(self):
return '%s' % (self.__class__.__name__)
def getExceptionType(self):
return '%s' % (self.__class__.__name__).split('.')[-1]
def getJsonRep(self):
return json.dumps({
'errorMessage' : self.getErrorMessage(),
'errorCode' : self.getErrorCode(),
'exceptionType' : self.getExceptionType(),
})
def getFullJsonRep(self):
return self.getJsonRep();
#!/usr/bin/env python
from dm.common.constants import dmStatus
DM_EXCEPTION_MAP = {
dmStatus.DM_ERROR : 'dmException.DmException',
dmStatus.DM_INTERNAL_ERROR : 'internalError.InternalError',
dmStatus.DM_COMMUNICATION_ERROR : 'communicationError.CommunicationError',
dmStatus.DM_CONFIGURATION_ERROR : 'configurationError.ConfigurationError',
dmStatus.DM_AUTHORIZATION_ERROR : 'authorizationError.AuthorizationError',
dmStatus.DM_AUTHENTICATION_ERROR : 'authenticationError.AuthenticationError',
dmStatus.DM_DB_ERROR : 'dbError.DbError',
dmStatus.DM_URL_ERROR : 'urlError.UrlError',
dmStatus.DM_INVALID_ARGUMENT : 'invalidArgument.InvalidArgument',
dmStatus.DM_INVALID_REQUEST : 'invalidRequest.InvalidRequest',
dmStatus.DM_INVALID_SESSION : 'invalidSession.InvalidSession',
dmStatus.DM_COMMAND_FAILED : 'commandFailed.CommandFailed',
dmStatus.DM_OBJECT_NOT_FOUND : 'objectNotFound.ObjectNotFound',
dmStatus.DM_OBJECT_ALREADY_EXISTS : 'objectAlreadyExists.ObjectAlreadyExists',
dmStatus.DM_INVALID_OBJECT_STATE : 'invalidObjectState.InvalidObjectState',
dmStatus.DM_FILE_PROCESSING_ERROR : 'fileProcessingError.FileProcessingError',
}
#!/usr/bin/env python
import cherrypy
from cherrypy import HTTPError
class DmHttpError(HTTPError):
def __init__ (self, httpCode, httpError, dmEx):
HTTPError.__init__(self, httpCode, httpError)
self.dmException = dmEx
def set_response(self):
HTTPError.set_response(self)
cherrypy.response.headers['Dm-Status-Code'] = self.dmException.getErrorCode()
cherrypy.response.headers['Dm-Status-Message'] = self.dmException.getErrorMessage()
cherrypy.response.headers['Dm-Exception-Type'] = self.dmException.getExceptionType()
#!/usr/bin/env python
#
# File processing error class.
#
#######################################################################
from dm.common.constants import dmStatus
from dm.common.exceptions.dmException import DmException
#######################################################################
class FileProcessingError(DmException):
def __init__ (self, error='', **kwargs):
DmException.__init__(self, error, dmStatus.DM_FILE_PROCESSING_ERROR, **kwargs)
#!/usr/bin/env python
#
# Internal error class.
#
#######################################################################
from dm.common.constants import dmStatus
from dm.common.exceptions.dmException import DmException
#######################################################################
class InternalError(DmException):
def __init__ (self, error='', **kwargs):
DmException.__init__(self, error, dmStatus.DM_INTERNAL_ERROR, **kwargs)
#!/usr/bin/env python
#
# Invalid argument error class.
#
#######################################################################
from dm.common.constants import dmStatus
from dm.common.exceptions.dmException import DmException
#######################################################################
class InvalidArgument(DmException):
def __init__ (self, error='', **kwargs):
DmException.__init__(self, error, dmStatus.DM_INVALID_ARGUMENT, **kwargs)
#!/usr/bin/env python
#
# Object not found error class.
#
#######################################################################
from dm.common.constants import dmStatus
from dm.common.exceptions.dmException import DmException
#######################################################################
class ObjectNotFound(DmException):
def __init__ (self, error='', **kwargs):
DmException.__init__(self, error, dmStatus.DM_INVALID_OBJECT_STATE, **kwargs)
#!/usr/bin/env python
#
# Invalid request error class.
#
#######################################################################
from dm.common.constants import dmStatus
from dm.common.exceptions.dmException import DmException
#######################################################################
class InvalidRequest(DmException):
def __init__ (self, error='', **kwargs):
DmException.__init__(self, error, dmStatus.DM_INVALID_REQUEST, **kwargs)
#!/usr/bin/env python
#
# Invalid session error class.
#
#######################################################################
from dm.common.constants import dmStatus
from dm.common.exceptions.dmException import DmException
#######################################################################
class InvalidSession(DmException):
def __init__ (self, error='', **kwargs):
DmException.__init__(self, error, dmStatus.DM_INVALID_SESSION, **kwargs)
#!/usr/bin/env python
#
# Object already exists error class.
#
#######################################################################
from dm.common.constants import dmStatus
from dm.common.exceptions.dmException import DmException
#######################################################################
class ObjectAlreadyExists(DmException):
def __init__ (self, error='', **kwargs):
DmException.__init__(self, error, dmStatus.DM_OBJECT_ALREADY_EXISTS, **kwargs)
#!/usr/bin/env python
#
# Object not found error class.
#
#######################################################################
from dm.common.constants import dmStatus
from dm.common.exceptions.dmException import DmException
#######################################################################
class ObjectNotFound(DmException):
def __init__ (self, error='', **kwargs):
DmException.__init__(self, error, dmStatus.DM_OBJECT_NOT_FOUND, **kwargs)
#!/usr/bin/env python
#
# Url error class.
#
#######################################################################
from dm.common.constants import dmStatus
from dm.common.exceptions.dmException import DmException
#######################################################################
class UrlError(DmException):
def __init__ (self, error='', **kwargs):
DmException.__init__(self, error, dmStatus.DM_URL_ERROR, **kwargs)
#!/usr/bin/env python
import copy
import types
import re
from dm.common.objects.dmObject import DmObject
from dm.common.exceptions.dmException import DmException
from dm.common.mongodb.api.dmMongoDbApi import DmMongoDbApi
from dm.common.mongodb.impl.datasetCollection import DatasetCollection
from dm.common.mongodb.api.fileMongoDbApi import FileMongoDbApi
from dm.common.mongodb.api.dmMongoDbApi import DmMongoDbApi
from dm.common.objects.datasetMetadata import DatasetMetadata
class DatasetMongoDbApi(DmMongoDbApi):
SYSTEM_KEY_LIST = ['_id', 'datasetName', 'experimentName']
USE_DATASET_NAME_KEY = '_useDatasetName'
USE_EXPERIMENT_NAME_KEY = '_useDatasetName'
def __init__(self):
DmMongoDbApi.__init__(self)
self.datasetCollection = DatasetCollection(self.dbClient)
self.fileMongoDbApi = FileMongoDbApi()
@DmMongoDbApi.executeDbCall
def addExperimentDataset(self, datasetInfo, **kwargs):
datasetInfo2 = self.getMongoDict(datasetInfo)
dbDatasetMetadata = self.datasetCollection.addByUniqueKeys(datasetInfo2)
return self.toDmObject(dbDatasetMetadata, DatasetMetadata)
@DmMongoDbApi.executeDbCall
def getDatasets(self, queryDict={}, returnFieldDict=DatasetCollection.ALL_FIELDS_DICT, **kwargs):
queryDict2 = self.getMongoDict(queryDict)
return self.listToDmObjects(self.datasetCollection.findByQueryDict(queryDict2, returnFieldDict), DatasetMetadata)
@DmMongoDbApi.executeDbCall
def getDatasetById(self, id, **kwargs):
dbDatasetMetadata = self.datasetCollection.findById(id)
return self.toDmObject(dbDatasetMetadata, DatasetMetadata)
@DmMongoDbApi.executeDbCall
def getExperimentDataset(self, experimentName, datasetName, **kwargs):
queryDict = { 'datasetName' : datasetName, 'experimentName' : experimentName }
dbDatasetMetadata = self.datasetCollection.findByUniqueKeys(queryDict)
return self.toDmObject(dbDatasetMetadata, DatasetMetadata)
@DmMongoDbApi.executeDbCall
def getExperimentDatasets(self, experimentName, queryDict={}, returnFieldDict=DatasetCollection.ALL_FIELDS_DICT, **kwargs):
queryDict2 = copy.copy(queryDict)
queryDict2['experimentName'] = experimentName
return self.getDatasets(queryDict2, returnFieldDict)
@DmMongoDbApi.executeDbCall
def updateDatasetById(self, datasetInfo, **kwargs):
datasetInfo2 = self.getMongoDict(datasetInfo)
dbDatasetMetadata = self.datasetCollection.updateById(datasetInfo2)
return self.toDmObject(dbDatasetMetadata, DatasetMetadata)
@DmMongoDbApi.executeDbCall
def updateExperimentDataset(self, datasetInfo, **kwargs):
datasetInfo2 = self.getMongoDict(datasetInfo)
dbDatasetMetadata = self.datasetCollection.updateByUniqueKeys(datasetInfo2)
return self.toDmObject(dbDatasetMetadata, DatasetMetadata)
@DmMongoDbApi.executeDbCall
def updateOrAddExperimentDataset(self, datasetInfo, **kwargs):
datasetInfo2 = self.getMongoDict(datasetInfo)
dbDatasetMetadata = self.datasetCollection.updateOrAddByUniqueKeys(datasetInfo2)
return self.toDmObject(dbDatasetMetadata, DatasetMetadata)
@DmMongoDbApi.executeDbCall
def getExperimentDatasetFiles(self, experimentName, datasetName, returnFieldDict=DatasetCollection.ALL_FIELDS_DICT, **kwargs):
self.getLogger().debug('Looking for dataset %s (experiment %s)' % (datasetName, experimentName))
datasetDict = self.getExperimentDataset(experimentName, datasetName).getDictRep(DmObject.ALL_KEYS)
del datasetDict['id']
useDatasetName = kwargs.get(self.USE_DATASET_NAME_KEY, False)
if not useDatasetName:
del datasetDict['datasetName']
useExperimentName = kwargs.get(self.USE_EXPERIMENT_NAME_KEY, False)
if not useExperimentName:
del datasetDict['experimentName']
self.getLogger().debug('Converting dataset dict to regex patterns')
ignoreCase = kwargs.get(self.REGEX_IGNORE_CASE_KEY, True)
queryDict = self.convertStringsToRegex(datasetDict, ignoreCase)
return self.fileMongoDbApi.getExperimentFiles(experimentName, queryDict, returnFieldDict)
#######################################################################
# Testing.
if __name__ == '__main__':
api = DatasetMongoDbApi()
import time
t = long(time.time())
datasetName = 'd-%s' % t
experimentName = 'exp-01'
datasetInfo = {'datasetName' : datasetName, 'intKey' : 1, 'doubleKey' : 2.0, 'stringKey' : 'myString' , 'experimentName' : experimentName}
dataset = api.updateOrAddExperimentDataset(datasetInfo)
print '\nADDED DATASET\n', dataset
datasets = api.getDatasets()
print '\nDATASETS: \n', api.getDatasets()
for dataset in datasets:
print dataset.getDictRep()
#import re
#regex = re.compile("file0.*", re.IGNORECASE)
datasetName = 'dataset1'
datasetInfo = {'datasetName' : datasetName, 'experimentName' : experimentName, 'fileName' : 'file0.*'}
dataset = api.updateOrAddExperimentDataset(datasetInfo)
print '\nUPDATED DATASET\n', dataset
print '\nDATASET FILES\n', api.getExperimentDatasetFiles(experimentName, datasetName)
#!/usr/bin/env python
import copy
import types
import re
from dm.common.exceptions.dmException import DmException
from dm.common.utility.loggingManager import LoggingManager
from dm.common.mongodb.impl.mongoDbManager import MongoDbManager
class DmMongoDbApi:
""" Base Mongo DB API class. """
SYSTEM_KEY_LIST = ['_id']
REGEX_IGNORE_KEY_LIST = ['_id']
REGEX_IGNORE_CASE_KEY = '_ignoreCase'
def __init__(self):
self.logger = LoggingManager.getInstance().getLogger(self.__class__.__name__)
self.dbClient = MongoDbManager.getInstance().getDbClient()
# Decorator for all DB methods
@classmethod
def executeDbCall(cls, func):
def dbCall(*args, **kwargs):
try:
try:
return func(*args, **kwargs)
except DmException, ex:
raise
except Exception, ex:
cls.getLogger().exception('%s' % ex)
raise DmException(exception=ex)
finally:
# For now, do nothing
pass
return dbCall
@classmethod
def getLogger(cls):
logger = LoggingManager.getInstance().getLogger(cls.__name__)
return logger
@classmethod
def listToDmObjects(cls, mongoDbObjectList, dmObjectClass):
dmObjectList = []
for o in mongoDbObjectList:
dmObjectList.append(cls.toDmObject(o, dmObjectClass))
return dmObjectList
@classmethod
def toDmObject(cls, mongoDbObject, dmObjectClass):
cls.scrubMongoDbObject(mongoDbObject)
return dmObjectClass(mongoDbObject)
@classmethod
def scrubMongoDbObject(cls, mongoDbObject):
for key in cls.SYSTEM_KEY_LIST:
if mongoDbObject.has_key(key):
# Remove leading underscore
if key.startswith('_'):
newKey = key[1:]
mongoDbObject[newKey] = str(mongoDbObject[key])
del mongoDbObject[key]
@classmethod
def getMongoDict(cls, dict):
mongoDict = copy.copy(dict)
for key in cls.SYSTEM_KEY_LIST:
# if dictionary has system key, do not modify it
if mongoDict.has_key(key):
continue
# If provided dict has system key without leading underscore
# modify it
key2 = key[1:]
if mongoDict.has_key(key2):
mongoDict[key] = mongoDict[key2]
del mongoDict[key2]
return mongoDict
@classmethod
def convertStringsToRegex(cls, dict, ignoreCase=True):
dict2 = copy.copy(dict)
for (key,value) in dict2.items():
if key in cls.REGEX_IGNORE_KEY_LIST:
continue
elif type(value) == types.StringType or type(value) == types.UnicodeType:
cls.getLogger().debug('Converting to regex: %s for key %s' % (value,key))
if ignoreCase:
regex = re.compile(value, re.IGNORECASE)
else:
regex = re.compile(value)
dict2[key] = regex
return dict2
#######################################################################
# Testing.
if __name__ == '__main__':
api = DmMongoDbApi()
#!/usr/bin/env python
import copy
import types
import re
from dm.common.exceptions.dmException import DmException
from dm.common.mongodb.api.dmMongoDbApi import DmMongoDbApi
from dm.common.mongodb.impl.fileCollection import FileCollection
from dm.common.mongodb.api.dmMongoDbApi import DmMongoDbApi
from dm.common.objects.fileMetadata import FileMetadata
from dm.common.exceptions.invalidRequest import InvalidRequest
class FileMongoDbApi(DmMongoDbApi):
SYSTEM_KEY_LIST = ['_id', 'experimentFilePath', 'experimentName']
def __init__(self):
DmMongoDbApi.__init__(self)
self.fileCollectionDict = {}
def getFileCollection(self, experimentName):
fileCollection = self.fileCollectionDict.get(experimentName)
if not fileCollection:
fileCollection = FileCollection(self.dbClient, experimentName)
self.fileCollectionDict[experimentName] = fileCollection
return fileCollection
@classmethod
def getAndCheckExperimentName(cls, dictObject):
experimentName = dictObject.get('experimentName')
cls.checkExperimentName(experimentName)
return experimentName
@classmethod
def checkExperimentName(cls, experimentName):
if not experimentName:
raise InvalidRequest('Experiment name has not been provided.')
@DmMongoDbApi.executeDbCall
def addExperimentFile(self, fileInfo, **kwargs):
experimentName = self.getAndCheckExperimentName(fileInfo)
fileInfo2 = self.getMongoDict(fileInfo)
dbFileMetadata = self.getFileCollection(experimentName).addByUniqueKeys(fileInfo2)
return self.toDmObject(dbFileMetadata, FileMetadata)
@DmMongoDbApi.executeDbCall
def getExperimentFiles(self, experimentName, queryDict={}, returnFieldDict=FileCollection.ALL_FIELDS_DICT, **kwargs):
self.checkExperimentName(experimentName)
queryDict2 = self.getMongoDict(queryDict)
self.getLogger().debug('Converting query dict to regex patterns')
ignoreCase = kwargs.get(self.REGEX_IGNORE_CASE_KEY, True)
queryDict2 = self.convertStringsToRegex(queryDict2, ignoreCase)
return self.listToDmObjects(self.getFileCollection(experimentName).findByQueryDict(queryDict2, returnFieldDict), FileMetadata)
@DmMongoDbApi.executeDbCall
def getExperimentFileById(self, experimentName, id, **kwargs):
self.checkExperimentName(experimentName)
dbFileMetadata = self.getFileCollection(experimentName).findById(id)
return self.toDmObject(dbFileMetadata, FileMetadata)
@DmMongoDbApi.executeDbCall
def getExperimentFile(self, experimentName, experimentFilePath, **kwargs):
self.checkExperimentName(experimentName)
queryDict = { 'experimentFilePath' : experimentFilePath, 'experimentName' : experimentName }
dbFileMetadata = self.getFileCollection(experimentName).findByUniqueKeys(queryDict)
return self.toDmObject(dbFileMetadata, FileMetadata)
@DmMongoDbApi.executeDbCall
def updateExperimentFileById(self, fileInfo, **kwargs):
experimentName = self.getAndCheckExperimentName(fileInfo)
fileInfo2 = self.getMongoDict(fileInfo)
dbFileMetadata = self.getFileCollection(experimentName).updateById(fileInfo2)
return self.toDmObject(dbFileMetadata, FileMetadata)
@DmMongoDbApi.executeDbCall
def updateExperimentFile(self, fileInfo, **kwargs):
experimentName = self.getAndCheckExperimentName(fileInfo)
fileInfo2 = self.getMongoDict(fileInfo)
dbFileMetadata = self.getFileCollection(experimentName).updateByUniqueKeys(fileInfo2)
return self.toDmObject(dbFileMetadata, FileMetadata)
@DmMongoDbApi.executeDbCall
def updateOrAddExperimentFile(self, fileInfo, **kwargs):
experimentName = self.getAndCheckExperimentName(fileInfo)
fileInfo2 = self.getMongoDict(fileInfo)
dbFileMetadata = self.getFileCollection(experimentName).updateOrAddByUniqueKeys(fileInfo2)
return self.toDmObject(dbFileMetadata, FileMetadata)
#######################################################################
# Testing.
if __name__ == '__main__':
from dm.common.mongodb.impl.mongoDbManager import MongoDbManager
mgr = MongoDbManager.getInstance()
mgr.dbName = 'dm'
api = FileMongoDbApi()
experimentFilePath = 'file02'
experimentName = 'exp-01'
fileInfo = {'experimentFilePath' : experimentFilePath, 'intKey' : 1, 'doubleKey' : 2.0, 'stringKey' : 'myString' , 'experimentName' : experimentName}
file = api.updateOrAddExperimentFile(fileInfo)
print '\nADDED FILE\n', file
import time
t = long(time.time())
experimentFilePath = 'f-%s' % t
experimentName = 'exp-01'
fileInfo = {'experimentFilePath' : experimentFilePath, 'intKey' : 1, 'doubleKey' : 2.0, 'stringKey' : 'myString' , 'dictKey' : {'a' : 'A', 'b' : 'B', 'c' : 3}, 'experimentName' : experimentName}
file = api.updateOrAddExperimentFile(fileInfo)
print '\nADDED FILE\n', file
files = api.getFiles()
for file in files:
print 'FILE: %s\n' % file.getDictRep()
fileInfo = {'experimentFilePath' : experimentFilePath, 'experimentName' : experimentName, 'intKey' : 101}
file = api.updateExperimentFile(fileInfo)
print '\nUPDATED FILE\n', file
print '\nFILES FOR EXPERIMENT exp1: \n', api.getExperimentFiles(experimentName)
print '\nFILES FOR EXPERIMENT exp1 with experimentFilePath=file01: \n', api.getExperimentFiles(experimentName, queryDict={'experimentFilePath':'file02'})
#!/usr/bin/env python
import copy
import types
import re
from dm.common.exceptions.dmException import DmException
from dm.common.mongodb.api.dmMongoDbApi import DmMongoDbApi
from dm.common.mongodb.impl.workflowCollection import WorkflowCollection
from dm.common.mongodb.api.dmMongoDbApi import DmMongoDbApi
from dm.common.objects.workflow import Workflow
from dm.common.exceptions.invalidRequest import InvalidRequest
class WorkflowMongoDbApi(DmMongoDbApi):
SYSTEM_KEY_LIST = ['_id', 'name', 'owner']
def __init__(self):
DmMongoDbApi.__init__(self)
self.workflowCollectionDict = {}
def getWorkflowCollection(self, owner):
workflowCollection = self.workflowCollectionDict.get(owner)
if not workflowCollection:
workflowCollection = WorkflowCollection(self.dbClient, owner)
self.workflowCollectionDict[owner] = workflowCollection
return workflowCollection
@classmethod
def getAndCheckOwner(cls, dictObject):
owner = dictObject.get('owner')
cls.checkOwner(owner)
return owner
@classmethod
def checkOwner(cls, owner):
if not owner:
raise InvalidRequest('Owner name has not been provided.')
@DmMongoDbApi.executeDbCall
def addWorkflow(self, workflow, **kwargs):
owner = self.getAndCheckOwner(owner)
workflow2 = self.getMongoDict(workflow)
dbWorkflow = self.getWorkflowCollection(owner).addByUniqueKeys(workflow2)
return self.toDmObject(dbWorkflow, Workflow)
@DmMongoDbApi.executeDbCall
def getWorkflows(self, owner, queryDict={}, returnFieldDict=WorkflowCollection.ALL_FIELDS_DICT, **kwargs):
self.checkOwner(owner)
queryDict2 = self.getMongoDict(queryDict)
ignoreCase = kwargs.get(self.REGEX_IGNORE_CASE_KEY, True)
queryDict2 = self.convertStringsToRegex(queryDict2, ignoreCase)
return self.listToDmObjects(self.getWorkflowCollection(owner).findByQueryDict(queryDict2, returnFieldDict), Workflow)
@DmMongoDbApi.executeDbCall
def getWorkflowById(self, owner, id, **kwargs):
self.checkOwner(owner)
dbWorkflow = self.getWorkflowCollection(owner).findById(id)
return self.toDmObject(dbWorkflow, Workflow)
@DmMongoDbApi.executeDbCall
def getWorkflowByName(self, owner, name, **kwargs):
self.checkOwner(owner)
queryDict = { 'name' : name, 'owner' : owner }
dbWorkflow = self.getWorkflowCollection(owner).findByUniqueKeys(queryDict)
return self.toDmObject(dbWorkflow, Workflow)
@DmMongoDbApi.executeDbCall
def updateWorkflowById(self, workflow, **kwargs):
owner = self.getAndCheckOwner(workflow)
workflow2 = self.getMongoDict(workflow)
dbWorkflow = self.getWorkflowCollection(owner).updateById(workflow2)
return self.toDmObject(dbWorkflow, Workflow)
@DmMongoDbApi.executeDbCall
def updateWorkflow(self, workflow, **kwargs):
owner = self.getAndCheckOwner(workflow)
workflow2 = self.getMongoDict(workflow)
dbWorkflow = self.getWorkflowCollection(owner).updateByUniqueKeys(workflow2)
return self.toDmObject(dbWorkflow, Workflow)
@DmMongoDbApi.executeDbCall
def updateOrAddWorkflow(self, workflow, **kwargs):
owner = self.getAndCheckOwner(workflow)
workflow2 = self.getMongoDict(workflow)
dbWorkflow = self.getWorkflowCollection(owner).updateOrAddByUniqueKeys(workflow2)
return self.toDmObject(dbWorkflow, Workflow)
#######################################################################
# Testing.
if __name__ == '__main__':
from dm.common.mongodb.impl.mongoDbManager import MongoDbManager
mgr = MongoDbManager.getInstance()
mgr.dbName = 'dm'
api = WorkflowMongoDbApi()
workflows = api.getWorkflows('sveseli')
for workflow in workflows:
print 'WORKFLOW: %s\n' % workflow.getDictRep()
workflow = api.getWorkflowByName('sveseli', 'workflow-01')
print 'WORKFLOW: %s\n' % workflow.getDictRep()