Skip to content

Commit

Permalink
more logging around the placement service default converters
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcwarren committed Apr 19, 2024
1 parent fcfbb08 commit f6ce994
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ public PlacementService azureStoragePlacementService() {
public static void addDefaultConverters(PlacementService conversion, String bucket) {

// Serializable -> BlobId
logger.info("Adding Serializable->BlobId converter");
conversion.addConverter(new BlobIdResolverConverter(bucket));

// ContentPropertyInfo -> BlobId
logger.info("Adding ContentPropertyInfo->BlobId converter");
conversion.addConverter(new Converter<ContentPropertyInfo<Object, Serializable>, BlobId>() {

private String defaultBucket = bucket;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ public Resource getResource(S entity, PropertyPath propertyPath, GetResourcePara
BlobId blobId = null;
TypeDescriptor contentPropertyInfoType = ContentPropertyInfoTypeDescriptor.withGenerics(entity, property);
if (placementService.canConvert(contentPropertyInfoType, TypeDescriptor.valueOf(BlobId.class))) {
ContentPropertyInfo<S, SID> contentPropertyInfo = ContentPropertyInfo.of(entity,
(SID) property.getContentId(entity), propertyPath, property);
ContentPropertyInfo<S, SID> contentPropertyInfo = ContentPropertyInfo.of(entity, (SID) property.getContentId(entity), propertyPath, property);



blobId = placementService.convert(contentPropertyInfo, BlobId.class);

if (blobId != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.springframework.content.commons.utils;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.content.commons.config.ContentPropertyInfo;
import org.springframework.core.ResolvableType;
import org.springframework.core.convert.TypeDescriptor;
Expand All @@ -15,6 +17,8 @@

public class PlacementServiceImpl extends DefaultConversionService implements PlacementService {

private static Log logger = LogFactory.getLog(PlacementServiceImpl.class);

public static final String CONTENT_PROPERTY_INFO_GENERIC_PARAMETERS_MISSING_MESSAGE = "Unable to determine entity type <S> and content id type <SID> for " +
ContentPropertyInfo.class.getName() + "; does the class parameterize those types?";

Expand Down Expand Up @@ -53,22 +57,29 @@ public void addConverter(Converter<?, ?> converter) {
"Converter [" + converter.getClass().getName() + "]; does the class parameterize those types?");
}
ResolvableType sourceType = generics[0];
logger.info("generics[0] sourceType: " + sourceType.toString());
if (sourceType.resolve() == ContentPropertyInfo.class) {
ResolvableType targetType = generics[1];
logger.info("generics[1] targetType: " + targetType.toString());

ResolvableType[] sourceTypeGenerics = sourceType.getGenerics();
if (sourceTypeGenerics.length != 2) {
throw new IllegalArgumentException(CONTENT_PROPERTY_INFO_GENERIC_PARAMETERS_MISSING_MESSAGE);
}

logger.info("sourceTypeGenerics[0]: " + sourceTypeGenerics[0].toString());
logger.info("sourceTypeGenerics[1]: " + sourceTypeGenerics[1].toString());

Class<?> entityClass = sourceTypeGenerics[0].resolve();
Class<?> contentIdClass = sourceTypeGenerics[1].resolve();
if (entityClass == null || contentIdClass == null) {
throw new IllegalArgumentException(CONTENT_PROPERTY_INFO_GENERIC_PARAMETERS_MISSING_MESSAGE);
}

logger.info("Adding converter as ContentPropertyInfoConverterAdapter");
addConverter(new ContentPropertyInfoConverterAdapter(converter, sourceType, targetType, entityClass, contentIdClass));
} else {
logger.info("Adding as regular converter");
super.addConverter(converter);
}
}
Expand Down

0 comments on commit f6ce994

Please sign in to comment.