import { Injectable } from '@angular/core' ; import { AlfrescoApiService , UserPreferencesService } from '@alfresco/adf-core' ; import { Observable , from } from 'rxjs' ; import { MinimalNodeEntity , NodePaging , Node , DeletedNodesPaging , PersonEntry , NodeEntry , DiscoveryEntry , FavoritePaging , SharedLinkPaging , SearchRequest , ResultSetPaging , SiteBody , SiteEntry , FavoriteBody , FavoriteEntry , NodesApi , TrashcanApi , SharedlinksApi , DiscoveryApi , FavoritesApi , ContentApi , SitesApi , SearchApi , PeopleApi , VersionsApi , DirectAccessUrlEntry , VersionPaging } from '@alfresco/js-api' ; import { map } from 'rxjs/operators' ; @ Injectable ( { providedIn : 'root' } ) export class ContentApiService { _nodesApi : NodesApi ; get nodesApi ( ) : NodesApi { this . _nodesApi = this . _nodesApi ?? new NodesApi ( this . api . getInstance ( ) ) ; return this . _nodesApi ; } _trashcanApi : TrashcanApi ; get trashcanApi ( ) : TrashcanApi { this . _trashcanApi = this . _trashcanApi ?? new TrashcanApi ( this . api . getInstance ( ) ) ; return this . _trashcanApi ; } _sharedLinksApi : SharedlinksApi ; get sharedLinksApi ( ) : SharedlinksApi { this . _sharedLinksApi = this . _sharedLinksApi ?? new SharedlinksApi ( this . api . getInstance ( ) ) ; return this . _sharedLinksApi ; } _discoveryApi : DiscoveryApi ; get discoveryApi ( ) : DiscoveryApi { this . _discoveryApi = this . _discoveryApi ?? new DiscoveryApi ( this . api . getInstance ( ) ) ; return this . _discoveryApi ; } _favoritesApi : FavoritesApi ; get favoritesApi ( ) : FavoritesApi { this . _favoritesApi = this . _favoritesApi ?? new FavoritesApi ( this . api . getInstance ( ) ) ; return this . _favoritesApi ; } _contentApi : ContentApi ; get contentApi ( ) : ContentApi { this . _contentApi = this . _contentApi ?? new ContentApi ( this . api . getInstance ( ) ) ; return this . _contentApi ; } _sitesApi : SitesApi ; get sitesApi ( ) : SitesApi { this . _sitesApi = this . _sitesApi ?? new SitesApi ( this . api . getInstance ( ) ) ; return this . _sitesApi ; } _searchApi : SearchApi ; get searchApi ( ) : SearchApi { this . _searchApi = this . _searchApi ?? new SearchApi ( this . api . getInstance ( ) ) ; return this . _searchApi ; } _peopleApi : PeopleApi ; get peopleApi ( ) : PeopleApi { this . _peopleApi = this . _peopleApi ?? new PeopleApi ( this . api . getInstance ( ) ) ; return this . _peopleApi ; } _versionsApi : VersionsApi ; get versionsApi ( ) : VersionsApi { this . _versionsApi = this . _versionsApi ?? new VersionsApi ( this . api . getInstance ( ) ) ; return this . _versionsApi ; } constructor ( private api , private preferences ) { } param nodeId param options returns deleteNode ( nodeId , options = { } ) { return from ( this . nodesApi . deleteNode ( nodeId , options ) ) ; } param nodeId param options returns getNode ( nodeId , options = { } ) { const defaults = { include : [ 'path' , 'properties' , 'allowableOperations' , 'permissions' , 'definition' ] } ; const queryOptions = Object . assign ( defaults , options ) ; return from ( this . nodesApi . getNode ( nodeId , queryOptions ) ) ; } getNodeInfo ( nodeId , options ? ) { const defaults = { include : [ 'isFavorite' , 'allowableOperations' , 'path' , 'definition' ] } ; const queryOptions = Object . assign ( defaults , options || { } ) ; return from ( new Promise ( ( resolve , reject ) => { this . nodesApi . getNode ( nodeId , queryOptions ) . then ( ( nodeEntry ) => { resolve ( nodeEntry . entry ) ; } , ( error ) => { reject ( error ) ; } ) ; } ) ) ; } param nodeId param options returns getNodeChildren ( nodeId , options = { } ) { const defaults = { maxItems : this . preferences . paginationSize , skipCount : 0 , include : [ 'isLocked' , 'path' , 'properties' , 'allowableOperations' , 'permissions' ] } ; const queryOptions = Object . assign ( defaults , options ) ; return from ( this . nodesApi . listNodeChildren ( nodeId , queryOptions ) ) ; } deleteSharedLink ( linkId ) { return from ( this . sharedLinksApi . deleteSharedLink ( linkId ) ) ; } getDeletedNodes ( options = { } ) { const defaults = { include : [ 'path' ] } ; const queryOptions = Object . assign ( defaults , options ) ; return from ( this . trashcanApi . listDeletedNodes ( queryOptions ) ) ; } restoreNode ( nodeId ) { return from ( this . trashcanApi . restoreDeletedNode ( nodeId ) ) ; } purgeDeletedNode ( nodeId ) { return from ( this . trashcanApi . deleteDeletedNode ( nodeId ) ) ; } param personId param options returns getPerson ( personId , options ? ) { return from ( this . peopleApi . getPerson ( personId , options ) ) ; } param nodeId param targetParentId param name param opts copyNode ( nodeId , targetParentId , name ? , opts ? ) { return from ( this . nodesApi . copyNode ( nodeId , { targetParentId , name } , opts ) ) ; } returns getRepositoryInformation ( ) { return from ( this . discoveryApi . getRepositoryInformation ( ) ) ; } getFavorites ( personId , opts ? ) { return from ( this . favoritesApi . listFavorites ( personId , opts ) ) ; } getFavoriteLibraries ( personId = '-me-' , opts ? ) { return this . getFavorites ( personId , { ... opts , where : '(EXISTS(target/site))' } ) . pipe ( map ( ( response ) => { return { list : { entries : response . list . entries . map ( ( { entry } ) => { entry . target . site . createdAt = entry . createdAt ; return { entry : entry . target . site } ; } ) , pagination : response . list . pagination } } ; } ) ) ; } findSharedLinks ( opts ? ) { return from ( this . sharedLinksApi . listSharedLinks ( opts ) ) ; } getSharedLinkContent ( sharedId , attachment ? ) { return this . contentApi . getSharedLinkContentUrl ( sharedId , attachment ) ; } search ( request ) { return from ( this . searchApi . search ( request ) ) ; } getContentUrl ( nodeId , attachment ? ) { return this . contentApi . getContentUrl ( nodeId , attachment ) ; } getVersionContentUrl ( nodeId , versionId , attachment ? ) { return this . contentApi . getVersionContentUrl ( nodeId , versionId , attachment ) ; } deleteSite ( siteId ? , opts ? ) { return from ( this . sitesApi . deleteSite ( siteId , opts ) ) ; } leaveSite ( siteId ? ) { return from ( this . sitesApi . deleteSiteMembership ( siteId , '-me-' ) ) ; } createSite ( siteBody , opts ? ) { return from ( this . sitesApi . createSite ( siteBody , opts ) ) ; } getSite ( siteId ? , opts ? ) { return from ( this . sitesApi . getSite ( siteId , opts ) ) ; } updateLibrary ( siteId , siteBody ) { return from ( this . sitesApi . updateSite ( siteId , siteBody ) ) ; } addFavorite ( nodes ) { const payload = nodes . map ( ( node ) => { const { isFolder , nodeId , id } = node . entry as any ; const siteId = node . entry [ 'guid' ] ; const type = siteId ? 'site' : isFolder ? 'folder' : 'file' ; const guid = siteId || nodeId || id ; return { target : { [ type ] : { guid } } } ; } ) ; return from ( this . favoritesApi . createFavorite ( '-me-' , payload as any ) ) ; } removeFavorite ( nodes ) { return from ( Promise . all ( nodes . map ( ( node ) => { const id = node . entry . nodeId || node . entry . id ; return this . favoritesApi . deleteFavorite ( '-me-' , id ) ; } ) ) ) ; } unlockNode ( nodeId , opts ? ) { return this . nodesApi . unlockNode ( nodeId , opts ) ; } getNodeVersions ( nodeId , opts ? ) { return from ( this . versionsApi . listVersionHistory ( nodeId , opts ) ) ; } requestNodeDirectAccessUrl ( nodeId ) { return from ( this . nodesApi . requestDirectAccessUrl ( nodeId ) ) ; } requestVersionDirectAccessUrl ( nodeId , versionId ) { return from ( this . versionsApi . requestDirectAccessUrl ( nodeId , versionId ) ) ; } }