Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
vijay_kumar49
Active Contributor

Hello Friends,

Agenda:

1.      How to get Groups/Roles and Users from the Enterprise Portal by using Webdynpro JAVA

2.      How to Change the Old Groups Name to New Group Name by using Webdynpro JAVA

How to get Groups/Roles and Users from the Enterprise Portal by using Webdynpro JAVA

Please look at below screen shoot for search the Groups/Roles and Users from the Enterprise Portal.

When I select either Group/Role/User from the dropdown menu

SchCriteriaName: - In the input filed place you will pass Group/Role/User names (If you know) or Pass *(Star) and Search the information from the Portal.

When I Click on Go Button. It’s called to the below method.

Code:-

public void onActionsearchResults(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, java.lang.String srchParameter )

{

//@@begin onActionsearchResults(ServerEvent)

wdContext.currentContextElement().setNewGrpwithPermission("");

wdContext.currentContextElement().setUpdateGroup("");


String srchCriteria = wdContext.currentContextElement().getSchCriteriaType();

String schCriteriaText = wdContext.currentContextElement().getSchCriteriaName();

if (schCriteriaText == null || schCriteriaText.trim().length() == 0) {

schCriteriaText = "*";

}

wdContext.nodeGroupTable().invalidate();

wdContext.nodeRoleTable().invalidate();

wdContext.nodeUserTable().invalidate();


if (srchCriteria.equalsIgnoreCase("G")) {

wdContext.currentContextElement().setHorizontalGutterVisible_main(WDVisibility.VISIBLE);

wdContext.currentContextElement().setGroupTableVisibility(WDVisibility.VISIBLE);

wdContext.currentContextElement().setGetResourceButVisibility(WDVisibility.VISIBLE);


wdContext.currentContextElement().setRoleTableVisibility(WDVisibility.NONE);

wdContext.currentContextElement().setUsrTableVisibility(WDVisibility.NONE);

wdContext.currentContextElement().setKmResourceVisibility(WDVisibility.NONE);

wdContext.currentContextElement().setNewGroupCreationVisibility(WDVisibility.NONE);


try {

IGroupFactory groupFact = UMFactory.getGroupFactory();

IGroupSearchFilter groupFilt = groupFact.getGroupSearchFilter();

groupFilt.setUniqueName(schCriteriaText.trim(), ISearchAttribute.LIKE_OPERATOR, false);

ISearchResult result = groupFact.searchGroups(groupFilt);


if (result.size() != 0) {

if(result.getState() == ISearchResult.SEARCH_RESULT_OK) {

while(result.hasNext()) {

String groupUniqId = (String)result.next();

IGroup thisGroup = groupFact.getGroup(groupUniqId);


IPrivateV_KMResourceView.IGroupTableElement grpTable = wdContext.createGroupTableElement();

grpTable.setGroupNames(groupUniqId);

grpTable.setDisplayName(thisGroup.getDisplayName());

grpTable.setUniqueID(thisGroup.getUniqueID());


wdContext.nodeGroupTable().addElement(grpTable);

}

}

} else {

wdComponentAPI.getMessageManager().reportWarning("No element found.");

wdContext.nodeKMContent().invalidate();

wdContext.currentContextElement().setKmResourceVisibility(WDVisibility.NONE);

wdContext.currentContextElement().setNewGroupCreationVisibility(WDVisibility.NONE);

wdContext.currentContextElement().setGetResourceButVisibility(WDVisibility.NONE);

}

} catch (Exception e) {

// TODO: handle exception

}


} else if (srchCriteria.equalsIgnoreCase("R")) {

//wdThis.wdFirePlugToRoleView();

wdContext.currentContextElement().setRoleTableVisibility(WDVisibility.VISIBLE);


wdContext.currentContextElement().setGroupTableVisibility(WDVisibility.NONE);

wdContext.currentContextElement().setUsrTableVisibility(WDVisibility.NONE);

wdContext.currentContextElement().setKmResourceVisibility(WDVisibility.NONE);


try {

com.sap.security.api.IRoleFactory rFactory = UMFactory.getRoleFactory();

IRoleSearchFilter roleSrcFilter = rFactory.getRoleSearchFilter();

roleSrcFilter.setUniqueName(schCriteriaText.trim(),ISearchAttribute.LIKE_OPERATOR,false);

ISearchResult srhResults = rFactory.searchRoles(roleSrcFilter);


if (srhResults.size() != 0){

if(srhResults.getState() == ISearchResult.SEARCH_RESULT_OK) {

while(srhResults.hasNext()) {

String rUniqId = (String)srhResults.next();

IRole thisRole = rFactory.getRole(rUniqId);


IPrivateV_KMResourceView.IRoleTableElement rTable = wdContext.createRoleTableElement();

rTable.setRoles(thisRole.getDisplayName());


wdContext.nodeRoleTable().addElement(rTable);

}

}

} else {

wdComponentAPI.getMessageManager().reportWarning("No element found.");

}


} catch (UMException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}


} else if (srchCriteria.equalsIgnoreCase("U")) {


wdContext.currentContextElement().setGroupTableVisibility(WDVisibility.NONE);

wdContext.currentContextElement().setUsrTableVisibility(WDVisibility.VISIBLE);


try {

IUserFactory uFactory = UMFactory.getUserFactory();

IUserSearchFilter usrSrchFilter = uFactory.getUserSearchFilter();

usrSrchFilter.setUniqueName(schCriteriaText.trim(),ISearchAttribute.LIKE_OPERATOR,false);

ISearchResult srchResluts = uFactory.searchUsers(usrSrchFilter);


if (srchResluts.size() != 0){

if(srchResluts.getState() == ISearchResult.SEARCH_RESULT_OK) {

while (srchResluts.hasNext()){

String userID = (String) srchResluts.next();

com.sap.security.api.IUser sapUser = uFactory.getUser(userID);


IPrivateV_KMResourceView.IUserTableElement usrTable = wdContext.createUserTableElement();

usrTable.setLogonId(sapUser.getUserAccounts()[0].getLogonUid());

usrTable.setUserNames(sapUser.getLastName()+','+" "+sapUser.getFirstName());

wdContext.nodeUserTable().addElement(usrTable);

}

}

} else {

wdComponentAPI.getMessageManager().reportWarning("No element found.");

}


} catch (UMException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}


//@@end

}


How to Change the Old Groups Name to New Group Name by using Webdynpro JAVA

Now I selected Group under dropdown and click on Search the groups from the Portal.

Here when I select the group name from the table. Its showing new group name input file ui element.

Before this input field is in invisible. So we need set the Visible property.

So Select Old group name and provide new group name in newGrpwithPermission input filed

              

           Then click on Create Button. It’s called below method.

public void onActionnewGroupwithPermissions(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActionnewGroupwithPermissions(ServerEvent)


else if (emailTO == null || emailTO.trim().length() == 0){

wdComponentAPI.getMessageManager().reportException("Please set the Email before Create New Group",true);

wdContext.currentContextElement().setKmResourceVisibility(WDVisibility.NONE);


} else {

String newGroupName = wdContext.currentContextElement().getNewGrpwithPermission();

if (newGroupName != null && !(newGroupName).equalsIgnoreCase("")) {


IWDControllerInfo controllerInfo = wdControllerAPI.getViewInfo().getViewController(); //START: lightwight popup window


// Let factory create window with first button

IWDEventHandlerInfo evtHndlr = controllerInfo.findInEventHandlers("CreateNewGroup_Canceled");


//<-- Name of event handler, has to match exactly

String confTextBody = "You are about to Create New Group with Selected Group Data. Are you sure?";

IWDConfirmationDialog confDialog = wdComponentAPI.getWindowManager().createConfirmationWindow(confTextBody,evtHndlr,"No, Cancel");


/* dialogText, evtHndlr, buttonText OR evtHndlr.getName() */

evtHndlr = controllerInfo.findInEventHandlers("CreateNewGroup_Confirmed"); //Name of event handler, has to match exactly

confDialog.addChoice(evtHndlr, "Yes, Confirm");


//align and display window

confDialog.setTitle("Create New Group Confirmation?");


// set window size in pixels

confDialog.setWindowSize(340,100); //confDialog.setWindowPosition(WDWindowPos.CENTER);

confDialog.show(); //replaces deprecated confDialog.open();

} else {

wdComponentAPI.getMessageManager().reportException("Please Enter the Group Name",true);

wdContext.currentContextElement().setKmResourceVisibility(WDVisibility.NONE);

}

}

//@@end

}

When I click on Yes Button, its called below method.

public void CreateNewGroup_Canceled(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin CreateNewGroup_Canceled(ServerEvent)

//@@end

}

public void CreateNewGroup_Confirmed(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin CreateNewGroup_Confirmed(ServerEvent)

IGroup iGroup;

IGroupFactory groupFactory = UMFactory.getGroupFactory();

startTime = System.currentTimeMillis();


try {

iGroup = groupFactory.newGroup(wdContext.currentContextElement().getNewGrpwithPermission());

iGroup.commit(); // Group Created in UME

String newGroupUniqueID = iGroup.getUniqueID();

newGroupUniqueName = iGroup.getUniqueName();

iGroup = UMFactory.getGroupFactory().getGroup(selectedOldGroupUniqueID); //IGroup seltdGroup

Iterator getOldRole = iGroup.getRoles(true);

while (getOldRole.hasNext()) {

String oldRoleName = (String) getOldRole.next();


IGroup newGroup = groupFactory.getGroup(newGroupUniqueID);//IGroup newGroup

//newGroup.addToRole(role.getUniqueID());

newGroup.addToRole(oldRoleName);

newGroup.save();

// wdComponentAPI.getMessageManager().reportSuccess("Role addeed in New Group");

}

Iterator grpParent = iGroup.getParentGroups(true);

while (grpParent.hasNext()) {

// wdComponentAPI.getMessageManager().reportSuccess("Parent Loop Starts");

String gParent = (String) grpParent.next();

groupFactory.addGroupToParent(newGroupUniqueID,gParent); // will get the ParentGroups form the Old group and Added to the New Group.

}

Iterator childGroupsIt = iGroup.getGroupMembers(true);

while (childGroupsIt.hasNext()) {

String chGroup = (String) childGroupsIt.next();

IGroup newGroup = groupFactory.getMutableGroup(newGroupUniqueID);//IGroup newGroup

newGroup.addGroupMember(chGroup);

newGroup.save();

newGroup.commit();

}

Iterator grpUsers = iGroup.getUserMembers(true);

while (grpUsers.hasNext()) {

String user = (String) grpUsers.next();

IGroup newGroup = groupFactory.getMutableGroup(newGroupUniqueID);//IGroup newGroup

newGroup.addUserMember(user);

newGroup.save();

newGroup.commit();

}

}

catch (UMException um) {

// TODO Auto-generated catch block

um.printStackTrace();

wdComponentAPI.getMessageManager().reportException(um.getMessage(), false);

}

//@@end

}

Hope this is helpful !!!

Thank you,

Regards

Vijay Kalluri

2 Comments
Labels in this area