Skip to content

Commit e759868

Browse files
committed
fix: when adding a pdf during process edition, the content is never saved - EXO-81221
Before this fix, when you create a pdf form inside a process during process edition (not process creation), The content of the pdf is never saved. This is because the "move" action is not correctly done with the session, the jcr:content node have still path in the old location Using workplace.move ensure to move and save all the node and subtree
1 parent 37f8ada commit e759868

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

processes-services/src/main/java/org/exoplatform/processes/service/ProcessesAttachmentServiceImpl.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,16 @@ private void moveOrCopyAttachmentsJcrNodes(List<Attachment> attachments,
209209
String destPath = destNode.getPath().concat("/").concat(attachmentNode.getName());
210210
if (!copy && !attachment.isEXoDrive()) {
211211
Node sourceEntityIdNode = attachmentNode.getParent();
212-
session.move(attachmentNode.getPath(), destPath);
213-
attachmentNode = (Node) session.getItem(destPath);
214-
attachmentNode.addMixin(NodetypeConstant.EXO_HIDDENABLE);
212+
session.save();
213+
Workspace workspace = session.getWorkspace();
214+
workspace.move(attachmentNode.getPath(), destPath);
215+
Node copyNode = (Node) session.getItem(destPath);
216+
copyNode.addMixin(NodetypeConstant.EXO_HIDDENABLE);
215217
if (attachments.size() - 1 == index && sourceEntityIdNode != null
216218
&& sourceEntityIdNode.getPrimaryNodeType().isNodeType(NodetypeConstant.NT_FOLDER)) {
217219
sourceEntityIdNode.remove();
218220
}
219-
session.save();
221+
copyNode.save();
220222
} else {
221223
session.save();
222224
Workspace workspace = session.getWorkspace();

processes-services/src/test/java/org/exoplatform/processes/service/ProcessesAttachmentServiceImplTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,10 @@ public void moveAttachmentsToEntity() throws Exception {
142142
List<Attachment> attachmentList = new ArrayList<>();
143143
Attachment attachment = new Attachment();
144144
attachment.setId("1");
145+
Workspace workspace = mock(Workspace.class);
145146
Session session = mock(Session.class);
146147
Node node = mock(Node.class);
148+
when(session.getWorkspace()).thenReturn(workspace);
147149
ExtendedNode extendedNode = mock(ExtendedNode.class);
148150
ProjectDto projectDto = new ProjectDto();
149151
projectDto.setId(1L);
@@ -189,7 +191,7 @@ public void moveAttachmentsToEntity() throws Exception {
189191
when(extendedNode.getPath()).thenReturn("destPath");
190192
when(node.getParent()).thenReturn(node);
191193
processesAttachmentService.moveAttachmentsToEntity(1L, 1L, "workflow", 1L, "workdraft", 1L);
192-
verify(session, times(1)).move("srcPath", "destPath/test");
194+
verify(workspace, times(1)).move("srcPath", "destPath/test");
193195

194196
}
195197

0 commit comments

Comments
 (0)