Creating a new user group

	
	// BO necessary util classes and defining instances for each class
	IInfoStore boInfoStore = null;
	IInfoStore boInfoStore2 = null;
	IInfoObject boIInfoObject = null;
	IInfoObject boIInfoObject2 = null;
	IInfoObjects boInfoObjects = null;
	IInfoObjects boInfoObjects2 = null;
	SDKException sdkException = null;
	IEnterpriseSession boEnterpriseSession = null;
	IPluginMgr boPluginMgr;
	IPluginInfo boPluginInfo;
	IUser boCurUser = null;
	IUserGroup boGroup = null;
	IUserAliases allias = null;

boEnterpriseSession = CrystalEnterprise.getSessionMgr().logon(
					USERNAME, PASSWORD, SERVER, AUTHTYPE);
			boInfoStore = (IInfoStore) boEnterpriseSession.getService("",
					"InfoStore");
	boEnterpriseSession = CrystalEnterprise.getSessionMgr().logon(
					USERNAME, PASSWORD, SERVER, AUTHTYPE);
			boInfoStore = (IInfoStore) boEnterpriseSession.getService("",
					"InfoStore");


	public void createNewUserGroup(String groupName, String parentGroupName) {
		logger.debug("createNewUserGroup " + groupName + parentGroupName);
		int parentID = acquireGroupID(parentGroupName);

		try {
			boInfoStore = (IInfoStore) boEnterpriseSession.getService("",
					"InfoStore");

			// Retrieve the user plug in
			boPluginMgr = boInfoStore.getPluginMgr();
			boPluginInfo = boPluginMgr
					.getPluginInfo("CrystalEnterprise.UserGroup");

			// Create a new infoobject collection
			boInfoObjects = boInfoStore.newInfoObjectCollection();

			// add a new user using boIInfoObject instance
			boIInfoObject = boInfoObjects.add(boPluginInfo);

			boGroup = (IUserGroup) boInfoObjects.get(0);

			boGroup.setTitle(groupName);
			boGroup.setDescription(groupName + " user group");
			boGroup.setParentID(parentID);
			boInfoStore.commit(boInfoObjects);
		} catch (SDKException e) {
			logger.error("Exception to create new user group " + groupName
					+ parentGroupName + e);
		}
	}

		public Integer acquireGroupID(String groupName) {
		logger.debug("acquireGroupID " + groupName);
		try {
			boInfoStore = (IInfoStore) boEnterpriseSession.getService("",
					"InfoStore");

			// Retrieve groups
			boInfoObjects = boInfoStore
					.query("SELECT SI_ID, SI_NAME, SI_USERGROUPS, SI_PARENTID FROM CI_SYSTEMOBJECTS WHERE SI_PROGID='CrystalEnterprise.UserGroup' AND SI_NAME = '"
							+ groupName + "'");
			boGroup = (IUserGroup) boInfoObjects.get(0);

			return boGroup.getID();

		} catch (SDKException e) {
			logger.error("Exception to acquire group id " + groupName + e);
		}

		return 0;
	}

Leave a Reply

Your email address will not be published. Required fields are marked *