<jupyter_start><jupyter_text>Create System Metadata v2Basic example of version 2.0 system metadata for an EML metadata document. The mediaType and fileName options are specified.Note: This code uses a current beta branch of the version 2.0 d1_common_python source located at https://repository.dataone.org/software/cicore/branches/d1_common_python_v2_vieglais<jupyter_code>from d1_common.types import dataoneTypes

# Create minimal System Metadata instance with bogus data
system_metadata = dataoneTypes.systemMetadata()
system_metadata.identifier = "Test_identifier"
system_metadata.formatId = "eml://ecoinformatics.org/eml-2.0.1"
system_metadata.size = 17181
checksum = dataoneTypes.checksum("03ce09c6b4c3efc1681f3023402998a2")
checksum.algorithm = "MD5"
system_metadata.checksum = checksum
system_metadata.submitter = "CN=urn:node:cnStageUNM1,DC=dataone,DC=org"
system_metadata.rightsHolder = "CN=testRightsHolder,DC=dataone,DC=org"

#enable public read by adding read permission for the "Public" user
access_policy = dataoneTypes.accessPolicy()
access_rule = dataoneTypes.accessRule()
access_rule.subject.append("Public")
access_rule.permission.append(dataoneTypes.Permission('read'))
access_policy.append(access_rule)
system_metadata.accessPolicy = access_policy

#Replication Policy
replication_policy = dataoneTypes.replicationPolicy()
replication_policy.replicationAllowed = True
replication_policy.numberReplicas = 3
system_metadata.replicationPolicy = replication_policy

#Media type information
media_type = dataoneTypes.mediaType()
media_type.name = "text/xml"
system_metadata.mediaType = media_type
system_metadata.fileName = "metadata.xml"

dom = system_metadata.toDOM(None)
xml = dom.toprettyxml(indent="  ")
print xml<jupyter_output><?xml version="1.0" ?>
<ns1:systemMetadata xmlns:ns1="http://ns.dataone.org/service/types/v2.0">
  <identifier>Test_identifier</identifier>
  <formatId>eml://ecoinformatics.org/eml-2.0.1</formatId>
  <size>17181</size>
  <checksum algorithm="MD5">03ce09c6b4c3efc1681f3023402998a2</checksum>
  <submitter>CN=urn:node:cnStageUNM1,DC=dataone,DC=org</submitter>
  <rightsHolder>CN=testRightsHolder,DC=dataone,DC=org</rightsHolder>
  <accessPolicy>
    <allow>
      <subject>Public</subject>
      <permission>read</permission>
    </allow>
  </accessPolicy>
  <replicationPolicy numberReplicas="3" replicationAllowed="true"/>
  <mediaType name="text/xml"/>
  <fileName>metadata.xml</fileName>
</ns1:systemMetadata><jupyter_text>Create Version 2.0 System Metadata With a Complex Media TypeSome IANA media types (aka MIME types) have required or optional parameters. A good example is ``video/H264`` ( http://www.iana.org/assignments/media-types/video/H264 ). The example below provides a fictious system metadata instance describing a video file.<jupyter_code># Create minimal System Metadata instance with bogus data
system_metadata = dataoneTypes.systemMetadata()
system_metadata.identifier = "H264_video_example"
#No H264 formatId, so use generic octet-stream
system_metadata.formatId = "application/octet-stream"
system_metadata.size = 171199843
checksum = dataoneTypes.checksum("03ce094432c3efc1681f3023402998a2")
checksum.algorithm = "MD5"
system_metadata.checksum = checksum
system_metadata.submitter = "CN=urn:node:cnStageUNM1,DC=dataone,DC=org"
system_metadata.rightsHolder = "CN=testRightsHolder,DC=dataone,DC=org"

#enable public read by adding read permission for the "Public" user
access_policy = dataoneTypes.accessPolicy()
access_rule = dataoneTypes.accessRule()
access_rule.subject.append("Public")
access_rule.permission.append(dataoneTypes.Permission('read'))
access_policy.append(access_rule)
system_metadata.accessPolicy = access_policy

#Replication Policy
replication_policy = dataoneTypes.replicationPolicy()
replication_policy.replicationAllowed = True
replication_policy.numberReplicas = 3
system_metadata.replicationPolicy = replication_policy

#Media Type with optional parameters
media_type.name = "video/H264"
media_type_property = dataoneTypes.MediaTypeProperty("H44I")
media_type_property.name = "profile-level-id"
media_type.property_.append(media_type_property)

media_type_property = dataoneTypes.MediaTypeProperty("6F", name="max-recv-level")
media_type.property_.append(media_type_property)

media_type_property = dataoneTypes.MediaTypeProperty("255", name="sar-supported")
media_type.property_.append(media_type_property)

system_metadata.mediaType = media_type
system_metadata.fileName = "cool_video.avc"

dom = system_metadata.toDOM(None)
xml = dom.toprettyxml(indent="  ")
print xml<jupyter_output><?xml version="1.0" ?>
<ns1:systemMetadata xmlns:ns1="http://ns.dataone.org/service/types/v2.0">
  <identifier>H264_video_example</identifier>
  <formatId>application/octet-stream</formatId>
  <size>171199843</size>
  <checksum algorithm="MD5">03ce094432c3efc1681f3023402998a2</checksum>
  <submitter>CN=urn:node:cnStageUNM1,DC=dataone,DC=org</submitter>
  <rightsHolder>CN=testRightsHolder,DC=dataone,DC=org</rightsHolder>
  <accessPolicy>
    <allow>
      <subject>Public</subject>
      <permission>read</permission>
    </allow>
  </accessPolicy>
  <replicationPolicy numberReplicas="3" replicationAllowed="true"/>
  <mediaType name="video/H264">
    <property name="profile-level-id">H44I</property>
    <property name="max-recv-level">6F</property>
    <property name="sar-supported">255</property>
  </mediaType>
  <fileName>cool_video.avc</fileName>
</ns1:systemMetadata>
{'fraction_non_alphanumeric': 0.11220940874977119, 'fraction_numerical': 0.035877722862895846, 'mean_word_length': 7.497667185069984, 'pattern_counts': {'":': 0, '<': 68, '<?xml version=': 2, '>': 68, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 14}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '178781', 'license': 'Apache-2.0', 'n_tokens_mistral': 1859, 'n_tokens_neox': 1765, 'n_words': 299, 'path': 'notebooks/system_metadata_v2_media_type.ipynb', 'repo_name': 'vdave/dataonePythonExamples', 'size': '5463'}