Commit 5742de5a authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch '194-optional-instcode-in-add-many' into 'master'

Optional INSTCODE in "add many"

Closes #194

See merge request genesys-pgr/genesys-server!101
parents e0752d2b c80dedd9
......@@ -201,6 +201,12 @@ public interface GenesysService {
*/
Accession getAccession(String instCode, String acceNumb) throws NonUniqueAccessionException;
/**
* @param acceNumb
* @return list of accessions
*/
List<Accession> listAccessions(String acceNumb);
List<FaoInstitute> findHoldingInstitutes(Set<Long> accessionIds);
Set<Long> listAccessions(FaoInstitute holdingInstitute, Set<Long> accessionIds);
......
......@@ -318,6 +318,18 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
}
}
/**
* {@inheritDoc}
*/
@Override
public List<Accession> listAccessions(final String acceNumb) {
List<Accession> accessions = new ArrayList<>();
for (final Accession accession : accessionRepository.findByAccessionName(acceNumb)) {
accessions.add(lazyLoadAccession(accession));
}
return accessions;
}
@Override
public Accession getAccession(String instCode, String doi, String acceNumb, String genus) throws NonUniqueAccessionException {
try {
......
......@@ -146,24 +146,22 @@ public class SelectionController extends BaseController {
public String add(ModelMap model, RedirectAttributes redirectAttrs, @RequestParam(required = true, value = "instCode") String instCode,
@RequestParam(required = true, value = "accessionIds") String accessionIds) {
if (StringUtils.isBlank(instCode)) {
return "redirect:/sel/";
}
final String[] splits = accessionIds.split("[,;\\t\\n]+");
for (final String s : splits) {
// System.err.println(">> '" + s.trim() + "'");
if (!StringUtils.isBlank(instCode)) {
try {
final Accession accession = genesysService.getAccession(instCode, s.trim());
if (accession != null) {
// System.err.println("\t" + accession.getId());
selectionBean.add(accession.getId());
} else {
// System.err.println("\t NF='" + s + "'");
}
} catch (NonUniqueAccessionException e) {
// Non-unique
}
} else {
for (final Accession accession : genesysService.listAccessions(s.trim())) {
selectionBean.add(accession.getId());
}
}
}
return "redirect:/sel/";
}
......
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