-
Notifications
You must be signed in to change notification settings - Fork 3
Upgrade to the latest version of XP 8 #2427 #2428
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ | |
| import com.fasterxml.jackson.annotation.JsonIgnore; | ||
|
|
||
| import com.enonic.xp.app.users.rest.resource.schema.content.LocaleMessageResolver; | ||
| import com.enonic.xp.app.users.rest.resource.schema.mixin.InlineMixinResolver; | ||
| import com.enonic.xp.app.users.rest.resource.schema.mixin.CmsFormFragmentServiceResolver; | ||
| import com.enonic.xp.form.Form; | ||
| import com.enonic.xp.form.FormItem; | ||
|
|
||
|
|
@@ -19,7 +19,7 @@ public class FormJson | |
| private final List<FormItemJson> items; | ||
|
|
||
|
|
||
| public FormJson( final Form form, final LocaleMessageResolver localeMessageResolver, final InlineMixinResolver inlineMixinResolver ) | ||
| public FormJson( final Form form, final LocaleMessageResolver localeMessageResolver, final CmsFormFragmentServiceResolver inlineMixinResolver ) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ℹ️ Codacy found a minor CodeStyle issue: Line is longer than 140 characters (found 147). The issue reported by the Checkstyle linter indicates that the line defining the constructor for the To address this issue, we can break the constructor parameters into multiple lines for better readability while keeping it within the character limit. Here's the suggested code change: public FormJson(final Form form, final LocaleMessageResolver localeMessageResolver,
final CmsFormFragmentServiceResolver inlineMixinResolver)This comment was generated by an experimental AI tool. |
||
| { | ||
| this.form = inlineMixinResolver.inlineForm( form ); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,20 @@ | ||
| package com.enonic.xp.app.users.json.form; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonIgnore; | ||
| import com.fasterxml.jackson.annotation.JsonInclude; | ||
| import com.google.common.collect.ImmutableList; | ||
|
|
||
| import com.enonic.xp.app.users.rest.resource.schema.content.LocaleMessageResolver; | ||
| import com.enonic.xp.data.Value; | ||
| import com.enonic.xp.form.Input; | ||
| import com.enonic.xp.inputtype.InputTypeConfig; | ||
| import com.enonic.xp.inputtype.InputTypeName; | ||
| import com.enonic.xp.inputtype.InputTypeProperty; | ||
| import com.enonic.xp.util.GenericValue; | ||
|
|
||
| import static com.google.common.base.Strings.nullToEmpty; | ||
|
|
||
|
|
@@ -65,26 +65,6 @@ public String getLabel() | |
| } | ||
| } | ||
|
|
||
| public boolean isImmutable() | ||
| { | ||
| return input.isImmutable(); | ||
| } | ||
|
|
||
| public boolean isIndexed() | ||
| { | ||
| return input.isIndexed(); | ||
| } | ||
|
|
||
| public boolean isMaximizeUIInputWidth() | ||
| { | ||
| return input.isMaximizeUIInputWidth(); | ||
| } | ||
|
|
||
| public String getCustomText() | ||
| { | ||
| return input.getCustomText(); | ||
| } | ||
|
|
||
| public String getHelpText() | ||
| { | ||
| if ( localeMessageResolver != null && !nullToEmpty( input.getHelpTextI18nKey() ).isBlank() ) | ||
|
|
@@ -97,11 +77,6 @@ public String getHelpText() | |
| } | ||
| } | ||
|
|
||
| public String getValidationRegexp() | ||
| { | ||
| return input.getValidationRegexp(); | ||
| } | ||
|
|
||
| public OccurrencesJson getOccurrences() | ||
| { | ||
| return occurrences; | ||
|
|
@@ -112,20 +87,67 @@ public String getInputType() | |
| return this.inputType; | ||
| } | ||
|
|
||
| public Map<String, List<Map<String, String>>> getConfig() | ||
| public Map<String, List<Map<String, Object>>> getConfig() | ||
| { | ||
| final InputTypeConfig config = this.input.getInputTypeConfig(); | ||
| final GenericValue config = this.input.getInputTypeConfig(); | ||
|
|
||
| final Map<String, List<Map<String, String>>> json = new LinkedHashMap<>(); | ||
| for ( final String name : config.getNames() ) | ||
| { | ||
| final Map<String, List<Map<String, Object>>> json = new LinkedHashMap<>(); | ||
|
|
||
| json.put( name, toJson( config.getProperties( name ) ) ); | ||
| } | ||
| config.getProperties().forEach( entry -> { | ||
| final String name = entry.getKey(); | ||
| final GenericValue value = entry.getValue(); | ||
|
|
||
| if ( "option".equals( entry.getKey() ) && ( InputTypeName.RADIO_BUTTON.equals( this.input.getInputType() ) || | ||
| InputTypeName.COMBO_BOX.equals( this.input.getInputType() ) ) ) | ||
| { | ||
| json.put( name, doHandleRadioButtonOrComboBox( value ) ); | ||
| } | ||
| else | ||
| { | ||
| json.put( name, toJsonAsList( value ) ); | ||
| } | ||
| } ); | ||
|
|
||
| return json; | ||
| } | ||
|
|
||
| private List<Map<String, Object>> doHandleRadioButtonOrComboBox( final GenericValue value ) | ||
| { | ||
| final List<Map<String, Object>> result = new ArrayList<>(); | ||
|
|
||
| value.asList().forEach( item -> { | ||
| final Map<String, Object> json = new LinkedHashMap<>(); | ||
|
|
||
| final String optionValue = item.optional( "value" ).map( GenericValue::asString ).orElse( null ); | ||
|
|
||
| json.put( "@value", optionValue ); | ||
|
|
||
| final Optional<GenericValue> label = item.optional( "label" ); | ||
| if ( label.isPresent() ) | ||
| { | ||
| final GenericValue labelValue = label.get(); | ||
|
|
||
| String labelText = labelValue.optional( "text" ).map( GenericValue::asString ).orElse( null ); | ||
| if ( labelValue.optional( "i18n" ).isPresent() ) | ||
| { | ||
| final String i18nKey = labelValue.property( "i18n" ).asString(); | ||
| json.put( "@i18n", i18nKey ); | ||
|
|
||
| if ( InputTypeName.RADIO_BUTTON.equals( this.input.getInputType() ) ) | ||
| { | ||
| labelText = this.localeMessageResolver.localizeMessage( i18nKey, labelText ); | ||
| } | ||
| } | ||
|
|
||
| json.put( "value", labelText ); | ||
| } | ||
|
|
||
| result.add( json ); | ||
| } ); | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| @JsonInclude(JsonInclude.Include.NON_NULL) | ||
| public PropertyValueJson getDefaultValue() | ||
| { | ||
|
|
@@ -137,34 +159,41 @@ public void setDefaultValue( final Value defaultValue ) | |
| this.defaultValue = defaultValue; | ||
| } | ||
|
|
||
| private List<Map<String, String>> toJson( final Collection<InputTypeProperty> properties ) | ||
| private List<Map<String, Object>> toJsonAsList( final GenericValue value ) | ||
| { | ||
| final List<Map<String, String>> json = new ArrayList<>( ); | ||
| for ( final InputTypeProperty property : properties ) | ||
| final List<Map<String, Object>> json = new ArrayList<>( ); | ||
| for ( final GenericValue property : value.asList() ) | ||
| { | ||
| json.add( toJson( property ) ); | ||
| } | ||
|
|
||
| return json; | ||
| } | ||
|
|
||
| private Map<String, String> toJson( final InputTypeProperty property ) | ||
| { | ||
| final Map<String, String> json = new LinkedHashMap<>(); | ||
|
|
||
| String propertyValue = property.getValue(); | ||
|
|
||
| for ( final Map.Entry<String, String> attribute : property.getAttributes().entrySet() ) | ||
| { | ||
| if ( InputTypeName.RADIO_BUTTON.equals( this.input.getInputType() ) && "i18n".equals( attribute.getKey() ) ) | ||
| { | ||
| propertyValue = this.localeMessageResolver.localizeMessage( attribute.getValue(), propertyValue ); | ||
| } | ||
| json.put( "@" + attribute.getKey(), attribute.getValue() ); | ||
| private Map<String, Object> toJson( final GenericValue property ) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generic value can already return raw value perfectly serializable |
||
| { | ||
| final Map<String, Object> json = new LinkedHashMap<>(); | ||
|
|
||
| switch ( property.getType() ) { | ||
| case STRING: | ||
| json.put( "value", property.asString() ); | ||
| break; | ||
| case NUMBER: | ||
| json.put( "value", property.asDouble() ); | ||
| break; | ||
| case BOOLEAN: | ||
| json.put( "value", property.asBoolean() ); | ||
| break; | ||
| case LIST: | ||
| json.put( "value", property.asList().stream().map( this::toJson ).collect( ImmutableList.toImmutableList() ) ); | ||
| break; | ||
| case OBJECT: | ||
| property.getProperties().forEach( entry -> json.put( entry.getKey(), toJson( entry.getValue() ) ) ); | ||
| break; | ||
| default: | ||
| throw new AssertionError( property.getType() ); | ||
| } | ||
|
|
||
| json.put( "value", propertyValue ); | ||
|
|
||
| return json; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete