コード例 #1
0
 def test_2_remove_child_node_from_objects(self):
     """ test_2 _remove_child_node_from_objects """
     objects = {
         "abc": {"id": "abc", "children": [{"id": "abc.a"}, {"id": "abc.b"}]},
         "abc.a": {"id": "abc.a", "title": "thing a"},
         "abc.b": {"id": "abc.b", "title": "thing b"}
     }
     clean_up_content_class = CleanUpCompositeJson({})
     fixed_objects = clean_up_content_class._remove_child_node_from_objects(objects, "abc.b")
     self.assertTrue("abc.b" not in fixed_objects)
コード例 #2
0
 def test_1_find_parent_child_relationships(self):
     """ test_1 _find_parent_child_relationships """
     objects = {
         "abc": {"id": "abc", "children": [{"id": "abc.a"}, {"id": "abc.b"}]},
         "abc.a": {"id": "abc.a", "title": "thing a"},
         "abc.b": {"id": "abc.b", "title": "thing b"}
     }
     clean_up_content_class = CleanUpCompositeJson({})
     families_array = clean_up_content_class._find_parent_child_relationships(objects)
     expected_object = [{'parentId': 'abc', 'childId': 'abc.a', 'sequence': 0}, {'parentId': 'abc', 'childId': 'abc.b', 'sequence': 0}]
     self.assertEqual(families_array, expected_object)
コード例 #3
0
 def test_4_fix_parent_child_relationships(self):
     """ test_4 _fix_parent_child_relationships """
     objects = {
         "abc": {"id": "abc", "children": [{"id": "abc.a"}, {"id": "abc.b"}]},
         "abc.a": {"id": "abc.a", "title": "thing a"},
         "abc.b": {"id": "abc.b", "title": "thing b"}
     }
     clean_up_content_class = CleanUpCompositeJson({})
     fixed_objects = clean_up_content_class._fix_parent_child_relationships(objects)
     expected_object = {'abc': {'hierarchySearchable': False, 'id': 'abc', 'items': [{'id': 'abc.a', 'title': 'thing a', 'sequence': 0}, {'id': 'abc.b', 'title': 'thing b', 'sequence': 0}]}}
     self.assertEqual(fixed_objects, expected_object)
コード例 #4
0
 def test_5_clean_up_composite_json(self):
     """ test_5 _clean_up_composite_json """
     composite_json = {
         "objects":
             {
                 "abc": {"id": "abc", "children": [{"id": "abc.a"}, {"id": "abc.b"}]},
                 "abc.a": {"id": "abc.a", "title": "thing a"},
                 "abc.b": {"id": "abc.b", "title": "thing b"}
             }
     }
     clean_up_content_class = CleanUpCompositeJson({})
     fixed_composite_json = clean_up_content_class._clean_up_composite_json(composite_json)
     expected_composite_json = {'objects': {'abc': {'hierarchySearchable': False, 'id': 'abc', 'items': [{'id': 'abc.a', 'title': 'thing a', 'sequence': 0}, {'id': 'abc.b', 'title': 'thing b', 'sequence': 0}]}}}
     self.assertEqual(fixed_composite_json, expected_composite_json)
コード例 #5
0
 def test_8_cleaned_up_content_searchable(self):
     """ test_8_cleaned_up_content_searchable """
     composite_json = {
         "objects":
             {
                 "abc": {"id": "abc", "children": [{"id": "abc.1"}, {"id": "abc.2"}]},
                 "abc.1": {"id": "abc.1", "title": "thing a"},
                 "abc.2": {"id": "abc.2", "title": "thing b"}
             }
     }
     fixed_composite_json = CleanUpCompositeJson(composite_json).cleaned_up_content
     expected_composite_json = {'objects': {'abc': {'hierarchySearchable': True, 'id': 'abc', 'items': [{'id': 'abc.1', 'title': 'thing a', 'sequence': 0}, {'id': 'abc.2', 'title': 'thing b', 'sequence': 0}]}}}
     self.assertEqual(fixed_composite_json, expected_composite_json)
コード例 #6
0
def run(event, _context):
    """ run the process to retrieve and process web kiosk metadata """
    _suplement_event(event)
    config = setup_pipeline_config(event)
    google_config = load_config_ssm(config['google_keys_ssm_base'])
    config.update(google_config)
    museum_config = load_config_ssm(config['museum_keys_ssm_base'])
    config.update(museum_config)
    time_to_break = datetime.now() + timedelta(
        seconds=config['seconds-to-allow-for-processing'])
    print("Will break after ", time_to_break)

    mode = event.get("mode", "full")
    if mode not in ["full", "incremental", "ids"]:
        mode = "full"
    json_web_kiosk_class = ProcessWebKioskJsonMetadata(config, event,
                                                       time_to_break)
    if event["museumExecutionCount"] == 1:
        if not event.get('local'):
            save_file_system_record(config.get('website-metadata-tablename'),
                                    'Google', 'Museum')
            save_source_system_record(config.get('website-metadata-tablename'),
                                      'EmbARK')
        composite_json = json_web_kiosk_class.get_composite_json_metadata(mode)
        museum_image_metadata = json_web_kiosk_class.find_images_for_composite_json_metadata(
            composite_json)
        composite_json = CleanUpCompositeJson(
            composite_json).cleaned_up_content
        event['countToProcess'] = len(composite_json.get('objects'))
        write_s3_json(config['process-bucket'],
                      'museum_composite_metadata.json', composite_json)
        write_s3_json(config['process-bucket'], 'museum_image_metadata.json',
                      museum_image_metadata)
    else:
        composite_json = read_s3_json(config['process-bucket'],
                                      'museum_composite_metadata.json')
        museum_image_metadata = read_s3_json(config['process-bucket'],
                                             'museum_image_metadata.json')

    if composite_json:
        objects_processed = json_web_kiosk_class.process_composite_json_metadata(
            composite_json, museum_image_metadata)
        event['museumHarvestComplete'] = _done_processing(composite_json)
    else:
        print('No JSON to process')

    if event["museumExecutionCount"] >= event["maximumMuseumExecutions"]:
        event['museumHarvestComplete'] = True
    if event['museumHarvestComplete']:
        if s3_file_exists(config['process-bucket'],
                          'museum_composite_metadata.json'):
            delete_s3_key(config['process-bucket'],
                          'museum_composite_metadata.json')
        if s3_file_exists(config['process-bucket'],
                          'museum_image_metadata.json'):
            delete_s3_key(config['process-bucket'],
                          'museum_image_metadata.json')
    elif composite_json:
        write_s3_json(config['process-bucket'],
                      'museum_composite_metadata.json', composite_json)
        key = 'countHarvestedLoop' + str(event["museumExecutionCount"])
        event[key] = objects_processed
    event['countRemaining'] = len(composite_json.get('objects'))
    return event