Commit 19edccfd authored by Matija Obreza's avatar Matija Obreza

Merge branch 'crop-include-files' into 'master'

Crop details: include list of publicly readable files in /crop/{shortName} folder

See merge request genesys-pgr/genesys-server!407
parents eb402dba b44f95d7
......@@ -20,10 +20,14 @@ import java.io.Serializable;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
import org.genesys.blocks.model.JsonViews;
import org.genesys.blocks.security.SecurityContextUtil;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.model.RepositoryFile;
import org.genesys.filerepository.model.RepositoryFolder;
import org.genesys2.server.model.genesys.Taxonomy2;
import org.genesys2.server.model.impl.Article;
import org.genesys2.server.model.impl.Crop;
......@@ -152,15 +156,22 @@ public interface CropService {
@JsonView({ JsonViews.Public.class })
public Article blurb;
public Long accessionCount;
public ImageGallery imageGallery;
public ImageGallery imageGallery; // gallery at /crop/{cropName}/covers
public List<RepositoryFile> files; // list of files in /crop/{cropName}
@JsonView({ JsonViews.Public.class })
public Map<String, ElasticsearchService.TermResult> overview;
public static CropDetails from(Crop crop, Article blurb, Long accessionCount, ImageGallery imageGallery, Map<String, ElasticsearchService.TermResult> overview) {
public static CropDetails from(Crop crop, Article blurb, Long accessionCount, ImageGallery imageGallery, RepositoryFolder folder, Map<String, ElasticsearchService.TermResult> overview) {
CropDetails cropDetails = new CropDetails();
cropDetails.crop = crop;
cropDetails.blurb = blurb;
cropDetails.accessionCount = accessionCount;
if (folder != null) {
folder.getFiles().size();
// We only provide publicly accessible files
cropDetails.files = folder.getFiles().stream().filter(file -> SecurityContextUtil.anyoneHasPermission(file, "READ")).collect(Collectors.toList());
}
cropDetails.imageGallery = imageGallery;
cropDetails.overview = overview;
......
......@@ -36,8 +36,9 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.StopWatch;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.model.RepositoryImage;
import org.genesys.filerepository.model.RepositoryFolder;
import org.genesys.filerepository.service.ImageGalleryService;
import org.genesys.filerepository.service.RepositoryService;
import org.genesys2.server.component.security.AsAdminInvoker;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.genesys.Accession;
......@@ -122,6 +123,9 @@ public class CropServiceImpl implements CropService {
@Autowired
protected AsAdminInvoker asAdminInvoker;
@Autowired
private RepositoryService repositoryService;
/**
* @param shortName the crop name ("groundnuts") as provided by partners, but
* can also be a list of names ("peanut,goober,groundnut")
......@@ -181,10 +185,12 @@ public class CropServiceImpl implements CropService {
}
LOG.trace("got covers after {}ms", stopWatch.getTime());
RepositoryFolder folder = repositoryService.getFolder(Paths.get("/crop", crop.getShortName()));
Map<String, ElasticsearchService.TermResult> overview = getOverviewData(byCrop);
LOG.trace("got overview after {}ms", stopWatch.getTime());
return CropDetails.from(crop, article, accessionCount, imageGallery, overview);
return CropDetails.from(crop, article, accessionCount, imageGallery, folder, overview);
}
@PreAuthorize("hasRole('ADMINISTRATOR')")
......@@ -252,7 +258,7 @@ public class CropServiceImpl implements CropService {
} catch (InvalidRepositoryPathException e) {
}
return CropDetails.from(c, null, null, imageGallery, null);
return CropDetails.from(c, null, null, imageGallery, null, null);
}).collect(Collectors.toList());
}
......
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