Example #1
0
    def get_statement(self, refresh=False):
        if not refresh and self._statement:
            return self._statement

        if not self.dataverse:
            raise NoContainerError('This dataset has not been added to a Dataverse.')

        if not self.statement_uri:
            # Try to find statement uri without a request to the server
            link = get_element(
                self.get_entry(),
                tag='link',
                attribute='rel',
                attribute_value='http://purl.org/net/sword/terms/statement',
            )
            if link is None:
                # Find link with request to server
                link = get_element(
                    self.get_entry(refresh=True),
                    tag='link',
                    attribute='rel',
                    attribute_value='http://purl.org/net/sword/terms/statement',
                )
            self.statement_uri = link.get('href')

        resp = requests.get(self.statement_uri, auth=self.connection.auth)

        if resp.status_code != 200:
            raise ConnectionError('Statement could not be retrieved.')

        self._statement = resp.content
        return self._statement
Example #2
0
    def get_statement(self, refresh=False):
        if not refresh and self._statement:
            return self._statement

        if not self.dataverse:
            raise NoContainerError(
                'This dataset has not been added to a Dataverse.')

        if not self.statement_uri:
            # Try to find statement uri without a request to the server
            link = get_element(
                self.get_entry(),
                tag='link',
                attribute='rel',
                attribute_value='http://purl.org/net/sword/terms/statement',
            )
            if link is None:
                # Find link with request to server
                link = get_element(
                    self.get_entry(refresh=True),
                    tag='link',
                    attribute='rel',
                    attribute_value='http://purl.org/net/sword/terms/statement',
                )
            self.statement_uri = link.get('href')

        resp = requests.get(self.statement_uri, auth=self.connection.auth)

        if resp.status_code != 200:
            raise ConnectionError('Statement could not be retrieved.')

        self._statement = resp.content
        return self._statement
Example #3
0
 def test_init_from_xml(self):
     dataset = Dataset.from_xml_file(ATOM_DATASET)
     title = utils.get_element(dataset.get_entry(),
                               namespace='dcterms',
                               tag='title').text
     publisher = utils.get_element(dataset.get_entry(),
                                   namespace='dcterms',
                                   tag='rights').text
     assert title == 'Roasting at Home'
     assert publisher == 'Creative Commons CC-BY 3.0 (unported) http://creativecommons.org/licenses/by/3.0/'
Example #4
0
 def test_init(self):
     dataset = Dataset(title='My Dataset', publisher='Mr. Pub Lisher')
     title = utils.get_element(dataset._entry,
                               namespace='dcterms',
                               tag='title').text
     publisher = utils.get_element(dataset._entry,
                                   namespace='dcterms',
                                   tag='publisher').text
     assert title == 'My Dataset'
     assert title == dataset.title
     assert publisher == 'Mr. Pub Lisher'
 def test_get_element(self):
     with open(ATOM_DATASET) as f:
         entry = f.read()
     # One value
     title = utils.get_element(entry, 'title', 'dcterms').text
     self.assertEqual(title, 'Roasting at Home')
     # Two values
     creator = utils.get_element(entry, 'creator', 'dcterms').text
     self.assertEqual(creator, 'Peets, John')
     # No values
     nonsense = utils.get_element(entry, 'nonsense', 'booga')
     self.assertIsNone(nonsense)
 def test_get_element(self):
     with open(ATOM_STUDY) as f:
         entry = f.read()
     # One value
     title = utils.get_element(entry, 'title', 'dcterms').text
     self.assertEqual(title, 'Roasting at Home')
     # Two values
     creator = utils.get_element(entry, 'creator', 'dcterms').text
     self.assertEqual(creator, 'Peets, John')
     # No values
     nonsense = utils.get_element(entry, 'nonsense', 'booga')
     self.assertIsNone(nonsense)
 def test_init_from_xml(self):
     dataset = Dataset.from_xml_file(ATOM_DATASET)
     title = utils.get_element(
         dataset.get_entry(),
         namespace='dcterms',
         tag='title'
     ).text
     publisher = utils.get_element(
         dataset.get_entry(),
         namespace='dcterms',
         tag='rights'
     ).text
     self.assertEqual(title, 'Roasting at Home')
     self.assertEqual(publisher, 'Creative Commons CC-BY 3.0 (unported) http://creativecommons.org/licenses/by/3.0/')
 def test_init_from_xml(self):
     study = Study.from_xml_file(ATOM_STUDY)
     title = utils.get_element(
         study.get_entry(),
         namespace='dcterms',
         tag='title'
     ).text
     publisher = utils.get_element(
         study.get_entry(),
         namespace='dcterms',
         tag='rights'
     ).text
     self.assertEqual(title, 'Roasting at Home')
     self.assertEqual(publisher, 'Creative Commons CC-BY 3.0 (unported) http://creativecommons.org/licenses/by/3.0/')
 def test_init(self):
     study = Study(title='My Study', publisher='Mr. Pub Lisher')
     title = utils.get_element(
         study._entry,
         namespace='dcterms',
         tag='title'
     ).text
     publisher = utils.get_element(
         study._entry,
         namespace='dcterms',
         tag='publisher'
     ).text
     self.assertEqual(title, 'My Study')
     self.assertEqual(publisher, 'Mr. Pub Lisher')
 def test_init(self):
     dataset = Dataset(title='My Dataset', publisher='Mr. Pub Lisher')
     title = utils.get_element(
         dataset._entry,
         namespace='dcterms',
         tag='title'
     ).text
     publisher = utils.get_element(
         dataset._entry,
         namespace='dcterms',
         tag='publisher'
     ).text
     self.assertEqual(title, 'My Dataset')
     self.assertEqual(title, dataset.title)
     self.assertEqual(publisher, 'Mr. Pub Lisher')
Example #11
0
    def test_get_element(self):
        with open(ATOM_DATASET) as f:
            entry = f.read()

        # One value
        title = utils.get_element(entry, 'title', 'dcterms').text
        assert title == 'Roasting at Home'

        # Two values
        creator = utils.get_element(entry, 'creator', 'dcterms').text
        assert creator == 'Peets, John'

        # No values
        nonsense = utils.get_element(entry, 'nonsense', 'booga')
        assert nonsense is None
    def test_get_element(self):
        with open(ATOM_DATASET) as f:
            entry = f.read()

        # One value
        title = utils.get_element(entry, 'title', 'dcterms').text
        assert title == 'Roasting at Home'

        # Two values
        creator = utils.get_element(entry, 'creator', 'dcterms').text
        assert creator == 'Peets, John'

        # No values
        nonsense = utils.get_element(entry, 'nonsense', 'booga')
        assert nonsense is None
 def test_init(self):
     dataset = Dataset(title='My Dataset', publisher='Mr. Pub Lisher')
     title = utils.get_element(
         dataset._entry,
         namespace='dcterms',
         tag='title'
     ).text
     publisher = utils.get_element(
         dataset._entry,
         namespace='dcterms',
         tag='publisher'
     ).text
     assert title == 'My Dataset'
     assert title == dataset.title
     assert publisher == 'Mr. Pub Lisher'
Example #14
0
    def __init__(self, entry=SWORD_BOOTSTRAP, dataverse=None, edit_uri=None,
                 edit_media_uri=None, statement_uri=None, **kwargs):
        """
        Datasets must have a title, description, and author.
        This can be specified in the atom entry or as kwargs
        """
        self.dataverse = dataverse

        self.edit_uri = edit_uri
        self.edit_media_uri = edit_media_uri
        self.statement_uri = statement_uri
        self.is_deleted = False

        self._entry = etree.XML(entry) if isinstance(entry, str) else entry
        self._statement = None
        self._metadata = {}
        self._id = None

        # Updates sword entry from keyword arguments
        for key in kwargs:
            value = kwargs[key]
            if isinstance(value, list):
                for item in value:
                    add_field(self._entry, key, item, 'dcterms')
            else:
                add_field(self._entry, key, value, 'dcterms')

        self.title = get_element(
            self._entry, tag='title', namespace='dcterms'
        ).text
Example #15
0
    def __init__(self,
                 entry=SWORD_BOOTSTRAP,
                 dataverse=None,
                 edit_uri=None,
                 edit_media_uri=None,
                 statement_uri=None,
                 **kwargs):
        """
        Datasets must have a title, description, and author.
        This can be specified in the atom entry or as kwargs
        """
        self.dataverse = dataverse

        self.edit_uri = edit_uri
        self.edit_media_uri = edit_media_uri
        self.statement_uri = statement_uri
        self.is_deleted = False

        self._entry = etree.XML(entry) if isinstance(entry, str) else entry
        self._statement = None
        self._metadata = {}
        self._id = None

        # Updates sword entry from keyword arguments
        for key in kwargs:
            value = kwargs[key]
            if isinstance(value, list):
                for item in value:
                    add_field(self._entry, key, item, 'dcterms')
            else:
                add_field(self._entry, key, value, 'dcterms')

        self.title = get_element(self._entry, tag='title',
                                 namespace='dcterms').text
 def title(self):
     return sanitize(
         get_element(
             self.collection,
             namespace='atom',
             tag='title',
         ).text)
Example #17
0
    def get_state(self, refresh=False):
        if self.is_deleted:
            return 'DEACCESSIONED'

        return get_element(self.get_statement(refresh),
                           tag='category',
                           attribute='term',
                           attribute_value='latestVersionState').text
Example #18
0
    def get_state(self, refresh=False):
        if self.is_deleted:
            return 'DEACCESSIONED'

        return get_element(
            self.get_statement(refresh),
            tag='category',
            attribute='term',
            attribute_value='latestVersionState'
        ).text
Example #19
0
    def from_dataverse(cls, entry_element, dataverse):

        # Entry not in appropriate format--extract relevant metadata
        id_element = get_element(entry_element, tag='id')
        title_element = get_element(entry_element, tag='title')
        edit_media_element = get_element(
            entry_element,
            tag='link',
            attribute='rel',
            attribute_value='edit-media',
        )

        return cls(
            title=title_element.text,
            id=id_element.text,
            dataverse=dataverse,
            edit_uri=entry_element.base,
            edit_media_uri=edit_media_element.get('href'),
        )
Example #20
0
    def from_dataverse(cls, entry_element, dataverse):

        # Entry not in appropriate format--extract relevant metadata
        id_element = get_element(entry_element, tag='id')
        title_element = get_element(entry_element, tag='title')
        edit_media_element = get_element(
            entry_element,
            tag='link',
            attribute='rel',
            attribute_value='edit-media',
        )

        return cls(
            title=title_element.text,
            id=id_element.text,
            dataverse=dataverse,
            edit_uri=entry_element.base,
            edit_media_uri=edit_media_element.get('href'),
        )
Example #21
0
    def _refresh(self, receipt=None):
        if receipt:
            self.edit_uri = get_element(receipt,
                                        tag='link',
                                        attribute='rel',
                                        attribute_value='edit').get('href')
            self.edit_media_uri = get_element(
                receipt,
                tag='link',
                attribute='rel',
                attribute_value='edit-media').get('href')
            self.statement_uri = get_element(
                receipt,
                tag='link',
                attribute='rel',
                attribute_value='http://purl.org/net/sword/terms/statement'
            ).get('href')

        self.get_statement(refresh=True)
        self.get_entry(refresh=True)
        self.get_metadata('latest', refresh=True)
Example #22
0
    def _refresh(self, receipt=None):
        if receipt:
            self.edit_uri = get_element(
                receipt,
                tag='link',
                attribute='rel',
                attribute_value='edit'
            ).get('href')
            self.edit_media_uri = get_element(
                receipt,
                tag='link',
                attribute='rel',
                attribute_value='edit-media'
            ).get('href')
            self.statement_uri = get_element(
                receipt,
                tag='link',
                attribute='rel',
                attribute_value='http://purl.org/net/sword/terms/statement'
            ).get('href')

        self.get_statement(refresh=True)
        self.get_entry(refresh=True)
        self.get_metadata('latest', refresh=True)
Example #23
0
    def is_published(self):

        # Always check latest version
        collection_info = requests.get(
            self.collection.get('href'),
            auth=self.connection.auth,
        ).content

        status_tag = get_element(
            collection_info,
            namespace='http://purl.org/net/sword/terms/state',
            tag='dataverseHasBeenReleased',
        )
        status = status_tag.text

        return status.lower() == 'true'
    def is_published(self):

        # Always check latest version
        collection_info = requests.get(
            self.collection.get('href'),
            auth=self.connection.auth,verify=self.connection.verify
        ).content

        status_tag = get_element(
            collection_info,
            namespace='http://purl.org/net/sword/terms/state',
            tag='dataverseHasBeenReleased',
        )
        status = status_tag.text

        return status.lower() == 'true'
Example #25
0
 def title(self):
     return sanitize(get_element(
         self.collection,
         namespace='atom',
         tag='title',
     ).text)
Example #26
0
 def citation(self):
     return get_element(
         self.get_entry(),
         namespace='http://purl.org/dc/terms/',
         tag='bibliographicCitation'
     ).text
Example #27
0
 def citation(self):
     return get_element(self.get_entry(),
                        namespace='http://purl.org/dc/terms/',
                        tag='bibliographicCitation').text