Esempio n. 1
0
def install_episode():
    DS_COMP_MODEL = u"""
    <dsCompositeModel xmlns="info:fedora/fedora-system:def/dsCompositeModel#">
      <comment xmlns="info:fedora/fedora-system:def/comment#">
        This DS-COMPOSITE-MODEL datastream is included as a starting point to
          assist in the creation of a content model. The DS-COMPOSITE-MODEL
          should define the datastreams that are required for any objects
          conforming to this content model.
        For more information about content models, see:
          http://fedora-commons.org/confluence/x/dgBI.
        For examples of completed content model objects, see the demonstration
          objects included with your Fedora distribution, such as:
          demo:CMImage, demo:UVA_STD_IMAGE, demo:DualResImageCollection,
          demo:TEI_TO_PDFDOC, and demo:XML_TO_HTMLDOC.
        For more information about the demonstration objects, see:
          http://fedora-commons.org/confluence/x/AwFI.
      </comment>
      <dsTypeModel ID="THUMBNAIL">
        <form MIME="image/jpeg"></form>
      </dsTypeModel>
      <dsTypeModel ID="RAW">
        <form MIME="application/octet-stream"></form>
      </dsTypeModel>
      <dsTypeModel ID="RAW_INFO">
        <form MIME="text/plain"></form>
      </dsTypeModel>
      <dsTypeModel ID="MP4">
        <form MIME="video/mp4"></form>
      </dsTypeModel>
      <dsTypeModel ID="OGV">
        <form MIME="video/ogg"></form>
      </dsTypeModel>
    </dsCompositeModel>
    """

    client = get_client()

    obj = client.createObject(pp("EPISODE"), label=u"Content Model for video objects")

    obj.addDataStream(u"RELS-EXT")
    rels = obj["RELS-EXT"]
    rels[NS.rdfs.hasModel].append(dict(type=u"uri", value=u"info:fedora/fedora-system:ContentModel-3.0"))
    rels.checksumType = u"DISABLED"
    rels.setContent()

    obj.addDataStream(
        u"DS-COMPOSITE-MODEL",
        DS_COMP_MODEL,
        label=u"datastream composite model",
        formatURI=u"info:fedora/fedora-system:FedoraDSCompositeModel-1.0",
        logMessage=u"adding ds comp model",
    )
    comp = obj["DS-COMPOSITE-MODEL"]
    comp.checksumType = u"DISABLED"

    dc = obj["DC"]
    for datastream in [dc, comp, rels]:
        datastream.versionable = False

    return True
Esempio n. 2
0
 def testInstallPurgeEpisodeContentModel(self):
     # episode is installed in setup, so it should fail to add it again
     self.assertRaises(FedoraConnectionException, install_episode)
     purge_episode()
     # removing it twice should raise the same exception
     self.assertRaises(FedoraConnectionException, purge_episode)
     # when not already in the system, install should work
     install_episode()
     client = get_client()
     client.getObject(pp('EPISODE'))  # as should get
Esempio n. 3
0
 def testInstallPurgeEpisodeContentModel(self):
     # episode is installed in setup, so it should fail to add it again
     self.assertRaises(FedoraConnectionException, install_episode)
     purge_episode()
     # removing it twice should raise the same exception
     self.assertRaises(FedoraConnectionException, purge_episode)
     # when not already in the system, install should work
     install_episode()
     client = get_client()
     client.getObject(pp('EPISODE')) # as should get
Esempio n. 4
0
def purge_episode():
    client = get_client()
    client.deleteObject(pp("EPISODE"), logMessage=u"clearing episode model")
Esempio n. 5
0
def purge_episode():
    client = get_client()
    client.deleteObject(pp('EPISODE'), logMessage=u'clearing episode model')
Esempio n. 6
0
def install_episode():
    DS_COMP_MODEL = u"""
    <dsCompositeModel xmlns="info:fedora/fedora-system:def/dsCompositeModel#">
      <comment xmlns="info:fedora/fedora-system:def/comment#">
        This DS-COMPOSITE-MODEL datastream is included as a starting point to
          assist in the creation of a content model. The DS-COMPOSITE-MODEL
          should define the datastreams that are required for any objects
          conforming to this content model.
        For more information about content models, see:
          http://fedora-commons.org/confluence/x/dgBI.
        For examples of completed content model objects, see the demonstration
          objects included with your Fedora distribution, such as:
          demo:CMImage, demo:UVA_STD_IMAGE, demo:DualResImageCollection,
          demo:TEI_TO_PDFDOC, and demo:XML_TO_HTMLDOC.
        For more information about the demonstration objects, see:
          http://fedora-commons.org/confluence/x/AwFI.
      </comment>
      <dsTypeModel ID="THUMBNAIL">
        <form MIME="image/jpeg"></form>
      </dsTypeModel>
      <dsTypeModel ID="RAW">
        <form MIME="application/octet-stream"></form>
      </dsTypeModel>
      <dsTypeModel ID="RAW_INFO">
        <form MIME="text/plain"></form>
      </dsTypeModel>
      <dsTypeModel ID="MP4">
        <form MIME="video/mp4"></form>
      </dsTypeModel>
      <dsTypeModel ID="OGV">
        <form MIME="video/ogg"></form>
      </dsTypeModel>
    </dsCompositeModel>
    """

    client = get_client()

    obj = client.createObject(pp('EPISODE'),
                              label=u'Content Model for video objects')

    obj.addDataStream(u'RELS-EXT')
    rels = obj['RELS-EXT']
    rels[NS.rdfs.hasModel].append(
        dict(type=u'uri', value=u'info:fedora/fedora-system:ContentModel-3.0'))
    rels.checksumType = u'DISABLED'
    rels.setContent()

    obj.addDataStream(
        u'DS-COMPOSITE-MODEL',
        DS_COMP_MODEL,
        label=u'datastream composite model',
        formatURI=u'info:fedora/fedora-system:FedoraDSCompositeModel-1.0',
        logMessage=u'adding ds comp model')
    comp = obj['DS-COMPOSITE-MODEL']
    comp.checksumType = u'DISABLED'

    dc = obj['DC']
    for datastream in [dc, comp, rels]:
        datastream.versionable = False

    return True
Esempio n. 7
0
class VideoObjectManager(FedoraObjectManager):
    __cmodel__ = u'info:fedora/' + pp('EPISODE')

    @staticmethod
    def create(user, raw, raw_info, mp4, ogv, thumbnail, dc={}):
        fc = get_client()
        pid = fc.getNextPID(RTV_PID_NAMESPACE)

        obj = fc.createObject(pid, label=unicode(dc['title']))
        obj.addDataStream(u'RELS-EXT')
        rels = obj['RELS-EXT']
        rels[NS.rdfs.hasModel].append(
            dict(type=u'uri', value=VideoObjectManager.__cmodel__))
        rels.checksumType = u'DISABLED'
        rels.setContent()
        # info on raw media
        obj.addDataStream('RAW_INFO',
                          raw_info,
                          controlGroup=u'M',
                          label=u'source media info',
                          mimeType=u'text/plain',
                          checksumType=u'DISABLED',
                          versionable=False)
        info = obj['RAW_INFO']
        info.setContent()
        # media datastreams
        dstreams = (
            # datastream name, url, mimetype
            ('RAW', raw, u'application/octet-stream', u'R'),
            ('MP4', mp4, u'video/mp4', u'R'),
            ('OGV', ogv, u'video/ogv', u'R'),
            ('THUMBNAIL', thumbnail, u'image/jpeg', u'R'))
        for (dsname, url, mime, cgroup) in dstreams:
            obj.addDataStream(dsname,
                              controlGroup=cgroup,
                              label=u'media ds',
                              logMessage=u'adding ds',
                              location=unicode(url),
                              mimeType=mime,
                              checksumType=u'DISABLED',
                              versionable=False)

            #            These 2 lines basically commit the change to the fedora object,
            #            which helps us avoid getting object locked errors when adding
            #            numerous datastreams to an object in a short period of time.

            ds = obj[dsname]
            ds.setContent()

        vid = VideoObjectManager.get(pid=pid)
        if dc:
            vid.dict_to_dc(dc)
        return vid

    @staticmethod
    def all():
        fc = get_client()
        sparql = '''prefix rdfs: <%s>
        select ?s where {?s rdfs:hasModel <%s>.}
        ''' % (NS.rdfs, VideoObjectManager.__cmodel__)
        result = fc.searchTriples(sparql)

        pids = []
        for r in result:
            pids.append(unicode(r['s']['value'].replace('info:fedora/', '')))
        vids = [Video(pid) for pid in pids]
        return vids

    @staticmethod
    def get(**kwargs):
        fc = get_client()
        subqueries = []
        fields = kwargs.keys()
        for k, v in kwargs.iteritems():
            subqueries.append(''.join([k, '~', v]))
        query = unicode(' '.join(subqueries))
        results = [obj for obj in fc.searchObjects(query, fields)]
        if len(results) > 1:
            raise MultipleResultsError('Search yielded %d results' %
                                       len(results))
        elif len(results) == 0:
            raise ObjectNotFoundError('The search "%s" yielded 0 results' %
                                      query)
        return Video(pid=results[0]['pid'])