コード例 #1
0
 def post(self, id):
     """
     Creates a new draft from an existing harvest item.
     """
     try:
         harvest = Harvest.query.filter(Harvest.id == id).one()
         actions.create_draft_from_item(harvest)
         actions.delete_harvested_item(harvest.id)
     except NoResultFound:
         return {
             'success': False,
             'message': {
                 'code': 404,
                 'description': 'Harvest item not found.'
             }
         }, 404
     except IntegrityError:
         return {
             'success': False,
             'message': {
                 'code': 400,
                 'description': 'Draft for this harvested item already exists.'
             }
         }, 400
     return {
         'success': True,
         'message': {
             'code': 200,
             'description': 'Draft successfully created.'
         }
     }, 200
コード例 #2
0
def harvest(url, harvester='csw'):
    result = requests.get(url)
    if harvester == 'opertusmundi':
        items = result.json().get('result').get('items')
        new_items = _from_op_catalogue(items, url)
    elif harvester == 'ckan':
        items = result.json().get('result').get('results')
        new_items = _from_ckan(items, url)
    elif harvester == 'csw':
        new_items = _from_csw(url)

    harvests = Harvest.query
    harvested_ids = []

    for data in new_items:
        id = data.get('id')
        harvest = harvests.filter(Harvest.id == id).first()
        if not harvest:
            log.info('Harvesting item %s', id)
            actions.create_harvested_item(data)
        # update if it exists
        else:
            actions.update_harvested_item(harvest, data)
        harvested_ids.append(id)
    # delete any existing harvested data deleted in remote
    harvests = harvests.filter(Harvest.harvested_from == url)
    for harvest in (h for h in harvests if h.id not in harvested_ids):
        log.debug('Deleting harvest %s', harvest.id)
        actions.delete_harvested_item(harvest.id)

    return len(new_items)
コード例 #3
0
 def delete(self, id):
     """
     Deletes a item.
     """
     try:
         actions.delete_harvested_item(id)
     except:
         return {
             'success': False,
             'message': {
                 'code': 404,
                 'description': 'Harvested item not found'
             }
         }, 404
     return {
         'success': True,
         'message': {
             'code': 200,
             'description': 'Harvested item successfully deleted.'
         }
     }, 200
コード例 #4
0
 def delete(self, id):
     """
     Deletes a harvested item.
     """
     try:
         actions.delete_harvested_item(id)
     except Exception as ex:
         current_app.logger.error('Harvested item delete failed: ' +
                                  str(ex))
         return {
             'success': False,
             'message': {
                 'code': 404,
                 'description': 'Harvested item delete faled: ' + str(ex)
             }
         }, 404
     return {
         'success': True,
         'message': {
             'code': 200,
             'description': 'Harvested item successfully deleted.'
         }
     }, 200