@@ -335,12 +335,139 @@ public static WorkForm valueOf(WorkSummary work) {
335335 return w ;
336336 }
337337
338+ public static WorkForm valueOf (org .orcid .jaxb .model .record_v2 .Work work , int maxContributorsForUI ) {
339+ if (work == null )
340+ return null ;
341+
342+ WorkForm w = new WorkForm ();
343+
344+ // Set work id
345+ if (work .getPutCode () != null ) {
346+ w .setPutCode (Text .valueOf (work .getPutCode ()));
347+ }
348+
349+ // Set language
350+ if (!PojoUtil .isEmpty (work .getLanguageCode ())) {
351+ w .setLanguageCode (Text .valueOf (work .getLanguageCode ()));
352+ }
353+
354+ // Set type
355+ if (work .getWorkType () != null ) {
356+ w .setWorkType (Text .valueOf (work .getWorkType ().value ()));
357+ // Set category
358+ org .orcid .jaxb .model .record_v2 .WorkCategory category = org .orcid .jaxb .model .record_v2 .WorkCategory .fromWorkType (work .getWorkType ());
359+ w .setWorkCategory (Text .valueOf (category .value ()));
360+ }
361+
362+ if (work .getWorkTitle () != null ) {
363+ // Set title
364+ if (work .getWorkTitle ().getTitle () != null ) {
365+ w .setTitle (Text .valueOf (work .getWorkTitle ().getTitle ().getContent ()));
366+ }
367+ // Set translated title
368+ if (work .getWorkTitle ().getTranslatedTitle () != null ) {
369+ TranslatedTitleForm tt = new TranslatedTitleForm ();
370+ tt .setContent (work .getWorkTitle ().getTranslatedTitle ().getContent ());
371+ tt .setLanguageCode (work .getWorkTitle ().getTranslatedTitle ().getLanguageCode ());
372+ w .setTranslatedTitle (tt );
373+ }
374+ // Set subtitle
375+ if (work .getWorkTitle ().getSubtitle () != null ) {
376+ w .setSubtitle (Text .valueOf (work .getWorkTitle ().getSubtitle ().getContent ()));
377+ }
378+ }
379+
380+ // Set journal title
381+ if (work .getJournalTitle () != null ) {
382+ w .setJournalTitle (Text .valueOf (work .getJournalTitle ().getContent ()));
383+ }
384+
385+ // Set description
386+ if (work .getShortDescription () != null ) {
387+ w .setShortDescription (Text .valueOf (work .getShortDescription ()));
388+ }
389+
390+ // Set url
391+ if (work .getUrl () != null ) {
392+ w .setUrl (Text .valueOf (work .getUrl ().getValue ()));
393+ }
394+
395+ // Set visibility
396+ if (work .getVisibility () != null ) {
397+ w .setVisibility (Visibility .valueOf (work .getVisibility ()));
398+ }
399+
400+ // Set country
401+ if (work .getCountry () != null && work .getCountry ().getValue () != null ) {
402+ w .setCountryCode (Text .valueOf (work .getCountry ().getValue ().name ()));
403+ }
404+
405+ // Set publication date
406+ FuzzyDate fuzzyPublicationDate = null ;
407+ if (work .getPublicationDate () != null ) {
408+ org .orcid .jaxb .model .common_v2 .PublicationDate publicationDate = work .getPublicationDate ();
409+ Integer year = PojoUtil .isEmpty (publicationDate .getYear ()) ? null : Integer .valueOf (publicationDate .getYear ().getValue ());
410+ Integer month = PojoUtil .isEmpty (publicationDate .getMonth ()) ? null : Integer .valueOf (publicationDate .getMonth ().getValue ());
411+ Integer day = PojoUtil .isEmpty (publicationDate .getDay ()) ? null : Integer .valueOf (publicationDate .getDay ().getValue ());
412+ if (year != null && year == 0 ) {
413+ year = null ;
414+ }
415+ if (month != null && month == 0 ) {
416+ month = null ;
417+ }
418+ if (day != null && day == 0 ) {
419+ day = null ;
420+ }
421+ fuzzyPublicationDate = FuzzyDate .valueOf (year , month , day );
422+ w .setPublicationDate (Date .valueOf (fuzzyPublicationDate ));
423+ }
424+ w .setDateSortString (PojoUtil .createDateSortString (null , fuzzyPublicationDate ));
425+
426+ // Set citation
427+ if (work .getWorkCitation () != null ) {
428+ Citation citation = new Citation ();
429+ if (!PojoUtil .isEmpty (work .getWorkCitation ().getCitation ())) {
430+ citation .setCitation (Text .valueOf (work .getWorkCitation ().getCitation ()));
431+ }
432+ if (work .getWorkCitation ().getWorkCitationType () != null ) {
433+ citation .setCitationType (Text .valueOf (work .getWorkCitation ().getWorkCitationType ().value ()));
434+ }
435+
436+ w .setCitation (citation );
437+ }
438+ // Set contributors
439+ populateContributors (work , w , maxContributorsForUI );
440+ // Set external identifiers
441+ populateExternalIdentifiers (work , w );
442+
443+ // Set created date
444+ w .setCreatedDate (Date .valueOf (work .getCreatedDate ()));
445+
446+ // Set last modified
447+ w .setLastModified (Date .valueOf (work .getLastModifiedDate ()));
448+
449+ if (work .getSource () != null ) {
450+ // Set source
451+ w .setSource (work .getSource ().retrieveSourcePath ());
452+ if (work .getSource ().getSourceName () != null ) {
453+ w .setSourceName (work .getSource ().getSourceName ().getContent ());
454+ }
455+ }
456+ return w ;
457+ }
458+
338459 private static void populateExternalIdentifiers (Work work , WorkForm workForm ) {
339460 if (work .getExternalIdentifiers () != null ) {
340461 populateExternalIdentifiers (work .getExternalIdentifiers (), workForm , work .getWorkType ());
341462 }
342463 }
343-
464+
465+ private static void populateExternalIdentifiers (org .orcid .jaxb .model .record_v2 .Work work , WorkForm workForm ) {
466+ if (work .getExternalIdentifiers () != null ) {
467+ populateExternalIdentifiers (work .getExternalIdentifiers (), workForm , work .getWorkType ());
468+ }
469+ }
470+
344471 public static void populateExternalIdentifiers (ExternalIDs extIds , WorkForm workForm , WorkType workType ) {
345472 if (extIds != null ) {
346473 List <ActivityExternalIdentifier > workExternalIdentifiersList = new ArrayList <ActivityExternalIdentifier >();
@@ -367,7 +494,34 @@ public static void populateExternalIdentifiers(ExternalIDs extIds, WorkForm work
367494 workForm .setWorkExternalIdentifiers (workExternalIdentifiersList );
368495 }
369496 }
370-
497+
498+ public static void populateExternalIdentifiers (org .orcid .jaxb .model .record_v2 .ExternalIDs extIds , WorkForm workForm , org .orcid .jaxb .model .record_v2 .WorkType workType ) {
499+ if (extIds != null ) {
500+ List <ActivityExternalIdentifier > workExternalIdentifiersList = new ArrayList <ActivityExternalIdentifier >();
501+ for (org .orcid .jaxb .model .record_v2 .ExternalID extId : extIds .getExternalIdentifier ()) {
502+ if (extId .getRelationship () == null ) {
503+ if (org .orcid .jaxb .model .message .WorkExternalIdentifierType .ISSN .equals (extId .getType ())) {
504+ if (WorkType .BOOK .equals (workType )) {
505+ extId .setRelationship (org .orcid .jaxb .model .record_v2 .Relationship .PART_OF );
506+ } else {
507+ extId .setRelationship (org .orcid .jaxb .model .record_v2 .Relationship .SELF );
508+ }
509+ } else if (org .orcid .jaxb .model .message .WorkExternalIdentifierType .ISBN .equals (extId .getType ())) {
510+ if (WorkType .BOOK_CHAPTER .equals (workType ) || WorkType .CONFERENCE_PAPER .equals (workType )) {
511+ extId .setRelationship (org .orcid .jaxb .model .record_v2 .Relationship .PART_OF );
512+ } else {
513+ extId .setRelationship (org .orcid .jaxb .model .record_v2 .Relationship .SELF );
514+ }
515+ } else {
516+ extId .setRelationship (org .orcid .jaxb .model .record_v2 .Relationship .SELF );
517+ }
518+ }
519+ workExternalIdentifiersList .add (ActivityExternalIdentifier .valueOf (extId ));
520+ }
521+ workForm .setWorkExternalIdentifiers (workExternalIdentifiersList );
522+ }
523+ }
524+
371525 private static void populateExternalIdentifiers (WorkForm workForm , Work work ) {
372526 ExternalIDs workExternalIds = new ExternalIDs ();
373527 if (workForm .getWorkExternalIdentifiers () != null && !workForm .getWorkExternalIdentifiers ().isEmpty ()) {
@@ -394,6 +548,30 @@ private static void populateExternalIdentifiers(WorkForm workForm, Work work) {
394548 work .setWorkExternalIdentifiers (workExternalIds );
395549 }
396550
551+ private static void populateContributors (org .orcid .jaxb .model .record_v2 .Work work , WorkForm workForm , int maxContributorsForUI ) {
552+ List <Contributor > contributorsList = new ArrayList <Contributor >();
553+ if (work .getWorkContributors () != null ) {
554+ List <org .orcid .jaxb .model .common_v2 .Contributor > contributors = null ;
555+ if (Features .ORCID_ANGULAR_WORKS_CONTRIBUTORS .isActive ()) {
556+ if (work .getWorkContributors ().getContributor ().size () > maxContributorsForUI ) {
557+ contributors = work .getWorkContributors ().getContributor ().subList (0 , maxContributorsForUI );
558+ } else {
559+ contributors = work .getWorkContributors ().getContributor ();
560+ }
561+ } else {
562+ contributors = work .getWorkContributors ().getContributor ();
563+ }
564+
565+ if (contributors != null ) {
566+ for (org .orcid .jaxb .model .common_v2 .Contributor contributor : contributors ) {
567+ contributorsList .add (Contributor .valueOf (contributor ));
568+ }
569+ }
570+
571+ }
572+ workForm .setContributors (contributorsList );
573+ }
574+
397575 private static void populateContributors (Work work , WorkForm workForm , int maxContributorsForUI ) {
398576 List <Contributor > contributorsList = new ArrayList <Contributor >();
399577 if (work .getWorkContributors () != null ) {
0 commit comments