=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/fileresource/FileResourceStore.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/fileresource/FileResourceStore.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/fileresource/FileResourceStore.java 2015-10-26 16:01:20 +0000 @@ -0,0 +1,40 @@ +package org.hisp.dhis.fileresource; + +/* + * Copyright (c) 2004-2015, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.hisp.dhis.common.GenericIdentifiableObjectStore; + +/** + * @author Halvdan Hoem Grelland + */ +public interface FileResourceStore + extends GenericIdentifiableObjectStore +{ + void saveInTransaction( FileResource fileResource ); +} === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/DefaultFileResourceService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/DefaultFileResourceService.java 2015-10-22 23:43:32 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/DefaultFileResourceService.java 2015-10-26 16:01:20 +0000 @@ -31,7 +31,6 @@ import com.google.common.io.ByteSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.hisp.dhis.common.GenericIdentifiableObjectStore; import org.hisp.dhis.system.scheduling.Scheduler; import org.joda.time.DateTime; import org.joda.time.Duration; @@ -66,10 +65,17 @@ // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- - - private GenericIdentifiableObjectStore fileResourceStore; - - public void setFileResourceStore( GenericIdentifiableObjectStore fileResourceStore ) +// +// private GenericIdentifiableObjectStore fileResourceStore; +// +// public void setFileResourceStore( GenericIdentifiableObjectStore fileResourceStore ) +// { +// this.fileResourceStore = fileResourceStore; +// } + + private FileResourceStore fileResourceStore; + + public void setFileResourceStore( FileResourceStore fileResourceStore ) { this.fileResourceStore = fileResourceStore; } @@ -125,7 +131,8 @@ public FileResource getFileResource( String uid ) { // TODO Consider need for ensureStorageStatus - return ensureStorageStatus( fileResourceStore.getByUid( uid ) ); +// return ensureStorageStatus( fileResourceStore.getByUid( uid ) ); + return fileResourceStore.getByUid( uid ); } @Override @@ -142,12 +149,11 @@ .stream().filter( IS_ORPHAN_PREDICATE ).collect( Collectors.toList() ); } - @Transactional @Override public String saveFileResource( FileResource fileResource, File file ) { fileResource.setStorageStatus( FileResourceStorageStatus.PENDING ); - fileResourceStore.save( fileResource ); + fileResourceStore.saveInTransaction( fileResource ); ListenableFuture saveContentTask = scheduler.executeTask( () -> fileResourceContentStore.saveFileResourceContent( fileResource, file ) ); @@ -158,6 +164,23 @@ return uid; } +// +// @Transactional +// @Override +// public String saveFileResource( FileResource fileResource, File file ) +// { +// fileResource.setStorageStatus( FileResourceStorageStatus.PENDING ); +// fileResourceStore.save( fileResource ); +// +// ListenableFuture saveContentTask = +// scheduler.executeTask( () -> fileResourceContentStore.saveFileResourceContent( fileResource, file ) ); +// +// String uid = fileResource.getUid(); +// +// saveContentTask.addCallback( uploadCallbackProvider.getCallback( uid ) ); +// +// return uid; +// } @Transactional @Override === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/FileResourceUploadCallbackProvider.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/FileResourceUploadCallbackProvider.java 2015-10-22 23:43:32 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/FileResourceUploadCallbackProvider.java 2015-10-26 16:01:20 +0000 @@ -35,6 +35,7 @@ import org.joda.time.Period; import org.joda.time.format.PeriodFormat; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.concurrent.ListenableFutureCallback; /** @@ -53,6 +54,7 @@ { DateTime startTime = DateTime.now(); + @Transactional @Override public void onFailure( Throwable ex ) { @@ -69,6 +71,7 @@ } } + @Transactional @Override public void onSuccess( String result ) { === added directory 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/hibernate' === added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/hibernate/HibernateFileResourceStore.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/hibernate/HibernateFileResourceStore.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/hibernate/HibernateFileResourceStore.java 2015-10-26 16:01:20 +0000 @@ -0,0 +1,50 @@ +package org.hisp.dhis.fileresource.hibernate; + +/* + * Copyright (c) 2004-2015, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore; +import org.hisp.dhis.fileresource.FileResource; +import org.hisp.dhis.fileresource.FileResourceStore; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +/** + * @author Halvdan Hoem Grelland + */ +public class HibernateFileResourceStore + extends HibernateIdentifiableObjectStore + implements FileResourceStore +{ + @Transactional( propagation = Propagation.REQUIRES_NEW ) + @Override + public void saveInTransaction( FileResource fileResource ) + { + save( fileResource ); + } +} === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2015-10-14 11:29:47 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2015-10-26 16:01:20 +0000 @@ -576,7 +576,12 @@ - + + + + + +