Revision: 33191
Author: mnour
Date: 2012-02-28 17:47:52 +0100 (Tue, 28 Feb 2012)
Log Message:
-----------
HSTTWO-2049: Create rest service for channel manager
-# BlueprintService has been refactored to BlueprintHandler
-# Blueprint now is a true POJO
-# Spotted some more places where ChannelManager is used directly to get
channels information started to work on that
-# Still there is more refactory and more places to change but there is
progress everyday now
-# Also merged with some changes made by Jannis
Modified Paths:
--------------
hippo-cms7/addons/addon-channel-manager/trunk/frontend/pom.xml
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/RootPanel.java
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/channels/BlueprintStore.java
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/channels/ChannelStore.java
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/channels/ChannelStoreFactory.java
Modified: hippo-cms7/addons/addon-channel-manager/trunk/frontend/pom.xml
===================================================================
--- hippo-cms7/addons/addon-channel-manager/trunk/frontend/pom.xml
2012-02-28 16:34:56 UTC (rev 33190)
+++ hippo-cms7/addons/addon-channel-manager/trunk/frontend/pom.xml
2012-02-28 16:47:52 UTC (rev 33191)
@@ -18,15 +18,8 @@
</properties>
<dependencies>
-
<dependency>
<groupId>org.onehippo.cms7.hst</groupId>
- <artifactId>hst-api</artifactId>
- <version>${hippo.hst.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.onehippo.cms7.hst</groupId>
<artifactId>hst-rest-api</artifactId>
<version>${hippo.hst.version}</version>
<scope>provided</scope>
Modified:
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/RootPanel.java
===================================================================
---
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/RootPanel.java
2012-02-28 16:34:56 UTC (rev 33190)
+++
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/RootPanel.java
2012-02-28 16:47:52 UTC (rev 33191)
@@ -24,6 +24,7 @@
import org.hippoecm.frontend.plugin.IPluginContext;
import org.hippoecm.frontend.plugin.config.IPluginConfig;
import org.hippoecm.frontend.service.IRestProxyService;
+import org.hippoecm.hst.rest.BlueprintService;
import org.hippoecm.hst.rest.ChannelService;
import org.json.JSONException;
import org.json.JSONObject;
@@ -90,19 +91,21 @@
// Retrieve the Channel Service
ChannelService channelService = null;
+ BlueprintService blueprintService = null;
IRestProxyService restProxyService =
context.getService(config.getString(CONFIG_REST_PROXY_SERVICE_ID,
IRestProxyService.class.getName()), IRestProxyService.class);
if (restProxyService != null) {
channelService =
restProxyService.createRestProxy(ChannelService.class);
+ blueprintService =
restProxyService.createRestProxy(BlueprintService.class);
}
// COMMENT - MNour: Here we can inject the Channels REST service
- this.channelStore = ChannelStoreFactory.createStore(context,
channelListConfig, channelService);
+ this.channelStore = ChannelStoreFactory.createStore(context,
channelListConfig, channelService, blueprintService);
this.channelStoreFuture = new ExtStoreFuture<Object>(channelStore);
add(this.channelStore);
add(this.channelStoreFuture);
- this.blueprintStore = new BlueprintStore();
+ this.blueprintStore = new BlueprintStore(blueprintService);
// card 0: channel manager
final ExtPanel channelManagerCard = new ExtPanel();
Modified:
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/channels/BlueprintStore.java
===================================================================
---
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/channels/BlueprintStore.java
2012-02-28 16:34:56 UTC (rev 33190)
+++
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/channels/BlueprintStore.java
2012-02-28 16:47:52 UTC (rev 33191)
@@ -25,6 +25,7 @@
import org.hippoecm.hst.configuration.channel.Channel;
import org.hippoecm.hst.configuration.channel.ChannelException;
import org.hippoecm.hst.configuration.channel.ChannelManager;
+import org.hippoecm.hst.rest.BlueprintService;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -43,10 +44,18 @@
private static final long serialVersionUID = 1L;
private static final Logger log =
LoggerFactory.getLogger(BlueprintStore.class);
+ private transient List<Blueprint> blueprints;
private Long total;
+ private final BlueprintService blueprintService;
+ public BlueprintStore(BlueprintService blueprintService) {
+ super(Arrays.asList(new ExtField(FIELD_NAME), new
ExtField(FIELD_DESCRIPTION), new ExtField(FIELD_HAS_CONTENT_PROTOTYPE), new
ExtField(FIELD_CONTENT_ROOT)));
+ this.blueprintService = blueprintService;
+ }
+
public BlueprintStore() {
super(Arrays.asList(new ExtField(FIELD_NAME), new
ExtField(FIELD_DESCRIPTION), new ExtField(FIELD_HAS_CONTENT_PROTOTYPE), new
ExtField(FIELD_CONTENT_ROOT)));
+ this.blueprintService = null;
}
@Override
@@ -85,7 +94,7 @@
boolean hasPrototype = blueprint.hasContentPrototype();
object.put(FIELD_HAS_CONTENT_PROTOTYPE, hasPrototype);
- Channel channel = blueprint.createChannel();
+ Channel channel = blueprint.getPrototypeChannel();
object.put(FIELD_CONTENT_ROOT, channel.getContentRoot());
data.put(object);
@@ -94,18 +103,27 @@
}
private List<Blueprint> getBlueprints() {
- ChannelManager channelManager = ChannelUtil.getChannelManager();
- if (channelManager == null) {
- log.info("Cannot load the channel manager: no blueprints will be
shown.", ChannelManager.class.getName());
- return Collections.emptyList();
- }
-
- try {
- return channelManager.getBlueprints();
- } catch (ChannelException e) {
- log.warn("Error retrieving blueprints, no blueprints will be
shown", e);
- }
+ if (blueprints == null) {
+ if (blueprintService == null) {
+ ChannelManager channelManager =
ChannelUtil.getChannelManager();
+ if (channelManager == null) {
+ log.info("Cannot load the channel manager: no
blueprints will be shown.", ChannelManager.class.getName());
+ return Collections.emptyList();
+ }
- return Collections.emptyList();
+ try {
+ return channelManager.getBlueprints();
+ } catch (ChannelException e) {
+ log.warn("Error retrieving blueprints, no
blueprints will be shown", e);
+ }
+
+ return Collections.emptyList();
+ } else {
+ blueprints = blueprintService.getBlueprints();
+ }
+ }
+
+ return blueprints;
}
+
}
Modified:
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/channels/ChannelStore.java
===================================================================
---
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/channels/ChannelStore.java
2012-02-28 16:34:56 UTC (rev 33190)
+++
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/channels/ChannelStore.java
2012-02-28 16:47:52 UTC (rev 33191)
@@ -41,6 +41,7 @@
import org.hippoecm.hst.configuration.channel.Channel;
import org.hippoecm.hst.configuration.channel.ChannelException;
import org.hippoecm.hst.configuration.channel.ChannelManager;
+import org.hippoecm.hst.rest.BlueprintService;
import org.hippoecm.hst.rest.ChannelService;
import org.hippoecm.hst.security.HstSubject;
import org.hippoecm.hst.site.HstServices;
@@ -82,8 +83,10 @@
region,
url
}
+
public static final List<String> ALL_FIELD_NAMES;
public static final List<String> INTERNAL_FIELDS;
+
static {
List<String> names = new ArrayList<String>();
for (ChannelField field : ChannelField.values()) {
@@ -101,6 +104,9 @@
private static final long serialVersionUID = 1L;
private static final Logger log =
LoggerFactory.getLogger(ChannelStore.class);
+
+ private static final String
WARNING_MESSAGE_USING_CHANNEL_MANAGER_AS_FALLBACK = "No RESTful {} service
configured. Using channel manager as fallback!";
+
private transient List<Channel> channels;
private final String storeId;
@@ -108,18 +114,34 @@
private final SortOrder sortOrder;
private final LocaleResolver localeResolver;
private final ChannelService channelService;
+ private final BlueprintService blueprintService;
- public ChannelStore(String storeId, List<ExtField> fields, String
sortFieldName, SortOrder sortOrder, LocaleResolver localeResolver,
ChannelService channelService) {
+ public ChannelStore(String storeId, List<ExtField> fields, String
sortFieldName, SortOrder sortOrder,
+ LocaleResolver localeResolver, ChannelService channelService,
BlueprintService blueprintService) {
+
super(fields);
this.storeId = storeId;
this.sortFieldName = sortFieldName;
this.sortOrder = sortOrder;
this.localeResolver = localeResolver;
this.channelService = channelService;
+ this.blueprintService = blueprintService;
+
+ if (this.channelService == null) {
+ if (log.isWarnEnabled()) {
+
log.warn(WARNING_MESSAGE_USING_CHANNEL_MANAGER_AS_FALLBACK, "channel");
+ }
+ }
+
+ if (this.blueprintService == null) {
+ if (log.isWarnEnabled()) {
+ log.warn(WARNING_MESSAGE_USING_CHANNEL_MANAGER_AS_FALLBACK,
"blueprint");
+ }
+ }
}
public ChannelStore(String storeId, List<ExtField> fields, String
sortFieldName, SortOrder sortOrder, LocaleResolver localeResolver) {
- this(storeId, fields, sortFieldName, sortOrder, localeResolver, null);
+ this(storeId, fields, sortFieldName, sortOrder, localeResolver, null,
null);
}
@Override
@@ -274,18 +296,22 @@
protected JSONObject createRecord(JSONObject record) throws
ActionFailedException, JSONException {
final ChannelManager channelManager =
HstServices.getComponentManager().getComponent(ChannelManager.class.getName());
- // create new channel
+ // Create new channel
final String blueprintId = record.getString("blueprintId");
final Channel newChannel;
try {
- newChannel =
channelManager.getBlueprint(blueprintId).createChannel();
+ if (blueprintService == null) {
+ newChannel =
channelManager.getBlueprint(blueprintId).getPrototypeChannel();
+ } else {
+ newChannel =
blueprintService.getBlueprint(blueprintId).getPrototypeChannel();
+ }
} catch (ChannelException e) {
log.warn("Could not create new channel with blueprint '{}': {}",
blueprintId, e.getMessage());
log.debug("Cause:", e);
throw new
ActionFailedException(getResourceValue("error.blueprint.cannot.create.channel",
blueprintId), e);
}
- // set channel parameters
+ // Set channel parameters
final String channelName = record.getString("name");
newChannel.setName(channelName);
newChannel.setUrl(record.getString("url"));
Modified:
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/channels/ChannelStoreFactory.java
===================================================================
---
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/channels/ChannelStoreFactory.java
2012-02-28 16:34:56 UTC (rev 33190)
+++
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/channels/ChannelStoreFactory.java
2012-02-28 16:47:52 UTC (rev 33191)
@@ -24,6 +24,7 @@
import org.hippoecm.frontend.plugin.IPluginContext;
import org.hippoecm.frontend.plugin.config.IPluginConfig;
import org.hippoecm.frontend.translation.ILocaleProvider;
+import org.hippoecm.hst.rest.BlueprintService;
import org.hippoecm.hst.rest.ChannelService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -41,7 +42,7 @@
// prevent instantiation
}
- public static ChannelStore createStore(IPluginContext context,
IPluginConfig config, ChannelService channelService) {
+ public static ChannelStore createStore(IPluginContext context,
IPluginConfig config, ChannelService channelService, BlueprintService
blueprintService) {
Set<String> storeFieldNames = parseChannelFields(config);
// then create a list of all the Ext fields in the store
@@ -62,12 +63,13 @@
parseSortColumn(config, storeFieldNames),
parseSortOrder(config),
new LocaleResolver(localeProvider),
- channelService);
+ channelService,
+ blueprintService);
}
public static ChannelStore createStore(IPluginContext context,
IPluginConfig config) {
- return createStore(context, config, null);
+ return createStore(context, config, null, null);
}
static Set<String> parseChannelFields(IPluginConfig config) {
_______________________________________________
Hippocms-svn mailing list
[email protected]
https://lists.onehippo.org/mailman/listinfo/hippocms-svn