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

FORMS-16342 adding xfa data model in CC #1474

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft
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 @@ -17,17 +17,7 @@

import java.io.IOException;
import java.math.BigDecimal;
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.*;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -68,9 +58,12 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.node.ArrayNode;

public class AbstractFormComponentImpl extends AbstractComponentImpl implements FormComponent {
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = ReservedProperties.PN_DATAREF)
Expand Down Expand Up @@ -298,6 +291,10 @@
if (rulesProperties.size() > 0) {
properties.put(CUSTOM_RULE_PROPERTY_WRAPPER, rulesProperties);
}
List<String> disabledScripts = getDisabledXFAScripts();
if (disabledScripts.size() > 0) {
properties.put("fd:disabledXfaScripts", disabledScripts);

Check warning on line 296 in bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/util/AbstractFormComponentImpl.java

View check run for this annotation

Codecov / codecov/patch

bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/util/AbstractFormComponentImpl.java#L296

Added line #L296 was not covered by tests
}
return properties;
}

Expand Down Expand Up @@ -550,4 +547,24 @@
return customDorProperties;
}

private List<String> getDisabledXFAScripts() {
Set<String> disabledScripts = new HashSet<>();
String xfaScripts = resource.getValueMap().get("fd:xfaScripts", "");
if (StringUtils.isNotEmpty(xfaScripts)) {
// read string xfaScripts to jsonNode
ObjectMapper mapper = new ObjectMapper();

Check warning on line 555 in bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/util/AbstractFormComponentImpl.java

View check run for this annotation

Codecov / codecov/patch

bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/util/AbstractFormComponentImpl.java#L555

Added line #L555 was not covered by tests
try {
ArrayNode node = (ArrayNode) mapper.readTree(xfaScripts);

Check warning on line 557 in bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/util/AbstractFormComponentImpl.java

View check run for this annotation

Codecov / codecov/patch

bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/util/AbstractFormComponentImpl.java#L557

Added line #L557 was not covered by tests
// iterate through the array node and add the elements which have disabled property set to true
for (JsonNode jsonNode : node) {
if (jsonNode.has("disabled") && jsonNode.get("disabled").asBoolean()) {
disabledScripts.add(jsonNode.get("activity").asText());

Check warning on line 561 in bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/util/AbstractFormComponentImpl.java

View check run for this annotation

Codecov / codecov/patch

bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/util/AbstractFormComponentImpl.java#L561

Added line #L561 was not covered by tests
}
}
} catch (IOException e) {
logger.error("Error while parsing xfaScripts {} {}", e, resource.getPath());
}

Check warning on line 566 in bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/util/AbstractFormComponentImpl.java

View check run for this annotation

Codecov / codecov/patch

bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/util/AbstractFormComponentImpl.java#L563-L566

Added lines #L563 - L566 were not covered by tests
}
return new ArrayList<>(disabledScripts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@
String[] enumName = map.values().toArray(new String[0]);
return Arrays.stream(enumName)
.map(p -> {
return this.translate(ReservedProperties.PN_ENUM_NAMES, p);
String value = this.translate(ReservedProperties.PN_ENUM_NAMES, p);
if (value == null) {
value = "";

Check warning on line 112 in bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/util/AbstractOptionsFieldImpl.java

View check run for this annotation

Codecov / codecov/patch

bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/util/AbstractOptionsFieldImpl.java#L112

Added line #L112 was not covered by tests
}
return value;
})
.toArray(String[]::new);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
handler="CQ.FormsCoreComponents.editorhooks.viewQualifiedName"
icon="viewSOMExpression"
text="View Qualified Name"/>
<viewXFAScripts
jcr:primaryType="nt:unstructured"
condition="CQ.FormsCoreComponents.editorhooks.hasXfaScripts"
handler="CQ.FormsCoreComponents.editorhooks.viewXfaScripts"
icon="code"
text="View XFA Scripts"/>
</cq:actionConfigs>
<cq:inplaceEditing
jcr:primaryType="cq:InplaceEditingConfig"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
handler="CQ.FormsCoreComponents.editorhooks.viewQualifiedName"
icon="viewSOMExpression"
text="View Qualified Name"/>
<viewXFAScripts
jcr:primaryType="nt:unstructured"
condition="CQ.FormsCoreComponents.editorhooks.hasXfaScripts"
handler="CQ.FormsCoreComponents.editorhooks.viewXfaScripts"
icon="code"
text="View XFA Scripts"/>
</cq:actionConfigs>
<cq:inplaceEditing
jcr:primaryType="cq:InplaceEditingConfig"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,21 @@
Utils = window.CQ.FormsCoreComponents.Utils.v1;

var JSON_SCHEMA = 'jsonschema',
NONE = "none",
NONE = 'none',
FORM_DATA_MODEL = "formdatamodel",
FORM_TEMPLATE = 'formtemplates',
CONNECTOR = "connector",
SCHEMA_REF = "input[name='./schemaRef']",
XDP_REF = "input[name='./xdpRef']",
SCHEMA_TYPE = "input[name='./schemaType']",
SCHEMA_CONTAINER = ".cmp-adaptiveform-container__schemaselectorcontainer",
FDM_CONTAINER = ".cmp-adaptiveform-container__fdmselectorcontainer",
CONNECTOR_CONTAINER = ".cmp-adaptiveform-container__marketoselectorcontainer",
FORM_TEMPLATE_CONTAINER = ".cmp-adaptiveform-container__formtemplateselectorcontainer",
SCHEMA_DROPDOWN_SELECTOR = ".cmp-adaptiveform-container__schemaselector",
FDM_DROPDOWN_SELECTOR = ".cmp-adaptiveform-container__fdmselector",
CONNECTOR_DROPDOWN_SELECTOR = ".cmp-adaptiveform-container__marketoselector",
FORM_TEMPLATE_DROPDOWN_SELECTOR = ".cmp-adaptiveform-container__formtemplateselector",
FORM_MODEL_SELECTOR = ".cmp-adaptiveform-container__selectformmodel",
FM_AF_ROOT = "/content/forms/af/",
FM_DAM_ROOT ="/content/dam/formsanddocuments/",
Expand Down Expand Up @@ -113,9 +117,19 @@
if (isForm()){
var afAssetPath = getAfAssetMetadataPath();
DAM_SCHEMA_TYPE = "[name='" + afAssetPath + "/formmodel']";
DAM_SCHEMA_REF = "[name='" + afAssetPath + "/schemaRef']";
addFormParameter(afAssetPath + '/formmodel', schemaType);
addFormParameter(afAssetPath + '/schemaRef');
if(schemaType == JSON_SCHEMA){
DAM_SCHEMA_REF = "[name='" + afAssetPath + "/schemaRef']";
addFormParameter(afAssetPath + '/schemaRef');
} else if(schemaType == FORM_TEMPLATE){
DAM_SCHEMA_REF = "[name='" + afAssetPath + "/xdpRef']";
addFormParameter(afAssetPath + '/xdpRef');
// we don't want user to change the data model if form template has been selected
dialog.find('coral-selectlist-item[value="none"]').remove();
dialog.find('coral-selectlist-item[value="jsonschema"]').remove();
dialog.find('coral-selectlist-item[value="formdatamodel"]').remove();
dialog.find('coral-selectlist-item[value="connector"]').remove();
}
}
document.body.appendChild(formModelChangeConfirmationDialog);
prefillSchema(schemaType, dialog);
Expand All @@ -133,6 +147,10 @@

function prefillSchema(schemaType, dialog){
var schemaRef = dialog.find(SCHEMA_REF);
// for formtemplates we don't have schemaRef instead xdpRef
if(schemaType == FORM_TEMPLATE){
schemaRef = dialog.find(XDP_REF);
}
if(schemaRef.length > 0){
schemaRef = schemaRef[0].value;
configuredFormModel = schemaRef;
Expand All @@ -143,6 +161,8 @@
$(FDM_DROPDOWN_SELECTOR).val(schemaRef);
} else if (schemaType == CONNECTOR) {
$(CONNECTOR_DROPDOWN_SELECTOR).val(schemaRef);
} else if (schemaType == FORM_TEMPLATE) {
$(FORM_TEMPLATE_DROPDOWN_SELECTOR).val(schemaRef);
}
}
};
Expand Down Expand Up @@ -192,6 +212,21 @@
}
};

function formTemplateSelectorOnChanged(dialog) {
var selectedSchema = dialog.find(FORM_TEMPLATE_DROPDOWN_SELECTOR);
if(selectedSchema.length > 0) {
selectedSchema = selectedSchema[0].value;
setElementValue(dialog, SCHEMA_REF, selectedSchema);
setElementValue(dialog, DAM_SCHEMA_REF, selectedSchema);
isSchemaChanged = true;
if (configuredFormModel) {
confirmFormModelChange(selectedSchema, $(FORM_TEMPLATE_DROPDOWN_SELECTOR));
} else {
toBeConfiguredFormModel = selectedSchema;
}
}
};

function setElementValue(dialog, elementRef, value){
var element = dialog.find(elementRef);
if(element.length > 0){
Expand Down Expand Up @@ -225,20 +260,29 @@
function hideContainersExcept(selectedSchemaType) {
if (selectedSchemaType == JSON_SCHEMA) {
$(FDM_CONTAINER).hide();
$(FORM_TEMPLATE_CONTAINER).hide();
$(CONNECTOR_CONTAINER).hide();
$(SCHEMA_CONTAINER).show();
} else if (selectedSchemaType == FORM_DATA_MODEL) {
$(SCHEMA_CONTAINER).hide();
$(FORM_TEMPLATE_CONTAINER).hide();
$(CONNECTOR_CONTAINER).hide();
$(FDM_CONTAINER).show();
} else if (selectedSchemaType == CONNECTOR) {
$(SCHEMA_CONTAINER).hide();
$(FDM_CONTAINER).hide();
$(FORM_TEMPLATE_CONTAINER).hide();
$(CONNECTOR_CONTAINER).show();
} else if (selectedSchemaType == 'none') {
} else if (selectedSchemaType == FORM_TEMPLATE) {
$(FDM_CONTAINER).hide();
$(CONNECTOR_CONTAINER).hide();
$(SCHEMA_CONTAINER).hide();
$(FORM_TEMPLATE_CONTAINER).show();
} else if (selectedSchemaType == NONE) {
$(FDM_CONTAINER).hide();
$(SCHEMA_CONTAINER).hide();
$(CONNECTOR_CONTAINER).hide();
$(FORM_TEMPLATE_CONTAINER).hide();
}
};

Expand Down Expand Up @@ -266,7 +310,8 @@
var formModelSelector = dialog.find(FORM_MODEL_SELECTOR)[0],
schemaSelector = dialog.find(SCHEMA_DROPDOWN_SELECTOR)[0],
fdmSelector = dialog.find(FDM_DROPDOWN_SELECTOR)[0],
connectorSelector = dialog.find(CONNECTOR_DROPDOWN_SELECTOR)[0];
connectorSelector = dialog.find(CONNECTOR_DROPDOWN_SELECTOR)[0],
formTemplateSelector = dialog.find(FORM_TEMPLATE_DROPDOWN_SELECTOR)[0];
if (formModelSelector) {
formModelSelector.on("change", function() {
selectFormModelOnChanged(dialog);
Expand All @@ -287,6 +332,11 @@
connectorSelectorOnChanged(dialog);
});
};
if(formTemplateSelector) {
formTemplateSelector.on("change", function() {
formTemplateSelectorOnChanged(dialog);
});
}
selectFormModelOnLoad(dialog);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@
jcr:primaryType="nt:unstructured"
sling:resourceType="/libs/fd/af/connectors/rendercondition/marketo"/>
</optionConnectormodel>
<optionFormTemplates
jcr:primaryType="nt:unstructured"
text="Form Templates"
value="formtemplates"/>
</items>
</selectformmodel>
<schemaRef name="./schemaRef"
Expand Down Expand Up @@ -185,6 +189,29 @@
</fdmselector>
</items>
</fdmselectorcontainer>
<formTemplateSelectorContainer
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/container"
granite:class="cmp-adaptiveform-container__formtemplateselectorcontainer">
<items jcr:primaryType="nt:unstructured">
<formTemplateSelector
granite:class="cmp-adaptiveform-container__formtemplateselector"
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/select"
name="./xdpRef"
disabled="false"
fieldLabel="Select Form Template *"
validation="datamodel.config"
renderReadOnly="false">
<datasource
jcr:primaryType="nt:unstructured"
sling:resourceType="fd/af/components/commons/datasources/propertyprovider"
guideDataModel="basic"
layoutType="fd/af/layouts/panel"
type="formtemplates"/>
</formTemplateSelector>
</items>
</formTemplateSelectorContainer>
<marketoselectorcontainer
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/container"
Expand Down
Loading
Loading