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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations