Example #1
0
    def _publish(self, envelopData):
        if isinstance(envelopData,unicode):
            envelopeData = json.loads(envelopData)
            
        result={self.__OK: True}

        try:
            # Set the envelop data timestaps.
            timeStamp = h. nowToISO8601Zformat()
            for stamp in ResourceDataModel._TIME_STAMPS:
                    envelopData[stamp] = timeStamp
                    
            resourceData = ResourceDataModel(envelopData)
            #Check if the envelop get filtered out
            isFilteredOut, reason = self._isResourceDataFilteredOut(resourceData)
            if isFilteredOut:
                result[self.__ERROR] = reason
            else:
                resourceData.publishing_node = LRNode.nodeDescription.node_id
                resourceData.save()
                result[resourceData._DOC_ID] = resourceData.doc_ID 
                 
        except SpecValidationException as ex:
            log.exception(ex)
            result[self.__ERROR]  = "\n"+pprint.pformat(str(ex), indent=4)
        except Exception as ex:
            log.exception(ex)
            result[self.__ERROR]  = "internal error"
            
        if result.has_key(self.__ERROR):
            result[self.__OK] = False
        
        return result
Example #2
0
    def _publish(self, envelopData):
        if isinstance(envelopData, unicode):
            envelopeData = json.loads(envelopData)

        result = {self.__OK: True}

        try:
            # Set the envelop data timestaps.
            timeStamp = h.nowToISO8601Zformat()
            for stamp in ResourceDataModel._TIME_STAMPS:
                envelopData[stamp] = timeStamp

            resourceData = ResourceDataModel(envelopData)
            #Check if the envelop get filtered out
            isFilteredOut, reason = self._isResourceDataFilteredOut(
                resourceData)
            if isFilteredOut:
                result[self.__ERROR] = reason
            else:
                resourceData.publishing_node = LRNode.nodeDescription.node_id
                resourceData.save()
                result[resourceData._DOC_ID] = resourceData.doc_ID

        except SpecValidationException as ex:
            log.exception(ex)
            result[self.__ERROR] = "\n" + pprint.pformat(str(ex), indent=4)
        except Exception as ex:
            log.exception(ex)
            result[self.__ERROR] = "internal error"

        if result.has_key(self.__ERROR):
            result[self.__OK] = False

        return result
 def handleDocument(newDoc):
     should_delete = True
     try:
         newDoc['node_timestamp'] = h.nowToISO8601Zformat()
         rd = ResourceDataModel(newDoc)
         rd.save(log_exceptions=False)
     except SpecValidationException as e:
         log.error(newDoc['_id'] + str(e))
     except ResourceConflict:
         log.error('conflict')
     except Exception as ex:
         should_delete = False  # don't delete something unexpected happend
         log.error(ex)
     if should_delete:
         try:
             del database[newDoc['_id']]
         except Exception as ex:
             log.error(ex)
	def _handle(self, change, database):
		should_delete = True
		try:
			log.debug('got here')
			newDoc = change[_DOC]
			newDoc['node_timestamp'] = h.nowToISO8601Zformat()
			rd = ResourceDataModel(newDoc)
			rd.save(log_exceptions=False)				
		except SpecValidationException:
			log.error(str(newDoc) + " Fails Validation" )
		except ResourceConflict:
			pass #ignore conflicts
		except Exception as ex:
			should_delete = False # don't delete something unexpected happend
			log.error(ex)
		if should_delete:
			try:
				del database[change[_ID]]
			except Exception as ex:
				log.error(ex)