Commit fb7bd137 authored by Matija Obreza's avatar Matija Obreza

Implemented filtering on institute.networks

parent ca3dccef
......@@ -66,8 +66,12 @@ public class ElasticQueryBuilder implements Visitor<Void, Void> {
} else if (path.startsWith("accessionId.")) {
// Example of @JsonUnwrapped
return path.replace("accessionId.", "");
} else if (path.equals("institute.networks.slug")) {
// Example of @JsonIdentityReference(alwaysAsId = true)
return "institute.networks";
}
}
return path;
}
......
......@@ -20,11 +20,24 @@ import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.MessageFormat;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.MapKey;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.persistence.*;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.StringUtils;
import org.genesys.blocks.model.BasicModel;
import org.genesys.blocks.model.EntityId;
......@@ -36,7 +49,11 @@ import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldIndex;
import org.springframework.data.elasticsearch.annotations.FieldType;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.databind.ObjectMapper;
@Cacheable
@Entity
......@@ -94,6 +111,13 @@ public class FaoInstitute extends BasicModel implements GeoReferencedEntity, Acl
@IgnoreField
private Map<String, FaoInstituteSetting> settings = new HashMap<String, FaoInstituteSetting>();
@JsonView({ JsonViews.Public.class })
@ManyToMany(cascade = {}, fetch = FetchType.LAZY, mappedBy = "members")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "slug")
@JsonIdentityReference(alwaysAsId = true)
@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
private List<Organization> networks;
private long accessionCount;
private boolean pgrActivity;
private boolean maintainsCollection;
......@@ -108,7 +132,6 @@ public class FaoInstitute extends BasicModel implements GeoReferencedEntity, Acl
@Column(name = "pdciHistogram")
private String pdciHistogram;
public FaoInstitute() {
}
......@@ -277,6 +300,14 @@ public class FaoInstitute extends BasicModel implements GeoReferencedEntity, Acl
this.codeSGSV = codeSGSV;
}
public List<Organization> getNetworks() {
return networks;
}
public void setNetworks(List<Organization> networks) {
this.networks = networks;
}
public Double getPdciMin() {
return pdciMin;
}
......
......@@ -40,7 +40,7 @@ public class Organization extends AuditedModel {
private static final long serialVersionUID = 2710908645431936666L;
@Column(nullable = false, length = 150)
@Column(nullable = false, length = 150, unique = true)
private String slug;
@Lob
......
......@@ -71,8 +71,7 @@ public class SubsetController extends BaseController {
public String listSubsets(final HttpServletResponse response, final ModelMap model, @RequestParam(value = "page", required = false, defaultValue = "1") int page,
@RequestParam(value = "results", required = true, defaultValue = "50") int results) throws IOException {
final SubsetFilter filter = new SubsetFilter();
filter.state.add(PublishState.PUBLISHED);
final SubsetFilter filter = new SubsetFilter().state(PublishState.PUBLISHED);
final Page<Subset> subsets = subsetService.list(filter, new PageRequest(page - 1, Integer.min(results, maxPageSize), new Sort("id")));
model.addAttribute("pagedData", subsets);
......
......@@ -462,6 +462,16 @@ public class AppliedFiltersConverter {
code.addAll(codes);
break;
}
case "networks": {
Set<String> networks = ff.networks;
if (networks == null) {
networks = ff.networks = new HashSet<>();
}
Set<String> codes = toStringSet(af);
LOG.debug("Got Institute networks {}", codes);
networks.addAll(codes);
break;
}
default:
throw new RuntimeException("Unhandled Institute filter property=" + filterName);
}
......
......@@ -19,6 +19,7 @@ import static org.genesys2.server.model.impl.QFaoInstitute.faoInstitute;
import java.util.Set;
import org.apache.commons.collections.CollectionUtils;
import org.genesys.blocks.model.filters.BasicModelFilter;
import org.genesys.blocks.model.filters.StringFilter;
import org.genesys2.server.model.impl.FaoInstitute;
......@@ -45,6 +46,9 @@ public class InstituteFilter extends BasicModelFilter<InstituteFilter, FaoInstit
/** The accessions. */
public Boolean accessions;
/** The networks. */
public Set<String> networks;
/**
* Builds the query.
*
......@@ -81,6 +85,10 @@ public class InstituteFilter extends BasicModelFilter<InstituteFilter, FaoInstit
}
}
if (CollectionUtils.isNotEmpty(networks)) {
and.and(institute.networks.any().slug.in(networks));
}
return and;
}
......
......@@ -185,6 +185,7 @@ public class SubsetRestControllerTest extends AbstractApiTest {
assertThat(storedSubset.getAccessionIds().size(), is(1));
storedSubset.getInstitute().setSettings(null);
storedSubset.getInstitute().setNetworks(null);
final String s = verboseMapper.writeValueAsString(storedSubset);
/*@formatter:off*/
......
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