Search in sources :

Example 1 with PermissionModel

use of com.synopsys.integration.alert.component.users.web.role.PermissionModel in project hub-alert by blackducksoftware.

the class PermissionModelUtil method convertToPermissionMatrixModel.

public static PermissionMatrixModel convertToPermissionMatrixModel(Set<PermissionModel> permissionModels) {
    Map<PermissionKey, Integer> permissionMatrix = new HashMap<>();
    for (PermissionModel permissionModel : permissionModels) {
        String descriptorKey = permissionModel.getDescriptorName();
        String context = permissionModel.getContext();
        PermissionKey permissionKey = new PermissionKey(context, descriptorKey);
        int accessOperationsBits = 0;
        if (permissionModel.isCreate()) {
            accessOperationsBits = BitwiseUtil.combineBits(accessOperationsBits, AccessOperation.CREATE.getBit());
        }
        if (permissionModel.isRead()) {
            accessOperationsBits = BitwiseUtil.combineBits(accessOperationsBits, AccessOperation.READ.getBit());
        }
        if (permissionModel.isDelete()) {
            accessOperationsBits = BitwiseUtil.combineBits(accessOperationsBits, AccessOperation.DELETE.getBit());
        }
        if (permissionModel.isExecute()) {
            accessOperationsBits = BitwiseUtil.combineBits(accessOperationsBits, AccessOperation.EXECUTE.getBit());
        }
        if (permissionModel.isWrite()) {
            accessOperationsBits = BitwiseUtil.combineBits(accessOperationsBits, AccessOperation.WRITE.getBit());
        }
        if (permissionModel.isUploadDelete()) {
            accessOperationsBits = BitwiseUtil.combineBits(accessOperationsBits, AccessOperation.UPLOAD_FILE_DELETE.getBit());
        }
        if (permissionModel.isUploadRead()) {
            accessOperationsBits = BitwiseUtil.combineBits(accessOperationsBits, AccessOperation.UPLOAD_FILE_READ.getBit());
        }
        if (permissionModel.isUploadWrite()) {
            accessOperationsBits = BitwiseUtil.combineBits(accessOperationsBits, AccessOperation.UPLOAD_FILE_WRITE.getBit());
        }
        permissionMatrix.put(permissionKey, accessOperationsBits);
    }
    return new PermissionMatrixModel(permissionMatrix);
}
Also used : PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) HashMap(java.util.HashMap) PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) PermissionModel(com.synopsys.integration.alert.component.users.web.role.PermissionModel)

Aggregations

PermissionKey (com.synopsys.integration.alert.common.persistence.model.PermissionKey)1 PermissionMatrixModel (com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel)1 PermissionModel (com.synopsys.integration.alert.component.users.web.role.PermissionModel)1 HashMap (java.util.HashMap)1