Commit e0847780 authored by Matija Obreza's avatar Matija Obreza

Removed Genesys 1 trait database

parent bbd3329c
/**
* Copyright 2014 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.genesys2.server.api;
import java.util.Collection;
import org.genesys2.server.model.genesys.Metadata;
import org.genesys2.server.model.genesys.Method;
import org.genesys2.server.model.genesys.Parameter;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.CropRule;
import org.genesys2.server.model.impl.CropTaxonomy;
import org.genesys2.server.model.impl.Team;
import org.genesys2.server.model.impl.User;
import org.springframework.data.domain.Page;
public class OAuth2Cleanup {
public static <T> T clean(T t) {
if (t instanceof User) {
final User user = (User) t;
user.setId(null);
user.setPassword(null);
}
if (t instanceof Method) {
final Method method = (Method) t;
method.setParameter(null);
}
if (t instanceof Parameter) {
final Parameter param = (Parameter) t;
param.setCrop(null);
}
if (t instanceof Crop) {
final Crop crop = (Crop) t;
crop.setCropRules(null);
}
if (t instanceof CropRule) {
final CropRule cropRule = (CropRule) t;
cropRule.setCrop(null);
cropRule.setId(null);
}
if (t instanceof CropTaxonomy) {
final CropTaxonomy cropTaxa = (CropTaxonomy) t;
cropTaxa.setCrop(null);
cropTaxa.getTaxonomy().setCropTaxonomies(null);
}
if (t instanceof Team) {
final Team team = (Team) t;
team.setMembers(null);
team.setInstitutes(null);
}
if (t instanceof Metadata) {
// Metadata metadata = (Metadata) t;
}
return t;
}
public static <T> Collection<T> clean(Collection<T> x) {
for (final T m : x) {
clean(m);
}
return x;
}
public static <T> Page<T> clean(Page<T> x) {
for (final T m : x.getContent()) {
clean(m);
}
return x;
}
}
......@@ -16,33 +16,25 @@
package org.genesys2.server.api.v0;
import java.io.EOFException;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.xml.bind.ValidationException;
import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.ModelValidationException;
import org.genesys2.server.api.OAuth2Cleanup;
import org.genesys2.server.exception.AuthorizationException;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.genesys.Parameter;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.CropRule;
import org.genesys2.server.model.impl.CropTaxonomy;
import org.genesys2.server.service.CropService;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.TraitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -65,9 +57,6 @@ public class CropsController extends ApiBaseController {
@Autowired
GenesysService genesysService;
@Autowired
TraitService traitService;
@Autowired
CropService cropService;
......@@ -138,21 +127,6 @@ public class CropsController extends ApiBaseController {
return cropService.delete(cropService.getCrop(shortName));
}
/**
* Get crop descriptors /crops/{shortName}/descriptors
* @return
*
* @return
* @throws AuthorizationException
*/
@RequestMapping(value = "/{shortName}/descriptors", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE })
public Page<Parameter> getCropDescriptors(@PathVariable("shortName") String shortName) throws AuthorizationException {
LOG.info("Getting crop descriptors {}", shortName);
final Crop crop = cropService.getCrop(shortName);
final Page<Parameter> descriptors = traitService.listTraits(crop, new PageRequest(0, 50));
return OAuth2Cleanup.clean(descriptors);
}
/**
* Get crop taxonomy rules /crops/{shortName}/rules
* @return
......@@ -200,7 +174,7 @@ public class CropsController extends ApiBaseController {
LOG.info("Getting crop taxa {}", shortName);
final Crop crop = cropService.getCrop(shortName);
final Page<CropTaxonomy> cropTaxa = cropService.getCropTaxonomies(crop, new PageRequest(0, 50));
return OAuth2Cleanup.clean(cropTaxa);
return cropTaxa;
}
/**
......@@ -230,26 +204,4 @@ public class CropsController extends ApiBaseController {
cropService.rebuildTaxonomies(crop);
}
@RequestMapping(value = "/{shortName}/descriptors/xlsx", method = RequestMethod.POST)
public void downloadExcel(ModelMap model, @PathVariable(value = "shortName") String shortName, HttpServletResponse response) throws IOException {
final Crop crop = cropService.getCrop(shortName);
if (crop == null) {
throw new NotFoundElement();
}
LOG.debug("Downloading descriptors for crop {}", shortName);
// Write descriptors to the stream.
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.addHeader("Content-Disposition", String.format("attachment; filename=\"genesys-descriptors-%1$s.xlsx\"", crop.getShortName()));
final OutputStream outputStream = response.getOutputStream();
try {
traitService.writeDescriptorsXlsx(crop, outputStream);
response.flushBuffer();
} catch (EOFException e) {
LOG.warn("Download was aborted: {}", e.getMessage());
}
}
}
......@@ -21,11 +21,8 @@ import java.util.List;
import org.genesys.blocks.oauth.service.OAuthClientDetailsService;
import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.ModelValidationException;
import org.genesys2.server.api.OAuth2Cleanup;
import org.genesys2.server.component.security.SecurityUtils;
import org.genesys2.server.exception.AuthorizationException;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.impl.User;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.TeamService;
import org.genesys2.server.service.UserService;
......@@ -161,7 +158,7 @@ public class MeController extends ApiBaseController {
throw new ModelValidationException("Validation error", violations);
}
LOG.info("Creating team {}", teamJson);
return OAuth2Cleanup.clean(teamService.addTeam(teamJson.name));
return teamService.addTeam(teamJson.name);
}
@RequestMapping(value = "/teams/{teamId}/leave", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
......
......@@ -24,15 +24,12 @@ import org.genesys.blocks.model.JsonViews;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.ModelValidationException;
import org.genesys2.server.api.OAuth2Cleanup;
import org.genesys2.server.exception.AuthorizationException;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.genesys.Parameter;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.CropRule;
import org.genesys2.server.model.impl.CropTaxonomy;
import org.genesys2.server.service.CropService;
import org.genesys2.server.service.TraitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.data.domain.Page;
......@@ -60,9 +57,6 @@ public class CropsController extends ApiBaseController {
public static final String CONTROLLER_URL = ApiBaseController.APIv1_BASE + "/crops";
@Autowired
private TraitService traitService;
@Autowired
private CropService cropService;
......@@ -163,21 +157,6 @@ public class CropsController extends ApiBaseController {
return cropService.delete(cropService.getCrop(shortName));
}
/**
* Get crop descriptors /crops/{shortName}/descriptors
* @return
*
* @return
* @throws AuthorizationException
*/
@RequestMapping(value = "/{shortName}/descriptors", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE })
public Page<Parameter> getCropDescriptors(@PathVariable("shortName") String shortName) throws AuthorizationException {
LOG.info("Getting crop descriptors {}", shortName);
final Crop crop = cropService.getCrop(shortName);
final Page<Parameter> descriptors = traitService.listTraits(crop, new PageRequest(0, 50));
return OAuth2Cleanup.clean(descriptors);
}
/**
* Get crop taxonomy rules /crops/{shortName}/rules
* @return
......@@ -225,8 +204,7 @@ public class CropsController extends ApiBaseController {
public Page<CropTaxonomy> getCropTaxa(@PathVariable("shortName") String shortName) throws AuthorizationException {
LOG.info("Getting crop taxa {}", shortName);
final Crop crop = cropService.getCrop(shortName);
final Page<CropTaxonomy> cropTaxa = cropService.getCropTaxonomies(crop, new PageRequest(0, 50));
return OAuth2Cleanup.clean(cropTaxa);
return cropService.getCropTaxonomies(crop, new PageRequest(0, 50));
}
/**
......
package org.genesys2.server.model.elastic;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.genesys2.server.model.genesys.ExperimentTrait;
import org.genesys2.server.model.genesys.Method;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Version;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldIndex;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.Parent;
@Document(indexName = "genesys", type = "trait", refreshInterval = "-1")
public class AccessionEsTrait {
private static final Logger LOG = LoggerFactory.getLogger(AccessionEsTrait.class);
@Id
private Long id;
@Version
private Long version;
@Parent(type = "mcpd")
private long accessionId;
@Field(index = FieldIndex.not_analyzed, type = FieldType.Long)
private long methodId;
@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
private Set<String> sval = new HashSet<String>();
@Field(index = FieldIndex.not_analyzed, type = FieldType.Long)
private Set<Long> ival = new HashSet<Long>();
@Field(index = FieldIndex.not_analyzed, type = FieldType.Double)
private Set<Double> dval = new HashSet<Double>();
public static List<AccessionEsTrait> traits(List<Method> listMethods, Map<Long, List<ExperimentTrait>> accessionTraitValues) {
ArrayList<AccessionEsTrait> accessionEsTraits = new ArrayList<AccessionEsTrait>();
if (listMethods == null || listMethods.isEmpty())
return accessionEsTraits;
if (accessionTraitValues == null || accessionTraitValues.isEmpty())
return accessionEsTraits;
for (Method m : listMethods) {
List<ExperimentTrait> vals = accessionTraitValues.get(m.getId());
if (vals != null && !vals.isEmpty())
accessionEsTraits.add(AccessionEsTrait.from(m, vals));
}
return accessionEsTraits;
}
public static AccessionEsTrait from(Method m, List<ExperimentTrait> vals) {
AccessionEsTrait t = new AccessionEsTrait();
t.methodId = m.getId();
t.sval = new HashSet<String>();
for (ExperimentTrait et : vals) {
if (et == null)
continue;
Object value = et.getValue();
if (value == null)
continue;
else if (value instanceof String)
t.sval.add((String) value);
else if (value instanceof Integer)
t.ival.add(((Integer) value).longValue());
else if (value instanceof Long)
t.ival.add((Long) value);
else if (value instanceof Double)
t.dval.add((Double) value);
else if (value instanceof Float)
t.dval.add(((Float) value).doubleValue());
else if (value instanceof BigDecimal)
t.dval.add(((BigDecimal) value).doubleValue());
else
LOG.warn("Unsupported value type {}", value.getClass());
}
return t;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getVersion() {
return version;
}
public void setVersion(Long version) {
this.version = version;
}
public long getAccessionId() {
return accessionId;
}
public void setAccessionId(long accessionId) {
this.accessionId = accessionId;
}
public long getMethodId() {
return methodId;
}
public void setMethodId(long methodId) {
this.methodId = methodId;
}
public Set<String> getSval() {
return sval;
}
public void setSval(Set<String> sval) {
this.sval = sval;
}
public Set<Long> getIval() {
return ival;
}
public void setIval(Set<Long> ival) {
this.ival = ival;
}
public Set<Double> getDval() {
return dval;
}
public void setDval(Set<Double> dval) {
this.dval = dval;
}
}
\ No newline at end of file
......@@ -84,10 +84,6 @@ public class AccessionId extends AuditedVersionedModel implements IdUUID {
@Type(type = "uuid-binary")
protected UUID uuid;
@OneToMany(cascade = {}, fetch = FetchType.LAZY, mappedBy = "accession", orphanRemoval = false)
@JsonIgnore
private List<AccessionTrait> traits;
@ManyToMany(cascade = {}, fetch = FetchType.LAZY)
@JoinTable(name = "accession_listitem", joinColumns = @JoinColumn(name = "acceid"), inverseJoinColumns = @JoinColumn(name = "listid"))
@JsonView({ JsonViews.Indexed.class })
......
/**
* Copyright 2014 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.genesys2.server.model.genesys;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import org.genesys.blocks.model.BasicModel;
@Entity
@Table(name = "accessiontrait", uniqueConstraints = { @UniqueConstraint(name = "UQ_accessiontrait_all", columnNames = { "metadataId", "accessionId", "methodId" }) })
public class AccessionTrait extends BasicModel {
private static final long serialVersionUID = -240056837800843686L;
@ManyToOne(cascade = {}, optional = false)
@JoinColumn(name = "accessionId")
private AccessionId accession;
@Column(name = "metadataId")
private long metadataId;
@Column(name = "methodId")
private long methodId;
public AccessionId getAccession() {
return accession;
}
public void setAccession(AccessionId accession) {
this.accession = accession;
}
public long getMetadataId() {
return metadataId;
}
public void setMetadataId(long metadataId) {
this.metadataId = metadataId;
}
public long getMethodId() {
return methodId;
}
public void setMethodId(long methodId) {
this.methodId = methodId;
}
}
/**
* Copyright 2014 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.genesys2.server.model.genesys;
/*
* Looks like {@link AccessionTrait}
*/
public class ExperimentAccessionTrait {
private long experimentId;
private long accessionId;
private Object value;
public ExperimentAccessionTrait(final long experimentId, final long accessionId, final Object value) {
this.experimentId = experimentId;
this.accessionId = accessionId;
this.value = value;
}
public long getExperimentId() {
return experimentId;
}
public void setExperimentId(final long experimentId) {
this.experimentId = experimentId;
}
public long getAccessionId() {
return accessionId;
}
public void setAccessionId(long accessionId) {
this.accessionId = accessionId;
}
public Object getValue() {
return value;
}
public void setValue(final Object value) {
this.value = value;
}
@Override
public String toString() {
return "{" + value + ", " + experimentId + "}";
}
}
/**
* Copyright 2014 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.genesys2.server.model.genesys;
public class ExperimentTrait {
private long experimentId;
private Object value;
public ExperimentTrait(final long experimentId, final Object value) {
this.experimentId = experimentId;
this.value = value;
}
public long getExperimentId() {
return experimentId;
}
public void setExperimentId(final long experimentId) {
this.experimentId = experimentId;
}
public Object getValue() {
return value;
}
public void setValue(final Object value) {
this.value = value;