Revision: 33162
Author: mnour
Date: 2012-02-27 14:39:15 +0100 (Mon, 27 Feb 2012)
Log Message:
-----------
HSTTWO-2049: Create rest service for channel manager
- Now the ChannelStore is updated to bu created with an optional configured
RESTfull ChannelService which is then used, if available, to interact with
Channel RESTfull resources.
- If not available, ChannelStore will try to use the ChannelManager directly
so that would provide and backword compatibility/fallback policy for projects
deployed in the old way when hst-api is deployed in the shared class loader.
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/ChannelStore.java
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/ChannelUtil.java
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/plugins/channelactions/ChannelActionsPlugin.java
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/service/ChannelDocumentUrlService.java
hippo-cms7/addons/addon-channel-manager/trunk/pom.xml
hippo-cms7/addons/addon-channel-manager/trunk/repository/src/main/resources/channel-manager-perspective.xml
Added Paths:
-----------
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/ChannelManagerConsts.java
Modified: hippo-cms7/addons/addon-channel-manager/trunk/frontend/pom.xml
===================================================================
--- hippo-cms7/addons/addon-channel-manager/trunk/frontend/pom.xml
2012-02-27 13:36:20 UTC (rev 33161)
+++ hippo-cms7/addons/addon-channel-manager/trunk/frontend/pom.xml
2012-02-27 13:39:15 UTC (rev 33162)
@@ -25,6 +25,12 @@
<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>
+ </dependency>
<dependency>
<groupId>org.onehippo.cms7.hst</groupId>
@@ -94,11 +100,6 @@
<artifactId>hippo-addon-hst-configuration-editor-frontend</artifactId>
</dependency>
<dependency>
- <groupId>org.onehippo.cms7.hst</groupId>
- <artifactId>hst-rest-api</artifactId>
- </dependency>
-
- <dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>${commons-lang.version}</version>
Added:
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/ChannelManagerConsts.java
===================================================================
---
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/ChannelManagerConsts.java
(rev 0)
+++
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/ChannelManagerConsts.java
2012-02-27 13:39:15 UTC (rev 33162)
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2012 Hippo.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onehippo.cms7.channelmanager;
+
+/**
+ * Class to hold constant values used all-over the channel manager code
+ */
+public final class ChannelManagerConsts {
+
+ public static final String CONFIG_REST_PROXY_SERVICE_ID =
"rest.proxy.service.id";
+
+}
Property changes on:
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/ChannelManagerConsts.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Id
Added: svn:eol-style
## -0,0 +1 ##
+native
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-27 13:36:20 UTC (rev 33161)
+++
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/RootPanel.java
2012-02-27 13:39:15 UTC (rev 33162)
@@ -15,12 +15,16 @@
*/
package org.onehippo.cms7.channelmanager;
+import static
org.onehippo.cms7.channelmanager.ChannelManagerConsts.CONFIG_REST_PROXY_SERVICE_ID;
+
import org.apache.wicket.RequestCycle;
import org.apache.wicket.ResourceReference;
import org.apache.wicket.model.Model;
import org.hippoecm.frontend.PluginRequestTarget;
import org.hippoecm.frontend.plugin.IPluginContext;
import org.hippoecm.frontend.plugin.config.IPluginConfig;
+import org.hippoecm.frontend.service.IRestProxyService;
+import org.hippoecm.hst.rest.ChannelService;
import org.json.JSONException;
import org.json.JSONObject;
import org.onehippo.cms7.channelmanager.channels.BlueprintStore;
@@ -84,7 +88,16 @@
final IPluginConfig channelListConfig =
config.getPluginConfig(CONFIG_CHANNEL_LIST);
- this.channelStore = ChannelStoreFactory.createStore(context,
channelListConfig);
+ // Retrieve the Channel Service
+ ChannelService channelService = 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);
+ }
+
+ // COMMENT - MNour: Here we can inject the Channels REST service
+ this.channelStore = ChannelStoreFactory.createStore(context,
channelListConfig, channelService);
this.channelStoreFuture = new ExtStoreFuture<Object>(channelStore);
add(this.channelStore);
add(this.channelStoreFuture);
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-27 13:36:20 UTC (rev 33161)
+++
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/channels/ChannelStore.java
2012-02-27 13:39:15 UTC (rev 33162)
@@ -31,9 +31,7 @@
import javax.security.auth.Subject;
import org.apache.commons.lang.StringUtils;
-import org.apache.wicket.Application;
import org.apache.wicket.RequestCycle;
-import org.apache.wicket.Resource;
import org.apache.wicket.ResourceReference;
import org.apache.wicket.Session;
import org.apache.wicket.ajax.AjaxRequestTarget;
@@ -42,7 +40,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.core.container.ComponentManager;
+import org.hippoecm.hst.rest.ChannelService;
import org.hippoecm.hst.security.HstSubject;
import org.hippoecm.hst.site.HstServices;
import org.json.JSONArray;
@@ -100,21 +98,27 @@
private static final long serialVersionUID = 1L;
private static final Logger log =
LoggerFactory.getLogger(ChannelStore.class);
- private transient Map<String, Channel> channels;
+ private transient List<Channel> channels;
private final String storeId;
private final String sortFieldName;
private final SortOrder sortOrder;
private final LocaleResolver localeResolver;
+ private final ChannelService channelService;
- public ChannelStore(String storeId, List<ExtField> fields, String
sortFieldName, SortOrder sortOrder, LocaleResolver localeResolver) {
+ public ChannelStore(String storeId, List<ExtField> fields, String
sortFieldName, SortOrder sortOrder, LocaleResolver localeResolver,
ChannelService channelService) {
super(fields);
this.storeId = storeId;
this.sortFieldName = sortFieldName;
this.sortOrder = sortOrder;
this.localeResolver = localeResolver;
+ this.channelService = channelService;
}
+ public ChannelStore(String storeId, List<ExtField> fields, String
sortFieldName, SortOrder sortOrder, LocaleResolver localeResolver) {
+ this(storeId, fields, sortFieldName, sortOrder, localeResolver, null);
+ }
+
@Override
protected JSONObject getProperties() throws JSONException {
//Need the sortinfo and xaction params since we are using
GroupingStore instead of
@@ -144,8 +148,8 @@
protected JSONArray getData() throws JSONException {
JSONArray data = new JSONArray();
- RequestCycle rc = RequestCycle.get();
- for (Channel channel : getChannels().values()) {
+ RequestCycle requestCycle = RequestCycle.get();
+ for (Channel channel : getChannels()) {
Map<String, Object> channelProperties = channel.getProperties();
JSONObject object = new JSONObject();
for (ExtField field : getFields()) {
@@ -157,11 +161,11 @@
if (StringUtils.isNotBlank(fieldValue)) {
if (ChannelField.type.toString().equals(field.getName())) {
- CharSequence typeImgUrl = rc.urlFor(new
ResourceReference(ChannelManagerPerspective.class, fieldValue+"-type.png"));
+ CharSequence typeImgUrl = requestCycle.urlFor(new
ResourceReference(ChannelManagerPerspective.class, fieldValue+"-type.png"));
object.put(field.getName() + "_img",
typeImgUrl.toString());
}
if
(ChannelField.region.toString().equals(field.getName())) {
- CharSequence regionImgUrl = rc.urlFor(new
ResourceReference(ChannelManagerPerspective.class, fieldValue+"-region.png"));
+ CharSequence regionImgUrl = requestCycle.urlFor(new
ResourceReference(ChannelManagerPerspective.class, fieldValue+"-region.png"));
object.put(field.getName() + "_img",
regionImgUrl.toString());
}
}
@@ -180,9 +184,8 @@
return getResourceValue("field." + fieldName);
}
- // custom channel property; translations are provided by the resource
bundle of the custom ChannelInfo class
- Map<String, Channel> channelMap = getChannels();
- for (Channel channel : channelMap.values()) {
+ // Custom channel property; translations are provided by the resource
bundle of the custom ChannelInfo class
+ for (Channel channel : getChannels()) {
String header =
ChannelResourceModel.getChannelResourceValue(channel, fieldName);
if (header != null) {
return header;
@@ -333,21 +336,27 @@
return new
ActionFailedException(getResourceValue("error.cannot.create.channel",
newChannel.getName()));
}
- private Map<String, Channel> getChannels() {
+ private List<Channel> getChannels() {
if (channels == null) {
- // reload channels
- ChannelManager channelManager = ChannelUtil.getChannelManager();
- if (channelManager == null) {
- log.info("Cannot load the channel manager. No channels will be
shown.");
- return Collections.emptyMap();
- }
- try {
- channels = channelManager.getChannels();
- } catch (ChannelException e) {
- log.error("Failed to retrieve channels", e);
- return Collections.emptyMap();
- }
+ // Re/Load channels
+ if (channelService == null) {
+ ChannelManager channelManager =
ChannelUtil.getChannelManager();
+ if (channelManager == null) {
+ log.info("Cannot load the channel
manager. No channels will be shown.");
+ return Collections.emptyList();
+ }
+ try {
+ channels = new
ArrayList<Channel>(channelManager.getChannels().values());
+ } catch (ChannelException e) {
+ log.error("Failed to retrieve
channels", e);
+ return Collections.emptyList();
+ }
+ } else {
+ channels = channelService.getChannels();
+ }
+ channels = channelService.getChannels();
}
+
return channels;
}
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-27 13:36:20 UTC (rev 33161)
+++
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/channels/ChannelStoreFactory.java
2012-02-27 13:39:15 UTC (rev 33162)
@@ -24,11 +24,11 @@
import org.hippoecm.frontend.plugin.IPluginContext;
import org.hippoecm.frontend.plugin.config.IPluginConfig;
import org.hippoecm.frontend.translation.ILocaleProvider;
+import org.hippoecm.hst.rest.ChannelService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wicketstuff.js.ext.data.ExtField;
-
public final class ChannelStoreFactory {
private static final Logger log =
LoggerFactory.getLogger(ChannelStore.class);
@@ -41,7 +41,7 @@
// prevent instantiation
}
- public static ChannelStore createStore(IPluginContext context,
IPluginConfig config) {
+ public static ChannelStore createStore(IPluginContext context,
IPluginConfig config, ChannelService channelService) {
Set<String> storeFieldNames = parseChannelFields(config);
// then create a list of all the Ext fields in the store
@@ -50,17 +50,26 @@
fieldList.add(new ExtField(storeFieldName));
}
- // get the Hippo locale provider to resolve locales of new channels
+ // Retrieve the Hippo locale provider to resolve locales of new
channels
String localeProviderServiceId =
config.getString(ILocaleProvider.SERVICE_ID, ILocaleProvider.class.getName());
ILocaleProvider localeProvider =
context.getService(localeProviderServiceId, ILocaleProvider.class);
if (localeProvider == null) {
- throw new IllegalStateException("Cannot find locale provider
service with ID '" + localeProviderServiceId + "'");
+ throw new IllegalStateException(String.format("Cannot find locale
provider service with ID '%s'", localeProviderServiceId));
}
- return new ChannelStore("channel-store", fieldList,
parseSortColumn(config, storeFieldNames),
- parseSortOrder(config), new LocaleResolver(localeProvider));
+ return new ChannelStore("channel-store",
+ fieldList,
+ parseSortColumn(config, storeFieldNames),
+ parseSortOrder(config),
+ new LocaleResolver(localeProvider),
+ channelService);
+
}
+ public static ChannelStore createStore(IPluginContext context,
IPluginConfig config) {
+ return createStore(context, config, null);
+ }
+
static Set<String> parseChannelFields(IPluginConfig config) {
Set<String> storeFieldNames = new HashSet<String>();
Modified:
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/channels/ChannelUtil.java
===================================================================
---
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/channels/ChannelUtil.java
2012-02-27 13:36:20 UTC (rev 33161)
+++
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/channels/ChannelUtil.java
2012-02-27 13:39:15 UTC (rev 33162)
@@ -30,7 +30,7 @@
return null;
}
- return
HstServices.getComponentManager().getComponent(ChannelManager.class.getName());
+ return componentManager.getComponent(ChannelManager.class.getName());
}
/**
Modified:
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/plugins/channelactions/ChannelActionsPlugin.java
===================================================================
---
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/plugins/channelactions/ChannelActionsPlugin.java
2012-02-27 13:36:20 UTC (rev 33161)
+++
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/plugins/channelactions/ChannelActionsPlugin.java
2012-02-27 13:39:15 UTC (rev 33162)
@@ -15,6 +15,8 @@
*/
package org.onehippo.cms7.channelmanager.plugins.channelactions;
+import static
org.onehippo.cms7.channelmanager.ChannelManagerConsts.CONFIG_REST_PROXY_SERVICE_ID;
+
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
@@ -48,13 +50,12 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@SuppressWarnings("deprecation")
+@SuppressWarnings({ "deprecation", "serial" })
public class ChannelActionsPlugin extends
CompatibilityWorkflowPlugin<Workflow> {
private static final Logger log =
LoggerFactory.getLogger(ChannelActionsPlugin.class);
private static final Comparator<ChannelDocument>
DEFAULT_CHANNEL_DOCUMENT_COMPARATOR = new ChannelDocumentNameComparator();
- public static final String CONFIG_REST_PROXY_SERVICE_ID =
"rest.proxy.service.id";
public static final String CONFIG_CHANNEL_MANAGER_SERVICE_ID =
"channel.manager.service.id";
private final IRestProxyService restProxyService;
@@ -83,7 +84,8 @@
@Override
protected void onModelChanged() {
super.onModelChanged();
- WorkflowDescriptorModel model = (WorkflowDescriptorModel)
ChannelActionsPlugin.this.getDefaultModel();
+ @SuppressWarnings("rawtypes")
+ WorkflowDescriptorModel model = (WorkflowDescriptorModel)
ChannelActionsPlugin.this.getDefaultModel();
if (model != null) {
try {
Node node = model.getNode();
Modified:
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/service/ChannelDocumentUrlService.java
===================================================================
---
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/service/ChannelDocumentUrlService.java
2012-02-27 13:36:20 UTC (rev 33161)
+++
hippo-cms7/addons/addon-channel-manager/trunk/frontend/src/main/java/org/onehippo/cms7/channelmanager/service/ChannelDocumentUrlService.java
2012-02-27 13:39:15 UTC (rev 33162)
@@ -15,6 +15,8 @@
*/
package org.onehippo.cms7.channelmanager.service;
+import static
org.onehippo.cms7.channelmanager.ChannelManagerConsts.CONFIG_REST_PROXY_SERVICE_ID;
+
import javax.jcr.Node;
import javax.jcr.RepositoryException;
@@ -35,7 +37,7 @@
*
* The following configuration properties are available:
* <ul>
- * <li>'rest.proxy.service.id': the ID of the REST proxy service to use. If
omitted, the default REST proxy service is
+ * <li>'rest.proxy.service.id': Referenced by CONFIG_REST_PROXY_SERVICE_ID
constant, The ID of the REST proxy service to use. If omitted, the default REST
proxy service is
* used.</li>
* <li>'service.id': the ID to register this service under.</li>
* <li>'type': the type of mounts to use for link creation. If omitted or
empty, the type 'live' is used.</li>
@@ -43,8 +45,6 @@
*/
public class ChannelDocumentUrlService extends Plugin implements
IDocumentUrlService {
- public static final String CONFIG_REST_PROXY_SERVICE_ID =
"rest.proxy.service.id";
-
private static final String DEFAULT_TYPE = "live";
private static final Logger log =
LoggerFactory.getLogger(ChannelDocumentUrlService.class);
private static final long serialVersionUID = 1L;
Modified: hippo-cms7/addons/addon-channel-manager/trunk/pom.xml
===================================================================
--- hippo-cms7/addons/addon-channel-manager/trunk/pom.xml 2012-02-27
13:36:20 UTC (rev 33161)
+++ hippo-cms7/addons/addon-channel-manager/trunk/pom.xml 2012-02-27
13:39:15 UTC (rev 33162)
@@ -50,11 +50,6 @@
<artifactId>hippo-cms-api</artifactId>
<version>${hippo.cms.version}</version>
</dependency>
- <dependency>
- <groupId>org.onehippo.cms7.hst</groupId>
- <artifactId>hst-rest-api</artifactId>
- <version>${hippo.hst.version}</version>
- </dependency>
<!-- Test dependencies -->
<dependency>
Modified:
hippo-cms7/addons/addon-channel-manager/trunk/repository/src/main/resources/channel-manager-perspective.xml
===================================================================
---
hippo-cms7/addons/addon-channel-manager/trunk/repository/src/main/resources/channel-manager-perspective.xml
2012-02-27 13:36:20 UTC (rev 33161)
+++
hippo-cms7/addons/addon-channel-manager/trunk/repository/src/main/resources/channel-manager-perspective.xml
2012-02-27 13:39:15 UTC (rev 33162)
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<sv:node sv:name="channel-manager-perspective"
xmlns:sv="http://www.jcp.org/jcr/sv/1.0"
xmlns:h="http://www.onehippo.org/jcr/xmlimport" h:merge="insert"
h:location="browserLoader">
+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>frontend:plugin</sv:value>
</sv:property>
@@ -16,7 +17,9 @@
<sv:property sv:name="wicket.id" sv:type="String">
<sv:value>service.tab</sv:value>
</sv:property>
-
+ <sv:property sv:name="rest.proxy.service.id" sv:type="String">
+ <sv:value>hst.rest.proxy.service</sv:value>
+ </sv:property>
<sv:node sv:name="channel-list">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>frontend:pluginconfig</sv:value>
@@ -33,13 +36,11 @@
<sv:value>ascending</sv:value>
</sv:property>
</sv:node>
-
<sv:node sv:name="templatecomposer">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>frontend:pluginconfig</sv:value>
</sv:property>
</sv:node>
-
<sv:node sv:name="layout.wireframe">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>frontend:pluginconfig</sv:value>
@@ -57,5 +58,4 @@
<sv:value>center</sv:value>
</sv:property>
</sv:node>
-
-</sv:node>
\ No newline at end of file
+</sv:node>
_______________________________________________
Hippocms-svn mailing list
[email protected]
https://lists.onehippo.org/mailman/listinfo/hippocms-svn