Skip to content

Commit

Permalink
Serialze create items due to bug in concurrent item creation
Browse files Browse the repository at this point in the history
  • Loading branch information
jweisman committed Jun 23, 2020
1 parent 457bd04 commit 7e46898
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
7 changes: 4 additions & 3 deletions cloudapp/src/app/item/item.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ActivatedRoute } from '@angular/router';
import { CloudAppRestService, FormGroupUtil } from '@exlibris/exl-cloudapp-angular-lib';
import { tap, switchMap, finalize } from 'rxjs/operators';
import { FormGroup, FormArray, FormControl } from '@angular/forms';
import { Item, ItemData } from '../models/item';
import { Item } from '../models/item';
import { Location, ReceivingResponse } from '../models/location';
import { xmlToFields } from '../models/marc-utils';
import { forkJoin } from 'rxjs';
Expand Down Expand Up @@ -42,21 +42,23 @@ export class ItemComponent implements OnInit {
this.restService.call('/conf/code-tables/ItemPolicy')
])
.pipe(
/* Get PO Line and Itme Policy code table */
tap(([poline, codeTable])=>{
this.itemPolicies =
codeTable.row.map(
row=>({code: row.code, description: row.description})
);
this.poline=poline;
}),
/* Get holdings and last item */
switchMap(([poline])=>forkJoin([
this.restService.call(`/bibs/${poline.resource_metadata.mms_id.value}/holdings/ALL/items?order_by=description&limit=2`),
this.restService.call(`/bibs/${poline.resource_metadata.mms_id.value}/holdings`)
])),
finalize(()=>this.loading=false)
)
.subscribe(([items, holdings])=>{
if (items.item.length > 0) this.lastItem = items.item[0] as Item;
if (items.item && items.item.length > 0) this.lastItem = items.item[0] as Item;
this.holdings = holdings.holding;
const locationsForm = FormGroupUtil.toFormGroup(new Location());
locationsForm.setValidators(this.validateLocation);
Expand Down Expand Up @@ -107,7 +109,6 @@ export class ItemComponent implements OnInit {
this.poline.resource_metadata.mms_id.value,
this.poline.number
);
console.log('results', results);
response.locations.push(results)
}
this.loading = false;
Expand Down
1 change: 0 additions & 1 deletion cloudapp/src/app/main/main.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export class MainComponent implements OnInit, OnDestroy {
.pipe( finalize(()=>this.loading=false) )
.subscribe(
results => {
console.log('results', results);
this.searchResults = results.total_record_count;
this.entities=(results.po_line || []).map(p=>({
id: p.number,
Expand Down
37 changes: 19 additions & 18 deletions cloudapp/src/app/models/receiving.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Injectable } from '@angular/core';
import { CloudAppRestService, HttpMethod } from '@exlibris/exl-cloudapp-angular-lib';
import { Item } from './item';
import { Location, ReceivingLocationResponse } from './location';
import { Observable, forkJoin, iif, of } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { iif, of, from } from 'rxjs';
import { map, switchMap, concatMap, toArray } from 'rxjs/operators';
import { Utils } from './utilities';
import { replaceFields } from './marc-utils';

Expand All @@ -21,27 +21,27 @@ export class ReceivingService {
* For each location
* Combine item data with holding ID & policy
* Create POST request for each item
* ForkJoin
* Create items (serially due to concurrency bug in Alma [URM-132010])
* Update holdings record (remove summaries and add)
* Report back
*/
return new Promise(resolve => {
let items = new Array<Observable<any>>();
let items = [];
let response: ReceivingLocationResponse;
for (let i = 0; i < location.copies.quantity; i++) {
items.push(
this.createItem(
itemTemplate,
location.holdingId,
polNumber,
location.copies.provideBarcodes
? location.copies.barcodes[i]
: null,
location.policy
)
)
items.push({
item: itemTemplate,
holdingId: location.holdingId,
polNumber: polNumber,
barcode: location.copies.provideBarcodes
? location.copies.barcodes[i]
: null,
policy: location.policy
})
}
forkJoin(items).pipe(
from(items).pipe(
concatMap(item=>this.createItem(item)),
toArray(),
map(results => {
response = {
description: location.holdingId,
Expand Down Expand Up @@ -84,7 +84,8 @@ export class ReceivingService {
)
}

private createItem(item: Item, holdingId: string, polNumber: string, barcode: string = "", policy: string = "" ) {
private createItem(params: {item: Item, holdingId: string, polNumber: string, barcode: string, policy: string }) {
const { item, holdingId, polNumber, barcode, policy } = params;
item.holding_data.holding_id = holdingId;
item.item_data.barcode = barcode;
item.item_data.policy.value = policy;
Expand All @@ -95,4 +96,4 @@ export class ReceivingService {
requestBody: item
}))
}
}
}

0 comments on commit 7e46898

Please sign in to comment.