Commit 7f963609 authored by Matija Obreza's avatar Matija Obreza

Diversity Trees: "new version" created without RepositoryFile and no Refs

parent dbb93610
......@@ -595,6 +595,7 @@ public class DiversityTreeServiceImpl implements DiversityTreeService {
final DiversityTree tree = new DiversityTree();
copyValues(tree, source);
tree.setTreeFile(null);
tree.setCrop(validCropName(source.getCrop()));
tree.setState(PublishState.DRAFT);
tree.setCurrent(null);
......@@ -602,9 +603,6 @@ public class DiversityTreeServiceImpl implements DiversityTreeService {
tree.setVersions(source.getVersions());
DiversityTree saved = treeRepository.save(tree);
// Copy accessionRefs
copyAccessionRefs(saved, source.getAccessionRefs());
// Copy creators
copyCreators(saved, source.getCreators());
......@@ -762,48 +760,6 @@ public class DiversityTreeServiceImpl implements DiversityTreeService {
target.setRole(source.getRole());
}
/**
* Copy and save DiversityTree accessionRefs.
*
* @param target the target
* @param accessionRefs the DiversityTree accessionRefs
* @return
*/
private DiversityTree copyAccessionRefs(final DiversityTree target, final List<DiversityTreeAccessionRef> accessionRefs) {
if (accessionRefs == null || accessionRefs.size() == 0) {
return target;
}
final DiversityTree loadedTree = get(target);
List<DiversityTreeAccessionRef> copiedAccessionRefs = Lists.newArrayList();
accessionRefs.forEach(sAccessionRef -> {
DiversityTreeAccessionRef copy = new DiversityTreeAccessionRef();
copyAccessionRef(copy, sAccessionRef);
copy.setList(loadedTree);
copiedAccessionRefs.add(copy);
});
accessionRefRepository.saveAll(copiedAccessionRefs);
loadedTree.setAccessionCount((int) accessionRefRepository.countByList(loadedTree));
LOG.info("Done saving {} accession refs, have {} in DiversityTree", accessionRefs.size(), loadedTree.getAccessionCount());
return treeRepository.save(loadedTree);
}
/**
* Copy DiversityTree accessionRef values.
*
* @param target the target
* @param source the source
*/
private void copyAccessionRef(final DiversityTreeAccessionRef target, final DiversityTreeAccessionRef source) {
target.setDoi(source.getDoi());
target.setInstCode(source.getInstCode());
target.setAcceNumb(source.getAcceNumb());
target.setGenus(source.getGenus());
target.setSpecies(source.getSpecies());
target.setAccession(source.getAccession());
target.setNodeKey(source.getNodeKey());
}
/**
* Copy and save DiversityTree creators.
......
......@@ -433,7 +433,7 @@ public class DiversityTreeServiceTest extends CatalogServiceTest {
// fetch accessionRefs of new version of tree
Page<DiversityTreeAccessionRef> page = treeService.listAccessionRefs(newVersion, PageRequest.of(0, 10));
assertEquals(5, page.getTotalElements());
assertEquals(0, page.getTotalElements());
}
/**
......
......@@ -386,7 +386,7 @@ public class DiversityTreeControllerTest extends AbstractDiversityTreeController
.andExpect(jsonPath("$.current", is(nullValue())))
.andExpect(jsonPath("$.crop", is(CROP_SHORT_NAME)))
.andExpect(jsonPath("$.currentVersion", is(publishedTree.getUuid().toString())))
.andExpect(jsonPath("$.accessionCount", is(1)))
.andExpect(jsonPath("$.accessionCount", is(0)))
.andExpect(jsonPath("$.state", is(PublishState.DRAFT.toString())))
;
/*@formatter:on*/
......
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