use of org.apache.ranger.entity.XXEnumDef in project ranger by apache.
the class ServiceDBStore method deleteServiceDef.
public void deleteServiceDef(Long serviceDefId, Boolean forceDelete) throws Exception {
if (LOG.isDebugEnabled()) {
LOG.debug("==> ServiceDBStore.deleteServiceDef(" + serviceDefId + ", " + forceDelete + ")");
}
bizUtil.blockAuditorRoleUser();
UserSessionBase session = ContextUtil.getCurrentUserSession();
if (session == null) {
throw restErrorUtil.createRESTException("UserSession cannot be null, only Admin can update service-def", MessageEnums.OPER_NO_PERMISSION);
}
if (!session.isKeyAdmin() && !session.isUserAdmin()) {
throw restErrorUtil.createRESTException("User is not allowed to update service-def, only Admin can update service-def", MessageEnums.OPER_NO_PERMISSION);
}
RangerServiceDef serviceDef = getServiceDef(serviceDefId);
if (serviceDef == null) {
throw restErrorUtil.createRESTException("No Service Definiton found for Id: " + serviceDefId, MessageEnums.DATA_NOT_FOUND);
}
List<XXService> serviceList = daoMgr.getXXService().findByServiceDefId(serviceDefId);
if (!forceDelete) {
if (CollectionUtils.isNotEmpty(serviceList)) {
throw restErrorUtil.createRESTException("Services exists under given service definition, can't delete Service-Def: " + serviceDef.getName(), MessageEnums.OPER_NOT_ALLOWED_FOR_ENTITY);
}
}
XXDataMaskTypeDefDao dataMaskDao = daoMgr.getXXDataMaskTypeDef();
List<XXDataMaskTypeDef> dataMaskDefs = dataMaskDao.findByServiceDefId(serviceDefId);
for (XXDataMaskTypeDef dataMaskDef : dataMaskDefs) {
dataMaskDao.remove(dataMaskDef);
}
List<XXAccessTypeDef> accTypeDefs = daoMgr.getXXAccessTypeDef().findByServiceDefId(serviceDefId);
for (XXAccessTypeDef accessType : accTypeDefs) {
deleteXXAccessTypeDef(accessType);
}
XXContextEnricherDefDao xContextEnricherDao = daoMgr.getXXContextEnricherDef();
List<XXContextEnricherDef> contextEnrichers = xContextEnricherDao.findByServiceDefId(serviceDefId);
for (XXContextEnricherDef context : contextEnrichers) {
xContextEnricherDao.remove(context);
}
XXEnumDefDao enumDefDao = daoMgr.getXXEnumDef();
List<XXEnumDef> enumDefList = enumDefDao.findByServiceDefId(serviceDefId);
for (XXEnumDef enumDef : enumDefList) {
List<XXEnumElementDef> enumEleDefList = daoMgr.getXXEnumElementDef().findByEnumDefId(enumDef.getId());
for (XXEnumElementDef eleDef : enumEleDefList) {
daoMgr.getXXEnumElementDef().remove(eleDef);
}
enumDefDao.remove(enumDef);
}
XXPolicyConditionDefDao policyCondDao = daoMgr.getXXPolicyConditionDef();
List<XXPolicyConditionDef> policyCondList = policyCondDao.findByServiceDefId(serviceDefId);
for (XXPolicyConditionDef policyCond : policyCondList) {
List<XXPolicyItemCondition> policyItemCondList = daoMgr.getXXPolicyItemCondition().findByPolicyConditionDefId(policyCond.getId());
for (XXPolicyItemCondition policyItemCond : policyItemCondList) {
daoMgr.getXXPolicyItemCondition().remove(policyItemCond);
}
policyCondDao.remove(policyCond);
}
List<XXResourceDef> resDefList = daoMgr.getXXResourceDef().findByServiceDefId(serviceDefId);
for (XXResourceDef resDef : resDefList) {
deleteXXResourceDef(resDef);
}
XXServiceConfigDefDao configDefDao = daoMgr.getXXServiceConfigDef();
List<XXServiceConfigDef> configDefList = configDefDao.findByServiceDefId(serviceDefId);
for (XXServiceConfigDef configDef : configDefList) {
configDefDao.remove(configDef);
}
if (CollectionUtils.isNotEmpty(serviceList)) {
for (XXService service : serviceList) {
deleteService(service.getId());
}
}
Long version = serviceDef.getVersion();
if (version == null) {
version = Long.valueOf(1);
LOG.info("Found Version Value: `null`, so setting value of version to 1, While updating object, version should not be null.");
} else {
version = Long.valueOf(version.longValue() + 1);
}
serviceDef.setVersion(version);
serviceDefService.delete(serviceDef);
LOG.info("ServiceDefinition has been deleted successfully. Service-Def Name: " + serviceDef.getName());
dataHistService.createObjectDataHistory(serviceDef, RangerDataHistService.ACTION_DELETE);
postDelete(serviceDef);
if (LOG.isDebugEnabled()) {
LOG.debug("<== ServiceDBStore.deleteServiceDef(" + serviceDefId + ", " + forceDelete + ")");
}
}
use of org.apache.ranger.entity.XXEnumDef in project ranger by apache.
the class TestRangerServiceDefServiceBase method test18populateXXToRangerEnumDef.
@Test
public void test18populateXXToRangerEnumDef() {
XXEnumElementDefDao xEnumElementDefDao = Mockito.mock(XXEnumElementDefDao.class);
List<XXEnumElementDef> enumElementDefList = new ArrayList<XXEnumElementDef>();
XXEnumElementDef enumElementDefObj = new XXEnumElementDef();
enumElementDefObj.setAddedByUserId(Id);
enumElementDefObj.setCreateTime(new Date());
enumElementDefObj.setEnumdefid(Id);
enumElementDefObj.setId(Id);
enumElementDefObj.setLabel("Simple");
enumElementDefObj.setName("simple");
enumElementDefObj.setOrder(0);
enumElementDefObj.setUpdatedByUserId(Id);
enumElementDefObj.setUpdateTime(new Date());
enumElementDefList.add(enumElementDefObj);
XXEnumDef enumDefObj = new XXEnumDef();
enumDefObj.setAddedByUserId(Id);
enumDefObj.setCreateTime(new Date());
enumDefObj.setDefaultindex(0);
enumDefObj.setDefid(Id);
enumDefObj.setId(Id);
enumDefObj.setName("authnType");
enumDefObj.setUpdatedByUserId(Id);
enumDefObj.setUpdateTime(new Date());
Mockito.when(daoManager.getXXEnumElementDef()).thenReturn(xEnumElementDefDao);
Mockito.when(xEnumElementDefDao.findByEnumDefId(enumDefObj.getId())).thenReturn(enumElementDefList);
RangerEnumDef dbRangerEnumDef = rangerServiceDefService.populateXXToRangerEnumDef(enumDefObj);
Assert.assertNotNull(dbRangerEnumDef);
Assert.assertEquals(dbRangerEnumDef.getName(), enumDefObj.getName());
Mockito.verify(daoManager).getXXEnumElementDef();
}
use of org.apache.ranger.entity.XXEnumDef in project ranger by apache.
the class TestRangerServiceDefServiceBase method test19populateRangerEnumElementDefToXX.
@Test
public void test19populateRangerEnumElementDefToXX() {
RangerEnumElementDef rangerEnumElementDefObj = new RangerEnumElementDef();
rangerEnumElementDefObj.setLabel("Simple");
rangerEnumElementDefObj.setName("simple");
rangerEnumElementDefObj.setRbKeyLabel(null);
XXEnumElementDef enumElementDefObj = new XXEnumElementDef();
enumElementDefObj.setAddedByUserId(Id);
enumElementDefObj.setCreateTime(new Date());
enumElementDefObj.setEnumdefid(Id);
enumElementDefObj.setId(Id);
enumElementDefObj.setLabel("Simple");
enumElementDefObj.setName("simple");
enumElementDefObj.setOrder(0);
enumElementDefObj.setUpdatedByUserId(Id);
enumElementDefObj.setUpdateTime(new Date());
XXEnumDef enumDefObj = new XXEnumDef();
enumDefObj.setAddedByUserId(Id);
enumDefObj.setCreateTime(new Date());
enumDefObj.setDefaultindex(0);
enumDefObj.setDefid(Id);
enumDefObj.setId(Id);
enumDefObj.setName("authnType");
enumDefObj.setUpdatedByUserId(Id);
enumDefObj.setUpdateTime(new Date());
Mockito.when((XXEnumElementDef) rangerAuditFields.populateAuditFields(enumElementDefObj, enumDefObj)).thenReturn(enumElementDefObj);
XXEnumElementDef dbEnumElementDef = rangerServiceDefService.populateRangerEnumElementDefToXX(rangerEnumElementDefObj, enumElementDefObj, enumDefObj, 1);
Assert.assertNotNull(dbEnumElementDef);
Assert.assertEquals(dbEnumElementDef.getId(), enumElementDefObj.getId());
Assert.assertEquals(dbEnumElementDef.getName(), enumElementDefObj.getName());
Assert.assertEquals(dbEnumElementDef.getLabel(), enumElementDefObj.getLabel());
Assert.assertEquals(dbEnumElementDef.getCreateTime(), enumElementDefObj.getCreateTime());
Assert.assertEquals(dbEnumElementDef.getAddedByUserId(), enumElementDefObj.getAddedByUserId());
Assert.assertEquals(dbEnumElementDef.getUpdateTime(), enumElementDefObj.getUpdateTime());
Assert.assertEquals(dbEnumElementDef.getUpdatedByUserId(), enumElementDefObj.getUpdatedByUserId());
Mockito.verify(rangerAuditFields).populateAuditFields(enumElementDefObj, enumDefObj);
}
use of org.apache.ranger.entity.XXEnumDef in project ranger by apache.
the class TestRangerServiceDefServiceBase method test16populateRangerEnumDefToXX.
@Test
public void test16populateRangerEnumDefToXX() {
RangerEnumDef rangerEnumDefObj = new RangerEnumDef();
rangerEnumDefObj.setName("authnType");
rangerEnumDefObj.setDefaultIndex(0);
XXEnumDef enumDefObj = new XXEnumDef();
enumDefObj.setAddedByUserId(Id);
enumDefObj.setCreateTime(new Date());
enumDefObj.setDefaultindex(0);
enumDefObj.setDefid(Id);
enumDefObj.setId(Id);
enumDefObj.setName("authnType");
enumDefObj.setUpdatedByUserId(Id);
enumDefObj.setUpdateTime(new Date());
XXServiceDef serviceDefObj = new XXServiceDef();
serviceDefObj.setAddedByUserId(Id);
serviceDefObj.setCreateTime(new Date());
serviceDefObj.setDescription("HDFS Repository");
serviceDefObj.setGuid("1427365526516_835_0");
serviceDefObj.setId(Id);
Mockito.when((XXEnumDef) rangerAuditFields.populateAuditFields(enumDefObj, serviceDefObj)).thenReturn(enumDefObj);
XXEnumDef dbEnumDef = rangerServiceDefService.populateRangerEnumDefToXX(rangerEnumDefObj, enumDefObj, serviceDefObj, 1);
Assert.assertNotNull(dbEnumDef);
Assert.assertEquals(dbEnumDef, enumDefObj);
Assert.assertEquals(dbEnumDef.getName(), enumDefObj.getName());
Assert.assertEquals(dbEnumDef.getDefid(), enumDefObj.getDefid());
Assert.assertEquals(dbEnumDef.getId(), enumDefObj.getId());
Assert.assertEquals(dbEnumDef.getCreateTime(), enumDefObj.getCreateTime());
}
use of org.apache.ranger.entity.XXEnumDef in project ranger by apache.
the class TestRangerServiceDefServiceBase method test17populateRangerEnumDefToXXnullValue.
@Test
public void test17populateRangerEnumDefToXXnullValue() {
RangerEnumDef rangerEnumDefObj = null;
XXEnumDef enumDefObj = null;
XXServiceDef serviceDefObj = null;
Mockito.when(restErrorUtil.createRESTException("RangerServiceDef cannot be null.", MessageEnums.DATA_NOT_FOUND)).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
XXEnumDef dbEnumDef = rangerServiceDefService.populateRangerEnumDefToXX(rangerEnumDefObj, enumDefObj, serviceDefObj, 1);
Assert.assertNull(dbEnumDef);
}
Aggregations