Skip to content

Conversation

@nphoenix
Copy link

@nphoenix nphoenix commented Dec 25, 2025

Summary

Fixes CTDL-ASN file detection to support context arrays and embedded competency structures, enabling import of standards-compliant files.

Fixes #1408 and #1410

Problem

CTDL-ASN files fail to import with errors:

  • "Invalid file" for embedded competency structures
  • "Context is not CTDL-ASN" for files with context arrays

Both structures are valid per the CTDL-ASN specification but are currently rejected by CASS.

Root Cause

The analyzeJsonLdFramework() function in src/mixins/import.js (lines 502-535) has two bugs:

  1. String-only context check: Only checks if @context === "https://credreg.net/ctdl...", which fails when @context is an array (valid per JSON-LD spec)
  2. @graph-only structure: Requires @graph structure, rejecting valid embedded ceterms:competencies arrays

Solution

Updated analyzeJsonLdFramework() to:

  • Normalize @context to handle both strings and arrays
  • Check for CTDL substring in any context URL (not exact string match)
  • Support both @graph and embedded ceterms:competencies structures
  • Extract competencies from either location

Code Changes

File: src/mixins/import.js
Function: analyzeJsonLdFramework() (lines 502-535)

Key changes:

// Handle context as both string and array
var contextToCheck = jsonObj["@context"];
if (Array.isArray(contextToCheck)) {
    contextString = contextToCheck[0];
    hasCtdlContext = contextToCheck.some(function(c) {
        return typeof c === 'string' && c.indexOf('credreg.net/ctdl') !== -1;
    });
} else {
    contextString = contextToCheck;
    hasCtdlContext = contextString && contextString.indexOf('credreg.net/ctdl') !== -1;
}

// Support both @graph and embedded structures
if (jsonObj["@graph"]) {
    data = jsonObj["@graph"];
} else if (jsonObj["@type"]) {
    // Handle embedded ceterms:competencies or ceasn:competencies
    var embeddedComps = jsonObj["ceterms:competencies"] || jsonObj["ceasn:competencies"];
    if (embeddedComps && Array.isArray(embeddedComps)) {
        data = embeddedComps;
        // Add framework itself
        data.unshift(jsonObj);
    }
}

Testing Results

Before Fix

TEST-01 (ICICLE Framework from , 74 competencies)
  Result: ❌ "Invalid file"
  
TEST-02 (CTDL-ASN with context array)
  Result: ❌ "Context is not CTDL-ASN"

After Fix

TEST-01 (ICICLE Framework , 74 competencies)
  Result: ✅ "1 Framework and 74 Competencies Detected"
  
TEST-02 (CTDL-ASN with context array)
  Result: ✅ Correctly recognized and counted

Known Limitations

This PR fixes the detection phase of CTDL-ASN import. Additional bugs remain in the import execution phase that will require separate fixes:

  • Import execution may still fail after successful detection
  • CTDL-ASN export functionality also needs fixes
  • Format auto-detection for all .json files needs improvement

However, this fix is a critical first step - without proper detection, import cannot proceed at all.

Impact

Immediate benefits:

  • ✅ Enables recognition of CTDL-ASN files
  • ✅ Supports standards-compliant JSON-LD context arrays
  • ✅ Supports both @graph and embedded structures per spec

Standards compliance:

  • Aligns with CTDL-ASN specification: https://credreg.net/ctdl-asn/handbook
  • Follows JSON-LD best practices for context handling
  • Enables interoperability with other competency framework tools

Testing

Tested with multiple CTDL-ASN file variations:

  • Context as string vs array
  • @graph structure vs embedded competencies
  • Various competency counts (1 to 74)
  • Files and hand-crafted examples

All variations now detect correctly.


This PR addresses an interoperability issue preventing import of standards-compliant CTDL-ASN files into CASS.
TEST-01-ORIGINAL.jsonld.txt
TEST-05-MINIMAL-2-competencies.jsonld.txt

Support context arrays and embedded competencies
Added functions to convert embedded CTDL-ASN structures to @graph format for backend compatibility. Enhanced JSON-LD analysis to support both @graph and embedded structures.

- Add convertToGraphStructure() to handle embedded ceterms:competencies
- Modify importJsonLd() to convert before sending to backend
- Enhance comments documenting PR cassproject#1408 fixes
- Works around backend limitation requiring @graph format

Fixes: no @graph created, unsure how to parse error
Related: cassproject#1408, cassproject#1410"
…petencies

Fixes three critical issues with CTDL-ASN framework imports:

1. Enhanced CTDL-ASN Detection
   - Handles @context as both array and string formats
   - Detects embedded ceterms:competencies structures
   - Identifies CTDL-ASN files with various structural patterns

2. Added @graph Conversion
   - Converts embedded competencies to @graph format required by backend
   - Preserves existing @graph structures unchanged
   - Handles CompetencyFramework, ConceptScheme, ProgressionModel, Collection

3. Fixed File Upload Bug
   - File uploads now convert to @graph before backend (previously only URLs did)
   - Refactored to use sendData() helper for consistent processing
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
2 Security Hotspots

See analysis details on SonarQube Cloud

@nphoenix nphoenix marked this pull request as draft December 27, 2025 00:14
@nphoenix
Copy link
Author

nphoenix commented Dec 27, 2025

@nphoenix nphoenix marked this pull request as ready for review December 27, 2025 00:16
@nphoenix nphoenix changed the title Fix CTDL-ASN detection: support context arrays and embedded structures Fix CTDL-ASN detection: support context arrays and embedded structures (fixes #1408, fixes #1410) Dec 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CTDL-ASN files fail detection with context arrays

1 participant