Skip navigation

Jive Developers

1 Post authored by: norick

For some time now, we've been wishing for an easy way to update the URLs for Places. Sometimes we name a Place in a hurry and later come up with a better name. Jive allows us to change quite a bit about a Place, but currently, changing the "displayName", the name that appears at the end of the Place's URL, is impossible through Jive's web interface and the Admin Console. It is only possible via the Jive REST API which, frankly, isn't quite that convenient for busy Community Administrators.

 

To fix this problem of inconvenience, I've created a .NET app (code included below) that allows administrators to quickly update a Place's displayName using Jive's .NET SDK. To update a Place, one must simply log in to their Jive account through the app, select the Place whose URL they would like to change, and provide a new displayName for the Place.

 

When we implemented this functionality for our Jive instance, we wrapped this app in an ASP.NET Web API controller, hosted the code on a web server, and created a web app that makes requests to the hosted app. This allowed us to build a UI that further simplified the process of updating Places. For the sake of simplicity, here I am only sharing the C# code for the app. But note that this can be easily built on top of.

 

Here is the code for the .NET app:

 

using System.Collections.Generic;
using Net.Pokeshot.JiveSdk.Models;
using Net.Pokeshot.JiveSdk.Clients;
using System.Net;
using System;


namespace PlaceUpdaterConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            string jiveUrl, username, password;


            // Get User/Site Info.
            Console.Write("Jive Community Url: ");
            jiveUrl = Console.ReadLine();


            Console.Write("Jive Username: ");
            username = Console.ReadLine();


            Console.Write("Password: ");
            password = Console.ReadLine();
            Console.WriteLine();
            Console.WriteLine();


            var creds = new NetworkCredential(username, password);


            // Get a list of places available.
            PlacesClient p = new PlacesClient(jiveUrl, creds);
            var places = p.GetPlaces(count: int.MaxValue);
            printPlaces(places);


            var selectedPlace = selectPlace(places);
            Console.WriteLine("Current URL for {0}:\n{1}", selectedPlace.name, selectedPlace?.resources?.html?.@ref);


            string url = selectedPlace?.resources?.html?.@ref;
            int lastSlash = url?.LastIndexOf('/') ?? 0;
            Console.Write("\nNew URL:\n{0}", url.Remove(lastSlash + 1, url.Length - lastSlash - 1));
            string displayName = Console.ReadLine();


            // Update the display name of the place the user selected.
            selectedPlace.displayName = displayName;


            Console.Write("\nChange {0}'s URL? (y/n): ", selectedPlace.name);
            var isCorrect = Console.ReadLine();
            if (isCorrect != "y" && isCorrect != "Y")
            {
                Console.WriteLine("\nOperation Canceled");
                return;
            }


            // Send the newly updated Place back to Jive.
            p.UpdatePlace(int.Parse(selectedPlace.placeID), selectedPlace);


            Console.WriteLine("\nSuccessfully Updated");


            Console.ReadLine();
        }


        private static GenericPlace selectPlace(List<GenericPlace> places)
        {
            string isCorrect;
            GenericPlace selectedPlace;
            do
            {


                Console.Write("\nSelect a PlaceId from the list above: ");
                string placeId = Console.ReadLine();
                selectedPlace = places.Find(x => x.placeID == placeId);


                Console.Write("You selected {0}. Is this right? (y/n): ", selectedPlace.name);
                isCorrect = Console.ReadLine();
            } while (isCorrect != "y" && isCorrect != "Y");
            Console.WriteLine();


            return selectedPlace;
        }


        private static void printPlaces(List<GenericPlace> places)
        {
            int columnWidth = 26;


            Console.WriteLine(" {0,-" + columnWidth + "} | {1,-" + columnWidth + "} | {2,-7} | {3, -7} ", "Place Name", "Display Name", "Type", "placeId");
            Console.WriteLine(new String('-', columnWidth * 2 + 7 + 6 + 11));
            foreach (var place in places)
            {
                Console.WriteLine(
                    " {0,-" + columnWidth + "} | {1,-" + columnWidth + "} | {2,-7} | {3, -6} ",
                    place?.name?.Length > columnWidth ? place.name.Remove(columnWidth - 3, place.name.Length - columnWidth + 3) + "..." : place.name,
                    place?.displayName?.Length > columnWidth ? place.displayName.Remove(columnWidth - 3, place.displayName.Length - columnWidth + 3) + "..." : place.displayName,
                    place?.type,
                    place?.placeID
                    );


            }
        }
    }
}

 

I hope someone else finds this useful.

Filter Blog

By date: By tag: