Exemplo n.º 1
0
 def _get_experiment_metadata(self, experiment, metadataPrefix):
     return Metadata(
         experiment, {
             '_writeMetadata': oai_dc_writer,
             'title': [experiment.title],
             'description': [experiment.description],
         })
Exemplo n.º 2
0
    def _get_experiment_metadata(self, experiment, metadataPrefix):
        license_ = experiment.license or License.get_none_option_license()
        # Access Rights statement
        access_type = None
        if experiment.public_access == Experiment.PUBLIC_ACCESS_METADATA:
            access = "Only metadata is publicly available online." + \
                    " Requests for further access should be directed to a" + \
                    " listed data manager."
            access_type = "restricted"
        else:
            access = "All data is publicly available online."
            access_type = "open"

        def get_related_info(ps):
            psm = ParameterSetManager(ps)
            parameter_names = ['type', 'identifier', 'title', 'notes']
            try:
                parameters = {
                    key: psm.get_param(key, True)
                    for key in parameter_names
                }
                parameters['id'] = ps.id
                return parameters
            except ExperimentParameter.DoesNotExist:
                return dict()  # drop Related_Info record with missing fields

        ns = 'http://ands.org.au/standards/rif-cs/registryObjects#relatedInfo'
        related_info = map(
            get_related_info,
            ExperimentParameterSet.objects.filter(experiment=experiment,
                                                  schema__namespace=ns))

        def get_subject(ps, type_):
            psm = ParameterSetManager(ps)
            return {'text': psm.get_param('code', True), 'type': type_}

        ns = 'http://purl.org/asc/1297.0/2008/for/'
        subjects = [
            get_subject(ps, 'anzsrc-for')
            for ps in ExperimentParameterSet.objects.filter(
                experiment=experiment, schema__namespace=ns)
        ]
        collectors = experiment.experimentauthor_set.exclude(url='')
        return Metadata(
            experiment,
            {
                '_writeMetadata': self._get_experiment_writer_func(),
                'id': experiment.id,
                'title': experiment.title,
                'description': experiment.description,
                # Note: Property names are US-spelling, but RIF-CS is Australian
                'licence_name': license_.name,
                'licence_uri': license_.url,
                'access': access,
                'access_type': access_type,
                'collectors': collectors,
                'managers': experiment.get_owners(),
                'related_info': related_info,
                'subjects': subjects
            })
Exemplo n.º 3
0
    def __call__(self, element):
        map = {}
        # create XPathEvaluator for this element
        xpath_evaluator = etree.XPathEvaluator(element,
                                               namespaces=self._namespaces)

        e = xpath_evaluator.evaluate
        # now extra field info according to xpath expr
        for field_name, (field_type, expr) in self._fields.items():
            if field_type == 'bytes':
                value = str(e(expr))
            elif field_type == 'bytesList':
                value = [str(item) for item in e(expr)]
            elif field_type == 'text':
                # make sure we get back unicode strings instead
                # of lxml.etree._ElementUnicodeResult objects.
                value = unicode(e(expr))
            elif field_type == 'textList':
                # make sure we get back unicode strings instead
                # of lxml.etree._ElementUnicodeResult objects.
                value = [unicode(v) for v in e(expr)]
            elif field_type == 'firstText':
                value = e(expr)
                if isinstance(value, list):
                    if len(value) > 0:
                        value = unicode(value[0])
                    else:
                        value = None
                else:
                    value = unicode(value)
            elif field_type == 'lxmlelement':
                if expr is not None:
                    value = e(expr)
                    if isinstance(value, list):
                        if len(value) > 0:
                            value = value[0]
                        else:
                            value = None
                else:
                    value = element
            elif field_type == 'xmlstring':
                value = e(expr)
                if isinstance(value, list):
                    if len(value) > 0:
                        value = etree.tostring(value[0], encoding="UTF-8")
                    else:
                        value = None
                else:
                    value = etree.tostring(value, encoding="UTF-8")
            elif isinstance(field_type, MetadataReader):
                value = e(expr)
                if isinstance(value, list):
                    value = [field_type(v) for v in value]
                else:
                    value = field_type(value)
            else:
                raise "Unknown field type: %s" % field_type
            map[field_name] = value
        return Metadata(map)
 def _get_experiment_metadata(self, experiment, metadataPrefix):
     return Metadata({
         '_writeMetadata': lambda e, m: oai_dc_writer(e, m),
         'title': [experiment.title],
         'description': [experiment.description],
         'identifier': [str(experiment.id)],
         'creator': str(experiment.created_by.id)
     })
Exemplo n.º 5
0
 def _get_user_metadata(self, user, metadataPrefix):
     owns_experiments = Experiment.safe.owned_by_user_id(user.id)\
                                       .exclude(public_access=Experiment.PUBLIC_ACCESS_NONE)
     return Metadata({
         '_writeMetadata': self._get_user_writer_func(),
         'id': user.id,
         'email': user.email,
         'given_name': user.first_name,
         'family_name': user.last_name,
         'owns_experiments': owns_experiments,
     })