Skip to content

Latest commit

 

History

History
324 lines (257 loc) · 10.5 KB

File metadata and controls

324 lines (257 loc) · 10.5 KB

🎉 Project Summary - Dataverse Bulk Metadata Update Tool

Your enhanced Dataverse bulk metadata update repository has been successfully created! This is an advanced version of the original single-dataset tool, now supporting multiple datasets with specific DOIs.

📦 What Has Been Created

Core Features Implemented

Multi-Dataset Support

  • Handle multiple datasets with different DOIs simultaneously
  • Bulk update files across all datasets in one workflow
  • CSV-based organization with DOI as first column

Bidirectional Conversion

  • JSON → CSV: Convert JSON templates to editable CSV format
  • CSV → JSON: Convert updated CSV back to JSON files for Dataverse
  • Seamless bidirectional workflow for maximum flexibility

Metadata Management

  • First column: DOI (dataset identifier)
  • Second column: Dataset name
  • File-level metadata: descriptions, file paths, labels
  • Track update status for each file

Dataverse Integration

  • Direct API connection to Dataverse instances
  • Dry-run mode to preview changes before applying
  • Secure credential management via environment variables
  • Batch update capabilities

ZIP and Folder Support

  • JSON files organized in data/json_templates/ folder
  • Support for multiple JSON files in a single directory
  • Easy to add/remove datasets

📂 Directory Structure

Update_FileMetadata_Dataverse_multipleDOIs/
│
├── 📄 Core Python Scripts
│   ├── utils.py                     # Utility functions for JSON/CSV operations
│   ├── json_to_csv.py              # Convert JSON → CSV
│   ├── csv_to_json.py              # Convert CSV → JSON  
│   └── dataverse_api.py            # Dataverse API integration
│
├── 📁 Data Directories
│   ├── data/json_templates/         # Input: Your JSON template files
│   │   ├── climate_data_2024.json   # (Sample)
│   │   ├── genomic_data_species_a.json  # (Sample)
│   │   └── survey_data_2024.json    # (Sample)
│   ├── data/json_output/            # Output: Generated JSON files
│   └── data/metadata.csv            # Editable metadata file
│
├── 📋 Configuration & Documentation
│   ├── config.ini                   # Configuration file
│   ├── requirements.txt             # Python dependencies
│   └── .gitignore                   # Git ignore rules
│
├── 📚 Documentation Files
│   ├── README.md                    # Full documentation ⭐ START HERE
│   ├── SETUP_GUIDE.md               # Quick 5-minute setup
│   ├── INSTALLATION.md              # Detailed installation
│   ├── WORKFLOW.md                  # Step-by-step workflow
│   ├── EXAMPLES.md                  # Practical use cases
│   └── LICENSE                      # MIT License
│
├── 🚀 Utility Scripts
│   └── quick_start.sh               # Automated quick start script
│
└── 📦 Version Control
    └── .git/                        # Git repository (if initialized)

🚀 Quick Start (5 Minutes)

1. Setup Environment

python3 -m venv venv
source venv/bin/activate
pip install requests

2. Convert JSON to CSV

python json_to_csv.py \
    --input-dir ./data/json_templates \
    --output-csv ./data/metadata.csv

3. Edit Metadata

  • Open data/metadata.csv in Excel or Google Sheets
  • Update new_description and new_file_path columns
  • Save the file

4. Convert Back to JSON

python csv_to_json.py --csv-file ./data/metadata.csv

5. Push to Dataverse (Optional)

export DATAVERSE_SERVER_URL="https://your-dataverse.org"
export DATAVERSE_API_TOKEN="your-token"

python dataverse_api.py --csv-file ./data/metadata.csv --no-dry-run

📊 CSV Structure

The generated CSV has these columns:

Column Purpose Example
DOI Dataset identifier (read-only) doi:10.5061/dryad.example1
dataset_name Dataset name (read-only) Climate Data 2024
file_id File ID (read-only) file_001
file_label File name (read-only) temperature_data.csv
file_description Current description (read-only) Monthly average temperature...
file_path Current directory (read-only) raw_data
file_size File size in bytes (read-only) 2048576
file_type Data type (read-only) Text
original_description Backup of original (read-only) Same as file_description
new_description ✏️ EDIT THIS Updated description
new_file_path ✏️ EDIT THIS New directory path
status Update status pending, updated, no_changes

🎯 Supported Workflows

Workflow 1: Bulk Description Updates

JSON Files → CSV (auto-generated) → Edit descriptions → JSON → Dataverse

Workflow 2: File Path Reorganization

JSON Files → CSV → Update paths → JSON → Dataverse

Workflow 3: Multiple Dataset Management

Multiple JSON Files → Single CSV → Edit all datasets → Multiple JSONs → Dataverse

Workflow 4: Scheduled Updates

Cron Job → JSON → CSV → Updates → JSON → Dataverse (automated)

📋 Sample Data Included

Three sample datasets are included for testing:

  1. Climate Data 2024 - North America

    • 3 files: temperature data, precipitation analysis, methodology
    • DOI: doi:10.5061/dryad.example1
  2. Genomic Sequencing Dataset - Species A

    • 4 files: sequence reads (R1, R2), assembly summary, quality report
    • DOI: doi:10.5061/dryad.example2
  3. Survey Results - Consumer Preferences 2024

    • 4 files: survey responses, demographics, R script, findings report
    • DOI: doi:10.5061/dryad.example3

Total: 11 sample file records for testing

🔧 Python Modules

utils.py - Utility Functions

  • load_json_file() - Load JSON
  • save_json_file() - Save JSON
  • load_csv_file() - Load CSV
  • save_csv_file() - Save CSV
  • extract_metadata_from_json() - Extract metadata
  • validate_csv_row() - Validate data
  • get_json_files_from_directory() - Get all JSON files

json_to_csv.py - JSON to CSV Conversion

  • Main function: json_to_csv_converter()
  • Supports single file or directory conversion
  • Auto-generates CSV with all metadata columns

csv_to_json.py - CSV to JSON Conversion

  • Main function: csv_to_json_converter()
  • Groups CSV rows by DOI
  • Creates separate JSON files per dataset

dataverse_api.py - Dataverse Integration

  • Class: DataverseAPI - API client
  • Methods:
    • get_dataset_metadata() - Get dataset info
    • get_file_metadata() - Get file info
    • update_file_metadata() - Update file metadata
    • get_dataset_files() - List files
    • test_connection() - Test connection
  • Function: push_updates_from_csv() - Bulk push updates

📖 Documentation Guide

Document Purpose Read Time
SETUP_GUIDE.md Quick 5-minute setup 5 min ⚡
README.md Full documentation 15 min 📖
INSTALLATION.md Detailed setup help 10 min 🛠️
WORKFLOW.md Complete workflow 20 min 🔄
EXAMPLES.md Practical use cases 15 min 💡

👉 Start with SETUP_GUIDE.md for quickest start!

✨ Key Improvements Over Original

Feature Original New Version
Number of datasets Single Multiple
DOI handling Single DOI Multiple DOIs in one file
CSV format N/A DOI + Dataset name as columns
Bulk operations Limited Full bulk update support
Organization Manual Folder-based templates
Workflow One-way Bidirectional conversion
Dry-run mode No Full preview capability
Documentation Minimal Comprehensive with examples

🔐 Security Features

Credential Security

  • API tokens stored in environment variables only
  • Never hardcoded in files or committed to git
  • .gitignore prevents accidental commits

Data Protection

  • Dry-run mode to preview changes first
  • Backup of original JSON files
  • Git version control for tracking changes

Access Control

  • Environment variable based credentials
  • Secure API token handling
  • HTTPS-only Dataverse connections (recommended)

🧪 Testing & Validation

All components have been tested:

  • ✅ JSON loading and parsing
  • ✅ CSV generation and parsing
  • ✅ File I/O operations
  • ✅ Argument parsing and defaults
  • ✅ Sample data included for testing

Run the quick test:

python json_to_csv.py --input-dir ./data/json_templates

Expected output: 11 rows converted successfully

📝 Configuration

config.ini includes settings for:

  • Dataverse server URL
  • API token management
  • Path configurations
  • CSV column names
  • Logging options
  • Workflow settings

🎓 Learning Path

  1. Beginner: Read SETUP_GUIDE.md (5 min)
  2. User: Follow WORKFLOW.md (20 min)
  3. Advanced: Review EXAMPLES.md for custom scripts
  4. Developer: Study individual Python modules

🚀 Next Steps

  1. Read the SETUP_GUIDE.md for quick start
  2. Place your JSON files in data/json_templates/
  3. Run the conversion with python json_to_csv.py
  4. Edit the CSV with your updates
  5. Convert back to JSON with python csv_to_json.py
  6. Push to Dataverse with python dataverse_api.py

📞 Troubleshooting

If you encounter issues:

  1. Check INSTALLATION.md for setup problems
  2. Review WORKFLOW.md for process issues
  3. See EXAMPLES.md for code examples
  4. Check error messages in logs/

💡 Pro Tips

  • Always test first: Use dry-run mode before applying changes
  • Version control: Use git to track CSV changes
  • Batch updates: Process multiple datasets at once
  • Scheduling: Set up cron jobs for automated updates
  • Logging: Enable detailed logging for debugging

📦 Deliverables

You now have: ✅ 4 Python modules (utils, converters, API) ✅ 3 sample JSON files for testing ✅ 5 documentation files ✅ Sample CSV with 11 file records ✅ Configuration file ✅ Requirements file ✅ Quick start script ✅ Git ignore file

Total: 18 files with complete functionality

🎉 Ready to Use!

Your repository is production-ready and fully documented. Start with SETUP_GUIDE.md and you'll be updating Dataverse metadata in minutes!


Created: May 2026
Python Version: 3.7+
Main Dependencies: requests
License: MIT

For questions or issues, refer to the comprehensive documentation included in the repository.