We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
hsapi /scimeta/elements endpoint errors with no authentication
**Description of the bug**
/scimeta/elements hsapi endpoint responds with a system error when no authentication credentials are provided.

Steps to reproduce the bug:
1. Go to https://www.hydroshare.org/hsapi/resource/16b27156f2b1483099f09d3b688e43fb/scimeta/elements/
1. See error

**Expected behavior**
API endpoints should handle requests that do not provide authentication.  Unauthenticated requests that make publicly accessible requests should provide a response.  Unauthenticated requests that make privately accessible requests should respond with a 403.

**Additional information**
Environment:


Request Method: GET
Request URL: http://localhost:8000/hsapi/resource/068d77bb3f4c442194e9f08056aca1cf/scimeta/elements/

Django Version: 1.11.29
Python Version: 3.6.9
Installed Applications:
('mezzanine.boot',
 'test_without_migrations',
 'autocomplete_light',
 'django.contrib.auth',
 'oauth2_provider',
 'corsheaders',
 'django.contrib.contenttypes',
 'django.contrib.redirects',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.sitemaps',
 'django.contrib.gis',
 'django.contrib.postgres',
 'inplaceeditform',
 'django_nose',
 'django_irods',
 'drf_yasg',
 'theme',
 'theme.blog_mods',
 'heartbeat',
 'mezzanine.conf',
 'mezzanine.core',
 'mezzanine.generic',
 'mezzanine.blog',
 'mezzanine.forms',
 'mezzanine.pages',
 'mezzanine.galleries',
 'crispy_forms',
 'mezzanine.accounts',
 'haystack',
 'rest_framework',
 'robots',
 'hs_core',
 'hs_access_control',
 'hs_labels',
 'hs_metrics',
 'irods_browser_app',
 'hs_geo_raster_resource',
 'ref_ts',
 'hs_app_timeseries',
 'widget_tweaks',
 'hs_app_netCDF',
 'hs_model_program',
 'hs_modelinstance',
 'hs_tools_resource',
 'hs_swat_modelinstance',
 'hs_geographic_feature_resource',
 'hs_script_resource',
 'hs_sitemap',
 'hs_collection_resource',
 'hs_modflow_modelinstance',
 'hs_tracking',
 'hs_file_types',
 'hs_composite_resource',
 'hs_rest_api',
 'hs_dictionary',
 'hs_odm2',
 'security',
 'markdown',
 'hs_communities',
 'hs_discover',
 'debug_toolbar',
 'filebrowser_safe',
 'grappelli_safe',
 'django.contrib.admin',
 'django.contrib.staticfiles',
 'django_comments')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'corsheaders.middleware.CorsMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'mezzanine.core.request.CurrentRequestMiddleware',
 'mezzanine.core.middleware.RedirectFallbackMiddleware',
 'mezzanine.core.middleware.AdminLoginInterfaceSelectorMiddleware',
 'mezzanine.core.middleware.SitePermissionMiddleware',
 'mezzanine.pages.middleware.PageMiddleware',
 'hs_core.robots.RobotFilter',
 'hs_tracking.middleware.Tracking',
 'debug_toolbar.middleware.DebugToolbarMiddleware')



Traceback:

File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
  41.             response = get_response(request)

File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  217.                 response = self.process_exception_by_middleware(e, request)

File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  215.                 response = response.render()

File "/usr/local/lib/python3.6/site-packages/django/template/response.py" in render
  107.             self.content = self.rendered_content

File "/usr/local/lib/python3.6/site-packages/rest_framework/response.py" in rendered_content
  70.         ret = renderer.render(self.data, accepted_media_type, context)

File "/usr/local/lib/python3.6/site-packages/rest_framework/renderers.py" in render
  724.         context = self.get_context(data, accepted_media_type, renderer_context)

File "/usr/local/lib/python3.6/site-packages/rest_framework/renderers.py" in get_context
  656.         raw_data_put_form = self.get_raw_data_form(data, view, 'PUT', request)

File "/usr/local/lib/python3.6/site-packages/rest_framework/renderers.py" in get_raw_data_form
  552.                     serializer = view.get_serializer(instance=instance)

File "/usr/local/lib/python3.6/site-packages/rest_framework/generics.py" in get_serializer
  110.         return serializer_class(*args, **kwargs)

Exception Type: TypeError at /hsapi/resource/068d77bb3f4c442194e9f08056aca1cf/scimeta/elements/
Exception Value: 'CoreMetaDataSerializer' object is not callable



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `hs_core/views/resource_metadata_rest_api.py`
Content:
```
1 import logging
2 
3 from django.http import QueryDict
4 
5 from rest_framework.response import Response
6 from rest_framework.exceptions import ValidationError
7 from rest_framework import status
8 from rest_framework import generics
9 from rest_framework import serializers
10 
11 from hs_core import hydroshare
12 from hs_core.models import Contributor, CoreMetaData, Coverage, Creator, Date, \
13     Format, FundingAgency, Identifier, Subject, Relation, GeospatialRelation
14 from hs_core.views import utils as view_utils
15 from hs_core.views.utils import ACTION_TO_AUTHORIZE
16 
17 logger = logging.getLogger(__name__)
18 
19 
20 class Identifiers(serializers.DictField):
21     child = serializers.CharField()
22 
23 
24 class PartySerializer(serializers.Serializer):
25     name = serializers.CharField()
26     hydroshare_user_id = serializers.IntegerField(required=False)
27     organization = serializers.CharField(required=False)
28     email = serializers.EmailField(required=False)
29     address = serializers.CharField(required=False)
30     phone = serializers.CharField(required=False)
31     homepage = serializers.URLField(required=False)
32     identifiers = Identifiers(required=False)
33 
34     class Meta:
35         model = Creator
36         fields = {'name', 'hydroshare_user_id', 'organization', 'email',
37                   'address', 'phone', 'homepage', 'identifiers'}
38 
39 
40 class CreatorSerializer(PartySerializer):
41     order = serializers.IntegerField(required=False)
42 
43     class Meta:
44         model = Contributor
45 
46 
47 class DateSerializer(serializers.Serializer):
48     # term = 'Date'
49     type = serializers.CharField(required=False)
50     start_date = serializers.DateTimeField(required=False)
51     end_date = serializers.DateTimeField(required=False)
52 
53     class Meta:
54         model = Date
55 
56 
57 class CoverageSerializer(serializers.Serializer):
58     type = serializers.CharField(required=False)
59     value = serializers.SerializerMethodField(required=False)
60 
61     class Meta:
62         model = Coverage
63 
64     def get_value(self, obj):
65         return obj.value
66 
67 
68 class FormatSerializer(serializers.Serializer):
69     value = serializers.CharField(required=False)
70 
71     class Meta:
72         model = Format
73 
74 
75 class FundingAgencySerializer(serializers.Serializer):
76     agency_name = serializers.CharField()
77     award_title = serializers.CharField(required=False)
78     award_number = serializers.CharField(required=False)
79     agency_url = serializers.URLField(required=False)
80 
81     class Meta:
82         model = FundingAgency
83 
84 
85 class IdentifierSerializer(serializers.Serializer):
86     name = serializers.CharField(required=False)
87     url = serializers.URLField(required=False)
88 
89     class Meta:
90         model = Identifier
91 
92 
93 class SubjectSerializer(serializers.Serializer):
94     value = serializers.CharField(required=False)
95 
96     class Meta:
97         model = Subject
98 
99 
100 class RelationSerializer(serializers.Serializer):
101     type = serializers.CharField(required=False)
102     value = serializers.CharField(required=False)
103 
104     class Meta:
105         model = Relation
106 
107 
108 class GeospatialRelationSerializer(RelationSerializer):
109     type = serializers.CharField(required=False)
110     value = serializers.CharField(required=False)
111     text = serializers.CharField(required=False)
112 
113     class Meta:
114         model = GeospatialRelation
115 
116 
117 class CoreMetaDataSerializer(serializers.Serializer):
118     title = serializers.CharField(required=False)
119     creators = CreatorSerializer(required=False, many=True)
120     contributors = PartySerializer(required=False, many=True)
121     coverages = CoverageSerializer(required=False, many=True)
122     dates = DateSerializer(required=False, many=True)
123     description = serializers.CharField(required=False)
124     formats = FormatSerializer(required=False, many=True)
125     funding_agencies = FundingAgencySerializer(required=False, many=True)
126     identifiers = IdentifierSerializer(required=False, many=True)
127     language = serializers.CharField(required=False)
128     rights = serializers.CharField(required=False)
129     type = serializers.CharField(required=False)
130     publisher = serializers.CharField(required=False)
131     subjects = SubjectSerializer(required=False, many=True)
132     relations = RelationSerializer(required=False, many=True)
133     geospatialrelations = GeospatialRelationSerializer(required=False, many=True)
134 
135     class Meta:
136         model = CoreMetaData
137 
138 
139 class MetadataElementsRetrieveUpdate(generics.RetrieveUpdateDestroyAPIView):
140     """
141     Retrieve resource science (Dublin Core) metadata
142 
143     REST URL: /hsapi/resource/{pk}/scimeta/elements/
144     HTTP method: GET
145 
146     :type pk: str
147     :param pk: id of the resource
148     :return: resource science metadata as JSON document
149     :rtype: str
150     :raises:
151     NotFound: return json format: {'detail': 'No resource was found for resource id:pk'}
152     PermissionDenied: return json format: {'detail': 'You do not have permission to perform
153     this action.'}
154 
155     REST URL: /hsapi/resource/{pk}/scimeta/elements/
156     HTTP method: PUT
157 
158     :type pk: str
159     :param pk: id of the resource
160     :type request: JSON formatted string
161     :param request: resource metadata
162     :return: updated resource science metadata as JSON document
163     :rtype: str
164     :raises:
165     NotFound: return json format: {'detail': 'No resource was found for resource id':pk}
166     PermissionDenied: return json format: {'detail': 'You do not have permission to perform
167     this action.'}
168     ValidationError: return json format: {parameter-1': ['error message-1'],
169     'parameter-2': ['error message-2'], .. }
170     """
171     ACCEPT_FORMATS = ('application/json',)
172 
173     allowed_methods = ('GET', 'PUT')
174 
175     # Overwritten by resource types with extended metadata
176     serializer_class = CoreMetaDataSerializer
177 
178     def get(self, request, pk):
179         view_utils.authorize(request, pk, needed_permission=ACTION_TO_AUTHORIZE.VIEW_METADATA)
180         resource = hydroshare.get_resource_by_shortkey(shortkey=pk)
181         serializer = resource.metadata.serializer
182         self.serializer_class = resource.metadata.serializer
183         return Response(data=serializer.data, status=status.HTTP_200_OK)
184 
185     def put(self, request, pk):
186         # Update science metadata
187         resource, _, _ = view_utils.authorize(
188             request, pk,
189             needed_permission=ACTION_TO_AUTHORIZE.EDIT_RESOURCE)
190 
191         metadata = []
192         put_data = request.data.copy()
193 
194         # convert the QueryDict to dict
195         if isinstance(put_data, QueryDict):
196             put_data = put_data.dict()
197         try:
198             resource.metadata.parse_for_bulk_update(put_data, metadata)
199             hydroshare.update_science_metadata(pk=pk, metadata=metadata, user=request.user)
200         except Exception as ex:
201             error_msg = {
202                 'resource': "Resource metadata update failed: %s, %s"
203                             % (ex.__class__, str(ex))
204             }
205             raise ValidationError(detail=error_msg)
206 
207         resource = hydroshare.get_resource_by_shortkey(shortkey=pk)
208         serializer = resource.metadata.serializer
209         self.serializer_class = serializer
210         return Response(data=serializer.data, status=status.HTTP_202_ACCEPTED)
211
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/hs_core/views/resource_metadata_rest_api.py b/hs_core/views/resource_metadata_rest_api.py
--- a/hs_core/views/resource_metadata_rest_api.py
+++ b/hs_core/views/resource_metadata_rest_api.py
@@ -179,7 +179,6 @@
         view_utils.authorize(request, pk, needed_permission=ACTION_TO_AUTHORIZE.VIEW_METADATA)
         resource = hydroshare.get_resource_by_shortkey(shortkey=pk)
         serializer = resource.metadata.serializer
-        self.serializer_class = resource.metadata.serializer
         return Response(data=serializer.data, status=status.HTTP_200_OK)
 
     def put(self, request, pk):
@@ -206,5 +205,4 @@
 
         resource = hydroshare.get_resource_by_shortkey(shortkey=pk)
         serializer = resource.metadata.serializer
-        self.serializer_class = serializer
         return Response(data=serializer.data, status=status.HTTP_202_ACCEPTED)

{"golden_diff": "diff --git a/hs_core/views/resource_metadata_rest_api.py b/hs_core/views/resource_metadata_rest_api.py\n--- a/hs_core/views/resource_metadata_rest_api.py\n+++ b/hs_core/views/resource_metadata_rest_api.py\n@@ -179,7 +179,6 @@\n         view_utils.authorize(request, pk, needed_permission=ACTION_TO_AUTHORIZE.VIEW_METADATA)\n         resource = hydroshare.get_resource_by_shortkey(shortkey=pk)\n         serializer = resource.metadata.serializer\n-        self.serializer_class = resource.metadata.serializer\n         return Response(data=serializer.data, status=status.HTTP_200_OK)\n \n     def put(self, request, pk):\n@@ -206,5 +205,4 @@\n \n         resource = hydroshare.get_resource_by_shortkey(shortkey=pk)\n         serializer = resource.metadata.serializer\n-        self.serializer_class = serializer\n         return Response(data=serializer.data, status=status.HTTP_202_ACCEPTED)\n", "issue": "hsapi /scimeta/elements endpoint errors with no authentication\n**Description of the bug**\r\n/scimeta/elements hsapi endpoint responds with a system error when no authentication credentials are provided.\r\n\r\nSteps to reproduce the bug:\r\n1. Go to https://www.hydroshare.org/hsapi/resource/16b27156f2b1483099f09d3b688e43fb/scimeta/elements/\r\n1. See error\r\n\r\n**Expected behavior**\r\nAPI endpoints should handle requests that do not provide authentication.  Unauthenticated requests that make publicly accessible requests should provide a response.  Unauthenticated requests that make privately accessible requests should respond with a 403.\r\n\r\n**Additional information**\r\nEnvironment:\r\n\r\n\r\nRequest Method: GET\r\nRequest URL: http://localhost:8000/hsapi/resource/068d77bb3f4c442194e9f08056aca1cf/scimeta/elements/\r\n\r\nDjango Version: 1.11.29\r\nPython Version: 3.6.9\r\nInstalled Applications:\r\n('mezzanine.boot',\r\n 'test_without_migrations',\r\n 'autocomplete_light',\r\n 'django.contrib.auth',\r\n 'oauth2_provider',\r\n 'corsheaders',\r\n 'django.contrib.contenttypes',\r\n 'django.contrib.redirects',\r\n 'django.contrib.sessions',\r\n 'django.contrib.sites',\r\n 'django.contrib.sitemaps',\r\n 'django.contrib.gis',\r\n 'django.contrib.postgres',\r\n 'inplaceeditform',\r\n 'django_nose',\r\n 'django_irods',\r\n 'drf_yasg',\r\n 'theme',\r\n 'theme.blog_mods',\r\n 'heartbeat',\r\n 'mezzanine.conf',\r\n 'mezzanine.core',\r\n 'mezzanine.generic',\r\n 'mezzanine.blog',\r\n 'mezzanine.forms',\r\n 'mezzanine.pages',\r\n 'mezzanine.galleries',\r\n 'crispy_forms',\r\n 'mezzanine.accounts',\r\n 'haystack',\r\n 'rest_framework',\r\n 'robots',\r\n 'hs_core',\r\n 'hs_access_control',\r\n 'hs_labels',\r\n 'hs_metrics',\r\n 'irods_browser_app',\r\n 'hs_geo_raster_resource',\r\n 'ref_ts',\r\n 'hs_app_timeseries',\r\n 'widget_tweaks',\r\n 'hs_app_netCDF',\r\n 'hs_model_program',\r\n 'hs_modelinstance',\r\n 'hs_tools_resource',\r\n 'hs_swat_modelinstance',\r\n 'hs_geographic_feature_resource',\r\n 'hs_script_resource',\r\n 'hs_sitemap',\r\n 'hs_collection_resource',\r\n 'hs_modflow_modelinstance',\r\n 'hs_tracking',\r\n 'hs_file_types',\r\n 'hs_composite_resource',\r\n 'hs_rest_api',\r\n 'hs_dictionary',\r\n 'hs_odm2',\r\n 'security',\r\n 'markdown',\r\n 'hs_communities',\r\n 'hs_discover',\r\n 'debug_toolbar',\r\n 'filebrowser_safe',\r\n 'grappelli_safe',\r\n 'django.contrib.admin',\r\n 'django.contrib.staticfiles',\r\n 'django_comments')\r\nInstalled Middleware:\r\n('django.contrib.sessions.middleware.SessionMiddleware',\r\n 'django.middleware.locale.LocaleMiddleware',\r\n 'django.contrib.auth.middleware.AuthenticationMiddleware',\r\n 'corsheaders.middleware.CorsMiddleware',\r\n 'django.middleware.common.CommonMiddleware',\r\n 'django.middleware.csrf.CsrfViewMiddleware',\r\n 'django.contrib.messages.middleware.MessageMiddleware',\r\n 'mezzanine.core.request.CurrentRequestMiddleware',\r\n 'mezzanine.core.middleware.RedirectFallbackMiddleware',\r\n 'mezzanine.core.middleware.AdminLoginInterfaceSelectorMiddleware',\r\n 'mezzanine.core.middleware.SitePermissionMiddleware',\r\n 'mezzanine.pages.middleware.PageMiddleware',\r\n 'hs_core.robots.RobotFilter',\r\n 'hs_tracking.middleware.Tracking',\r\n 'debug_toolbar.middleware.DebugToolbarMiddleware')\r\n\r\n\r\n\r\nTraceback:\r\n\r\nFile \"/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py\" in inner\r\n  41.             response = get_response(request)\r\n\r\nFile \"/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py\" in _get_response\r\n  217.                 response = self.process_exception_by_middleware(e, request)\r\n\r\nFile \"/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py\" in _get_response\r\n  215.                 response = response.render()\r\n\r\nFile \"/usr/local/lib/python3.6/site-packages/django/template/response.py\" in render\r\n  107.             self.content = self.rendered_content\r\n\r\nFile \"/usr/local/lib/python3.6/site-packages/rest_framework/response.py\" in rendered_content\r\n  70.         ret = renderer.render(self.data, accepted_media_type, context)\r\n\r\nFile \"/usr/local/lib/python3.6/site-packages/rest_framework/renderers.py\" in render\r\n  724.         context = self.get_context(data, accepted_media_type, renderer_context)\r\n\r\nFile \"/usr/local/lib/python3.6/site-packages/rest_framework/renderers.py\" in get_context\r\n  656.         raw_data_put_form = self.get_raw_data_form(data, view, 'PUT', request)\r\n\r\nFile \"/usr/local/lib/python3.6/site-packages/rest_framework/renderers.py\" in get_raw_data_form\r\n  552.                     serializer = view.get_serializer(instance=instance)\r\n\r\nFile \"/usr/local/lib/python3.6/site-packages/rest_framework/generics.py\" in get_serializer\r\n  110.         return serializer_class(*args, **kwargs)\r\n\r\nException Type: TypeError at /hsapi/resource/068d77bb3f4c442194e9f08056aca1cf/scimeta/elements/\r\nException Value: 'CoreMetaDataSerializer' object is not callable\r\n\r\n\n", "before_files": [{"content": "import logging\n\nfrom django.http import QueryDict\n\nfrom rest_framework.response import Response\nfrom rest_framework.exceptions import ValidationError\nfrom rest_framework import status\nfrom rest_framework import generics\nfrom rest_framework import serializers\n\nfrom hs_core import hydroshare\nfrom hs_core.models import Contributor, CoreMetaData, Coverage, Creator, Date, \\\n    Format, FundingAgency, Identifier, Subject, Relation, GeospatialRelation\nfrom hs_core.views import utils as view_utils\nfrom hs_core.views.utils import ACTION_TO_AUTHORIZE\n\nlogger = logging.getLogger(__name__)\n\n\nclass Identifiers(serializers.DictField):\n    child = serializers.CharField()\n\n\nclass PartySerializer(serializers.Serializer):\n    name = serializers.CharField()\n    hydroshare_user_id = serializers.IntegerField(required=False)\n    organization = serializers.CharField(required=False)\n    email = serializers.EmailField(required=False)\n    address = serializers.CharField(required=False)\n    phone = serializers.CharField(required=False)\n    homepage = serializers.URLField(required=False)\n    identifiers = Identifiers(required=False)\n\n    class Meta:\n        model = Creator\n        fields = {'name', 'hydroshare_user_id', 'organization', 'email',\n                  'address', 'phone', 'homepage', 'identifiers'}\n\n\nclass CreatorSerializer(PartySerializer):\n    order = serializers.IntegerField(required=False)\n\n    class Meta:\n        model = Contributor\n\n\nclass DateSerializer(serializers.Serializer):\n    # term = 'Date'\n    type = serializers.CharField(required=False)\n    start_date = serializers.DateTimeField(required=False)\n    end_date = serializers.DateTimeField(required=False)\n\n    class Meta:\n        model = Date\n\n\nclass CoverageSerializer(serializers.Serializer):\n    type = serializers.CharField(required=False)\n    value = serializers.SerializerMethodField(required=False)\n\n    class Meta:\n        model = Coverage\n\n    def get_value(self, obj):\n        return obj.value\n\n\nclass FormatSerializer(serializers.Serializer):\n    value = serializers.CharField(required=False)\n\n    class Meta:\n        model = Format\n\n\nclass FundingAgencySerializer(serializers.Serializer):\n    agency_name = serializers.CharField()\n    award_title = serializers.CharField(required=False)\n    award_number = serializers.CharField(required=False)\n    agency_url = serializers.URLField(required=False)\n\n    class Meta:\n        model = FundingAgency\n\n\nclass IdentifierSerializer(serializers.Serializer):\n    name = serializers.CharField(required=False)\n    url = serializers.URLField(required=False)\n\n    class Meta:\n        model = Identifier\n\n\nclass SubjectSerializer(serializers.Serializer):\n    value = serializers.CharField(required=False)\n\n    class Meta:\n        model = Subject\n\n\nclass RelationSerializer(serializers.Serializer):\n    type = serializers.CharField(required=False)\n    value = serializers.CharField(required=False)\n\n    class Meta:\n        model = Relation\n\n\nclass GeospatialRelationSerializer(RelationSerializer):\n    type = serializers.CharField(required=False)\n    value = serializers.CharField(required=False)\n    text = serializers.CharField(required=False)\n\n    class Meta:\n        model = GeospatialRelation\n\n\nclass CoreMetaDataSerializer(serializers.Serializer):\n    title = serializers.CharField(required=False)\n    creators = CreatorSerializer(required=False, many=True)\n    contributors = PartySerializer(required=False, many=True)\n    coverages = CoverageSerializer(required=False, many=True)\n    dates = DateSerializer(required=False, many=True)\n    description = serializers.CharField(required=False)\n    formats = FormatSerializer(required=False, many=True)\n    funding_agencies = FundingAgencySerializer(required=False, many=True)\n    identifiers = IdentifierSerializer(required=False, many=True)\n    language = serializers.CharField(required=False)\n    rights = serializers.CharField(required=False)\n    type = serializers.CharField(required=False)\n    publisher = serializers.CharField(required=False)\n    subjects = SubjectSerializer(required=False, many=True)\n    relations = RelationSerializer(required=False, many=True)\n    geospatialrelations = GeospatialRelationSerializer(required=False, many=True)\n\n    class Meta:\n        model = CoreMetaData\n\n\nclass MetadataElementsRetrieveUpdate(generics.RetrieveUpdateDestroyAPIView):\n    \"\"\"\n    Retrieve resource science (Dublin Core) metadata\n\n    REST URL: /hsapi/resource/{pk}/scimeta/elements/\n    HTTP method: GET\n\n    :type pk: str\n    :param pk: id of the resource\n    :return: resource science metadata as JSON document\n    :rtype: str\n    :raises:\n    NotFound: return json format: {'detail': 'No resource was found for resource id:pk'}\n    PermissionDenied: return json format: {'detail': 'You do not have permission to perform\n    this action.'}\n\n    REST URL: /hsapi/resource/{pk}/scimeta/elements/\n    HTTP method: PUT\n\n    :type pk: str\n    :param pk: id of the resource\n    :type request: JSON formatted string\n    :param request: resource metadata\n    :return: updated resource science metadata as JSON document\n    :rtype: str\n    :raises:\n    NotFound: return json format: {'detail': 'No resource was found for resource id':pk}\n    PermissionDenied: return json format: {'detail': 'You do not have permission to perform\n    this action.'}\n    ValidationError: return json format: {parameter-1': ['error message-1'],\n    'parameter-2': ['error message-2'], .. }\n    \"\"\"\n    ACCEPT_FORMATS = ('application/json',)\n\n    allowed_methods = ('GET', 'PUT')\n\n    # Overwritten by resource types with extended metadata\n    serializer_class = CoreMetaDataSerializer\n\n    def get(self, request, pk):\n        view_utils.authorize(request, pk, needed_permission=ACTION_TO_AUTHORIZE.VIEW_METADATA)\n        resource = hydroshare.get_resource_by_shortkey(shortkey=pk)\n        serializer = resource.metadata.serializer\n        self.serializer_class = resource.metadata.serializer\n        return Response(data=serializer.data, status=status.HTTP_200_OK)\n\n    def put(self, request, pk):\n        # Update science metadata\n        resource, _, _ = view_utils.authorize(\n            request, pk,\n            needed_permission=ACTION_TO_AUTHORIZE.EDIT_RESOURCE)\n\n        metadata = []\n        put_data = request.data.copy()\n\n        # convert the QueryDict to dict\n        if isinstance(put_data, QueryDict):\n            put_data = put_data.dict()\n        try:\n            resource.metadata.parse_for_bulk_update(put_data, metadata)\n            hydroshare.update_science_metadata(pk=pk, metadata=metadata, user=request.user)\n        except Exception as ex:\n            error_msg = {\n                'resource': \"Resource metadata update failed: %s, %s\"\n                            % (ex.__class__, str(ex))\n            }\n            raise ValidationError(detail=error_msg)\n\n        resource = hydroshare.get_resource_by_shortkey(shortkey=pk)\n        serializer = resource.metadata.serializer\n        self.serializer_class = serializer\n        return Response(data=serializer.data, status=status.HTTP_202_ACCEPTED)\n", "path": "hs_core/views/resource_metadata_rest_api.py"}], "after_files": [{"content": "import logging\n\nfrom django.http import QueryDict\n\nfrom rest_framework.response import Response\nfrom rest_framework.exceptions import ValidationError\nfrom rest_framework import status\nfrom rest_framework import generics\nfrom rest_framework import serializers\n\nfrom hs_core import hydroshare\nfrom hs_core.models import Contributor, CoreMetaData, Coverage, Creator, Date, \\\n    Format, FundingAgency, Identifier, Subject, Relation, GeospatialRelation\nfrom hs_core.views import utils as view_utils\nfrom hs_core.views.utils import ACTION_TO_AUTHORIZE\n\nlogger = logging.getLogger(__name__)\n\n\nclass Identifiers(serializers.DictField):\n    child = serializers.CharField()\n\n\nclass PartySerializer(serializers.Serializer):\n    name = serializers.CharField()\n    hydroshare_user_id = serializers.IntegerField(required=False)\n    organization = serializers.CharField(required=False)\n    email = serializers.EmailField(required=False)\n    address = serializers.CharField(required=False)\n    phone = serializers.CharField(required=False)\n    homepage = serializers.URLField(required=False)\n    identifiers = Identifiers(required=False)\n\n    class Meta:\n        model = Creator\n        fields = {'name', 'hydroshare_user_id', 'organization', 'email',\n                  'address', 'phone', 'homepage', 'identifiers'}\n\n\nclass CreatorSerializer(PartySerializer):\n    order = serializers.IntegerField(required=False)\n\n    class Meta:\n        model = Contributor\n\n\nclass DateSerializer(serializers.Serializer):\n    # term = 'Date'\n    type = serializers.CharField(required=False)\n    start_date = serializers.DateTimeField(required=False)\n    end_date = serializers.DateTimeField(required=False)\n\n    class Meta:\n        model = Date\n\n\nclass CoverageSerializer(serializers.Serializer):\n    type = serializers.CharField(required=False)\n    value = serializers.SerializerMethodField(required=False)\n\n    class Meta:\n        model = Coverage\n\n    def get_value(self, obj):\n        return obj.value\n\n\nclass FormatSerializer(serializers.Serializer):\n    value = serializers.CharField(required=False)\n\n    class Meta:\n        model = Format\n\n\nclass FundingAgencySerializer(serializers.Serializer):\n    agency_name = serializers.CharField()\n    award_title = serializers.CharField(required=False)\n    award_number = serializers.CharField(required=False)\n    agency_url = serializers.URLField(required=False)\n\n    class Meta:\n        model = FundingAgency\n\n\nclass IdentifierSerializer(serializers.Serializer):\n    name = serializers.CharField(required=False)\n    url = serializers.URLField(required=False)\n\n    class Meta:\n        model = Identifier\n\n\nclass SubjectSerializer(serializers.Serializer):\n    value = serializers.CharField(required=False)\n\n    class Meta:\n        model = Subject\n\n\nclass RelationSerializer(serializers.Serializer):\n    type = serializers.CharField(required=False)\n    value = serializers.CharField(required=False)\n\n    class Meta:\n        model = Relation\n\n\nclass GeospatialRelationSerializer(RelationSerializer):\n    type = serializers.CharField(required=False)\n    value = serializers.CharField(required=False)\n    text = serializers.CharField(required=False)\n\n    class Meta:\n        model = GeospatialRelation\n\n\nclass CoreMetaDataSerializer(serializers.Serializer):\n    title = serializers.CharField(required=False)\n    creators = CreatorSerializer(required=False, many=True)\n    contributors = PartySerializer(required=False, many=True)\n    coverages = CoverageSerializer(required=False, many=True)\n    dates = DateSerializer(required=False, many=True)\n    description = serializers.CharField(required=False)\n    formats = FormatSerializer(required=False, many=True)\n    funding_agencies = FundingAgencySerializer(required=False, many=True)\n    identifiers = IdentifierSerializer(required=False, many=True)\n    language = serializers.CharField(required=False)\n    rights = serializers.CharField(required=False)\n    type = serializers.CharField(required=False)\n    publisher = serializers.CharField(required=False)\n    subjects = SubjectSerializer(required=False, many=True)\n    relations = RelationSerializer(required=False, many=True)\n    geospatialrelations = GeospatialRelationSerializer(required=False, many=True)\n\n    class Meta:\n        model = CoreMetaData\n\n\nclass MetadataElementsRetrieveUpdate(generics.RetrieveUpdateDestroyAPIView):\n    \"\"\"\n    Retrieve resource science (Dublin Core) metadata\n\n    REST URL: /hsapi/resource/{pk}/scimeta/elements/\n    HTTP method: GET\n\n    :type pk: str\n    :param pk: id of the resource\n    :return: resource science metadata as JSON document\n    :rtype: str\n    :raises:\n    NotFound: return json format: {'detail': 'No resource was found for resource id:pk'}\n    PermissionDenied: return json format: {'detail': 'You do not have permission to perform\n    this action.'}\n\n    REST URL: /hsapi/resource/{pk}/scimeta/elements/\n    HTTP method: PUT\n\n    :type pk: str\n    :param pk: id of the resource\n    :type request: JSON formatted string\n    :param request: resource metadata\n    :return: updated resource science metadata as JSON document\n    :rtype: str\n    :raises:\n    NotFound: return json format: {'detail': 'No resource was found for resource id':pk}\n    PermissionDenied: return json format: {'detail': 'You do not have permission to perform\n    this action.'}\n    ValidationError: return json format: {parameter-1': ['error message-1'],\n    'parameter-2': ['error message-2'], .. }\n    \"\"\"\n    ACCEPT_FORMATS = ('application/json',)\n\n    allowed_methods = ('GET', 'PUT')\n\n    # Overwritten by resource types with extended metadata\n    serializer_class = CoreMetaDataSerializer\n\n    def get(self, request, pk):\n        view_utils.authorize(request, pk, needed_permission=ACTION_TO_AUTHORIZE.VIEW_METADATA)\n        resource = hydroshare.get_resource_by_shortkey(shortkey=pk)\n        serializer = resource.metadata.serializer\n        return Response(data=serializer.data, status=status.HTTP_200_OK)\n\n    def put(self, request, pk):\n        # Update science metadata\n        resource, _, _ = view_utils.authorize(\n            request, pk,\n            needed_permission=ACTION_TO_AUTHORIZE.EDIT_RESOURCE)\n\n        metadata = []\n        put_data = request.data.copy()\n\n        # convert the QueryDict to dict\n        if isinstance(put_data, QueryDict):\n            put_data = put_data.dict()\n        try:\n            resource.metadata.parse_for_bulk_update(put_data, metadata)\n            hydroshare.update_science_metadata(pk=pk, metadata=metadata, user=request.user)\n        except Exception as ex:\n            error_msg = {\n                'resource': \"Resource metadata update failed: %s, %s\"\n                            % (ex.__class__, str(ex))\n            }\n            raise ValidationError(detail=error_msg)\n\n        resource = hydroshare.get_resource_by_shortkey(shortkey=pk)\n        serializer = resource.metadata.serializer\n        return Response(data=serializer.data, status=status.HTTP_202_ACCEPTED)\n", "path": "hs_core/views/resource_metadata_rest_api.py"}]}