package org.ovirt.engine.core.bll; import java.util.Collections; import java.util.Map; import org.ovirt.engine.core.common.AuditLogType; import org.ovirt.engine.core.common.VdcObjectType; import org.ovirt.engine.core.common.action.RolesOperationsParameters; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.dal.VdcBllMessages; import org.ovirt.engine.core.dal.dbbroker.DbFacade; public class AddRoleCommand<T extends RolesOperationsParameters> extends RolesOperationCommandBase<T> { public AddRoleCommand(T parameters) { super(parameters); } @Override protected boolean canDoAction() { boolean returnValue = true; if (DbFacade.getInstance().getRoleDAO().getByName(getRole().getname()) != null) { addCanDoActionMessage(VdcBllMessages.VAR__ACTION__ADD); addCanDoActionMessage(VdcBllMessages.ERROR_CANNOT_UPDATE_ROLE_NAME); returnValue = false; } return returnValue; } @Override public AuditLogType getAuditLogTypeValue() { return getSucceeded() ? AuditLogType.USER_ADD_ROLE : AuditLogType.USER_ADD_ROLE_FAILED; } @Override protected void executeCommand() { getRole().setId(Guid.NewGuid()); DbFacade.getInstance().getRoleDAO().save(getRole()); getReturnValue().setActionReturnValue(getRole().getId()); setSucceeded(true); } @Override public Map<Guid, VdcObjectType> getPermissionCheckSubjects() { return Collections.singletonMap(MultiLevelAdministrationHandler.SYSTEM_OBJECT_ID, VdcObjectType.System); } }