Skip to content

Commit

Permalink
Merge branch 'SCC-3731/item-table-model' of github.com:NYPL/research-…
Browse files Browse the repository at this point in the history
…catalog into SCC-3731/item-table-model
  • Loading branch information
dgcohen committed Nov 7, 2023
2 parents d3e7486 + d45c251 commit 72195aa
Show file tree
Hide file tree
Showing 10 changed files with 431 additions and 44 deletions.
283 changes: 283 additions & 0 deletions __test__/fixtures/itemFixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,283 @@
export const itemPhysicallyRequestable = {
"@id": "res:i10572545",
"@type": ["bf:Item"],
accessMessage: [
{
"@id": "accessMessage:1",
prefLabel: "Use in library",
},
],
aeonUrl: [
"https://specialcollections.nypl.org/aeon/Aeon.dll?Action=10&Form=30&Title=Spaghetti+westerns.&Site=LPAMRAMI&CallNumber=*LDC+14245&ItemPlace=[New+York?]+:&ItemPublisher=DRG+Records+Inc.,&Date=p1995.&ItemInfo3=https://catalog.nypl.org/record=b19028235&ReferenceNumber=b190282356&ItemInfo1=USE+IN+LIBRARY&ItemNumber=33433085319782&ItemISxN=i265238791&Genre=Music+CD&Location=Performing+Arts+Music+Division",
],
catalogItemType: [
{
"@id": "catalogItemType:55",
prefLabel: "book, limited circ, MaRLI",
},
],
eddRequestable: false,
enumerationChronology: ["no. 4 (2001)"],
formatLiteral: ["Text"],
holdingLocation: [
{
"@id": "loc:mal82",
prefLabel: "Schwarzman Building - Main Reading Room 315",
},
],
idBarcode: ["33433090622188"],
identifier: [
{
"@type": "bf:ShelfMark",
"@value": "D-11 2906",
},
{
"@type": "bf:Barcode",
"@value": "33433090622188",
},
],
owner: [
{
"@id": "orgs:1101",
prefLabel: "General Research Division",
},
],
physRequestable: true,
physicalLocation: ["D-11 2906"],
requestable: [true],
shelfMark: ["D-11 2906"],
specRequestable: false,
status: [
{
"@id": "status:a",
prefLabel: "Available",
},
],
uri: "i10572545",
idNyplSourceId: {
"@type": "SierraNypl",
"@value": "10572545",
},
}

export const itemEddRequestable = {
"@id": "res:i15550040",
accessMessage: [
{
"@id": "accessMessage:2",
prefLabel: "Request in advance",
},
],
catalogItemType: [
{
"@id": "catalogItemType:55",
prefLabel: "book, limited circ, MaRLI",
},
],
eddRequestable: true,
holdingLocation: [
{
"@id": "loc:rc2ma",
prefLabel: "Offsite",
},
],
idBarcode: ["33433073236758"],
identifier: [
{
"@type": "bf:ShelfMark",
"@value": "JFC 06-438",
},
{
"@type": "bf:Barcode",
"@value": "33433073236758",
},
],
owner: [
{
"@id": "orgs:1000",
prefLabel: "Stephen A. Schwarzman Building",
},
],
physRequestable: false,
physicalLocation: ["JFC 06-438"],
recapCustomerCode: ["NA"],
requestable: [true],
shelfMark: ["JFC 06-438"],
specRequestable: false,
status: [
{
"@id": "status:a",
prefLabel: "Available",
},
],
uri: "i15550040",
idNyplSourceId: {
"@type": "SierraNypl",
"@value": "15550040",
},
}

export const itemUnavailable = {
"@id": "res:i17193499",
"@type": ["bf:Item"],
accessMessage: [
{
"@id": "accessMessage:4",
prefLabel: "Restricted use",
},
],
aeonUrl: [
"https://specialcollections.nypl.org/aeon/Aeon.dll?Action=10&Form=30&Title=On+top+of+spaghetti+[videorecording];The+Paper+Bag+Players+[present]+written,+designed,+choreographed+and+directed+by+Judith+Martin+video+produced+and+directed+by+Mary+Lou+Teel.&Site=LPATF&CallNumber=NCOV+2803&ItemPlace=Tarrytown,+N.Y.,&Date=c1996.&ItemInfo3=https://catalog.nypl.org/record=b15976955&ReferenceNumber=b159769553&ItemInfo1=RESTRICTED+USE&ItemInfo2=Restricted+to+qualified+researchers.&ItemISxN=i171934994&Genre=VHS&Location=Library+for+the+Performing+Arts+Theatre+on+Film+and+Tape+Archive",
],
catalogItemType: [
{
"@id": "catalogItemType:24",
prefLabel: "archival video recording",
},
],
eddRequestable: false,
formatLiteral: ["Moving image"],
holdingLocation: [
{
"@id": "loc:paf28",
prefLabel: "Performing Arts Research Collections - TOFT",
},
],
identifier: [
{
"@type": "bf:ShelfMark",
"@value": "NCOV 2803",
},
],
physRequestable: false,
physicalLocation: ["NCOV 2803"],
requestable: [true],
shelfMark: ["NCOV 2803"],
specRequestable: true,
status: [
{
"@id": "status:k",
prefLabel: "Check with staff",
},
],
uri: "i17193499",
idNyplSourceId: {
"@type": "SierraNypl",
"@value": "17193499",
},
}

export const itemNonNYPLReCAP = {
"@id": "res:ci1628993",
accessMessage: [
{
"@id": "accessMessage:2",
prefLabel: "Request in advance",
},
],
catalogItemType: [
{
"@id": "catalogItemType:1",
prefLabel: "non-circ",
},
],
eddRequestable: true,
idBarcode: ["CU63051249"],
identifier: [
{
"@type": "bf:ShelfMark",
"@value": "PT2676.L395 L3 1992g",
},
{
"@type": "bf:Barcode",
"@value": "CU63051249",
},
],
owner: [
{
"@id": "orgs:0002",
prefLabel: "Columbia University Libraries",
},
],
physRequestable: true,
physicalLocation: ["PT2676.L395 L3 1992g"],
recapCustomerCode: ["CU"],
requestable: [true],
shelfMark: ["PT2676.L395 L3 1992g"],
specRequestable: false,
status: [
{
"@id": "status:a",
prefLabel: "Available",
},
],
uri: "ci1628993",
idNyplSourceId: {
"@type": "RecapCul",
"@value": "1628993",
},
}

export const itemNYPLReCAP = {
"@id": "res:i10572546",
"@type": ["bf:Item"],
accessMessage: [
{
"@id": "accessMessage:2",
prefLabel: "Request in advance",
},
],
catalogItemType: [
{
"@id": "catalogItemType:55",
prefLabel: "book, limited circ, MaRLI",
},
],
eddRequestable: true,
formatLiteral: ["Text"],
holdingLocation: [
{
"@id": "loc:rc2ma",
prefLabel: "Offsite",
},
],
idBarcode: ["33433077546822"],
identifier: [
{
"@type": "bf:ShelfMark",
"@value":
"VTI (Prezzolini, G. History of spaghetti eating and cooking for: spaghetti dinner)",
},
{
"@type": "bf:Barcode",
"@value": "33433077546822",
},
],
owner: [
{
"@id": "orgs:1000",
prefLabel: "Stephen A. Schwarzman Building",
},
],
physRequestable: true,
physicalLocation: [
"VTI (Prezzolini, G. History of spaghetti eating and cooking for: spaghetti dinner)",
],
recapCustomerCode: ["NA"],
requestable: [true],
shelfMark: [
"VTI (Prezzolini, G. History of spaghetti eating and cooking for: spaghetti dinner)",
],
specRequestable: false,
status: [
{
"@id": "status:a",
prefLabel: "Available",
},
],
uri: "i10572546",
idNyplSourceId: {
"@type": "SierraNypl",
"@value": "10572546",
},
}
2 changes: 0 additions & 2 deletions pages/search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ export default function Search({ results }) {

// Map Search Results Elements from response to SearchResultBib objects
const searchResultBibs = mapElementsToSearchResultsBibs(searchResultsElements)
console.log(searchResultsElements)
console.log(searchResultBibs)

// Map DRB Works from response to DRBResult objects
const drbResults = mapWorksToDRBResults(drbWorks)
Expand Down
35 changes: 13 additions & 22 deletions src/models/Item.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { isEmpty } from "underscore"

import type {
SearchResultsItem,
ItemStatus,
JSONLDValue,
ItemLocation,
} from "../types/itemTypes"
import { locationLabelToKey } from "../utils/itemUtils"
import type SearchResultsBib from "./SearchResultsBib"
import {
itemAvailabilityKeys,
itemAvailableIds,
defaultNYPLLocation,
nonNYPLReCAPLocation,
locationLabelToKey,
nonNYPLDefaultLocation,
locationEndpointsMap,
} from "../utils/itemUtils"

Expand All @@ -22,11 +20,10 @@ import {
export default class Item {
id: string
bibId: string
status?: ItemStatus
status?: JSONLDValue
source?: string
accessMessage?: string
callNumber?: string
isElectronicResource: boolean
volume?: string
format?: string
barcode?: string
Expand All @@ -36,15 +33,14 @@ export default class Item {
isEDDRequestable: boolean

constructor(item: SearchResultsItem, bib: SearchResultsBib) {
this.id = item["@id"] ? item["@id"].substring(4) : ""
this.id = item.uri || ""
this.bibId = bib.id
this.status = item.status?.length ? item.status[0] : null
this.source = item.idNyplSourceId ? item.idNyplSourceId["@type"] : null
this.accessMessage = item.accessMessage?.length
? item.accessMessage[0]?.prefLabel
: ""
this.callNumber = item.shelfMark.length ? item.shelfMark[0] : null
this.isElectronicResource = !!item.electronicLocator?.length
this.volume = item.enumerationChronology?.length
? item.enumerationChronology[0]
: null
Expand All @@ -53,29 +49,24 @@ export default class Item {
: bib.materialType
this.barcode = item.idBarcode?.length ? item.idBarcode[0] : null
this.location = this.getLocationFromItem(item)
this.aeonUrl = item.aeonUrl
this.aeonUrl = item.aeonUrl?.length ? item.aeonUrl[0] : null
this.isPhysicallyRequestable = item.physRequestable
this.isEDDRequestable = item.eddRequestable
}

// Item availability is determined by the existence of status label in the availability keys list
// Item availability is determined by the existence of status id in the availability ids list
get isAvailable(): boolean {
// Lowercase and remove non-word characters from status label
const availability =
!isEmpty(this.status) && this.status?.prefLabel
? this.status.prefLabel.replace(/\W/g, "").toLowerCase()
: ""
return itemAvailabilityKeys.includes(availability)
return itemAvailableIds.includes(this.status["@id"])
}

get isReCAP(): boolean {
return this.isNonNYPLReCAP() || this.isNYPLReCAP()
return this.isPartnerReCAP() || this.isNYPLReCAP()
}

// Pre-processing logic for setting Item holding location
getLocationFromItem(item: SearchResultsItem): ItemLocation {
let location = defaultNYPLLocation
if (this.isNonNYPLReCAP) location = nonNYPLReCAPLocation
if (this.isPartnerReCAP) location = nonNYPLDefaultLocation

// Check for existence of Location object in API response
const itemLocationFromAPI = item.holdingLocation?.length
Expand All @@ -95,7 +86,7 @@ export default class Item {
}

// Determine if item is Non-NYPL ReCAP by existence of "Recap" string in item source attribute
isNonNYPLReCAP(): boolean {
isPartnerReCAP(): boolean {
return this.source.indexOf("Recap") !== -1
}

Expand All @@ -105,7 +96,7 @@ export default class Item {
}

// It's non-ReCAP NYPL-owned item if item source is Sierra and location is not ReCAP
isNYPLNonReCAP(): boolean {
isOnsite(): boolean {
return this.isSierraItem() && !this.locationIsReCAP()
}

Expand Down
Loading

0 comments on commit 72195aa

Please sign in to comment.