@@ -11,6 +11,8 @@ import { EntityRow } from "../table/entity-row.model";
1111import { ProjectRowMapper } from "../hca-table-projects/project-row-mapper" ;
1212import { Project } from "../shared/project.model" ;
1313import { getUnspecifiedIfNullValue } from "../table/table-methods" ;
14+ import { Contributor } from "../shared/contributor.model" ;
15+ import { Publication } from "../shared/publication.model" ;
1416
1517export class ProjectMapper extends ProjectRowMapper {
1618
@@ -28,15 +30,19 @@ export class ProjectMapper extends ProjectRowMapper {
2830 */
2931 public mapRow ( ) : EntityRow {
3032
31- // If there publications listed in the updated project (from projects edits JSON), use the updated project's
32- // publications. Otherwise, use the publication data returned from the server.
33- const publications = this . updatedProject . publications && this . updatedProject . publications . length > 0 ?
34- this . updatedProject . publications :
35- this . rollupArray ( this . row . projects , "publications" ) ;
33+ // If there publications listed in the updated project (loaded from the projects edits JSON), use the updated
34+ // project's publications. That is, replace the entire publications array returned from the server with the
35+ // publications array specified in the project edits JSON.
36+ // Otherwise, use the publication data returned from the server.
37+ const publications = this . mapPublications ( this . row . projects , this . updatedProject ) ;
38+
39+ // If there are contributors listed in the updated project (loaded from the project edits JSON), use it to
40+ // update the project's contributors. Otherwise, use the publication data return from server.
41+ const contributors = this . mapContributors ( this . row . projects , this . updatedProject ) ;
3642
3743 return Object . assign ( { } , super . mapRow ( ) , {
3844 arrayExpressAccessions : getUnspecifiedIfNullValue ( this . projects . arrayExpressAccessions ) ,
39- contributors : this . rollupArray ( this . row . projects , " contributors" ) ,
45+ contributors : contributors ,
4046 fileType : ( this . row . fileTypeSummaries || [ ] ) . map ( fileType => fileType . fileType ) ,
4147 geoSeriesAccessions : getUnspecifiedIfNullValue ( this . projects . geoSeriesAccessions ) ,
4248 insdcProjectAccessions : getUnspecifiedIfNullValue ( this . projects . insdcProjectAccessions ) ,
@@ -47,6 +53,54 @@ export class ProjectMapper extends ProjectRowMapper {
4753 } ) ;
4854 }
4955
56+ /**
57+ * Determine the set of contributors for the project being mapped. If there are project edits for this project, we
58+ * must overwrite contributor data as specified in the project edits. For contributor edits, we only overwrite the
59+ * values of the contributors that are specified in the project edits JSON (and not the entire contributor list).
60+ *
61+ * @param {any[] } projects
62+ * @param {Project } updatedProject
63+ * @returns {Contributor[] }
64+ */
65+ private mapContributors ( projects : any [ ] , updatedProject : Project ) : Contributor [ ] {
66+
67+ const projectContributors = this . rollupArray ( this . row . projects , "contributors" ) ;
68+ if ( ! updatedProject . contributors || updatedProject . contributors . length === 0 ) {
69+ return projectContributors ;
70+ }
71+
72+ // Updates have been specified for this project's contributors list; update according to the project edits.
73+ const updatedContributorsByName = updatedProject . contributors . reduce ( ( accum , contributor ) => {
74+
75+ accum . set ( contributor . contactName , contributor ) ;
76+ return accum ;
77+ } , new Map < string , Contributor > ( ) ) ;
78+
79+ return projectContributors . reduce ( ( accum , contributor ) => {
80+ const updatedContributor = updatedContributorsByName . get ( contributor . contactName ) || { } ;
81+ accum . push ( Object . assign ( { } , contributor , updatedContributor ) ) ;
82+ return accum ;
83+ } , [ ] ) ;
84+ }
85+
86+ /**
87+ * Determine the set of publications for the project being mapped. If there are project edits for this project, we
88+ * must overwrite publication data as specified in the project edits. For publication edits, we overwrite the entire
89+ * set of publications, using only the publications set in the JSON.
90+ *
91+ * @param {any[] } projects
92+ * @param {Project } updatedProject
93+ * @returns {Contributor[] }
94+ */
95+ private mapPublications ( projects : any [ ] , updatedProject : Project ) : Publication [ ] {
96+
97+ if ( updatedProject . publications && updatedProject . publications . length > 0 ) {
98+ return updatedProject . publications ;
99+ }
100+
101+ return this . rollupArray ( this . row . projects , "publications" ) ;
102+ }
103+
50104 /**
51105 * Custom roll up functionality for project meta - combine all values of the specified key into a single array, but
52106 * do not map to single string value. For example, we want to be able to pull out specific contributor or
0 commit comments