Search in sources :

Example 11 with XXTagDef

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

the class RangerTagDefService method getTagDefByGuid.

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

Example 12 with XXTagDef

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

the class RangerTagServiceBase method mapViewToEntityBean.

@Override
protected T mapViewToEntityBean(V vObj, T xObj, int OPERATION_CONTEXT) {
    String guid = (StringUtils.isEmpty(vObj.getGuid())) ? guidUtil.genGUID() : vObj.getGuid();
    XXTagDef xTagDef = daoMgr.getXXTagDef().findByName(vObj.getType());
    if (xTagDef == null) {
        throw restErrorUtil.createRESTException("No TagDefinition found with name :" + vObj.getType(), MessageEnums.INVALID_INPUT_DATA);
    }
    xObj.setGuid(guid);
    xObj.setType(xTagDef.getId());
    xObj.setOwner(vObj.getOwner());
    String validityPeriods = JsonUtils.listToJson(vObj.getValidityPeriods());
    Map<String, Object> options = vObj.getOptions();
    if (options == null) {
        options = new HashMap<>();
    }
    if (StringUtils.isNotBlank(validityPeriods)) {
        options.put(RangerTag.OPTION_TAG_VALIDITY_PERIODS, validityPeriods);
    } else {
        options.remove(RangerTag.OPTION_TAG_VALIDITY_PERIODS);
    }
    xObj.setOptions(JsonUtils.mapToJson(options));
    return xObj;
}
Also used : XXTagDef(org.apache.ranger.entity.XXTagDef)

Example 13 with XXTagDef

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

the class TestRangerTagDefService method test8getTagDefsByServiceId.

@Test
public void test8getTagDefsByServiceId() {
    List<XXTagDef> xxTagDefs = new ArrayList<XXTagDef>();
    XXTagDef xxTagDef = new XXTagDef();
    xxTagDef.setId(id);
    xxTagDef.setName(name);
    xxTagDefs.add(xxTagDef);
    XXTagDefDao xXTagDefDao = Mockito.mock(XXTagDefDao.class);
    Mockito.when(daoMgr.getXXTagDef()).thenReturn(xXTagDefDao);
    Mockito.when(xXTagDefDao.findByServiceId(serviceId)).thenReturn(xxTagDefs);
    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);
    List<RangerTagDef> result = rangerTagDefService.getTagDefsByServiceId(serviceId);
    Assert.assertEquals(result.get(0).getId(), tagAttrDefList.get(0).getId());
    Assert.assertEquals(result.get(0).getName(), tagAttrDefList.get(0).getName());
    Mockito.verify(daoMgr).getXXTagDef();
    Mockito.verify(xXTagDefDao).findByServiceId(serviceId);
    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) ArrayList(java.util.ArrayList) XXTagAttributeDef(org.apache.ranger.entity.XXTagAttributeDef) XXTagAttributeDefDao(org.apache.ranger.db.XXTagAttributeDefDao) XXTagDefDao(org.apache.ranger.db.XXTagDefDao) Test(org.junit.Test)

Example 14 with XXTagDef

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

the class TestRangerTagDefService method test9getTagDefsByServiceId.

@Test
public void test9getTagDefsByServiceId() {
    List<XXTagDef> xxTagDefs = new ArrayList<XXTagDef>();
    XXTagDefDao xXTagDefDao = Mockito.mock(XXTagDefDao.class);
    Mockito.when(daoMgr.getXXTagDef()).thenReturn(xXTagDefDao);
    Mockito.when(xXTagDefDao.findByServiceId(serviceId)).thenReturn(xxTagDefs);
    List<RangerTagDef> result = rangerTagDefService.getTagDefsByServiceId(serviceId);
    Assert.assertNotNull(result);
    Mockito.verify(daoMgr).getXXTagDef();
    Mockito.verify(xXTagDefDao).findByServiceId(serviceId);
}
Also used : RangerTagDef(org.apache.ranger.plugin.model.RangerTagDef) XXTagDef(org.apache.ranger.entity.XXTagDef) ArrayList(java.util.ArrayList) XXTagDefDao(org.apache.ranger.db.XXTagDefDao) Test(org.junit.Test)

Example 15 with XXTagDef

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

the class TestRangerTagDefService method test7getTagDefByName.

@Test
public void test7getTagDefByName() {
    XXTagDef xxTagDef = null;
    XXTagDefDao xXTagDefDao = Mockito.mock(XXTagDefDao.class);
    Mockito.when(daoMgr.getXXTagDef()).thenReturn(xXTagDefDao);
    Mockito.when(xXTagDefDao.findByName(name)).thenReturn(xxTagDef);
    RangerTagDef result = rangerTagDefService.getTagDefByName(name);
    Assert.assertNull(result);
    Mockito.verify(daoMgr).getXXTagDef();
    Mockito.verify(xXTagDefDao).findByName(name);
}
Also used : RangerTagDef(org.apache.ranger.plugin.model.RangerTagDef) XXTagDef(org.apache.ranger.entity.XXTagDef) XXTagDefDao(org.apache.ranger.db.XXTagDefDao) Test(org.junit.Test)

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