Show TOC

Categorizing WorkspacesLocate this document in the navigation structure

Use

Categorization is useful for organizing workspaces and facilitating search in the Workspace Directory. A workspace category typically has a number of values that can be assigned to a workspace. This enables filtering the workspaces in the Filter Workspaces panel by these category values.

Workspace categories are defined by an administrator. For more information, see Managing Workspace Categories.

The Workspace API enables you to retrieve existing categories and assign them to workspaces. The relevant APIs ( ICategory, ICategories, ICategoryValue, WorkspaceCategory) are contained in the com.sap.workspaces.workspace package.

The following samples illustrate how to retrieve existing workspace categories, and how to assign a category and its values to a workspace.

Retrieve Existing Workspace Categories
	public void retrieveCategories(IPortalComponentRequest request, IUser user)
	{	
		Locale locale = request.getLocale();
		ICategories categoriesService = (ICategories) RuntimeFactory.getWorkspacesRuntime().getService(ICategories.class);
		ICategory[] categories = categoriesService.getCategories(user);
		ICategory category;
		String categoryName;
		String validValueName;
		ICategoryValue[] categoryValues;

		// Iterate through all categories and retrieve their properties
		for (int i=0; i<categories.length; i++) {
			category = categories[i];
			categoryName = category.getName(locale);
			categoryValues = category.getValues(locale);

			// Retrieve category values
			for (int j=0; j<categoryValues.length; j++) {
				validValueName = categoryValues[j].getName(locale);
				}
		//Display category properties and values...
		}
	}
Assign Category to Workspace
	public void assignWorkspaceCategory(ICategory category, WorkspaceProperties workspaceProperties) 

	{
		// Define an array of categories, even for a single category
		// as required by the setCategories() method
		WorkspaceCategory[] workspaceCategoriesArr = new WorkspaceCategory[1];
		WorkspaceCategory workspaceCategory = new WorkspaceCategory(category.getID());

		// Retrieve the selected category values
		String[] valuesList = getSelectedValues(category.getID());
		workspaceCategory.setValueIDs(valuesList);

		workspaceCategoriesArr[0] = workspaceCategory;

		// Assign the category and selected values to the workspace
		workspaceProperties.setCategories(workspaceCategoriesArr);

	}

	// Select the category values
	private String[] getSelectedValues(String categoryId){

		String[] valuesList = new String[] {"value1", "value2", "value3"};

		return valuesList;

	}