@Test public void test1mapViewToEntityBean() { XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class); XXService xService = Mockito.mock(XXService.class); RangerPolicy rangerPolicy = rangerPolicy(); XXPolicy policy = policy(); int OPERATION_CONTEXT = 0; Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao); Mockito.when(xServiceDao.findByName(rangerPolicy.getService())) .thenReturn(xService); XXPolicy dbPolicy = policyService.mapViewToEntityBean(rangerPolicy, policy, OPERATION_CONTEXT); Assert.assertNotNull(dbPolicy); Assert.assertEquals(dbPolicy.getId(), policy.getId()); Assert.assertEquals(dbPolicy.getGuid(), policy.getGuid()); Assert.assertEquals(dbPolicy.getName(), policy.getName()); Assert.assertEquals(dbPolicy.getAddedByUserId(), policy.getAddedByUserId()); Assert.assertEquals(dbPolicy.getIsEnabled(), policy.getIsEnabled()); Assert.assertEquals(dbPolicy.getVersion(), policy.getVersion()); Assert.assertEquals(dbPolicy.getDescription(), policy.getDescription()); Mockito.verify(daoManager).getXXService(); }
@Override protected T mapViewToEntityBean(V vObj, T xObj, int OPERATION_CONTEXT) { String guid = (StringUtils.isEmpty(vObj.getGuid())) ? guidUtil.genGUID() : vObj.getGuid(); xObj.setGuid(guid); xObj.setVersion(vObj.getVersion()); XXService xService = daoMgr.getXXService().findByName(vObj.getService()); if (xService == null) { throw restErrorUtil.createRESTException("No corresponding service found for policyName: " + vObj.getName() + "Service Not Found : " + vObj.getService(), MessageEnums.INVALID_INPUT_DATA); } xObj.setService(xService.getId()); xObj.setName(StringUtils.trim(vObj.getName())); xObj.setPolicyType(vObj.getPolicyType() == null ? RangerPolicy.POLICY_TYPE_ACCESS : vObj.getPolicyType()); xObj.setPolicyPriority(vObj.getPolicyPriority() == null ? RangerPolicy.POLICY_PRIORITY_NORMAL : vObj.getPolicyPriority()); xObj.setDescription(vObj.getDescription()); xObj.setResourceSignature(vObj.getResourceSignature()); xObj.setIsAuditEnabled(vObj.getIsAuditEnabled()); xObj.setIsEnabled(vObj.getIsEnabled()); Long zoneId = convertZoneNameToZoneId(vObj.getZoneName(), vObj); xObj.setZoneId(zoneId); String validitySchedules = JsonUtils.listToJson(vObj.getValiditySchedules()); Map<String, Object> options = vObj.getOptions(); if (options == null) { options = new HashMap<>(); } if (StringUtils.isNotBlank(validitySchedules)) { options.put(OPTION_POLICY_VALIDITY_SCHEDULES, validitySchedules); } else { options.remove(OPTION_POLICY_VALIDITY_SCHEDULES); } xObj.setOptions(JsonUtils.mapToJson(options)); xObj.setPolicyText(JsonUtils.objectToJson(vObj)); return xObj; }
RangerPolicyServiceBase extends
		RangerBaseModelService<T, V> { @Override protected T mapViewToEntityBean(V vObj, T xObj, int OPERATION_CONTEXT) { String guid = (StringUtils.isEmpty(vObj.getGuid())) ? guidUtil.genGUID() : vObj.getGuid(); xObj.setGuid(guid); xObj.setVersion(vObj.getVersion()); XXService xService = daoMgr.getXXService().findByName(vObj.getService()); if (xService == null) { throw restErrorUtil.createRESTException("No corresponding service found for policyName: " + vObj.getName() + "Service Not Found : " + vObj.getService(), MessageEnums.INVALID_INPUT_DATA); } xObj.setService(xService.getId()); xObj.setName(StringUtils.trim(vObj.getName())); xObj.setPolicyType(vObj.getPolicyType() == null ? RangerPolicy.POLICY_TYPE_ACCESS : vObj.getPolicyType()); xObj.setPolicyPriority(vObj.getPolicyPriority() == null ? RangerPolicy.POLICY_PRIORITY_NORMAL : vObj.getPolicyPriority()); xObj.setDescription(vObj.getDescription()); xObj.setResourceSignature(vObj.getResourceSignature()); xObj.setIsAuditEnabled(vObj.getIsAuditEnabled()); xObj.setIsEnabled(vObj.getIsEnabled()); Long zoneId = convertZoneNameToZoneId(vObj.getZoneName(), vObj); xObj.setZoneId(zoneId); String validitySchedules = JsonUtils.listToJson(vObj.getValiditySchedules()); Map<String, Object> options = vObj.getOptions(); if (options == null) { options = new HashMap<>(); } if (StringUtils.isNotBlank(validitySchedules)) { options.put(OPTION_POLICY_VALIDITY_SCHEDULES, validitySchedules); } else { options.remove(OPTION_POLICY_VALIDITY_SCHEDULES); } xObj.setOptions(JsonUtils.mapToJson(options)); xObj.setPolicyText(JsonUtils.objectToJson(vObj)); return xObj; } }
RangerPolicyServiceBase extends
		RangerBaseModelService<T, V> { @Override protected T mapViewToEntityBean(V vObj, T xObj, int OPERATION_CONTEXT) { String guid = (StringUtils.isEmpty(vObj.getGuid())) ? guidUtil.genGUID() : vObj.getGuid(); xObj.setGuid(guid); xObj.setVersion(vObj.getVersion()); XXService xService = daoMgr.getXXService().findByName(vObj.getService()); if (xService == null) { throw restErrorUtil.createRESTException("No corresponding service found for policyName: " + vObj.getName() + "Service Not Found : " + vObj.getService(), MessageEnums.INVALID_INPUT_DATA); } xObj.setService(xService.getId()); xObj.setName(StringUtils.trim(vObj.getName())); xObj.setPolicyType(vObj.getPolicyType() == null ? RangerPolicy.POLICY_TYPE_ACCESS : vObj.getPolicyType()); xObj.setPolicyPriority(vObj.getPolicyPriority() == null ? RangerPolicy.POLICY_PRIORITY_NORMAL : vObj.getPolicyPriority()); xObj.setDescription(vObj.getDescription()); xObj.setResourceSignature(vObj.getResourceSignature()); xObj.setIsAuditEnabled(vObj.getIsAuditEnabled()); xObj.setIsEnabled(vObj.getIsEnabled()); Long zoneId = convertZoneNameToZoneId(vObj.getZoneName(), vObj); xObj.setZoneId(zoneId); String validitySchedules = JsonUtils.listToJson(vObj.getValiditySchedules()); Map<String, Object> options = vObj.getOptions(); if (options == null) { options = new HashMap<>(); } if (StringUtils.isNotBlank(validitySchedules)) { options.put(OPTION_POLICY_VALIDITY_SCHEDULES, validitySchedules); } else { options.remove(OPTION_POLICY_VALIDITY_SCHEDULES); } xObj.setOptions(JsonUtils.mapToJson(options)); xObj.setPolicyText(JsonUtils.objectToJson(vObj)); return xObj; } RangerPolicyServiceBase(); }
RangerPolicyServiceBase extends
		RangerBaseModelService<T, V> { @Override protected T mapViewToEntityBean(V vObj, T xObj, int OPERATION_CONTEXT) { String guid = (StringUtils.isEmpty(vObj.getGuid())) ? guidUtil.genGUID() : vObj.getGuid(); xObj.setGuid(guid); xObj.setVersion(vObj.getVersion()); XXService xService = daoMgr.getXXService().findByName(vObj.getService()); if (xService == null) { throw restErrorUtil.createRESTException("No corresponding service found for policyName: " + vObj.getName() + "Service Not Found : " + vObj.getService(), MessageEnums.INVALID_INPUT_DATA); } xObj.setService(xService.getId()); xObj.setName(StringUtils.trim(vObj.getName())); xObj.setPolicyType(vObj.getPolicyType() == null ? RangerPolicy.POLICY_TYPE_ACCESS : vObj.getPolicyType()); xObj.setPolicyPriority(vObj.getPolicyPriority() == null ? RangerPolicy.POLICY_PRIORITY_NORMAL : vObj.getPolicyPriority()); xObj.setDescription(vObj.getDescription()); xObj.setResourceSignature(vObj.getResourceSignature()); xObj.setIsAuditEnabled(vObj.getIsAuditEnabled()); xObj.setIsEnabled(vObj.getIsEnabled()); Long zoneId = convertZoneNameToZoneId(vObj.getZoneName(), vObj); xObj.setZoneId(zoneId); String validitySchedules = JsonUtils.listToJson(vObj.getValiditySchedules()); Map<String, Object> options = vObj.getOptions(); if (options == null) { options = new HashMap<>(); } if (StringUtils.isNotBlank(validitySchedules)) { options.put(OPTION_POLICY_VALIDITY_SCHEDULES, validitySchedules); } else { options.remove(OPTION_POLICY_VALIDITY_SCHEDULES); } xObj.setOptions(JsonUtils.mapToJson(options)); xObj.setPolicyText(JsonUtils.objectToJson(vObj)); return xObj; } RangerPolicyServiceBase();  }
RangerPolicyServiceBase extends
		RangerBaseModelService<T, V> { @Override protected T mapViewToEntityBean(V vObj, T xObj, int OPERATION_CONTEXT) { String guid = (StringUtils.isEmpty(vObj.getGuid())) ? guidUtil.genGUID() : vObj.getGuid(); xObj.setGuid(guid); xObj.setVersion(vObj.getVersion()); XXService xService = daoMgr.getXXService().findByName(vObj.getService()); if (xService == null) { throw restErrorUtil.createRESTException("No corresponding service found for policyName: " + vObj.getName() + "Service Not Found : " + vObj.getService(), MessageEnums.INVALID_INPUT_DATA); } xObj.setService(xService.getId()); xObj.setName(StringUtils.trim(vObj.getName())); xObj.setPolicyType(vObj.getPolicyType() == null ? RangerPolicy.POLICY_TYPE_ACCESS : vObj.getPolicyType()); xObj.setPolicyPriority(vObj.getPolicyPriority() == null ? RangerPolicy.POLICY_PRIORITY_NORMAL : vObj.getPolicyPriority()); xObj.setDescription(vObj.getDescription()); xObj.setResourceSignature(vObj.getResourceSignature()); xObj.setIsAuditEnabled(vObj.getIsAuditEnabled()); xObj.setIsEnabled(vObj.getIsEnabled()); Long zoneId = convertZoneNameToZoneId(vObj.getZoneName(), vObj); xObj.setZoneId(zoneId); String validitySchedules = JsonUtils.listToJson(vObj.getValiditySchedules()); Map<String, Object> options = vObj.getOptions(); if (options == null) { options = new HashMap<>(); } if (StringUtils.isNotBlank(validitySchedules)) { options.put(OPTION_POLICY_VALIDITY_SCHEDULES, validitySchedules); } else { options.remove(OPTION_POLICY_VALIDITY_SCHEDULES); } xObj.setOptions(JsonUtils.mapToJson(options)); xObj.setPolicyText(JsonUtils.objectToJson(vObj)); return xObj; } RangerPolicyServiceBase();  static final String OPTION_POLICY_VALIDITY_SCHEDULES; }