Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOI: Short-URLs via ZMSIndex #133

Open
drfho opened this issue Mar 3, 2023 · 3 comments
Open

DOI: Short-URLs via ZMSIndex #133

drfho opened this issue Mar 3, 2023 · 3 comments
Assignees
Labels
question Further information is requested

Comments

@drfho
Copy link
Contributor

drfho commented Mar 3, 2023

When ZMSIndex was a ContentObj-Lib the doi-Python-Script object

from Products.zms import standard
request = container.REQUEST
RESPONSE = request.RESPONSE
zmscontext = context.content
path_ = 'index_html'
if request['traverse_subpath']:
path_ = standard.id_quote('_'.join(request['traverse_subpath']))
catalog = context.zcatalog_index
query = {'zcat_attr_dc_identifier_doi':path_}
rows = catalog(query)
for x in rows:
# ### test ####
# print x['get_uid']
# print context.content.getLinkObj('{$%s}'%x['get_uid'])
# print context.content.getLinkObj('{$%s}'%x['get_uid']).absolute_url()
# return printed
# #############
ob = zmscontext.getLinkObj('{$%s}'%x['get_uid'])
RESPONSE.redirect(ob.absolute_url())
return standard.FileFromData(zmscontext,ob.absolute_url())
# Return a string identifying this script.
return standard.FileFromData(zmscontext,"'%s' not found!"%path_)

could resolve short-URls on basis of an attribute like www.mysite.com/doi/myid

How does it work after the doi()-function has moved with ZMSIndex into ZMS core?

@drfho drfho added documentation question Further information is requested and removed documentation labels Mar 3, 2023
@drfho
Copy link
Contributor Author

drfho commented Mar 3, 2023

After shifting to ZMS core the ZMSIndex.doi()-function

def doi(self):
request = self.REQUEST
RESPONSE = request.RESPONSE
zmscontext = self.getDocumentElement()
path_ = 'index_html'
if request['traverse_subpath']:
path_ = standard.id_quote('_'.join(request['traverse_subpath']))
catalog = self.get_catalog()
query = {'zcat_attr_dc_identifier_doi':path_}
rows = catalog(query)
for x in rows:
# ### test ####
# print x['get_uid']
# print zmscontext.getLinkObj('{$%s}'%x['get_uid'])
# print zmscontext.getLinkObj('{$%s}'%x['get_uid']).absolute_url()
# return printed
# #############
ob = zmscontext.getLinkObj('{$%s}'%x['get_uid'])
RESPONSE.redirect(ob.absolute_url())
return standard.FileFromData(zmscontext,ob.absolute_url())
# Return a string identifying this script.
return standard.FileFromData(zmscontext,"'%s' not found!"%path_)
################################################################################

works indirectly and has to be called within a Zope-Python-Script object to provide the traversal function which is needed to get the document id (DOI) from the URL path.

Screen Image: Zope-Python-Script object 'short' calls the zmsindex.doi() function:
image

The pictured example shows how to configure a Short-URL resolver based on the ZMS-IDs:

  1. Insert a Python-Script on ZMS-Root level; the id of the Python-Script can be chosen arbitrarily; in the upper example it is named "short", so a short-URL would look like this: www.mysite.com/short/e30 and redirect into the hierarchy where the id is actually located.
request = container.REQUEST
response =  request.response
resp = container.content.zmsindex.doi()
return resp.getData()
  1. Insert a new attribute attr_dc_identifier_doi of type "py" to the ZMS-node types that should be resolved (usually ZMSFolder and ZMSDocument); this code return the ID of the current content node:
  return zmscontext.getId()
  1. In the Admin-Menu of ZMSIndex add the new attribute attr_dc_identifier_doi to the index and execute "Reindex"

image

  1. Check in the zcatalog_index object whether the new attribute is actually indexed

@drfho
Copy link
Contributor Author

drfho commented Mar 4, 2023

If you prefer to enter indivdual DOIs manually and you may want to change ( :-o ) these DOIs after the node was inserted, a refresh of the node's catalog item will be necessary. Because ZMSIndex by default is not affected by attribute changes, the reindexing can be triggered

  1. implicitly by an onChangeObjEvt method of the meta-object class or
  2. explicitly by the user. An additional button can be provided by a JS function that is injected via /common/added/zmi.js and may look like this:
$(function(){
    const $doi_input = $('#tr_attr_dc_identifier_doi input');
    const $btn_refresh_catalog = $('<a>', {
        style:'float:right;margin-top:-2.175rem;border-radius:0 4px 4px 0;',
        title:'Refresh Catalog Item',
        class:'btn btn-primary ml-2'
    }).on('click', function() {
            if ( $doi_input.attr('data-initial-value')==$doi_input.prop('value') ) {
                if ( confirm('Do You really want to refresh the Catalog item?') ) {
                    self.location.href='?refresh_catalog=True&manage_tabs_message=Reindexed';
                }
            } else {
                confirm('Please save the new entry, first')
            };
            return false;
    }).append($('<i>', {
            title:'Refresh catalog', 
            class:'fas fa-sync-alt'
    }));

    $doi_input.after($btn_refresh_catalog);
});

image

NOTE: the triggering of catalog_refesh needs 8405e9d

@admbzts
Copy link
Contributor

admbzts commented Nov 28, 2023

(zmsdev)
multilingual support my be achieved by adding the language-id to the path:

www.mysite.com/short/e30 (defaults to primary-language, e.g. ger)
www.mysite.com/short/e30/ger => ger
www.mysite.com/short/e30/eng => eng

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants