Skip to content

Commit

Permalink
fix: normalize file and name so that the digital media list has no bl…
Browse files Browse the repository at this point in the history
…ank items
  • Loading branch information
cleydyr committed May 28, 2024
1 parent d1520ca commit fcd2c9c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
15 changes: 15 additions & 0 deletions src/main/java/biblivre/cataloging/RecordAttachmentDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;

@Setter
Expand All @@ -37,6 +38,20 @@ public class RecordAttachmentDTO extends AbstractDTO {
private String path;
private String uri;

public void normalizeFileAndName() {
if (StringUtils.isBlank(file)) {
file = name;
}

if (StringUtils.isBlank(file)) {
file = uri;
}

if (StringUtils.isBlank(name)) {
name = file;
}
}

@Override
public JSONObject toJSONObject() {
JSONObject json = new JSONObject();
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/biblivre/marc/MarcDataReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,18 @@ public List<RecordAttachmentDTO> getAttachments() {

return fields.stream()
.map(
field ->
new RecordAttachmentDTO(
getFirstSubfieldData(field, 'f'),
getFirstSubfieldData(field, 'y'),
getFirstSubfieldData(field, 'd'),
getFirstSubfieldData(field, 'u')))
field -> {
RecordAttachmentDTO recordAttachmentDTO =
new RecordAttachmentDTO(
getFirstSubfieldData(field, 'f'),
getFirstSubfieldData(field, 'y'),
getFirstSubfieldData(field, 'd'),
getFirstSubfieldData(field, 'u'));

recordAttachmentDTO.normalizeFileAndName();

return recordAttachmentDTO;
})
.toList();
}

Expand Down

0 comments on commit fcd2c9c

Please sign in to comment.