Skip to content

Commit

Permalink
use people api and new js api where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
DenysVuika committed Jul 17, 2020
1 parent c3b5d17 commit ccb27d3
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@
* limitations under the License.
*/

import {
AlfrescoApiService,
LogService,
PaginationModel
} from '@alfresco/adf-core';

import { AlfrescoApiService, LogService, PaginationModel } from '@alfresco/adf-core';
import {
NodePaging,
PersonEntry,
SitePaging,
DeletedNodesPaging,
SearchRequest,
SharedLinkPaging,
FavoritePaging,
SiteMemberPaging,
SiteRolePaging
SiteRolePaging,
PeopleApi,
SitesApi,
SearchApi,
FavoritesApi,
SharedlinksApi,
TrashcanApi,
NodesApi
} from '@alfresco/js-api';
import { Injectable } from '@angular/core';
import { Observable, from, of, throwError } from 'rxjs';
Expand All @@ -43,8 +43,38 @@ export class CustomResourcesService {

private CREATE_PERMISSION = 'create';

constructor(private apiService: AlfrescoApiService,
private logService: LogService) {
constructor(private apiService: AlfrescoApiService, private logService: LogService) {}

private get api() {
return this.apiService.getInstance();
}

private get peopleApi(): PeopleApi {
return new PeopleApi(this.api);
}

private get sitesApi(): SitesApi {
return new SitesApi(this.api);
}

private get searchApi(): SearchApi {
return new SearchApi(this.api);
}

private get favoritesApi(): FavoritesApi {
return new FavoritesApi(this.api);
}

private get sharedLinksApi(): SharedlinksApi {
return new SharedlinksApi(this.api);
}

private get trashcanApi(): TrashcanApi {
return new TrashcanApi(this.api);
}

private get nodesApi(): NodesApi {
return new NodesApi(this.api);
}

/**
Expand Down Expand Up @@ -79,8 +109,8 @@ export class CustomResourcesService {
];

return new Observable((observer) => {
this.apiService.peopleApi.getPerson(personId)
.then((person: PersonEntry) => {
this.peopleApi.getPerson(personId)
.then((person) => {
const username = person.entry.id;
const filterQueries = [
{ query: `cm:modified:[NOW/DAY-30DAYS TO NOW/DAY+1DAY]` },
Expand All @@ -94,7 +124,7 @@ export class CustomResourcesService {
});
}

const query: SearchRequest = new SearchRequest({
const query = new SearchRequest({
query: {
query: '*',
language: 'afts'
Expand All @@ -111,7 +141,7 @@ export class CustomResourcesService {
skipCount: pagination.skipCount
}
});
return this.apiService.searchApi.search(query)
return this.searchApi.search(query)
.then((searchResult) => {
observer.next(searchResult);
observer.complete();
Expand Down Expand Up @@ -147,7 +177,7 @@ export class CustomResourcesService {
};

return new Observable((observer) => {
this.apiService.favoritesApi.getFavorites('-me-', options)
this.favoritesApi.listFavorites('-me-', options)
.then((result: FavoritePaging) => {
const page: FavoritePaging = {
list: {
Expand Down Expand Up @@ -195,7 +225,7 @@ export class CustomResourcesService {
};

return new Observable((observer) => {
this.apiService.peopleApi.listSiteMembershipsForPerson('-me-', options)
this.sitesApi.listSiteMembershipsForPerson('-me-', options)
.then((result: SiteRolePaging) => {
const page: SiteMemberPaging = new SiteMemberPaging( {
list: {
Expand Down Expand Up @@ -236,8 +266,10 @@ export class CustomResourcesService {
};

return new Observable((observer) => {
this.apiService.sitesApi.getSites(options)
.then((page: SitePaging) => {
this.sitesApi
.listSites(options)
.then(
(page) => {
page.list.entries.map(
({ entry }: any) => {
entry.name = entry.name || entry.title;
Expand Down Expand Up @@ -269,7 +301,7 @@ export class CustomResourcesService {
skipCount: pagination.skipCount
};

return from(this.apiService.nodesApi.getDeletedNodes(options))
return from(this.trashcanApi.listDeletedNodes(options))
.pipe(catchError((err) => this.handleError(err)));

}
Expand All @@ -291,7 +323,7 @@ export class CustomResourcesService {
where
};

return from(this.apiService.sharedLinksApi.findSharedLinks(options))
return from(this.sharedLinksApi.listSharedLinks(options))
.pipe(catchError((err) => this.handleError(err)));
}

Expand Down Expand Up @@ -369,7 +401,7 @@ export class CustomResourcesService {

} else if (nodeId) {
// cases when nodeId is '-my-', '-root-' or '-shared-'
return from(this.apiService.nodesApi.getNode(nodeId)
return from(this.nodesApi.getNode(nodeId)
.then((node) => [node.entry.id]));
}

Expand Down
18 changes: 8 additions & 10 deletions lib/core/services/ecm-user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { ContentService } from './content.service';
import { AlfrescoApiService } from './alfresco-api.service';
import { LogService } from './log.service';
import { EcmUserModel } from '../models/ecm-user.model';
import { PersonEntry } from '@alfresco/js-api';
import { PeopleApi } from '@alfresco/js-api';

@Injectable({
providedIn: 'root'
Expand All @@ -34,17 +34,19 @@ export class EcmUserService {
private logService: LogService) {
}

private get peopleApi(): PeopleApi {
return new PeopleApi(this.apiService.getInstance());
}

/**
* Gets information about a user identified by their username.
* @param userName Target username
* @returns User information
*/
getUserInfo(userName: string): Observable<EcmUserModel> {
return from(this.apiService.getInstance().core.peopleApi.getPerson(userName))
return from(this.peopleApi.getPerson(userName))
.pipe(
map((personEntry: PersonEntry) => {
return new EcmUserModel(personEntry.entry);
}),
map((personEntry) => new EcmUserModel(personEntry.entry)),
catchError((err) => this.handleError(err))
);
}
Expand All @@ -63,10 +65,7 @@ export class EcmUserService {
* @returns Image URL
*/
getUserProfileImage(avatarId: string): string {
if (avatarId) {
return this.contentService.getContentUrl(avatarId);
}
return null;
return this.contentService.getContentUrl(avatarId);
}

/**
Expand All @@ -77,5 +76,4 @@ export class EcmUserService {
this.logService.error(error);
return throwError(error || 'Server error');
}

}
9 changes: 2 additions & 7 deletions lib/testing/src/lib/core/actions/identity/identity.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,15 @@ import { RolesService } from './roles.service';
import { Logger } from '../../utils/logger';

export class IdentityService {

api: ApiService;

constructor(api: ApiService) {
this.api = api;
}

ROLES = {
ACTIVITI_USER: 'ACTIVITI_USER',
ACTIVITI_ADMIN: 'ACTIVITI_ADMIN',
ACTIVITI_DEVOPS: 'ACTIVITI_DEVOPS',
ACTIVITI_IDENTITY: 'ACTIVITI_IDENTITY'
};

constructor(public api: ApiService) {}

async createIdentityUserWithRole(roles: string[]): Promise<any> {
const rolesService = new RolesService(this.api);
const user = await this.createIdentityUser();
Expand Down

0 comments on commit ccb27d3

Please sign in to comment.