@@ -464,8 +464,11 @@ public String getAuthorsEditors(SolrDocument doc, String key) {
464464 private String getAuthors (SolrDocument doc ) {
465465 StringBuilder sb = new StringBuilder ();
466466
467- getAuthorEditorBlock (doc , Constants .authorOrganizationFields , sb );
468- getAuthorEditorBlock (doc , Constants .authorPersonFields , sb );
467+ // Process organization authors
468+ processJsonField (doc , Constants .CITATION_AUTHOR_ORGANIZATION_JSON , true , sb );
469+
470+ // Process person authors
471+ processJsonField (doc , Constants .CITATION_AUTHOR_PERSON_JSON , false , sb );
469472
470473 logger .debug ("getAuthors: " + sb );
471474 return sb .toString ();
@@ -474,48 +477,148 @@ private String getAuthors(SolrDocument doc) {
474477 private String getEditors (SolrDocument doc ) {
475478 StringBuilder sb = new StringBuilder ();
476479
477- getAuthorEditorBlock (doc , Constants .editorOrganizationFields , sb );
478- getAuthorEditorBlock (doc , Constants .editorPersonFields , sb );
480+ // Process organization editors
481+ processJsonField (doc , Constants .CITATION_EDITOR_ORGANIZATION_JSON , true , sb );
482+
483+ // Process person editors
484+ processJsonField (doc , Constants .CITATION_EDITOR_PERSON_JSON , false , sb );
479485
480486 logger .debug ("getEditors: " + sb );
481487 return sb .toString ();
482488 }
483489
484- private void getAuthorEditorBlock (SolrDocument doc , List <String > fields , StringBuilder sb ) {
485- logger .debug ("Processing fields: " + fields );
490+ /**
491+ * Process JSON field containing author/editor information.
492+ *
493+ * @param doc Solr document
494+ * @param fieldName Name of the JSON field to process
495+ * @param isOrganization true if processing Organization, false if processing Person
496+ * @param sb StringBuilder to append formatted output
497+ */
498+ private void processJsonField (SolrDocument doc , String fieldName , boolean isOrganization , StringBuilder sb ) {
499+ Collection <Object > values = doc .getFieldValues (fieldName );
500+ if (values == null || values .isEmpty ()) {
501+ logger .debug ("No values found for field: " + fieldName );
502+ return ;
503+ }
504+
505+ logger .debug ("Processing " + values .size () + " JSON entries for field: " + fieldName );
506+
507+ for (Object value : values ) {
508+ try {
509+ String jsonString = value .toString ();
510+ JSONObject jsonObj = new JSONObject (jsonString );
511+
512+ if (isOrganization ) {
513+ formatOrganization (jsonObj , sb );
514+ } else {
515+ formatPerson (jsonObj , sb );
516+ }
517+
518+ } catch (JSONException e ) {
519+ logger .error ("Error parsing JSON for field " + fieldName + ": " + e .getMessage (), e );
520+ }
521+ }
522+ }
523+
524+ /**
525+ * Format Organization JSON object for display.
526+ */
527+ private void formatOrganization (JSONObject jsonObj , StringBuilder sb ) throws JSONException {
528+ if (!jsonObj .has ("Organization" )) {
529+ return ;
530+ }
486531
487- // First, collect all values for each field
488- Map <String , List <Object >> fieldValues = new LinkedHashMap <>();
489- int maxSize = 0 ;
532+ JSONObject org = jsonObj .getJSONObject ("Organization" );
490533
491- for (String field : fields ) {
492- Collection <Object > values = doc .getFieldValues (field );
493- if (values != null ) {
494- List <Object > valueList = new ArrayList <>(values );
495- fieldValues .put (field , valueList );
496- maxSize = Math .max (maxSize , valueList .size ());
497- logger .debug ("Found " + valueList .size () + " values for field: " + field );
534+ if (org .has ("organization_name" )) {
535+ String orgName = org .getString ("organization_name" );
536+
537+ // Add organization name with ROR link if available
538+ if (org .has ("organization_rorid" )) {
539+ String rorUrl = org .getString ("organization_rorid" );
540+ sb .append ("<a href=\" " ).append (rorUrl ).append ("\" target=\" _blank\" >" );
541+ sb .append (orgName );
542+ sb .append ("</a>" );
498543 } else {
499- logger . debug ( "No values found for field: " + field );
544+ sb . append ( orgName );
500545 }
546+ sb .append ("<br />" );
547+ }
548+ }
549+
550+ /**
551+ * Format Person JSON object for display.
552+ */
553+ private void formatPerson (JSONObject jsonObj , StringBuilder sb ) throws JSONException {
554+ if (!jsonObj .has ("Person" )) {
555+ return ;
501556 }
502557
503- // Now transpose the data - iterate by index
504- for (int i = 0 ; i < maxSize ; i ++) {
505- logger .debug ("Processing group " + (i + 1 ) + " of " + maxSize );
506- for (String field : fields ) {
507- List <Object > values = fieldValues .get (field );
508- if (values != null && i < values .size ()) {
509- String value = values .get (i ).toString ();
510- logger .debug ("Adding value for " + field + ": " + value );
511- sb .append (value + " " );
512- if (!field .contains ("given_name" )) {
558+ JSONObject person = jsonObj .getJSONObject ("Person" );
559+
560+ // Determine the person's name
561+ String personName = null ;
562+ if (person .has ("given_name" ) && person .has ("family_name" )) {
563+ personName = person .getString ("given_name" ) + " " + person .getString ("family_name" );
564+ } else if (person .has ("display_full_name" )) {
565+ personName = person .getString ("display_full_name" );
566+ }
567+
568+ // Add name with ORCID link if available
569+ if (personName != null ) {
570+ if (person .has ("person_orcid" )) {
571+ String orcidUrl = person .getString ("person_orcid" );
572+ sb .append ("<a href=\" " ).append (orcidUrl ).append ("\" target=\" _blank\" >" );
573+ sb .append (personName );
574+ sb .append ("</a>" );
575+ } else {
576+ sb .append (personName );
577+ }
578+ sb .append ("<br />" );
579+ }
580+
581+ // Add affiliations
582+ if (person .has ("Affiliation" )) {
583+ Object affiliation = person .get ("Affiliation" );
584+
585+ if (affiliation instanceof JSONArray ) {
586+ JSONArray affiliations = (JSONArray ) affiliation ;
587+ for (int i = 0 ; i < affiliations .length (); i ++) {
588+ JSONObject aff = affiliations .getJSONObject (i );
589+ if (aff .has ("organization_name" )) {
590+ String affOrgName = aff .getString ("organization_name" );
591+ // Add affiliation with ROR link if available
592+ if (aff .has ("organization_rorid" )) {
593+ String rorUrl = aff .getString ("organization_rorid" );
594+ sb .append ("<a href=\" " ).append (rorUrl ).append ("\" target=\" _blank\" >" );
595+ sb .append (affOrgName );
596+ sb .append ("</a>" );
597+ } else {
598+ sb .append (affOrgName );
599+ }
513600 sb .append ("<br />" );
514601 }
515602 }
603+ } else if (affiliation instanceof JSONObject ) {
604+ JSONObject aff = (JSONObject ) affiliation ;
605+ if (aff .has ("organization_name" )) {
606+ String affOrgName = aff .getString ("organization_name" );
607+ // Add affiliation with ROR link if available
608+ if (aff .has ("organization_rorid" )) {
609+ String rorUrl = aff .getString ("organization_rorid" );
610+ sb .append ("<a href=\" " ).append (rorUrl ).append ("\" target=\" _blank\" >" );
611+ sb .append (affOrgName );
612+ sb .append ("</a>" );
613+ } else {
614+ sb .append (affOrgName );
615+ }
616+ sb .append ("<br />" );
617+ }
516618 }
517- sb .append ("<br />" );
518619 }
620+
621+ sb .append ("<br />" );
519622 }
520623
521624 private String cleanIdentifier (String identifier ) {
0 commit comments