Commit d466d8cd authored by Viacheslav Pavlov's avatar Viacheslav Pavlov Committed by Matija Obreza

Added converter from AccessionIdentifier3 to genesys UUID

parent 53fb86ef
......@@ -17,6 +17,7 @@
package org.genesys2.server.api.v1;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
......@@ -27,7 +28,9 @@ import org.genesys.blocks.model.JsonViews;
import org.genesys.catalog.api.FilteredPage;
import org.genesys.catalog.service.ShortFilterService;
import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.model.AccessionHeaderJson;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.impl.AccessionIdentifier3;
import org.genesys2.server.service.AccessionService;
import org.genesys2.server.service.ElasticsearchService;
import org.genesys2.server.service.ElasticsearchService.TermResult;
......@@ -162,6 +165,17 @@ public class AccessionController {
return elasticsearchService.termStatisticsAuto(Accession.class, filter, 10, terms.toArray(new String[] {}));
}
/**
* Converts AccessionIdentifiers to UUID
* @param identifiers accession identifiers to lookup in DB
* @return map with UUIDs and related AccessionIdentifiers
*/
@PostMapping(value = "/toUUID", produces = { MediaType.APPLICATION_JSON_VALUE })
public Map<UUID, AccessionIdentifier3> toUUID(@RequestBody List<AccessionHeaderJson> identifiers) {
return accessionService.toUUID(identifiers);
}
/**
* Get term overview for filters
*
......
......@@ -15,9 +15,12 @@
*/
package org.genesys2.server.service;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.impl.AccessionIdentifier3;
import org.genesys2.server.service.filter.AccessionFilter;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
......@@ -48,4 +51,11 @@ public interface AccessionService {
* @return the by doi
*/
Accession getByDoi(String doi);
/**
* Converts AccessionIdentifiers to UUID
* @param identifiers accession identifiers to lookup in DB
* @return map with UUIDs and related AccessionIdentifiers
*/
Map<UUID, AccessionIdentifier3> toUUID(List<? extends AccessionIdentifier3> identifiers);
}
......@@ -17,10 +17,14 @@ package org.genesys2.server.service.impl;
import java.util.List;
import java.util.UUID;
import java.util.Map;
import java.util.HashMap;
import java.util.Optional;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionData;
import org.genesys2.server.model.genesys.AccessionId;
import org.genesys2.server.model.impl.AccessionIdentifier3;
import org.genesys2.server.persistence.AccessionRepository;
import org.genesys2.server.service.AccessionService;
import org.genesys2.server.service.ElasticsearchService;
......@@ -97,6 +101,24 @@ public class AccessionServiceImpl implements AccessionService {
return lazyLoad(accessionRepository.findByDoi(doi));
}
@Override
public Map<UUID, AccessionIdentifier3> toUUID(List<? extends AccessionIdentifier3> identifiers) {
Map<UUID, AccessionIdentifier3> res = new HashMap<>();
List<Accession> foundAccessions = accessionRepository.findById(identifiers);
for(Accession accession: foundAccessions) {
Optional<? extends AccessionIdentifier3> toPut = identifiers.stream()
.filter(id -> id.getAccessionNumber().equals(accession.getAccessionNumber())
&& id.getGenus().equals(accession.getGenus())
&& id.getHoldingInstitute().equals(accession.getInstCode())
).findFirst();
toPut.ifPresent(accessionIdentifier3 -> res.put(accession.getUuid(), accessionIdentifier3));
}
return res;
}
/*
* (non-Javadoc)
* @see
......
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