Commit 141a2bd6 authored by Matija Obreza's avatar Matija Obreza

Fix: Copying existing Creator records to a new version of a subset

- Needs new entry in the table
parent 066d051a
......@@ -20,7 +20,6 @@ import static org.genesys2.server.model.impl.QSubsetCreator.subsetCreator;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
......@@ -33,9 +32,10 @@ import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.validation.Valid;
import com.querydsl.jpa.JPAExpressions;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.StopWatch;
import org.genesys.blocks.security.service.CustomAclService;
......@@ -94,11 +94,14 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;
import com.querydsl.jpa.JPAExpressions;
/**
* The Class SubsetServiceImpl.
*
* @author Maxym Borodenko
* @author Matija Obreza
* @author Viacheslav Pavlov
*/
@Service
@Transactional(readOnly = true)
......@@ -107,6 +110,9 @@ public class SubsetServiceImpl implements SubsetService {
private static final Logger LOG = LoggerFactory.getLogger(SubsetServiceImpl.class);
@PersistenceContext
private EntityManager entityManager;
@Autowired
private SubsetRepository subsetRepository;
......@@ -817,9 +823,18 @@ public class SubsetServiceImpl implements SubsetService {
subset.setCurrent(null);
subset.setUuid(null);
subset.setVersions(source.getVersions());
subset.setCreators(new ArrayList<>(source.getCreators()));
Subset saved = lazyLoad(subsetRepository.save(subset));
// Copy creators
source.getCreators().forEach(creator -> {
entityManager.detach(creator);
creator.setSubset(subset);
creator.setId(null);
creator.setVersion(null);
creator.setUuid(null);
subsetCreatorRepository.save(creator);
});
setAccessionRefs(saved, new HashSet<>(source.getAccessionRefs()));
saved.setCurrentVersion(source.getUuid());
......
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