예제 #1
0
def put_collection(collection_id, institution_id, title, hidden=None, object_store_uri=None):
    PythonApi.getInstance().getCollectionCommandService().putCollection(
        collection_id,
        Collection.Builder()
            .setHidden(Optional.fromNullable(hidden))
            .setInstitutionId(institution_id)
            .setObjectStoreUri(Optional.fromNullable(object_store_uri))
            .setTitle(title)
            .build()
    )
예제 #2
0
 def findAmbiguity(cls, original, replacement):
     """ generated source for method findAmbiguity """
     Preconditions.checkArgument(original.__name__ == replacement.__name__)
     Preconditions.checkArgument(not original == replacement)
     ConcurrencyUtils.checkForInterruption()
     replacementsByOriginalTupleIndex = Maps.newHashMap()
     # Make the arguments ?v0, ?v1, ?v2, ... so we can find the tuple indices easily
     originalSentence = original.getSentenceFromTuple(getNumberedTuple(original.getTupleSize()))
     replacementSentence = replacement.getSentenceFromTuple(getNumberedTuple(replacement.getTupleSize()))
     success = cls.findAmbiguity(originalSentence.getBody(), replacementSentence.getBody(), replacementsByOriginalTupleIndex)
     if success:
         return Optional.of(cls.Ambiguity.create(original, replacementsByOriginalTupleIndex, replacement))
     else:
         return Optional.absent()
    def _parse_record_metadata_description_element(self, element, object_builder):
        text = element.text.strip()
        if len(text) == 0:
            return

        description_type = None
        qualifier = element.attrib.get('qualifier', None)
        if qualifier is not None:
            if qualifier == 'content':
                description_type = None
            elif qualifier == 'physical':
                description_type = DescriptionType.PHYSICAL
            else:
                self._logger.warn("unknown description qualifier '%s'", qualifier)

        object_builder.descriptions.append(
            Description.Builder()
                .setText(text)
                .setType(Optional.fromNullable(description_type))
                .build()
        )
예제 #4
0
def put_institution(institution_id, institution_title, institution_url, store_parameters, collection_store_uri=None, data_rights=None):
    if data_rights is None:
        data_rights = \
            RightsSet.Builder()\
                .setElements(ImmutableList.of(
                    Rights.Builder()
                        .setRightsHolder(institution_title)
                        .setText("Copyright %s %s" % (datetime.now().year, institution_title))
                        .setType(RightsType.COPYRIGHTED)
                        .build()

                ))\
                .build()

    PythonApi.getInstance().getInstitutionCommandService().putInstitution(
        institution_id,
        Institution.Builder()
            .setCollectionStoreUri(Optional.fromNullable(collection_store_uri))
            .setDataRights(data_rights)
            .setStoreParameters(store_parameters)
            .setTitle(institution_title)
            .setUrl(institution_url)
            .build()
    )
    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_)