Commit 80a834f6 authored by Viacheslav Pavlov's avatar Viacheslav Pavlov

Added decoding from accession number to uuid

parent c49a8704
...@@ -23,7 +23,6 @@ import java.io.OutputStream; ...@@ -23,7 +23,6 @@ import java.io.OutputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols; import java.text.DecimalFormatSymbols;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
...@@ -77,7 +76,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; ...@@ -77,7 +76,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.hazelcast.util.CollectionUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
...@@ -140,6 +138,17 @@ public class AccessionController { ...@@ -140,6 +138,17 @@ public class AccessionController {
return accessionService.uuidsFromIds(ids); 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 * Gets the accession
* *
......
...@@ -68,6 +68,24 @@ public interface AccessionService { ...@@ -68,6 +68,24 @@ public interface AccessionService {
*/ */
List<UUID> uuidsFromIds(List<Long> ids); 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 * List accessions by filter
* *
......
...@@ -28,6 +28,7 @@ import java.util.UUID; ...@@ -28,6 +28,7 @@ import java.util.UUID;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.genesys.blocks.auditlog.service.AuditTrailService; import org.genesys.blocks.auditlog.service.AuditTrailService;
...@@ -288,6 +289,39 @@ public class AccessionServiceImpl implements AccessionService { ...@@ -288,6 +289,39 @@ public class AccessionServiceImpl implements AccessionService {
return uuids; 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 @Override
public Set<Long> filterAvailableForDistributionByUuid(Set<UUID> accessionUuids) { public Set<Long> filterAvailableForDistributionByUuid(Set<UUID> accessionUuids) {
if (accessionUuids == null || accessionUuids.size() == 0) { 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