mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Removed unsed services
This commit is contained in:
@@ -83,11 +83,9 @@ import { SearchService } from '../+search-page/search-service/search.service';
|
|||||||
import { RoleService } from './roles/role.service';
|
import { RoleService } from './roles/role.service';
|
||||||
import { MyDSpaceGuard } from '../+my-dspace-page/my-dspace.guard';
|
import { MyDSpaceGuard } from '../+my-dspace-page/my-dspace.guard';
|
||||||
import { MyDSpaceResponseParsingService } from './data/mydspace-response-parsing.service';
|
import { MyDSpaceResponseParsingService } from './data/mydspace-response-parsing.service';
|
||||||
import { MessageService } from './message/message.service';
|
|
||||||
import { ClaimedTaskDataService } from './tasks/claimed-task-data.service';
|
import { ClaimedTaskDataService } from './tasks/claimed-task-data.service';
|
||||||
import { PoolTaskDataService } from './tasks/pool-task-data.service';
|
import { PoolTaskDataService } from './tasks/pool-task-data.service';
|
||||||
import { TaskResponseParsingService } from './tasks/task-response-parsing.service';
|
import { TaskResponseParsingService } from './tasks/task-response-parsing.service';
|
||||||
import { MessageResponseParsingService } from './message/message-response-parsing.service';
|
|
||||||
|
|
||||||
const IMPORTS = [
|
const IMPORTS = [
|
||||||
CommonModule,
|
CommonModule,
|
||||||
@@ -173,8 +171,6 @@ const PROVIDERS = [
|
|||||||
SearchService,
|
SearchService,
|
||||||
MyDSpaceGuard,
|
MyDSpaceGuard,
|
||||||
RoleService,
|
RoleService,
|
||||||
MessageResponseParsingService,
|
|
||||||
MessageService,
|
|
||||||
TaskResponseParsingService,
|
TaskResponseParsingService,
|
||||||
ClaimedTaskDataService,
|
ClaimedTaskDataService,
|
||||||
PoolTaskDataService,
|
PoolTaskDataService,
|
||||||
|
@@ -18,7 +18,6 @@ import { MetadataschemaParsingService } from './metadataschema-parsing.service';
|
|||||||
import { MetadatafieldParsingService } from './metadatafield-parsing.service';
|
import { MetadatafieldParsingService } from './metadatafield-parsing.service';
|
||||||
import { URLCombiner } from '../url-combiner/url-combiner';
|
import { URLCombiner } from '../url-combiner/url-combiner';
|
||||||
import { TaskResponseParsingService } from '../tasks/task-response-parsing.service';
|
import { TaskResponseParsingService } from '../tasks/task-response-parsing.service';
|
||||||
import { MessageResponseParsingService } from '../message/message-response-parsing.service';
|
|
||||||
|
|
||||||
/* tslint:disable:max-classes-per-file */
|
/* tslint:disable:max-classes-per-file */
|
||||||
|
|
||||||
@@ -372,26 +371,6 @@ export class DeleteByIDRequest extends DeleteRequest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class MessagePostRequest extends PostRequest {
|
|
||||||
constructor(uuid: string, href: string, public body?: any, public options?: HttpOptions) {
|
|
||||||
super(uuid, href, body, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
getResponseParser(): GenericConstructor<ResponseParsingService> {
|
|
||||||
return MessageResponseParsingService;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class MessageGetRequest extends GetRequest {
|
|
||||||
constructor(uuid: string, href: string, public options?: HttpOptions) {
|
|
||||||
super(uuid, href, null, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
getResponseParser(): GenericConstructor<ResponseParsingService> {
|
|
||||||
return MessageResponseParsingService;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class TaskPostRequest extends PostRequest {
|
export class TaskPostRequest extends PostRequest {
|
||||||
constructor(uuid: string, href: string, public body?: any, public options?: HttpOptions) {
|
constructor(uuid: string, href: string, public body?: any, public options?: HttpOptions) {
|
||||||
super(uuid, href, body, options);
|
super(uuid, href, body, options);
|
||||||
|
@@ -1,17 +0,0 @@
|
|||||||
import { RemoteDataError } from '../data/remote-data-error';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A class to represent the data retrieved by after processing a message
|
|
||||||
*/
|
|
||||||
export class MessageDataResponse {
|
|
||||||
constructor(
|
|
||||||
private isSuccessful: boolean,
|
|
||||||
public error?: RemoteDataError,
|
|
||||||
public payload?: any
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
|
|
||||||
get hasSucceeded(): boolean {
|
|
||||||
return this.isSuccessful;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,37 +0,0 @@
|
|||||||
import { Inject, Injectable } from '@angular/core';
|
|
||||||
|
|
||||||
import { ResponseParsingService } from '../data/parsing.service';
|
|
||||||
import { RestRequest } from '../data/request.models';
|
|
||||||
import { DSpaceRESTV2Response } from '../dspace-rest-v2/dspace-rest-v2-response.model';
|
|
||||||
import { BaseResponseParsingService } from '../data/base-response-parsing.service';
|
|
||||||
import { GLOBAL_CONFIG } from '../../../config';
|
|
||||||
import { GlobalConfig } from '../../../config/global-config.interface';
|
|
||||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
|
||||||
import { ErrorResponse, MessageResponse, RestResponse } from '../cache/response.models';
|
|
||||||
import { NormalizedObjectFactory } from '../cache/models/normalized-object-factory';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class MessageResponseParsingService extends BaseResponseParsingService implements ResponseParsingService {
|
|
||||||
|
|
||||||
protected objectFactory = NormalizedObjectFactory;
|
|
||||||
protected toCache = false;
|
|
||||||
|
|
||||||
constructor(@Inject(GLOBAL_CONFIG) protected EnvConfig: GlobalConfig,
|
|
||||||
protected objectCache: ObjectCacheService,) {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse {
|
|
||||||
if (this.isSuccessStatus(data.statusCode)) {
|
|
||||||
return new MessageResponse( data.statusCode, data.statusText);
|
|
||||||
} else {
|
|
||||||
return new ErrorResponse(
|
|
||||||
Object.assign(
|
|
||||||
new Error('Unexpected response from server'),
|
|
||||||
{ statusCode: data.statusCode, statusText: data.statusText }
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,107 +0,0 @@
|
|||||||
import { Injectable } from '@angular/core';
|
|
||||||
import { HttpHeaders } from '@angular/common/http';
|
|
||||||
|
|
||||||
import { merge as observableMerge, Observable, of as observableOf } from 'rxjs';
|
|
||||||
import { catchError, distinctUntilChanged, filter, flatMap, map, mergeMap, tap } from 'rxjs/operators';
|
|
||||||
|
|
||||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
|
||||||
import { RequestService } from '../data/request.service';
|
|
||||||
import { isNotEmpty } from '../../shared/empty.util';
|
|
||||||
import { MessageGetRequest, MessagePostRequest, PostRequest, RestRequest } from '../data/request.models';
|
|
||||||
import { DSpaceRESTv2Service, HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service';
|
|
||||||
import { MessageDataResponse } from './message-data-response';
|
|
||||||
import { RemoteDataError } from '../data/remote-data-error';
|
|
||||||
import { getResponseFromEntry } from '../shared/operators';
|
|
||||||
import { ErrorResponse, MessageResponse, RestResponse } from '../cache/response.models';
|
|
||||||
import { RestRequestMethod } from '../data/rest-request-method';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class MessageService {
|
|
||||||
protected linkPath = 'messages';
|
|
||||||
|
|
||||||
constructor(protected http: DSpaceRESTv2Service,
|
|
||||||
protected requestService: RequestService,
|
|
||||||
protected halService: HALEndpointService) {
|
|
||||||
}
|
|
||||||
|
|
||||||
protected fetchRequest(requestId: string): Observable<MessageDataResponse> {
|
|
||||||
const responses = this.requestService.getByUUID(requestId).pipe(
|
|
||||||
getResponseFromEntry()
|
|
||||||
);
|
|
||||||
const errorResponses = responses.pipe(
|
|
||||||
filter((response: RestResponse) => !response.isSuccessful),
|
|
||||||
mergeMap((response: ErrorResponse) => observableOf(
|
|
||||||
new MessageDataResponse(
|
|
||||||
response.isSuccessful,
|
|
||||||
new RemoteDataError(response.statusCode, response.statusText, response.errorMessage)
|
|
||||||
))
|
|
||||||
));
|
|
||||||
const successResponses = responses.pipe(
|
|
||||||
filter((response: RestResponse) => response.isSuccessful),
|
|
||||||
map((response: MessageResponse) => new MessageDataResponse(response.isSuccessful)),
|
|
||||||
distinctUntilChanged()
|
|
||||||
);
|
|
||||||
return observableMerge(errorResponses, successResponses);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected getEndpointByMethod(endpoint: string, method: string): string {
|
|
||||||
return isNotEmpty(method) ? `${endpoint}/${method}` : `${endpoint}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
public postToEndpoint(method: string, body: any, options?: HttpOptions): Observable<MessageDataResponse> {
|
|
||||||
const requestId = this.requestService.generateRequestId();
|
|
||||||
return this.halService.getEndpoint(this.linkPath).pipe(
|
|
||||||
filter((href: string) => isNotEmpty(href)),
|
|
||||||
map((endpointURL: string) => this.getEndpointByMethod(endpointURL, method)),
|
|
||||||
distinctUntilChanged(),
|
|
||||||
map((endpointURL: string) => new MessagePostRequest(requestId, endpointURL, body, options)),
|
|
||||||
tap((request: PostRequest) => this.requestService.configure(request)),
|
|
||||||
flatMap((request: PostRequest) => this.fetchRequest(requestId)),
|
|
||||||
distinctUntilChanged());
|
|
||||||
}
|
|
||||||
|
|
||||||
public getRequest(method: string, options?: HttpOptions): Observable<any> {
|
|
||||||
const requestId = this.requestService.generateRequestId();
|
|
||||||
return this.halService.getEndpoint(this.linkPath).pipe(
|
|
||||||
map((endpointURL: string) => this.getEndpointByMethod(endpointURL, method)),
|
|
||||||
filter((href: string) => isNotEmpty(href)),
|
|
||||||
distinctUntilChanged(),
|
|
||||||
map((endpointURL: string) => new MessageGetRequest(requestId, endpointURL)),
|
|
||||||
tap((request: RestRequest) => this.requestService.configure(request, true)),
|
|
||||||
flatMap((request: RestRequest) => this.fetchRequest(requestId)),
|
|
||||||
distinctUntilChanged());
|
|
||||||
}
|
|
||||||
|
|
||||||
public createMessage(body: any, options?: HttpOptions): Observable<MessageDataResponse> {
|
|
||||||
return this.postToEndpoint('', this.requestService.prepareBody(body), this.makeHttpOptions());
|
|
||||||
}
|
|
||||||
|
|
||||||
public markAsRead(body: any, options?: HttpOptions): Observable<MessageDataResponse> {
|
|
||||||
return this.postToEndpoint('read', this.requestService.prepareBody(body), this.makeHttpOptions());
|
|
||||||
}
|
|
||||||
|
|
||||||
public markAsUnread(body: any, options?: HttpOptions): Observable<MessageDataResponse> {
|
|
||||||
return this.postToEndpoint('unread', this.requestService.prepareBody(body), this.makeHttpOptions());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected makeHttpOptions() {
|
|
||||||
const options: HttpOptions = Object.create({});
|
|
||||||
let headers = new HttpHeaders();
|
|
||||||
headers = headers.append('Content-Type', 'application/x-www-form-urlencoded');
|
|
||||||
options.headers = headers;
|
|
||||||
return options;
|
|
||||||
}
|
|
||||||
|
|
||||||
public getMessageContent(url: string): Observable<any> {
|
|
||||||
if (isNotEmpty(url)) {
|
|
||||||
const options: HttpOptions = Object.create({});
|
|
||||||
options.observe = 'response';
|
|
||||||
options.responseType = 'text';
|
|
||||||
return this.http.request(RestRequestMethod.GET, url, null, options).pipe(
|
|
||||||
map((res) => ({ payload: res.payload })),
|
|
||||||
catchError((err) => observableOf({ payload: '' })));
|
|
||||||
} else {
|
|
||||||
return observableOf({ payload: '' });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user