Beispiel #1
0
 def get_type_title(self, obj):
     """Get type title."""
     try:
         return ObjectType.get_by_dict(obj['upload_type'])['title']['en']
     except Exception:
         from flask import current_app
         current_app.logger.exception("Failed object {}".format(obj['upload_type']))
         raise
Beispiel #2
0
def is_openaire_publication(record):
    """Determine if record is a publication for OpenAIRE."""
    oatype = ObjectType.get_by_dict(record.get('resource_type')).get(
        'openaire', {})
    if not oatype or oatype['type'] != _OAType.publication:
        return False

    # Has grants, is part of ecfunded community or is open access.
    if record.get('grants') or 'ecfunded' in record.get('communities', []) or \
            'open' == record.get('access_right'):
        return True
    return False
Beispiel #3
0
def is_openaire_publication(record):
    """Determine if record is a publication for OpenAIRE."""
    oatype = ObjectType.get_by_dict(record.get('resource_type')).get(
        'openaire', {})
    if not oatype or oatype['type'] != _OAType.publication:
        return False

    # Has grants, is part of ecfunded community or is open access.
    if record.get('grants') or 'ecfunded' in record.get('communities', []) or \
            'open' == record.get('access_right'):
        return True
    return False
Beispiel #4
0
    def validate_data(self, obj):
        """Validate resource type."""
        type_ = obj.get('resource_type.type')
        if type_ in ['publication', 'image']:
            type_dict = {
                'type': type_,
                'subtype': obj.get('resource_type.subtype'),
            }
            field_names = ['{0}_type'.format(type_)]
        else:
            type_dict = {'type': type_}
            field_names = ['upload_type']

        if ObjectType.get_by_dict(type_dict) is None:
            raise ValidationError(
                _('Invalid upload, publication or image type.'),
                field_names=field_names,
            )
Beispiel #5
0
    def validate_data(self, obj):
        """Validate resource type."""
        type_ = obj.get('resource_type.type')
        if type_ in ['publication', 'image']:
            type_dict = {
                'type': type_,
                'subtype': obj.get('resource_type.subtype'),
            }
            field_names = ['{0}_type'.format(type_)]
        else:
            type_dict = {'type': type_}
            field_names = ['upload_type']

        if ObjectType.get_by_dict(type_dict) is None:
            raise ValidationError(
                _('Invalid upload, publication or image type.'),
                field_names=field_names,
            )
Beispiel #6
0
    def validate_data(self, obj):
        """Validate resource type."""
        type_ = obj.get('resource_type', {}).get('type')
        if type_ in ['publication', 'image']:
            type_dict = {
                'type': type_,
                'subtype': obj.get('resource_type', {}).get('subtype')
            }
            field_names = ['{0}_type'.format(type_)]
        else:
            type_dict = {'type': type_}
            field_names = ['upload_type']

        if ObjectType.get_by_dict(type_dict) is None:
            raise ValidationError(
                _('Invalid upload, publication or image type.'),
                field_names=field_names,
            )
        if not is_valid_openaire_type(obj.get('resource_type', {}),
                                      obj.get('communities', [])):
            raise ValidationError(
                _('Invalid OpenAIRE subtype.'),
                field_names=['openaire_subtype'],
            )
Beispiel #7
0
    def validate_data(self, obj):
        """Validate resource type."""
        type_ = obj.get('resource_type', {}).get('type')
        if type_ in ['publication', 'image']:
            type_dict = {
                'type': type_,
                'subtype': obj.get('resource_type', {}).get('subtype')
            }
            field_names = ['{0}_type'.format(type_)]
        else:
            type_dict = {'type': type_}
            field_names = ['upload_type']

        if ObjectType.get_by_dict(type_dict) is None:
            raise ValidationError(
                _('Invalid upload, publication or image type.'),
                field_names=field_names,
            )
        if not is_valid_openaire_type(obj.get('resource_type', {}),
                                      obj.get('communities', [])):
            raise ValidationError(
                _('Invalid OpenAIRE subtype.'),
                field_names=['openaire_subtype'],
            )
Beispiel #8
0
 def _get_schema_class(self, obj):
     data = obj['metadata']
     obj_type = ObjectType.get_by_dict(data['resource_type'])
     return getattr(schemas, obj_type['schema.org'][19:])
Beispiel #9
0
 def _openaire_type(self, obj):
     return ObjectType.get_by_dict(
         obj.get('metadata', {}).get('resource_type')
     ).get('openaire')
Beispiel #10
0
 def get_type(self, obj):
     """Get record CSL type."""
     metadata = obj['metadata']
     obj_type = ObjectType.get_by_dict(metadata.get('resource_type'))
     return obj_type.get('csl', missing) if obj_type else missing
Beispiel #11
0
def is_openaire_other(record):
    """Determine if the record has type 'other' for OpenAIRE."""
    oatype = ObjectType.get_by_dict(record.get('resource_type')).get(
        'openaire', {})
    return oatype and oatype['type'] == _OAType.other
Beispiel #12
0
def is_openaire_software(record):
    """Determine if the record is a software for OpenAIRE."""
    oatype = ObjectType.get_by_dict(record.get('resource_type')).get(
        'openaire', {})
    return oatype and oatype['type'] == _OAType.software
Beispiel #13
0
def is_openaire_dataset(record):
    """Determine if record is a dataset for OpenAIRE."""
    oatype = ObjectType.get_by_dict(record.get('resource_type')).get(
        'openaire', {})
    return oatype and oatype['type'] == _OAType.dataset
Beispiel #14
0
def is_openaire_other(record):
    """Determine if the record has type 'other' for OpenAIRE."""
    oatype = ObjectType.get_by_dict(record.get('resource_type')).get(
        'openaire', {})
    return oatype and oatype['type'] == _OAType.other
Beispiel #15
0
 def _get_schema_class(self, obj):
     data = obj['metadata']
     obj_type = ObjectType.get_by_dict(data['resource_type'])
     return getattr(schemas, obj_type['schema.org'][19:])
Beispiel #16
0
def is_openaire_software(record):
    """Determine if the record is a software for OpenAIRE."""
    oatype = ObjectType.get_by_dict(record.get('resource_type')).get(
        'openaire', {})
    return oatype and oatype['type'] == _OAType.software
Beispiel #17
0
 def get_type(self, obj):
     """Get record CSL type."""
     metadata = obj['metadata']
     obj_type = ObjectType.get_by_dict(metadata.get('resource_type'))
     return obj_type.get('csl', 'article') if obj_type else 'article'
Beispiel #18
0
def is_openaire_dataset(record):
    """Determine if record is a dataset for OpenAIRE."""
    oatype = ObjectType.get_by_dict(record.get('resource_type')).get(
        'openaire', {})
    return oatype and oatype['type'] == _OAType.dataset
Beispiel #19
0
 def _openaire_type(self, obj):
     return ObjectType.get_by_dict(
         obj.get('metadata', {}).get('resource_type')).get('openaire')