def __init__(self, *args, **kwds): unittest.TestCase.__init__(self, *args, **kwds) data_dir_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', '..', '..', '..', '..', 'data', 'extracted', 'untvca', 'txfc')) self.__store = \ OaiPmhFsObjectStore( record_mapper=TxfcOaiPmhRecordMapper(), uri=Uri.parse(OaiPmhFsObjectStore.URI_SCHEME + ':/' + data_dir_path.replace(os.path.sep, '/')) )
def _parse_work_type(self, text): text = text.strip().replace(' ', '') if text in DCMI_TYPES: if text in ('Image', 'PhysicalObject', 'StillImage'): return \ WorkType.builder()\ .setText(text)\ .setVocabRef( VocabRef.builder() .setRefid(text)\ .setVocab(Vocab.DCMI_TYPE)\ .setUri(Uri.parse(DCMI_TYPES_BASE_URL + text))\ .build() )\ .build()
def _parse_record_metadata_rights_element(self, element, object_builder): text = element.text.strip() if len(text) == 0: return qualifier = element.attrib.get('qualifier', None) if qualifier is None: self._logger.warn("rights element without qualifier on record %s", object_builder.record_identifier) return if qualifier == 'access': assert text == 'public', text elif qualifier == 'license': if text == 'by-nc-nd': license_vocab_ref = \ VocabRef.Builder()\ .setVocab(Vocab.CREATIVE_COMMONS)\ .setUri(Uri.parse('https://creativecommons.org/licenses/by-nc-nd/2.0/'))\ .build() else: license_vocab_ref = None self._logger.warn("ignoring unknown license text '%s' on record %s", text, object_builder.record_identifier) object_builder.rights.append( Rights.Builder() .setLicenseVocabRef(license_vocab_ref) .setRightsHolder(self._RIGHTS_HOLDER) .setText(text) .setType(RightsType.LICENSED) .build() ) elif qualifier == 'statement': object_builder.rights.append( Rights.Builder() .setRightsHolder(self._RIGHTS_HOLDER) .setText(text) .setType(RightsType.COPYRIGHTED) .build() ) else: self._logger.warn("ignoring unknown rights qualifier '%s' on record %s", qualifier, object_builder.record_identifier)
def _parse_record_metadata_resourceType_element(self, element, object_builder): text = element.text.strip() if len(text) == 0: return if text == 'physical-object': text = 'PhysicalObject' elif text == 'video': text = 'MovingImage' else: raise NotImplementedError(text) object_builder.work_types.append( WorkType.Builder()\ .setText(text)\ .setVocabRef( VocabRef.Builder() .setRefid(text)\ .setVocab(Vocab.DCMI_TYPE)\ .setUri(Uri.parse(DCMI_TYPES_BASE_URL + text))\ .build() )\ .build() )
def __init__(self, *args, **kwds): _OmekaObjectStoreTest.__init__(self, *args, **kwds) self._store = OmekaApiObjectStore( api_key=OMEKA_API_TEST_API_KEY, uri=Uri.parse(OMEKA_API_TEST_ENDPOINT_URL.replace("http://", "omekaapi://")) )
def __init__(self, *args, **kwds): _OmekaCollectionStoreTest.__init__(self, *args, **kwds) data_dir_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', '..', '..', '..', '..', 'data', 'extracted')) self._store = OmekaFsCollectionStore(uri=Uri.parse('omekafs:/' + data_dir_path.replace(os.path.sep, '/')))
def __init__(self, *args, **kwds): _OmekaCollectionStoreTest.__init__(self, *args, **kwds) self._store = OmekaApiCollectionStore(api_key=OMEKA_API_TEST_API_KEY, uri=Uri.parse(OMEKA_API_TEST_ENDPOINT_URL.replace('http://', 'omekaapi://')))
def __init__(self, *args, **kwds): _OmekaObjectStoreTest.__init__(self, *args, **kwds) data_dir_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', '..', '..', '..', '..', 'data', 'extracted')) self._store = OmekaFsObjectStore(endpoint_url=self.ENDPOINT_URL, uri=Uri.parse('omekafs:/' + data_dir_path.replace(os.path.sep, '/')))
.setText("The contents of Texas Fashion Collection, hosted by the University of North Texas Libraries (digital content including images, text, and sound and video recordings) are made publicly available by the collection-holding partners for use in research, teaching, and private study. For the full terms of use, see http://digital.library.unt.edu/terms-of-use/") .setType(RightsType.COPYRIGHTED) .build() )) .build(), institution_id=InstitutionId.parse('untvca'), institution_title='Texas Fashion Collection', institution_url=Url.parse('http://digital.library.unt.edu/explore/collections/TXFC/'), store_parameters=ImmutableMap.of( 'record_mapper', TxfcOaiPmhRecordMapper.__module__ + '.' + TxfcOaiPmhRecordMapper.__name__ # @UndefinedVariable ), ) put_collection( collection_id=CollectionId.parse('untvca/txfc'), institution_id=InstitutionId.parse('untvca'), object_store_uri=Uri.parse(OaiPmhFsObjectStore.URI_SCHEME + ':/' + os.path.join(data_dir_path, 'untvca', 'txfc').replace(os.path.sep, '/')), title='Texas Fashion Collection' ) put_institution( collection_store_uri=Uri.parse(OmekaFsCollectionStore.URI_SCHEME + ':/' + data_dir_path.replace(os.path.sep, '/')), institution_id=InstitutionId.parse('vccc'), institution_title='Vassar College Costume Collection', institution_url=Url.parse('http://vcomeka.com/vccc/'), store_parameters=ImmutableMap.of( 'endpoint_url', 'http://vcomeka.com/vccc', 'resource_mapper', VcccOmekaResourceMapper.__module__ + '.' + VcccOmekaResourceMapper.__name__ # @UndefinedVariable ), ) put_institution( collection_store_uri=Uri.parse(OmekaApiCollectionStore.URI_SCHEME + '://historicdress.org/omeka2/'),
def map_omeka_item(self, collection_id, endpoint_url, omeka_item, omeka_item_files, square_thumbnail_height_px, square_thumbnail_width_px): object_id = ObjectId.parse(str(collection_id) + '/' + str(omeka_item.id)) vocab_ref = VocabRef.Builder().setVocab(Vocab.COSTUME_CORE).build() feature_name = None omeka_collection_id = int(collection_id.getUnqualifiedCollectionId()) for item in self.OMEKA_COLLECTIONS.iteritems(): if item[1] == omeka_collection_id: feature_name = item[0] break assert feature_name is not None feature_value = None item_image_credit_line = item_image_license = None for element_text in omeka_item.element_texts: if len(element_text.text) == 0: continue if element_text.element_set.name == 'Dublin Core': if element_text.element.name == 'Title': if feature_value is None: feature_value = element_text.text elif element_text.element_set.name == 'Item Type Metadata': if element_text.element.name == 'Image Creator': item_image_credit_line = element_text.text elif element_text.element.name == 'Image License': item_image_license = element_text.text else: self._logger.warn("Omeka item %d has unknown element set name '%s'", omeka_item.id, element_text.element_set.name) object_builder = \ Object.Builder()\ .setCollectionId(collection_id)\ .setHidden(True)\ .setInstitutionId(collection_id.getInstitutionId())\ .setStructures(\ StructureSet.Builder().setElements(ImmutableList.of( Structure.Builder() .setText(feature_value) .setType( StructureType.Builder() .setText(feature_name) .setVocabRef(vocab_ref) .build() ) .build() )) .build() )\ .setTitles( TitleSet.Builder().setElements(ImmutableList.of( Title.Builder() .setText("%(feature_value)s" % locals()) .setType(TitleType.DESCRIPTIVE) .build() )) .build() )\ .setViewType(ViewType.DETAIL) images = [] for file_ in omeka_item_files: if not file_.mime_type.startswith('image/'): continue image_credit_line = item_image_credit_line image_license = item_image_license for element_text in file_.element_texts: if element_text.element_set.name == 'Dublin Core': if element_text.element.name == 'License': image_license = element_text.text elif element_text.element.name == 'Provenance': image_credit_line = element_text.text if image_credit_line is None or len(image_credit_line) == 0: self._logger.warn("Omeka item %d has a file %d missing a Provenance", omeka_item.id, file_.id) continue if image_license is None or len(image_license) == 0: self._logger.warn("Omeka item %d has a file %d missing a License", omeka_item.id, file_.id) continue license_vocab_ref = None if image_license.lower() == 'public domain': rights_type = RightsType.PUBLIC_DOMAIN elif image_license == 'CC0': rights_type = RightsType.LICENSED license_vocab_ref = \ VocabRef.Builder()\ .setVocab(Vocab.CREATIVE_COMMONS)\ .setUri(Uri.parse('https://creativecommons.org/publicdomain/zero/1.0/'))\ .build() elif image_license.startswith('CC BY-SA '): rights_type = RightsType.LICENSED version = image_license[len('CC BY-SA '):] float(version) license_vocab_ref = \ VocabRef.Builder()\ .setVocab(Vocab.CREATIVE_COMMONS)\ .setUri(Uri.parse("https://creativecommons.org/licenses/by-sa/%s/" % version))\ .build() else: rights_type = RightsType.LICENSED image_builder = Image.Builder() # @UndefinedVariable file_urls = file_.file_urls image_builder.setOriginal(ImageVersion.Builder().setUrl(Url.parse(file_urls.original)).build()) image_builder.setRights( RightsSet.Builder().setElements(ImmutableList.of( Rights.Builder() .setLicenseVocabRef(Optional.fromNullable(license_vocab_ref)) .setRightsHolder(image_credit_line) .setText(image_license) .setType(rights_type) .build() )) .build() ) if file_urls.square_thumbnail is None: self._logger.warn("Omeka item %d has a file %d missing a square thumbnail", omeka_item.id, file_.id) continue image_builder.setSquareThumbnail( ImageVersion.Builder() .setHeightPx(UnsignedInteger.valueOf(square_thumbnail_height_px)) .setUrl(Url.parse(file_urls.square_thumbnail)) .setWidthPx(UnsignedInteger.valueOf(square_thumbnail_width_px)) .build() ) images.append(image_builder.build()) if len(images) > 0: object_builder.setImages(ImmutableList.copyOf(images)) else: self._logger.warn("Omeka item %d has no valid images", omeka_item.id) object_ = object_builder.build() object_id = ObjectId.parse(str(collection_id) + '/' + urllib.quote(feature_value, '')) return ObjectEntry(object_id, object_)