Search in sources :

Example 11 with FormItem

use of com.enonic.xp.form.FormItem in project xp by enonic.

the class ContentTypeMapper method serializeFormItemSet.

private void serializeFormItemSet(final MapGenerator gen, final FormItemSet itemSet) {
    gen.map();
    gen.value("formItemType", "ItemSet");
    gen.value("name", itemSet.getName());
    gen.value("label", itemSet.getLabel());
    gen.value("customText", itemSet.getCustomText());
    gen.value("helpText", itemSet.getHelpText());
    serializeOccurrences(gen, itemSet.getOccurrences());
    gen.array("items");
    for (FormItem formItem : itemSet) {
        serializeItem(gen, formItem);
    }
    gen.end();
    gen.end();
}
Also used : FormItem(com.enonic.xp.form.FormItem)

Example 12 with FormItem

use of com.enonic.xp.form.FormItem in project xp by enonic.

the class ContentTypeMapper method serializeLayout.

private void serializeLayout(final MapGenerator gen, final FieldSet fieldSet) {
    gen.map();
    gen.value("formItemType", "Layout");
    gen.value("name", fieldSet.getName());
    gen.value("label", fieldSet.getLabel());
    gen.array("items");
    for (FormItem formItem : fieldSet) {
        serializeItem(gen, formItem);
    }
    gen.end();
    gen.end();
}
Also used : FormItem(com.enonic.xp.form.FormItem)

Example 13 with FormItem

use of com.enonic.xp.form.FormItem in project xp by enonic.

the class XmlMacroDescriptorParserTest method assertResult.

private void assertResult() throws Exception {
    final MacroDescriptor result = this.builder.build();
    assertEquals("myapplication:mymacro", result.getKey().toString());
    assertEquals("My macro", result.getDisplayName());
    assertEquals("key.display-name", result.getDisplayNameI18nKey());
    assertEquals("key.description", result.getDescriptionI18nKey());
    assertEquals("This macro is a test", result.getDescription());
    assertEquals(3, result.getForm().size());
    final FormItem item = result.getForm().getFormItem("myDate");
    assertNotNull(item);
    final Input input = (Input) item;
    assertEquals(InputTypeName.DATE.toString(), input.getInputType().toString());
    assertEquals("key.label", input.getLabelI18nKey());
    assertEquals("key.help-text", input.getHelpTextI18nKey());
    final FormItem contentSelectorItem = result.getForm().getFormItem("someonesParent");
    assertNotNull(contentSelectorItem);
    final Input contentSelectorInput = (Input) contentSelectorItem;
    assertEquals(InputTypeName.CONTENT_SELECTOR.toString(), contentSelectorInput.getInputType().toString());
    assertEquals("key.parent", contentSelectorInput.getLabelI18nKey());
    assertEquals("mytype", contentSelectorInput.getInputTypeConfig().getProperty("allowContentType").getValue());
    assertEquals(2, contentSelectorInput.getInputTypeConfig().getProperties("allowContentType").size());
    assertEquals("path1", contentSelectorInput.getInputTypeConfig().getProperty("allowPath").getValue());
    assertEquals(2, contentSelectorInput.getInputTypeConfig().getProperties("allowPath").size());
    assertEquals("system:reference", contentSelectorInput.getInputTypeConfig().getProperty("relationshipType").getValue());
    final InputTypeConfig config = input.getInputTypeConfig();
    assertNotNull(config);
}
Also used : Input(com.enonic.xp.form.Input) MacroDescriptor(com.enonic.xp.macro.MacroDescriptor) FormItem(com.enonic.xp.form.FormItem) InputTypeConfig(com.enonic.xp.inputtype.InputTypeConfig)

Example 14 with FormItem

use of com.enonic.xp.form.FormItem in project xp by enonic.

the class ImageContentProcessor method extractMetadata.

private ExtraDatas extractMetadata(final MediaInfo mediaInfo, final XDatas xDatas, final CreateAttachment sourceAttachment) {
    final ExtraDatas.Builder extradatasBuilder = ExtraDatas.create();
    final Map<XDataName, ExtraData> metadataMap = new HashMap<>();
    final ExtraData geoData = extractGeoLocation(mediaInfo, xDatas);
    if (geoData != null) {
        metadataMap.put(MediaInfo.GPS_INFO_METADATA_NAME, geoData);
        extradatasBuilder.add(geoData);
    }
    for (Map.Entry<String, Collection<String>> entry : mediaInfo.getMetadata().asMap().entrySet()) {
        for (XData xData : xDatas) {
            final String formItemName = getConformityName(entry.getKey());
            final FormItem formItem = xData.getForm().getFormItems().getItemByName(formItemName);
            if (formItem == null) {
                continue;
            }
            ExtraData extraData = metadataMap.get(xData.getName());
            if (extraData == null) {
                extraData = new ExtraData(xData.getName(), new PropertyTree());
                metadataMap.put(xData.getName(), extraData);
                extradatasBuilder.add(extraData);
            }
            if (FormItemType.INPUT.equals(formItem.getType())) {
                Input input = (Input) formItem;
                if (InputTypeName.DATE_TIME.equals(input.getInputType())) {
                    extraData.getData().addLocalDateTime(formItemName, ValueTypes.LOCAL_DATE_TIME.convert(entry.getValue().toArray()[0]));
                } else if (InputTypeName.LONG.equals(input.getInputType())) {
                    final Long[] longValues = entry.getValue().stream().map(Long::parseLong).toArray(Long[]::new);
                    extraData.getData().addLongs(formItemName, longValues);
                } else {
                    extraData.getData().addStrings(formItemName, entry.getValue());
                }
            }
        }
    }
    fillComputedFormItems(metadataMap.values(), mediaInfo, sourceAttachment);
    return extradatasBuilder.build();
}
Also used : HashMap(java.util.HashMap) FormItem(com.enonic.xp.form.FormItem) ExtraData(com.enonic.xp.content.ExtraData) XDataName(com.enonic.xp.schema.xdata.XDataName) Input(com.enonic.xp.form.Input) PropertyTree(com.enonic.xp.data.PropertyTree) ExtraDatas(com.enonic.xp.content.ExtraDatas) Collection(java.util.Collection) XData(com.enonic.xp.schema.xdata.XData) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 15 with FormItem

use of com.enonic.xp.form.FormItem in project xp by enonic.

the class ImageContentProcessor method extractGeoLocation.

private ExtraData extractGeoLocation(final MediaInfo mediaInfo, final XDatas xDatas) {
    final ImmutableMultimap<String, String> mediaItems = mediaInfo.getMetadata();
    final Double geoLat = parseDouble(mediaItems.get(GEO_LATITUDE).stream().findFirst().orElse(null));
    final Double geoLong = parseDouble(mediaItems.get(GEO_LONGITUDE).stream().findFirst().orElse(null));
    if (geoLat == null || geoLong == null) {
        return null;
    }
    final XData geoMixin = xDatas.getXData(MediaInfo.GPS_INFO_METADATA_NAME);
    if (geoMixin == null) {
        return null;
    }
    final ExtraData extraData = new ExtraData(geoMixin.getName(), new PropertyTree());
    final FormItem formItem = geoMixin.getForm().getFormItems().getItemByName(MediaInfo.GPS_INFO_GEO_POINT);
    if (FormItemType.INPUT.equals(formItem.getType())) {
        final Input input = (Input) formItem;
        if (InputTypeName.GEO_POINT.equals(input.getInputType())) {
            final GeoPoint geoPoint = new GeoPoint(geoLat, geoLong);
            extraData.getData().addGeoPoint(formItem.getName(), ValueTypes.GEO_POINT.convert(geoPoint));
        }
    }
    return extraData;
}
Also used : GeoPoint(com.enonic.xp.util.GeoPoint) Input(com.enonic.xp.form.Input) FormItem(com.enonic.xp.form.FormItem) PropertyTree(com.enonic.xp.data.PropertyTree) XData(com.enonic.xp.schema.xdata.XData) ExtraData(com.enonic.xp.content.ExtraData)

Aggregations

FormItem (com.enonic.xp.form.FormItem)18 Input (com.enonic.xp.form.Input)9 ContentType (com.enonic.xp.schema.content.ContentType)6 Test (org.junit.jupiter.api.Test)6 FormItemSet (com.enonic.xp.form.FormItemSet)5 FormOptionSet (com.enonic.xp.form.FormOptionSet)5 FieldSet (com.enonic.xp.form.FieldSet)4 FormOptionSetOption (com.enonic.xp.form.FormOptionSetOption)4 Form (com.enonic.xp.form.Form)3 ExtraData (com.enonic.xp.content.ExtraData)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 Occurrences (com.enonic.xp.form.Occurrences)2 InputTypeConfig (com.enonic.xp.inputtype.InputTypeConfig)2 XData (com.enonic.xp.schema.xdata.XData)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ExtraDatas (com.enonic.xp.content.ExtraDatas)1 PropertySet (com.enonic.xp.data.PropertySet)1 FormItems (com.enonic.xp.form.FormItems)1 InlineMixin (com.enonic.xp.form.InlineMixin)1