@@ -24,6 +24,7 @@ import {
2424 switchMap ,
2525 take ,
2626} from 'rxjs/operators' ;
27+ import { validate as uuidValidate } from 'uuid' ;
2728
2829import { BrowseService } from '../browse/browse.service' ;
2930import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service' ;
@@ -34,6 +35,7 @@ import { NotificationsService } from '../notification-system/notifications.servi
3435import { Bundle } from '../shared/bundle.model' ;
3536import { Collection } from '../shared/collection.model' ;
3637import { ExternalSourceEntry } from '../shared/external-source-entry.model' ;
38+ import { FollowLinkConfig } from '../shared/follow-link-config.model' ;
3739import { GenericConstructor } from '../shared/generic-constructor' ;
3840import { HALEndpointService } from '../shared/hal-endpoint.service' ;
3941import { Item } from '../shared/item.model' ;
@@ -58,6 +60,7 @@ import {
5860 PatchData ,
5961 PatchDataImpl ,
6062} from './base/patch-data' ;
63+ import { SearchDataImpl } from './base/search-data' ;
6164import { BundleDataService } from './bundle-data.service' ;
6265import { DSOChangeAnalyzer } from './dso-change-analyzer.service' ;
6366import { FindListOptions } from './find-list-options.model' ;
@@ -83,6 +86,7 @@ export abstract class BaseItemDataService extends IdentifiableDataService<Item>
8386 private createData : CreateData < Item > ;
8487 private patchData : PatchData < Item > ;
8588 private deleteData : DeleteData < Item > ;
89+ private searchData : SearchDataImpl < Item > ;
8690
8791 protected constructor (
8892 protected linkPath ,
@@ -101,6 +105,7 @@ export abstract class BaseItemDataService extends IdentifiableDataService<Item>
101105 this . createData = new CreateDataImpl ( this . linkPath , requestService , rdbService , objectCache , halService , notificationsService , this . responseMsToLive ) ;
102106 this . patchData = new PatchDataImpl < Item > ( this . linkPath , requestService , rdbService , objectCache , halService , comparator , this . responseMsToLive , this . constructIdEndpoint ) ;
103107 this . deleteData = new DeleteDataImpl ( this . linkPath , requestService , rdbService , objectCache , halService , notificationsService , this . responseMsToLive , this . constructIdEndpoint ) ;
108+ this . searchData = new SearchDataImpl ( this . linkPath , requestService , rdbService , objectCache , halService , this . responseMsToLive ) ;
104109 }
105110
106111 /**
@@ -425,6 +430,57 @@ export abstract class BaseItemDataService extends IdentifiableDataService<Item>
425430 return this . createData . create ( object , ...params ) ;
426431 }
427432
433+ /**
434+ * Returns an observable of {@link RemoteData} of an object, based on its CustomURL or ID, with a list of
435+ * {@link FollowLinkConfig}, to automatically resolve {@link HALLink}s of the object
436+ * @param id CustomUrl or UUID of object we want to retrieve
437+ * @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
438+ * no valid cached version. Defaults to true
439+ * @param reRequestOnStale Whether or not the request should automatically be re-
440+ * requested after the response becomes stale
441+ * @param linksToFollow List of {@link FollowLinkConfig} that indicate which
442+ * {@link HALLink}s should be automatically resolved
443+ * @param projections List of {@link projections} used to pass as parameters
444+ */
445+ public findByCustomUrl ( id : string , useCachedVersionIfAvailable = true , reRequestOnStale = true , linksToFollow : FollowLinkConfig < Item > [ ] , projections : string [ ] = [ ] ) : Observable < RemoteData < Item > > {
446+ const searchHref = 'findByCustomURL' ;
447+
448+ const options = Object . assign ( { } , {
449+ searchParams : [
450+ new RequestParam ( 'q' , id ) ,
451+ ] ,
452+ } ) ;
453+
454+ projections . forEach ( ( projection ) => {
455+ options . searchParams . push ( new RequestParam ( 'projection' , projection ) ) ;
456+ } ) ;
457+
458+ const hrefObs = this . searchData . getSearchByHref ( searchHref , options , ...linksToFollow ) ;
459+
460+ return this . findByHref ( hrefObs , useCachedVersionIfAvailable , reRequestOnStale , ...linksToFollow ) ;
461+ }
462+
463+ /**
464+ * Returns an observable of {@link RemoteData} of an object, based on its ID, with a list of
465+ * {@link FollowLinkConfig}, to automatically resolve {@link HALLink}s of the object
466+ * @param id ID of object we want to retrieve
467+ * @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
468+ * no valid cached version. Defaults to true
469+ * @param reRequestOnStale Whether or not the request should automatically be re-
470+ * requested after the response becomes stale
471+ * @param linksToFollow List of {@link FollowLinkConfig} that indicate which
472+ * {@link HALLink}s should be automatically resolved
473+ */
474+ public findById ( id : string , useCachedVersionIfAvailable = true , reRequestOnStale = true , ...linksToFollow : FollowLinkConfig < Item > [ ] ) : Observable < RemoteData < Item > > {
475+
476+ if ( uuidValidate ( id ) ) {
477+ const href$ = this . getIDHrefObs ( encodeURIComponent ( id ) , ...linksToFollow ) ;
478+ return this . findByHref ( href$ , useCachedVersionIfAvailable , reRequestOnStale , ...linksToFollow ) ;
479+ } else {
480+ return this . findByCustomUrl ( id , useCachedVersionIfAvailable , reRequestOnStale , linksToFollow ) ;
481+ }
482+ }
483+
428484}
429485
430486/**
0 commit comments