Commit fbf47ce6 authored by Matija Obreza's avatar Matija Obreza

Merge branch 'merge-catalog-tests' into 'master'

Merge catalog tests

See merge request genesys-pgr/genesys-server!165
parents 65e83758 a878520e
......@@ -79,7 +79,7 @@
<querydsl.version>4.1.4</querydsl.version>
<hibernate.version>4.3.11.Final</hibernate.version>
<hsqldb.version>2.3.3</hsqldb.version>
<hsqldb.version>2.3.6</hsqldb.version>
<ehcache.version>2.7.4</ehcache.version>
<slf4j.version>1.7.21</slf4j.version>
......@@ -268,6 +268,13 @@
<version>${spring-data-jpa.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<version>${spring.security.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
......@@ -646,12 +653,8 @@
<version>2.19.1</version>
<configuration>
<forkMode>once</forkMode>
<argLine>-Xms512m -Xmx1024m</argLine>
<argLine>-Xms512m -Xmx1024m -server</argLine>
<testFailureIgnore>false</testFailureIgnore>
<includes>
<!-- Only API documentation -->
<include>*.docs.*Test.java</include>
</includes>
</configuration>
</plugin>
<plugin>
......@@ -864,6 +867,10 @@
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>${project.build.directory}/generated-resources</directory>
<filtering>false</filtering>
......
......@@ -61,7 +61,7 @@ import io.swagger.annotations.Api;
public class DatasetController {
// Rest controller base URL
protected static final String CONTROLLER_URL = ApiBaseController.APIv0_BASE + "/dataset";
public static final String CONTROLLER_URL = ApiBaseController.APIv0_BASE + "/dataset";
private static final Logger LOG = LoggerFactory.getLogger(DatasetController.class);
......
......@@ -49,7 +49,7 @@ import java.util.UUID;
public class DatasetCreatorController {
/** The Constant API_BASE. */
protected static final String CONTROLLER_URL = DatasetController.CONTROLLER_URL + "/{UUID}/datasetcreator";
public static final String CONTROLLER_URL = DatasetController.CONTROLLER_URL + "/{UUID}/datasetcreator";
/** The dataset service. */
@Autowired
......
......@@ -116,7 +116,7 @@ public class DescriptorController {
* @throws IOException
*/
@PostMapping(value = "/list")
public FilteredPage<Descriptor> listDescriptorsByFilter(@RequestParam(name = "p", required = false, defaultValue = "0") final int page,
public FilteredPage<Descriptor> listDescriptors(@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,
......@@ -141,7 +141,7 @@ public class DescriptorController {
* @param filterCode the filter code
* @return the filtered page
* @throws IOException Signals that an I/O exception has occurred.
* @deprecated Use {@link #listDescriptorsByFilter(int, int, org.springframework.data.domain.Sort.Direction, String[], DescriptorFilter)}
* @deprecated Use {@link #listDescriptors(int, int, org.springframework.data.domain.Sort.Direction, String[], DescriptorFilter)}
*/
@PostMapping(value = "/list/{filterCode}")
public FilteredPage<Descriptor> listDescriptorsByShort(@RequestParam(name = "p", required = false, defaultValue = "0") final int page,
......
......@@ -41,7 +41,7 @@ import java.util.Map;
public class DescriptorListExporter {
@Autowired
private FreemarkerTemplating freemarker;
private FreemarkerTemplating freemarkerTemplating;
/** The Constant OPTIONS. */
/*@formatter:off*/
......@@ -75,7 +75,7 @@ public class DescriptorListExporter {
public String markdownDescriptorList(final DescriptorList descriptorList) throws FreemarkerException {
final Map<String, Object> root = new HashMap<>();
root.put("descriptorList", descriptorList);
return freemarker.processTemplateResource("descriptorlist/booklet.ftl", root);
return freemarkerTemplating.processTemplateResource("descriptorlist/booklet.ftl", root);
}
/**
......@@ -88,7 +88,7 @@ public class DescriptorListExporter {
public String htmlDescriptorList(final DescriptorList descriptorList) throws FreemarkerException {
final Map<String, Object> root = new HashMap<>();
root.put("descriptorList", descriptorList);
final String markdown = freemarker.processTemplateResource("descriptorlist/booklet.ftl", root);
final String markdown = freemarkerTemplating.processTemplateResource("descriptorlist/booklet.ftl", root);
// System.err.println(markdown);
final Parser parser = Parser.builder(OPTIONS).build();
......@@ -103,7 +103,7 @@ public class DescriptorListExporter {
root.put("author", StringUtils.defaultIfEmpty(descriptorList.getPublisher(), descriptorList.getOwner().getName()));
root.put("html", html);
return freemarker.processTemplateResource("html.ftl", root);
return freemarkerTemplating.processTemplateResource("html.ftl", root);
}
}
......@@ -79,7 +79,7 @@ public class DatasetServiceImpl implements DatasetService {
/** The file repo service. */
@Autowired
private RepositoryService fileRepoService;
private RepositoryService repositoryService;
@Autowired
private CustomAclService aclService;
......@@ -304,7 +304,7 @@ public class DatasetServiceImpl implements DatasetService {
InvalidRepositoryFileDataException {
dataset = datasetRepository.findByUuidAndVersion(dataset.getUuid(), dataset.getVersion());
final RepositoryFile repositoryFile = fileRepoService.addFile(Paths.get(datasetRepositoryPath, dataset.getUuid().toString()).toAbsolutePath().toString(), file
final RepositoryFile repositoryFile = repositoryService.addFile(Paths.get(datasetRepositoryPath, dataset.getUuid().toString()).toAbsolutePath().toString(), file
.getOriginalFilename(), file.getContentType(), file.getBytes(), null);
dataset.getRepositoryFiles().add(repositoryFile);
return lazyLoad(datasetRepository.save(dataset));
......@@ -320,7 +320,7 @@ public class DatasetServiceImpl implements DatasetService {
if (datasetFile == null) {
throw new NotFoundElement("No such dataset file");
}
final RepositoryFile updated = fileRepoService.updateMetadata(metadata);
final RepositoryFile updated = repositoryService.updateMetadata(metadata);
// replace it
dataset.getRepositoryFiles().replaceAll(df -> df.getUuid().equals(datasetFile.getUuid()) ? updated : df);
return lazyLoad(dataset);
......@@ -335,9 +335,9 @@ public class DatasetServiceImpl implements DatasetService {
public Dataset removeDatasetFile(Dataset dataset, final UUID fileUuid) throws NotFoundElement, NoSuchRepositoryFileException, IOException {
dataset = datasetRepository.findByUuidAndVersion(dataset.getUuid(), dataset.getVersion());
final RepositoryFile repositoryFile = fileRepoService.getFile(fileUuid);
final RepositoryFile repositoryFile = repositoryService.getFile(fileUuid);
dataset.getRepositoryFiles().remove(repositoryFile);
fileRepoService.removeFile(repositoryFile);
repositoryService.removeFile(repositoryFile);
return lazyLoad(datasetRepository.save(dataset));
}
......
......@@ -43,10 +43,12 @@ import io.swagger.annotations.Api;
@Controller("adminCacheApi0")
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = { "/api/v0/admin/cache", "/json/v0/cache" })
@RequestMapping(value = { CacheController.API_URL, "/json/v0/cache" })
@Api(tags = { "admin" })
public class CacheController extends ApiBaseController {
public final static String API_URL = ApiBaseController.APIv0_ADMIN_BASE + "/cache";
@Autowired
private MappingService mappingService;
......
......@@ -56,7 +56,7 @@ import net.sf.oval.Validator;
@Api(tags = { "crop" })
public class CropsController extends ApiBaseController {
protected static final String CONTROLLER_URL = ApiBaseController.APIv0_BASE + "/crops";
public static final String CONTROLLER_URL = ApiBaseController.APIv0_BASE + "/crops";
@Autowired
GenesysService genesysService;
......
......@@ -62,7 +62,7 @@ public class PermissionController extends ApiBaseController {
@RequestMapping(value = "/add", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ApiResult addPermission(@RequestBody PermissionJson permissionJson) {
LOG.info("Adding permission {}", permissionJson);
final AclObjectIdentity oid = aclService.getObjectIdentity(permissionJson.getOid(), permissionJson.getClazz());
final AclObjectIdentity oid = aclService.ensureObjectIdentity(permissionJson.getOid(), permissionJson.getClazz());
if (permissionJson.getAuthority() != null) {
final AclSid sid = aclService.getAuthoritySid(permissionJson.getAuthority());
......
......@@ -80,7 +80,7 @@ public class AccessionId extends AuditedVersionedModel implements IdUUID {
@OneToOne(fetch = FetchType.LAZY, cascade = { CascadeType.ALL }, optional = true, orphanRemoval = true)
@JoinColumn(name = "pdciId", unique = true)
@JsonIgnoreProperties({ "accession" })
@JsonView({ JsonViews.Root.class })
@JsonView({ JsonViews.Internal.class })
private PDCI pdci;
@Column(name = "storage", nullable = false)
......
......@@ -49,7 +49,7 @@ public class AccessionListServiceImpl implements AccessionListService {
@Autowired
AccessionListRepository accessionListRepository;
@Autowired
@Autowired(required = false)
ElasticUpdater elasticUpdater;
@Override
......@@ -95,9 +95,10 @@ public class AccessionListServiceImpl implements AccessionListService {
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#accessionList, 'WRITE')")
@Transactional
public void removeAll(AccessionList accessionList) {
// Re-index
elasticUpdater.updateAll(Accession.class, accessionListRepository.getAccessionIds(accessionList).toArray(ArrayUtils.EMPTY_LONG_OBJECT_ARRAY));
if (elasticUpdater!=null) {
// Re-index
elasticUpdater.updateAll(Accession.class, accessionListRepository.getAccessionIds(accessionList).toArray(ArrayUtils.EMPTY_LONG_OBJECT_ARRAY));
}
accessionListRepository.removeAll(accessionList);
}
......@@ -105,9 +106,10 @@ public class AccessionListServiceImpl implements AccessionListService {
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#accessionList, 'WRITE')")
@Transactional
public void addToList(AccessionList list, AccessionData accession) {
// Re-index
elasticUpdater.update(Accession.class, accession.getId());
if (elasticUpdater!=null) {
// Re-index
elasticUpdater.update(Accession.class, accession.getId());
}
accessionListRepository.addOne(list, accession.getAccessionId());
}
......@@ -120,22 +122,28 @@ public class AccessionListServiceImpl implements AccessionListService {
accessionListRepository.addAll(acceList, accessionIds);
// Re-index
elasticUpdater.updateAll(Accession.class, accessionIds.toArray(ArrayUtils.EMPTY_LONG_OBJECT_ARRAY));
if (elasticUpdater!=null) {
// Re-index
elasticUpdater.updateAll(Accession.class, accessionIds.toArray(ArrayUtils.EMPTY_LONG_OBJECT_ARRAY));
}
}
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#accessionList, 'WRITE')")
@Transactional
public void setList(AccessionList accessionList, Collection<Long> accessionIds) {
// Re-index
elasticUpdater.updateAll(Accession.class, accessionListRepository.getAccessionIds(accessionList).toArray(ArrayUtils.EMPTY_LONG_OBJECT_ARRAY));
if (elasticUpdater!=null) {
// Re-index
elasticUpdater.updateAll(Accession.class, accessionListRepository.getAccessionIds(accessionList).toArray(ArrayUtils.EMPTY_LONG_OBJECT_ARRAY));
}
accessionListRepository.removeAll(accessionList);
accessionListRepository.addAll(accessionList, accessionIds);
// Re-index
elasticUpdater.updateAll(Accession.class, accessionIds.toArray(ArrayUtils.EMPTY_LONG_OBJECT_ARRAY));
if (elasticUpdater!=null) {
// Re-index
elasticUpdater.updateAll(Accession.class, accessionIds.toArray(ArrayUtils.EMPTY_LONG_OBJECT_ARRAY));
}
}
@Override
......@@ -144,17 +152,20 @@ public class AccessionListServiceImpl implements AccessionListService {
public void addToList(AccessionList accessionList, AppliedFilters filters) {
accessionListRepository.addAll(accessionList, filters);
// Re-index
elasticUpdater.updateAll(Accession.class, accessionListRepository.getAccessionIds(accessionList).toArray(ArrayUtils.EMPTY_LONG_OBJECT_ARRAY));
if (elasticUpdater!=null) {
// Re-index
elasticUpdater.updateAll(Accession.class, accessionListRepository.getAccessionIds(accessionList).toArray(ArrayUtils.EMPTY_LONG_OBJECT_ARRAY));
}
}
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#accessionList, 'DELETE')")
@Transactional
public void delete(AccessionList accessionList) {
// Re-index
elasticUpdater.updateAll(Accession.class, accessionListRepository.getAccessionIds(accessionList).toArray(ArrayUtils.EMPTY_LONG_OBJECT_ARRAY));
if (elasticUpdater!=null) {
// Re-index
elasticUpdater.updateAll(Accession.class, accessionListRepository.getAccessionIds(accessionList).toArray(ArrayUtils.EMPTY_LONG_OBJECT_ARRAY));
}
accessionListRepository.delete(accessionList);
}
......
......@@ -25,6 +25,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import javax.annotation.Resource;
......@@ -58,8 +59,6 @@ import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import com.hazelcast.core.ILock;
@Service
public class ElasticSearchManagementServiceImpl implements ElasticSearchManagementService {
......@@ -81,7 +80,7 @@ public class ElasticSearchManagementServiceImpl implements ElasticSearchManageme
private GenesysLowlevelRepository genesysLowlevelRepository;
@Resource
private ILock elasticsearchAdminLock;
private Lock elasticsearchAdminLock;
private final Map<String, Class<?>> clazzMap;
......
......@@ -15,10 +15,7 @@
**/
package org.genesys2.server.service.impl;
import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
import static org.elasticsearch.index.query.QueryBuilders.functionScoreQuery;
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
import static org.elasticsearch.index.query.QueryBuilders.queryStringQuery;
import static org.elasticsearch.index.query.QueryBuilders.*;
import static org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders.fieldValueFactorFunction;
import java.util.ArrayList;
......@@ -35,7 +32,6 @@ import org.genesys2.server.model.impl.ActivityPost;
import org.genesys2.server.model.impl.Article;
import org.genesys2.server.model.impl.Country;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.mvc.JspHelper;
import org.genesys2.server.persistence.ActivityPostRepository;
import org.genesys2.server.persistence.ArticleRepository;
import org.genesys2.server.persistence.CountryRepository;
......@@ -86,9 +82,6 @@ public class FullTextSearchServiceImpl implements FullTextSearchService, Initial
@Autowired
private FaoInstituteRepository instituteRepository;
@Autowired
private JspHelper jspHelper;
@Autowired
private ContentService contentService;
......@@ -326,7 +319,7 @@ public class FullTextSearchServiceImpl implements FullTextSearchService, Initial
document.setSummary(activityPost.getTitle());
document.setCreatedDate(activityPost.getCreatedDate());
document.setLastModifiedDate(activityPost.getLastModifiedDate());
document.setUrlToContent("/content/news/" + activityPost.getId() + "/" + this.jspHelper.suggestUrlForText(activityPost.getTitle()));
document.setUrlToContent("/content/news/" + activityPost.getId() + "/");
}
private void updateDocument(Country country, FullTextDocument document) {
......
......@@ -14,7 +14,7 @@
* limitations under the License.
**/
package org.genesys2.server.persistence;
package org.genesys2.server.service.impl;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
......@@ -24,7 +24,8 @@ import java.sql.SQLException;
import java.util.List;
import org.genesys2.server.model.genesys.Method;
import org.genesys2.server.service.impl.DirectMysqlQuery;
import org.genesys2.server.persistence.GenesysLowlevelRepository;
import org.genesys2.server.persistence.MethodRepository;
import org.genesys2.server.service.impl.DirectMysqlQuery.MethodResolver;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.slf4j.Logger;
......
......@@ -17,6 +17,7 @@
package org.genesys2.server.service.impl;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import javax.annotation.Resource;
......@@ -49,7 +50,7 @@ public class TaxonomyManager {
* update logic
*/
@Resource
private ILock taxonomyUpdateLock;
private Lock taxonomyUpdateLock;
public Taxonomy2 ensureTaxonomy2(String genus, String species, String spAuthor, String subtaxa, String subtAuthor) {
if (StringUtils.isBlank(genus)) {
......
......@@ -14,7 +14,7 @@
* limitations under the License.
**/
package org.genesys2.server.persistence;
package org.genesys2.server.service.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
......@@ -37,6 +37,11 @@ import org.genesys2.server.model.genesys.ExperimentAccessionTrait;
import org.genesys2.server.model.genesys.ExperimentTrait;
import org.genesys2.server.model.genesys.Metadata;
import org.genesys2.server.model.genesys.Method;
import org.genesys2.server.persistence.AccessionTraitRepository;
import org.genesys2.server.persistence.MetadataAccessionRepository;
import org.genesys2.server.persistence.MetadataMethodRepository;
import org.genesys2.server.persistence.MethodRepository;
import org.genesys2.server.persistence.TraitValueRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -51,7 +56,7 @@ import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
@Repository
@Transactional(readOnly = true)
//@Transactional(readOnly = true)
public class TraitValueRepositoryImpl implements TraitValueRepository {
public static final Logger LOG = LoggerFactory.getLogger(TraitValueRepository.class);
private JdbcTemplate jdbcTemplate;
......
......@@ -22,6 +22,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import javax.annotation.Resource;
......@@ -34,8 +35,6 @@ import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.query.IndexQuery;
import org.springframework.stereotype.Component;
import com.hazelcast.core.IQueue;
/**
* Component that receives updated or deleted accession IDs and uses a
* background thread to refresh ES
......@@ -50,10 +49,10 @@ public class ElasticUpdater {
private ElasticsearchTemplate elasticsearchTemplate;
@Resource
private IQueue<ElasticNode> elasticRemoveQueue;
private BlockingQueue<ElasticNode> elasticRemoveQueue;
@Resource
private IQueue<ElasticNode> elasticUpdateQueue;
private BlockingQueue<ElasticNode> elasticUpdateQueue;
/**
* Schedule objects for removal
......
......@@ -337,7 +337,10 @@ public class ElasticUpdaterAspect {
if (LOG.isTraceEnabled()) {
LOG.trace("Returning from {} id={}", joinPoint.toLongString(), (long) joinPoint.getArgs()[0]);
}
elasticUpdater.remove(Article.class, (Long) joinPoint.getArgs()[0]);
// test for deleteAll with no args
if (joinPoint.getArgs().length > 0) {
elasticUpdater.remove(Article.class, (Long) joinPoint.getArgs()[0]);
}
}
/**
......@@ -352,7 +355,10 @@ public class ElasticUpdaterAspect {
if (LOG.isTraceEnabled()) {
LOG.trace("Returning from {} id={}", joinPoint.toLongString(), (long) joinPoint.getArgs()[0]);
}
elasticUpdater.remove(FullTextDocument.class, (Long) joinPoint.getArgs()[0]);
// test for deleteAll with no args
if (joinPoint.getArgs().length > 0) {
elasticUpdater.remove(FullTextDocument.class, (Long) joinPoint.getArgs()[0]);
}
}
/**
......@@ -367,7 +373,10 @@ public class ElasticUpdaterAspect {
if (LOG.isTraceEnabled()) {
LOG.trace("Returning from {} id={}", joinPoint.toLongString(), (long) joinPoint.getArgs()[0]);
}
elasticUpdater.remove(Country.class, (Long) joinPoint.getArgs()[0]);
// test for deleteAll with no args
if (joinPoint.getArgs().length > 0) {
elasticUpdater.remove(Country.class, (Long) joinPoint.getArgs()[0]);
}
}
/**
......@@ -382,6 +391,9 @@ public class ElasticUpdaterAspect {
if (LOG.isTraceEnabled()) {
LOG.trace("Returning from {} id={}", joinPoint.toLongString(), (long) joinPoint.getArgs()[0]);
}
elasticUpdater.remove(FaoInstitute.class, (Long) joinPoint.getArgs()[0]);
// test for deleteAll with no args
if (joinPoint.getArgs().length > 0) {
elasticUpdater.remove(FaoInstitute.class, (Long) joinPoint.getArgs()[0]);
}
}
}
......@@ -3,6 +3,7 @@ package org.genesys2.server.service.worker;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import javax.annotation.Resource;
......@@ -17,14 +18,12 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
import com.hazelcast.core.IQueue;
/**
* ES Processor component uses Spring's @Scheduled annotation to scan queues with 2000ms delay measured from the
* completion time of each preceding invocation.
*/
@Component
class ElasticUpdaterProcessor {
public class ElasticUpdaterProcessor {
public static final Logger LOG = LoggerFactory.getLogger(ElasticUpdaterProcessor.class);
private static final int BATCH_SIZE = 100;
......@@ -39,10 +38,10 @@ class ElasticUpdaterProcessor {
private ThreadPoolTaskExecutor executor;
@Resource
private IQueue<ElasticNode> elasticRemoveQueue;
private BlockingQueue<ElasticNode> elasticRemoveQueue;
@Resource
private IQueue<ElasticNode> elasticUpdateQueue;
private BlockingQueue<ElasticNode> elasticUpdateQueue;
private HashMap<String, Set<Long>> buckets = new HashMap<String, Set<Long>>();
......
......@@ -33,16 +33,23 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.Import;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.core.annotation.Order;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;