Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Save form] Re-saving of draft creates new draft instead of updating exis… #1400

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public class FormContainerImpl extends AbstractContainerImpl implements FormCont
public static final String FD_FORM_DATA_ENABLED = "fd:formDataEnabled";
public static final String FD_ROLE_ATTRIBUTE = "fd:roleAttribute";

private static final String DRAFT_PREFILL_SERVICE = "service://FP/draft/";

@SlingObject(injectionStrategy = InjectionStrategy.OPTIONAL)
@Nullable
private SlingHttpServletRequest request;
Expand Down Expand Up @@ -317,6 +319,14 @@ public String getLanguageDirection() {
(request != null && StringUtils.isNotBlank(request.getParameter(GuideConstants.AF_DATA_REF)))) {
formDataEnabled = true;
}

// set draftId in properties in case of forms portal prefill
if (request != null && StringUtils.isNotBlank(request.getParameter(GuideConstants.AF_DATA_REF))) {
final String dataRef = request.getParameter(GuideConstants.AF_DATA_REF);
if (dataRef.startsWith(DRAFT_PREFILL_SERVICE)) {
girotraapankaj marked this conversation as resolved.
Show resolved Hide resolved
properties.put(GuideConstants.DRAFT_ID, StringUtils.substringAfter(dataRef, DRAFT_PREFILL_SERVICE));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this property does not get stored on jcr, it will be added when FP prefill is used.

}
}
properties.put(FD_ROLE_ATTRIBUTE, getRoleAttribute());
properties.put(FD_FORM_DATA_ENABLED, formDataEnabled);
properties.put(ReservedProperties.FD_AUTO_SAVE_PROPERTY_WRAPPER, this.autoSaveConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,18 @@ void testGetFormDataEnabledWhenDataRefIsSet() throws Exception {
request.setParameterMap(new HashMap<>());
}

@Test
void testDraftIdPropertyWhenDataRefIsSet() throws Exception {
MockSlingHttpServletRequest request = context.request();
Map<String, Object> tempMap = new HashMap<>();
tempMap.put(GuideConstants.AF_DATA_REF, "service://FP/draft/KH5DOFY2RMWVOOVREE324MRXIY");
request.setParameterMap(tempMap);
FormContainer formContainer = Utils.getComponentUnderTest(PATH_FORM_WITHOUT_PREFILL, FormContainer.class, context);
assertEquals("KH5DOFY2RMWVOOVREE324MRXIY", formContainer.getProperties().get(GuideConstants.DRAFT_ID));
// reset the parameter map
request.setParameterMap(new HashMap<>());
}

@Test
void testGetFormDataDisabled() throws Exception {
FormContainer formContainer = Utils.getComponentUnderTest(PATH_FORM_WITHOUT_PREFILL, FormContainer.class, context);
Expand Down
Loading