<commit_before>/**
 * The contents of this file are subject to the license and copyright
 * detailed in the LICENSE and NOTICE files at the root of the source
 * tree and available online at
 *
 * http://www.dspace.org/license/
 */
package org.dspace.curate;

import java.util.Date;
import java.text.DateFormat;
import java.util.Locale;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import org.dspace.authorize.AuthorizeException;
import org.dspace.content.DSpaceObject;
import org.dspace.content.DCValue;
import org.dspace.content.Item;
import org.dspace.core.Context;
import org.dspace.core.Constants;

import org.dspace.workflow.WorkflowItem;
import org.datadryad.api.DryadDataPackage;
import org.dspace.storage.rdbms.DatabaseManager;
import org.dspace.storage.rdbms.TableRow;

import org.apache.log4j.Logger;

/**
 * PlosItemsReviewMonth reports on items from PLOS publications that have been in the review workflow 
 * longer than one month.
 *
 * The task succeeds if it was able to calculate the correct result.
 *
 * Input: a collection (any collection)
 * Output: a CSV indicating simple information about the PLOS data packages 
 *         that have been in review longer than one month
 *
 * @author <NAME>/<NAME>
 */
@Distributive
public class ItemsInReviewPlosMonth extends AbstractCurationTask {

    private static Logger log = Logger.getLogger(FileSimpleStats.class);
    private static DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
    Context context;
    
    
    
    // Database objects
    static final String DB_MANUSCRIPT_TABLE = "manuscript";
    static final String DB_COLUMN_ID = "manuscript_id";
    static final String DB_COLUMN_ORGANIZATION_ID = "organization_id";
    static final String DB_COLUMN_MSID = "msid";
    static final String DB_COLUMN_VERSION = "version";
    // active is stored as String because DatabaseManager doesn't support Boolean
    static final String DB_COLUMN_ACTIVE = "active";
    static final String DB_COLUMN_JSON_DATA = "json_data";
    
    static final String DB_ACTIVE_TRUE = String.valueOf(true);
    static final String DB_ACTIVE_FALSE = String.valueOf(false);    
    

    @Override 
    public void init(Curator curator, String taskId) throws IOException {
        super.init(curator, taskId);

        try {
            context = new Context();
        } catch (SQLException e) {
            log.fatal("Cannot initialize database connection", e);
        }
    }
    
 
    /** returns data from the manuscript table based on the given Manuscript ID and organization code */
     // private static Manuscript getManuscriptByIdAndOrg(Context myContext, String msid, String organizationCode) throws SQLException, IOException {
     private static String getManuscriptData(Context myContext, String msid, String organizationCode) throws SQLException, IOException {

        // Integer organizationId = getOrganizationInternalId(myContext, organizationCode);

            String query = "SELECT * FROM MANUSCRIPT WHERE msid = ? and active = ?";
            TableRow row = DatabaseManager.querySingleTable(myContext, DB_MANUSCRIPT_TABLE, query, msid, DB_ACTIVE_TRUE);
            // Manuscript manuscript = manuscriptFromTableRow(row);
            // return manuscript;
            
            if(row != null) {
            	String json_data = row.getStringColumn(DB_COLUMN_JSON_DATA);
            	return json_data;
        	} else {
            	return null;
        	}
            // return row;            
    }
    
    
    /** returns the number of days between today's date and anotherDateMS, which is passed in */
	public static int numDaysSince(long anotherDateMS) {
	
        Date todayDate = new Date();
        long todayDateMS = todayDate.getTime();

        long timeBetweenDatesMS = todayDateMS - anotherDateMS;
        long timeInReview = timeBetweenDatesMS / (24 * 60 * 60 * 1000);
        int numDaysInReview = (int) timeInReview;<commit_msg>debug statements added - more<commit_after>/**
 * The contents of this file are subject to the license and copyright
 * detailed in the LICENSE and NOTICE files at the root of the source
 * tree and available online at
 *
 * http://www.dspace.org/license/
 */
package org.dspace.curate;

import java.util.Date;
import java.text.DateFormat;
import java.util.Locale;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import org.dspace.authorize.AuthorizeException;
import org.dspace.content.DSpaceObject;
import org.dspace.content.DCValue;
import org.dspace.content.Item;
import org.dspace.core.Context;
import org.dspace.core.Constants;

import org.dspace.workflow.WorkflowItem;
import org.datadryad.api.DryadDataPackage;
import org.dspace.storage.rdbms.DatabaseManager;
import org.dspace.storage.rdbms.TableRow;

import org.apache.log4j.Logger;

/**
 * PlosItemsReviewMonth reports on items from PLOS publications that have been in the review workflow 
 * longer than one month.
 *
 * The task succeeds if it was able to calculate the correct result.
 *
 * Input: a collection (any collection)
 * Output: a CSV indicating simple information about the PLOS data packages 
 *         that have been in review longer than one month
 *
 * @author <NAME>/<NAME>
 */
@Distributive
public class ItemsInReviewPlosMonth extends AbstractCurationTask {

    private static Logger log = Logger.getLogger(FileSimpleStats.class);
    private static DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
    Context context;
    
    
    
    // Database objects
    static final String DB_MANUSCRIPT_TABLE = "manuscript";
    static final String DB_COLUMN_ID = "manuscript_id";
    static final String DB_COLUMN_ORGANIZATION_ID = "organization_id";
    static final String DB_COLUMN_MSID = "msid";
    static final String DB_COLUMN_VERSION = "version";
    // active is stored as String because DatabaseManager doesn't support Boolean
    static final String DB_COLUMN_ACTIVE = "active";
    static final String DB_COLUMN_JSON_DATA = "json_data";
    
    static final String DB_ACTIVE_TRUE = String.valueOf(true);
    static final String DB_ACTIVE_FALSE = String.valueOf(false);    
    

    @Override 
    public void init(Curator curator, String taskId) throws IOException {
        super.init(curator, taskId);

        try {
            context = new Context();
        } catch (SQLException e) {
            log.fatal("Cannot initialize database connection", e);
        }
    }
    
 
    /** returns data from the manuscript table based on the given Manuscript ID and organization code */
     // private static Manuscript getManuscriptByIdAndOrg(Context myContext, String msid, String organizationCode) throws SQLException, IOException {
     private static String getManuscriptData(Context myContext, String msid, String organizationCode) throws SQLException, IOException {

        // Integer organizationId = getOrganizationInternalId(myContext, organizationCode);
System.out.println("In the getManuscriptData method");
            String query = "SELECT * FROM MANUSCRIPT WHERE msid = ? and active = ?";
            TableRow row = DatabaseManager.querySingleTable(myContext, DB_MANUSCRIPT_TABLE, query, msid, DB_ACTIVE_TRUE);
            // Manuscript manuscript = manuscriptFromTableRow(row);
            // return manuscript;
System.out.println("row");
System.out.println(row);

            if(row != null) {
            	String json_data = row.getStringColumn(DB_COLUMN_JSON_DATA);
            	return json_data;
        	} else {
            	return null;
        	}
            // return row;            
    }
    
    
    /** returns the number of days between today's date and anotherDateMS, which is passed in */
	public static int numDaysSince(long anotherDateMS) {
	
        Date todayDate = new Date();
        long todayDateMS = todayDate.getTime();

        long timeBetweenDatesMS = todayDateMS - anotherDateMS;
        long timeInReview = timeBetweenDatesMS / (24 * 60 * 60 * 1000);
        int numDaysInReview = (int) timeInReview;
{'fraction_non_alphanumeric': 0.08085928071445812, 'fraction_numerical': 0.0026550808592807145, 'mean_word_length': 3.304935064935065, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, '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': '7153539', 'n_tokens_mistral': 2349, 'n_tokens_neox': 2264, 'n_words': 704}