-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into MODBULKOPS-149
- Loading branch information
Showing
11 changed files
with
432 additions
and
30 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
src/main/java/org/folio/bulkops/domain/bean/ElectronicAccessEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.folio.bulkops.domain.bean; | ||
|
||
import java.util.List; | ||
|
||
public interface ElectronicAccessEntity { | ||
List<ElectronicAccess> getElectronicAccess(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
src/main/java/org/folio/bulkops/processor/ElectronicAccessUpdaterFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package org.folio.bulkops.processor; | ||
|
||
import static java.lang.String.format; | ||
import static java.util.Objects.isNull; | ||
import static java.util.Optional.ofNullable; | ||
import static org.apache.commons.lang3.StringUtils.EMPTY; | ||
import static org.apache.commons.lang3.StringUtils.equalsIgnoreCase; | ||
|
||
import org.folio.bulkops.domain.bean.ElectronicAccessEntity; | ||
import org.folio.bulkops.domain.dto.Action; | ||
import org.folio.bulkops.domain.dto.UpdateOptionType; | ||
import org.folio.bulkops.exception.BulkOperationException; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Objects; | ||
|
||
@Component | ||
public class ElectronicAccessUpdaterFactory { | ||
public Updater<? extends ElectronicAccessEntity> updater(UpdateOptionType option, Action action) { | ||
return switch (option) { | ||
case ELECTRONIC_ACCESS_URL_RELATIONSHIP -> updateUrlRelationship(option, action); | ||
case ELECTRONIC_ACCESS_URI -> updateUri(option, action); | ||
case ELECTRONIC_ACCESS_LINK_TEXT -> updateLinkText(option, action); | ||
case ELECTRONIC_ACCESS_MATERIALS_SPECIFIED -> updateMaterialsSpecified(option, action); | ||
case ELECTRONIC_ACCESS_URL_PUBLIC_NOTE -> updatePublicNote(option, action); | ||
default -> notSupported(option, action); | ||
}; | ||
} | ||
|
||
private Updater<? extends ElectronicAccessEntity> updateUrlRelationship(UpdateOptionType option, Action action) { | ||
return switch (action.getType()) { | ||
case CLEAR_FIELD -> electronicAccessEntity -> ofNullable(electronicAccessEntity.getElectronicAccess()) | ||
.ifPresent(list -> list.forEach(electronicAccess -> electronicAccess.setRelationshipId(null))); | ||
case FIND_AND_REMOVE_THESE -> electronicAccessEntity -> ofNullable(electronicAccessEntity.getElectronicAccess()) | ||
.ifPresent(list -> list.stream() | ||
.filter(electronicAccess -> equalsIgnoreCase(electronicAccess.getRelationshipId(), action.getInitial())) | ||
.forEach(electronicAccess -> electronicAccess.setRelationshipId(null))); | ||
case FIND_AND_REPLACE -> electronicAccessEntity -> ofNullable(electronicAccessEntity.getElectronicAccess()) | ||
.ifPresent(list -> list.stream() | ||
.filter(electronicAccess -> equalsIgnoreCase(electronicAccess.getRelationshipId(), action.getInitial())) | ||
.forEach(electronicAccess -> electronicAccess.setRelationshipId(action.getUpdated()))); | ||
case REPLACE_WITH -> electronicAccessEntity -> ofNullable(electronicAccessEntity.getElectronicAccess()) | ||
.ifPresent(list -> list.forEach(electronicAccess -> electronicAccess.setRelationshipId(action.getUpdated()))); | ||
default -> notSupported(option, action); | ||
}; | ||
} | ||
|
||
private Updater<? extends ElectronicAccessEntity> updateUri(UpdateOptionType option, Action action) { | ||
return switch (action.getType()) { | ||
case CLEAR_FIELD -> electronicAccessEntity -> ofNullable(electronicAccessEntity.getElectronicAccess()) | ||
.ifPresent(list -> list.forEach(electronicAccess -> electronicAccess.setUri(EMPTY))); | ||
case FIND_AND_REMOVE_THESE -> electronicAccessEntity -> ofNullable(electronicAccessEntity.getElectronicAccess()) | ||
.ifPresent(list -> list.stream() | ||
.filter(electronicAccess -> Objects.equals(electronicAccess.getUri(), action.getInitial())) | ||
.forEach(electronicAccess -> electronicAccess.setUri(EMPTY))); | ||
case FIND_AND_REPLACE -> electronicAccessEntity -> ofNullable(electronicAccessEntity.getElectronicAccess()) | ||
.ifPresent(list -> list.stream() | ||
.filter(electronicAccess -> Objects.equals(electronicAccess.getUri(), action.getInitial())) | ||
.forEach(electronicAccess -> electronicAccess.setUri(isNull(action.getUpdated()) ? EMPTY : action.getUpdated()))); | ||
case REPLACE_WITH -> electronicAccessEntity -> ofNullable(electronicAccessEntity.getElectronicAccess()) | ||
.ifPresent(list -> list.forEach(electronicAccess -> electronicAccess.setUri(isNull(action.getUpdated()) ? EMPTY : action.getUpdated()))); | ||
default -> notSupported(option, action); | ||
}; | ||
} | ||
|
||
private Updater<? extends ElectronicAccessEntity> updateLinkText(UpdateOptionType option, Action action) { | ||
return switch (action.getType()) { | ||
case CLEAR_FIELD -> electronicAccessEntity -> ofNullable(electronicAccessEntity.getElectronicAccess()) | ||
.ifPresent(list -> list.forEach(electronicAccess -> electronicAccess.setLinkText(null))); | ||
case FIND_AND_REMOVE_THESE -> electronicAccessEntity -> ofNullable(electronicAccessEntity.getElectronicAccess()) | ||
.ifPresent(list -> list.stream() | ||
.filter(electronicAccess -> Objects.equals(electronicAccess.getLinkText(), action.getInitial())) | ||
.forEach(electronicAccess -> electronicAccess.setLinkText(null))); | ||
case FIND_AND_REPLACE -> electronicAccessEntity -> ofNullable(electronicAccessEntity.getElectronicAccess()) | ||
.ifPresent(list -> list.stream() | ||
.filter(electronicAccess -> Objects.equals(electronicAccess.getLinkText(), action.getInitial())) | ||
.forEach(electronicAccess -> electronicAccess.setLinkText(action.getUpdated()))); | ||
case REPLACE_WITH -> electronicAccessEntity -> ofNullable(electronicAccessEntity.getElectronicAccess()) | ||
.ifPresent(list -> list.forEach(electronicAccess -> electronicAccess.setLinkText(action.getUpdated()))); | ||
default -> notSupported(option, action); | ||
}; | ||
} | ||
|
||
private Updater<? extends ElectronicAccessEntity> updateMaterialsSpecified(UpdateOptionType option, Action action) { | ||
return switch (action.getType()) { | ||
case CLEAR_FIELD -> electronicAccessEntity -> ofNullable(electronicAccessEntity.getElectronicAccess()) | ||
.ifPresent(list -> list.forEach(electronicAccess -> electronicAccess.setMaterialsSpecification(null))); | ||
case FIND_AND_REMOVE_THESE -> electronicAccessEntity -> ofNullable(electronicAccessEntity.getElectronicAccess()) | ||
.ifPresent(list -> list.stream() | ||
.filter(electronicAccess -> Objects.equals(electronicAccess.getMaterialsSpecification(), action.getInitial())) | ||
.forEach(electronicAccess -> electronicAccess.setMaterialsSpecification(null))); | ||
case FIND_AND_REPLACE -> electronicAccessEntity -> ofNullable(electronicAccessEntity.getElectronicAccess()) | ||
.ifPresent(list -> list.stream() | ||
.filter(electronicAccess -> Objects.equals(electronicAccess.getMaterialsSpecification(), action.getInitial())) | ||
.forEach(electronicAccess -> electronicAccess.setMaterialsSpecification(action.getUpdated()))); | ||
case REPLACE_WITH -> electronicAccessEntity -> ofNullable(electronicAccessEntity.getElectronicAccess()) | ||
.ifPresent(list -> list.forEach(electronicAccess -> electronicAccess.setMaterialsSpecification(action.getUpdated()))); | ||
default -> notSupported(option, action); | ||
}; | ||
} | ||
|
||
private Updater<? extends ElectronicAccessEntity> updatePublicNote(UpdateOptionType option, Action action) { | ||
return switch (action.getType()) { | ||
case CLEAR_FIELD -> electronicAccessEntity -> ofNullable(electronicAccessEntity.getElectronicAccess()) | ||
.ifPresent(list -> list.forEach(electronicAccess -> electronicAccess.setPublicNote(null))); | ||
case FIND_AND_REMOVE_THESE -> electronicAccessEntity -> ofNullable(electronicAccessEntity.getElectronicAccess()) | ||
.ifPresent(list -> list.stream() | ||
.filter(electronicAccess -> Objects.equals(electronicAccess.getPublicNote(), action.getInitial())) | ||
.forEach(electronicAccess -> electronicAccess.setPublicNote(null))); | ||
case FIND_AND_REPLACE -> electronicAccessEntity -> ofNullable(electronicAccessEntity.getElectronicAccess()) | ||
.ifPresent(list -> list.stream() | ||
.filter(electronicAccess -> Objects.equals(electronicAccess.getPublicNote(), action.getInitial())) | ||
.forEach(electronicAccess -> electronicAccess.setPublicNote(action.getUpdated()))); | ||
case REPLACE_WITH -> electronicAccessEntity -> ofNullable(electronicAccessEntity.getElectronicAccess()) | ||
.ifPresent(list -> list.forEach(electronicAccess -> electronicAccess.setPublicNote(action.getUpdated()))); | ||
default -> notSupported(option, action); | ||
}; | ||
} | ||
|
||
private Updater<? extends ElectronicAccessEntity> notSupported(UpdateOptionType option, Action action) { | ||
return electronicAccessEntity -> { | ||
throw new BulkOperationException(format("Combination %s and %s isn't supported yet", option, action.getType())); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/resources/db/changelog/changes/08-11-2023_add_electronic_access_options_types.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ALTER TYPE UpdateOptionType ADD VALUE IF NOT EXISTS 'ELECTRONIC_ACCESS_URL_RELATIONSHIP'; | ||
ALTER TYPE UpdateOptionType ADD VALUE IF NOT EXISTS 'ELECTRONIC_ACCESS_URI'; | ||
ALTER TYPE UpdateOptionType ADD VALUE IF NOT EXISTS 'ELECTRONIC_ACCESS_LINK_TEXT'; | ||
ALTER TYPE UpdateOptionType ADD VALUE IF NOT EXISTS 'ELECTRONIC_ACCESS_MATERIALS_SPECIFIED'; | ||
ALTER TYPE UpdateOptionType ADD VALUE IF NOT EXISTS 'ELECTRONIC_ACCESS_URL_PUBLIC_NOTE'; |
13 changes: 13 additions & 0 deletions
13
src/main/resources/db/changelog/changes/08-11-2023_add_electronic_access_options_types.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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="08-11-2023_add_electronic_access_options_types" author="firebird"> | ||
<sqlFile path="08-11-2023_add_electronic_access_options_types.sql" relativeToChangelogFile="true" /> | ||
</changeSet> | ||
|
||
</databaseChangeLog> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.