Instantly share code, notes, and snippets.
-
Save prb112/7155725 to your computer and use it in GitHub Desktop.
shows how to update tags in the social business toolkit sdk
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> | |
<%@page import="java.util.Collection"%> | |
<%@page import="java.io.PrintWriter"%> | |
<%@page import="com.ibm.commons.runtime.Context"%> | |
<%@page import="com.ibm.sbt.services.client.connections.communities.Community"%> | |
<%@page import="com.ibm.sbt.services.client.connections.communities.CommunityList"%> | |
<%@page import="com.ibm.sbt.services.client.connections.communities.CommunityService"%> | |
<%@page import="java.util.HashMap"%> | |
<%@page import="java.util.ArrayList"%> | |
<%@page import="java.util.List"%> | |
<%@page | |
language="java" contentType="text/html; charset=ISO-8859-1" | |
pageEncoding="ISO-8859-1"%> | |
<html> | |
<head> | |
<title>SBT JAVA Sample - Update Community Tags</title> | |
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> | |
</head> | |
<body> | |
<h4>Update Community Tags</h4> | |
<div id="content"> | |
<% | |
try { | |
/** | |
* Uses the smartCloudBasic endpoint, however it could be a forms | |
*/ | |
CommunityService communityService = new CommunityService("smartcloudBasic"); | |
/** | |
* Checks to see if the endpoint is authenticated | |
* if not, it forces the authentication | |
*/ | |
if(!communityService.getEndpoint().isAuthenticated()){ | |
communityService.getEndpoint().authenticate(true); | |
} | |
/* | |
* Outputs the Current List of Communities | |
*/ | |
CommunityList communities = communityService.getMyCommunities(); | |
out.println("Communities"); | |
out.println("<br/>"); | |
out.println("------------------"); | |
out.println("<br/>"); | |
for(Community c : communities){ | |
out.println(c.getCommunityUuid()); | |
out.println(" "); | |
out.println(c.getTitle()); | |
out.println("<br/>"); | |
} | |
out.println("------------------"); | |
out.println("<br/>"); | |
/* | |
* Gets a Specific Community Entity | |
*/ | |
//Cloud | |
//String communityUuid = "4aa94a1a-8710-4abf-ac63-b6a0c3d1e930"; | |
//Greenhouse | |
//String communityUuid = "2fba29fd-adfa-4d28-98cc-05cab12a7c43"; | |
//SBTDEV | |
String communityUuid = "5fefd8cc-b79e-4709-baac-9aa168f1f772"; | |
Community community = communityService.getCommunity(communityUuid); | |
/* | |
* Gets the current details of the Community | |
*/ | |
out.println(community.getTitle()); | |
out.println("<br/>"); | |
/* | |
* Outputs the current tags | |
*/ | |
List<String> tags = community.getTags(); | |
int tagCount = 1; | |
for(String tag : tags){ | |
out.println("Tag" + tagCount++ + ":" + tag); | |
out.println("<br/>"); | |
} | |
/* | |
* Creates a new tag list without the removed tag | |
*/ | |
String removeTag = "test3"; | |
List<String> updatedTags = new ArrayList<String>(); | |
for(String tag : tags){ | |
if(tag.compareTo(removeTag)!=0){ | |
updatedTags.add(tag); | |
} | |
} | |
out.println("<br/>"); | |
out.println(" Tag is removed "); | |
/* | |
* Update the Set Tags | |
*/ | |
community.setTags(updatedTags); | |
out.println("<br/>"); | |
out.println("Tags are updated in the Community Entity"); | |
/* | |
* Updates the Community with the given changes. | |
*/ | |
community.save(); | |
} catch (Exception e) { | |
out.println("<pre>"); | |
out.println(e.getMessage()); | |
out.println(e.getStackTrace()); | |
out.println("</pre>"); | |
e.printStackTrace(); | |
} | |
%> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment