Skip to content

Commit

Permalink
MODSOURMAN-1228: Instance date type logic added.
Browse files Browse the repository at this point in the history
  • Loading branch information
VRohach committed Oct 8, 2024
1 parent 09ebdfc commit 569011e
Show file tree
Hide file tree
Showing 8 changed files with 220 additions and 0 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@
<path>${basedir}/ramls/settings/organization_collection.json</path>
<path>${basedir}/ramls/settings/subjectSources.json</path>
<path>${basedir}/ramls/settings/subjectTypes.json</path>
<path>${basedir}/ramls/settings/instanceDateTypes.json</path>
<path>${basedir}/ramls/settings/acquisitions_unit.json</path>
<path>${basedir}/ramls/settings/acquisitions_unit_collection.json</path>
<path>${basedir}/ramls/settings/acquisition_method.json</path>
Expand Down
5 changes: 5 additions & 0 deletions ramls/instance.json
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@
"type": "object",
"description": "Instance Dates",
"properties": {
"dateTypeId": {
"type": "string",
"description": "Date type ID",
"$ref": "raml-storage/raml-util/schemas/uuid.schema"
},
"date1": {
"type": "string",
"description": "Date 1",
Expand Down
59 changes: 59 additions & 0 deletions ramls/settings/instanceDateType.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "An instance date type that indicates the type of dates given in Date 1 and Date 2",
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "Unique ID of the instance date type; a UUID",
"readonly": true
},
"name": {
"type": "string",
"description": "Name of the instance date type",
"readonly": true
},
"code": {
"type": "string",
"description": "Code of the instance date type",
"maxLength": 1,
"readonly": true
},
"displayFormat": {
"type": "object",
"description": "Describes how to format Date 1 and Date 2",
"properties": {
"delimiter": {
"type": "string",
"description": "Delimiter that will be used to format Date 1 and Date 2",
"example": ",",
"readonly": true
},
"keepDelimiter": {
"type": "boolean",
"description": "Define if formated date string should keep delimiter if one of dates is not exist",
"example": false,
"readonly": true
}
},
"readonly": true,
"additionalProperties": false
},
"source": {
"type": "string",
"description": "label indicating where the instance date type entry originates from, i.e. 'folio' or 'local'",
"enum": [
"folio",
"local"
],
"readonly": true
},
"metadata": {
"type": "object",
"$ref": "../raml-storage/raml-util/schemas/metadata.schema",
"readonly": true
}
},
"additionalProperties": false
}

19 changes: 19 additions & 0 deletions ramls/settings/instanceDateTypes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "A collection of instance date types",
"type": "object",
"properties": {
"instanceDateTypes": {
"description": "List of instance date types",
"type": "array",
"items": {
"type": "object",
"$ref": "instanceDateType.json"
}
},
"totalRecords": {
"description": "Estimated or exact total number of records",
"type": "integer"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.folio.HoldingsNoteType;
import org.folio.HoldingsType;
import org.folio.IdentifierType;
import org.folio.InstanceDateType;
import org.folio.InstanceFormat;
import org.folio.InstanceNoteType;
import org.folio.InstanceType;
Expand Down Expand Up @@ -199,6 +200,38 @@ private String concatSubFields(JsonObject ruleParameter, List<Subfield> subfield
}
},

SET_DATE_TYPE_ID() {
private static final String DEFAULT_DATE_TYPE = "No attempt to code";

@Override
public String apply(RuleExecutionContext context) {
String subFieldValue = context.getSubFieldValue();
char sixthChar = subFieldValue.charAt(6);
List<InstanceDateType> dateTypes = context.getMappingParameters().getInstanceDateTypes();
if (dateTypes == null || dateTypes.isEmpty()) {
return StringUtils.EMPTY;
}
String defaultDateTypeId = findDateTypeId(dateTypes, StringUtils.EMPTY);
return matchInstanceDateTypeViaCode(sixthChar, dateTypes, defaultDateTypeId);
}

private String findDateTypeId(List<InstanceDateType> dates, String defaultId) {
return dates.stream()
.filter(date -> date.getName().equalsIgnoreCase(DEFAULT_DATE_TYPE))
.findFirst()
.map(InstanceDateType::getId)
.orElse(defaultId);
}

private String matchInstanceDateTypeViaCode(char sixthChar, List<InstanceDateType> instanceDateTypes, String defaultId) {
return instanceDateTypes.stream()
.filter(instanceFormat -> instanceFormat.getCode().equalsIgnoreCase(String.valueOf(sixthChar)))
.findFirst()
.map(InstanceDateType::getId)
.orElse(defaultId);
}
},

SET_PUBLISHER_ROLE() {
@Override
public String apply(RuleExecutionContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.folio.HoldingsType;
import org.folio.IdentifierType;
import org.folio.IllPolicy;
import org.folio.InstanceDateType;
import org.folio.InstanceFormat;
import org.folio.InstanceNoteType;
import org.folio.InstanceRelationshipType;
Expand Down Expand Up @@ -57,6 +58,7 @@ public class MappingParameters {
private List<InstanceNoteType> instanceNoteTypes = new ArrayList<>();
private List<AlternativeTitleType> alternativeTitleTypes = new ArrayList<>();
private List<IssuanceMode> issuanceModes = new ArrayList<>();
private List<InstanceDateType> instanceDateTypes = new ArrayList<>();
private List<InstanceStatus> instanceStatuses = new ArrayList<>();
private List<NatureOfContentTerm> natureOfContentTerms = new ArrayList<>();
private List<InstanceRelationshipType> instanceRelationshipTypes = new ArrayList<>();
Expand Down Expand Up @@ -180,6 +182,15 @@ public MappingParameters withIssuanceModes(List<IssuanceMode> issuanceModes) {
return this;
}

public List<InstanceDateType> getInstanceDateTypes() {
return instanceDateTypes;
}

public MappingParameters withInstanceDateTypes(List<InstanceDateType> instanceDateTypes) {
this.instanceDateTypes = new UnmodifiableList<>(instanceDateTypes);
return this;
}

public void setInitialized(boolean initialized) {
this.initialized = initialized;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.apache.commons.lang3.StringUtils;
import org.folio.AuthorityNoteType;
import org.folio.ClassificationType;
import org.folio.InstanceDateType;
import org.folio.InstanceType;
import org.folio.ElectronicAccessRelationship;
import org.folio.InstanceFormat;
Expand Down Expand Up @@ -270,6 +271,81 @@ public void CAPITALIZE_shouldReturnExpectedResult() {
}
}

@Test
public void SET_DATE_TYPE_ID_shouldReturnExpectedResult() {
// given
String expectedInstanceDateTypeId = UUID.randomUUID().toString();
InstanceDateType firstInstanceDateType = new InstanceDateType()
.withId(UUID.randomUUID().toString())
.withName("No attempt to code")
.withCode("|");

InstanceDateType secondInstanceDateType = new InstanceDateType()
.withId(expectedInstanceDateTypeId)
.withName("Single known date/probable date")
.withCode("s");

InstanceDateType thirdInstanceDateType = new InstanceDateType()
.withId(UUID.randomUUID().toString())
.withName("Range of years of bulk of collection")
.withCode("k");

RuleExecutionContext context = new RuleExecutionContext();
context.setSubFieldValue("901214s19910101nyua");
context.setMappingParameters(new MappingParameters().withInstanceDateTypes(Arrays.asList(firstInstanceDateType, secondInstanceDateType, thirdInstanceDateType)));
// when
String actualInstanceDateTypeId = runFunction("set_date_type_id", context);
// then
assertEquals(expectedInstanceDateTypeId, actualInstanceDateTypeId);
}

@Test
public void SET_DATE_TYPE_ID_shouldReturnUnspecifiedIssuanceModeIdIfNoMatchedExists() {
// given
String expectedInstanceDateTypeId = UUID.randomUUID().toString();
InstanceDateType instanceDateType = new InstanceDateType()
.withId(expectedInstanceDateTypeId)
.withName("No attempt to code")
.withCode("|");

RuleExecutionContext context = new RuleExecutionContext();
context.setSubFieldValue("zzzzzzzzzz");
context.setMappingParameters(new MappingParameters().withInstanceDateTypes(Collections.singletonList(instanceDateType)));
// when
String actualInstanceDateTypeId = runFunction("set_date_type_id", context);
// then
assertEquals(expectedInstanceDateTypeId, actualInstanceDateTypeId);
}
@Test
public void SET_DATE_TYPE_ID_shouldReturnEmptyStringIfNoMatchedExistsAndUnspecifiedInstanceTypeIdNotExists() {
// given
String expectedInstanceDateTypeId = UUID.randomUUID().toString();
InstanceDateType instanceDateTypeId = new InstanceDateType()
.withId(expectedInstanceDateTypeId)
.withName("Detailed date")
.withCode("e");

RuleExecutionContext context = new RuleExecutionContext();
context.setSubFieldValue("zzzzzzzzzz");
context.setMappingParameters(new MappingParameters().withInstanceDateTypes(Collections.singletonList(instanceDateTypeId)));
// when
String actualInstanceDateTypeId = runFunction("set_date_type_id", context);
// then
assertEquals(StringUtils.EMPTY, actualInstanceDateTypeId);
}

@Test
public void SET_DATE_TYPE_MODE_ID_shouldReturnEmptyStringIfNoSettingsSpecified() {
// given
RuleExecutionContext context = new RuleExecutionContext();
context.setMappingParameters(new MappingParameters());
context.setSubFieldValue("901214s19910101nyua");
// when
String actualInstanceDateTypeId = runFunction("set_date_type_id", context);
// then
assertEquals(StringUtils.EMPTY, actualInstanceDateTypeId);
}

@Test
public void SET_PUBLISHER_ROLE_shouldReturnExpectedResult() {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@
}
]
},
{
"target": "dates.dateTypeId",
"description": "Date type ID",
"subfield": [],
"createSingleObject": true,
"rules": [
{
"description": "",
"conditions": [
{
"type": "set_date_type_id"
}
]
}
]
},
{
"target": "dates.date1",
"description": "Date 1",
Expand Down

0 comments on commit 569011e

Please sign in to comment.