Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Features
* Migrate Package Endpoints to HoldingsIQ v2 API ([MODKBEKBJ-804](https://folio-org.atlassian.net/browse/MODKBEKBJ-804))
* Add additional fields to POST /eholdings/packages endpoint ([MODKBEKBJ-823](https://folio-org.atlassian.net/browse/MODKBEKBJ-823))

### Bug fixes
* Fix offset handling when retrieving holdings from HoldingsIQ. ([MODKBEKBJ-825](https://folio-org.atlassian.net/browse/MODKBEKBJ-825))
Expand Down
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@
<Multi-Release>true</Multi-Release>
</manifestEntries>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
<artifactSet />
<outputFile>${project.build.directory}/${project.artifactId}-fat.jar</outputFile>
Expand All @@ -627,6 +628,7 @@
<excludes>
<exclude>**/log4j.properties</exclude>
<exclude>**/Log4j2Plugins.dat</exclude>
<exclude>module-info.class</exclude>
</excludes>
</filter>
</filters>
Expand Down
49 changes: 40 additions & 9 deletions ramls/types/packages/packagePostDataAttributes.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,57 @@
"javaType": "org.folio.rest.jaxrs.model.PackagePostDataAttributes",
"additionalProperties": false,
"properties": {
"name": {
"accessTypeId": {
"type": "string",
"description": "Package name",
"example": "Advanced Placement Psychology Collection"
"description": "Access type id",
"$ref": "../../raml-util/schemas/uuid.schema",
"example": "f973c3b6-85fc-4d35-bda8-f31b568957bf"
},
"contentType": {
"type": "string",
"description": "Package content type",
"$ref": "contentTypeEnum.json"
},
"accessTypeId": {
"type": "string",
"description": "Access type id",
"$ref": "../../raml-util/schemas/uuid.schema",
"example": "f973c3b6-85fc-4d35-bda8-f31b568957bf"
},
"customAltNames": {
"description": "The list of custom alternate names for the package",
"items": {
"$ref": "packageAltName.json",
"type": "object"
},
"type": "array"
},
"customCoverage": {
"type": "object",
"description": "Custom Coverage",
"$ref": "../coverage.json"
},
"customDescription": {
"description": "The custom description of the package",
"example": "Package of medicinal journals (custom)",
"type": "string"
},
"customDisplayName": {
"description": "The custom description of the package",
"type": "string"
},
"isFreeAccess": {
"description": "Whether this package has free access designation or not",
"example": false,
"type": "boolean"
},
"name": {
"type": "string",
"description": "Package name",
"example": "Advanced Placement Psychology Collection"
},
"proxy": {
"$ref": "../proxy.json",
"description": "Proxy",
"type": "object"
},
"url": {
"description": "Package URL",
"type": "string"
}
},
"required": [
Expand Down
2 changes: 1 addition & 1 deletion ramls/types/proxies/proxyUrl.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Proxy Url Schema",
"description": "Proxy Url Schema",
"javaType": "org.folio.rest.jaxrs.model.ProxyUrl",
"javaType": "org.folio.rest.jaxrs.model.ProxyUrlDto",
"type": "object",
"additionalProperties": false,
"extends": {
Expand Down
2 changes: 1 addition & 1 deletion ramls/types/proxy.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Proxy Schema",
"description": "Proxy Schema",
"javaType": "org.folio.rest.jaxrs.model.Proxy",
"javaType": "org.folio.rest.jaxrs.model.ProxyDto",
"type": "object",
"additionalProperties": true,
"properties": {
Expand Down
15 changes: 0 additions & 15 deletions ramls/types/proxyPut.json

This file was deleted.

15 changes: 0 additions & 15 deletions ramls/types/tokenPut.json

This file was deleted.

11 changes: 5 additions & 6 deletions src/main/java/org/folio/common/ListUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,25 @@
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import lombok.experimental.UtilityClass;
import org.apache.commons.lang3.StringUtils;
import org.jspecify.annotations.Nullable;

@UtilityClass
public class ListUtils {

private static final Pattern SPLIT_BY_COMMA_PATTERN = Pattern.compile("\\s*,\\s*");

public static <T, R> List<R> mapItems(Collection<T> source, Function<? super T, ? extends R> mapper) {
Objects.requireNonNull(source, "Collection is null");
return source.stream().map(mapper).collect(Collectors.toList());
}

public static <T, R> List<R> mapItemsNullable(Collection<T> source, Function<? super T, ? extends R> mapper) {
public static <T, R> @Nullable List<R> mapItemsNullable(Collection<T> source,
Function<? super T, ? extends R> mapper) {
if (source == null) {
return null;
}
return source.stream().map(mapper).collect(Collectors.toList());
return source.stream().map(mapper).filter(Objects::nonNull).collect(Collectors.toList());
}

public static String createPlaceholders(int size) {
Expand All @@ -40,6 +39,6 @@ public static String createPlaceholders(int placeholderSize, int copiesSize) {
public static List<String> parseByComma(String string) {
return StringUtils.isBlank(string)
? Collections.emptyList()
: Arrays.asList(SPLIT_BY_COMMA_PATTERN.split(string));
: Arrays.stream(StringUtils.split(string, ',')).map(String::trim).toList();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package org.folio.rest.converter.packages;

import static org.folio.common.ListUtils.mapItems;

import java.util.Arrays;
import java.util.List;
import org.folio.holdingsiq.model.AlternateName;
import org.folio.holdingsiq.model.CoverageDates;
import org.folio.holdingsiq.model.PackagePut;
import org.folio.holdingsiq.model.Proxy;
import org.folio.holdingsiq.model.Visibility;
import org.folio.rest.jaxrs.model.PackagePutDataAttributes;
import org.folio.rest.jaxrs.model.PackageVisibility;
import org.folio.rest.jaxrs.model.VisibilityData;

public abstract class CommonPackagePutRequestConverter {

protected PackagePut.PackagePutBuilder convertCommonAttributes(PackagePutDataAttributes attributes) {
var builder = PackagePut.builder();

convertSimpleFields(attributes, builder);

if (attributes.getProxy() != null) {
builder.proxy(convertProxy(attributes));
}

if (attributes.getCustomCoverage() != null) {
builder.customCoverage(convertCoverageDates(attributes));
}

if (attributes.getCustomAltNames() != null) {
builder.customAltNames(convertCustomAltNames(attributes));
}

var visibilityData = attributes.getVisibilityData();
if (visibilityData == null || visibilityData.getIsHidden() == null) {
builder.visibilityDetails(mapItems(attributes.getVisibility(),
pv -> new Visibility(pv.getCategory().value(), pv.getHidden(), pv.getReason())));
} else {
builder.visibilityDetails(convertVisibilities(visibilityData));
}

return builder;
}

private void convertSimpleFields(PackagePutDataAttributes attributes, PackagePut.PackagePutBuilder builder) {
builder.isSelected(attributes.getIsSelected());
builder.isFullPackage(attributes.getIsFullPackage());
builder.customDescription(attributes.getCustomDescription());
builder.customDisplayName(attributes.getCustomDisplayName());
builder.packageFreeAccess(attributes.getIsFreeAccess());
builder.packageUrl(attributes.getUrl());
}

private List<Visibility> convertVisibilities(VisibilityData visibilityData) {
return Arrays.stream(PackageVisibility.Category.values())
.map(category -> new Visibility(category.value(), visibilityData.getIsHidden(), visibilityData.getReason()))
.toList();
}

private List<AlternateName> convertCustomAltNames(PackagePutDataAttributes attributes) {
return mapItems(attributes.getCustomAltNames(),
packageAltName -> new AlternateName(packageAltName.getId(), packageAltName.getAltName()));
}

private CoverageDates convertCoverageDates(PackagePutDataAttributes attributes) {
return CoverageDates.builder()
.beginCoverage(attributes.getCustomCoverage().getBeginCoverage())
.endCoverage(attributes.getCustomCoverage().getEndCoverage())
.build();
}

private Proxy convertProxy(PackagePutDataAttributes attributes) {
return Proxy.builder()
.id(attributes.getProxy().getId())
// RM API gives an error when we pass inherited as true along with updated proxy value
// Hard code it to false; it should not affect the state of inherited that RM API maintains
.inherited(false)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.folio.rest.converter.packages;

import static org.folio.common.ListUtils.mapItemsNullable;
import static org.folio.rest.converter.packages.PackageConverterUtils.CONTENT_TYPE_TO_RMAPI_CODE;

import javax.annotation.Nullable;
import org.folio.holdingsiq.model.AlternateName;
import org.folio.holdingsiq.model.CoverageDates;
import org.folio.holdingsiq.model.PackagePost;
import org.folio.holdingsiq.model.Proxy;
import org.folio.rest.jaxrs.model.Coverage;
import org.folio.rest.jaxrs.model.PackageAltName;
import org.folio.rest.jaxrs.model.PackagePostRequest;
import org.folio.rest.jaxrs.model.ProxyDto;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

@Component
public class CustomPackagePostRequestConverter implements Converter<PackagePostRequest, PackagePost> {

@Override
public PackagePost convert(PackagePostRequest postPackageBody) {
var data = postPackageBody.getData();
var attributes = data.getAttributes();
return PackagePost.builder()
.customAltNames(mapItemsNullable(attributes.getCustomAltNames(), this::convertAlternateName))
.coverage(convertCoverageDates(attributes.getCustomCoverage()))
.customDescription(attributes.getCustomDescription())
.customDisplayName(attributes.getCustomDisplayName())
.contentType(CONTENT_TYPE_TO_RMAPI_CODE.getOrDefault(attributes.getContentType(), 6))
.packageName(attributes.getName())
.packageFreeAccess(attributes.getIsFreeAccess())
.proxy(convertProxy(attributes.getProxy()))
.build();
}

private @Nullable CoverageDates convertCoverageDates(@Nullable Coverage customCoverage) {
if (customCoverage == null) {
return null;
}
return CoverageDates.builder()
.beginCoverage(customCoverage.getBeginCoverage())
.endCoverage(customCoverage.getEndCoverage())
.build();
}

private @Nullable Proxy convertProxy(@Nullable ProxyDto proxy) {
if (proxy == null) {
return null;
}
return Proxy.builder()
.id(proxy.getId())
.inherited(false)
.build();
}

private @Nullable AlternateName convertAlternateName(@Nullable PackageAltName packageAltName) {
if (packageAltName == null) {
return null;
}
return new AlternateName(packageAltName.getId(), packageAltName.getAltName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.folio.rest.converter.packages;

import static org.folio.rest.converter.packages.PackageConverterUtils.CONTENT_TYPE_TO_RMAPI_CODE;

import org.folio.holdingsiq.model.PackagePut;
import org.folio.rest.jaxrs.model.PackagePutRequest;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

@Component
public class CustomPackagePutRequestConverter
extends CommonPackagePutRequestConverter
implements Converter<PackagePutRequest, PackagePut> {

@Override
public PackagePut convert(PackagePutRequest request) {
var attributes = request.getData().getAttributes();
var builder = convertCommonAttributes(attributes);
builder.packageName(attributes.getName());
var contentType = CONTENT_TYPE_TO_RMAPI_CODE.get(attributes.getContentType());
builder.contentType(contentType != null ? contentType : 6);
return builder.build();
}
}
Loading
Loading