Skip to content

Commit 724db4a

Browse files
RSDEV-633 Save chemicals in copied documents to the chemistry service (#332)
## Description ## When a document is copied, the chemical element was saved via the dao layer rather than manager layer, which meant the call to save the chemical to rspace document pair to the chemistry service was bypassed. This meant the copied document wouldn't be returned as a search hit when searching for the chemical element. The fix is to save the copied document via the manager rather than the dao layer. ## Design decisions As the test requires an instance of the chemistry service, it's been ignored in the open-source build, which is the case for other chemistry-dependent tests. I've created https://researchspace.atlassian.net/browse/RSDEV-673 with some ideas on how to handle these tests in a nicer way. I'll enable this test in the closed-source repo once it's been synced. ## Testing notes Passing Jenkins build here: https://jenkins.researchspace.com/job/rspace-web/job/rsdev-633-save-copied-chems/2/ (shows there are no regressions, though the new test will be ignored in this build.) --------- Co-authored-by: rs-fraser <fraser.macinnes> Co-authored-by: Maciej Kowalski <mKowalski256@users.noreply.github.com>
1 parent 7d26eb4 commit 724db4a

File tree

2 files changed

+63
-3
lines changed

2 files changed

+63
-3
lines changed

src/main/java/com/researchspace/service/impl/DocumentCopyManagerImpl.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.researchspace.dao.FieldDao;
66
import com.researchspace.dao.FolderDao;
77
import com.researchspace.dao.InternalLinkDao;
8-
import com.researchspace.dao.RSChemElementDao;
98
import com.researchspace.dao.RSMathDao;
109
import com.researchspace.dao.RecordDao;
1110
import com.researchspace.files.service.FileStore;
@@ -37,6 +36,7 @@
3736
import com.researchspace.service.DocumentCopyManager;
3837
import com.researchspace.service.FieldManager;
3938
import com.researchspace.service.FileDuplicateStrategy;
39+
import com.researchspace.service.RSChemElementManager;
4040
import com.researchspace.service.RequiresActiveLicense;
4141
import com.researchspace.service.ThumbnailManager;
4242
import com.researchspace.service.exceptions.RecordCopyException;
@@ -64,7 +64,7 @@ public class DocumentCopyManagerImpl implements DocumentCopyManager {
6464

6565
private @Autowired EcatCommentDao ecatCommentDao;
6666
private @Autowired EcatImageAnnotationDao imageAnnotationDao;
67-
private @Autowired RSChemElementDao rsChemElementDao;
67+
private @Autowired RSChemElementManager rsChemElementManager;
6868
private @Autowired RSMathDao mathDao;
6969
private @Autowired FieldDao fieldDao;
7070
private @Autowired FieldManager fieldMgr;
@@ -152,7 +152,15 @@ private String copyChemElementsToField(
152152
RSChemElement copyChem = origChem.shallowCopy();
153153
copyChem.setParentId(destFieldId);
154154
copyChem.setRecord(destRecord);
155-
rsChemElementDao.save(copyChem);
155+
try {
156+
rsChemElementManager.save(copyChem, user);
157+
} catch (IOException e) {
158+
log.error(
159+
"Problem saving chemical in document with id {}.",
160+
destRecord.getId(),
161+
e);
162+
}
163+
156164
chemOldKey2NewKey.put(origChem.getId(), copyChem.getId());
157165
}
158166
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.researchspace.chemistry;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import com.researchspace.model.ChemSearchedItem;
6+
import com.researchspace.model.RSChemElement;
7+
import com.researchspace.model.User;
8+
import com.researchspace.model.record.RSForm;
9+
import com.researchspace.model.record.StructuredDocument;
10+
import com.researchspace.service.RSChemElementManager;
11+
import com.researchspace.service.RecordManager;
12+
import com.researchspace.testutils.RealTransactionSpringTestBase;
13+
import java.util.List;
14+
import org.junit.Ignore;
15+
import org.junit.Test;
16+
import org.springframework.beans.factory.annotation.Autowired;
17+
import org.springframework.test.context.TestPropertySource;
18+
19+
@Ignore(
20+
"Requires chemistry service to run. See"
21+
+ " https://documentation.researchspace.com/article/1jbygguzoa")
22+
@TestPropertySource(
23+
properties = {"chemistry.service.url=http://localhost:8090", "chemistry.provider=indigo"})
24+
public class ChemistryDocumentCopyIT extends RealTransactionSpringTestBase {
25+
26+
@Autowired RecordManager recordManager;
27+
28+
@Autowired RSChemElementManager chemElementManager;
29+
30+
@Test
31+
public void testCopiedDocumentsAreChemistrySearchable() throws Exception {
32+
User user = createInitAndLoginAnyUser();
33+
RSForm form = createAnyForm(user);
34+
35+
// create doc with chemical structure
36+
StructuredDocument doc = createDocumentInFolder(user.getRootFolder(), form, user);
37+
RSChemElement chem = addChemStructureToField(doc.getFields().get(0), user);
38+
39+
// confirm 1 search result when searching for the chemical structure
40+
List<ChemSearchedItem> searchHits =
41+
chemElementManager.search(chem.getSmilesString(), "EXACT", 1000, user);
42+
assertEquals(1, searchHits.size());
43+
44+
// copy the doc
45+
recordManager.copy(doc.getId(), "copy", user, user.getRootFolder().getId());
46+
47+
// confirm 2 search results
48+
List<ChemSearchedItem> searchHitsAfterCopy =
49+
chemElementManager.search(chem.getSmilesString(), "EXACT", 1000, user);
50+
assertEquals(2, searchHitsAfterCopy.size());
51+
}
52+
}

0 commit comments

Comments
 (0)