<commit_before>package org.dspace.app.xmlui.aspect.submission;

import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.log4j.Logger;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
import org.dspace.app.xmlui.utils.HandleUtil;
import org.dspace.app.xmlui.utils.UIException;
import org.dspace.app.xmlui.wing.Message;
import org.dspace.app.xmlui.wing.WingException;
import org.dspace.app.xmlui.wing.element.*;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Collection;
import org.dspace.content.DCValue;
import org.dspace.content.DSpaceObject;
import org.dspace.content.Item;
import org.dspace.identifier.DOIIdentifierProvider;
import org.dspace.identifier.IdentifierNotFoundException;
import org.dspace.identifier.IdentifierNotResolvableException;
import org.dspace.identifier.IdentifierService;
import org.dspace.utils.DSpace;
import org.dspace.workflow.DryadWorkflowUtils;
import org.dspace.workflow.WorkflowItem;
import org.dspace.workflow.WorkflowRequirementsManager;
import org.xml.sax.SAXException;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * User: kevin (kevin at atmire.com)
 * Date: 18-aug-2010
 * Time: 11:27:27
 * <p/>
 * The user interface for the review step
 */
public class DryadReviewTransformer extends AbstractDSpaceTransformer {

    private static final Logger log = Logger.getLogger(DryadReviewTransformer.class);

    protected static final Message T_showfull = message("xmlui.Submission.general.showfull");
    protected static final Message T_showsimple = message("xmlui.Submission.general.showsimple");
    protected static final Message T_workflow_head = message("xmlui.Submission.general.workflow.head");
    protected static final Message T_workflow_trail = message("xmlui.Submission.general.workflow.trail");
    protected static final Message T_dspace_home = message("xmlui.general.dspace_home");
    protected static final Message T_workflow_title = message("xmlui.Submission.general.workflow.title");
    private static final Message T_head_has_part = message("xmlui.ArtifactBrowser.ItemViewer.head_hasPart");
    private static final Message T_in_workflow = message("xmlui.DryadItemSummary.in_workflow");


    private String doi;
    private WorkflowItem wfItem;
    private boolean authorized;
    List<Item> dataFiles = new ArrayList<Item>();

    @Override
    public void setup(SourceResolver resolver, Map objectModel, String src, Parameters parameters) throws ProcessingException, SAXException, IOException {
        super.setup(resolver, objectModel, src, parameters);
        authorized = false;

        Request request = ObjectModelHelper.getRequest(objectModel);

        int wfItemId;

        if ( (wfItem=getWFItem(request)) == null) return;


        String token = request.getParameter("token");
        if (token != null) {
            String reviewerKey = getItemToken();
            authorized = token.equals(reviewerKey);
            if (authorized)
                request.getSession().setAttribute("reviewerToken", token);
        }
    }


    @Override
    public void addPageMeta(PageMeta pageMeta) throws SAXException, WingException, UIException, SQLException, IOException, AuthorizeException {
        super.addPageMeta(pageMeta);

        if (wfItem != null) {

            String title = "";
            DCValue[] vals = wfItem.getItem().getMetadata("dc.title");
            if (vals != null && vals[0] != null)
                title = vals[0].value;

            pageMeta.addMetadata("title").addContent("Reviewing " + title);
            Collection collection = wfItem.getCollection();

            pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
            HandleUtil.buildHandleTrail(collection, pageMeta, contextPath);
            pageMeta.addTrail().addContent(T_workflow_trail);

            Item dataPackage = DryadWorkflowUtils.getDataPackage(context, wfItem.getItem());
            if (dataPackage != null) {
                //We have a data package, indicating that we are viewing a data file
                //Add the review key to the page meta so we can use that
                DCValue[] reviewerKeys = dataPackage.getMetadata(WorkflowRequirementsManager.WORKFLOW_SCHEMA, "step", "reviewerKey", Item.ANY);
                if (0 < reviewerKeys.length)
                    pageMeta.addMetadata("identifier", "reviewerKey").addContent(reviewerKeys[0].value);
            }<commit_msg>Allow dois for review access<commit_after>package org.dspace.app.xmlui.aspect.submission;

import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.log4j.Logger;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
import org.dspace.app.xmlui.utils.HandleUtil;
import org.dspace.app.xmlui.utils.UIException;
import org.dspace.app.xmlui.wing.Message;
import org.dspace.app.xmlui.wing.WingException;
import org.dspace.app.xmlui.wing.element.*;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Collection;
import org.dspace.content.DCValue;
import org.dspace.content.DSpaceObject;
import org.dspace.content.Item;
import org.dspace.identifier.DOIIdentifierProvider;
import org.dspace.identifier.IdentifierNotFoundException;
import org.dspace.identifier.IdentifierNotResolvableException;
import org.dspace.identifier.IdentifierService;
import org.dspace.utils.DSpace;
import org.dspace.workflow.DryadWorkflowUtils;
import org.dspace.workflow.WorkflowItem;
import org.dspace.workflow.WorkflowRequirementsManager;
import org.xml.sax.SAXException;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.datadryad.api.DryadDataPackage;

/**
 * User: kevin (kevin at atmire.com)
 * Date: 18-aug-2010
 * Time: 11:27:27
 * <p/>
 * The user interface for the review step
 */
public class DryadReviewTransformer extends AbstractDSpaceTransformer {

    private static final Logger log = Logger.getLogger(DryadReviewTransformer.class);

    protected static final Message T_showfull = message("xmlui.Submission.general.showfull");
    protected static final Message T_showsimple = message("xmlui.Submission.general.showsimple");
    protected static final Message T_workflow_head = message("xmlui.Submission.general.workflow.head");
    protected static final Message T_workflow_trail = message("xmlui.Submission.general.workflow.trail");
    protected static final Message T_dspace_home = message("xmlui.general.dspace_home");
    protected static final Message T_workflow_title = message("xmlui.Submission.general.workflow.title");
    private static final Message T_head_has_part = message("xmlui.ArtifactBrowser.ItemViewer.head_hasPart");
    private static final Message T_in_workflow = message("xmlui.DryadItemSummary.in_workflow");


    private String doi;
    private WorkflowItem wfItem;
    private boolean authorized;
    List<Item> dataFiles = new ArrayList<Item>();

    @Override
    public void setup(SourceResolver resolver, Map objectModel, String src, Parameters parameters) throws ProcessingException, SAXException, IOException {
        super.setup(resolver, objectModel, src, parameters);
        authorized = false;

        Request request = ObjectModelHelper.getRequest(objectModel);

        int wfItemId;

        if ( (wfItem=getWFItem(request)) == null) return;


        String token = request.getParameter("token");
        if (token != null) {
            String reviewerKey = getItemToken();
            authorized = token.equals(reviewerKey);
            if (authorized) {
                request.getSession().setAttribute("reviewerToken", token);
            }
        }

        String requestDoi = request.getParameter("doi");
        if(requestDoi != null) {
            // Must match the item's DOI
            DryadDataPackage dataPackage = new DryadDataPackage(wfItem.getItem());
            String packageDOI = dataPackage.getIdentifier();
            authorized = requestDoi.equals(packageDOI);
            if(authorized) {
                // We authorize based on the DOI but still use the token for the session
                String reviewerKey = getItemToken();
                request.getSession().setAttribute("reviewerToken", reviewerKey);
            }
        }
    }


    @Override
    public void addPageMeta(PageMeta pageMeta) throws SAXException, WingException, UIException, SQLException, IOException, AuthorizeException {
        super.addPageMeta(pageMeta);

        if (wfItem != null) {

            String title = "";
            DCValue[] vals = wfItem.getItem().getMetadata("dc.title");
            if (vals != null && vals[0] != null)
                title = vals[0].value;

            pageMeta.addMetadata("title").addContent("Reviewing " + title);
            Collection collection = wfItem.getCollection();

            pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
            HandleUtil.buildHandleTrail(collection, pageMeta, contextPath);
            pageMeta.addTrail().addContent(T_workflow_trail);

            Item dataPackage = DryadWorkflowUtils.getDataPackage(context, wfItem.getItem());
            if (dataPackage != null) {
                //We have a data package, indicating that we are viewing a data file
                //Add the review key to the page meta so we can use that
                DCValue[] reviewerKeys = dataPackage.getMetadata(WorkflowRequirementsManager.WORKFLOW_SCHEMA, "step", "reviewerKey", Item.ANY);
                if (0 < reviewerKeys.length)
                    pageMeta.addMetadata("identifier", "reviewerKey").addContent(reviewerKeys[0].value);
            }
{'fraction_non_alphanumeric': 0.09934885556432518, 'fraction_numerical': 0.0033543804262036307, 'mean_word_length': 3.675738007380074, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 32}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4632893', 'n_tokens_mistral': 2884, 'n_tokens_neox': 2787, 'n_words': 607}