use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class XUserPermissionServiceBase method mapViewToEntityBean.
@Override
protected T mapViewToEntityBean(V vObj, T mObj, int OPERATION_CONTEXT) {
// Assuming that vObj.userId coming from UI/Client would be of XXUser, but in DB it should be of XXPortalUser so
// have to map XXUser.ID to XXPortalUser.ID and if portalUser does not exist then not allowing to create/update
XXPortalUser portalUser = daoManager.getXXPortalUser().findByXUserId(vObj.getUserId());
if (portalUser == null) {
throw restErrorUtil.createRESTException("Invalid UserId: [" + vObj.getUserId() + "], Please make sure while create/update given userId should be of x_user", MessageEnums.INVALID_INPUT_DATA);
}
mObj.setUserId(portalUser.getId());
mObj.setModuleId(vObj.getModuleId());
mObj.setIsAllowed(vObj.getIsAllowed());
if (OPERATION_CONTEXT == OPERATION_CREATE_CONTEXT) {
validateXUserPermForCreate(mObj);
} else if (OPERATION_CONTEXT == OPERATION_UPDATE_CONTEXT) {
validateXUserPermForUpdate(mObj);
}
return mObj;
}
use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class XResourceService method mapViewToEntityBean.
@Override
protected XXResource mapViewToEntityBean(VXResource vObj, XXResource mObj, int OPERATION_CONTEXT) {
XXResource ret = null;
if (vObj != null && mObj != null) {
ret = super.mapViewToEntityBean(vObj, mObj, OPERATION_CONTEXT);
ret.setUdfs(vObj.getUdfs());
XXPortalUser xXPortalUser = null;
if (ret.getAddedByUserId() == null || ret.getAddedByUserId() == 0) {
if (!stringUtil.isEmpty(vObj.getOwner())) {
xXPortalUser = daoManager.getXXPortalUser().findByLoginId(vObj.getOwner());
if (xXPortalUser != null) {
ret.setAddedByUserId(xXPortalUser.getId());
}
}
}
if (ret.getUpdatedByUserId() == null || ret.getUpdatedByUserId() == 0) {
if (!stringUtil.isEmpty(vObj.getUpdatedBy())) {
xXPortalUser = daoManager.getXXPortalUser().findByLoginId(vObj.getUpdatedBy());
if (xXPortalUser != null) {
ret.setUpdatedByUserId(xXPortalUser.getId());
}
}
}
}
return ret;
}
use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class XTrxLogService method mapEntityToViewBean.
@Override
protected VXTrxLog mapEntityToViewBean(VXTrxLog vObj, XXTrxLog mObj) {
VXTrxLog ret = null;
if (mObj != null && vObj != null) {
ret = super.mapEntityToViewBean(vObj, mObj);
XXPortalUser xXPortalUser = null;
if (stringUtil.isEmpty(ret.getOwner())) {
xXPortalUser = daoManager.getXXPortalUser().getById(mObj.getAddedByUserId());
if (xXPortalUser != null) {
ret.setOwner(xXPortalUser.getLoginId());
}
}
if (stringUtil.isEmpty(ret.getUpdatedBy())) {
xXPortalUser = daoManager.getXXPortalUser().getById(mObj.getUpdatedByUserId());
if (xXPortalUser != null) {
ret.setUpdatedBy(xXPortalUser.getLoginId());
}
}
}
return ret;
}
use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class XGroupService method createXGroupWithOutLogin.
public VXGroup createXGroupWithOutLogin(VXGroup vxGroup) {
XXGroup xxGroup = daoManager.getXXGroup().findByGroupName(vxGroup.getName());
boolean groupExists = true;
if (xxGroup == null) {
xxGroup = new XXGroup();
groupExists = false;
}
xxGroup = mapViewToEntityBean(vxGroup, xxGroup, 0);
XXPortalUser xXPortalUser = daoManager.getXXPortalUser().getById(createdByUserId);
if (xXPortalUser != null) {
xxGroup.setAddedByUserId(createdByUserId);
xxGroup.setUpdatedByUserId(createdByUserId);
}
if (groupExists) {
getDao().update(xxGroup);
} else {
getDao().create(xxGroup);
}
xxGroup = daoManager.getXXGroup().findByGroupName(vxGroup.getName());
vxGroup = postCreate(xxGroup);
return vxGroup;
}
use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class TestRangerServiceService method test3PopulateViewBean.
@Test
public void test3PopulateViewBean() {
XXServiceConfigMapDao xServiceConfigMapDao = Mockito.mock(XXServiceConfigMapDao.class);
XXPortalUserDao xPortalUserDao = Mockito.mock(XXPortalUserDao.class);
XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
XXService xService = xService();
String name = "fdfdfds";
List<XXServiceConfigMap> svcConfigMapList = new ArrayList<XXServiceConfigMap>();
XXServiceConfigMap xConfMap = new XXServiceConfigMap();
xConfMap.setAddedByUserId(null);
xConfMap.setConfigkey(name);
xConfMap.setConfigvalue(name);
xConfMap.setCreateTime(new Date());
xConfMap.setServiceId(null);
xConfMap.setUpdatedByUserId(null);
xConfMap.setUpdateTime(new Date());
svcConfigMapList.add(xConfMap);
XXPortalUser tUser = new XXPortalUser();
tUser.setAddedByUserId(userId);
tUser.setCreateTime(new Date());
tUser.setEmailAddress("test@gmail.com");
tUser.setFirstName(name);
tUser.setId(userId);
tUser.setLastName(name);
XXServiceDef xServiceDef = new XXServiceDef();
xServiceDef.setAddedByUserId(userId);
xServiceDef.setCreateTime(new Date());
xServiceDef.setDescription("test");
xServiceDef.setGuid("1427365526516_835_0");
xServiceDef.setId(userId);
XXServiceVersionInfoDao xServiceVersionInfoDao = Mockito.mock(XXServiceVersionInfoDao.class);
XXServiceVersionInfo serviceVersionInfo = new XXServiceVersionInfo();
serviceVersionInfo.setServiceId(xService.getId());
serviceVersionInfo.setPolicyVersion(xService.getPolicyVersion());
serviceVersionInfo.setPolicyUpdateTime(xService.getPolicyUpdateTime());
serviceVersionInfo.setTagVersion(xService.getTagVersion());
serviceVersionInfo.setTagUpdateTime(xService.getTagUpdateTime());
Mockito.when(daoManager.getXXServiceVersionInfo()).thenReturn(xServiceVersionInfoDao);
Mockito.when(xServiceVersionInfoDao.findByServiceId(xService.getId())).thenReturn(serviceVersionInfo);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(xPortalUserDao);
Mockito.when(xPortalUserDao.getById(userId)).thenReturn(tUser);
Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
Mockito.when(xServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef);
Mockito.when(daoManager.getXXServiceConfigMap()).thenReturn(xServiceConfigMapDao);
Mockito.when(xServiceConfigMapDao.findByServiceId(xService.getId())).thenReturn(svcConfigMapList);
RangerService dbService = serviceService.populateViewBean(xService);
Assert.assertNotNull(dbService);
Assert.assertEquals(userId, dbService.getId());
Assert.assertEquals(xService.getAddedByUserId(), dbService.getId());
Assert.assertEquals(xService.getId(), dbService.getId());
Assert.assertEquals(xService.getDescription(), dbService.getDescription());
Assert.assertEquals(xService.getGuid(), dbService.getGuid());
Assert.assertEquals(xService.getName(), dbService.getName());
Assert.assertEquals(xService.getPolicyUpdateTime(), dbService.getPolicyUpdateTime());
Assert.assertEquals(xService.getPolicyVersion(), dbService.getPolicyVersion());
Assert.assertEquals(xService.getVersion(), dbService.getVersion());
Mockito.verify(daoManager).getXXServiceDef();
Mockito.verify(daoManager).getXXServiceConfigMap();
}
Aggregations