Commit 622a19e0 authored by Matija Obreza's avatar Matija Obreza

Merge branch 'ui-268-add-accessions-by-name-to-my-list'

* ui-268-add-accessions-by-name-to-my-list:
  Added decoding from accession number to uuid
parents 294271f1 80a834f6
......@@ -133,6 +133,17 @@ public class AccessionController {
return accessionService.uuidsFromIds(ids);
}
@GetMapping(value = "/acce-number/{acceNumber}", produces = { MediaType.APPLICATION_JSON_VALUE })
public UUID uuidFromAcceNumber(@RequestParam(value = "instCode", required = false) String instCode , @PathVariable("acceNumber") String acceNumber) {
return accessionService.uuidFromAcceNumber(instCode, acceNumber);
}
@PostMapping(value = "/acce-number", produces = { MediaType.APPLICATION_JSON_VALUE })
public List<UUID> uuidsFromAcceNumbers(@RequestParam(value = "instCode", required = false) String instCode, @RequestBody List<String> acceNumbers) {
return accessionService.uuidsFromAcceNumbers(instCode, acceNumbers);
}
/**
* Gets the accession
*
......
......@@ -69,6 +69,24 @@ public interface AccessionService {
*/
List<UUID> uuidsFromIds(List<Long> ids);
/**
* Get accession#uuid from accession number and instcode.
*
* @param acceNumber the accession number
* @param instCode code of holder institute (can be null)
* @return the uuid
*/
UUID uuidFromAcceNumber(String instCode, String acceNumber);
/**
* Get accession#uuids from ids
*
* @param acceNumbers accession numbers
* @param instCode code of holder institute (can be null)
* @return the list of uuids
*/
List<UUID> uuidsFromAcceNumbers(String instCode, List<String> acceNumbers);
/**
* List accessions by filter
*
......
......@@ -28,6 +28,7 @@ import java.util.UUID;
import java.util.regex.Matcher;
import java.util.stream.Collectors;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.apache.commons.collections.CollectionUtils;
import org.genesys.blocks.auditlog.service.AuditTrailService;
......@@ -298,6 +299,39 @@ public class AccessionServiceImpl implements AccessionService {
return uuids;
}
@Override
public List<UUID> uuidsFromAcceNumbers(String instCode, List<String> acceNumbers) {
QAccession accession = QAccession.accession;
List<UUID> uuids = new ArrayList<>();
for (int fromIndex = 0; fromIndex < acceNumbers.size(); fromIndex += LOAD_CHUNK_SIZE) {
BooleanBuilder predicate = new BooleanBuilder();
if (instCode != null) {
predicate.and(accession.instituteCode.eq(instCode));
}
predicate.and(accession.accessionNumber.in(acceNumbers.subList(fromIndex, Math.min(fromIndex + LOAD_CHUNK_SIZE, acceNumbers.size()))));
List<Accession> accessions = Lists.newArrayList(accessionRepository.findAll(predicate));
uuids.addAll(accessions.stream().map(AccessionData::getAccessionId).map(AccessionId::getUuid).collect(Collectors.toList()));
}
return uuids;
}
@Override
public UUID uuidFromAcceNumber(String instCode, String acceNumber) {
Accession accession = instCode == null ?
accessionRepository.findByInstituteCodeAndAccessionNumber(instCode, acceNumber)
: accessionRepository.findOne(QAccession.accession.accessionNumber.eq(acceNumber));
if (accession == null) {
throw new NotFoundElement("No accession with instCode " + instCode + " and acceNumb: " + acceNumber);
}
return accession.getUuid();
}
@Override
public Set<Long> filterAvailableForDistributionByUuid(Set<UUID> accessionUuids) {
if (accessionUuids == null || accessionUuids.size() == 0) {
......
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