use of com.enonic.xp.app.ApplicationKey in project xp by enonic.
the class ContentMapper method serializeExtraData.
private void serializeExtraData(final MapGenerator gen, final Iterable<ExtraData> values) {
gen.map("x");
final ListMultimap<ApplicationKey, ExtraData> extradatasByModule = ArrayListMultimap.create();
for (ExtraData extraData : values) {
extradatasByModule.put(extraData.getName().getApplicationKey(), extraData);
}
for (final ApplicationKey applicationKey : extradatasByModule.keys()) {
final List<ExtraData> extraDatas = extradatasByModule.get(applicationKey);
if (extraDatas.isEmpty()) {
continue;
}
gen.map(extraDatas.get(0).getApplicationPrefix());
for (final ExtraData extraData : extraDatas) {
gen.map(extraData.getName().getLocalName());
new PropertyTreeMapper(extraData.getData()).serialize(gen);
gen.end();
}
gen.end();
}
gen.end();
}
use of com.enonic.xp.app.ApplicationKey in project xp by enonic.
the class BaseContentHandler method createExtraDatas.
ExtraDatas createExtraDatas(final Map<String, Object> mapValue, final ContentTypeName contentTypeName) {
if (mapValue == null) {
return null;
}
final ExtraDatas.Builder extradatasBuilder = ExtraDatas.create();
mapValue.forEach((key, metadatasObject) -> {
final ApplicationKey applicationKey = ExtraData.fromApplicationPrefix(key);
if (metadatasObject instanceof Map) {
final Map<String, Object> metadatas = (Map<String, Object>) metadatasObject;
metadatas.forEach((metadataName, value) -> {
final XDataName xDataName = XDataName.from(applicationKey, metadataName);
final ExtraData item = createExtraData(xDataName, contentTypeName, value);
if (item != null) {
extradatasBuilder.add(item);
}
});
}
});
return extradatasBuilder.build();
}
use of com.enonic.xp.app.ApplicationKey in project xp by enonic.
the class DescriptorBasedComponentRenderer method doRender.
private PortalResponse doRender(final R component, final PortalRequest portalRequest) {
final ComponentDescriptor descriptor = resolveDescriptor(component);
if (descriptor == null) {
return renderEmptyComponent(component, portalRequest);
}
// create controller
final ControllerScript controllerScript = this.controllerScriptFactory.fromDir(descriptor.getComponentPath());
// render
final Component previousComponent = portalRequest.getComponent();
final ApplicationKey previousApplication = portalRequest.getApplicationKey();
try {
portalRequest.setComponent(component);
portalRequest.setApplicationKey(descriptor.getKey().getApplicationKey());
final PortalResponse portalResponse = controllerScript.execute(portalRequest);
final RenderMode renderMode = portalRequest.getMode();
final MediaType contentType = portalResponse.getContentType();
if (renderMode == RenderMode.EDIT && contentType != null && contentType.withoutParameters().type().equals("text")) {
final Object bodyObj = portalResponse.getBody();
if (bodyObj == null || (bodyObj instanceof String && nullToEmpty((String) bodyObj).isBlank())) {
if (portalResponse.getStatus().equals(HttpStatus.METHOD_NOT_ALLOWED)) {
final String errorMessage = "No method provided to handle request";
return renderErrorComponentPlaceHolder(component, errorMessage);
}
return renderEmptyComponent(component, portalRequest);
}
}
final PortalResponse injectedResponse = LIVE_EDIT_ATTRIBUTE_INJECTION.injectLiveEditAttribute(portalResponse, component.getType());
return injectedResponse;
} finally {
portalRequest.setComponent(previousComponent);
portalRequest.setApplicationKey(previousApplication);
}
}
use of com.enonic.xp.app.ApplicationKey in project xp by enonic.
the class ProcessorChainResolverTest method testFilterChainResolver.
@Test
public void testFilterChainResolver() {
ApplicationKey ak1 = ApplicationKey.from("ak1");
SiteConfig sc1 = SiteConfig.create().application(ak1).config(new PropertyTree()).build();
ApplicationKey ak2 = ApplicationKey.from("ak2");
SiteConfig sc2 = SiteConfig.create().application(ak2).config(new PropertyTree()).build();
ApplicationKey ak3 = ApplicationKey.from("ak3");
SiteConfig sc3 = SiteConfig.create().application(ak3).config(new PropertyTree()).build();
portalRequest.setSite(Site.create().siteConfigs(SiteConfigs.from(sc1, sc2, sc3)).name("Site").path("/site").parentPath(ContentPath.ROOT).build());
ResponseProcessorDescriptor fd12 = ResponseProcessorDescriptor.create().application(ak1).name("ak1-2").order(2).build();
ResponseProcessorDescriptor fd13 = ResponseProcessorDescriptor.create().application(ak1).name("ak1-3").order(3).build();
ResponseProcessorDescriptor fd15 = ResponseProcessorDescriptor.create().application(ak1).name("ak1-5").order(5).build();
SiteDescriptor sd1 = SiteDescriptor.create().responseProcessors(ResponseProcessorDescriptors.from(fd13, fd15, fd12)).build();
Mockito.when(siteService.getDescriptor(Mockito.eq(ak1))).thenReturn(sd1);
ResponseProcessorDescriptor fd21 = ResponseProcessorDescriptor.create().application(ak2).name("ak2-1").order(1).build();
ResponseProcessorDescriptor fd22 = ResponseProcessorDescriptor.create().application(ak2).name("ak1-2").order(2).build();
ResponseProcessorDescriptor fd23 = ResponseProcessorDescriptor.create().application(ak2).name("ak2-3").order(3).build();
SiteDescriptor sd2 = SiteDescriptor.create().responseProcessors(ResponseProcessorDescriptors.from(fd22, fd23, fd21)).build();
Mockito.when(siteService.getDescriptor(Mockito.eq(ak2))).thenReturn(sd2);
ResponseProcessorDescriptor fd32 = ResponseProcessorDescriptor.create().application(ak3).name("ak3-2").order(2).build();
SiteDescriptor sd3 = SiteDescriptor.create().responseProcessors(ResponseProcessorDescriptors.from(fd32)).build();
Mockito.when(siteService.getDescriptor(Mockito.eq(ak3))).thenReturn(sd3);
ResponseProcessorDescriptors filters = resolver.resolve(portalRequest);
assertEquals(7, filters.getSize());
ResponseProcessorDescriptor fd = filters.get(0);
assertEquals(1, fd.getOrder());
assertEquals(ak2, fd.getApplication());
fd = filters.get(1);
assertEquals(2, fd.getOrder());
assertEquals(ak1, fd.getApplication());
fd = filters.get(2);
assertEquals(2, fd.getOrder());
assertEquals(ak2, fd.getApplication());
fd = filters.get(3);
assertEquals(2, fd.getOrder());
assertEquals(ak3, fd.getApplication());
fd = filters.get(4);
assertEquals(3, fd.getOrder());
assertEquals(ak1, fd.getApplication());
fd = filters.get(5);
assertEquals(3, fd.getOrder());
assertEquals(ak2, fd.getApplication());
fd = filters.get(6);
assertEquals(5, fd.getOrder());
assertEquals(ak1, fd.getApplication());
}
use of com.enonic.xp.app.ApplicationKey in project xp by enonic.
the class ApplicationRegistryImpl method configureApplication.
@Override
public void configureApplication(final Bundle bundle, final Configuration configuration) {
requireNonNull(configuration, "configuration can't be null");
final ApplicationKey applicationKey = ApplicationKey.from(bundle);
final ApplicationAdaptor application = applications.compute(applicationKey, (key, existingApp) -> {
if (existingApp != null) {
if (existingApp.getConfig() == null) {
// Normal applications get configured when their bundles get in STARTING/STARTED state,
// but they already got installed via #installApplication and should exist in registry
LOG.info("Configuring application {} bundle {}", applicationKey, bundle.getBundleId());
existingApp.setConfig(configuration);
} else {
// Configured application (for which #setConfiguration was already called at least once)
// must mimic stop/start cycle without actual bundle stop/start
LOG.info("Reconfiguring application {} bundle {}", applicationKey, bundle.getBundleId());
applicationListenerHub.deactivated(existingApp);
existingApp.setConfig(configuration);
callInvalidators(applicationKey);
}
return existingApp;
} else {
// System applications don't get installed or stated via #installApplication/#startApplication,
// but they should get configured as soon as their bundles get started.
LOG.info("Registering configured application {} bundle {}", applicationKey, bundle.getBundleId());
final ApplicationAdaptor app = applicationFactoryService.getApplication(bundle);
if (app == null) {
throw new IllegalStateException("Can't configure application " + app);
}
app.setConfig(configuration);
return app;
}
});
applicationListenerHub.activated(application);
}
Aggregations