Skip to content

Commit 49b822c

Browse files
committed
[DSC-1974] Fix search manager to better fetch data and follow authority for objects which are not item
1 parent 37bb707 commit 49b822c

4 files changed

Lines changed: 36 additions & 17 deletions

File tree

src/app/core/browse/search-manager.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ import { DSpaceObject } from '../shared/dspace-object.model';
1414
import { PaginatedSearchOptions } from '../../shared/search/models/paginated-search-options.model';
1515
import { SearchObjects } from '../../shared/search/models/search-objects.model';
1616
import { SearchService } from '../shared/search/search.service';
17-
import { WorkspaceItem } from '../submission/models/workspaceitem.model';
18-
import { WorkflowItem } from '../submission/models/workflowitem.model';
19-
import { hasValue } from '../../shared/empty.util';
17+
import { hasValue, isNotEmpty } from '../../shared/empty.util';
2018
import { FollowAuthorityMetadata } from '../../../config/search-follow-metadata.interface';
2119
import { MetadataValue } from '../shared/metadata.models';
2220
import { Metadata } from '../shared/metadata.utils';
2321
import isArray from 'lodash/isArray';
22+
import { WORKSPACEITEM } from '../eperson/models/workspaceitem.resource-type';
23+
import { WORKFLOWITEM } from '../eperson/models/workflowitem.resource-type';
24+
import { ITEM } from '../shared/item.resource-type';
2425

2526
/**
2627
* The service aims to manage browse requests and subsequent extra fetch requests.
@@ -84,7 +85,8 @@ export class SearchManager {
8485
protected completeSearchObjectsWithExtraData<T extends DSpaceObject>() {
8586
return switchMap((searchObjectsRD: RemoteData<SearchObjects<T>>) => {
8687
if (searchObjectsRD.isSuccess) {
87-
const items: Item[] = searchObjectsRD.payload.page.map((searchResult) => searchResult.indexableObject) as any;
88+
const items: Item[] = searchObjectsRD.payload.page
89+
.map((searchResult) => isNotEmpty(searchResult?._embedded?.indexableObject) ? searchResult._embedded.indexableObject : searchResult.indexableObject) as any;
8890
return this.fetchExtraData(items).pipe(map(() => {
8991
return searchObjectsRD;
9092
}));
@@ -96,13 +98,16 @@ export class SearchManager {
9698
protected fetchExtraData<T extends DSpaceObject>(objects: T[]): Observable<any> {
9799

98100
const items: Item[] = objects
99-
.map((object) => {
100-
if (object instanceof WorkspaceItem || object instanceof WorkflowItem) {
101-
return object.item as Item;
102-
}
103-
if (object instanceof Item) {
101+
.map((object: any) => {
102+
if (object.type === ITEM.value) {
104103
return object as Item;
104+
} else if (object.type === WORKSPACEITEM.value || object.type === WORKFLOWITEM.value) {
105+
return object?._embedded?.item as Item;
106+
} else {
107+
// Handle workflow task here, where the item is embedded in a workflowitem
108+
return object?._embedded?.workflowitem?._embedded?.item as Item;
105109
}
110+
106111
})
107112
.filter((item) => hasValue(item));
108113

@@ -127,12 +132,12 @@ export class SearchManager {
127132
if (item.entityType === followMetadata.type) {
128133
if (isArray(followMetadata.metadata)) {
129134
followMetadata.metadata.forEach((metadata) => {
130-
item.allMetadata(metadata)
135+
Metadata.all(item.metadata, metadata)
131136
.filter((metadataValue: MetadataValue) => Metadata.hasValidItemAuthority(metadataValue.authority))
132137
.forEach((metadataValue: MetadataValue) => uuidMap[metadataValue.authority] = metadataValue);
133138
});
134139
} else {
135-
item.allMetadata(followMetadata.metadata)
140+
Metadata.all(item.metadata, followMetadata.metadata)
136141
.filter((metadataValue: MetadataValue) => Metadata.hasValidItemAuthority(metadataValue.authority))
137142
.forEach((metadataValue: MetadataValue) => uuidMap[metadataValue.authority] = metadataValue);
138143
}

src/app/core/browse/search.manager.spec.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { of } from 'rxjs';
1212
import { MetadataValue } from '../shared/metadata.models';
1313
import { v4 as uuidv4 } from 'uuid';
1414
import { AUTHORITY_REFERENCE } from '../shared/metadata.utils';
15+
import { ITEM } from '../shared/item.resource-type';
1516

1617
describe('SearchManager', () => {
1718
let scheduler: TestScheduler;
@@ -31,7 +32,8 @@ describe('SearchManager', () => {
3132
})
3233

3334
]
34-
}
35+
},
36+
type: ITEM.value
3537
});
3638

3739
const secondPublication = Object.assign(new Item(), {
@@ -44,7 +46,8 @@ describe('SearchManager', () => {
4446
value: 'author2'
4547
})
4648
]
47-
}
49+
},
50+
type: ITEM.value
4851
});
4952

5053
const firstProject = Object.assign(new Item(), {
@@ -57,7 +60,8 @@ describe('SearchManager', () => {
5760
value: 'author3'
5861
})
5962
]
60-
}
63+
},
64+
type: ITEM.value
6165
});
6266

6367
const thirdPublication = Object.assign(new Item(), {
@@ -70,7 +74,8 @@ describe('SearchManager', () => {
7074
})
7175

7276
]
73-
}
77+
},
78+
type: ITEM.value
7479
});
7580

7681
const invalidAuthorityPublication = Object.assign(new Item(), {
@@ -84,7 +89,8 @@ describe('SearchManager', () => {
8489
})
8590

8691
]
87-
}
92+
},
93+
type: ITEM.value
8894
});
8995

9096
const mockBrowseService: any = {

src/app/shared/search/search.component.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@ export class SearchComponent implements OnInit, OnDestroy {
9898
/**
9999
* Embedded keys to force during the search
100100
*/
101-
@Input() forcedEmbeddedKeys: Map<string, string[]> = new Map([['default', ['metrics']]]);
101+
@Input() forcedEmbeddedKeys: Map<string, string[]> = new Map([
102+
['default', ['metrics']],
103+
['workspace', ['item','metrics']],
104+
['workflow', ['workflowitem', 'item','metrics']]
105+
]);
102106

103107
/**
104108
* A hidden query that will be used but not displayed in the url/searchbar

src/config/default-app-config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,10 @@ export class DefaultAppConfig implements AppConfig {
397397
{
398398
type: 'Product',
399399
metadata: ['dc.contributor.author']
400+
},
401+
{
402+
type: 'Patent',
403+
metadata: ['dc.contributor.author']
400404
}
401405
];
402406

0 commit comments

Comments
 (0)