Exemplo n.º 1
0
    def get_aggs(self, obj_list):
        """Apply aggregations transformation."""
        aggs = obj_list.get("aggregations")
        if not aggs:
            return missing

        for name, agg in aggs.items():
            # Aggregation key/name must match vocabulary id.
            vocab = Vocabularies.get_vocabulary(name)
            if not vocab:
                continue

            buckets = agg.get('buckets')
            if buckets:
                apply_labels(vocab, buckets)

        # FIXME: This is hardcoded because vocabularies has not been
        # fully migrated. Ideally all would be treated equally in the for
        # loop above.
        # languages = aggs.get("languages")

        # if languages:
        #     languages["buckets"] = serialize_vocabulary(
        #         "languages", languages["buckets"])

        return aggs
Exemplo n.º 2
0
    def get_aggs(self, obj_list):
        """Apply aggregations transformation."""
        aggs = obj_list.get("aggregations")
        if not aggs:
            return missing

        for name, agg in aggs.items():
            # Aggregation key/name must match vocabulary id.
            vocab = Vocabularies.get_vocabulary(name)
            if not vocab:
                continue

            buckets = agg.get('buckets')
            if buckets:
                apply_labels(vocab, buckets)

        # TODO: temporary hack until vocabularies can be fixed
        is_published_agg = aggs.get('is_published')
        if is_published_agg:
            for b in is_published_agg.get('buckets', []):
                if b.get('key') == 1:
                    b['label'] = _("Published")
                elif b.get('key') == 0:
                    b['label'] = _("New")

        # FIXME: This is hardcoded because vocabularies has not been
        # fully migrated. Ideally all would be treated equally in the for
        # loop above.
        # languages = aggs.get("languages")

        # if languages:
        #     languages["buckets"] = serialize_vocabulary(
        #         "languages", languages["buckets"])

        return aggs
Exemplo n.º 3
0
 def get_type(self, obj):
     """Get resource type."""
     resource_type = obj["metadata"]["resource_type"]
     vocabulary = Vocabularies.get_vocabulary('resource_type')
     entry = vocabulary.get_entry_by_dict(resource_type)
     return {
         'resourceTypeGeneral': entry.get("datacite_general", "Other"),
         'resourceType': entry.get("datacite_type", "Other"),
     }
Exemplo n.º 4
0
    def vocabulary_title(dict_key, vocabulary_key, alt_key=None):
        """Returns formatted vocabulary-corresponding human-readable string.

        In some cases the dict needs to be reconstructed. `alt_key` will be the
        key while `dict_key` will become the value.
        """
        if alt_key:
            dict_key = {alt_key: dict_key}
        vocabulary = Vocabularies.get_vocabulary(vocabulary_key)
        return vocabulary.get_title_by_dict(dict_key) if vocabulary else ""
Exemplo n.º 5
0
    def get_aggs(self, obj_list):
        """Apply aggregations transformation."""
        aggs = obj_list.get("aggregations")
        if not aggs:
            return missing

        for name, agg in aggs.items():
            # Aggregation key/name must match vocabulary id.
            vocab = Vocabularies.get_vocabulary(name)
            if not vocab:
                continue

            buckets = agg.get('buckets')
            if buckets:
                apply_labels(vocab, buckets)

        return aggs
Exemplo n.º 6
0
    def _serialize_ui_options_from_vocabulary(self,
                                              vocabulary_name,
                                              top_bucket_key=None):
        """Creates UI facet label options from RDM vocabularies.

        :params top_bucket_key: Key used for nested buckets to indicate
                                the top level aggregation.
        """
        ui_options = {}
        vocabulary = Vocabularies.get_vocabulary(
            vocabulary_name).dump_options()
        if type(vocabulary) is dict:
            ui_options[top_bucket_key] = {}
            for key in vocabulary.keys():
                for option in vocabulary[key]:
                    ui_options[top_bucket_key][option['value']] = \
                        str(option['text'])
        else:
            for option in vocabulary:
                ui_options[option['value']] = str(option['text'])
        return ui_options
Exemplo n.º 7
0
 def vocabulary(self):
     """Get the vocabulary."""
     return Vocabularies.get_vocabulary(self.vocabulary_name)