def index(rec_type, recid=None):
        """Render a basic view, with dummy permission editor-view."""
        json_editor_config = current_app.config["RECORDS_EDITOR_UI_CONFIG"]
        if rec_type not in json_editor_config:
            abort(404)

        ui_config = copy.deepcopy(json_editor_config[rec_type])

        ui_config["recordConfig"]["apiUrl"] = "{0}{1}".format(
            request.url_root, ui_config["recordConfig"]["apiUrl"])

        ui_config["recordConfig"]["schema"] = current_jsonschemas.path_to_url(
            ui_config["recordConfig"]["schema"])
        return render_template(
            app.config["RECORDS_EDITOR_TEMPLATE"],
            editor_url=app.config["RECORDS_EDITOR_URL_PREFIX"],
            module_name="Invenio-Records-Editor",
            ui_config=ui_config,
        )
Ejemplo n.º 2
0
    def _create_deposit(user,
                        schema_name,
                        metadata=None,
                        experiment=None,
                        files={},
                        publish=False,
                        mapping=None):
        """Create a new deposit for given user and schema name.

        e.g cms-analysis-v0.0.1,
        with minimal metadata defined for this schema type.
        """
        # create schema for record
        with app.test_request_context():
            schema = create_schema(schema_name,
                                   experiment=experiment,
                                   deposit_mapping=mapping)
            deposit_schema_url = current_jsonschemas.path_to_url(
                schema.deposit_path)

            metadata = metadata or minimal_metadata(deposit_schema_url)
            login_user(user)
            id_ = uuid4()
            deposit_minter(id_, metadata)
            deposit = Deposit.create(metadata, id_=id_)

            for k, v in files.items():
                deposit.files[k] = v
            if files:
                deposit.commit()

            db.session.commit()

        if publish:
            deposit.publish()
            _, record = deposit.fetch_published()
            RecordIndexer().index(record)

            current_search.flush_and_refresh(schema.record_index)

        current_search.flush_and_refresh(schema.deposit_index)

        return Deposit.get_record(deposit.id)
Ejemplo n.º 3
0
    def create(cls, data, id_=None, index_refresh='false', **kwargs):
        """Create a new record instance and store it in elasticsearch.

        :param data: Dict with the record metadata.
        :param id_: Specify a UUID to use for the new record, instead of
                    automatically generated.
        :param index_refresh: If `true` then refresh the affected shards to
            make this operation visible to search, if `wait_for` then wait for
            a refresh to make this operation visible to search, if `false`
            (the default) then do nothing with refreshes.
            Valid choices: 'true', 'false', 'wait_for'
        :returns: A new :class:`Record` instance.
        """
        if id_:
            data['pid'] = id_

        record = cls(data, model=None, **kwargs)

        # Run pre create extensions
        for e in cls._extensions:
            e.pre_create(record)

        if current_app.config.get('RERO_ILS_ENABLE_OPERATION_LOG_VALIDATION'):
            # Validate also encodes the data
            # For backward compatibility we pop them here.
            format_checker = kwargs.pop('format_checker', None)
            validator = kwargs.pop('validator', None)
            if '$schema' not in record:
                record['$schema'] = current_jsonschemas.path_to_url(
                    cls._schema)
            record._validate(format_checker=format_checker,
                             validator=validator,
                             use_model=False)

        current_search_client.index(index=cls.get_index(record),
                                    body=record.dumps(),
                                    id=record['pid'],
                                    refresh=index_refresh)

        # Run post create extensions
        for e in cls._extensions:
            e.post_create(record)
        return record
Ejemplo n.º 4
0
 def build_deposit_schema(self, record):
     """Get schema path for deposit."""
     return current_jsonschemas.path_to_url(self.schema.deposit_path)
Ejemplo n.º 5
0
 def record_schema(self):
     """Get corresponding schema path for record."""
     return current_jsonschemas.path_to_url(self.schema.record_path)
Ejemplo n.º 6
0
def schema_name_to_url(schema_name, version=None):
    """Return url eg. https://host.com/schemas/schema-v0.0.1.json."""
    schema = resolve_schema_by_name_and_version(schema_name, version)
    url = current_jsonschemas.path_to_url(schema.deposit_path)
    return url
Ejemplo n.º 7
0
def schema_name_to_url(schema_name):
    """Return url eg. https://host.com/schemas/schema-v0.0.1.json."""
    schema = Schema.get_latest(schema_name)
    url = current_jsonschemas.path_to_url(schema.deposit_path)

    return url