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());
}
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());
}
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;
}
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;
}
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;
}
Aggregations