Search in sources :

Example 1 with XXEnumDef

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 + ")");
    }
}
Also used : XXDataMaskTypeDefDao(org.apache.ranger.db.XXDataMaskTypeDefDao) XXPolicyConditionDefDao(org.apache.ranger.db.XXPolicyConditionDefDao) XXPolicyItemCondition(org.apache.ranger.entity.XXPolicyItemCondition) UserSessionBase(org.apache.ranger.common.UserSessionBase) XXDataMaskTypeDef(org.apache.ranger.entity.XXDataMaskTypeDef) XXEnumDefDao(org.apache.ranger.db.XXEnumDefDao) XXPolicyConditionDef(org.apache.ranger.entity.XXPolicyConditionDef) XXAccessTypeDef(org.apache.ranger.entity.XXAccessTypeDef) XXServiceConfigDef(org.apache.ranger.entity.XXServiceConfigDef) XXResourceDef(org.apache.ranger.entity.XXResourceDef) XXEnumElementDef(org.apache.ranger.entity.XXEnumElementDef) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) XXEnumDef(org.apache.ranger.entity.XXEnumDef) XXService(org.apache.ranger.entity.XXService) XXServiceConfigDefDao(org.apache.ranger.db.XXServiceConfigDefDao) XXContextEnricherDef(org.apache.ranger.entity.XXContextEnricherDef) XXContextEnricherDefDao(org.apache.ranger.db.XXContextEnricherDefDao)

Example 2 with XXEnumDef

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();
}
Also used : XXEnumElementDef(org.apache.ranger.entity.XXEnumElementDef) XXEnumDef(org.apache.ranger.entity.XXEnumDef) ArrayList(java.util.ArrayList) XXEnumElementDefDao(org.apache.ranger.db.XXEnumElementDefDao) RangerEnumDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerEnumDef) Date(java.util.Date) Test(org.junit.Test)

Example 3 with XXEnumDef

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);
}
Also used : XXEnumElementDef(org.apache.ranger.entity.XXEnumElementDef) RangerEnumElementDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerEnumElementDef) XXEnumDef(org.apache.ranger.entity.XXEnumDef) Date(java.util.Date) Test(org.junit.Test)

Example 4 with XXEnumDef

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());
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXEnumDef(org.apache.ranger.entity.XXEnumDef) RangerEnumDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerEnumDef) Date(java.util.Date) Test(org.junit.Test)

Example 5 with XXEnumDef

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);
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) WebApplicationException(javax.ws.rs.WebApplicationException) XXEnumDef(org.apache.ranger.entity.XXEnumDef) RangerEnumDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerEnumDef) Test(org.junit.Test)

Aggregations

XXEnumDef (org.apache.ranger.entity.XXEnumDef)7 XXEnumElementDef (org.apache.ranger.entity.XXEnumElementDef)5 RangerEnumDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerEnumDef)5 Test (org.junit.Test)4 Date (java.util.Date)3 XXContextEnricherDefDao (org.apache.ranger.db.XXContextEnricherDefDao)3 XXDataMaskTypeDefDao (org.apache.ranger.db.XXDataMaskTypeDefDao)3 XXEnumDefDao (org.apache.ranger.db.XXEnumDefDao)3 XXEnumElementDefDao (org.apache.ranger.db.XXEnumElementDefDao)3 XXPolicyConditionDefDao (org.apache.ranger.db.XXPolicyConditionDefDao)3 XXServiceConfigDefDao (org.apache.ranger.db.XXServiceConfigDefDao)3 XXAccessTypeDef (org.apache.ranger.entity.XXAccessTypeDef)3 XXContextEnricherDef (org.apache.ranger.entity.XXContextEnricherDef)3 XXDataMaskTypeDef (org.apache.ranger.entity.XXDataMaskTypeDef)3 XXPolicyConditionDef (org.apache.ranger.entity.XXPolicyConditionDef)3 XXResourceDef (org.apache.ranger.entity.XXResourceDef)3 XXServiceConfigDef (org.apache.ranger.entity.XXServiceConfigDef)3 XXServiceDef (org.apache.ranger.entity.XXServiceDef)3 RangerEnumElementDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerEnumElementDef)3 XXAccessTypeDefDao (org.apache.ranger.db.XXAccessTypeDefDao)2