{"action":"created","comment":{"url":"https://api.github.com/repos/artefactual/archivematica/pulls/comments/70879925","id":70879925,"diff_hunk":"@@ -0,0 +1,104 @@\n+# This file is part of Archivematica.\n+#\n+# Copyright 2010-2016 Artefactual Systems Inc. <http://artefactual.com>\n+#\n+# Archivematica is free software: you can redistribute it and/or modify\n+# it under the terms of the GNU Affero General Public License as published by\n+# the Free Software Foundation, either version 3 of the License, or\n+# (at your option) any later version.\n+#\n+# Archivematica is distributed in the hope that it will be useful,\n+# but WITHOUT ANY WARRANTY; without even the implied warranty of\n+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+# GNU General Public License for more details.\n+#\n+# You should have received a copy of the GNU General Public License\n+# along with Archivematica.  If not, see <http://www.gnu.org/licenses/>.\n+\n+import logging\n+import os\n+import tempfile\n+\n+from agentarchives.atom.client import AtomClient, AtomError\n+from metsrw import METSDocument, MetsError\n+from storageService import extract_file\n+from slumber.exceptions import SlumberHttpBaseException\n+\n+from components import helpers\n+from main.models import DashboardSetting\n+\n+\n+logger = logging.getLogger('archivematica.dashboard')\n+\n+\n+def get_atom_client():\n+    url = helpers.get_setting('dip_upload_atom_url')\n+    key = helpers.get_setting('dip_upload_atom_key')\n+    return AtomClient(url, key)\n+\n+\n+class AtomMetadataUploadError(Exception):\n+    pass\n+\n+\n+def upload_dip_metadata_to_atom(aip_name, aip_uuid, parent_slug):\n+    \"\"\"\n+    Write to a AtoM's resource (parent_slug) the metadata of the objects of a\n+    AIP given its name and UUID. Return the slug of the new container resource\n+    created to hold the metadata objects.\n+    \"\"\"\n+    try:\n+        with tempfile.NamedTemporaryFile() as temp:\n+            # Download METS file\n+            mets_path = '{}-{}/data/METS.{}.xml'.format(aip_name, aip_uuid, aip_uuid)\n+            logger.debug('Extracting file %s into %s', mets_path, temp.name)\n+            extract_file(aip_uuid, mets_path, temp.name)\n+\n+            client = get_atom_client()\n+            mw = METSDocument.fromfile(temp.name)\n+\n+            # Create file container\n+            logger.info('Creating file container with slug %s and title %s', parent_slug, aip_name)\n+            file_slug = client.add_child(parent_slug=parent_slug, title=aip_name, level='File')\n+\n+            def add_prop_from_xml(dict_, name, el, xpath):\n+                \"\"\"\n+                Write to a dictionary a new pair with the given key and the value\n+                taken from the text attribute of the element matched by the given\n+                XPath query.\n+                \"\"\"\n+                res = el.find(xpath)\n+                if res is not None and res.text:\n+                    dict_[name] = res.text\n+                    logger.debug('Extracted property %s from METS: %s', name, res.text)\n+                logger.debug('Failed to extract property %s from METS: not found', name)\n+\n+            # Add objects\n+            for item in mw.all_files():\n+                if item.type == 'Directory' or item.use != 'original':\n+                    continue\n+                attrs = {","path":"src/dashboard/src/components/archival_storage/atom.py","position":80,"original_position":80,"commit_id":"5a74dad45618afc89f78c1ca74c9ee247bbb2192","original_commit_id":"5a74dad45618afc89f78c1ca74c9ee247bbb2192","user":{"login":"Hwesta","id":3166226,"avatar_url":"https://avatars.githubusercontent.com/u/3166226?v=3","gravatar_id":"","url":"https://api.github.com/users/Hwesta","html_url":"https://github.com/Hwesta","followers_url":"https://api.github.com/users/Hwesta/followers","following_url":"https://api.github.com/users/Hwesta/following{/other_user}","gists_url":"https://api.github.com/users/Hwesta/gists{/gist_id}","starred_url":"https://api.github.com/users/Hwesta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Hwesta/subscriptions","organizations_url":"https://api.github.com/users/Hwesta/orgs","repos_url":"https://api.github.com/users/Hwesta/repos","events_url":"https://api.github.com/users/Hwesta/events{/privacy}","received_events_url":"https://api.github.com/users/Hwesta/received_events","type":"User","site_admin":false},"body":"The way it is is probably better. I was wondering if the properties could be given a default value of None, but it sounds like that's not workable.","created_at":"2016-07-14T20:43:37Z","updated_at":"2016-07-14T20:43:37Z","html_url":"https://github.com/artefactual/archivematica/pull/468#discussion_r70879925","pull_request_url":"https://api.github.com/repos/artefactual/archivematica/pulls/468","_links":{"self":{"href":"https://api.github.com/repos/artefactual/archivematica/pulls/comments/70879925"},"html":{"href":"https://github.com/artefactual/archivematica/pull/468#discussion_r70879925"},"pull_request":{"href":"https://api.github.com/repos/artefactual/archivematica/pulls/468"}}},"pull_request":{"url":"https://api.github.com/repos/artefactual/archivematica/pulls/468","id":76256766,"html_url":"https://github.com/artefactual/archivematica/pull/468","diff_url":"https://github.com/artefactual/archivematica/pull/468.diff","patch_url":"https://github.com/artefactual/archivematica/pull/468.patch","issue_url":"https://api.github.com/repos/artefactual/archivematica/issues/468","number":468,"state":"open","locked":false,"title":"Metadata-only dip upload, refs #9752","user":{"login":"sevein","id":606459,"avatar_url":"https://avatars.githubusercontent.com/u/606459?v=3","gravatar_id":"","url":"https://api.github.com/users/sevein","html_url":"https://github.com/sevein","followers_url":"https://api.github.com/users/sevein/followers","following_url":"https://api.github.com/users/sevein/following{/other_user}","gists_url":"https://api.github.com/users/sevein/gists{/gist_id}","starred_url":"https://api.github.com/users/sevein/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sevein/subscriptions","organizations_url":"https://api.github.com/users/sevein/orgs","repos_url":"https://api.github.com/users/sevein/repos","events_url":"https://api.github.com/users/sevein/events{/privacy}","received_events_url":"https://api.github.com/users/sevein/received_events","type":"User","site_admin":false},"body":"Redmine: https://projects.artefactual.com/issues/9752","created_at":"2016-07-05T11:15:42Z","updated_at":"2016-07-14T20:43:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3112f569803e490a9b7d7d8a1c8d5fef9531439a","assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/artefactual/archivematica/milestones/4","html_url":"https://github.com/artefactual/archivematica/milestones/1.6.0","labels_url":"https://api.github.com/repos/artefactual/archivematica/milestones/4/labels","id":1317264,"number":4,"title":"1.6.0","description":"","creator":{"login":"Hwesta","id":3166226,"avatar_url":"https://avatars.githubusercontent.com/u/3166226?v=3","gravatar_id":"","url":"https://api.github.com/users/Hwesta","html_url":"https://github.com/Hwesta","followers_url":"https://api.github.com/users/Hwesta/followers","following_url":"https://api.github.com/users/Hwesta/following{/other_user}","gists_url":"https://api.github.com/users/Hwesta/gists{/gist_id}","starred_url":"https://api.github.com/users/Hwesta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Hwesta/subscriptions","organizations_url":"https://api.github.com/users/Hwesta/orgs","repos_url":"https://api.github.com/users/Hwesta/repos","events_url":"https://api.github.com/users/Hwesta/events{/privacy}","received_events_url":"https://api.github.com/users/Hwesta/received_events","type":"User","site_admin":false},"open_issues":13,"closed_issues":87,"state":"open","created_at":"2015-09-21T20:50:42Z","updated_at":"2016-07-13T00:10:54Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/artefactual/archivematica/pulls/468/commits","review_comments_url":"https://api.github.com/repos/artefactual/archivematica/pulls/468/comments","review_comment_url":"https://api.github.com/repos/artefactual/archivematica/pulls/comments{/number}","comments_url":"https://api.github.com/repos/artefactual/archivematica/issues/468/comments","statuses_url":"https://api.github.com/repos/artefactual/archivematica/statuses/5a74dad45618afc89f78c1ca74c9ee247bbb2192","head":{"label":"artefactual:dev/issue-9867-metadata-only-dip-upload","ref":"dev/issue-9867-metadata-only-dip-upload","sha":"5a74dad45618afc89f78c1ca74c9ee247bbb2192","user":{"login":"artefactual","id":1163545,"avatar_url":"https://avatars.githubusercontent.com/u/1163545?v=3","gravatar_id":"","url":"https://api.github.com/users/artefactual","html_url":"https://github.com/artefactual","followers_url":"https://api.github.com/users/artefactual/followers","following_url":"https://api.github.com/users/artefactual/following{/other_user}","gists_url":"https://api.github.com/users/artefactual/gists{/gist_id}","starred_url":"https://api.github.com/users/artefactual/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/artefactual/subscriptions","organizations_url":"https://api.github.com/users/artefactual/orgs","repos_url":"https://api.github.com/users/artefactual/repos","events_url":"https://api.github.com/users/artefactual/events{/privacy}","received_events_url":"https://api.github.com/users/artefactual/received_events","type":"Organization","site_admin":false},"repo":{"id":5811958,"name":"archivematica","full_name":"artefactual/archivematica","owner":{"login":"artefactual","id":1163545,"avatar_url":"https://avatars.githubusercontent.com/u/1163545?v=3","gravatar_id":"","url":"https://api.github.com/users/artefactual","html_url":"https://github.com/artefactual","followers_url":"https://api.github.com/users/artefactual/followers","following_url":"https://api.github.com/users/artefactual/following{/other_user}","gists_url":"https://api.github.com/users/artefactual/gists{/gist_id}","starred_url":"https://api.github.com/users/artefactual/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/artefactual/subscriptions","organizations_url":"https://api.github.com/users/artefactual/orgs","repos_url":"https://api.github.com/users/artefactual/repos","events_url":"https://api.github.com/users/artefactual/events{/privacy}","received_events_url":"https://api.github.com/users/artefactual/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/artefactual/archivematica","description":"Free and open-source digital preservation system designed to maintain standards-based, long-term access to collections of digital objects.","fork":false,"url":"https://api.github.com/repos/artefactual/archivematica","forks_url":"https://api.github.com/repos/artefactual/archivematica/forks","keys_url":"https://api.github.com/repos/artefactual/archivematica/keys{/key_id}","collaborators_url":"https://api.github.com/repos/artefactual/archivematica/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/artefactual/archivematica/teams","hooks_url":"https://api.github.com/repos/artefactual/archivematica/hooks","issue_events_url":"https://api.github.com/repos/artefactual/archivematica/issues/events{/number}","events_url":"https://api.github.com/repos/artefactual/archivematica/events","assignees_url":"https://api.github.com/repos/artefactual/archivematica/assignees{/user}","branches_url":"https://api.github.com/repos/artefactual/archivematica/branches{/branch}","tags_url":"https://api.github.com/repos/artefactual/archivematica/tags","blobs_url":"https://api.github.com/repos/artefactual/archivematica/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/artefactual/archivematica/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/artefactual/archivematica/git/refs{/sha}","trees_url":"https://api.github.com/repos/artefactual/archivematica/git/trees{/sha}","statuses_url":"https://api.github.com/repos/artefactual/archivematica/statuses/{sha}","languages_url":"https://api.github.com/repos/artefactual/archivematica/languages","stargazers_url":"https://api.github.com/repos/artefactual/archivematica/stargazers","contributors_url":"https://api.github.com/repos/artefactual/archivematica/contributors","subscribers_url":"https://api.github.com/repos/artefactual/archivematica/subscribers","subscription_url":"https://api.github.com/repos/artefactual/archivematica/subscription","commits_url":"https://api.github.com/repos/artefactual/archivematica/commits{/sha}","git_commits_url":"https://api.github.com/repos/artefactual/archivematica/git/commits{/sha}","comments_url":"https://api.github.com/repos/artefactual/archivematica/comments{/number}","issue_comment_url":"https://api.github.com/repos/artefactual/archivematica/issues/comments{/number}","contents_url":"https://api.github.com/repos/artefactual/archivematica/contents/{+path}","compare_url":"https://api.github.com/repos/artefactual/archivematica/compare/{base}...{head}","merges_url":"https://api.github.com/repos/artefactual/archivematica/merges","archive_url":"https://api.github.com/repos/artefactual/archivematica/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/artefactual/archivematica/downloads","issues_url":"https://api.github.com/repos/artefactual/archivematica/issues{/number}","pulls_url":"https://api.github.com/repos/artefactual/archivematica/pulls{/number}","milestones_url":"https://api.github.com/repos/artefactual/archivematica/milestones{/number}","notifications_url":"https://api.github.com/repos/artefactual/archivematica/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/artefactual/archivematica/labels{/name}","releases_url":"https://api.github.com/repos/artefactual/archivematica/releases{/id}","deployments_url":"https://api.github.com/repos/artefactual/archivematica/deployments","created_at":"2012-09-14T16:43:38Z","updated_at":"2016-05-04T22:11:04Z","pushed_at":"2016-07-14T16:06:39Z","git_url":"git://github.com/artefactual/archivematica.git","ssh_url":"git@github.com:artefactual/archivematica.git","clone_url":"https://github.com/artefactual/archivematica.git","svn_url":"https://github.com/artefactual/archivematica","homepage":"http://www.archivematica.org","size":30547,"stargazers_count":90,"watchers_count":90,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":27,"mirror_url":null,"open_issues_count":26,"forks":27,"open_issues":26,"watchers":90,"default_branch":"stable/1.5.x"}},"base":{"label":"artefactual:qa/1.x","ref":"qa/1.x","sha":"8e49b8bdaac911dac0dbfab9d814ff89342f4c1f","user":{"login":"artefactual","id":1163545,"avatar_url":"https://avatars.githubusercontent.com/u/1163545?v=3","gravatar_id":"","url":"https://api.github.com/users/artefactual","html_url":"https://github.com/artefactual","followers_url":"https://api.github.com/users/artefactual/followers","following_url":"https://api.github.com/users/artefactual/following{/other_user}","gists_url":"https://api.github.com/users/artefactual/gists{/gist_id}","starred_url":"https://api.github.com/users/artefactual/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/artefactual/subscriptions","organizations_url":"https://api.github.com/users/artefactual/orgs","repos_url":"https://api.github.com/users/artefactual/repos","events_url":"https://api.github.com/users/artefactual/events{/privacy}","received_events_url":"https://api.github.com/users/artefactual/received_events","type":"Organization","site_admin":false},"repo":{"id":5811958,"name":"archivematica","full_name":"artefactual/archivematica","owner":{"login":"artefactual","id":1163545,"avatar_url":"https://avatars.githubusercontent.com/u/1163545?v=3","gravatar_id":"","url":"https://api.github.com/users/artefactual","html_url":"https://github.com/artefactual","followers_url":"https://api.github.com/users/artefactual/followers","following_url":"https://api.github.com/users/artefactual/following{/other_user}","gists_url":"https://api.github.com/users/artefactual/gists{/gist_id}","starred_url":"https://api.github.com/users/artefactual/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/artefactual/subscriptions","organizations_url":"https://api.github.com/users/artefactual/orgs","repos_url":"https://api.github.com/users/artefactual/repos","events_url":"https://api.github.com/users/artefactual/events{/privacy}","received_events_url":"https://api.github.com/users/artefactual/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/artefactual/archivematica","description":"Free and open-source digital preservation system designed to maintain standards-based, long-term access to collections of digital objects.","fork":false,"url":"https://api.github.com/repos/artefactual/archivematica","forks_url":"https://api.github.com/repos/artefactual/archivematica/forks","keys_url":"https://api.github.com/repos/artefactual/archivematica/keys{/key_id}","collaborators_url":"https://api.github.com/repos/artefactual/archivematica/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/artefactual/archivematica/teams","hooks_url":"https://api.github.com/repos/artefactual/archivematica/hooks","issue_events_url":"https://api.github.com/repos/artefactual/archivematica/issues/events{/number}","events_url":"https://api.github.com/repos/artefactual/archivematica/events","assignees_url":"https://api.github.com/repos/artefactual/archivematica/assignees{/user}","branches_url":"https://api.github.com/repos/artefactual/archivematica/branches{/branch}","tags_url":"https://api.github.com/repos/artefactual/archivematica/tags","blobs_url":"https://api.github.com/repos/artefactual/archivematica/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/artefactual/archivematica/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/artefactual/archivematica/git/refs{/sha}","trees_url":"https://api.github.com/repos/artefactual/archivematica/git/trees{/sha}","statuses_url":"https://api.github.com/repos/artefactual/archivematica/statuses/{sha}","languages_url":"https://api.github.com/repos/artefactual/archivematica/languages","stargazers_url":"https://api.github.com/repos/artefactual/archivematica/stargazers","contributors_url":"https://api.github.com/repos/artefactual/archivematica/contributors","subscribers_url":"https://api.github.com/repos/artefactual/archivematica/subscribers","subscription_url":"https://api.github.com/repos/artefactual/archivematica/subscription","commits_url":"https://api.github.com/repos/artefactual/archivematica/commits{/sha}","git_commits_url":"https://api.github.com/repos/artefactual/archivematica/git/commits{/sha}","comments_url":"https://api.github.com/repos/artefactual/archivematica/comments{/number}","issue_comment_url":"https://api.github.com/repos/artefactual/archivematica/issues/comments{/number}","contents_url":"https://api.github.com/repos/artefactual/archivematica/contents/{+path}","compare_url":"https://api.github.com/repos/artefactual/archivematica/compare/{base}...{head}","merges_url":"https://api.github.com/repos/artefactual/archivematica/merges","archive_url":"https://api.github.com/repos/artefactual/archivematica/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/artefactual/archivematica/downloads","issues_url":"https://api.github.com/repos/artefactual/archivematica/issues{/number}","pulls_url":"https://api.github.com/repos/artefactual/archivematica/pulls{/number}","milestones_url":"https://api.github.com/repos/artefactual/archivematica/milestones{/number}","notifications_url":"https://api.github.com/repos/artefactual/archivematica/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/artefactual/archivematica/labels{/name}","releases_url":"https://api.github.com/repos/artefactual/archivematica/releases{/id}","deployments_url":"https://api.github.com/repos/artefactual/archivematica/deployments","created_at":"2012-09-14T16:43:38Z","updated_at":"2016-05-04T22:11:04Z","pushed_at":"2016-07-14T16:06:39Z","git_url":"git://github.com/artefactual/archivematica.git","ssh_url":"git@github.com:artefactual/archivematica.git","clone_url":"https://github.com/artefactual/archivematica.git","svn_url":"https://github.com/artefactual/archivematica","homepage":"http://www.archivematica.org","size":30547,"stargazers_count":90,"watchers_count":90,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":27,"mirror_url":null,"open_issues_count":26,"forks":27,"open_issues":26,"watchers":90,"default_branch":"stable/1.5.x"}},"_links":{"self":{"href":"https://api.github.com/repos/artefactual/archivematica/pulls/468"},"html":{"href":"https://github.com/artefactual/archivematica/pull/468"},"issue":{"href":"https://api.github.com/repos/artefactual/archivematica/issues/468"},"comments":{"href":"https://api.github.com/repos/artefactual/archivematica/issues/468/comments"},"review_comments":{"href":"https://api.github.com/repos/artefactual/archivematica/pulls/468/comments"},"review_comment":{"href":"https://api.github.com/repos/artefactual/archivematica/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/artefactual/archivematica/pulls/468/commits"},"statuses":{"href":"https://api.github.com/repos/artefactual/archivematica/statuses/5a74dad45618afc89f78c1ca74c9ee247bbb2192"}}}}
{"actor":{"display_login":"Hwesta"}}