Skip to content

Commit

Permalink
Merge 34da1dc into 8b639bc
Browse files Browse the repository at this point in the history
  • Loading branch information
atarix83 committed Jul 31, 2020
2 parents 8b639bc + 34da1dc commit 332a453
Show file tree
Hide file tree
Showing 134 changed files with 5,166 additions and 2,036 deletions.
4 changes: 1 addition & 3 deletions src/app/community-list-page/community-list-page.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { SharedModule } from '../shared/shared.module';
import { CommunityListPageComponent } from './community-list-page.component';
import { CommunityListPageRoutingModule } from './community-list-page.routing.module';
import { CommunityListComponent } from './community-list/community-list.component';
import { CdkTreeModule } from '@angular/cdk/tree';

/**
* The page which houses a title and the community list, as described in community-list.component
Expand All @@ -13,8 +12,7 @@ import { CdkTreeModule } from '@angular/cdk/tree';
imports: [
CommonModule,
SharedModule,
CommunityListPageRoutingModule,
CdkTreeModule,
CommunityListPageRoutingModule
],
declarations: [
CommunityListPageComponent,
Expand Down
1 change: 0 additions & 1 deletion src/app/core/auth/auth.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ export class AuthInterceptor implements HttpInterceptor {

// Pass on the new request instead of the original request.
return next.handle(newReq).pipe(
// tap((response) => console.log('next.handle: ', response)),
map((response) => {
// Intercept a Login/Logout response
if (response instanceof HttpResponse && this.isSuccess(response) && this.isAuthRequest(response)) {
Expand Down
1 change: 1 addition & 0 deletions src/app/core/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ export class AuthService {
} else {
// If redirectUrl is empty use history.
this.routeService.getHistory().pipe(
filter((history) => history.length > 0),
take(1)
).subscribe((history) => {
let redirUrl;
Expand Down
12 changes: 0 additions & 12 deletions src/app/core/cache/response.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { PageInfo } from '../shared/page-info.model';
import { ConfigObject } from '../config/models/config.model';
import { FacetValue } from '../../shared/search/facet-value.model';
import { SearchFilterConfig } from '../../shared/search/search-filter-config.model';
import { IntegrationModel } from '../integration/models/integration.model';
import { PaginatedList } from '../data/paginated-list';
import { SubmissionObject } from '../submission/models/submission-object.model';
import { DSpaceObject } from '../shared/dspace-object.model';
Expand Down Expand Up @@ -181,17 +180,6 @@ export class TokenResponse extends RestResponse {
}
}

export class IntegrationSuccessResponse extends RestResponse {
constructor(
public dataDefinition: PaginatedList<IntegrationModel>,
public statusCode: number,
public statusText: string,
public pageInfo?: PageInfo
) {
super(true, statusCode, statusText);
}
}

export class PostPatchSuccessResponse extends RestResponse {
constructor(
public dataDefinition: any,
Expand Down
29 changes: 18 additions & 11 deletions src/app/core/core.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CommonModule } from '@angular/common';
import { HTTP_INTERCEPTORS, HttpClient } from '@angular/common/http';
import { ModuleWithProviders, NgModule, Optional, SkipSelf } from '@angular/core';

import { DynamicFormLayoutService, DynamicFormService, DynamicFormValidationService } from '@ng-dynamic-forms/core';
import { EffectsModule } from '@ngrx/effects';

Expand All @@ -15,8 +16,8 @@ import { MenuService } from '../shared/menu/menu.service';
import { EndpointMockingRestService } from '../shared/mocks/dspace-rest-v2/endpoint-mocking-rest.service';
import {
MOCK_RESPONSE_MAP,
ResponseMapMock,
mockResponseMap
mockResponseMap,
ResponseMapMock
} from '../shared/mocks/dspace-rest-v2/mocks/response-map.mock';
import { NotificationsService } from '../shared/notifications/notifications.service';
import { SelectableListService } from '../shared/object-list/selectable-list/selectable-list.service';
Expand Down Expand Up @@ -80,9 +81,6 @@ import { EPersonDataService } from './eperson/eperson-data.service';
import { EpersonResponseParsingService } from './eperson/eperson-response-parsing.service';
import { EPerson } from './eperson/models/eperson.model';
import { Group } from './eperson/models/group.model';
import { AuthorityService } from './integration/authority.service';
import { IntegrationResponseParsingService } from './integration/integration-response-parsing.service';
import { AuthorityValue } from './integration/models/authority.value';
import { JsonPatchOperationsBuilder } from './json-patch/builder/json-patch-operations-builder';
import { MetadataField } from './metadata/metadata-field.model';
import { MetadataSchema } from './metadata/metadata-schema.model';
Expand Down Expand Up @@ -160,6 +158,12 @@ import { SubmissionCcLicenseDataService } from './submission/submission-cc-licen
import { SubmissionCcLicence } from './submission/models/submission-cc-license.model';
import { SubmissionCcLicenceUrl } from './submission/models/submission-cc-license-url.model';
import { SubmissionCcLicenseUrlDataService } from './submission/submission-cc-license-url-data.service';
import { VocabularyEntry } from './submission/vocabularies/models/vocabulary-entry.model';
import { Vocabulary } from './submission/vocabularies/models/vocabulary.model';
import { VocabularyEntriesResponseParsingService } from './submission/vocabularies/vocabulary-entries-response-parsing.service';
import { VocabularyEntryDetail } from './submission/vocabularies/models/vocabulary-entry-detail.model';
import { VocabularyService } from './submission/vocabularies/vocabulary.service';
import { VocabularyTreeviewService } from '../shared/vocabulary-treeview/vocabulary-treeview.service';

/**
* When not in production, endpoint responses can be mocked for testing purposes
Expand Down Expand Up @@ -193,7 +197,7 @@ const PROVIDERS = [
SiteDataService,
DSOResponseParsingService,
{ provide: MOCK_RESPONSE_MAP, useValue: mockResponseMap },
{ provide: DSpaceRESTv2Service, useFactory: restServiceFactory, deps: [MOCK_RESPONSE_MAP, HttpClient]},
{ provide: DSpaceRESTv2Service, useFactory: restServiceFactory, deps: [MOCK_RESPONSE_MAP, HttpClient] },
DynamicFormLayoutService,
DynamicFormService,
DynamicFormValidationService,
Expand Down Expand Up @@ -235,8 +239,6 @@ const PROVIDERS = [
SubmissionResponseParsingService,
SubmissionJsonPatchOperationsService,
JsonPatchOperationsBuilder,
AuthorityService,
IntegrationResponseParsingService,
UploaderService,
UUIDService,
NotificationsService,
Expand Down Expand Up @@ -300,7 +302,10 @@ const PROVIDERS = [
},
NotificationsService,
FilteredDiscoveryPageResponseParsingService,
{ provide: NativeWindowService, useFactory: NativeWindowFactory }
{ provide: NativeWindowService, useFactory: NativeWindowFactory },
VocabularyService,
VocabularyEntriesResponseParsingService,
VocabularyTreeviewService
];

/**
Expand Down Expand Up @@ -331,7 +336,6 @@ export const models =
SubmissionSectionModel,
SubmissionUploadsModel,
AuthStatus,
AuthorityValue,
BrowseEntry,
BrowseDefinition,
ClaimedTask,
Expand All @@ -350,7 +354,10 @@ export const models =
TemplateItem,
Feature,
Authorization,
Registration
Registration,
Vocabulary,
VocabularyEntry,
VocabularyEntryDetail
];

@NgModule({
Expand Down
34 changes: 8 additions & 26 deletions src/app/core/data/browse-entries-response-parsing.service.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,22 @@
import { Inject, Injectable } from '@angular/core';
import { isNotEmpty } from '../../shared/empty.util';
import { Injectable } from '@angular/core';
import { ObjectCacheService } from '../cache/object-cache.service';
import { ErrorResponse, GenericSuccessResponse, RestResponse } from '../cache/response.models';
import { DSpaceRESTV2Response } from '../dspace-rest-v2/dspace-rest-v2-response.model';
import { DSpaceSerializer } from '../dspace-rest-v2/dspace.serializer';
import { BrowseEntry } from '../shared/browse-entry.model';
import { BaseResponseParsingService } from './base-response-parsing.service';
import { ResponseParsingService } from './parsing.service';
import { RestRequest } from './request.models';
import { EntriesResponseParsingService } from './entries-response-parsing.service';
import { GenericConstructor } from '../shared/generic-constructor';

@Injectable()
export class BrowseEntriesResponseParsingService extends BaseResponseParsingService implements ResponseParsingService {
export class BrowseEntriesResponseParsingService extends EntriesResponseParsingService<BrowseEntry> {

protected toCache = false;

constructor(
protected objectCache: ObjectCacheService,
) { super();
) {
super(objectCache);
}

parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse {
if (isNotEmpty(data.payload)) {
let browseEntries = [];
if (isNotEmpty(data.payload._embedded) && Array.isArray(data.payload._embedded[Object.keys(data.payload._embedded)[0]])) {
const serializer = new DSpaceSerializer(BrowseEntry);
browseEntries = serializer.deserializeArray(data.payload._embedded[Object.keys(data.payload._embedded)[0]]);
}
return new GenericSuccessResponse(browseEntries, data.statusCode, data.statusText, this.processPageInfo(data.payload));
} else {
return new ErrorResponse(
Object.assign(
new Error('Unexpected response from browse endpoint'),
{ statusCode: data.statusCode, statusText: data.statusText }
)
);
}
getSerializerModel(): GenericConstructor<BrowseEntry> {
return BrowseEntry;
}

}
10 changes: 0 additions & 10 deletions src/app/core/data/bundle-data.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
import { HttpClient } from '@angular/common/http';
import { Store } from '@ngrx/store';
import { compare, Operation } from 'fast-json-patch';
import { Observable, of as observableOf } from 'rxjs';
import { NotificationsService } from '../../shared/notifications/notifications.service';
import { followLink } from '../../shared/utils/follow-link-config.model';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
import { SortDirection, SortOptions } from '../cache/models/sort-options.model';
import { ObjectCacheService } from '../cache/object-cache.service';
import { CoreState } from '../core.reducers';
import { DSpaceObject } from '../shared/dspace-object.model';
import { HALEndpointService } from '../shared/hal-endpoint.service';
import { Item } from '../shared/item.model';
import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
import { ChangeAnalyzer } from './change-analyzer';
import { DataService } from './data.service';
import { FindListOptions, PatchRequest } from './request.models';
import { RequestService } from './request.service';
import { getMockRequestService } from '../../shared/mocks/request.service.mock';
import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-service.stub';
import { BundleDataService } from './bundle-data.service';
Expand Down
6 changes: 3 additions & 3 deletions src/app/core/data/collection-data.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-servic
import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub';
import { getMockTranslateService } from '../../shared/mocks/translate.service.mock';
import { fakeAsync, tick } from '@angular/core/testing';
import { ContentSourceRequest, GetRequest, RequestError, UpdateContentSourceRequest } from './request.models';
import { ContentSourceRequest, GetRequest, UpdateContentSourceRequest } from './request.models';
import { ContentSource } from '../shared/content-source.model';
import { of as observableOf } from 'rxjs/internal/observable/of';
import { RequestEntry } from './request.reducer';
import { ErrorResponse, RestResponse } from '../cache/response.models';
import { ErrorResponse } from '../cache/response.models';
import { ObjectCacheService } from '../cache/object-cache.service';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
import { Collection } from '../shared/collection.model';
import { PageInfo } from '../shared/page-info.model';
import { PaginatedList } from './paginated-list';
import { createSuccessfulRemoteDataObject } from 'src/app/shared/remote-data.utils';
import { hot, getTestScheduler, cold } from 'jasmine-marbles';
import { cold, getTestScheduler, hot } from 'jasmine-marbles';
import { TestScheduler } from 'rxjs/testing';

const url = 'fake-url';
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/data/community-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { RequestService } from './request.service';
@dataService(COMMUNITY)
export class CommunityDataService extends ComColDataService<Community> {
protected linkPath = 'communities';
protected topLinkPath = 'communities/search/top';
protected topLinkPath = 'search/top';
protected cds = this;

constructor(
Expand Down
24 changes: 23 additions & 1 deletion src/app/core/data/data.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { FindListOptions, PatchRequest } from './request.models';
import { RequestService } from './request.service';
import { getMockRequestService } from '../../shared/mocks/request.service.mock';
import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-service.stub';
import { RequestParam } from '../cache/models/request-param.model';

const endpoint = 'https://rest.api/core';

Expand Down Expand Up @@ -150,7 +151,8 @@ describe('DataService', () => {
currentPage: 6,
elementsPerPage: 10,
sort: sortOptions,
startsWith: 'ab'
startsWith: 'ab',

};
const expected = `${endpoint}?page=${options.currentPage - 1}&size=${options.elementsPerPage}` +
`&sort=${sortOptions.field},${sortOptions.direction}&startsWith=${options.startsWith}`;
Expand All @@ -160,6 +162,26 @@ describe('DataService', () => {
});
});

it('should include all searchParams in href if any provided in options', () => {
options = { searchParams: [
new RequestParam('param1', 'test'),
new RequestParam('param2', 'test2'),
] };
const expected = `${endpoint}?param1=test&param2=test2`;

(service as any).getFindAllHref(options).subscribe((value) => {
expect(value).toBe(expected);
});
});

it('should include linkPath in href if any provided', () => {
const expected = `${endpoint}/test/entries`;

(service as any).getFindAllHref({}, 'test/entries').subscribe((value) => {
expect(value).toBe(expected);
});
});

it('should include single linksToFollow as embed', () => {
const expected = `${endpoint}?embed=bundles`;

Expand Down
27 changes: 15 additions & 12 deletions src/app/core/data/data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,17 @@ export abstract class DataService<T extends CacheableObject> implements UpdateDa
* Return an observable that emits created HREF
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which {@link HALLink}s should be automatically resolved
*/
protected getFindAllHref(options: FindListOptions = {}, linkPath?: string, ...linksToFollow: Array<FollowLinkConfig<T>>): Observable<string> {
let result$: Observable<string>;
public getFindAllHref(options: FindListOptions = {}, linkPath?: string, ...linksToFollow: Array<FollowLinkConfig<T>>): Observable<string> {
let endpoint$: Observable<string>;
const args = [];

result$ = this.getBrowseEndpoint(options, linkPath).pipe(distinctUntilChanged());
endpoint$ = this.getBrowseEndpoint(options).pipe(
filter((href: string) => isNotEmpty(href)),
map((href: string) => isNotEmpty(linkPath) ? `${href}/${linkPath}` : href),
distinctUntilChanged()
);

return result$.pipe(map((result: string) => this.buildHrefFromFindOptions(result, options, args, ...linksToFollow)));
return endpoint$.pipe(map((result: string) => this.buildHrefFromFindOptions(result, options, args, ...linksToFollow)));
}

/**
Expand All @@ -89,18 +93,12 @@ export abstract class DataService<T extends CacheableObject> implements UpdateDa
* Return an observable that emits created HREF
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which {@link HALLink}s should be automatically resolved
*/
protected getSearchByHref(searchMethod: string, options: FindListOptions = {}, ...linksToFollow: Array<FollowLinkConfig<T>>): Observable<string> {
public getSearchByHref(searchMethod: string, options: FindListOptions = {}, ...linksToFollow: Array<FollowLinkConfig<T>>): Observable<string> {
let result$: Observable<string>;
const args = [];

result$ = this.getSearchEndpoint(searchMethod);

if (hasValue(options.searchParams)) {
options.searchParams.forEach((param: RequestParam) => {
args.push(`${param.fieldName}=${param.fieldValue}`);
})
}

return result$.pipe(map((result: string) => this.buildHrefFromFindOptions(result, options, args, ...linksToFollow)));
}

Expand All @@ -114,7 +112,7 @@ export abstract class DataService<T extends CacheableObject> implements UpdateDa
* Return an observable that emits created HREF
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which {@link HALLink}s should be automatically resolved
*/
protected buildHrefFromFindOptions(href: string, options: FindListOptions, extraArgs: string[] = [], ...linksToFollow: Array<FollowLinkConfig<T>>): string {
public buildHrefFromFindOptions(href: string, options: FindListOptions, extraArgs: string[] = [], ...linksToFollow: Array<FollowLinkConfig<T>>): string {
let args = [...extraArgs];

if (hasValue(options.currentPage) && typeof options.currentPage === 'number') {
Expand All @@ -130,6 +128,11 @@ export abstract class DataService<T extends CacheableObject> implements UpdateDa
if (hasValue(options.startsWith)) {
args = [...args, `startsWith=${options.startsWith}`];
}
if (hasValue(options.searchParams)) {
options.searchParams.forEach((param: RequestParam) => {
args = [...args, `${param.fieldName}=${param.fieldValue}`];
})
}
args = this.addEmbedParams(args, ...linksToFollow);
if (isNotEmpty(args)) {
return new URLCombiner(href, `?${args.join('&')}`).toString();
Expand Down

0 comments on commit 332a453

Please sign in to comment.