Skip to content

Commit

Permalink
[DURACOM-247] Refactored by using a map of promises
Browse files Browse the repository at this point in the history
  • Loading branch information
atarix83 committed Apr 8, 2024
1 parent 115445a commit 883ceea
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/app/core/cache/builders/link.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
take,
} from 'rxjs/operators';

import { APP_DATA_SERVICES_MAP } from '../../../../config/app-config.interface';
import { APP_DATA_SERVICES_MAP, LazyDataServicesMap } from '../../../../config/app-config.interface';

Check failure on line 8 in src/app/core/cache/builders/link.service.spec.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

Imports must be broken into multiple lines if there are more than 1 elements

Check failure on line 8 in src/app/core/cache/builders/link.service.spec.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

'LazyDataServicesMap' is defined but never used

Check failure on line 8 in src/app/core/cache/builders/link.service.spec.ts

View workflow job for this annotation

GitHub Actions / tests (20.x)

Imports must be broken into multiple lines if there are more than 1 elements

Check failure on line 8 in src/app/core/cache/builders/link.service.spec.ts

View workflow job for this annotation

GitHub Actions / tests (20.x)

'LazyDataServicesMap' is defined but never used
import { TestDataService } from '../../../shared/testing/test-data-service.mock';
import { followLink } from '../../../shared/utils/follow-link-config.model';
import { HALLink } from '../../shared/hal-link.model';
Expand Down Expand Up @@ -37,9 +37,9 @@ class TestModel implements HALResource {
successor?: TestModel;
}

const mockDataServiceMap: any = {
[TEST_MODEL.value]: () => import('../../../shared/testing/test-data-service.mock').then(m => m.TestDataService),
};
const mockDataServiceMap: any = new Map([
[TEST_MODEL.value, () => import('../../../shared/testing/test-data-service.mock').then(m => m.TestDataService)],
]);

let testDataService: TestDataService;

Expand Down
72 changes: 70 additions & 2 deletions src/app/core/data-services-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,75 @@ import { CLAIMED_TASK } from './tasks/models/claimed-task-object.resource-type';
import { POOL_TASK } from './tasks/models/pool-task-object.resource-type';
import { WORKFLOW_ACTION } from './tasks/models/workflow-action-object.resource-type';

export const LAZY_DATA_SERVICES: LazyDataServicesMap = {
export const LAZY_DATA_SERVICES: LazyDataServicesMap = new Map([
[AUTHORIZATION.value, () => import('./data/feature-authorization/authorization-data.service').then(m => m.AuthorizationDataService)],
[BROWSE_DEFINITION.value, () => import('./browse/browse-definition-data.service').then(m => m.BrowseDefinitionDataService)],
[BULK_ACCESS_CONDITION_OPTIONS.value, () => import('./config/bulk-access-config-data.service').then(m => m.BulkAccessConfigDataService)],
[METADATA_SCHEMA.value, () => import('./data/metadata-schema-data.service').then(m => m.MetadataSchemaDataService)],
[SUBMISSION_UPLOADS_TYPE.value, () => import('./config/submission-uploads-config-data.service').then(m => m.SubmissionUploadsConfigDataService)],
[BITSTREAM.value, () => import('./data/bitstream-data.service').then(m => m.BitstreamDataService)],
[SUBMISSION_ACCESSES_TYPE.value, () => import('./config/submission-accesses-config-data.service').then(m => m.SubmissionAccessesConfigDataService)],
[SYSTEMWIDEALERT.value, () => import('./data/system-wide-alert-data.service').then(m => m.SystemWideAlertDataService)],
[USAGE_REPORT.value, () => import('./statistics/usage-report-data.service').then(m => m.UsageReportDataService)],
[ACCESS_STATUS.value, () => import('./data/access-status-data.service').then(m => m.AccessStatusDataService)],
[COLLECTION.value, () => import('./data/collection-data.service').then(m => m.CollectionDataService)],
[CLAIMED_TASK.value, () => import('./tasks/claimed-task-data.service').then(m => m.ClaimedTaskDataService)],
[VOCABULARY_ENTRY.value, () => import('./data/href-only-data.service').then(m => m.HrefOnlyDataService)],
[ITEM_TYPE.value, () => import('./data/href-only-data.service').then(m => m.HrefOnlyDataService)],
[LICENSE.value, () => import('./data/href-only-data.service').then(m => m.HrefOnlyDataService)],
[SUBSCRIPTION.value, () => import('../shared/subscriptions/subscriptions-data.service').then(m => m.SubscriptionsDataService)],
[COMMUNITY.value, () => import('./data/community-data.service').then(m => m.CommunityDataService)],
[VOCABULARY.value, () => import('./submission/vocabularies/vocabulary.data.service').then(m => m.VocabularyDataService)],
[BUNDLE.value, () => import('./data/bundle-data.service').then(m => m.BundleDataService)],
[CONFIG_PROPERTY.value, () => import('./data/configuration-data.service').then(m => m.ConfigurationDataService)],
[POOL_TASK.value, () => import('./tasks/pool-task-data.service').then(m => m.PoolTaskDataService)],
[CLAIMED_TASK.value, () => import('./tasks/claimed-task-data.service').then(m => m.ClaimedTaskDataService)],
[SUPERVISION_ORDER.value, () => import('./supervision-order/supervision-order-data.service').then(m => m.SupervisionOrderDataService)],
[WORKSPACEITEM.value, () => import('./submission/workspaceitem-data.service').then(m => m.WorkspaceitemDataService)],
[WORKFLOWITEM.value, () => import('./submission/workflowitem-data.service').then(m => m.WorkflowItemDataService)],
[VOCABULARY.value, () => import('./submission/vocabularies/vocabulary.data.service').then(m => m.VocabularyDataService)],
[VOCABULARY_ENTRY_DETAIL.value, () => import('./submission/vocabularies/vocabulary-entry-details.data.service').then(m => m.VocabularyEntryDetailsDataService)],
[SUBMISSION_CC_LICENSE_URL.value, () => import('./submission/submission-cc-license-url-data.service').then(m => m.SubmissionCcLicenseUrlDataService)],
[SUBMISSION_CC_LICENSE.value, () => import('./submission/submission-cc-license-data.service').then(m => m.SubmissionCcLicenseDataService)],
[USAGE_REPORT.value, () => import('./statistics/usage-report-data.service').then(m => m.UsageReportDataService)],
[RESOURCE_POLICY.value, () => import('./resource-policy/resource-policy-data.service').then(m => m.ResourcePolicyDataService)],
[RESEARCHER_PROFILE.value, () => import('./profile/researcher-profile-data.service').then(m => m.ResearcherProfileDataService)],
[ORCID_QUEUE.value, () => import('./orcid/orcid-queue-data.service').then(m => m.OrcidQueueDataService)],
[ORCID_HISTORY.value, () => import('./orcid/orcid-history-data.service').then(m => m.OrcidHistoryDataService)],
[FEEDBACK.value, () => import('./feedback/feedback-data.service').then(m => m.FeedbackDataService)],
[GROUP.value, () => import('./eperson/group-data.service').then(m => m.GroupDataService)],
[EPERSON.value, () => import('./eperson/eperson-data.service').then(m => m.EPersonDataService)],
[WORKFLOW_ACTION.value, () => import('./data/workflow-action-data.service').then(m => m.WorkflowActionDataService)],
[VERSION_HISTORY.value, () => import('./data/version-history-data.service').then(m => m.VersionHistoryDataService)],
[SITE.value, () => import('./data/site-data.service').then(m => m.SiteDataService)],
[ROOT.value, () => import('./data/root-data.service').then(m => m.RootDataService)],
[RELATIONSHIP_TYPE.value, () => import('./data/relationship-type-data.service').then(m => m.RelationshipTypeDataService)],
[RELATIONSHIP.value, () => import('./data/relationship-data.service').then(m => m.RelationshipDataService)],
[SCRIPT.value, () => import('./data/processes/script-data.service').then(m => m.ScriptDataService)],
[PROCESS.value, () => import('./data/processes/process-data.service').then(m => m.ProcessDataService)],
[METADATA_FIELD.value, () => import('./data/metadata-field-data.service').then(m => m.MetadataFieldDataService)],
[ITEM.value, () => import('./data/item-data.service').then(m => m.ItemDataService)],
[VERSION.value, () => import('./data/version-data.service').then(m => m.VersionDataService)],
[IDENTIFIERS.value, () => import('./data/identifier-data.service').then(m => m.IdentifierDataService)],
[FEATURE.value, () => import('./data/feature-authorization/authorization-data.service').then(m => m.AuthorizationDataService)],
[DSPACE_OBJECT.value, () => import('./data/dspace-object-data.service').then(m => m.DSpaceObjectDataService)],
[BITSTREAM_FORMAT.value, () => import('./data/bitstream-format-data.service').then(m => m.BitstreamFormatDataService)],
[SUBMISSION_COAR_NOTIFY_CONFIG.value, () => import('../submission/sections/section-coar-notify/coar-notify-config-data.service').then(m => m.CoarNotifyConfigDataService)],
[LDN_SERVICE_CONSTRAINT_FILTERS.value, () => import('../admin/admin-ldn-services/ldn-services-data/ldn-itemfilters-data.service').then(m => m.LdnItemfiltersService)],
[LDN_SERVICE.value, () => import('../admin/admin-ldn-services/ldn-services-data/ldn-services-data.service').then(m => m.LdnServicesService)],
[ADMIN_NOTIFY_MESSAGE.value, () => import('../admin/admin-notify-dashboard/services/admin-notify-messages.service').then(m => m.AdminNotifyMessagesService)],
[SUBMISSION_FORMS_TYPE.value, () => import('./config/submission-forms-config-data.service').then(m => m.SubmissionFormsConfigDataService)],
[NOTIFYREQUEST.value, () => import('./data/notify-services-status-data.service').then(m => m.NotifyRequestsStatusDataService)],
[QUALITY_ASSURANCE_EVENT_OBJECT.value, () => import('./notifications/qa/events/quality-assurance-event-data.service').then(m => m.QualityAssuranceEventDataService)],
[QUALITY_ASSURANCE_SOURCE_OBJECT.value, () => import('./notifications/qa/source/quality-assurance-source-data.service').then(m => m.QualityAssuranceSourceDataService)],
[QUALITY_ASSURANCE_TOPIC_OBJECT.value, () => import('./notifications/qa/topics/quality-assurance-topic-data.service').then(m => m.QualityAssuranceTopicDataService)],
[SUGGESTION.value, () => import('./notifications/suggestions-data.service').then(m => m.SuggestionsDataService)],
[SUGGESTION_SOURCE.value, () => import('./notifications/source/suggestion-source-data.service').then(m => m.SuggestionSourceDataService)],
[SUGGESTION_TARGET.value, () => import('./notifications/target/suggestion-target-data.service').then(m => m.SuggestionTargetDataService)],
[DUPLICATE.value, () => import('./submission/submission-duplicate-data.service').then(m => m.SubmissionDuplicateDataService)],
[CorrectionType.type.value, () => import('./submission/correctiontype-data.service').then(m => m.CorrectionTypeDataService)],
]);
/*export const LAZY_DATA_SERVICES: LazyDataServicesMap = {
[AUTHORIZATION.value]: () => import('./data/feature-authorization/authorization-data.service').then(m => m.AuthorizationDataService),
[BROWSE_DEFINITION.value]: () => import('./browse/browse-definition-data.service').then(m => m.BrowseDefinitionDataService),
[BULK_ACCESS_CONDITION_OPTIONS.value]: () => import('./config/bulk-access-config-data.service').then(m => m.BulkAccessConfigDataService),
Expand Down Expand Up @@ -136,6 +204,6 @@ export const LAZY_DATA_SERVICES: LazyDataServicesMap = {
[SUGGESTION_TARGET.value]: () => import('./notifications/target/suggestion-target-data.service').then(m => m.SuggestionTargetDataService),
[DUPLICATE.value]: () => import('./submission/submission-duplicate-data.service').then(m => m.SubmissionDuplicateDataService),
[CorrectionType.type.value]: () => import('./submission/correctiontype-data.service').then(m => m.CorrectionTypeDataService),
};
};*/


9 changes: 4 additions & 5 deletions src/app/core/lazy-data-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import {
} from 'rxjs';

import { LazyDataServicesMap } from '../../config/app-config.interface';
import { isNotEmpty } from '../shared/empty.util';
import { HALDataService } from './data/base/hal-data-service.interface';

/**
* Loads a service lazily. The service is loaded when the observable is subscribed to.
*
* @param map A map of promises returning the data services to load
* @param dataServicesMap A map of promises returning the data services to load
* @param key The key of the service
* @param injector The injector to use to load the service. If not provided, the current injector is used.
* @returns An observable of the service.
Expand All @@ -27,13 +26,13 @@ import { HALDataService } from './data/base/hal-data-service.interface';
* ```
*/
export function lazyDataService<T>(
map: LazyDataServicesMap,
dataServicesMap: LazyDataServicesMap,
key: string,
injector: Injector,
): Observable<T> {
return defer(() => {
if (isNotEmpty(map[key]) && typeof map[key] === 'function') {
const loader: () => Promise<Type<HALDataService<any>> | { default: HALDataService<any> }> = map[key];
if (dataServicesMap.has(key) && typeof dataServicesMap.get(key) === 'function') {
const loader: () => Promise<Type<HALDataService<any>> | { default: HALDataService<any> }> = dataServicesMap.get(key);
return loader()
.then((serviceOrDefault) => {
if ('default' in serviceOrDefault) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ const REINSTATE_BTN = 'reinstate';
const SAVE_BTN = 'save';
const DISCARD_BTN = 'discard';

const mockDataServiceMap: any = {
[ITEM.value]: () => import('../../shared/testing/test-data-service.mock').then(m => m.TestDataService),
};
const mockDataServiceMap: any = new Map([
[ITEM.value, () => import('../../shared/testing/test-data-service.mock').then(m => m.TestDataService)],
]);

describe('DsoEditMetadataComponent', () => {
let component: DsoEditMetadataComponent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import { cold } from 'jasmine-marbles';
import uniqueId from 'lodash/uniqueId';
import { of as observableOf } from 'rxjs';

import { APP_DATA_SERVICES_MAP } from '../../../config/app-config.interface';
import {
APP_DATA_SERVICES_MAP,
LazyDataServicesMap,
} from '../../../config/app-config.interface';
import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
import { buildPaginatedList } from '../../core/data/paginated-list.model';
import { RequestService } from '../../core/data/request.service';
Expand All @@ -41,10 +44,10 @@ import { SearchEvent } from './eperson-group-list-event-type';
import { EpersonSearchBoxComponent } from './eperson-search-box/eperson-search-box.component';
import { GroupSearchBoxComponent } from './group-search-box/group-search-box.component';

const mockDataServiceMap: any = {
[EPERSON.value]: () => import('../../core/eperson/eperson-data.service').then(m => m.EPersonDataService),
[GROUP.value]: () => import('../../core/eperson/group-data.service').then(m => m.GroupDataService),
};
const mockDataServiceMap: LazyDataServicesMap = new Map([
[EPERSON.value, () => import('../../core/eperson/eperson-data.service').then(m => m.EPersonDataService)],
[GROUP.value, () => import('../../core/eperson/group-data.service').then(m => m.GroupDataService)],
]);

describe('EpersonGroupListComponent test suite', () => {
let comp: EpersonGroupListComponent;
Expand Down
4 changes: 1 addition & 3 deletions src/config/app-config.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ const APP_CONFIG = new InjectionToken<AppConfig>('APP_CONFIG');

const APP_CONFIG_STATE = makeStateKey<AppConfig>('APP_CONFIG_STATE');

export interface LazyDataServicesMap {
[type: string]: () => Promise<Type<HALDataService<any>> | { default: HALDataService<any> }>
}
export type LazyDataServicesMap = Map<string, () => Promise<Type<HALDataService<any>> | { default: HALDataService<any> }>>;

export const APP_DATA_SERVICES_MAP: InjectionToken<LazyDataServicesMap> = new InjectionToken<LazyDataServicesMap>('APP_DATA_SERVICES_MAP');

Expand Down

0 comments on commit 883ceea

Please sign in to comment.