Skip to content

Commit

Permalink
Merge branch 'nacsis-cat-ill'
Browse files Browse the repository at this point in the history
  • Loading branch information
Dor-Karni committed Dec 14, 2021
2 parents fdd1002 + bcd7960 commit 18118b6
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 64 deletions.
2 changes: 1 addition & 1 deletion cloudapp/src/app/catalog/main/main.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

<ng-template #searchResults>
<results-list [numOfResults]="numOfResults" [pageIndex]="pageIndex" [pageSize]="pageSize"
[resultsSummaryDisplay]="resultsSummaryDisplay" [resultActionList]="getActionMenu()"
[resultsSummaryDisplay]="resultsSummaryDisplay" [resultActionList]="actionMenuEnteries"
(onActionSelected)="onActionsClick($event)" (onTitleSelected)="onTitleClick($event)"
(onPageSelected)="onPageAction($event)">
</results-list>
Expand Down
47 changes: 31 additions & 16 deletions cloudapp/src/app/catalog/main/main.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,18 @@ export class CatalogMainComponent implements AfterViewInit {
[SearchType.UniformTitles, this.initUniformTitlesSearchFields()]
]);
public ACTIONS_MENU_LIST = new Map([
[SearchType.Monographs, ['Catalog.Results.Actions.View', 'Catalog.Results.Actions.Import', 'Catalog.Results.Actions.ViewHoldings']],
[SearchType.Serials, ['Catalog.Results.Actions.View', 'Catalog.Results.Actions.Import', 'Catalog.Results.Actions.ViewHoldings']],
[SearchType.Monographs, ['Catalog.Results.Actions.View', 'Catalog.Results.Actions.Import']],
[SearchType.Serials, ['Catalog.Results.Actions.View', 'Catalog.Results.Actions.Import']],
[SearchType.Names, ['Catalog.Results.Actions.View' /* , 'Catalog.Results.Actions.Import' */]],
[SearchType.UniformTitles, ['Catalog.Results.Actions.View'/* , 'Catalog.Results.Actions.Import' */]]
]);


// Selection variables
public currentSearchType: SearchType = SearchType.Monographs;
private currentDatabase: string;// = 'BOOK'; // first default selection (since opened with Monographs)
private linkSearchType: SearchType;
currentDatabase: string;// = 'BOOK'; // first default selection (since opened with Monographs)
linkSearchType: SearchType;
actionMenuEnteries: Array<string>;

// UI variables
public panelState: boolean = true;
Expand Down Expand Up @@ -216,13 +217,23 @@ export class CatalogMainComponent implements AfterViewInit {

/*** Summary View Section ***/

public getActionMenu() {
return this.ACTIONS_MENU_LIST.get(this.currentSearchType);
getActionMenu() {
let searchedDBName = this.getParamsFromSearchQuery(this.currentSearchType).get(QueryParams.Databases);
// For searches inside BOOK or SERIAL DB, return the full option
if (searchedDBName === "BOOK" || searchedDBName === "SERIAL") {
let additionalMenu = [...this.ACTIONS_MENU_LIST.get(this.currentSearchType)];
additionalMenu.push('Catalog.Results.Actions.ViewHoldings');
return additionalMenu;
} else {
return this.ACTIONS_MENU_LIST.get(this.currentSearchType);
}
}

private setSearchResultsDisplay(){
this.catalogResultsData = this.catalogService.getSearchResults(this.currentSearchType);
this.numOfResults = this.catalogResultsData.getHeader().totalRecords;
this.actionMenuEnteries = new Array();
this.actionMenuEnteries = this.getActionMenu();
this.resultsSummaryDisplay = new Array();
this.catalogResultsData.getResults()?.forEach(result=>{
this.resultsSummaryDisplay.push(result.getSummaryDisplay());
Expand Down Expand Up @@ -329,16 +340,15 @@ export class CatalogMainComponent implements AfterViewInit {
onImportRecord(rawData: string) {
this.loading = true;
try {
this.catalogService.importRecordToAlma(this.currentSearchType, rawData)
.subscribe({
this.catalogService.importRecordToAlma(this.currentSearchType, rawData).subscribe({
next: (importedRecord) => {
let mmsIdText = " (" + importedRecord.mms_id + ")";
this.alert.success(this.translate.instant('Catalog.Results.ImportSucceeded') + mmsIdText, {autoClose: false, keepAfterRouteChange:true});
},
error: e => {
this.loading = false;
console.log(e.message);
this.alert.error(e.message, {keepAfterRouteChange:true});
console.log(e);
this.alert.error(e, {keepAfterRouteChange:true});
},
complete: () => this.loading = false
});
Expand Down Expand Up @@ -372,11 +382,7 @@ export class CatalogMainComponent implements AfterViewInit {


searchFormRefill() {
let paramsMap = new Map();
this.catalogService.getQueryParams().split("&").forEach(param => {
let paramAsKeyValue = param.split("=");
paramsMap.set(paramAsKeyValue[0],paramAsKeyValue[1]);
});
let paramsMap = this.getParamsFromSearchQuery();
this.pageIndex = paramsMap.get(QueryParams.PageIndex);
this.pageSize = paramsMap.get(QueryParams.PageSize);
this.currentSearchType = SearchType[paramsMap.get(QueryParams.SearchType)];
Expand All @@ -388,6 +394,15 @@ export class CatalogMainComponent implements AfterViewInit {
});
}

getParamsFromSearchQuery(searchType?: SearchType) {
let paramsMap = new Map();
this.catalogService.getQueryParams(searchType).split("&").forEach(param => {
let paramAsKeyValue = param.split("=");
paramsMap.set(paramAsKeyValue[0],paramAsKeyValue[1]);
});
return paramsMap;
}



/*** initializing the search fields ***/
Expand Down Expand Up @@ -456,4 +471,4 @@ export enum QueryParams {
SearchType = "searchType",
Databases = "dataBase",
ID = "ID"
}
}
28 changes: 23 additions & 5 deletions cloudapp/src/app/holdings/main/main.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ export class MainComponent implements OnInit, OnDestroy {
this.loading = true;
try{
this.almaApiService.getIntegrationProfile()
.subscribe(integrationProfile => {

this.integrationProfile = integrationProfile;
.subscribe( {
next : integrationProfile => {
if(this.isEmpty(integrationProfile.libraryCode) || this.isEmpty(integrationProfile.libraryID) || this.isEmpty(integrationProfile.systemPrefix)){
this.alert.error("The integration profile for NACSIS does not exist", {keepAfterRouteChange:true});
} else {
this.integrationProfile = integrationProfile;

let rawBibs = (pageInfo.entities || []).filter(e => e.type == EntityType.BIB_MMS);
let nacsisBibs: Entity[] = [];
Expand All @@ -80,14 +83,25 @@ export class MainComponent implements OnInit, OnDestroy {
error: e => {
this.loading = false;
console.log(e.message);
//this.alert.error(e.message, {keepAfterRouteChange:true});
this.alert.error(e.message, {keepAfterRouteChange:true});
},
complete: () => {
this.loading = false;
this.bibs = nacsisBibs;
}
});
});
}

},
error: e => {
this.loading = false;
console.log(e);
this.alert.error(e, {keepAfterRouteChange:true});
},
complete: () => {
this.loading = false;
}
});
} catch(e) {
this.loading = false;
console.log(e);
Expand Down Expand Up @@ -142,5 +156,9 @@ export class MainComponent implements OnInit, OnDestroy {
onCloseClick() {
this.isErrorMessageVisible = false;
}

isEmpty(val) {
return (val === undefined || val == null || val.length <= 0) ? true : false;
}
}

50 changes: 21 additions & 29 deletions cloudapp/src/app/service/alma.api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { of } from 'rxjs';
})
export class AlmaApiService {

integrationProfile :IntegrationProfile;

constructor(
private restService: CloudAppRestService,

Expand Down Expand Up @@ -63,42 +61,36 @@ export class AlmaApiService {

let url = "/conf/integration-profiles?type=CENTRAL_CATALOG_INTEGRATION";

if(this.integrationProfile != null && this.integrationProfile != undefined) {
return of(this.integrationProfile)
}
let libraryID: string = null;
let repositoryImportProfile: string = null;
let authorityImportProfileNames: string = null;
let authorityImportProfileUniformTitles: string = null;
let integrationProfile = new IntegrationProfile();

return this.restService.call(url).pipe(
mergeMap(response => {
// extract integration profile
let nacsisIntegrationProfile = response.integration_profile[0]; // assume can be only one CENTRAL_CATALOG_INTEGRATION
libraryID = nacsisIntegrationProfile.parameter.filter(param => param.action.value == "CENTRAL_CATALOG_INFORMATION_B" && param.name.value == "nacsisLibraryId")[0].value;
// extract import profiles
let ContributionConfigurationParams = nacsisIntegrationProfile.parameter.filter(param => param.action.value == "CENTRAL_CATALOG_CONTRIBUTION_CONFIGURATION");
repositoryImportProfile = ContributionConfigurationParams.filter(param => param.name.value == "repositoryImportProfile")[0].value;
authorityImportProfileNames = ContributionConfigurationParams.filter(param => param.name.value == "authNames")[0].value;
authorityImportProfileUniformTitles = ContributionConfigurationParams.filter(param => param.name.value == "authUniformTitle")[0].value;
return of(this.integrationProfile);
try {
// extract integration profile
let nacsisIntegrationProfile = response.integration_profile[0]; // assume can be only one CENTRAL_CATALOG_INTEGRATION
integrationProfile.libraryID = nacsisIntegrationProfile.parameter.filter(param => param.action.value == "CENTRAL_CATALOG_INFORMATION_B" && param.name.value == "nacsisLibraryId")[0].value;
// extract import profiles
let contributionConfigurationParams = nacsisIntegrationProfile.parameter.filter(param => param.action.value == "CENTRAL_CATALOG_CONTRIBUTION_CONFIGURATION");
integrationProfile.repositoryImportProfile = contributionConfigurationParams.filter(param => param.name.value == "repositoryImportProfile")[0].value;
// integrationProfile.authorityImportProfileNames = ContributionConfigurationParams.filter(param => param.name.value == "authNames")[0].value;
// integrationProfile.authorityImportProfileUniformTitles = ContributionConfigurationParams.filter(param => param.name.value == "authUniformTitle")[0].value;
} catch (e) {
console.log(e);
}
return of(integrationProfile);
}),
mergeMap(() => {
url = "/almaws/v1/conf/code-tables/NacsisExternalSystemCodes";
return this.restService.call(url);
}),
mergeMap(response => {
let libraryCode = response.row.filter(row => row.code == "libraryCode")[0].description;
let systemPrefix = response.row.filter(row => row.code == "systemPrefix")[0].description;

this.integrationProfile = new IntegrationProfile();
this.integrationProfile.libraryCode = libraryCode;
this.integrationProfile.libraryID = libraryID;
this.integrationProfile.systemPrefix = systemPrefix;
this.integrationProfile.repositoryImportProfile = repositoryImportProfile;
this.integrationProfile.authorityImportProfileNames = authorityImportProfileNames;
this.integrationProfile.authorityImportProfileUniformTitles = authorityImportProfileUniformTitles;
return of(this.integrationProfile);
try {
integrationProfile.libraryCode = response.row.filter(row => row.code == "libraryCode")[0].description;
integrationProfile.systemPrefix = response.row.filter(row => row.code == "systemPrefix")[0].description;
} catch (e) {
console.log(e);
}
return of(integrationProfile);
})
);
}
Expand Down
33 changes: 20 additions & 13 deletions cloudapp/src/app/service/catalog.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { HttpClient } from "@angular/common/http";
import { CloudAppEventsService, InitData } from '@exlibris/exl-cloudapp-angular-lib';
import { CloudAppEventsService, InitData, CloudAppRestService, HttpMethod } from '@exlibris/exl-cloudapp-angular-lib';
import { BaseService, Header } from "./base.service";
import { mergeMap } from 'rxjs/operators';
import { of } from 'rxjs';
Expand Down Expand Up @@ -28,6 +28,7 @@ export class CatalogService extends BaseService {
protected eventsService: CloudAppEventsService,
protected http: HttpClient,
protected almaApi: AlmaApiService,
private restService: CloudAppRestService,
protected translate: TranslateService
) {
super(eventsService, http);
Expand Down Expand Up @@ -90,9 +91,6 @@ export class CatalogService extends BaseService {
mergeMap(authToken => {
let headers = this.setAuthHeader(authToken);
return this.http.get<any>(fullUrl, { headers })
}),
mergeMap(response => {
return of(response);
})
);
}
Expand All @@ -115,28 +113,37 @@ export class CatalogService extends BaseService {
}

importRecordToAlma(searchType: SearchType, rawData: string) {
return this.almaApi.getIntegrationProfile().pipe(
return this.almaApi.getIntegrationProfile().pipe(
mergeMap(integrationProfile => {
let factoryValues = this.integrationProfileFactory(searchType, integrationProfile);
let body = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><" + factoryValues.typeTag + "><record_format>catp</record_format><record><![CDATA[" + rawData + "]]></record></" + factoryValues.typeTag + ">";
return this.http.post<any>("/almaws/v1/bibs" + factoryValues.urlType + "?import_profile=" + factoryValues.ID, body)
}),
mergeMap(response => {
return of(response);
// return of(response.warnings, response.mms_id);
let Request = {
url: "/almaws/v1/bibs" + factoryValues.urlType + "?import_profile=" + factoryValues.ID,
method: HttpMethod.POST,
requestBody: body
};
return this.restService.call(Request);
})
);
}
);
}

integrationProfileFactory(searchType: SearchType, integrationProfile: IntegrationProfile) {
switch(searchType) {
case (SearchType.Monographs):
return { typeTag: "bib", urlType: "", ID: integrationProfile.repositoryImportProfile };
case (SearchType.Serials):
if(this.isEmpty(integrationProfile.repositoryImportProfile)){
throw "The Repository Import Profile is not configured correctly";
}
return { typeTag: "bib", urlType: "", ID: integrationProfile.repositoryImportProfile };
case (SearchType.Names):
if(this.isEmpty(integrationProfile.authorityImportProfileNames)){
throw "The Authority Import Profile Names is not configured correctly";
}
return { typeTag: "authority", urlType: "/authorities", ID: integrationProfile.authorityImportProfileNames };
case (SearchType.UniformTitles):
if(this.isEmpty(integrationProfile.authorityImportProfileUniformTitles)){
throw "The Authority Import Profile Uniform Titles is not configured correctly";
}
return { typeTag: "authority", urlType: "/authorities", ID: integrationProfile.authorityImportProfileUniformTitles};
}
}
Expand Down

0 comments on commit 18118b6

Please sign in to comment.