Beispiel #1
0
 def test_getServiceIdByName_func(self):
     collection = getDbObject(TEST_DB)["services"]
     obj = collection.find_one({"_id": TEST_ID})
     print('Test object: ' + unicode(obj))
     try:
         getServiceIdByName('testservice')
     except ServiceNotExistException:
         self.assertTrue(False)
     with self.assertRaises(ServiceNotExistException):
         getServiceIdByName('OlchikovTestService')
Beispiel #2
0
 def test_getServiceIdByName_func(self):
     collection = getDbObject(TEST_DB)["services"]
     obj = collection.find_one({"_id": TEST_ID})
     print('Test object: ' + unicode(obj))
     try:
         getServiceIdByName('testservice')
     except ServiceNotExistException:
         self.assertTrue(False)
     with self.assertRaises(ServiceNotExistException):
         getServiceIdByName('OlchikovTestService')
        def post(self, serviceName):
            importDataDict = parserClass.parsePostParameters()
            channelName = importDataDict.get('channelName')
            getServiceIdByName(serviceName)
            getChannelByName(serviceName, channelName)
            job = jobClass(importFunction, importDataDict.get('channelName'),
                           importDataDict.get('openDataUrl'), importDataDict,
                           serviceName)

            return JobManager.startJob(job)
Beispiel #4
0
def geocoderImport(self, channelName, serviceName):
    # Checking for service existence
    getServiceIdByName(serviceName)
    # Getting channel id
    channel = getChannelByName(serviceName, channelName)
    channel_id = channel[ID]
    # Initialising requester and parser
    greqv = GeonamesRequestSender()
    gpars = GeocoderResponseParser()
    # Getting points collection
    points_coll = getDbObject(serviceName)[POINTS_COLL]
    # Getting first slice of <= 5000 points
    proc_step = 0
    point_block = list(points_coll.find({
        CHANNEL_ID: channel_id,
        JSON + '.' + ADDRESS: {"$exists": True}
    }).skip(proc_step).limit(PROC_BLOCK))
    login = PluginConfigReader(PLUGIN_NAME).getConfigContent()[
        SECTION_GEOCODING][GEONAMES_LOGIN]
    while point_block:
        current_size = len(point_block)
        addresses = [point[JSON][ADDRESS] for point in point_block]
        ids = [point[ID] for point in point_block]
        string_addresses = greqv.requestCoordinates(
            addresses,
            login,
            json_list_to_list_of_strings)
        json_coords = gpars.parseList(string_addresses)
        for i in range(0, current_size):
            # If no coords was found - we change nothing
            if json_coords[i] is None:
                continue
            points_coll.update(
                {ID: ids[i]},
                {'$set': {'location.coordinates': json_coords[i]}}
            )
        # Getting next slice of <= 5000 points
        proc_step += PROC_BLOCK
        point_block = list(
            points_coll.find().skip(proc_step).limit(PROC_BLOCK))
    # Task is done
    self.done = True
    # And thread is done too after return
    return []
Beispiel #5
0
 def get(self, serviceName, jobId):
     getServiceIdByName(serviceName)
     return JobManager.getJob(jobId)
Beispiel #6
0
 def delete(self, serviceName, jobId):
     getServiceIdByName(serviceName)
     return JobManager.stopJob(jobId)
Beispiel #7
0
 def get(self, serviceName):
     getServiceResult = getServiceIdByName(serviceName)
     return getServiceResult
Beispiel #8
0
 def testRemoveService(self):
     db[COLLECTION].save({NAME: TEST_OBJECT})
     removeService(TEST_OBJECT)
     with self.assertRaises(ServiceNotExistException):
         getServiceIdByName(TEST_OBJECT)
 def testRemoveService(self):
     db[COLLECTION].save({NAME: TEST_OBJECT})
     removeService(TEST_OBJECT)
     with self.assertRaises(ServiceNotExistException):
         getServiceIdByName(TEST_OBJECT)
Beispiel #10
0
 def get(self, serviceName):
     getServiceResult = getServiceIdByName(serviceName)
     return getServiceResult
 def get(self, serviceName):
     getServiceIdByName(serviceName)
     return JobManager.getJobs()