Search in sources :

Example 6 with XXTagDef

use of org.apache.ranger.entity.XXTagDef 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)

Example 7 with XXTagDef

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

the class TestRangerTagDefServiceBase method test1mapViewToEntityBean.

@Test
public void test1mapViewToEntityBean() {
    RangerTagDef rangerTagDef = new RangerTagDef();
    rangerTagDef.setId(id);
    rangerTagDef.setGuid(guid);
    XXTagDef xxTagDef = new XXTagDef();
    xxTagDef.setId(id);
    xxTagDef.setGuid(guid);
    xxTagDef.setName(name);
    xxTagDef.setVersion(version);
    int operationContext = 1;
    XXTagDef result = rangerTagDefService.mapViewToEntityBean(rangerTagDef, xxTagDef, operationContext);
    Assert.assertNotNull(result);
    Assert.assertEquals(result, xxTagDef);
    Assert.assertEquals(result.getGuid(), xxTagDef.getGuid());
    Assert.assertEquals(result.getName(), xxTagDef.getName());
    Assert.assertEquals(result.getId(), xxTagDef.getId());
    Assert.assertEquals(result.getVersion(), xxTagDef.getVersion());
}
Also used : RangerTagDef(org.apache.ranger.plugin.model.RangerTagDef) XXTagDef(org.apache.ranger.entity.XXTagDef) Test(org.junit.Test)

Example 8 with XXTagDef

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

the class RangerTagDefService method getTagDefsByServiceId.

public List<RangerTagDef> getTagDefsByServiceId(Long serviceId) {
    List<RangerTagDef> ret = new ArrayList<RangerTagDef>();
    List<XXTagDef> xxTagDefs = daoMgr.getXXTagDef().findByServiceId(serviceId);
    if (CollectionUtils.isNotEmpty(xxTagDefs)) {
        for (XXTagDef xxTagDef : xxTagDefs) {
            RangerTagDef tagDef = populateViewBean(xxTagDef);
            ret.add(tagDef);
        }
    }
    return ret;
}
Also used : RangerTagDef(org.apache.ranger.plugin.model.RangerTagDef) XXTagDef(org.apache.ranger.entity.XXTagDef) ArrayList(java.util.ArrayList)

Example 9 with XXTagDef

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

the class RangerTagServiceBase method mapEntityToViewBean.

@Override
protected V mapEntityToViewBean(V vObj, T xObj) {
    XXTagDef xTagDef = daoMgr.getXXTagDef().getById(xObj.getType());
    if (xTagDef == null) {
        throw restErrorUtil.createRESTException("No TagDefinition found with name :" + xObj.getType(), MessageEnums.INVALID_INPUT_DATA);
    }
    vObj.setGuid(xObj.getGuid());
    vObj.setType(xTagDef.getName());
    vObj.setOwner(xObj.getOwner());
    Map<String, Object> options = JsonUtils.jsonToObject(xObj.getOptions(), Map.class);
    if (MapUtils.isNotEmpty(options)) {
        String optionTagValidityPeriod = (String) options.remove(RangerTag.OPTION_TAG_VALIDITY_PERIODS);
        if (StringUtils.isNotBlank(optionTagValidityPeriod)) {
            List<RangerValiditySchedule> validityPeriods = JsonUtils.jsonToRangerValiditySchedule(optionTagValidityPeriod);
            vObj.setValidityPeriods(validityPeriods);
        }
    }
    vObj.setOptions(options);
    Map<String, String> attributes = getAttributesForTag(xObj);
    vObj.setAttributes(attributes);
    return vObj;
}
Also used : XXTagDef(org.apache.ranger.entity.XXTagDef) RangerValiditySchedule(org.apache.ranger.plugin.model.RangerValiditySchedule)

Example 10 with XXTagDef

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

the class RangerTagDefService method getTagDefByName.

public RangerTagDef getTagDefByName(String name) {
    RangerTagDef ret = null;
    XXTagDef xxTagDef = daoMgr.getXXTagDef().findByName(name);
    if (xxTagDef != null) {
        ret = populateViewBean(xxTagDef);
    }
    return ret;
}
Also used : RangerTagDef(org.apache.ranger.plugin.model.RangerTagDef) XXTagDef(org.apache.ranger.entity.XXTagDef)

Aggregations

XXTagDef (org.apache.ranger.entity.XXTagDef)15 RangerTagDef (org.apache.ranger.plugin.model.RangerTagDef)13 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)7 XXTagDefDao (org.apache.ranger.db.XXTagDefDao)6 XXTagAttributeDefDao (org.apache.ranger.db.XXTagAttributeDefDao)5 XXTagAttributeDef (org.apache.ranger.entity.XXTagAttributeDef)5 Date (java.util.Date)4 XXServiceVersionInfoDao (org.apache.ranger.db.XXServiceVersionInfoDao)1 RangerValiditySchedule (org.apache.ranger.plugin.model.RangerValiditySchedule)1