Commit ab861ffb authored by Matija Obreza's avatar Matija Obreza

Merge branch '349-image-gallery-500' into 'master'

Resolve "Image gallery 500"

Closes #349

See merge request genesys-pgr/genesys-server!245
parents 706e0c84 cfc82777
......@@ -17,6 +17,7 @@ package org.genesys.catalog.model.filters;
import static org.genesys.catalog.model.traits.QDescriptorList.descriptorList;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.lang3.ArrayUtils;
......@@ -24,10 +25,10 @@ import org.apache.commons.lang3.StringUtils;
import org.genesys.blocks.model.filters.StringFilter;
import org.genesys.blocks.model.filters.UuidModelFilter;
import org.genesys.catalog.model.traits.DescriptorList;
import org.genesys2.server.model.PublishState;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;
import org.genesys2.server.model.PublishState;
/**
* The Class DescriptorListFilter.
......@@ -113,4 +114,14 @@ public class DescriptorListFilter extends UuidModelFilter<DescriptorListFilter,
return and;
}
public DescriptorListFilter state(PublishState... state) {
if (this.state == null) {
this.state = new HashSet<>();
}
for (PublishState s : state) {
this.state.add(s);
}
return this;
}
}
......@@ -15,15 +15,14 @@
*/
package org.genesys.catalog.service;
import java.util.List;
import java.util.UUID;
import org.genesys.catalog.model.filters.DescriptorListFilter;
import org.genesys.catalog.model.traits.Descriptor;
import org.genesys.catalog.model.traits.DescriptorList;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.UUID;
/**
* DescriptorList service interface.
......@@ -32,6 +31,14 @@ import java.util.UUID;
*/
public interface DescriptorListService {
/**
* Count descriptor lists.
*
* @param filter the filter
* @return the long
*/
long countDescriptorLists(DescriptorListFilter filter);
/**
* Create DescriptionList.
*
......@@ -117,14 +124,6 @@ public interface DescriptorListService {
*/
Page<DescriptorList> listDescriptorListsForCurrentUser(DescriptorListFilter descriptorListFilter, Pageable page);
/**
* Upload DescriptorList with Descriptor list.
*
* @param file .csv file with data
* @return Created DescriptorList
*/
DescriptorList uploadDescriptorListOfCSV(MultipartFile file);
/**
* Delete descriptor list.
*
......@@ -134,8 +133,8 @@ public interface DescriptorListService {
DescriptorList deleteDescriptorList(DescriptorList descriptorList);
/**
* Puts the descriptorList into the Review state to be reviewed by admin.
* Admin and the user with MANAGE permission - only.
* Puts the descriptorList into the Review state to be reviewed by admin. Admin
* and the user with MANAGE permission - only.
*
* @param descriptorList the descriptorList
* @return descriptorList in REVIEWING state
......@@ -143,8 +142,8 @@ public interface DescriptorListService {
DescriptorList reviewDescriptorList(DescriptorList descriptorList);
/**
* Unpublishes published descriptorList.
* Admin and the user with MANAGE permission - only.
* Unpublishes published descriptorList. Admin and the user with MANAGE
* permission - only.
*
* @param descriptorList the descriptorList
* @return unpublished descriptorList
......
......@@ -47,13 +47,16 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.ConcurrencyFailureException;
import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.domain.*;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.acls.domain.BasePermission;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;
......@@ -79,6 +82,15 @@ public class DescriptorListServiceImpl implements DescriptorListService {
@Autowired
private DescriptorService descriptorService;
/* (non-Javadoc)
* @see org.genesys.catalog.service.DescriptorListService#countDescriptorLists(org.genesys.catalog.model.filters.DescriptorListFilter)
*/
@Override
public long countDescriptorLists(DescriptorListFilter filter) {
return descriptorListRepository.count(filter.buildQuery());
}
/**
* {@inheritDoc}
*/
......@@ -305,7 +317,7 @@ public class DescriptorListServiceImpl implements DescriptorListService {
@Override
public Page<DescriptorList> listDescriptorLists(final DescriptorListFilter filters, final Pageable page) {
Pageable markdownSortPageRequest = JPAUtils.toMarkdownSort(page, "title");
Page res = descriptorListRepository.findAll(new BooleanBuilder().and(filters.buildQuery()).and(descriptorList.state.in(PublishState.PUBLISHED)), markdownSortPageRequest);
Page<DescriptorList> res = descriptorListRepository.findAll(new BooleanBuilder().and(filters.buildQuery()).and(descriptorList.state.in(PublishState.PUBLISHED)), markdownSortPageRequest);
return new PageImpl<DescriptorList>(res.getContent(), page, res.getTotalElements());
}
......@@ -313,21 +325,15 @@ public class DescriptorListServiceImpl implements DescriptorListService {
public Page<DescriptorList> listDescriptorListsForCurrentUser(final DescriptorListFilter filter, final Pageable page) {
Pageable markdownSortPageRequest = JPAUtils.toMarkdownSort(page, "title");
if (securityUtils.hasRole(UserRole.ADMINISTRATOR)) {
Page res = descriptorListRepository.findAll(filter.buildQuery(), markdownSortPageRequest);
Page<DescriptorList> res = descriptorListRepository.findAll(filter.buildQuery(), markdownSortPageRequest);
return new PageImpl<DescriptorList>(res.getContent(), page, res.getTotalElements());
} else {
final HashSet<Long> partners = new HashSet<>(securityUtils.listObjectIdentityIdsForCurrentUser(Partner.class, BasePermission.WRITE));
Page res = descriptorListRepository.findAll(descriptorList.owner.id.in(partners).and(filter.buildQuery()), markdownSortPageRequest);
Page<DescriptorList> res = descriptorListRepository.findAll(descriptorList.owner.id.in(partners).and(filter.buildQuery()), markdownSortPageRequest);
return new PageImpl<DescriptorList>(res.getContent(), page, res.getTotalElements());
}
}
// TODO implement logic
@Override
public DescriptorList uploadDescriptorListOfCSV(final MultipartFile file) {
return null;
}
/**
* {@inheritDoc}
*/
......
......@@ -2,8 +2,10 @@ package org.genesys2.server.api.v1;
import org.genesys.catalog.model.filters.DatasetFilter;
import org.genesys.catalog.model.filters.DescriptorFilter;
import org.genesys.catalog.model.filters.DescriptorListFilter;
import org.genesys.catalog.model.filters.PartnerFilter;
import org.genesys.catalog.service.DatasetService;
import org.genesys.catalog.service.DescriptorListService;
import org.genesys.catalog.service.DescriptorService;
import org.genesys.catalog.service.PartnerService;
import org.genesys2.server.api.ApiBaseController;
......@@ -68,6 +70,8 @@ public class ApiInfoController {
@Autowired
private DescriptorService descriptorService;
@Autowired
private DescriptorListService descriptorListService;
@Autowired
private PartnerService partnerService;
/**
......@@ -88,6 +92,7 @@ public class ApiInfoController {
apiInfo.subsetCount = subsetService.countSubsets(new SubsetFilter().state(PublishState.PUBLISHED));
apiInfo.instituteCount = instituteService.countActive();
apiInfo.descriptorCount = descriptorService.countDescriptors(new DescriptorFilter().state(PublishState.PUBLISHED));
apiInfo.descriptorListCount = descriptorListService.countDescriptorLists(new DescriptorListFilter().state(PublishState.PUBLISHED));
apiInfo.partnerCount = partnerService.countPartners(new PartnerFilter());
apiInfo.captchaSiteKey = this.captchaSiteKey;
apiInfo.googleAnalyticsId = this.googleAnalyticsId;
......@@ -100,16 +105,17 @@ public class ApiInfoController {
* The Class ApiInfo.
*/
public static class ApiInfo {
public String artifactId;
public String artifactId;
public String version;
public String revision;
public String baseUrl;
public String[] cdnServers;
public long instituteCount;
public long accessionCount;
public long datasetCount;
public long subsetCount;
public long instituteCount;
public long descriptorListCount;
public long descriptorCount;
public long partnerCount;
public String captchaSiteKey;
......
......@@ -56,7 +56,7 @@ public class AsAdminAspect {
if (prevAuth == null
// or is not admin
|| ! prevAuth.getAuthorities().contains(UserRole.ADMINISTRATOR.getAuthority())
|| ! prevAuth.getAuthorities().contains(UserRole.ADMINISTRATOR)
// or not already SYS_ADMIN
|| !prevAuth.getName().equals(adminAuthorization.getName())) {
......
......@@ -140,7 +140,7 @@ public class GenesysImageGalleryAspects extends AbstractImageGalleryAspects impl
* @see org.genesys.filerepository.service.aspect.AbstractImageGalleryAspects#addImageToGallery(org.genesys.filerepository.model.RepositoryImage)
*/
@Override
protected void addImageToGallery(RepositoryImage repositoryImage) {
protected void addImageToGallery(RepositoryImage repositoryImage) throws InvalidRepositoryPathException {
imageGalleryAspect.addImageToGallery(repositoryImage);
}
......@@ -148,7 +148,7 @@ public class GenesysImageGalleryAspects extends AbstractImageGalleryAspects impl
* @see org.genesys.filerepository.service.aspect.AbstractImageGalleryAspects#removeImageFromGallery(org.genesys.filerepository.model.RepositoryImage)
*/
@Override
protected void removeImageFromGallery(RepositoryImage repositoryImage) {
protected void removeImageFromGallery(RepositoryImage repositoryImage) throws InvalidRepositoryPathException {
imageGalleryAspect.removeImageFromGallery(repositoryImage);
}
......
......@@ -71,7 +71,7 @@ public class RepositoryDownloadController extends BaseController {
sanityCheck(Paths.get(path), ext, repositoryFile);
data = this.repositoryService.getFileBytes(repositoryFile.storagePath());
data = this.repositoryService.getFileBytes(repositoryFile);
response.setHeader(HttpHeaders.CACHE_CONTROL, "max-age=86400, s-maxage=86400, public, no-transform");
response.setHeader(HttpHeaders.PRAGMA, "");
......
......@@ -652,12 +652,11 @@ public class WiewsController extends BaseController {
}
@GetMapping(value = "/{wiewsCode}/files/gallery/details")
public String viewInstituteGallery(ModelMap model, HttpServletRequest request, @PathVariable("wiewsCode") String wiewsCode, @RequestParam String galleryPath) {
public String viewInstituteGallery(ModelMap model, HttpServletRequest request, @PathVariable("wiewsCode") String wiewsCode, @RequestParam String galleryPath) throws InvalidRepositoryPathException {
// check user permissions
instituteService.getInstituteForEdit(wiewsCode);
final Path wiewsPath = Paths.get("/wiews/", wiewsCode);
ImageGallery imageGallery = imageGalleryService.loadImageGallery(wiewsPath.resolve(galleryPath));
ImageGallery imageGallery = imageGalleryService.loadImageGallery(Paths.get(galleryPath));
if (imageGallery == null) {
throw new ResourceNotFoundException("No image gallery here!");
......@@ -665,6 +664,7 @@ public class WiewsController extends BaseController {
imageGalleryService.ensureThumbnails(imageGallery, 200, 200);
model.addAttribute("thumbnailFormat", "200x200");
model.addAttribute("galleryPath", galleryPath);
model.addAttribute("imageGallery", imageGallery);
model.addAttribute("wiewsCode", wiewsCode);
......@@ -672,7 +672,7 @@ public class WiewsController extends BaseController {
}
@GetMapping(value = "/{wiewsCode}/files/gallery/edit")
public String editInstituteGallery(@RequestParam String galleryPath, @PathVariable("wiewsCode") String wiewsCode, ModelMap model) throws NoSuchRepositoryFileException {
public String editInstituteGallery(@RequestParam String galleryPath, @PathVariable("wiewsCode") String wiewsCode, ModelMap model) throws NoSuchRepositoryFileException, InvalidRepositoryPathException {
// check user permissions
instituteService.getInstituteForEdit(wiewsCode);
final Path wiewsPath = Paths.get("/wiews/", wiewsCode);
......@@ -682,6 +682,7 @@ public class WiewsController extends BaseController {
imageGallery = new ImageGallery();
imageGallery.setPath(galleryPath);
}
model.addAttribute("galleryPath", galleryPath);
model.addAttribute("imageGallery", imageGallery);
model.addAttribute("wiewsCode", wiewsCode);
......
......@@ -68,7 +68,7 @@ public class RepositoryGalleryController extends BaseController {
}
@RequestMapping(value = "/**", method = RequestMethod.GET)
public String listAllFiles(ModelMap model, HttpServletRequest request) {
public String listAllFiles(ModelMap model, HttpServletRequest request) throws InvalidRepositoryPathException {
String fullpath = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
fullpath = fullpath.substring(CONTROLLER_PATH.length());
......@@ -86,12 +86,13 @@ public class RepositoryGalleryController extends BaseController {
}
@RequestMapping(value = "/edit", method = RequestMethod.GET)
public String getEditPage(@RequestParam String galleryPath, ModelMap model) throws NoSuchRepositoryFileException {
public String getEditPage(@RequestParam String galleryPath, ModelMap model) throws NoSuchRepositoryFileException, InvalidRepositoryPathException {
ImageGallery imageGallery = imageGalleryService.loadImageGallery(Paths.get(galleryPath));
if (imageGallery == null) {
imageGallery = new ImageGallery();
imageGallery.setPath(galleryPath);
}
model.addAttribute("galleryPath", galleryPath);
model.addAttribute("imageGallery", imageGallery);
return JSP_PATH + "/edit";
......
......@@ -15,7 +15,10 @@
*/
package org.genesys2.spring.config;
import java.nio.file.Paths;
import org.genesys.blocks.security.service.CustomAclService;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.migration.RepositoryUpgrade20180920;
import org.genesys.filerepository.model.RepositoryFolder;
import org.genesys.filerepository.service.RepositoryService;
......@@ -26,6 +29,7 @@ import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
/**
* Declare sorts of things that upgrade the existing database
......@@ -67,6 +71,7 @@ public class ApplicationUpgrades implements InitializingBean {
*/
// TODO Remove in 2.5
@Bean
@DependsOn({ "currentApplicationContext" })
protected RepositoryUpgrade20180920 repositoryUpgrade20180920() throws Exception {
return new RepositoryUpgrade20180920();
}
......@@ -78,15 +83,19 @@ public class ApplicationUpgrades implements InitializingBean {
LOG.warn("Updating permissions on public folders");
asAdminInvoker.invoke(() -> {
for (RepositoryFolder repositoryFolder : repositoryService.getFolders(null)) {
for (RepositoryFolder repositoryFolder : repositoryService.getFolders(Paths.get("/"))) {
LOG.warn("Making {} publicly readable", repositoryFolder.getPath());
aclService.addCreatorPermissions(repositoryFolder);
repositoryService.listPaths(repositoryFolder.getFolderPath()).forEach(subFolder -> {
aclService.addCreatorPermissions(subFolder);
repositoryService.getFiles(subFolder.getFolderPath()).forEach(file -> {
aclService.addCreatorPermissions(file);
});
try {
repositoryService.getFiles(subFolder.getFolderPath()).forEach(file -> {
aclService.addCreatorPermissions(file);
});
} catch (InvalidRepositoryPathException e) {
LOG.error("Error updating permissions: {}", e.getMessage());
}
});
}
......
......@@ -11,7 +11,7 @@
<c:out value="${imageGallery.description}" />
</div>
<a href="<c:url value="/admin/r/g" />" class="btn btn-default"><spring:message code="cancel" /></a>
<a href="<c:url value="/admin/r/files${imageGallery.path}" />" class="btn btn-default"><spring:message code="navigate.back" /></a>
<a href="<c:url value="/admin/r/files${imageGallery.path}/" />" class="btn btn-default"><spring:message code="navigate.back" /></a>
<div class="row" id="imagegallery-thumbs">
<c:forEach items="${imageGallery.images}" var="image">
......
......@@ -13,12 +13,12 @@
code="cancel" /></a>
<h4>
Updating metadata for image gallery
<c:out value="${imageGallery.path}" />
<c:out value="${galleryPath}" />
</h4>
<form action="<c:url value="/admin/r/g/update" />" method="post">
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
<input type="hidden" name="galleryPath" value="<c:out value="${imageGallery.folder.path}" />">
<input type="hidden" name="galleryPath" value="<c:out value="${galleryPath}" />">
<div class="form-group">
<label for="title"><spring:message
......
......@@ -15,7 +15,7 @@
</div>
<div class="margin-top-20">
<a href="<c:url value="/wiews/${wiewsCode}/files/gallery" />" class="btn btn-default"><spring:message code="cancel"/></a>
<a href="<c:url value="/wiews/${wiewsCode}/files${gallerySubPath}" />" class="btn btn-default"><spring:message code="navigate.back"/></a>
<a href="<c:url value="/wiews/${wiewsCode}/files${galleryPath.substring(galleryPath.indexOf('/', 8))}/" />" class="btn btn-default"><spring:message code="navigate.back"/></a>
</div>
<div class="row" id="imagegallery-thumbs">
<c:forEach items="${imageGallery.images}" var="image">
......
......@@ -15,12 +15,12 @@
<h4>
Updating metadata for image gallery
<strong><c:out value="${imageGallery.path}" /></strong>
<strong><c:out value="${galleryPath}" /></strong>
</h4>
<form action="<c:url value="/wiews/${wiewsCode}/files/gallery/update" />" method="post">
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
<input type="hidden" name="galleryPath" value="<c:out value="${imageGallery.folder.path}" />">
<input type="hidden" name="galleryPath" value="<c:out value="${galleryPath}" />">
<div class="row">
<div class="col-md-6 margin-top-20">
......
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