def api_updateWorkLog():
    try : 
        # read the POST request payload
        inputJson = request.get_json(force=True) 
        app.logger.info('Info : write to worklog req received. payload: ' + str(inputJson)) 
        
        # Ethereum based producers list
        cop = ProducerOps('config.ini')
        updated, msg = cop.updateWorkLog(inputJson['wroklog'], inputJson['seasonID'], inputJson['cropID']) 
        #if worklog updated sucessfully
        if updated: 
            return prepareResponse({'message' :'SUCCESS'}, 200)
         # in case of any errors
        return prepareResponse({'message' :'unable to update worklog', 'info': msg}, 500) 
    except: 
        return prepareResponse({'message' :'unable to update worklog'}, 500)       
def api_updateInvestments():
    try : 
        # read the POST request payload
        inputJson = request.get_json(force=True) 
        app.logger.info('Info : update invetments req received. payload: ' + str(inputJson)) 
        
        # Ethereum based seasons list
        cop = ProducerOps('config.ini')
        updated, msg = cop.updateInvestments(inputJson['investment'], inputJson['seasonID'], inputJson['cropID']) 
        #if investments updated sucessfully
        if updated: 
            return prepareResponse({'message' :'SUCCESS'}, 200)
         # in case of any errors
        return prepareResponse({'message' :'unable to update invetments information', 'info': msg}, 500) 
    except: 
        return prepareResponse({'message' :'unable to update investment iformation'}, 500)       
def api_getAllCrops():
    try :
        # read the POST request payload
        inputjson = request.get_json(force=True)
        app.logger.info('Info : season crop lists request received ' + str(inputjson))
        
        # Ethereum based producers list
        cop = ProducerOps('config.ini')
        status, crops = cop.getAllCrops(inputjson['seasonID'])  
        # if successfully gets the list of crops
        if status:  
            return prepareResponse({'message' :'SUCCESS', 'result': crops}, 200)  
        # if there are any errors
        return prepareResponse({'message' :'unable to extract crops list'}, 500)
    except: 
        return prepareResponse({'message' :'unable to extract crops list'}, 500)  
def api_getCropSeasonByID():
    try :  
        # read the POST request payload
        inputjson = request.get_json(force=True)
        app.logger.info('Info : season information request received for '+ str(inputjson))
        
        # Ethereum based seasons list
        cop = ProducerOps('config.ini')
        exists, seasons = cop.getCropSeasonByID(inputjson['seasonID']) 
        # if seasons exists and gets his info
        if exists:
            return prepareResponse({'message' : 'SUCCESS', 'result': seasons}, 200) 
        # if there is any errors
        return prepareResponse({'message' : 'unable to extract season information'}, 500)
    except: 
        return prepareResponse({'message' : 'unable to extract season information'}, 500) 
def api_registerProducer():
    try : 
        # read the POST request payload
        inputJson = request.get_json(force=True) 
        app.logger.info('Info : producer registration req received. payload: ' + str(inputJson)) 
        
        # Ethereum based producers list
        cop = ProducerOps('config.ini')
        registered, msg = cop.registerProducer(inputJson['producer']) 
        #if producers registered sucessfully
        if registered: 
            return prepareResponse({'message' :'SUCCESS'}, 200)
         # in case of any errors
        return prepareResponse({'message' :'unable to register a producer', 'info': msg}, 500) 
    except: 
        return prepareResponse({'message' :'unable to register new producer'}, 500)
def api_registerCropSeason():
    try : 
        # read the POST request payload
        inputJson = request.get_json(force=True) 
        app.logger.info('Info : crops season registration req received. payload: ' + str(inputJson)) 
        
        # Ethereum based seasons list
        cop = ProducerOps('config.ini')
        print inputJson['season']
        registered, msg = cop.registerCropSeason(inputJson['season'])
        print msg
        #if season registered sucessfully
        if registered: 
            return prepareResponse({'message' :'SUCCESS'}, 200)
         # in case of any errors
        return prepareResponse({'message' :'unable to register a crop season', 'info': msg}, 500) 
    except: 
        return prepareResponse({'message' :'unable to register a crop season'}, 500)
    def __init__(self, confFile):

        # initialize and read the configuration
        self.confReader = ConfReader(confFile)
        self.database = str(
            self.confReader.GetConfigValue('configuration', 'agroChainDB'))
        self.collConsumers = str(
            self.confReader.GetConfigValue('collections', 'consumers'))
        self.collOrders = str(
            self.confReader.GetConfigValue('collections', 'orders'))
        # Create mongodb connection
        self.mongo = MongoDBServer(
            str(self.confReader.GetConfigValue('configuration',
                                               'mongosource')),
            int(self.confReader.GetConfigValue('configuration', 'mongoport')),
            '', '', True, False)
        # for all producer related operations
        self.ProdOps = ProducerOps(confFile)