Java tutorial
/* Copyright (C) 2009 NTT DATA Corporation This program is free software; you can redistribute it and/or Modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ package com.clustercontrol.accesscontrol.util; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.eclipse.jface.dialogs.MessageDialog; import com.clustercontrol.accesscontrol.bean.PrivilegeConstant.ObjectPrivilegeMode; import com.clustercontrol.util.HinemosMessage; import com.clustercontrol.util.Messages; import com.clustercontrol.ws.access.InvalidRole_Exception; import com.clustercontrol.ws.access.ObjectPrivilegeFilterInfo; import com.clustercontrol.ws.access.ObjectPrivilegeInfo; /** * ?DTO???????? * * @version 4.0.0 */ public class RoleObjectPrivilegeUtil { /** ? */ private static Log m_log = LogFactory.getLog(RoleObjectPrivilegeUtil.class); /** */ public static final String OBJECT_TYPE = "objectType"; /** ID */ public static final String OBJECT_ID = "objectId"; /** ID */ public static final String ROLE_ID = "roleId"; /** ? */ public static final String OBJECT_PRIVILEGE = "objectPrivilege"; /** ? */ public static final String CREATE_TIME = "createTime"; /** ?? */ public static final String CREATE_USER = "createUser"; /** */ public static final String MODIFY_USER = "modifyUSER"; /** */ public static final String MODIFY_TIME = "modifyTime"; /** * ????DB??????(???) */ public static List<ObjectPrivilegeInfo> beanList2dtoList(List<ObjectPrivilegeBean> beanList) { List<ObjectPrivilegeInfo> resultList = new ArrayList<ObjectPrivilegeInfo>(); for (ObjectPrivilegeBean bean : beanList) { // ?? ObjectPrivilegeInfo ?? ObjectPrivilegeInfo info = null; // ?????????????? if (bean.getReadPrivilege() || bean.getOwnerFlag()) { info = getCommon(bean); info.setObjectPrivilege(ObjectPrivilegeMode.READ.toString()); resultList.add(info); } // ? if (bean.getWritePrivilege()) { info = getCommon(bean); info.setObjectPrivilege(ObjectPrivilegeMode.MODIFY.toString()); resultList.add(info); } // ? if (bean.getExecPrivilege()) { info = getCommon(bean); info.setObjectPrivilege(ObjectPrivilegeMode.EXEC.toString()); resultList.add(info); } } return resultList; } /** * ?????DB?????? */ public static List<ObjectPrivilegeInfo> beanMap2dtoList(HashMap<String, ObjectPrivilegeBean> beanMap) { List<ObjectPrivilegeInfo> resultList = new ArrayList<ObjectPrivilegeInfo>(); ObjectPrivilegeBean bean = null; for (Map.Entry<String, ObjectPrivilegeBean> keyValue : beanMap.entrySet()) { bean = keyValue.getValue(); // ?? ObjectPrivilegeInfo ?? // ?? if (bean.getReadPrivilege()) { ObjectPrivilegeInfo info = getCommon(bean); info.setObjectPrivilege(ObjectPrivilegeMode.READ.toString()); resultList.add(info); } // ? if (bean.getWritePrivilege()) { ObjectPrivilegeInfo info = getCommon(bean); info.setObjectPrivilege(ObjectPrivilegeMode.MODIFY.toString()); resultList.add(info); } // ? if (bean.getExecPrivilege()) { ObjectPrivilegeInfo info = getCommon(bean); info.setObjectPrivilege(ObjectPrivilegeMode.EXEC.toString()); resultList.add(info); } } return resultList; } // utilMap2dtoList() ???? private static ObjectPrivilegeInfo getCommon(ObjectPrivilegeBean bean) { ObjectPrivilegeInfo info = new ObjectPrivilegeInfo(); // ID info.setRoleId(bean.getRoleId()); return info; } /** * DB??????(HashMap)??? */ public static HashMap<String, ObjectPrivilegeBean> dto2beanMap(List<ObjectPrivilegeInfo> infoList) { HashMap<String, ObjectPrivilegeBean> resultMap = new HashMap<String, ObjectPrivilegeBean>(); ObjectPrivilegeBean bean = null; if (infoList == null) { return null; } for (ObjectPrivilegeInfo info : infoList) { // ID????????? if (resultMap.get(info.getRoleId()) == null) { bean = new ObjectPrivilegeBean(); bean.setRoleId(info.getRoleId()); resultMap.put(info.getRoleId(), bean); } else bean = resultMap.get(info.getRoleId()); if (info.getObjectPrivilege().equals(ObjectPrivilegeMode.READ.toString())) { bean.setReadPrivilege(true); } else if (info.getObjectPrivilege().equals(ObjectPrivilegeMode.MODIFY.toString())) { bean.setWritePrivilege(true); } else if (info.getObjectPrivilege().equals(ObjectPrivilegeMode.EXEC.toString())) { bean.setExecPrivilege(true); } } return resultMap; } /** * ID???????????? */ public static HashMap<String, ObjectPrivilegeBean> dto2beanMap(String managerName, String objectId, String objectType) { // ???? List<ObjectPrivilegeInfo> objectPrivilegeList = null; // ? ObjectPrivilegeFilterInfo filter = new ObjectPrivilegeFilterInfo(); filter.setObjectId(objectId); filter.setObjectType(objectType); try { AccessEndpointWrapper wrapper = AccessEndpointWrapper.getWrapper(managerName); objectPrivilegeList = wrapper.getObjectPrivilegeInfoList(filter); } catch (InvalidRole_Exception e) { // ??? MessageDialog.openInformation(null, Messages.getString("message"), Messages.getString("message.accesscontrol.16")); } catch (Exception e) { // ? m_log.warn("getOwnUserList(), " + HinemosMessage.replace(e.getMessage()), e); MessageDialog.openError(null, Messages.getString("failed"), Messages.getString("message.hinemos.failure.unexpected") + ", " + HinemosMessage.replace(e.getMessage())); } return dto2beanMap(objectPrivilegeList); } // /** // * ObjectPrivilegeUtil ?? DB ? // */ // public void utilMap2dto(HashMap<String, ObjectPrivilegeUtil> utilMap) { // // // ??? // List<ObjectPrivilegeUtil> delegeList = new ArrayList<ObjectPrivilegeUtil>(); // // ??? // List<ObjectPrivilegeUtil> insertList = new ArrayList<ObjectPrivilegeUtil>(); // // // // } }