*
* @return the corrispondent output <code>LowFunctionality</code>
*/
public LowFunctionality toLowFunctionality(SbiFunctions hibFunct, boolean recoverBIObjects){
logger.debug( "IN" );
LowFunctionality lowFunct = new LowFunctionality();
lowFunct.setId(hibFunct.getFunctId());
logger.debug( "ID="+hibFunct.getFunctId().toString() );
lowFunct.setCode(hibFunct.getCode());
lowFunct.setCodType(hibFunct.getFunctTypeCd());
lowFunct.setDescription(hibFunct.getDescr());
lowFunct.setName(hibFunct.getName());
logger.debug( "NAME="+hibFunct.getName() );
lowFunct.setPath(hibFunct.getPath());
lowFunct.setProg(hibFunct.getProg());
SbiFunctions parentFuntionality = hibFunct.getParentFunct();
if (parentFuntionality != null)
// if it is not the root find the id of the parent functionality
lowFunct.setParentId(parentFuntionality.getFunctId());
else
// if it is the root set the parent id to null
lowFunct.setParentId(null);
List devRolesList = new ArrayList();
List testRolesList = new ArrayList();
List execRolesList = new ArrayList();
List createRolesList = new ArrayList();
Set roles = hibFunct.getSbiFuncRoles();
if (roles!=null){
logger.debug( "getSbiFuncRoles() size="+roles.size() );
Iterator iterRoles = roles.iterator();
while(iterRoles.hasNext()) {
SbiFuncRole hibfuncrole = (SbiFuncRole)iterRoles.next();
SbiExtRoles hibRole = hibfuncrole.getId().getRole();
SbiDomains hibPermission = hibfuncrole.getId().getState();
logger.debug( "hibfuncrole.getId().getRole().getName()="+hibRole.getName() );
RoleDAOHibImpl roleDAO = new RoleDAOHibImpl();
Role role = roleDAO.toRole(hibRole);
String state = hibPermission.getValueCd();
if(state.equals(SpagoBIConstants.PERMISSION_ON_FOLDER_TO_DEVELOP)) {
devRolesList.add(role);
} else if(state.equals(SpagoBIConstants.PERMISSION_ON_FOLDER_TO_TEST)) {
testRolesList.add(role);
} else if(state.equals(SpagoBIConstants.PERMISSION_ON_FOLDER_TO_EXECUTE)) {
execRolesList.add(role);
} else if(state.equals(SpagoBIConstants.PERMISSION_ON_FOLDER_TO_CREATE)) {
createRolesList.add(role);
}
}
}
Role[] execRoles = new Role[execRolesList.size()];
Role[] devRoles = new Role[devRolesList.size()];
Role[] testRoles = new Role[testRolesList.size()];
Role[] createRoles = new Role[createRolesList.size()];
for (int i = 0; i < execRolesList.size(); i++)
execRoles[i] = (Role) execRolesList.get(i);
for (int i = 0; i < testRolesList.size(); i++)
testRoles[i] = (Role) testRolesList.get(i);
for (int i = 0; i < devRolesList.size(); i++)
devRoles[i] = (Role) devRolesList.get(i);
for (int i = 0; i < createRolesList.size(); i++)
createRoles[i] = (Role) createRolesList.get(i);
lowFunct.setDevRoles(devRoles);
lowFunct.setTestRoles(testRoles);
lowFunct.setExecRoles(execRoles);
lowFunct.setCreateRoles(createRoles);
List biObjects = new ArrayList();
if (recoverBIObjects) {
BIObjectDAOHibImpl objDAO = null;
try {
objDAO = (BIObjectDAOHibImpl) DAOFactory.getBIObjectDAO();
Set hibObjFuncs = hibFunct.getSbiObjFuncs();
for (Iterator it = hibObjFuncs.iterator(); it.hasNext();) {
SbiObjFunc hibObjFunc = (SbiObjFunc) it.next();
BIObject object = objDAO.toBIObject(hibObjFunc.getId()
.getSbiObjects());
biObjects.add(object);
}
} catch (EMFUserError e) {
logger.error("Error", e);
}
}
lowFunct.setBiObjects(biObjects);
logger.debug( "OUT" );
return lowFunct;