Commit 723552fd authored by Maxym Borodenko's avatar Maxym Borodenko

ES not containing all data

parent a8b6c76a
......@@ -16,6 +16,7 @@
package org.genesys2.server.component.aspect;
import java.util.concurrent.BlockingQueue;
import java.util.regex.Matcher;
import org.aspectj.lang.JoinPoint;
......@@ -30,6 +31,7 @@ import org.genesys.filerepository.model.RepositoryImage;
import org.genesys.filerepository.service.ImageGalleryService;
import org.genesys.filerepository.service.aspect.AbstractImageGalleryAspects;
import org.genesys.filerepository.service.aspect.ImageGalleryAspectsImpl;
import org.genesys2.server.component.elastic.ElasticReindex;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionId;
import org.genesys2.server.persistence.AccessionIdRepository;
......@@ -41,6 +43,8 @@ import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import javax.annotation.Resource;
/**
* The Class GenesysImageGalleryAspects.
*/
......@@ -67,6 +71,9 @@ public class GenesysImageGalleryAspects extends AbstractImageGalleryAspects impl
@Autowired
private AccessionIdRepository accessionIdRepository;
@Resource
private BlockingQueue<ElasticReindex> elasticReindexQueue;
/**
* Instantiates a new genesys image gallery aspects.
*/
......@@ -132,6 +139,7 @@ public class GenesysImageGalleryAspects extends AbstractImageGalleryAspects impl
@Override
@Around(value = "execution(* org.genesys.filerepository.persistence.RepositoryImagePersistence.delete(*)) && args(repositoryImage)")
public Object aroundRepositoryImageDelete(ProceedingJoinPoint joinPoint, RepositoryImage repositoryImage) throws Throwable {
Object deletedObject = super.aroundRepositoryImageDelete(joinPoint, repositoryImage);
RepositoryFolder repositoryFolder = repositoryImage.getFolder();
if (isAccessionFolder(repositoryFolder)) {
Accession accession = accessionService.findMatchingAccession(repositoryFolder);
......@@ -140,7 +148,7 @@ public class GenesysImageGalleryAspects extends AbstractImageGalleryAspects impl
}
}
return super.aroundRepositoryImageDelete(joinPoint, repositoryImage);
return deletedObject;
}
/**
......@@ -196,8 +204,11 @@ public class GenesysImageGalleryAspects extends AbstractImageGalleryAspects impl
ImageGallery imageGallery = instituteFilesService.loadImageGallery(accession.getInstitute(), accession);
if (imageGallery != null) {
accessionId.setImageCount(imageGallery.getImages().size());
accessionIdRepository.save(accessionId);
} else {
accessionId.setImageCount(0);
}
accessionIdRepository.save(accessionId);
elasticReindexQueue.add(new ElasticReindex(Accession.class.getName(), accessionId.getId()));
} catch (InvalidRepositoryPathException e) {
LOG.warn("Error updating imageCount of accession, error is {}", e.getMessage());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment