Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File storage should convert new content id values properly #1044

Merged
merged 1 commit into from
Aug 19, 2022
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
4 changes: 2 additions & 2 deletions spring-content-fs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@
</dependency>
<!-- HSQL -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ public Resource getResource(S entity) {
@Override
public Resource getResource(S entity, PropertyPath propertyPath) {

SID contentId = getContentId(entity, propertyPath);
if (contentId == null) {
UUID newId = UUID.randomUUID();

Object convertedId = convertToExternalContentIdType(entity, newId);
ContentProperty contentProperty = this.mappingContext.getContentProperty(entity.getClass(), propertyPath.getName());
if (contentProperty == null) {
throw new StoreAccessException(String.format("Content property %s does not exist", propertyPath.getName()));
}

contentId = (SID)convertedId;
setContentId(entity, propertyPath, contentId, null);
SID contentId = (SID) contentProperty.getContentId(entity);
if (contentId == null) {
return null;
}
return getResource(contentId);
}
Expand Down Expand Up @@ -216,7 +216,10 @@ public S setContent(S property, PropertyPath propertyPath, InputStream content)

Serializable newId = UUID.randomUUID().toString();

Object convertedId = convertToExternalContentIdType(newId, contentProperty.getContentIdType(property));
Object convertedId = placer.convert(
newId,
TypeDescriptor.forObject(newId),
contentProperty.getContentIdType(property));

contentProperty.setContentId(property, convertedId, null);
}
Expand Down Expand Up @@ -386,29 +389,6 @@ private Object convertToExternalContentIdType(S property, Object contentId) {
return contentId.toString();
}

private Object convertToExternalContentIdType(Object contentId, TypeDescriptor contentIdType) {
if (placer.canConvert(TypeDescriptor.forObject(contentId),
contentIdType)) {
contentId = placer.convert(contentId, TypeDescriptor.forObject(contentId),
contentIdType);
return contentId;
}
return contentId.toString();
}

private SID getContentId(S entity, PropertyPath propertyPath) {

Assert.notNull(entity, "entity must not be null");
Assert.notNull(propertyPath, "propertyPath must not be null");

BeanWrapper wrapper = new BeanWrapperImpl(entity);
ContentProperty property = this.mappingContext.getContentProperty(entity.getClass(), propertyPath.getName());
if (property == null) {
throw new StoreAccessException(String.format("Content property %s does not exist", propertyPath.getName()));
}
return (SID) wrapper.getPropertyValue(property.getContentIdPropertyPath());
}

private void setContentId(S entity, PropertyPath propertyPath, SID contentId, Condition condition) {

Assert.notNull(entity, "entity must not be null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,14 +456,14 @@ FileSystemResourceLoader fileSystemResourceLoader() {
@Bean
public DataSource dataSource() {
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
return builder.setType(EmbeddedDatabaseType.H2).build();
return builder.setType(EmbeddedDatabaseType.HSQL).build();
}

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {

HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
vendorAdapter.setDatabase(Database.H2);
vendorAdapter.setDatabase(Database.HSQL);
vendorAdapter.setGenerateDdl(true);

LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
Expand Down Expand Up @@ -494,6 +494,7 @@ public interface ContentProperty {
}

@Entity
@Table(name="tentity")
public static class TEntity implements ContentProperty {

@Id
Expand Down
Loading