-
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.
MODBULKOPS-242 - Supported Bulk Edit Actions for FOLIO Instance Notes (…
- Loading branch information
1 parent
7aedf91
commit 4612d8d
Showing
21 changed files
with
766 additions
and
37 deletions.
There are no files selected for viewing
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
22 changes: 22 additions & 0 deletions
22
src/main/java/org/folio/bulkops/client/InstanceNoteTypesClient.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,22 @@ | ||
package org.folio.bulkops.client; | ||
|
||
import org.folio.bulkops.configs.FeignClientConfiguration; | ||
import org.folio.bulkops.domain.dto.InstanceNoteType; | ||
import org.folio.bulkops.domain.dto.InstanceNoteTypeCollection; | ||
import org.springframework.cloud.openfeign.FeignClient; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
@FeignClient(name = "instance-note-types", configuration = FeignClientConfiguration.class) | ||
public interface InstanceNoteTypesClient { | ||
@GetMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) | ||
InstanceNoteType getNoteTypeById(@PathVariable String id); | ||
|
||
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) | ||
InstanceNoteTypeCollection getNoteTypesByQuery(@RequestParam String query, @RequestParam("limit") int limit); | ||
|
||
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) | ||
InstanceNoteTypeCollection getInstanceNoteTypes(@RequestParam("limit") int limit); | ||
} |
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
60 changes: 60 additions & 0 deletions
60
src/main/java/org/folio/bulkops/domain/converter/InstanceNoteListConverter.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,60 @@ | ||
package org.folio.bulkops.domain.converter; | ||
|
||
import static org.folio.bulkops.domain.format.SpecialCharacterEscaper.escape; | ||
import static org.folio.bulkops.domain.format.SpecialCharacterEscaper.restore; | ||
import static org.folio.bulkops.util.Constants.ARRAY_DELIMITER; | ||
import static org.folio.bulkops.util.Constants.ITEM_DELIMITER; | ||
import static org.folio.bulkops.util.Constants.ITEM_DELIMITER_PATTERN; | ||
import static org.folio.bulkops.util.Utils.booleanToStringNullSafe; | ||
|
||
import org.apache.commons.lang3.ObjectUtils; | ||
import org.folio.bulkops.domain.bean.InstanceNote; | ||
import org.folio.bulkops.exception.EntityFormatException; | ||
import org.folio.bulkops.service.InstanceReferenceHelper; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
public class InstanceNoteListConverter extends BaseConverter<List<InstanceNote>> { | ||
private static final int NUMBER_OF_INSTANCE_NOTE_ELEMENTS = 3; | ||
private static final int INSTANCE_NOTE_NOTE_TYPE_INDEX = 0; | ||
private static final int INSTANCE_NOTE_NOTE_INDEX = 1; | ||
private static final int INSTANCE_NOTE_STAFF_ONLY_INDEX = 2; | ||
|
||
@Override | ||
public List<InstanceNote> convertToObject(String value) { | ||
return Arrays.stream(value.split(ITEM_DELIMITER_PATTERN)) | ||
.map(this::restoreInstanceNote) | ||
.filter(ObjectUtils::isNotEmpty) | ||
.toList(); | ||
} | ||
|
||
@Override | ||
public String convertToString(List<InstanceNote> object) { | ||
return object.stream() | ||
.filter(Objects::nonNull) | ||
.map(note -> String.join(ARRAY_DELIMITER, | ||
escape(InstanceReferenceHelper.service().getNoteTypeNameById(note.getInstanceNoteTypeId())), | ||
escape(note.getNote()), | ||
booleanToStringNullSafe(note.getStaffOnly()))) | ||
.collect(Collectors.joining(ITEM_DELIMITER)); | ||
} | ||
|
||
private InstanceNote restoreInstanceNote(String s) { | ||
if (ObjectUtils.isEmpty(s)) { | ||
return null; | ||
} | ||
var tokens = s.split(ARRAY_DELIMITER, -1); | ||
if (tokens.length < NUMBER_OF_INSTANCE_NOTE_ELEMENTS) { | ||
throw new EntityFormatException(String.format("Illegal number of instance note elements: %d, expected: %d", tokens.length, | ||
NUMBER_OF_INSTANCE_NOTE_ELEMENTS)); | ||
} | ||
return InstanceNote.builder() | ||
.instanceNoteTypeId(InstanceReferenceHelper.service().getNoteTypeIdByName(restore(tokens[INSTANCE_NOTE_NOTE_TYPE_INDEX]))) | ||
.note(restore(tokens[INSTANCE_NOTE_NOTE_INDEX])) | ||
.staffOnly(ObjectUtils.isEmpty(tokens[INSTANCE_NOTE_STAFF_ONLY_INDEX]) ? null : Boolean.parseBoolean(tokens[INSTANCE_NOTE_STAFF_ONLY_INDEX])) | ||
.build(); | ||
} | ||
} |
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
Oops, something went wrong.