Search in sources :

Example 1 with XXTagAttributeDef

use of org.apache.ranger.entity.XXTagAttributeDef in project ranger by apache.

the class TagDBStore method createTagAttributeDefs.

private List<XXTagAttributeDef> createTagAttributeDefs(Long tagDefId, List<RangerTagAttributeDef> tagAttrDefList) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> TagDBStore.createTagAttributeDefs(" + tagDefId + ", attributeDefCount=" + (tagAttrDefList == null ? 0 : tagAttrDefList.size()) + ")");
    }
    if (tagDefId == null) {
        throw errorUtil.createRESTException("TagDBStore.createTagAttributeDefs(): Error creating tag-attr def. tagDefId can not be null.", MessageEnums.ERROR_CREATING_OBJECT);
    }
    List<XXTagAttributeDef> ret = new ArrayList<XXTagAttributeDef>();
    if (CollectionUtils.isNotEmpty(tagAttrDefList)) {
        for (RangerTagDef.RangerTagAttributeDef attrDef : tagAttrDefList) {
            XXTagAttributeDef xAttrDef = new XXTagAttributeDef();
            xAttrDef.setTagDefId(tagDefId);
            xAttrDef.setName(attrDef.getName());
            xAttrDef.setType(attrDef.getType());
            xAttrDef = rangerAuditFields.populateAuditFieldsForCreate(xAttrDef);
            xAttrDef = daoManager.getXXTagAttributeDef().create(xAttrDef);
            ret.add(xAttrDef);
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== TagDBStore.createTagAttributeDefs(" + tagDefId + ", attributeDefCount=" + (tagAttrDefList == null ? 0 : tagAttrDefList.size()) + "): retCount=" + ret.size());
    }
    return ret;
}
Also used : RangerTagAttributeDef(org.apache.ranger.plugin.model.RangerTagDef.RangerTagAttributeDef) XXTagAttributeDef(org.apache.ranger.entity.XXTagAttributeDef) ArrayList(java.util.ArrayList)

Example 2 with XXTagAttributeDef

use of org.apache.ranger.entity.XXTagAttributeDef in project ranger by apache.

the class TestRangerTagDefService method test3postUpdate.

@Test
public void test3postUpdate() {
    XXTagDef tagDef = new XXTagDef();
    tagDef.setId(id);
    tagDef.setName(name);
    tagDef.setUpdateTime(new Date());
    List<XXTagAttributeDef> tagAttrDefList = new ArrayList<XXTagAttributeDef>();
    XXTagAttributeDef xxTagAttributeDef = new XXTagAttributeDef();
    xxTagAttributeDef.setId(id);
    xxTagAttributeDef.setName(name);
    tagAttrDefList.add(xxTagAttributeDef);
    XXTagAttributeDefDao xxTagAttributeDefDao = Mockito.mock(XXTagAttributeDefDao.class);
    XXServiceVersionInfoDao xxServiceVersionInfoDao = Mockito.mock(XXServiceVersionInfoDao.class);
    Mockito.when(daoMgr.getXXTagAttributeDef()).thenReturn(xxTagAttributeDefDao);
    Mockito.when(xxTagAttributeDefDao.findByTagDefId(tagDef.getId())).thenReturn(tagAttrDefList);
    Mockito.when(daoMgr.getXXServiceVersionInfo()).thenReturn(xxServiceVersionInfoDao);
    Mockito.doNothing().when(xxServiceVersionInfoDao).updateServiceVersionInfoForTagDefUpdate(tagDef.getId(), tagDef.getUpdateTime());
    RangerTagDef result = rangerTagDefService.postUpdate(tagDef);
    Assert.assertEquals(result.getId(), tagAttrDefList.get(0).getId());
    Assert.assertEquals(result.getName(), tagAttrDefList.get(0).getName());
    Mockito.verify(daoMgr).getXXTagAttributeDef();
    Mockito.verify(xxTagAttributeDefDao).findByTagDefId(tagDef.getId());
    Mockito.verify(daoMgr).getXXServiceVersionInfo();
    Mockito.verify(xxServiceVersionInfoDao).updateServiceVersionInfoForTagDefUpdate(tagDef.getId(), tagDef.getUpdateTime());
}
Also used : RangerTagDef(org.apache.ranger.plugin.model.RangerTagDef) XXTagDef(org.apache.ranger.entity.XXTagDef) XXTagAttributeDef(org.apache.ranger.entity.XXTagAttributeDef) ArrayList(java.util.ArrayList) XXTagAttributeDefDao(org.apache.ranger.db.XXTagAttributeDefDao) Date(java.util.Date) XXServiceVersionInfoDao(org.apache.ranger.db.XXServiceVersionInfoDao) Test(org.junit.Test)

Example 3 with XXTagAttributeDef

use of org.apache.ranger.entity.XXTagAttributeDef in project ranger by apache.

the class TestRangerTagDefService method test6getTagDefByName.

@Test
public void test6getTagDefByName() {
    RangerTagDef oldTagDef = new RangerTagDef();
    oldTagDef.setId(id);
    oldTagDef.setName(name);
    XXTagDef xxTagDef = new XXTagDef();
    xxTagDef.setId(id);
    xxTagDef.setName(name);
    xxTagDef.setUpdateTime(new Date());
    XXTagDefDao xXTagDefDao = Mockito.mock(XXTagDefDao.class);
    Mockito.when(daoMgr.getXXTagDef()).thenReturn(xXTagDefDao);
    Mockito.when(xXTagDefDao.findByName(name)).thenReturn(xxTagDef);
    List<XXTagAttributeDef> tagAttrDefList = new ArrayList<XXTagAttributeDef>();
    XXTagAttributeDef xxTagAttributeDef = new XXTagAttributeDef();
    xxTagAttributeDef.setId(id);
    xxTagAttributeDef.setName(name);
    tagAttrDefList.add(xxTagAttributeDef);
    XXTagAttributeDefDao xxTagAttributeDefDao = Mockito.mock(XXTagAttributeDefDao.class);
    Mockito.when(daoMgr.getXXTagAttributeDef()).thenReturn(xxTagAttributeDefDao);
    Mockito.when(xxTagAttributeDefDao.findByTagDefId(xxTagDef.getId())).thenReturn(tagAttrDefList);
    RangerTagDef result = rangerTagDefService.getTagDefByName(name);
    Assert.assertEquals(result.getId(), tagAttrDefList.get(0).getId());
    Assert.assertEquals(result.getName(), tagAttrDefList.get(0).getName());
    Mockito.verify(daoMgr).getXXTagDef();
    Mockito.verify(xXTagDefDao).findByName(name);
    Mockito.verify(daoMgr).getXXTagAttributeDef();
    Mockito.verify(xxTagAttributeDefDao).findByTagDefId(xxTagDef.getId());
}
Also used : RangerTagDef(org.apache.ranger.plugin.model.RangerTagDef) XXTagDef(org.apache.ranger.entity.XXTagDef) XXTagAttributeDef(org.apache.ranger.entity.XXTagAttributeDef) ArrayList(java.util.ArrayList) XXTagAttributeDefDao(org.apache.ranger.db.XXTagAttributeDefDao) XXTagDefDao(org.apache.ranger.db.XXTagDefDao) Date(java.util.Date) Test(org.junit.Test)

Example 4 with XXTagAttributeDef

use of org.apache.ranger.entity.XXTagAttributeDef in project ranger by apache.

the class TestRangerTagDefService method test10getPopulatedViewObject.

@Test
public void test10getPopulatedViewObject() {
    XXTagDef xxTagDef = new XXTagDef();
    xxTagDef.setId(id);
    xxTagDef.setName(name);
    xxTagDef.setUpdateTime(new Date());
    List<XXTagAttributeDef> tagAttrDefList = new ArrayList<XXTagAttributeDef>();
    XXTagAttributeDef xxTagAttributeDef = new XXTagAttributeDef();
    xxTagAttributeDef.setId(id);
    xxTagAttributeDef.setName(name);
    tagAttrDefList.add(xxTagAttributeDef);
    XXTagAttributeDefDao xxTagAttributeDefDao = Mockito.mock(XXTagAttributeDefDao.class);
    Mockito.when(daoMgr.getXXTagAttributeDef()).thenReturn(xxTagAttributeDefDao);
    Mockito.when(xxTagAttributeDefDao.findByTagDefId(xxTagDef.getId())).thenReturn(tagAttrDefList);
    RangerTagDef result = rangerTagDefService.getPopulatedViewObject(xxTagDef);
    Assert.assertEquals(result.getId(), tagAttrDefList.get(0).getId());
    Assert.assertEquals(result.getName(), tagAttrDefList.get(0).getName());
    Mockito.verify(daoMgr).getXXTagAttributeDef();
    Mockito.verify(xxTagAttributeDefDao).findByTagDefId(xxTagDef.getId());
}
Also used : RangerTagDef(org.apache.ranger.plugin.model.RangerTagDef) XXTagDef(org.apache.ranger.entity.XXTagDef) XXTagAttributeDef(org.apache.ranger.entity.XXTagAttributeDef) ArrayList(java.util.ArrayList) XXTagAttributeDefDao(org.apache.ranger.db.XXTagAttributeDefDao) Date(java.util.Date) Test(org.junit.Test)

Example 5 with XXTagAttributeDef

use of org.apache.ranger.entity.XXTagAttributeDef in project ranger by apache.

the class TestRangerTagDefService method test4getTagDefByGuid.

@Test
public void test4getTagDefByGuid() {
    XXTagDef xxTagDef = new XXTagDef();
    xxTagDef.setId(id);
    xxTagDef.setName(name);
    xxTagDef.setUpdateTime(new Date());
    XXTagDefDao xXTagDefDao = Mockito.mock(XXTagDefDao.class);
    Mockito.when(daoMgr.getXXTagDef()).thenReturn(xXTagDefDao);
    Mockito.when(xXTagDefDao.findByGuid(guid)).thenReturn(xxTagDef);
    List<XXTagAttributeDef> tagAttrDefList = new ArrayList<XXTagAttributeDef>();
    XXTagAttributeDef xxTagAttributeDef = new XXTagAttributeDef();
    xxTagAttributeDef.setId(id);
    xxTagAttributeDef.setName(name);
    tagAttrDefList.add(xxTagAttributeDef);
    XXTagAttributeDefDao xxTagAttributeDefDao = Mockito.mock(XXTagAttributeDefDao.class);
    Mockito.when(daoMgr.getXXTagAttributeDef()).thenReturn(xxTagAttributeDefDao);
    Mockito.when(xxTagAttributeDefDao.findByTagDefId(xxTagDef.getId())).thenReturn(tagAttrDefList);
    RangerTagDef result = rangerTagDefService.getTagDefByGuid(guid);
    Assert.assertEquals(result.getId(), tagAttrDefList.get(0).getId());
    Assert.assertEquals(result.getName(), tagAttrDefList.get(0).getName());
    Mockito.verify(daoMgr).getXXTagDef();
    Mockito.verify(xXTagDefDao).findByGuid(guid);
    Mockito.verify(daoMgr).getXXTagAttributeDef();
    Mockito.verify(xxTagAttributeDefDao).findByTagDefId(xxTagDef.getId());
}
Also used : RangerTagDef(org.apache.ranger.plugin.model.RangerTagDef) XXTagDef(org.apache.ranger.entity.XXTagDef) XXTagAttributeDef(org.apache.ranger.entity.XXTagAttributeDef) ArrayList(java.util.ArrayList) XXTagAttributeDefDao(org.apache.ranger.db.XXTagAttributeDefDao) XXTagDefDao(org.apache.ranger.db.XXTagDefDao) Date(java.util.Date) Test(org.junit.Test)

Aggregations

XXTagAttributeDef (org.apache.ranger.entity.XXTagAttributeDef)8 ArrayList (java.util.ArrayList)7 RangerTagDef (org.apache.ranger.plugin.model.RangerTagDef)6 XXTagAttributeDefDao (org.apache.ranger.db.XXTagAttributeDefDao)5 XXTagDef (org.apache.ranger.entity.XXTagDef)5 Test (org.junit.Test)5 Date (java.util.Date)4 XXTagDefDao (org.apache.ranger.db.XXTagDefDao)3 RangerTagAttributeDef (org.apache.ranger.plugin.model.RangerTagDef.RangerTagAttributeDef)2 XXServiceVersionInfoDao (org.apache.ranger.db.XXServiceVersionInfoDao)1