Commit a72a1855 authored by Matija Obreza's avatar Matija Obreza

Merge branch 'updated-crop-details-for-ui-321' into 'master'

Updated CropDetails

See merge request genesys-pgr/genesys-server!403
parents a3dba0c4 84863d64
......@@ -143,7 +143,7 @@ public class CropsController extends ApiBaseController {
* @return
* @throws AuthorizationException
*/
@JsonView(JsonViews.Public.class)
@JsonView(JsonViews.Root.class)
@RequestMapping(value = "/{shortName}/details", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE })
public CropService.CropDetails getCropDetails(@PathVariable("shortName") String shortName) throws InvalidRepositoryPathException {
LOG.info("Getting crop details {}", shortName);
......
......@@ -23,7 +23,7 @@ import java.util.Map;
import org.genesys.blocks.model.JsonViews;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.model.RepositoryImage;
import org.genesys.filerepository.model.ImageGallery;
import org.genesys2.server.model.genesys.Taxonomy2;
import org.genesys2.server.model.impl.Article;
import org.genesys2.server.model.impl.Crop;
......@@ -152,16 +152,16 @@ public interface CropService {
@JsonView({ JsonViews.Public.class })
public Article blurb;
public Long accessionCount;
public List<RepositoryImage> covers;
public ImageGallery imageGallery;
@JsonView({ JsonViews.Public.class })
public Map<String, ElasticsearchService.TermResult> overview;
public static CropDetails from(Crop crop, Article blurb, Long accessionCount, List<RepositoryImage> covers, Map<String, ElasticsearchService.TermResult> overview) {
public static CropDetails from(Crop crop, Article blurb, Long accessionCount, ImageGallery imageGallery, Map<String, ElasticsearchService.TermResult> overview) {
CropDetails cropDetails = new CropDetails();
cropDetails.crop = crop;
cropDetails.blurb = blurb;
cropDetails.accessionCount = accessionCount;
cropDetails.covers = covers;
cropDetails.imageGallery = imageGallery;
cropDetails.overview = overview;
return cropDetails;
......
......@@ -174,13 +174,17 @@ public class CropServiceImpl implements CropService {
LOG.trace("got count after {}ms", stopWatch.getTime());
ImageGallery imageGallery = imageGalleryService.loadImageGallery(Paths.get("/crop", crop.getShortName(), "covers"));
List<RepositoryImage> covers = imageGallery == null ? Collections.emptyList() : imageGallery.getImages();
if (imageGallery != null) {
if (imageGallery.getImages() != null) {
imageGallery.getImages().size();
}
}
LOG.trace("got covers after {}ms", stopWatch.getTime());
Map<String, ElasticsearchService.TermResult> overview = getOverviewData(byCrop);
LOG.trace("got overview after {}ms", stopWatch.getTime());
return CropDetails.from(crop, article, accessionCount, covers, overview);
return CropDetails.from(crop, article, accessionCount, imageGallery, overview);
}
@PreAuthorize("hasRole('ADMINISTRATOR')")
......@@ -236,15 +240,19 @@ public class CropServiceImpl implements CropService {
if (c.getOtherNames() != null)
c.getOtherNames().size();
List<RepositoryImage> covers = null;
ImageGallery imageGallery = null;
try {
ImageGallery imageGallery = imageGalleryService.loadImageGallery(Paths.get("/crop", c.getShortName(), "covers"));
covers = imageGallery == null ? Collections.emptyList() : imageGallery.getImages();
imageGallery = imageGalleryService.loadImageGallery(Paths.get("/crop", c.getShortName(), "covers"));
if (imageGallery != null) {
if (imageGallery.getImages() != null) {
imageGallery.getImages().size();
}
}
LOG.trace("got gallery for {} after {}ms", c.getShortName(), stopWatch.getTime());
} catch (InvalidRepositoryPathException e) {
}
return CropDetails.from(c, null, null, covers, null);
return CropDetails.from(c, null, null, imageGallery, null);
}).collect(Collectors.toList());
}
......
......@@ -272,7 +272,7 @@ public class CropsControllerTest extends AbstractApiTest {
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$.shortName", is("maize")))
.andExpect(jsonPath("$.blurb", is(notNullValue())))
.andExpect(jsonPath("$.covers", is(notNullValue())))
.andExpect(jsonPath("$.imageGallery", is(nullValue())))
.andExpect(jsonPath("$.overview", is(notNullValue())))
.andExpect(jsonPath("$.accessionCount", is(1)));
......
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