コード例 #1
0
ファイル: ddsite.py プロジェクト: minorg/dressdiscover
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
ファイル: ddsite.py プロジェクト: minorg/dressdiscover
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()
    )
コード例 #3
0
from os.path import os

from costume.api.services.collection.no_such_collection_exception import NoSuchCollectionException
from costume.lib.stores.collection.omeka._omeka_collection_store import _OmekaCollectionStore
from costume.lib.stores.collection.py_collection_store_factory import PyCollectionStoreFactory
from net.lab1318.costume.lib.python import PythonApi
from yomeka.client.omeka_json_parser import OmekaJsonParser


class OmekaFsCollectionStore(_OmekaCollectionStore):
    URI_SCHEME = 'omekafs'

    def getCollectionById(self, collectionId, logger, logMarker):
        collection_entries = self.getCollectionsByInstitutionId(collectionId.institutionId, logger, logMarker)
        for collection_entry in collection_entries:
            if collection_entry.id == collectionId:
                return collection_entry.model
        raise NoSuchCollectionException(collectionId)

    def getCollectionsByInstitutionId(self, institutionId, logger, logMarker):
        data_dir_path = self._uri.path.get()[1:].replace('/', os.path.sep)
        file_path = os.path.join(data_dir_path, str(institutionId), 'collections.json')
        with open(file_path) as f:
            return \
                self._map_omeka_collections(
                    institution_id=institutionId,
                    omeka_collections=OmekaJsonParser().parse_collection_dicts(json.loads(f.read()))
                )

PythonApi.getInstance().getCollectionStoreFactoryRegistry().registerCollectionStoreFactory(PyCollectionStoreFactory(OmekaFsCollectionStore), OmekaFsCollectionStore.URI_SCHEME)
コード例 #4
0
        self.__uri = uri
        self.__data_dir_path = self.__uri.path.get()[1:].replace("/", os.path.sep)

    def getObjectById(self, logger, log_marker, object_id):
        record_identifier = object_id.getUnqualifiedObjectId()
        record_identifier = urllib.unquote(record_identifier)
        file_path = os.path.join(self.__data_dir_path, "record", record_identifier + ".xml")
        if not os.path.isfile(file_path):
            raise NoSuchObjectException
        return self.__map_oai_pmh_record(collection_id=object_id.getCollectionId(), file_path=file_path)

    def getObjectsByCollectionId(self, collection_id, logger, log_marker):
        objects = []
        for root_dir_path, _, file_names in os.walk(os.path.join(self.__data_dir_path, "record")):
            for file_name in file_names:
                file_path = os.path.join(root_dir_path, file_name)
                if not file_path.endswith(".xml"):
                    os.rename(file_path, file_path + ".xml")
                    file_path = file_path + ".xml"
                objects.append(self.__map_oai_pmh_record(collection_id=collection_id, file_path=file_path))
        return ImmutableList.copyOf(objects)

    def __map_oai_pmh_record(self, collection_id, file_path):
        return self.__record_mapper.map_oai_pmh_record(collection_id, record_etree=ElementTree.parse(file_path))


if PythonApi.getInstance() is not None:
    PythonApi.getInstance().getObjectStoreFactoryRegistry().registerObjectStoreFactory(
        PyObjectStoreFactory(OaiPmhFsObjectStore), OaiPmhFsObjectStore.URI_SCHEME
    )
コード例 #5
0
        endpoint_url = 'http://' + str(uri.getAuthority().get()) + (uri.getPath().get() if uri.getPath().isPresent() else '')
        _OmekaObjectStore.__init__(self, endpoint_url=endpoint_url, uri=uri, **kwds)
        self.__api_client = OmekaRestApiClient(api_key=api_key, endpoint_url=endpoint_url)

    def getObjectById(self, logger, log_marker, object_id):
        try:
            omeka_item = self.__api_client.get_item(id=int(object_id.getUnqualifiedObjectId()))
        except NoSuchOmekaItemException:
            raise NoSuchObjectException
        return \
            self._map_omeka_item(
                collection_id=object_id.getCollectionId(),
                omeka_item=omeka_item,
                omeka_item_files=self.__api_client.get_all_files(item=omeka_item.id)
            )

    def getObjectsByCollectionId(self, collection_id, logger, log_marker):
        objects = []
        omeka_items = self.__api_client.get_all_items(collection=int(collection_id.getUnqualifiedCollectionId()))
        for omeka_item in omeka_items:
            objects.append(
                self._map_omeka_item(
                    collection_id=collection_id,
                    omeka_item=omeka_item,
                    omeka_item_files=self.__api_client.get_all_files(item=omeka_item.id),
                )
            )
        return ImmutableList.copyOf(objects)

PythonApi.getInstance().getObjectStoreFactoryRegistry().registerObjectStoreFactory(PyObjectStoreFactory(OmekaApiObjectStore), OmekaApiObjectStore.URI_SCHEME)