Commit f577f04b authored by Matija Obreza's avatar Matija Obreza

Dataset: upserting accessions does not return Accession data with AccessionRef

parent af9ff4e7
......@@ -121,7 +121,7 @@ public class ApiExceptionHandler {
@ExceptionHandler(MethodArgumentTypeMismatchException.class)
@ResponseBody
public ApiError<Exception> handleConverterArgumentError(final MethodArgumentTypeMismatchException e, final HttpServletRequest request) {
LOG.warn("Invalid argument {} for {} provided {} {}", e.getName(), e.getParameter(), request.getMethod(), request.getRequestURL(), e);
LOG.warn("Invalid argument {} for {} provided {} {}", e.getName(), e.getParameter(), request.getMethod(), request.getRequestURL());
return new ApiError<>(e);
}
......
......@@ -199,9 +199,11 @@ public class DatasetController {
* @throws NotFoundElement the not found element
*/
@PostMapping(value = "/upsertaccessions/{UUID},{version}")
@JsonView(JsonViews.Minimal.class)
public Dataset upsertAccessions(@PathVariable("UUID") final UUID uuid, @PathVariable("version") final int version,
@RequestBody final Set<AccessionRef> accessionRefs) throws NotFoundElement {
final Dataset dataset = datasetService.loadDataset(uuid, version);
LOG.debug("Received {} refs for Dataset {}", accessionRefs.size(), uuid);
return datasetService.upsertAccessions(dataset, accessionRefs);
}
......
......@@ -78,7 +78,7 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub
// index
indexes = { @Index(columnList = "datasetId, instCode, acceNumb"), @Index(columnList = "datasetId, genus") })
@Field(type = FieldType.Object)
@JsonView({ JsonViews.Public.class })
@JsonView({ JsonViews.Minimal.class })
private Set<AccessionRef> accessionRefs;
/** The descriptors. */
......
......@@ -34,6 +34,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.time.StopWatch;
import org.genesys.blocks.security.service.CustomAclService;
import org.genesys.catalog.model.Partner;
import org.genesys.catalog.model.dataset.Dataset;
......@@ -525,7 +526,10 @@ public class DatasetServiceImpl implements DatasetService {
if (loadedDataset == null) {
throw new NotFoundElement("Dataset doesn't exist");
}
loadedDataset.setState(PublishState.DRAFT);
if (loadedDataset.getState() != PublishState.DRAFT) {
throw new InvalidApiUsageException("Dataset should in draft state");
}
loadedDataset.setAccessionRefs(lookupMatchingAccessions(accessionRefs));
return lazyLoad(datasetRepository.save(loadedDataset));
}
......@@ -842,9 +846,10 @@ public class DatasetServiceImpl implements DatasetService {
* @return accessionRefs with matching accessions from Genesys
*/
private Set<AccessionRef> lookupMatchingAccessions(final Set<AccessionRef> accessionRefs) {
StopWatch stopWatch = StopWatch.createStarted();
List<AccessionRef> list = new ArrayList<AccessionRef>(accessionRefs);
List<Accession> foundAccessions = accessionRepository.find(list);
LOG.warn("Found {} matches for {} identifiers after {}ms", foundAccessions.size(), accessionRefs.size(), stopWatch.getTime());
LOG.info("Found {} matches for {} identifiers", foundAccessions.size(), accessionRefs.size());
accessionRefs.forEach(ref -> {
......@@ -860,7 +865,7 @@ public class DatasetServiceImpl implements DatasetService {
LOG.debug("No match for {}", ref);
}
});
LOG.warn("Matched accessions after {}ms", stopWatch.getTime());
return accessionRefs;
}
......
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