Search in sources :

Example 1 with XXPolicyRefDataMaskTypeDao

use of org.apache.ranger.db.XXPolicyRefDataMaskTypeDao in project ranger by apache.

the class PatchForMigratingOldRegimePolicyJson_J10046 method addDataMaskDefRef.

private void addDataMaskDefRef(String serviceType, Long policyId, Set<String> datamasks) throws Exception {
    logger.info("==> addDataMaskDefRef(id=" + policyId + ")");
    // insert policy-id, datamaskName into Ref table
    Map<String, Long> serviceDefDataMaskTypeIDMap = dataMaskTypeIdMap.get(serviceType);
    if (serviceDefDataMaskTypeIDMap == null) {
        serviceDefDataMaskTypeIDMap = new HashMap<>();
        dataMaskTypeIdMap.put(serviceType, serviceDefDataMaskTypeIDMap);
        XXServiceDef dbServiceDef = daoMgr.getXXServiceDef().findByName(serviceType);
        for (XXDataMaskTypeDef dataMaskTypeDef : daoMgr.getXXDataMaskTypeDef().findByServiceDefId(dbServiceDef.getId())) {
            serviceDefDataMaskTypeIDMap.put(dataMaskTypeDef.getName(), dataMaskTypeDef.getId());
        }
    }
    XXPolicyRefDataMaskTypeDao policyRefDataMaskTypeDao = daoMgr.getXXPolicyRefDataMaskType();
    for (String datamask : datamasks) {
        Long dataMaskTypeId = serviceDefDataMaskTypeIDMap.get(datamask);
        if (dataMaskTypeId == null) {
            throw new Exception(datamask + ": unknown dataMaskType in policy [id=" + policyId + "; serviceType=" + serviceType + "]. Known dataMaskTypes " + serviceDefDataMaskTypeIDMap.keySet());
        }
        XXPolicyRefDataMaskType policyRefDataMaskType = new XXPolicyRefDataMaskType();
        policyRefDataMaskType.setPolicyId(policyId);
        policyRefDataMaskType.setDataMaskTypeName(datamask);
        policyRefDataMaskType.setDataMaskDefId(dataMaskTypeId);
        policyRefDataMaskTypeDao.create(policyRefDataMaskType);
    }
    logger.info("<== addDataMaskDefRef(id=" + policyId + ")");
}
Also used : XXPolicyRefDataMaskType(org.apache.ranger.entity.XXPolicyRefDataMaskType) XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXDataMaskTypeDef(org.apache.ranger.entity.XXDataMaskTypeDef) XXPolicyRefDataMaskTypeDao(org.apache.ranger.db.XXPolicyRefDataMaskTypeDao)

Example 2 with XXPolicyRefDataMaskTypeDao

use of org.apache.ranger.db.XXPolicyRefDataMaskTypeDao in project ranger by apache.

the class PatchForUpdatingPolicyJson_J10019 method addDataMaskDefRef.

private void addDataMaskDefRef(String serviceType, Long policyId, Set<String> datamasks) throws Exception {
    logger.info("==> addDataMaskDefRef(id=" + policyId + ")");
    // insert policy-id, datamaskName into Ref table
    Map<String, Long> serviceDefDataMaskTypeIDMap = dataMaskTypeIdMap.get(serviceType);
    if (serviceDefDataMaskTypeIDMap == null) {
        serviceDefDataMaskTypeIDMap = new HashMap<>();
        dataMaskTypeIdMap.put(serviceType, serviceDefDataMaskTypeIDMap);
        XXServiceDef dbServiceDef = daoMgr.getXXServiceDef().findByName(serviceType);
        for (XXDataMaskTypeDef dataMaskTypeDef : daoMgr.getXXDataMaskTypeDef().findByServiceDefId(dbServiceDef.getId())) {
            serviceDefDataMaskTypeIDMap.put(dataMaskTypeDef.getName(), dataMaskTypeDef.getId());
        }
    }
    XXPolicyRefDataMaskTypeDao policyRefDataMaskTypeDao = daoMgr.getXXPolicyRefDataMaskType();
    for (String datamask : datamasks) {
        Long dataMaskTypeId = serviceDefDataMaskTypeIDMap.get(datamask);
        if (dataMaskTypeId == null) {
            throw new Exception(datamask + ": unknown dataMaskType in policy [id=" + policyId + "; serviceType=" + serviceType + "]. Known dataMaskTypes " + serviceDefDataMaskTypeIDMap.keySet());
        }
        XXPolicyRefDataMaskType policyRefDataMaskType = new XXPolicyRefDataMaskType();
        policyRefDataMaskType.setPolicyId(policyId);
        policyRefDataMaskType.setDataMaskTypeName(datamask);
        policyRefDataMaskType.setDataMaskDefId(dataMaskTypeId);
        policyRefDataMaskTypeDao.create(policyRefDataMaskType);
    }
    logger.info("<== addDataMaskDefRef(id=" + policyId + ")");
}
Also used : XXPolicyRefDataMaskType(org.apache.ranger.entity.XXPolicyRefDataMaskType) XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXDataMaskTypeDef(org.apache.ranger.entity.XXDataMaskTypeDef) XXPolicyRefDataMaskTypeDao(org.apache.ranger.db.XXPolicyRefDataMaskTypeDao)

Aggregations

XXPolicyRefDataMaskTypeDao (org.apache.ranger.db.XXPolicyRefDataMaskTypeDao)2 XXDataMaskTypeDef (org.apache.ranger.entity.XXDataMaskTypeDef)2 XXPolicyRefDataMaskType (org.apache.ranger.entity.XXPolicyRefDataMaskType)2 XXServiceDef (org.apache.ranger.entity.XXServiceDef)2