Search in sources :

Example 6 with MacroDescriptor

use of com.enonic.xp.macro.MacroDescriptor in project xp by enonic.

the class MacroDescriptorServiceImpl method getByKey.

@Override
public MacroDescriptor getByKey(final MacroKey key) {
    MacroDescriptor descriptor;
    if (isSystem(key.getApplicationKey())) {
        descriptor = builtinMacrosDescriptors.getByKey(key);
    } else {
        final ResourceProcessor<MacroKey, MacroDescriptor> descriptorProcessor = newDescriptorProcessor(key);
        descriptor = this.resourceService.processResource(descriptorProcessor);
        if (descriptor == null) {
            final ResourceProcessor<MacroKey, MacroDescriptor> controllerProcessor = newControllerProcessor(key);
            descriptor = this.resourceService.processResource(controllerProcessor);
        }
    }
    return descriptor;
}
Also used : MacroKey(com.enonic.xp.macro.MacroKey) MacroDescriptor(com.enonic.xp.macro.MacroDescriptor)

Example 7 with MacroDescriptor

use of com.enonic.xp.macro.MacroDescriptor in project xp by enonic.

the class MacroDescriptorServiceImpl method getAll.

@Override
public MacroDescriptors getAll() {
    final Set<MacroDescriptor> set = new LinkedHashSet<>(builtinMacrosDescriptors.getAll().getSet());
    for (final Application application : this.applicationService.getInstalledApplications()) {
        final MacroDescriptors macroDescriptors = getByApplication(application.getKey());
        set.addAll(macroDescriptors.getSet());
    }
    return MacroDescriptors.from(set);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MacroDescriptor(com.enonic.xp.macro.MacroDescriptor) Application(com.enonic.xp.app.Application) MacroDescriptors(com.enonic.xp.macro.MacroDescriptors)

Example 8 with MacroDescriptor

use of com.enonic.xp.macro.MacroDescriptor in project xp by enonic.

the class MacroDescriptorServiceImpl method getByApplication.

@Override
public MacroDescriptors getByApplication(final ApplicationKey applicationKey) {
    final List<MacroDescriptor> list = new ArrayList<>();
    if (isSystem(applicationKey)) {
        list.addAll(builtinMacrosDescriptors.getAll().getSet());
    } else {
        for (final DescriptorKey descriptorKey : descriptorKeyLocator.findKeys(applicationKey)) {
            final MacroKey macroKey = MacroKey.from(descriptorKey.getApplicationKey(), descriptorKey.getName());
            final MacroDescriptor descriptor = getByKey(macroKey);
            if (descriptor != null) {
                list.add(descriptor);
            }
        }
    }
    return MacroDescriptors.from(list);
}
Also used : MacroKey(com.enonic.xp.macro.MacroKey) MacroDescriptor(com.enonic.xp.macro.MacroDescriptor) ArrayList(java.util.ArrayList) DescriptorKey(com.enonic.xp.page.DescriptorKey)

Example 9 with MacroDescriptor

use of com.enonic.xp.macro.MacroDescriptor 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 10 with MacroDescriptor

use of com.enonic.xp.macro.MacroDescriptor in project xp by enonic.

the class ApplicationInfoServiceImplTest method mockMacros.

private void mockMacros(final ApplicationKey applicationKey) {
    final MacroDescriptor macroDescriptor1 = MacroDescriptor.create().key(MacroKey.from("my-app1:macro1")).description("my description").displayName("A macro").form(Form.create().build()).build();
    final MacroDescriptor macroDescriptor2 = MacroDescriptor.create().key(MacroKey.from("my-app2:macro2")).description("my description").displayName("B macro").form(Form.create().build()).build();
    final MacroDescriptors macroDescriptors = MacroDescriptors.from(macroDescriptor1, macroDescriptor2);
    Mockito.when(this.macroDescriptorService.getByApplications(ApplicationKeys.from(applicationKey, ApplicationKey.SYSTEM))).thenReturn(macroDescriptors);
}
Also used : MacroDescriptor(com.enonic.xp.macro.MacroDescriptor) MacroDescriptors(com.enonic.xp.macro.MacroDescriptors)

Aggregations

MacroDescriptor (com.enonic.xp.macro.MacroDescriptor)17 MacroKey (com.enonic.xp.macro.MacroKey)12 Test (org.junit.jupiter.api.Test)9 MacroDescriptors (com.enonic.xp.macro.MacroDescriptors)7 RenderException (com.enonic.xp.portal.impl.rendering.RenderException)6 ApplicationKey (com.enonic.xp.app.ApplicationKey)5 Form (com.enonic.xp.form.Form)5 Input (com.enonic.xp.form.Input)5 MacroProcessor (com.enonic.xp.portal.macro.MacroProcessor)5 Site (com.enonic.xp.site.Site)5 SiteConfig (com.enonic.xp.site.SiteConfig)5 ContentId (com.enonic.xp.content.ContentId)4 ContentPath (com.enonic.xp.content.ContentPath)4 PropertyTree (com.enonic.xp.data.PropertyTree)4 InputTypeName (com.enonic.xp.inputtype.InputTypeName)4 MacroDescriptorService (com.enonic.xp.macro.MacroDescriptorService)4 PortalRequest (com.enonic.xp.portal.PortalRequest)4 PortalResponse (com.enonic.xp.portal.PortalResponse)4 MacroProcessorFactory (com.enonic.xp.portal.macro.MacroProcessorFactory)4 ContentTypeName (com.enonic.xp.schema.content.ContentTypeName)4