Skip to content

Commit

Permalink
fix: events should only be published once per content operation (#1901)
Browse files Browse the repository at this point in the history
* fix: events should only be published once per content operation

Fixes #1869
  • Loading branch information
paulcwarren authored May 7, 2024
1 parent 699503b commit cb638de
Show file tree
Hide file tree
Showing 11 changed files with 270 additions and 203 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ jobs:
with:
path: ~/.m2
key: ${{ runner.os }}-maven-${{ github.run_id }}
- uses: actions/checkout@v2
with:
path: spring-content
- name: Re-build spring-content
run: |
pushd spring-content
mvn install -DskipTests=true
popd
- uses: actions/checkout@v2
with:
repository: paulcwarren/spring-content-examples
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.io.Serializable;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -21,11 +23,14 @@
import org.springframework.core.convert.converter.ConverterRegistry;

import com.azure.spring.autoconfigure.storage.resource.AzureStorageProtocolResolver;
import org.springframework.core.convert.converter.GenericConverter;

@Configuration
@Import(AzureStorageProtocolResolver.class)
public class AzureStorageConfiguration implements InitializingBean {

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

@Autowired(required = false)
private List<AzureStorageConfigurer> configurers;

Expand All @@ -46,10 +51,12 @@ 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
conversion.addConverter(new Converter<ContentPropertyInfo<Object, Serializable>, BlobId>() {
logger.info("Adding ContentPropertyInfo->BlobId converter");
Converter converter = new Converter<ContentPropertyInfo<Object, Serializable>, BlobId>() {

private String defaultBucket = bucket;

Expand All @@ -73,7 +80,8 @@ public BlobId convert(ContentPropertyInfo<Object, Serializable> info) {
return (key != null) ? new BlobId(strBucket, key.toString()) : null;
}

});
};
conversion.addConverter(converter);
}

private void addConverters(ConverterRegistry registry) {
Expand All @@ -89,5 +97,6 @@ private void addConverters(ConverterRegistry registry) {
public void afterPropertiesSet() throws Exception {
addDefaultConverters(conversion, bucket);
addConverters(conversion);
logger.info(conversion.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.UUID;
import java.util.*;

import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
Expand All @@ -26,8 +26,10 @@
import org.springframework.content.commons.utils.BeanUtils;
import org.springframework.content.commons.utils.Condition;
import org.springframework.content.commons.utils.PlacementService;
import org.springframework.content.commons.utils.PlacementServiceImpl;
import org.springframework.context.ApplicationContext;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.GenericConverter;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.WritableResource;
Expand All @@ -38,6 +40,7 @@

import internal.org.springframework.content.azure.io.AzureBlobResource;
import internal.org.springframework.content.commons.utils.ContentPropertyInfoTypeDescriptor;
import org.springframework.util.ClassUtils;

@Transactional
public class DefaultAzureStorageImpl<S, SID extends Serializable>
Expand Down Expand Up @@ -131,8 +134,8 @@ 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 = (BlobId) placementService.convert(contentPropertyInfo, contentPropertyInfoType, TypeDescriptor.valueOf(BlobId.class));

if (blobId != null) {
Expand Down
Loading

0 comments on commit cb638de

Please sign in to comment.