Skip to content

Commit

Permalink
Merge branch 'master' into MODBULKOPS-197
Browse files Browse the repository at this point in the history
  • Loading branch information
obozhko-folio authored Jan 8, 2024
2 parents ca89795 + d89fb6d commit dd9b10b
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 17 deletions.
15 changes: 15 additions & 0 deletions src/main/java/org/folio/bulkops/domain/bean/ContributorName.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,20 @@ public class ContributorName {

@JsonProperty("name")
private String name;

@JsonProperty("contributorTypeId")
private String contributorTypeId;

@JsonProperty("contributorTypeText")
private String contributorTypeText;

@JsonProperty("contributorNameTypeId")
private String contributorNameTypeId;

@JsonProperty("authorityId")
private String authorityId;

@JsonProperty("primary")
private Boolean primary;
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import static org.folio.bulkops.domain.dto.UpdateActionType.CLEAR_FIELD;
import static org.folio.bulkops.domain.dto.UpdateActionType.SET_TO_FALSE;
import static org.folio.bulkops.domain.dto.UpdateActionType.SET_TO_TRUE;
import static org.folio.bulkops.domain.dto.UpdateOptionType.SUPPRESS_FROM_DISCOVERY;
import static org.folio.bulkops.domain.dto.UpdateOptionType.STAFF_SUPPRESS;

import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
Expand All @@ -24,19 +24,19 @@ public class InstanceDataProcessor extends AbstractDataProcessor<Instance> {
@Override
public Validator<UpdateOptionType, Action> validator(Instance instance) {
return (option, action) -> {
if (CLEAR_FIELD.equals(action.getType()) && SUPPRESS_FROM_DISCOVERY.equals(option)) {
throw new RuleValidationException("Suppress from discovery flag cannot be cleared");
if (CLEAR_FIELD.equals(action.getType()) && STAFF_SUPPRESS.equals(option)) {
throw new RuleValidationException("Staff suppress flag cannot be cleared");
}
};
}

@Override
public Updater<Instance> updater(UpdateOptionType option, Action action) {
if (SUPPRESS_FROM_DISCOVERY.equals(option)) {
if (STAFF_SUPPRESS.equals(option)) {
if (SET_TO_TRUE.equals(action.getType())) {
return instance -> instance.setDiscoverySuppress(true);
return instance -> instance.setStaffSuppress(true);
} else if (SET_TO_FALSE.equals(action.getType())) {
return instance -> instance.setDiscoverySuppress(false);
return instance -> instance.setStaffSuppress(false);
}
}
return item -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ public String getInstanceFormatNameById(String id) {
try {
return isEmpty(id) ? EMPTY : instanceFormatsClient.getById(id).getName();
} catch (Exception e) {
throw new NotFoundException(format("Nature of content term was not found by id=%s", id));
throw new NotFoundException(format("Instance format was not found by id=%s", id));
}
}

@Cacheable(cacheNames = "instanceFormatIds")
public String getInstanceFormatIdByName(String name) {
var response = instanceFormatsClient.getByQuery(String.format(QUERY_PATTERN_NAME, encode(name)), 1);
if (response.getFormats().isEmpty()) {
throw new NotFoundException(format("Nature of content term was not found by name=%s", name));
throw new NotFoundException(format("Instance format was not found by name=%s", name));
}
return response.getFormats().get(0).getId();
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/db/changelog/changelog-master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@
<include file="changes/25-10-2023_add_notes_options_types_for_holdings.xml" relativeToChangelogFile="true"/>
<include file="changes/08-11-2023_add_electronic_access_options_types.xml" relativeToChangelogFile="true"/>
<include file="changes/27-12-2023_add_types_for_instance.xml" relativeToChangelogFile="true"/>
<include file="changes/05-01-2024_add_staff_suppress.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TYPE UpdateOptionType ADD VALUE IF NOT EXISTS 'STAFF_SUPPRESS';
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">


<changeSet id="05-01-2024_add_staff_suppress" author="firebird">
<sqlFile path="05-01-2024_add_staff_suppress.sql" relativeToChangelogFile="true" />
</changeSet>

</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"ELECTRONIC_ACCESS_URI",
"ELECTRONIC_ACCESS_LINK_TEXT",
"ELECTRONIC_ACCESS_MATERIALS_SPECIFIED",
"ELECTRONIC_ACCESS_URL_PUBLIC_NOTE"
"ELECTRONIC_ACCESS_URL_PUBLIC_NOTE",
"STAFF_SUPPRESS"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import static org.folio.bulkops.domain.dto.UpdateActionType.CLEAR_FIELD;
import static org.folio.bulkops.domain.dto.UpdateActionType.SET_TO_FALSE;
import static org.folio.bulkops.domain.dto.UpdateActionType.SET_TO_TRUE;
import static org.folio.bulkops.domain.dto.UpdateOptionType.SUPPRESS_FROM_DISCOVERY;
import static org.folio.bulkops.domain.dto.UpdateOptionType.STAFF_SUPPRESS;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -43,22 +43,22 @@ void setUp() {
}

@Test
void testSetDiscoverySuppressToTrue() {
var actual = processor.process(IDENTIFIER, new Instance(), rules(rule(SUPPRESS_FROM_DISCOVERY, SET_TO_TRUE, null)));
void testSetStaffSuppressToTrue() {
var actual = processor.process(IDENTIFIER, new Instance(), rules(rule(STAFF_SUPPRESS, SET_TO_TRUE, null)));
assertNotNull(actual.getUpdated());
assertTrue(actual.getUpdated().getDiscoverySuppress());
assertTrue(actual.getUpdated().getStaffSuppress());
}

@Test
void testSetDiscoverySuppressToFalse() {
var actual = processor.process(IDENTIFIER, new Instance(), rules(rule(SUPPRESS_FROM_DISCOVERY, SET_TO_FALSE, null)));
void testSetStaffSuppressToFalse() {
var actual = processor.process(IDENTIFIER, new Instance(), rules(rule(STAFF_SUPPRESS, SET_TO_FALSE, null)));
assertNotNull(actual.getUpdated());
assertFalse(actual.getUpdated().getDiscoverySuppress());
assertFalse(actual.getUpdated().getStaffSuppress());
}

@Test
void shouldNotUpdateInstanceWhenActionIsInvalid() {
var actual = processor.process(IDENTIFIER, new Instance().withDiscoverySuppress(true), rules(rule(SUPPRESS_FROM_DISCOVERY, CLEAR_FIELD, null)));
var actual = processor.process(IDENTIFIER, new Instance().withDiscoverySuppress(true), rules(rule(STAFF_SUPPRESS, CLEAR_FIELD, null)));
assertTrue(actual.getUpdated().getDiscoverySuppress());
verify(errorService).saveError(any(UUID.class), eq(IDENTIFIER), anyString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ void shouldConvertEntity(Class<BulkOperationsEntity> clazz) throws IOException {
.usingRecursiveComparison()
.ignoringFields("circulationNotes", "effectiveCallNumberComponents", "metadata", "status.date")
.isEqualTo(bean);
} else if (result instanceof Instance instance) {
assertThat(instance)
.usingRecursiveComparison()
.ignoringFields("version", "contributors.contributorTypeId", "contributors.contributorTypeText", "contributors.contributorNameTypeId", "contributors.authorityId", "contributors.primary")
.isEqualTo(bean);
} else {
assertEquals(bean, result);
}
Expand Down

0 comments on commit dd9b10b

Please sign in to comment.