Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/main' into authorities_…
Browse files Browse the repository at this point in the history
…and_controlled_vocabularies
  • Loading branch information
atarix83 committed Jul 23, 2020
2 parents fb1b6c7 + 095d5f3 commit a25ab56
Show file tree
Hide file tree
Showing 163 changed files with 2,127 additions and 1,135 deletions.
Expand Up @@ -209,7 +209,7 @@ describe('BitstreamFormatsComponent', () => {
selectBitstreamFormat: {},
deselectBitstreamFormat: {},
deselectAllBitstreamFormats: {},
delete: observableOf(true),
delete: observableOf({ isSuccessful: true }),
clearBitStreamFormatRequests: observableOf('cleared')
});

Expand Down
Expand Up @@ -11,6 +11,7 @@ import { hasValue } from '../../../shared/empty.util';
import { NotificationsService } from '../../../shared/notifications/notifications.service';
import { Router } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { RestResponse } from '../../../core/cache/response.models';

/**
* This component renders a list of bitstream formats
Expand Down Expand Up @@ -64,7 +65,7 @@ export class BitstreamFormatsComponent implements OnInit {
const tasks$ = [];
for (const format of formats) {
if (hasValue(format.id)) {
tasks$.push(this.bitstreamFormatService.delete(format.id));
tasks$.push(this.bitstreamFormatService.delete(format.id).pipe(map((response: RestResponse) => response.isSuccessful)));
}
}
zip(...tasks$).subscribe((results: boolean[]) => {
Expand Down
Expand Up @@ -5,8 +5,7 @@ import { hasNoValue, hasValue } from '../../shared/empty.util';
import { CommunityDataService } from '../../core/data/community-data.service';
import { RemoteData } from '../../core/data/remote-data';
import { Community } from '../../core/shared/community.model';
import { getFinishedRemoteData } from '../../core/shared/operators';
import { map, tap } from 'rxjs/operators';
import { map, tap, find } from 'rxjs/operators';
import { Observable, of as observableOf } from 'rxjs';

/**
Expand All @@ -29,18 +28,15 @@ export class CreateCollectionPageGuard implements CanActivate {
this.router.navigate(['/404']);
return observableOf(false);
}
const parent: Observable<RemoteData<Community>> = this.communityService.findById(parentID)
return this.communityService.findById(parentID)
.pipe(
getFinishedRemoteData(),
);

return parent.pipe(
map((communityRD: RemoteData<Community>) => hasValue(communityRD) && communityRD.hasSucceeded && hasValue(communityRD.payload)),
tap((isValid: boolean) => {
if (!isValid) {
this.router.navigate(['/404']);
}
})
find((communityRD: RemoteData<Community>) => hasValue(communityRD.payload) || hasValue(communityRD.error)),
map((communityRD: RemoteData<Community>) => hasValue(communityRD) && communityRD.hasSucceeded && hasValue(communityRD.payload)),
tap((isValid: boolean) => {
if (!isValid) {
this.router.navigate(['/404']);
}
})
);
}
}
Expand Up @@ -5,8 +5,7 @@ import { hasNoValue, hasValue } from '../../shared/empty.util';
import { CommunityDataService } from '../../core/data/community-data.service';
import { RemoteData } from '../../core/data/remote-data';
import { Community } from '../../core/shared/community.model';
import { getFinishedRemoteData } from '../../core/shared/operators';
import { map, tap } from 'rxjs/operators';
import { map, tap, find } from 'rxjs/operators';
import { Observable, of as observableOf } from 'rxjs';

/**
Expand All @@ -29,18 +28,16 @@ export class CreateCommunityPageGuard implements CanActivate {
return observableOf(true);
}

const parent: Observable<RemoteData<Community>> = this.communityService.findById(parentID)
return this.communityService.findById(parentID)
.pipe(
getFinishedRemoteData(),
);

return parent.pipe(
map((communityRD: RemoteData<Community>) => hasValue(communityRD) && communityRD.hasSucceeded && hasValue(communityRD.payload)),
tap((isValid: boolean) => {
if (!isValid) {
this.router.navigate(['/404']);
find((communityRD: RemoteData<Community>) => hasValue(communityRD.payload) || hasValue(communityRD.error)),
map((communityRD: RemoteData<Community>) => hasValue(communityRD) && communityRD.hasSucceeded && hasValue(communityRD.payload)),
tap((isValid: boolean) => {
if (!isValid) {
this.router.navigate(['/404']);
}
}
})
)
);
}
}
Expand Up @@ -114,7 +114,7 @@ describe('ItemBitstreamsComponent', () => {
}
);
bitstreamService = jasmine.createSpyObj('bitstreamService', {
deleteAndReturnResponse: jasmine.createSpy('deleteAndReturnResponse')
delete: jasmine.createSpy('delete')
});
objectCache = jasmine.createSpyObj('objectCache', {
remove: jasmine.createSpy('remove')
Expand Down Expand Up @@ -182,12 +182,25 @@ describe('ItemBitstreamsComponent', () => {
comp.submit();
});

it('should call deleteAndReturnResponse on the bitstreamService for the marked field', () => {
expect(bitstreamService.deleteAndReturnResponse).toHaveBeenCalledWith(bitstream2.id);
it('should call delete on the bitstreamService for the marked field', () => {
expect(bitstreamService.delete).toHaveBeenCalledWith(bitstream2.id);
});

it('should not call deleteAndReturnResponse on the bitstreamService for the unmarked field', () => {
expect(bitstreamService.deleteAndReturnResponse).not.toHaveBeenCalledWith(bitstream1.id);
it('should not call delete on the bitstreamService for the unmarked field', () => {
expect(bitstreamService.delete).not.toHaveBeenCalledWith(bitstream1.id);
});
});

describe('when dropBitstream is called', () => {
const event = {
fromIndex: 0,
toIndex: 50,
// tslint:disable-next-line:no-empty
finish: () => {}
};

beforeEach(() => {
comp.dropBitstream(bundle, event);
});
});

Expand Down
Expand Up @@ -165,7 +165,7 @@ export class ItemBitstreamsComponent extends AbstractItemUpdateComponent impleme
take(1),
switchMap((removedBistreams: Bitstream[]) => {
if (isNotEmpty(removedBistreams)) {
return observableZip(...removedBistreams.map((bitstream: Bitstream) => this.bitstreamService.deleteAndReturnResponse(bitstream.id)));
return observableZip(...removedBistreams.map((bitstream: Bitstream) => this.bitstreamService.delete(bitstream.id)));
} else {
return observableOf(undefined);
}
Expand Down
Expand Up @@ -21,6 +21,7 @@ import { RelationshipService } from '../../../core/data/relationship.service';
import { EntityTypeService } from '../../../core/data/entity-type.service';
import { LinkService } from '../../../core/cache/builders/link.service';
import { followLink } from '../../../shared/utils/follow-link-config.model';
import { RestResponse } from '../../../core/cache/response.models';

@Component({
selector: 'ds-item-delete',
Expand Down Expand Up @@ -327,8 +328,8 @@ export class ItemDeleteComponent
),
).subscribe((types) => {
this.itemDataService.delete(this.item.id, types).pipe(first()).subscribe(
(succeeded: boolean) => {
this.notify(succeeded);
(response: RestResponse) => {
this.notify(response.isSuccessful);
}
);
});
Expand Down
Expand Up @@ -5,7 +5,7 @@ import { PaginatedList } from '../../../../core/data/paginated-list';
import { RemoteData } from '../../../../core/data/remote-data';
import { Relationship } from '../../../../core/shared/item-relationships/relationship.model';
import { Item } from '../../../../core/shared/item.model';
import { getFinishedRemoteData, getSucceededRemoteData } from '../../../../core/shared/operators';
import { getFirstSucceededRemoteDataPayload, getSucceededRemoteData } from '../../../../core/shared/operators';
import { hasValue } from '../../../../shared/empty.util';

/**
Expand Down Expand Up @@ -75,16 +75,19 @@ export const paginatedRelationsToItems = (thisId: string) =>
getSucceededRemoteData(),
switchMap((relationshipsRD: RemoteData<PaginatedList<Relationship>>) => {
return observableCombineLatest(
...relationshipsRD.payload.page.map((rel: Relationship) => observableCombineLatest(rel.leftItem.pipe(getFinishedRemoteData()), rel.rightItem.pipe(getFinishedRemoteData())))
).pipe(
relationshipsRD.payload.page.map((rel: Relationship) =>
observableCombineLatest([
rel.leftItem.pipe(getFirstSucceededRemoteDataPayload()),
rel.rightItem.pipe(getFirstSucceededRemoteDataPayload())]
)
)).pipe(
map((arr) =>
arr
.filter(([leftItem, rightItem]) => leftItem.hasSucceeded && rightItem.hasSucceeded)
.map(([leftItem, rightItem]) => {
if (leftItem.payload.id === thisId) {
return rightItem.payload;
} else if (rightItem.payload.id === thisId) {
return leftItem.payload;
if (leftItem.id === thisId) {
return rightItem;
} else if (rightItem.id === thisId) {
return leftItem;
}
})
.filter((item: Item) => hasValue(item))
Expand Down
Expand Up @@ -7,6 +7,8 @@ import { RouteService } from '../../core/services/route.service';
import { NotificationsService } from '../../shared/notifications/notifications.service';
import { TranslateService } from '@ngx-translate/core';
import { RequestService } from '../../core/data/request.service';
import { map } from 'rxjs/operators';
import { RestResponse } from '../../core/cache/response.models';

@Component({
selector: 'ds-workflow-item-delete',
Expand Down Expand Up @@ -39,6 +41,6 @@ export class WorkflowItemDeleteComponent extends WorkflowItemActionPageComponent
*/
sendRequest(id: string): Observable<boolean> {
this.requestService.removeByHrefSubstring('/discover');
return this.workflowItemService.delete(id);
return this.workflowItemService.delete(id).pipe(map((response: RestResponse) => response.isSuccessful));
}
}
20 changes: 5 additions & 15 deletions src/app/core/cache/builders/remote-data-build.service.ts
@@ -1,26 +1,15 @@
import { Injectable } from '@angular/core';
import { combineLatest as observableCombineLatest, Observable, of as observableOf, race as observableRace } from 'rxjs';
import { distinctUntilChanged, map, startWith, switchMap } from 'rxjs/operators';
import {
hasValue,
hasValueOperator,
isEmpty,
isNotEmpty,
isNotUndefined
} from '../../../shared/empty.util';
import { hasValue, hasValueOperator, isEmpty, isNotEmpty, isNotUndefined } from '../../../shared/empty.util';
import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils';
import { FollowLinkConfig } from '../../../shared/utils/follow-link-config.model';
import { PaginatedList } from '../../data/paginated-list';
import { RemoteData } from '../../data/remote-data';
import { RemoteDataError } from '../../data/remote-data-error';
import { RequestEntry } from '../../data/request.reducer';
import { RequestService } from '../../data/request.service';
import {
filterSuccessfulResponses,
getRequestFromRequestHref,
getRequestFromRequestUUID,
getResourceLinksFromResponse
} from '../../shared/operators';
import { filterSuccessfulResponses, getRequestFromRequestHref, getRequestFromRequestUUID, getResourceLinksFromResponse } from '../../shared/operators';
import { PageInfo } from '../../shared/page-info.model';
import { CacheableObject } from '../object-cache.reducer';
import { ObjectCacheService } from '../object-cache.service';
Expand Down Expand Up @@ -98,7 +87,8 @@ export class RemoteDataBuildService {
let error: RemoteDataError;
const response = reqEntry ? reqEntry.response : undefined;
if (hasValue(response)) {
isSuccessful = response.isSuccessful;
isSuccessful = response.statusCode === 204 ||
response.statusCode >= 200 && response.statusCode < 300 && hasValue(payload);
const errorMessage = isSuccessful === false ? (response as ErrorResponse).errorMessage : undefined;
if (hasValue(errorMessage)) {
error = new RemoteDataError(
Expand Down Expand Up @@ -155,7 +145,7 @@ export class RemoteDataBuildService {
})
);

const payload$ = observableCombineLatest(tDomainList$, pageInfo$).pipe(
const payload$ = observableCombineLatest([tDomainList$, pageInfo$]).pipe(
map(([tDomainList, pageInfo]) => {
return new PaginatedList(pageInfo, tDomainList);
})
Expand Down
9 changes: 1 addition & 8 deletions src/app/core/cache/object-cache.reducer.ts
@@ -1,7 +1,5 @@
import { autoserialize, deserialize } from 'cerialize';
import { HALLink } from '../shared/hal-link.model';
import { HALResource } from '../shared/hal-resource.model';
import { excludeFromEquals } from '../utilities/equals.decorators';
import {
ObjectCacheAction,
ObjectCacheActionTypes,
Expand All @@ -15,12 +13,6 @@ import { CacheEntry } from './cache-entry';
import { ResourceType } from '../shared/resource-type';
import { applyPatch, Operation } from 'fast-json-patch';

export enum DirtyType {
Created = 'Created',
Updated = 'Updated',
Deleted = 'Deleted'
}

/**
* An interface to represent a JsonPatch
*/
Expand Down Expand Up @@ -72,6 +64,7 @@ export class ObjectCacheEntry implements CacheEntry {
patches: Patch[] = [];
isDirty: boolean;
}

/* tslint:enable:max-classes-per-file */

/**
Expand Down
3 changes: 2 additions & 1 deletion src/app/core/cache/server-sync-buffer.reducer.ts
Expand Up @@ -9,7 +9,7 @@ import { RestRequestMethod } from '../data/rest-request-method';

/**
* An entry in the ServerSyncBufferState
* href: unique href of an ObjectCacheEntry
* href: unique href of an ServerSyncBufferEntry
* method: RestRequestMethod type
*/
export class ServerSyncBufferEntry {
Expand Down Expand Up @@ -48,6 +48,7 @@ export function serverSyncBufferReducer(state = initialState, action: ServerSync
case ServerSyncBufferActionTypes.EMPTY: {
return emptyServerSyncQueue(state, action as EmptySSBAction);
}

default: {
return state;
}
Expand Down
5 changes: 5 additions & 0 deletions src/app/core/config/config-response-parsing.service.spec.ts
Expand Up @@ -177,6 +177,7 @@ describe('ConfigResponseParsingService', () => {
Object.assign(new SubmissionDefinitionModel(), {
isDefault: true,
name: 'traditional',
id: 'traditional',
type: 'submissiondefinition',
_links: {
sections: { href: 'https://rest.api/config/submissiondefinitions/traditional/sections' },
Expand All @@ -187,6 +188,7 @@ describe('ConfigResponseParsingService', () => {
header: 'submit.progressbar.describe.stepone',
mandatory: true,
sectionType: 'submission-form',
id: 'traditionalpageone',
visibility: {
main: null,
other: 'READONLY'
Expand All @@ -201,6 +203,7 @@ describe('ConfigResponseParsingService', () => {
header: 'submit.progressbar.describe.steptwo',
mandatory: true,
sectionType: 'submission-form',
id: 'traditionalpagetwo',
visibility: {
main: null,
other: 'READONLY'
Expand All @@ -215,6 +218,7 @@ describe('ConfigResponseParsingService', () => {
header: 'submit.progressbar.upload',
mandatory: false,
sectionType: 'upload',
id: 'upload',
visibility: {
main: null,
other: 'READONLY'
Expand All @@ -229,6 +233,7 @@ describe('ConfigResponseParsingService', () => {
header: 'submit.progressbar.license',
mandatory: true,
sectionType: 'license',
id: 'license',
visibility: {
main: null,
other: 'READONLY'
Expand Down
6 changes: 6 additions & 0 deletions src/app/core/config/models/config.model.ts
Expand Up @@ -6,6 +6,12 @@ import { excludeFromEquals } from '../../utilities/equals.decorators';

export abstract class ConfigObject implements CacheableObject {

/**
* The name for this configuration
*/
@autoserialize
public id: string;

/**
* The name for this configuration
*/
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/data/bitstream-format-data.service.spec.ts
Expand Up @@ -281,7 +281,7 @@ describe('BitstreamFormatDataService', () => {
format.uuid = 'format-uuid';
format.id = 'format-id';

const expected = cold('(b|)', {b: true});
const expected = cold('(b|)', { b: responseCacheEntry.response });
const result = service.delete(format.id);

expect(result).toBeObservable(expected);
Expand Down
6 changes: 3 additions & 3 deletions src/app/core/data/bitstream-format-data.service.ts
Expand Up @@ -155,9 +155,9 @@ export class BitstreamFormatDataService extends DataService<BitstreamFormat> {
/**
* Delete an existing DSpace Object on the server
* @param formatID The DSpace Object'id to be removed
* Return an observable that emits true when the deletion was successful, false when it failed
* @return the RestResponse as an Observable
*/
delete(formatID: string): Observable<boolean> {
delete(formatID: string): Observable<RestResponse> {
const requestId = this.requestService.generateRequestId();

const hrefObs = this.halService.getEndpoint(this.linkPath).pipe(
Expand All @@ -173,7 +173,7 @@ export class BitstreamFormatDataService extends DataService<BitstreamFormat> {

return this.requestService.getByUUID(requestId).pipe(
find((request: RequestEntry) => request.completed),
map((request: RequestEntry) => request.response.isSuccessful)
map((request: RequestEntry) => request.response)
);
}

Expand Down

0 comments on commit a25ab56

Please sign in to comment.