Commit ae7d8571 authored by Andrey Lugovskiy's avatar Andrey Lugovskiy
Browse files

- added MeController

 - added getPartners, getDatasets and getDescriptor for current user
 - code cleanUp
parent 4a61125f
......@@ -178,7 +178,7 @@
<groupId>org.springframework</groupId>
</exclusion>
</exclusions>
<scope>test</scope>
<scope>provided</scope>
</dependency>
<dependency>
......@@ -225,7 +225,6 @@
<version>2.3</version>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
......@@ -254,13 +253,6 @@
<version>${hsqldb.version}</version>
<scope>test</scope>
</dependency>
<!-- <dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.41</version>
<scope>test</scope>
</dependency> -->
<dependency>
<groupId>org.springframework</groupId>
......@@ -300,6 +292,7 @@
<artifactId>application-blocks-core</artifactId>
<version>${application.blocks.version}</version>
</dependency>
<dependency>
<groupId>org.genesys-pgr</groupId>
<artifactId>application-blocks-security</artifactId>
......@@ -353,5 +346,6 @@
</exclusions>
</dependency>
</dependencies>
</dependencies>
</project>
......@@ -16,13 +16,16 @@
package org.genesys.catalog.persistence.dataset;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.service.filters.DatasetFilter;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.UUID;
@Repository
......@@ -35,4 +38,6 @@ public interface DatasetRepository extends JpaRepository<Dataset, Long>, QueryDs
@Query("select distinct d from Dataset d where d.versions.currentVersion.uuid = d.uuid")
Page<Dataset> listAllCurrentVersion(Pageable page);
@Query("select distinct d from Dataset d where d.id in :ids")
List<Dataset> loadListByIds(@Param("ids") List<Long> ids);
}
......@@ -15,11 +15,18 @@
*/
package org.genesys.catalog.persistence.traits;
import java.util.List;
import java.util.UUID;
import org.genesys.catalog.model.traits.Descriptor;
import org.genesys.catalog.service.filters.DatasetFilter;
import org.genesys.catalog.service.filters.DescriptorFilter;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
@Repository
......@@ -28,4 +35,7 @@ public interface DescriptorRepository extends JpaRepository<Descriptor, Long>, Q
Descriptor findByUuid(UUID uuid);
Descriptor findByUuidAndVersion(UUID uuid, int version);
@Query("select distinct d from Dataset d where d.id in :ids")
List<Descriptor> loadListByIds(@Param("ids") List<Long> ids);
}
......@@ -123,6 +123,22 @@ public interface DatasetService {
*/
Page<Dataset> loadListByFilter(DatasetFilter filter, Pageable page);
/**
* List of dataset matching the filter by current user
*
* @param filter filter data
* @param page Pageable
* @return list of Dataset
*/
Page<Dataset> loadListByCurrentUserByFilter(DatasetFilter filter, Pageable page);
/**
* List of dataset by current user
*
* @return list of Dataset
*/
List<Dataset> loadListByCurrentUser();
/**
* Load list of Dataset
*
......
......@@ -20,6 +20,7 @@ import java.util.UUID;
import org.genesys.catalog.model.traits.Descriptor;
import org.genesys.catalog.service.filters.DescriptorFilter;
import org.genesys.catalog.service.filters.PartnerFilter;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PreAuthorize;
......@@ -78,6 +79,19 @@ public interface DescriptorService {
*/
Page<Descriptor> listDescriptorLists(Pageable page);
/**
* Page with descriptor list by user
* @param page parameters
* @return Page with descriptor list
*/
Page<Descriptor> loadListByCurrentUserByFilter(DescriptorFilter filter, Pageable page);
/**
* Page with descriptor list by user
* @return List with descriptor list
*/
List<Descriptor> loadListByCurrentUser();
/**
* Page with list of descriptors
* @param page parameters
......
......@@ -21,6 +21,7 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PreAuthorize;
import java.util.List;
import java.util.UUID;
/**
......@@ -76,6 +77,21 @@ public interface PartnerService {
*/
Page<Partner> listPartner(Pageable page);
/**
* Load page for Partners by current user
*
* @param page page with parameters
* @return page partners
*/
Page<Partner> loadListByCurrentUserByFilter(PartnerFilter filter, Pageable page);
/**
* Load list for Partners by current user
*
* @return page partners
*/
List<Partner> loadListByCurrentUser();
/**
* Load page for Partners by filter
*
......
......@@ -15,17 +15,6 @@
*/
package org.genesys.catalog.service.impl;
import java.io.IOException;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.genesys.catalog.exceptions.NotFoundElement;
import org.genesys.catalog.exceptions.PublishValidationException;
import org.genesys.catalog.model.dataset.Dataset;
......@@ -36,6 +25,7 @@ import org.genesys.catalog.persistence.dataset.DatasetVersionsRepository;
import org.genesys.catalog.service.DatasetService;
import org.genesys.catalog.service.DescriptorService;
import org.genesys.catalog.service.filters.DatasetFilter;
import org.genesys.catalog.util.Utils;
import org.genesys.filerepository.InvalidRepositoryFileDataException;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.NoSuchRepositoryFileException;
......@@ -48,10 +38,22 @@ import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
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 java.io.IOException;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@Service
@Transactional(readOnly = true)
public class DatasetServiceImpl implements DatasetService {
......@@ -68,6 +70,9 @@ public class DatasetServiceImpl implements DatasetService {
@Autowired
private RepositoryService fileRepoService;
@Autowired
private Utils utils;
@Value("${file.repository.path}")
public String fileRepositoryPath;
......@@ -214,11 +219,34 @@ public class DatasetServiceImpl implements DatasetService {
return datasetRepository.findAll(page);
}
/**
* {@inheritDoc}
*/
@Override
public Page<Dataset> loadListByFilter(DatasetFilter filter, Pageable page) {
return datasetRepository.findAll(filter.buildQuery(), page);
}
/**
* TODO in future
* {@inheritDoc}
*/
@Override
public Page<Dataset> loadListByCurrentUserByFilter(DatasetFilter filter, Pageable page) {
// AclSid userSid = SecurityContextUtil.getCurrentUser();
// List<Long> ids = aclService.listObjectIdentityIdsForSid(Dataset.class, userSid, BasePermission.WRITE);
// return datasetRepository.loadListByFilterByIds(ids, page, filter);
return null;
}
/**
* {@inheritDoc}
*/
@Override
public List<Dataset> loadListByCurrentUser() {
return datasetRepository.loadListByIds(utils.listObjectIdentityIdsForCurrentUser(Dataset.class, BasePermission.WRITE));
}
/**
* {@inheritDoc}
*/
......
......@@ -15,15 +15,11 @@
*/
package org.genesys.catalog.service.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.genesys.catalog.model.traits.Descriptor;
import org.genesys.catalog.model.traits.Descriptor.DataType;
import org.genesys.catalog.persistence.traits.DescriptorRepository;
import org.genesys.catalog.service.DescriptorService;
import org.genesys.catalog.service.filters.DescriptorFilter;
import org.genesys.catalog.util.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -33,9 +29,14 @@ import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
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 java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@Service
@Transactional(readOnly = true)
public class DescriptorServiceImpl implements DescriptorService {
......@@ -45,6 +46,9 @@ public class DescriptorServiceImpl implements DescriptorService {
@Autowired
private DescriptorRepository descriptorRepository;
@Autowired
private Utils utils;
/**
* {@inheritDoc}
*/
......@@ -140,6 +144,26 @@ public class DescriptorServiceImpl implements DescriptorService {
return descriptorRepository.findAll(page);
}
/**
* TODO in future
* {@inheritDoc}
*/
@Override
public Page<Descriptor> loadListByCurrentUserByFilter(DescriptorFilter filter, Pageable page) {
// AclSid userSid = SecurityContextUtil.getCurrentUser();
// List<Long> ids = aclService.listObjectIdentityIdsForSid(Descriptor.class, userSid, BasePermission.WRITE);
// return descriptorRepository.loadListByFilterByIds(page, filter, ids);
return null;
}
/**
* {@inheritDoc}
*/
@Override
public List<Descriptor> loadListByCurrentUser() {
return descriptorRepository.loadListByIds(utils.listObjectIdentityIdsForCurrentUser(Descriptor.class, BasePermission.WRITE));
}
/**
* {@inheritDoc}
*/
......@@ -167,7 +191,7 @@ public class DescriptorServiceImpl implements DescriptorService {
*/
private Descriptor lazyLoad(Descriptor descriptor) {
if (descriptor != null) {
if (descriptor.getDescriptorLists()!=null)
if (descriptor.getDescriptorLists() != null)
descriptor.getDescriptorLists().size();
if (descriptor.getVocabulary() != null)
descriptor.getVocabulary().getId();
......
......@@ -16,10 +16,12 @@
package org.genesys.catalog.service.impl;
import java.util.HashSet;
import java.util.List;
import java.util.UUID;
import org.genesys.catalog.service.PartnerService;
import org.genesys.catalog.service.filters.PartnerFilter;
import org.genesys.catalog.util.Utils;
import org.genesys.common.model.Partner;
import org.genesys.common.persistence.PartnerRepository;
import org.slf4j.Logger;
......@@ -30,6 +32,7 @@ import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
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;
......@@ -45,6 +48,9 @@ public class PartnerServiceImpl implements PartnerService {
@Autowired
private PartnerRepository partnerRepository;
@Autowired
private Utils utils;
/**
* {@inheritDoc}
*/
......@@ -114,6 +120,26 @@ public class PartnerServiceImpl implements PartnerService {
return partnerRepository.findAll(page);
}
/**
* TODO in future
* {@inheritDoc}
*/
@Override
public Page<Partner> loadListByCurrentUserByFilter(PartnerFilter filter, Pageable page) {
// AclSid userSid = SecurityContextUtil.getCurrentUser();
// List<Long> ids = aclService.listObjectIdentityIdsForSid(Partner.class, userSid, BasePermission.WRITE);
// return partnerRepository.loadListByFilterByIds(ids, page, filter);
return null;
}
/**
* {@inheritDoc}
*/
@Override
public List<Partner> loadListByCurrentUser() {
return partnerRepository.loadListByIds(utils.listObjectIdentityIdsForCurrentUser(Partner.class, BasePermission.WRITE));
}
/**
* {@inheritDoc}
*/
......
package org.genesys.catalog.util;
import org.genesys.blocks.security.SecurityContextUtil;
import org.genesys.blocks.security.model.AclAwareModel;
import org.genesys.blocks.security.model.AclSid;
import org.genesys.blocks.security.service.CustomAclService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.acls.model.Permission;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @author Andrey Lugovskoy.
*/
@Component
public class Utils {
@Autowired
private CustomAclService aclService;
public List<Long> listObjectIdentityIdsForCurrentUser(Class<? extends AclAwareModel> clazz, Permission permission) {
AclSid userSid = SecurityContextUtil.getCurrentUser();
return aclService.listObjectIdentityIdsForSid(clazz, userSid, permission);
}
}
......@@ -15,11 +15,17 @@
*/
package org.genesys.common.persistence;
import java.util.List;
import java.util.UUID;
import org.genesys.catalog.service.filters.PartnerFilter;
import org.genesys.common.model.Partner;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
@Repository
......@@ -31,4 +37,6 @@ public interface PartnerRepository extends JpaRepository<Partner, Long>, QueryDs
Partner findByUuidAndVersion(UUID uuid, int version);
@Query("select distinct p from Partner p where p.id in :ids")
List<Partner> loadListByIds(@Param("ids") List<Long> ids);
}
......@@ -43,7 +43,8 @@ import java.io.File;
* @author Matija Obreza
*/
@Configuration
@ComponentScan(basePackages = { "org.genesys.catalog.service", "org.genesys.filerepository.service", "org.genesys.blocks.security.service.impl" })
@ComponentScan(basePackages = { "org.genesys.catalog.service", "org.genesys.filerepository.service", "org.genesys.blocks.security.service.impl"
, "org.genesys.catalog.util" })
public class TestApplicationConfig {
@Bean
......
......@@ -33,7 +33,7 @@ import org.springframework.security.crypto.password.PasswordEncoder;
import java.io.File;
@Configuration
@ComponentScan({"org.genesys.filerepository.service", "org.genesys.catalog.service.impl",
@ComponentScan({"org.genesys.filerepository.service", "org.genesys.catalog.service.impl", "org.genesys.catalog.util",
"org.genesys.blocks.security.service.*", "org.genesys.blocks.auditlog.service.impl",
"org.genesys.catalog.server.components", "org.genesys.blocks.security.component"})
@EnableAspectJAutoProxy
......
package org.genesys.catalog.server.controller.api.v0.me;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.model.traits.Descriptor;
import org.genesys.catalog.service.DatasetService;
import org.genesys.catalog.service.DescriptorService;
import org.genesys.catalog.service.PartnerService;
import org.genesys.catalog.service.filters.DatasetFilter;
import org.genesys.catalog.service.filters.DescriptorFilter;
import org.genesys.catalog.service.filters.PartnerFilter;
import org.genesys.common.model.Partner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* @author Andrey Lugovskoy.
*/
@RestController
@RequestMapping(MeController.API_URL)
@PreAuthorize("isAuthenticated()")
public class MeController {
public static final String API_URL = "/api/v0/me";
@Autowired
private PartnerService partnerService;
@Autowired
private DatasetService datasetService;
@Autowired
private DescriptorService descriptorService;
// @GetMapping(value = "/partners")
public Page<Partner> myPartners(@RequestParam(name = "p", required = false, defaultValue = "0") final int page,
@RequestParam(name = "l", required = false, defaultValue = "50") final int pageSize,
@RequestParam(name = "d", required = false, defaultValue = "ASC") final Sort.Direction direction,
@RequestParam(name = "s", required = false, defaultValue = "id") final String[] sort, @RequestBody(required = false) PartnerFilter partnerFilter) {
return partnerService.loadListByCurrentUserByFilter(partnerFilter, new PageRequest(page, Integer.min(pageSize, 100), direction, sort));
}
@GetMapping(value = "/partners")
public List<Partner> myPartners() {
return partnerService.loadListByCurrentUser();
}
// @GetMapping(value = "/datasets")
public Page<Dataset> myDatasets(@RequestParam(name = "p", required = false, defaultValue = "0") final int page,
@RequestParam(name = "l", required = false, defaultValue = "50") final int pageSize,
@RequestParam(name = "d", required = false, defaultValue = "ASC") final Sort.Direction direction,
@RequestParam(name = "s", required = false, defaultValue = "id") final String[] sort, @RequestBody(required = false) DatasetFilter filter) {
return datasetService.loadListByCurrentUserByFilter(filter, new PageRequest(page, Integer.min(pageSize, 100), direction, sort));
}
@GetMapping(value = "/datasets")
public List<Dataset> myDatasets() {
return datasetService.loadListByCurrentUser();
}
// @GetMapping(value = "/descriptors")
public Page<Descriptor> myDescriptors(@RequestParam(name = "p", required = false, defaultValue = "0") final int page,
@RequestParam(name = "l", required = false, defaultValue = "50") final int pageSize,
@RequestParam(name = "d", required = false, defaultValue = "ASC") final Sort.Direction direction,
@RequestParam(name = "s", required = false, defaultValue = "id") final String[] sort, @RequestBody DescriptorFilter descriptorFilter) {
return descriptorService.loadListByCurrentUserByFilter(descriptorFilter, new PageRequest(page, Integer.min(pageSize, 100), direction, sort));
}
@GetMapping(value = "/descriptors")
public List<Descriptor> myDescriptors() {
return descriptorService.loadListByCurrentUser();
}
}
Supports Markdown
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