forked from OpenNTF/SocialSDK
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Community Widget base feature: "Add Widget"
- Loading branch information
Showing
8 changed files
with
943 additions
and
0 deletions.
There are no files selected for viewing
226 changes: 226 additions & 0 deletions
226
...bm.sbt.core/src/main/java/com/ibm/sbt/services/client/connections/communities/Widget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,226 @@ | ||
package com.ibm.sbt.services.client.connections.communities; | ||
|
||
import org.w3c.dom.Node; | ||
|
||
import com.ibm.commons.xml.NamespaceContext; | ||
import com.ibm.commons.xml.xpath.XPathExpression; | ||
import com.ibm.sbt.services.client.ClientServicesException; | ||
import com.ibm.sbt.services.client.base.AtomEntity; | ||
import com.ibm.sbt.services.client.base.BaseService; | ||
import com.ibm.sbt.services.client.base.datahandlers.XmlDataHandler; | ||
import com.ibm.sbt.services.client.connections.communities.model.WidgetXPath; | ||
import com.ibm.sbt.services.client.connections.communities.serializers.WidgetSerializer; | ||
|
||
/** | ||
* This File represents Community Widget | ||
* | ||
* @author Christian Gosch, inovex GmbH | ||
* | ||
*/ | ||
public class Widget extends AtomEntity { | ||
|
||
public Widget(WidgetCommunityService communityService, String id) { | ||
setService(communityService); | ||
setAsString(WidgetXPath.id, id); | ||
} | ||
|
||
public Widget() {} | ||
|
||
public Widget(String id) { | ||
setAsString(WidgetXPath.id, id); | ||
} | ||
|
||
public Widget(BaseService service, Node node, NamespaceContext namespaceCtx, | ||
XPathExpression xpathExpression) | ||
{ | ||
super(service, node, namespaceCtx, xpathExpression); | ||
} | ||
|
||
public Widget(WidgetCommunityService svc, XmlDataHandler handler) | ||
{ | ||
super(svc,handler); | ||
} | ||
|
||
/** | ||
* getId | ||
* | ||
* @return id (ATOM id URL) | ||
*/ | ||
public String getId() { | ||
return getAsString(WidgetXPath.id); | ||
} | ||
|
||
/** | ||
* getTitle | ||
* | ||
* @return title (Widget title) | ||
*/ | ||
public String getTitle() { | ||
return getAsString(WidgetXPath.title); | ||
} | ||
|
||
/** | ||
* Method sets the Widget title (Widget title) | ||
*/ | ||
public void setTitle(String title) { | ||
setAsString(WidgetXPath.title, title); | ||
} | ||
|
||
/** | ||
* getWidgetAtomUrl | ||
* | ||
* @return widgetAtomUrl (URL to get this Widgets ATOM entry.) | ||
*/ | ||
public String getWidgetAtomUrl() { | ||
return getAsString(WidgetXPath.widgetAtomUrl); | ||
} | ||
|
||
/** | ||
* getWidgetsEditUrl | ||
* | ||
* @return widgetsEditUrl (URL to use to edit Widget.) | ||
*/ | ||
public String getWidgetsEditUrl() { | ||
return getAsString(WidgetXPath.widgetsEditUrl); | ||
} | ||
|
||
/** | ||
* getWidgetUrl | ||
* | ||
* @return widgetUrl (URL that can be used in a Web browser to display the Widget.) | ||
*/ | ||
public String getWidgetUrl() { | ||
return getAsString(WidgetXPath.widgetBrowserUrl); | ||
} | ||
|
||
/** | ||
* getWidgetDefId | ||
* | ||
* <br><strong>valid values:</strong> StatusUpdates, Forum, Bookmarks, Files; Blog, IdeationBlog, Activities, Wiki, Calendar, RelatedCommunities, SubcommunityNav | ||
* | ||
* @return widgetDefId (Indicates the type of widget. Must match the widgetDefId of an enabled widget; Will be required for POSTs, Ignored for PUTs.) | ||
*/ | ||
public String getWidgetDefId() { | ||
return getAsString(WidgetXPath.widgetDefId); | ||
} | ||
|
||
/** | ||
* setWidgetDefId | ||
* | ||
* <br><strong>valid values:</strong> StatusUpdates, Forum, Bookmarks, Files; Blog, IdeationBlog, Activities, Wiki, Calendar, RelatedCommunities, SubcommunityNav | ||
* | ||
* @param widgetDefId (Indicates the type of widget. Must match the widgetDefId of an enabled widget; Will be required for POSTs, Ignored for PUTs.) | ||
*/ | ||
public void setWidgetDefId(String widgetDefId) { | ||
setAsString(WidgetXPath.widgetDefId, widgetDefId); | ||
} | ||
|
||
/** | ||
* getWidgetCategory | ||
* | ||
* @return widgetCategory (Category from Widget Configuration file.) | ||
*/ | ||
public String getWidgetCategory() { | ||
return getAsString(WidgetXPath.widgetCategory); | ||
} | ||
|
||
/** | ||
* getWidgetInstanceId | ||
* | ||
* @return widgetInstanceId (Widget Instance ID, required for PUT, ignored for POST, DELETE.) | ||
*/ | ||
public String getWidgetInstanceId() { | ||
return getAsString(WidgetXPath.widgetInstanceId); | ||
} | ||
|
||
/** | ||
* setWidgetInstanceId | ||
* | ||
* @param widgetInstanceId (Widget Instance ID, required for PUT, ignored for POST, DELETE.) | ||
*/ | ||
public void setWidgetInstanceId(String widgetInstanceId) { | ||
setAsString(WidgetXPath.widgetInstanceId, widgetInstanceId); | ||
} | ||
|
||
/** | ||
* getWidgetHidden | ||
* | ||
* @return widgetHidden (Hidden/Visible state, optional default false.) | ||
*/ | ||
public boolean getWidgetHidden() { | ||
return getAsBoolean(WidgetXPath.widgetHidden); | ||
} | ||
|
||
/** | ||
* setWidgetHidden | ||
* | ||
* @param widgetHidden (Hidden/Visible state, optional default false.) | ||
*/ | ||
public void setWidgetHidden(boolean widgetHidden) { | ||
setAsBoolean(WidgetXPath.widgetHidden, widgetHidden); | ||
} | ||
|
||
/** | ||
* getWidgetLocation | ||
* | ||
* <br><strong>valid values</strong>: col2 or col3 (or col2statusposts for Status Updates widget only) | ||
* | ||
* @return widgetLocation (Column location, required unless snx:hidden is true in which case it's ignored.) | ||
*/ | ||
public String getWidgetLocation() { | ||
return getAsString(WidgetXPath.widgetLocation); | ||
} | ||
|
||
/** | ||
* setWidgetLocation | ||
* | ||
* <br><strong>valid values</strong>: col2 or col3 (or col2statusposts for Status Updates widget only) | ||
* | ||
* @param widgetLocation (Column location, required unless snx:hidden is true in which case it's ignored.) | ||
*/ | ||
public void setWidgetLocation(String widgetLocation) { | ||
setAsString(WidgetXPath.widgetLocation, widgetLocation); | ||
} | ||
|
||
/** | ||
* getPreviousWidgetInstanceId | ||
* | ||
* <br><strong>valid values</strong>: ID or empty if first item in column | ||
* | ||
* @return previousWidgetInstanceId (Position given by previous widget instance id, optional. ignored if snx:hidden is true.) | ||
*/ | ||
public String getPreviousWidgetInstanceId() { | ||
return getAsString(WidgetXPath.previousWidgetInstanceId); | ||
} | ||
|
||
/** | ||
* setPreviousWidgetInstanceId | ||
* | ||
* <br><strong>valid values</strong>: ID or empty if first item in column | ||
* | ||
* @param previousWidgetInstanceId (Position given by previous widget instance id, optional. ignored if snx:hidden is true.) | ||
*/ | ||
public void setPreviousWidgetInstanceId(String previousWidgetInstanceId) { | ||
setAsString(WidgetXPath.previousWidgetInstanceId, previousWidgetInstanceId); | ||
} | ||
|
||
// XML persistence methods | ||
|
||
/** | ||
* This method is used by communityService wrapper methods to construct request body for Add/Update operations | ||
* @return Object | ||
*/ | ||
public Object constructCreateRequestBody() throws ClientServicesException { | ||
return createWidgetRequestPayload(); | ||
} | ||
|
||
private String createWidgetRequestPayload() throws ClientServicesException { | ||
WidgetSerializer serializer = new WidgetSerializer(this); | ||
String xml = serializer.createPayload(); | ||
return xml; | ||
} | ||
|
||
|
||
// TODO: Add methods to handle Widget properties. XML looks like sequence of: <snx:widgetProperty key="...">...</snx:widgetProperty> and forms a map. | ||
|
||
} |
162 changes: 162 additions & 0 deletions
162
...re/src/main/java/com/ibm/sbt/services/client/connections/communities/WidgetCommunity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
package com.ibm.sbt.services.client.connections.communities; | ||
|
||
import java.util.Map; | ||
|
||
import org.w3c.dom.Node; | ||
|
||
import com.ibm.commons.util.StringUtil; | ||
import com.ibm.commons.xml.NamespaceContext; | ||
import com.ibm.commons.xml.xpath.XPathExpression; | ||
import com.ibm.sbt.services.client.ClientServicesException; | ||
import com.ibm.sbt.services.client.base.BaseService; | ||
import com.ibm.sbt.services.client.base.datahandlers.EntityList; | ||
import com.ibm.sbt.services.client.base.datahandlers.XmlDataHandler; | ||
import com.ibm.sbt.services.client.connections.communities.model.CommunityXPath; | ||
|
||
/** | ||
* This class implements additional services to manage widgets inside a Connections Community. | ||
* This code should become part of Community, like management services for Bookmarks, Subcommunities etc. | ||
* The Community Widget itself is modeled by Widget, WidgetXPath etc. | ||
* | ||
* @author Christian Gosch, inovex GmbH, based on code by Carlos Manias | ||
* | ||
*/ | ||
public class WidgetCommunity extends Community { | ||
|
||
/** | ||
* Constructor (THIS IS AN EXTENDED COMMUNITY!) | ||
* | ||
* @param communityService | ||
* @param communityUuid | ||
*/ | ||
public WidgetCommunity(WidgetCommunityService communityService, String communityUuid) { | ||
setService(communityService); | ||
setAsString(CommunityXPath.communityUuid, communityUuid); | ||
} | ||
|
||
public WidgetCommunity(){} | ||
|
||
/** | ||
* Constructor (THIS IS AN EXTENDED COMMUNITY!) | ||
* | ||
* @param communityUuid | ||
*/ | ||
public WidgetCommunity(String communityUuid) { | ||
setAsString(CommunityXPath.communityUuid, communityUuid); | ||
} | ||
|
||
/** | ||
* Constructor (THIS IS AN EXTENDED COMMUNITY!) | ||
* @param svc | ||
* @param handler | ||
*/ | ||
public WidgetCommunity(WidgetCommunityService svc, XmlDataHandler handler) { | ||
super(svc,handler); | ||
} | ||
|
||
/** | ||
* | ||
* @param service | ||
* @param node | ||
* @param namespaceCtx | ||
* @param xpathExpression | ||
*/ | ||
public WidgetCommunity(BaseService service, Node node, NamespaceContext namespaceCtx, | ||
XPathExpression xpathExpression) { | ||
super(service, node, namespaceCtx, xpathExpression); | ||
} | ||
|
||
// Overridden persistence methods | ||
|
||
/** | ||
* This method loads the "widget enabled" community | ||
* | ||
* @return | ||
* @throws ClientServicesException | ||
*/ | ||
|
||
public WidgetCommunity load() throws ClientServicesException | ||
{ | ||
return getService().getCommunity(getCommunityUuid()); | ||
} | ||
|
||
/** | ||
* This method updates the "widget enabled" community on the server | ||
* | ||
* @return | ||
* @throws ClientServicesException | ||
*/ | ||
public WidgetCommunity save() throws ClientServicesException{ | ||
if(StringUtil.isEmpty(getCommunityUuid())){ | ||
String id = getService().createCommunity(this); | ||
return getService().getCommunity(id); | ||
}else{ | ||
getService().updateCommunity(this); | ||
return getService().getCommunity(getCommunityUuid()); | ||
} | ||
} | ||
|
||
@Override | ||
public WidgetCommunityService getService(){ | ||
return (WidgetCommunityService)super.getService(); | ||
} | ||
|
||
// Additional service methods for managing Widgets inside a Community | ||
|
||
/** Create widget of given type at this community | ||
* @param widgetDefId (required) | ||
* @return Widget created | ||
*/ | ||
public Widget createCommunityWidget(WidgetDefId widgetDefId) throws ClientServicesException { | ||
return getService().createCommunityWidget(this, widgetDefId); | ||
} | ||
|
||
/** | ||
* This method gets the widgets of a community | ||
* | ||
* @return list of widgets | ||
* @throws ClientServicesException | ||
*/ | ||
public EntityList<Widget> getCommunityWidgets() throws ClientServicesException { | ||
return getService().getCommunityWidgets(getCommunityUuid()); | ||
} | ||
|
||
/** | ||
* This method gets the widgets of a community | ||
* | ||
* @param widgetDefId | ||
* @return list of widgets | ||
* @throws ClientServicesException | ||
*/ | ||
public EntityList<Widget> getCommunityWidgets(WidgetDefId widgetDefId) throws ClientServicesException { | ||
return getService().getCommunityWidgets(getCommunityUuid(), widgetDefId); | ||
} | ||
|
||
/** | ||
* This method gets the widgets of a community | ||
* | ||
* @param parameters | ||
* Various parameters that can be passed to get a feed of widgets of a community. | ||
* The parameters must be exactly as they are supported by IBM Connections like ps, sortBy etc. | ||
* @return list of widgets | ||
* @throws ClientServicesException | ||
*/ | ||
public EntityList<Widget> getCommunityWidgets(Map<String, String> parameters) throws ClientServicesException { | ||
return getService().getCommunityWidgets(getCommunityUuid(), parameters ); | ||
} | ||
|
||
/** | ||
* This method gets the widgets of a community | ||
* | ||
* @param widgetDefId | ||
* @param parameters | ||
* Various parameters that can be passed to get a feed of widgets of a community. | ||
* The parameters must be exactly as they are supported by IBM Connections like ps, sortBy etc. | ||
* @return list of widgets | ||
* @throws ClientServicesException | ||
*/ | ||
public EntityList<Widget> getCommunityWidgets(WidgetDefId widgetDefId, Map<String, String> parameters) throws ClientServicesException { | ||
return getService().getCommunityWidgets(getCommunityUuid(), widgetDefId, parameters ); | ||
} | ||
|
||
} |
Oops, something went wrong.