Commit 30e22d35 authored by Matija Obreza's avatar Matija Obreza
Browse files

Use MetadataMethod for faster lookups

parent 89227162
package org.crophub.rest.common.model.genesys;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name = "metadatamethod")
public class MetadataMethod implements Serializable {
private static final long serialVersionUID = -240056837800843686L;
private Long id;
private Metadata metadata;
private Method method;
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@ManyToOne(cascade = {}, optional = false)
@JoinColumn(name = "metadataId")
public Metadata getMetadata() {
return metadata;
}
public void setMetadata(Metadata metadata) {
this.metadata = metadata;
}
@ManyToOne(cascade = {}, optional = false)
@JoinColumn(name = "methodId")
public Method getMethod() {
return method;
}
public void setMethod(Method method) {
this.method = method;
}
}
/**
* Copyright 2013 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package org.crophub.rest.common.persistence.domain;
import java.util.List;
import org.crophub.rest.common.model.genesys.Metadata;
import org.crophub.rest.common.model.genesys.MetadataMethod;
import org.crophub.rest.common.model.genesys.Method;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
public interface MetadataMethodRepository extends JpaRepository<MetadataMethod, Long> {
List<MetadataMethod> findByMetadata(Metadata metadata);
List<MetadataMethod> findByMethod(Method method);
@Query("select distinct mm.method from MetadataMethod mm where mm.metadata = ?1")
List<Method> listMetadataMethods(Metadata metadata);
}
......@@ -16,6 +16,7 @@ import org.crophub.rest.common.persistence.domain.AccessionCollectRepository;
import org.crophub.rest.common.persistence.domain.AccessionNameRepository;
import org.crophub.rest.common.persistence.domain.AccessionRepository;
import org.crophub.rest.common.persistence.domain.AccessionTraitRepository;
import org.crophub.rest.common.persistence.domain.MetadataMethodRepository;
import org.crophub.rest.common.persistence.domain.MetadataRepository;
import org.crophub.rest.common.persistence.domain.MethodRepository;
import org.crophub.rest.common.service.GenesysService;
......@@ -43,6 +44,8 @@ public class GenesysServiceImpl implements GenesysService {
private AccessionTraitRepository accessionTraitRepository;
@Autowired
private MetadataRepository metadataRepository;
@Autowired
private MetadataMethodRepository metadataMethodRepository;
@Autowired
private MethodRepository methodRepository;
......@@ -109,7 +112,7 @@ public class GenesysServiceImpl implements GenesysService {
public List<Metadata> listMetadata(Accession accession) {
return accessionTraitRepository.listMetadata(accession);
}
@Override
public Page<Metadata> listMetadata(PageRequest pageRequest) {
return metadataRepository.findAll(pageRequest);
......@@ -119,12 +122,11 @@ public class GenesysServiceImpl implements GenesysService {
public Metadata getMetadata(long metadataId) {
return metadataRepository.findOne(metadataId);
}
@Override
public List<Method> listMethods(Metadata metadata) {
return accessionTraitRepository.listMetadataMethods(metadata);
return metadataMethodRepository.listMetadataMethods(metadata);
}
@Override
public Page<Accession> listMetadataAccessions(Metadata metadata, PageRequest pageRequest) {
......
......@@ -37,7 +37,7 @@
<!-- Closed page and Authentication filter -->
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/data/**" access="isAuthenticated()" />
<!-- <intercept-url pattern="/data/**" access="isAuthenticated()" /> -->
<!--Override default login and logout pages -->
<form-login login-page="/login" login-processing-url="/login-attempt" authentication-failure-url="/login?error=1" default-target-url="/" />
......
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