assertThat(picoContainer.getParent().getParent().getParent().getComponentAdapters()).hasSize(
COMPONENTS_IN_LEVEL_1_AT_CONSTRUCTION
+ 24 // level 1
- + 52 // content of DaoModule
+ + 48 // content of DaoModule
+ 2 // content of EsSearchModule
+ 62 // content of CorePropertyDefinitions
+ 1 // content of CePropertyDefinitions
import org.sonar.db.component.ResourceDao;
import org.sonar.db.component.ResourceIndexDao;
import org.sonar.db.component.SnapshotDao;
-import org.sonar.db.dashboard.ActiveDashboardDao;
-import org.sonar.db.dashboard.DashboardDao;
-import org.sonar.db.dashboard.WidgetDao;
-import org.sonar.db.dashboard.WidgetPropertyDao;
import org.sonar.db.duplication.DuplicationDao;
import org.sonar.db.event.EventDao;
import org.sonar.db.issue.IssueChangeDao;
public class DaoModule extends Module {
private static final List<Class<? extends Dao>> classes = ImmutableList.<Class<? extends Dao>>builder().add(
- ActiveDashboardDao.class,
AuthorDao.class,
AuthorizationDao.class,
CeActivityDao.class,
ComponentDao.class,
ComponentLinkDao.class,
CustomMeasureDao.class,
- DashboardDao.class,
DuplicationDao.class,
EventDao.class,
FileSourceDao.class,
UserDao.class,
UserGroupDao.class,
UserPermissionDao.class,
- UserTokenDao.class,
- WidgetDao.class,
- WidgetPropertyDao.class).build();
+ UserTokenDao.class).build();
@Override
protected void configureModule() {
import org.sonar.db.component.ResourceDao;
import org.sonar.db.component.ResourceIndexDao;
import org.sonar.db.component.SnapshotDao;
-import org.sonar.db.dashboard.ActiveDashboardDao;
-import org.sonar.db.dashboard.DashboardDao;
-import org.sonar.db.dashboard.WidgetDao;
-import org.sonar.db.dashboard.WidgetPropertyDao;
import org.sonar.db.duplication.DuplicationDao;
import org.sonar.db.event.EventDao;
import org.sonar.db.issue.IssueChangeDao;
private final CeQueueDao ceQueueDao;
private final CeTaskInputDao ceTaskInputDao;
private final CeScannerContextDao ceScannerContextDao;
- private final DashboardDao dashboardDao;
- private final ActiveDashboardDao activeDashboardDao;
- private final WidgetDao widgetDao;
- private final WidgetPropertyDao widgetPropertyDao;
private final FileSourceDao fileSourceDao;
private final AuthorDao authorDao;
private final ResourceIndexDao componentIndexDao;
ceQueueDao = getDao(map, CeQueueDao.class);
ceTaskInputDao = getDao(map, CeTaskInputDao.class);
ceScannerContextDao = getDao(map, CeScannerContextDao.class);
- dashboardDao = getDao(map, DashboardDao.class);
- activeDashboardDao = getDao(map, ActiveDashboardDao.class);
- widgetDao = getDao(map, WidgetDao.class);
- widgetPropertyDao = getDao(map, WidgetPropertyDao.class);
fileSourceDao = getDao(map, FileSourceDao.class);
authorDao = getDao(map, AuthorDao.class);
componentIndexDao = getDao(map, ResourceIndexDao.class);
return ceScannerContextDao;
}
- public DashboardDao dashboardDao() {
- return dashboardDao;
- }
-
- public ActiveDashboardDao activeDashboardDao() {
- return activeDashboardDao;
- }
-
- public WidgetDao widgetDao() {
- return widgetDao;
- }
-
- public WidgetPropertyDao widgetPropertyDao() {
- return widgetPropertyDao;
- }
-
public FileSourceDao fileSourceDao() {
return fileSourceDao;
}
import org.sonar.db.component.SnapshotMapper;
import org.sonar.db.component.UuidWithProjectUuidDto;
import org.sonar.db.component.ViewsSnapshotDto;
-import org.sonar.db.dashboard.ActiveDashboardDto;
-import org.sonar.db.dashboard.ActiveDashboardMapper;
-import org.sonar.db.dashboard.DashboardDto;
-import org.sonar.db.dashboard.DashboardMapper;
-import org.sonar.db.dashboard.WidgetDto;
-import org.sonar.db.dashboard.WidgetMapper;
-import org.sonar.db.dashboard.WidgetPropertyDto;
-import org.sonar.db.dashboard.WidgetPropertyMapper;
import org.sonar.db.debt.RequirementMigrationDto;
import org.sonar.db.duplication.DuplicationMapper;
import org.sonar.db.duplication.DuplicationUnitDto;
MyBatisConfBuilder confBuilder = new MyBatisConfBuilder(database);
// DTO aliases, keep them sorted alphabetically
- confBuilder.loadAlias("ActiveDashboard", ActiveDashboardDto.class);
confBuilder.loadAlias("ActiveRule", ActiveRuleDto.class);
confBuilder.loadAlias("ActiveRuleParam", ActiveRuleParamDto.class);
confBuilder.loadAlias("Author", AuthorDto.class);
confBuilder.loadAlias("ComponentLink", ComponentLinkDto.class);
confBuilder.loadAlias("ComponentWithSnapshot", ComponentDtoWithSnapshotId.class);
confBuilder.loadAlias("CustomMeasure", CustomMeasureDto.class);
- confBuilder.loadAlias("Dashboard", DashboardDto.class);
confBuilder.loadAlias("DuplicationUnit", DuplicationUnitDto.class);
confBuilder.loadAlias("Event", EventDto.class);
confBuilder.loadAlias("FilePathWithHash", FilePathWithHashDto.class);
confBuilder.loadAlias("User", UserDto.class);
confBuilder.loadAlias("UuidWithProjectUuid", UuidWithProjectUuidDto.class);
confBuilder.loadAlias("ViewsSnapshot", ViewsSnapshotDto.class);
- confBuilder.loadAlias("WidgetProperty", WidgetPropertyDto.class);
- confBuilder.loadAlias("Widget", WidgetDto.class);
// ResourceMapper has to be loaded before IssueMapper because this last one used it
confBuilder.loadMapper(ResourceMapper.class);
// keep them sorted alphabetically
Class<?>[] mappers = {
- ActiveDashboardMapper.class,
ActiveRuleMapper.class,
AuthorMapper.class,
AuthorizationMapper.class,
ComponentLinkMapper.class,
ComponentMapper.class,
CustomMeasureMapper.class,
- DashboardMapper.class,
DuplicationMapper.class,
EventMapper.class,
FileSourceMapper.class,
UserGroupMapper.class,
UserMapper.class,
UserPermissionMapper.class,
- UserTokenMapper.class,
- WidgetMapper.class,
- WidgetPropertyMapper.class
+ UserTokenMapper.class
};
confBuilder.loadMappers(mappers);
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.db.dashboard;
-
-import java.util.List;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-import org.apache.ibatis.session.SqlSession;
-import org.sonar.db.Dao;
-import org.sonar.db.DbSession;
-import org.sonar.db.MyBatis;
-
-public class ActiveDashboardDao implements Dao {
-
- private MyBatis mybatis;
-
- public ActiveDashboardDao(MyBatis mybatis) {
- this.mybatis = mybatis;
- }
-
- public void insert(DbSession session, ActiveDashboardDto activeDashboardDto) {
- mapper(session).insert(activeDashboardDto);
- session.commit();
- }
-
- public void insert(ActiveDashboardDto activeDashboardDto) {
- DbSession session = mybatis.openSession(false);
- try {
- insert(session, activeDashboardDto);
- session.commit();
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- @CheckForNull
- public ActiveDashboardDto selectById(DbSession session, long id){
- return mapper(session).selectById(id);
- }
-
- public int selectMaxOrderIndexForNullUser() {
- SqlSession session = mybatis.openSession(false);
- try {
- Integer max = mapper(session).selectMaxOrderIndexForNullUser();
- return max != null ? max.intValue() : 0;
- } finally {
- session.close();
- }
-
- }
-
- public List<DashboardDto> selectGlobalDashboardsForUserLogin(@Nullable String login) {
- SqlSession session = mybatis.openSession(false);
- try {
- return mapper(session).selectGlobalDashboardsForUserLogin(login);
- } finally {
- session.close();
- }
- }
-
- public List<DashboardDto> selectProjectDashboardsForUserLogin(@Nullable String login) {
- SqlSession session = mybatis.openSession(false);
- try {
- return selectProjectDashboardsForUserLogin(session, login);
- } finally {
- session.close();
- }
- }
-
- public List<DashboardDto> selectProjectDashboardsForUserLogin(SqlSession session, @Nullable String login) {
- return mapper(session).selectProjectDashboardsForUserLogin(login);
- }
-
- private static ActiveDashboardMapper mapper(SqlSession session) {
- return session.getMapper(ActiveDashboardMapper.class);
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.db.dashboard;
-
-import java.util.Objects;
-
-public final class ActiveDashboardDto {
- private Long id;
- private Long dashboardId;
- private Long userId;
- private Integer orderIndex;
-
- /**
- * @return the id
- */
- public Long getId() {
- return id;
- }
-
- /**
- * @param id the id to set
- */
- public ActiveDashboardDto setId(Long id) {
- this.id = id;
- return this;
- }
-
- /**
- * @return the dashboardId
- */
- public Long getDashboardId() {
- return dashboardId;
- }
-
- /**
- * @param dashboardId the dashboardId to set
- */
- public ActiveDashboardDto setDashboardId(Long dashboardId) {
- this.dashboardId = dashboardId;
- return this;
- }
-
- /**
- * @return the userId
- */
- public Long getUserId() {
- return userId;
- }
-
- /**
- * @param userId the userId to set
- */
- public ActiveDashboardDto setUserId(Long userId) {
- this.userId = userId;
- return this;
- }
-
- /**
- * @return the orderIndex
- */
- public Integer getOrderIndex() {
- return orderIndex;
- }
-
- /**
- * @param orderIndex the orderIndex to set
- */
- public ActiveDashboardDto setOrderIndex(Integer orderIndex) {
- this.orderIndex = orderIndex;
- return this;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- ActiveDashboardDto that = (ActiveDashboardDto) o;
- return !(id != null ? !id.equals(that.id) : that.id != null);
- }
-
- @Override
- public int hashCode() {
- return Objects.hashCode(id);
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.db.dashboard;
-
-import java.util.List;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-import org.apache.ibatis.annotations.Param;
-
-public interface ActiveDashboardMapper {
-
- void insert(ActiveDashboardDto activeDashboardDto);
-
- ActiveDashboardDto selectById(long id);
-
- @CheckForNull
- Integer selectMaxOrderIndexForNullUser();
-
- List<DashboardDto> selectGlobalDashboardsForUserLogin(@Nullable @Param("login") String login);
-
- List<DashboardDto> selectProjectDashboardsForUserLogin(@Nullable @Param("login") String login);
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.db.dashboard;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-import org.apache.ibatis.session.SqlSession;
-import org.sonar.db.Dao;
-import org.sonar.db.DbSession;
-import org.sonar.db.MyBatis;
-
-public class DashboardDao implements Dao {
-
- private MyBatis mybatis;
-
- public DashboardDao(MyBatis mybatis) {
- this.mybatis = mybatis;
- }
-
- public DashboardDto selectGlobalDashboard(String name) {
- SqlSession session = mybatis.openSession(false);
- try {
- DashboardMapper mapper = session.getMapper(DashboardMapper.class);
- return mapper.selectGlobalDashboard(name);
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- public void insert(DbSession session, DashboardDto dashboardDto) {
- DashboardMapper dashboardMapper = session.getMapper(DashboardMapper.class);
- WidgetMapper widgetMapper = session.getMapper(WidgetMapper.class);
- WidgetPropertyMapper widgetPropertyMapper = session.getMapper(WidgetPropertyMapper.class);
- dashboardMapper.insert(dashboardDto);
- for (WidgetDto widgetDto : dashboardDto.getWidgets()) {
- widgetDto.setDashboardId(dashboardDto.getId());
- widgetMapper.insert(widgetDto);
- for (WidgetPropertyDto widgetPropertyDto : widgetDto.getWidgetProperties()) {
- widgetPropertyDto.setWidgetId(widgetDto.getId());
- widgetPropertyMapper.insert(widgetPropertyDto);
- }
- }
- }
-
- public void insert(DashboardDto dashboardDto) {
- DbSession session = mybatis.openSession(false);
- try {
- insert(session, dashboardDto);
- session.commit();
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- @CheckForNull
- public DashboardDto selectById(DbSession session, long id) {
- return mapper(session).selectById(id);
- }
-
- /**
- * Get dashboard if allowed : shared or owned by logged-in user
- * @param userId id of logged-in user, null if anonymous
- */
- @CheckForNull
- public DashboardDto selectAllowedByKey(DbSession session, Long key, @Nullable Long userId) {
- return mapper(session).selectAllowedById(key, userId != null ? userId : -1L);
- }
-
- private static DashboardMapper mapper(DbSession session) {
- return session.getMapper(DashboardMapper.class);
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.db.dashboard;
-
-import com.google.common.collect.Lists;
-import java.util.Collection;
-import java.util.List;
-import org.sonar.db.Dto;
-
-public final class DashboardDto extends Dto<Long> {
-
- private Long id;
- private Long userId;
- private String name;
- private String description;
- private String columnLayout;
- private boolean shared;
- private List<WidgetDto> widgetDtos = Lists.newArrayList();
-
- public Long getId() {
- return id;
- }
-
- @Override
- public Long getKey() {
- return id;
- }
-
- public DashboardDto setId(Long id) {
- this.id = id;
- return this;
- }
-
- public Long getUserId() {
- return userId;
- }
-
- public DashboardDto setUserId(Long userId) {
- this.userId = userId;
- return this;
- }
-
- public String getName() {
- return name;
- }
-
- public DashboardDto setName(String name) {
- this.name = name;
- return this;
- }
-
- public String getDescription() {
- return description;
- }
-
- public DashboardDto setDescription(String description) {
- this.description = description;
- return this;
- }
-
- public String getColumnLayout() {
- return columnLayout;
- }
-
- public DashboardDto setColumnLayout(String columnLayout) {
- this.columnLayout = columnLayout;
- return this;
- }
-
- public boolean getShared() {
- return shared;
- }
-
- public DashboardDto setShared(boolean shared) {
- this.shared = shared;
- return this;
- }
-
- public Collection<WidgetDto> getWidgets() {
- return widgetDtos;
- }
-
- public DashboardDto addWidget(WidgetDto widgetDto) {
- widgetDtos.add(widgetDto);
- return this;
- }
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.db.dashboard;
-
-import javax.annotation.CheckForNull;
-import org.apache.ibatis.annotations.Insert;
-import org.apache.ibatis.annotations.Options;
-import org.apache.ibatis.annotations.Param;
-import org.apache.ibatis.annotations.Select;
-
-public interface DashboardMapper {
-
- String COLUMNS = "id, user_id as \"userId\", name, description, column_layout as \"columnLayout\", " +
- "shared, created_at as \"createdAt\", updated_at as \"updatedAt\"";
-
- @CheckForNull
- @Select("select " + COLUMNS + " from dashboards where id=#{id}")
- DashboardDto selectById(long id);
-
- @CheckForNull
- @Select("select " + COLUMNS + " from dashboards where id=#{id} and (shared=${_true} or user_id=${userId})")
- DashboardDto selectAllowedById(@Param("id") long id, @Param("userId") long userId);
-
- @CheckForNull
- @Select("select " + COLUMNS + " from dashboards WHERE name=#{id} and user_id is null")
- DashboardDto selectGlobalDashboard(String name);
-
- @Insert("INSERT INTO dashboards (user_id, name, description, column_layout, shared, created_at, updated_at) " +
- "VALUES (#{userId}, #{name}, #{description}, #{columnLayout}, #{shared}, #{createdAt}, #{updatedAt})")
- @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
- void insert(DashboardDto dashboardDto);
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.db.dashboard;
-
-import java.util.Collection;
-import org.sonar.db.Dao;
-import org.sonar.db.DbSession;
-import org.sonar.db.MyBatis;
-
-public class WidgetDao implements Dao {
-
- private MyBatis myBatis;
-
- public WidgetDao(MyBatis myBatis) {
- this.myBatis = myBatis;
- }
-
- public WidgetDto selectByKey(Long widgetId) {
- DbSession session = myBatis.openSession(false);
- try {
- return selectByKey(session, widgetId);
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- public WidgetDto selectByKey(DbSession session, Long widgetId) {
- return mapper(session).selectById(widgetId);
- }
-
- public WidgetDto update(WidgetDto item) {
- DbSession session = myBatis.openSession(false);
- try {
- return update(session, item);
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- public WidgetDto update(DbSession session, WidgetDto item) {
- mapper(session).update(item);
- return item;
- }
-
- public Collection<WidgetDto> findByDashboard(DbSession session, long dashboardKey) {
- return mapper(session).selectByDashboard(dashboardKey);
- }
-
- public Collection<WidgetDto> findAll(DbSession session) {
- return mapper(session).selectAll();
- }
-
- private static WidgetMapper mapper(DbSession session) {
- return session.getMapper(WidgetMapper.class);
- }
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.db.dashboard;
-
-import com.google.common.collect.Lists;
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-
-public class WidgetDto {
- private Long id;
- private Long dashboardId;
- private String widgetKey;
- private String name;
- private String description;
- private Integer columnIndex;
- private Integer rowIndex;
- private boolean configured;
- private Integer resourceId;
- private Date createdAt;
- private Date updatedAt;
- private List<WidgetPropertyDto> widgetPropertyDtos = Lists.newArrayList();
-
- /**
- * @return the id
- */
- public Long getId() {
- return id;
- }
-
- /**
- * @param id the id to set
- */
- public WidgetDto setId(Long id) {
- this.id = id;
- return this;
- }
-
- /**
- * @return the dashboardId
- */
- public Long getDashboardId() {
- return dashboardId;
- }
-
- /**
- * @param dashboardId the dashboardId to set
- */
- public WidgetDto setDashboardId(Long dashboardId) {
- this.dashboardId = dashboardId;
- return this;
- }
-
- public String getWidgetKey() {
- return widgetKey;
- }
-
- public WidgetDto setWidgetKey(String s) {
- this.widgetKey = s;
- return this;
- }
-
- /**
- * @return the name
- */
- public String getName() {
- return name;
- }
-
- /**
- * @param name the name to set
- */
- public WidgetDto setName(String name) {
- this.name = name;
- return this;
- }
-
- /**
- * @return the description
- */
- public String getDescription() {
- return description;
- }
-
- /**
- * @param description the description to set
- */
- public WidgetDto setDescription(String description) {
- this.description = description;
- return this;
- }
-
- /**
- * @return the columnIndex
- */
- public Integer getColumnIndex() {
- return columnIndex;
- }
-
- /**
- * @param columnIndex the columnIndex to set
- */
- public WidgetDto setColumnIndex(Integer columnIndex) {
- this.columnIndex = columnIndex;
- return this;
- }
-
- /**
- * @return the rowIndex
- */
- public Integer getRowIndex() {
- return rowIndex;
- }
-
- /**
- * @param rowIndex the rowIndex to set
- */
- public WidgetDto setRowIndex(Integer rowIndex) {
- this.rowIndex = rowIndex;
- return this;
- }
-
- /**
- * @return the configured
- */
- public boolean getConfigured() {
- return configured;
- }
-
- /**
- * @param configured the configured to set
- */
- public WidgetDto setConfigured(boolean configured) {
- this.configured = configured;
- return this;
- }
-
- /**
- * @return the widgetProperties
- */
- public Collection<WidgetPropertyDto> getWidgetProperties() {
- return widgetPropertyDtos;
- }
-
- /**
- * @param widgetPropertyDto the widgetProperty to set
- */
- public WidgetDto addWidgetProperty(WidgetPropertyDto widgetPropertyDto) {
- widgetPropertyDtos.add(widgetPropertyDto);
- return this;
- }
-
- /**
- * @return the resourceId
- * @since 3.1
- */
- public Integer getResourceId() {
- return resourceId;
- }
-
- /**
- * @param resourceId the resourceId to set
- * @since 3.1
- */
- public WidgetDto setResourceId(Integer resourceId) {
- this.resourceId = resourceId;
- return this;
- }
-
- public WidgetDto setCreatedAt(Date datetime) {
- this.createdAt = datetime;
- return this;
- }
-
- public WidgetDto setUpdatedAt(Date datetime) {
- this.updatedAt = datetime;
- return this;
- }
-
- public final Date getCreatedAt() {
- return this.createdAt;
- }
-
- public final Date getUpdatedAt() {
- return this.updatedAt;
- }
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.db.dashboard;
-
-import java.util.Collection;
-import org.apache.ibatis.annotations.Insert;
-import org.apache.ibatis.annotations.Options;
-import org.apache.ibatis.annotations.Update;
-
-public interface WidgetMapper {
-
- @Insert("insert into widgets (dashboard_id, widget_key, name, description, column_index, " +
- " row_index, configured, created_at, updated_at, resource_id)" +
- " values (#{dashboardId,jdbcType=INTEGER}, #{widgetKey,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, " +
- " #{description,jdbcType=VARCHAR}, #{columnIndex,jdbcType=INTEGER}, " +
- " #{rowIndex,jdbcType=INTEGER}, #{configured,jdbcType=BOOLEAN}, #{createdAt,jdbcType=TIMESTAMP}, #{updatedAt,jdbcType=TIMESTAMP}, #{resourceId,jdbcType=INTEGER})")
- @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
- void insert(WidgetDto widgetDto);
-
- WidgetDto selectById(long widgetId);
-
- Collection<WidgetDto> selectByDashboard(long dashboardKey);
-
- Collection<WidgetDto> selectAll();
-
- @Update("UPDATE widgets SET " +
- "dashboard_id=#{dashboardId,jdbcType=INTEGER}, " +
- "widget_key=#{widgetKey,jdbcType=VARCHAR}, " +
- "name=#{name,jdbcType=VARCHAR}, " +
- "description=#{description,jdbcType=VARCHAR}, " +
- "column_index=#{columnIndex,jdbcType=INTEGER}, " +
- "row_index=#{rowIndex,jdbcType=INTEGER}, " +
- "configured=#{configured,jdbcType=BOOLEAN}, " +
- "created_at=#{createdAt,jdbcType=TIMESTAMP}, " +
- "updated_at=#{updatedAt,jdbcType=TIMESTAMP}, " +
- "resource_id=#{resourceId,jdbcType=INTEGER} " +
- "WHERE id=#{id}")
- @Options(useGeneratedKeys = false)
- void update(WidgetDto item);
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.db.dashboard;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import org.sonar.db.Dao;
-import org.sonar.db.DbSession;
-import org.sonar.db.MyBatis;
-
-import static org.sonar.db.DatabaseUtils.executeLargeInputs;
-
-public class WidgetPropertyDao implements Dao {
-
- private final MyBatis myBatis;
-
- public WidgetPropertyDao(MyBatis myBatis) {
- this.myBatis = myBatis;
- }
-
- public WidgetPropertyDto insert(WidgetPropertyDto item) {
- DbSession session = myBatis.openSession(false);
- try {
- return insert(session, item);
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- public WidgetPropertyDto insert(DbSession session, WidgetPropertyDto item) {
- mapper(session).insert(item);
- return item;
- }
-
- public void insert(DbSession session, Collection<WidgetPropertyDto> items) {
- for (WidgetPropertyDto item : items) {
- insert(session, item);
- }
- }
-
- public WidgetPropertyDto selectByKey(Long propertyId) {
- DbSession session = myBatis.openSession(false);
- try {
- return selectByKey(session, propertyId);
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- public WidgetPropertyDto selectByKey(DbSession session, Long propertyId) {
- return mapper(session).selectById(propertyId);
- }
-
- public Collection<WidgetPropertyDto> selectByDashboard(DbSession session, long dashboardKey) {
- return mapper(session).selectByDashboard(dashboardKey);
- }
-
- public void deleteByWidgetIds(DbSession session, List<Long> widgetIdsWithPropertiesToDelete) {
- executeLargeInputs(
- widgetIdsWithPropertiesToDelete,
- input -> {
- mapper(session).deleteByWidgetIds(input);
- return Collections.emptyList();
- });
- }
-
- private static WidgetPropertyMapper mapper(DbSession session) {
- return session.getMapper(WidgetPropertyMapper.class);
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.db.dashboard;
-
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.ListMultimap;
-import java.util.Collection;
-
-public class WidgetPropertyDto {
- private Long id;
- private Long widgetId;
- private String propertyKey;
- private String textValue;
-
- public Long getId() {
- return id;
- }
-
- public WidgetPropertyDto setId(Long id) {
- this.id = id;
- return this;
- }
-
- public Long getWidgetId() {
- return widgetId;
- }
-
- public WidgetPropertyDto setWidgetId(Long widgetId) {
- this.widgetId = widgetId;
- return this;
- }
-
- public String getPropertyKey() {
- return propertyKey;
- }
-
- public WidgetPropertyDto setPropertyKey(String s) {
- this.propertyKey = s;
- return this;
- }
-
- public String getTextValue() {
- return textValue;
- }
-
- public WidgetPropertyDto setTextValue(String s) {
- this.textValue = s;
- return this;
- }
-
- public static ListMultimap<Long, WidgetPropertyDto> groupByWidgetId(Collection<WidgetPropertyDto> properties) {
- ListMultimap<Long, WidgetPropertyDto> group = ArrayListMultimap.create();
- for (WidgetPropertyDto property : properties) {
- group.put(property.getWidgetId(), property);
- }
- return group;
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.db.dashboard;
-
-import java.util.Collection;
-import java.util.List;
-import javax.annotation.CheckForNull;
-import org.apache.ibatis.annotations.Insert;
-import org.apache.ibatis.annotations.Options;
-import org.apache.ibatis.annotations.Select;
-
-public interface WidgetPropertyMapper {
-
- String COLUMNS = "wp.id, wp.widget_id as \"widgetId\", wp.kee as \"propertyKey\", wp.text_value as \"textValue\"";
-
- @Insert("insert into widget_properties (widget_id, kee, text_value) values (#{widgetId}, #{propertyKey}, #{textValue})")
- @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
- void insert(WidgetPropertyDto dto);
-
- @CheckForNull
- @Select("select " + COLUMNS + " from widget_properties wp where wp.id=#{id}")
- WidgetPropertyDto selectById(long propertyId);
-
- @Select("select " + COLUMNS + " from widget_properties wp " +
- "inner join widgets w on w.id=wp.widget_id where w.dashboard_id=#{id}")
- Collection<WidgetPropertyDto> selectByDashboard(long dashboardKey);
-
- void deleteByWidgetIds(List<Long> widgetIds);
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-@ParametersAreNonnullByDefault
-package org.sonar.db.dashboard;
-
-import javax.annotation.ParametersAreNonnullByDefault;
-
}
mapper.removeUserFromGroups(dto.getId());
- mapper.deleteUserActiveDashboards(dto.getId());
- mapper.deleteUnsharedUserDashboards(dto.getId());
mapper.deleteUnsharedUserIssueFilters(dto.getLogin());
mapper.deleteUserIssueFilterFavourites(dto.getLogin());
mapper.deleteUnsharedUserMeasureFilters(dto.getId());
void removeUserFromGroups(long userId);
- void deleteUserActiveDashboards(long userId);
-
- void deleteUnsharedUserDashboards(long userId);
-
void deleteUnsharedUserIssueFilters(String login);
void deleteUserIssueFilterFavourites(String login);
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-
-<mapper namespace="org.sonar.db.dashboard.ActiveDashboardMapper">
-
- <sql id="activeDashboardColumns">
- ad.id,
- ad.user_id as "userId",
- ad.dashboard_id as "dashboardId",
- ad.order_index as "orderIndex"
- </sql>
-
- <insert id="insert" parameterType="ActiveDashboard" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
- INSERT INTO active_dashboards (dashboard_id, user_id, order_index)
- VALUES (#{dashboardId}, #{userId}, #{orderIndex})
- </insert>
-
- <select id="selectById" resultType="ActiveDashboard">
- SELECT <include refid="activeDashboardColumns"/>
- FROM active_dashboards ad
- WHERE ad.id=#{id}
- </select>
-
- <select id="selectMaxOrderIndexForNullUser" resultType="Integer">
- SELECT MAX(order_index)
- FROM active_dashboards
- WHERE user_id IS NULL
- </select>
-
- <sql id="dashboardColumns">
- d.id, d.user_id as "userId", d.name, d.description, d.column_layout as "columnLayout",
- d.shared, d.created_at as "createdAt", d.updated_at as "updatedAt"
- </sql>
-
- <select id="selectGlobalDashboardsForUserLogin" parameterType="String" resultType="Dashboard">
- SELECT
- <include refid="dashboardColumns"/>
- FROM dashboards d
- INNER JOIN active_dashboards ad on d.id=ad.dashboard_id
- LEFT OUTER JOIN users u on u.id=ad.user_id
- <where>
- <choose>
- <when test="login == null">
- AND u.login IS NULL
- </when>
- <otherwise>
- AND u.login=#{login}
- </otherwise>
- </choose>
- </where>
- ORDER BY order_index ASC
- </select>
-
- <select id="selectProjectDashboardsForUserLogin" parameterType="String" resultType="Dashboard">
- SELECT
- <include refid="dashboardColumns"/>
- FROM dashboards d
- INNER JOIN active_dashboards ad on d.id=ad.dashboard_id
- LEFT OUTER JOIN users u on u.id=ad.user_id
- <where>
- <choose>
- <when test="login == null">
- AND u.login IS NULL
- </when>
- <otherwise>
- AND u.login=#{login}
- </otherwise>
- </choose>
- </where>
- ORDER BY order_index ASC
- </select>
-
-</mapper>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-
-<mapper namespace="org.sonar.db.dashboard.DashboardMapper">
-
-</mapper>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-
-<mapper namespace="org.sonar.db.dashboard.WidgetMapper">
-
- <sql id="selectColumns">
- w.id as "id",
- w.dashboard_id as "dashboardId",
- w.widget_key as "widgetKey",
- w.name as "name",
- w.description as "description",
- w.column_index as "columnIndex",
- w.row_index as "rowIndex",
- w.configured as "configured",
- w.created_at as "createdAt",
- w.updated_at as "updatedAt",
- w.resource_id as "resourceId"
- </sql>
-
- <select id="selectById" parameterType="Long" resultType="Widget">
- select
- <include refid="selectColumns"/>
- from widgets w where w.id=#{id}
- </select>
-
- <select id="selectByDashboard" parameterType="Long" resultType="Widget">
- select
- <include refid="selectColumns"/>
- from widgets w where w.dashboard_id=#{id}
- </select>
-
- <select id="selectAll" resultType="Widget">
- select
- <include refid="selectColumns"/>
- from widgets w
- </select>
-
-</mapper>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-
-<mapper namespace="org.sonar.db.dashboard.WidgetPropertyMapper">
-
- <delete id="deleteByWidgetIds" parameterType="map">
- DELETE FROM widget_properties
- WHERE widget_id IN
- <foreach collection="list" open="(" close=")" item="wid" separator=",">#{wid}</foreach>
- </delete>
-
-</mapper>
DELETE FROM properties WHERE user_id=#{id}
</delete>
- <delete id="deleteUnsharedUserDashboards" parameterType="long">
- DELETE FROM dashboards WHERE user_id=#{id} and shared <> ${_true}
- </delete>
-
- <delete id="deleteUserActiveDashboards" parameterType="long">
- DELETE FROM active_dashboards WHERE user_id=#{id}
- </delete>
-
<delete id="deleteUnsharedUserMeasureFilters" parameterType="long">
DELETE FROM measure_filters WHERE user_id=#{id} and shared <> ${_true}
</delete>
public void verify_count_of_added_components() {
ComponentContainer container = new ComponentContainer();
new DaoModule().configure(container);
- assertThat(container.size()).isEqualTo(2 + 52);
+ assertThat(container.size()).isEqualTo(2 + 48);
}
}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.db.dashboard;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.utils.System2;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-
-public class ActiveDashboardDaoTest {
-
- @Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
-
- DbSession session = dbTester.getSession();
-
- ActiveDashboardDao underTest = dbTester.getDbClient().activeDashboardDao();
-
- @Test
- public void shouldInsert() {
- dbTester.prepareDbUnit(getClass(), "shouldInsert.xml");
-
- ActiveDashboardDto dashboard = new ActiveDashboardDto();
- dashboard.setDashboardId(2L);
- dashboard.setUserId(3L);
- dashboard.setOrderIndex(4);
- underTest.insert(dashboard);
-
- dbTester.assertDbUnit(getClass(), "shouldInsert-result.xml", "active_dashboards");
- }
-
- @Test
- public void shouldInsertWithNoUser() {
- dbTester.prepareDbUnit(getClass(), "shouldInsert.xml");
-
- ActiveDashboardDto dashboard = new ActiveDashboardDto();
- dashboard.setDashboardId(2L);
- dashboard.setOrderIndex(4);
- underTest.insert(dashboard);
-
- dbTester.assertDbUnit(getClass(), "shouldInsertWithNoUser-result.xml", "active_dashboards");
- }
-
- @Test
- public void shouldGetMaxOrderIndexForNullUser() {
- dbTester.prepareDbUnit(getClass(), "shouldGetMaxOrderIndexForNullUser.xml");
-
- int index = underTest.selectMaxOrderIndexForNullUser();
-
- assertThat(index).isEqualTo(15);
- }
-
- @Test
- public void shouldGetZeroMaxOrderIndex() {
- dbTester.prepareDbUnit(getClass(), "empty.xml");
-
- int index = underTest.selectMaxOrderIndexForNullUser();
-
- assertThat(index).isZero();
- }
-
- @Test
- public void should_get_dashboards_for_anonymous() {
- dbTester.prepareDbUnit(getClass(), "shouldSelectDashboardsForAnonymous.xml");
-
- assertThat(underTest.selectGlobalDashboardsForUserLogin(null)).hasSize(2).extracting("id").containsExactly(2L, 1L);
- }
-
- @Test
- public void should_get_dashboards_for_user() {
- dbTester.prepareDbUnit(getClass(), "shouldSelectDashboardsForUser.xml");
-
- assertThat(underTest.selectGlobalDashboardsForUserLogin("obiwan")).hasSize(2).extracting("id").containsExactly(2L, 1L);
- }
-
- @Test
- public void select_by_id() throws Exception {
- ActiveDashboardDto dto = new ActiveDashboardDto()
- .setDashboardId(10L)
- .setOrderIndex(2)
- .setUserId(5L);
- underTest.insert(session, dto);
- session.commit();
-
- ActiveDashboardDto dtoReloaded = underTest.selectById(session, dto.getId());
- assertThat(dtoReloaded).isNotNull();
- assertThat(dtoReloaded.getDashboardId()).isEqualTo(10L);
- assertThat(dtoReloaded.getUserId()).isEqualTo(5L);
- assertThat(dtoReloaded.getOrderIndex()).isEqualTo(2);
-
- assertThat(underTest.selectById(session, 123L)).isNull();
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.db.dashboard;
-
-import java.util.Date;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.utils.System2;
-import org.sonar.db.DbTester;
-
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
-
-
-public class DashboardDaoTest {
-
- @Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
-
- DashboardDao underTest = dbTester.getDbClient().dashboardDao();
-
- @Test
- public void shouldSelectGlobalDashboard() {
- dbTester.prepareDbUnit(getClass(), "shouldSelectGlobalDashboard.xml");
- DashboardDto dashboard = underTest.selectGlobalDashboard("SQALE");
- assertThat(dashboard.getId(), is(2L));
- assertThat(dashboard.getUserId(), nullValue());
-
- assertNull(underTest.selectGlobalDashboard("unknown"));
- }
-
- @Test
- public void shouldInsert() {
- dbTester.prepareDbUnit(getClass(), "shouldInsert.xml");
- Date aDate = new Date();
-
- DashboardDto dashboardDto = new DashboardDto();
- dashboardDto.setUserId(6L);
- dashboardDto.setName("My Dashboard");
- dashboardDto.setDescription("This is a dashboard");
- dashboardDto.setColumnLayout("100%");
- dashboardDto.setShared(true);
- dashboardDto.setCreatedAt(aDate);
- dashboardDto.setUpdatedAt(aDate);
-
- WidgetDto widgetDto = new WidgetDto();
- widgetDto.setWidgetKey("code_coverage");
- widgetDto.setName("Code coverage");
- widgetDto.setDescription("Widget for code coverage");
- widgetDto.setColumnIndex(13);
- widgetDto.setRowIndex(14);
- widgetDto.setConfigured(true);
- widgetDto.setCreatedAt(aDate);
- widgetDto.setUpdatedAt(aDate);
- dashboardDto.addWidget(widgetDto);
-
- WidgetPropertyDto property = new WidgetPropertyDto();
- property.setPropertyKey("displayITs");
- property.setTextValue("true");
- widgetDto.addWidgetProperty(property);
-
- underTest.insert(dashboardDto);
-
- dbTester.assertDbUnit(getClass(), "shouldInsert-result.xml", new String[] {"created_at", "updated_at"}, "dashboards", "widgets", "widget_properties");
- }
-
- @Test
- public void shouldInsertWithNullableColumns() {
- dbTester.prepareDbUnit(getClass(), "shouldInsert.xml");
-
- DashboardDto dashboardDto = new DashboardDto();
- dashboardDto.setUserId(null);
- dashboardDto.setName(null);
- dashboardDto.setDescription(null);
- dashboardDto.setColumnLayout(null);
- dashboardDto.setShared(true);
- dashboardDto.setCreatedAt(null);
- dashboardDto.setUpdatedAt(null);
-
- WidgetDto widgetDto = new WidgetDto();
- widgetDto.setWidgetKey("code_coverage");
- widgetDto.setName(null);
- widgetDto.setDescription(null);
- widgetDto.setColumnIndex(null);
- widgetDto.setRowIndex(null);
- widgetDto.setConfigured(true);
- widgetDto.setCreatedAt(null);
- widgetDto.setUpdatedAt(null);
- dashboardDto.addWidget(widgetDto);
-
- WidgetPropertyDto property = new WidgetPropertyDto();
- property.setPropertyKey(null);
- property.setTextValue(null);
- widgetDto.addWidgetProperty(property);
-
- underTest.insert(dashboardDto);
-
- dbTester.assertDbUnit(getClass(), "shouldInsertWithNullableColumns-result.xml", "dashboards", "widgets", "widget_properties");
- }
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.db.dashboard;
-
-import java.util.Collection;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.utils.System2;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class WidgetDaoTest {
-
- @Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
- DbSession dbSession = db.getSession();
-
- WidgetDao underTest = db.getDbClient().widgetDao();
-
- @Test
- public void should_select_all() {
- db.prepareDbUnit(this.getClass(), "before.xml");
-
- Collection<WidgetDto> widgets = underTest.findAll(db.getSession());
- assertThat(widgets).hasSize(5);
- for (WidgetDto widget : widgets) {
- assertThat(widget.getId()).isNotNull();
- assertThat(widget.getName()).isNotNull();
- assertThat(widget.getDescription()).isNotNull();
- }
- }
-
- @Test
- public void select_by_dashboard_key() {
- db.prepareDbUnit(this.getClass(), "before.xml");
-
- Collection<WidgetDto> result = underTest.findByDashboard(dbSession, 1L);
-
- assertThat(result).hasSize(5);
- }
-
- @Test
- public void select_by_key() {
- db.prepareDbUnit(this.getClass(), "before.xml");
-
- WidgetDto result = underTest.selectByKey(dbSession, 1L);
-
- assertThat(result).isNotNull();
- }
-}
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.RowNotFoundException;
-import org.sonar.db.dashboard.ActiveDashboardDto;
-import org.sonar.db.dashboard.DashboardDto;
import org.sonar.db.issue.IssueFilterDto;
import org.sonar.db.issue.IssueFilterFavouriteDto;
import org.sonar.db.measure.MeasureFilterDto;
import org.sonar.db.measure.MeasureFilterFavouriteDto;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.permission.UserPermissionDto;
import org.sonar.db.property.PropertyDto;
import org.sonar.db.property.PropertyQuery;
@Test
public void deactivate_user() throws Exception {
UserDto user = newActiveUser();
- DashboardDto dashboard = insertDashboard(user, false);
- ActiveDashboardDto activeDashboard = insertActiveDashboard(dashboard, user);
IssueFilterDto issueFilter = insertIssueFilter(user, false);
IssueFilterFavouriteDto issueFilterFavourite = insertIssueFilterFavourite(issueFilter, user);
MeasureFilterDto measureFilter = insertMeasureFilter(user, false);
assertThat(underTest.selectUserById(session, otherUser.getId())).isNotNull();
- assertThat(dbClient.dashboardDao().selectById(session, dashboard.getId())).isNull();
- assertThat(dbClient.activeDashboardDao().selectById(session, activeDashboard.getId())).isNull();
assertThat(dbClient.issueFilterDao().selectById(session, issueFilter.getId())).isNull();
assertThat(dbClient.issueFilterFavouriteDao().selectById(session, issueFilterFavourite.getId())).isNull();
assertThat(dbClient.measureFilterDao().selectById(session, measureFilter.getId())).isNull();
assertThat(dbClient.groupMembershipDao().countGroups(session, builder().login(user.getLogin()).membership(IN).build(), user.getId())).isZero();
}
- @Test
- public void deactivate_user_does_not_remove_shared_dashboard() throws Exception {
- UserDto user = newActiveUser();
- DashboardDto notSharedDashboard = insertDashboard(user, false);
- DashboardDto sharedDashboard = insertDashboard(user, true);
- session.commit();
-
- boolean deactivated = underTest.deactivateUserByLogin(session, user.getLogin());
- assertThat(deactivated).isTrue();
-
- assertThat(dbClient.dashboardDao().selectById(session, notSharedDashboard.getId())).isNull();
- DashboardDto sharedDashboardReloaded = dbClient.dashboardDao().selectById(session, sharedDashboard.getId());
- assertThat(sharedDashboardReloaded).isNotNull();
- assertThat(sharedDashboardReloaded.getUserId()).isEqualTo(user.getId());
- }
-
@Test
public void deactivate_user_does_not_remove_shared_issue_filter() throws Exception {
UserDto user = newActiveUser();
return dto;
}
- private DashboardDto insertDashboard(UserDto user, boolean shared) {
- DashboardDto dto = new DashboardDto().setUserId(user.getId()).setShared(shared);
- dbClient.dashboardDao().insert(session, dto);
- return dto;
- }
-
- private ActiveDashboardDto insertActiveDashboard(DashboardDto dashboard, UserDto user) {
- ActiveDashboardDto dto = new ActiveDashboardDto().setDashboardId(dashboard.getId()).setUserId(user.getId());
- dbClient.activeDashboardDao().insert(session, dto);
- return dto;
- }
-
private IssueFilterDto insertIssueFilter(UserDto user, boolean shared) {
IssueFilterDto dto = new IssueFilterDto().setUserLogin(user.getLogin()).setName(randomAlphanumeric(100)).setShared(shared);
dbClient.issueFilterDao().insert(session, dto);
+++ /dev/null
-<dataset>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <active_dashboards
- id="1"
- dashboard_id="1"
- user_id="[null]"
- order_index="1"/>
-
- <active_dashboards
- id="2"
- dashboard_id="2"
- user_id="[null]"
- order_index="15"/>
-
- <active_dashboards
- id="3"
- dashboard_id="3"
- user_id="3"
- order_index="25"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <active_dashboards
- id="1"
- dashboard_id="2"
- user_id="3"
- order_index="4"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <active_dashboards
- id="1"
- dashboard_id="2"
- user_id="[null]"
- order_index="4"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <users id="42"
- login="obiwan"
- name="Obiwan"
- email="obiwan@keno.bi"
- created_at="1418215735482"
- updated_at="1418215735482"
- active="[true]"
- is_root="[false]"/>
-
- <dashboards
- id="1"
- user_id="1"
- name="My Dashboard"
- description="Dashboard shared by admin"
- column_layout="100%"
- shared="[true]"
- />
- <dashboards
- id="2"
- user_id="[null]"
- name="Default Dashboard"
- description="Dashboard provided by system"
- column_layout="100%"
- shared="[true]"
- />
- <dashboards
- id="4"
- user_id="[null]"
- name="User Dashboard"
- description="Won't appear, not anonymous"
- column_layout="100%"
- shared="[true]"
- />
-
- <!-- Dashboard with ID 1 appears after ID 2 -->
- <active_dashboards
- id="1"
- dashboard_id="1"
- user_id="[null]"
- order_index="2"/>
- <!-- Dashboard with ID 2 appears before ID 1 -->
- <active_dashboards
- id="2"
- dashboard_id="2"
- user_id="[null]"
- order_index="1"/>
- <!-- Dashboard with ID 4 does not appear (not anonymous) -->
- <active_dashboards
- id="4"
- dashboard_id="4"
- user_id="42"
- order_index="1"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <users id="24"
- login="anakin"
- name="Anakin"
- email="anakin@skywalk.er"
- created_at="1418215735482"
- updated_at="1418215735482"
- active="[true]"
- is_root="[false]"/>
- <users id="42"
- login="obiwan"
- name="Obiwan"
- email="obiwan@keno.bi"
- created_at="1418215735482"
- updated_at="1418215735482"
- active="[true]"
- is_root="[false]"/>
-
- <dashboards
- id="1"
- user_id="1"
- name="My Dashboard"
- description="Dashboard shared by admin"
- column_layout="100%"
- shared="[true]"
- />
- <dashboards
- id="2"
- user_id="[null]"
- name="Default Dashboard"
- description="Dashboard provided by system"
- column_layout="100%"
- shared="[true]"
- />
- <dashboards
- id="4"
- user_id="[null]"
- name="Anonymous Dashboard"
- description="Won't appear, anonymous"
- column_layout="100%"
- shared="[true]"
- />
- <dashboards
- id="5"
- user_id="[null]"
- name="Another User Dashboard"
- description="Won't appear, different user"
- column_layout="100%"
- shared="[true]"
- />
-
- <!-- Dashboard with ID 1 appears after ID 2 -->
- <active_dashboards
- id="1"
- dashboard_id="1"
- user_id="42"
- order_index="2"/>
- <!-- Dashboard with ID 2 appears before ID 1 -->
- <active_dashboards
- id="2"
- dashboard_id="2"
- user_id="42"
- order_index="1"/>
- <!-- Dashboard with ID 4 does not appear (anonymous) -->
- <active_dashboards
- id="4"
- dashboard_id="4"
- user_id="[null]"
- order_index="1"/>
- <!-- Dashboard with ID 5 does not appear (another user) -->
- <active_dashboards
- id="5"
- dashboard_id="5"
- user_id="24"
- order_index="1"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <dashboards
- id="1"
- user_id="6"
- name="My Dashboard"
- description="This is a dashboard"
- column_layout="100%"
- shared="[true]"
- />
-
- <widgets
- id="1"
- dashboard_id="1"
- widget_key="code_coverage"
- name="Code coverage"
- description="Widget for code coverage"
- column_index="13"
- row_index="14"
- configured="[true]"
- resource_id="[null]"
- />
-
- <widget_properties
- id="1"
- widget_id="1"
- kee="displayITs"
- text_value="true"
- />
-
-</dataset>
+++ /dev/null
-<dataset>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <dashboards
- id="1"
- user_id="[null]"
- name="[null]"
- description="[null]"
- column_layout="[null]"
- shared="[true]"
- created_at="[null]"
- updated_at="[null]"
- />
-
- <widgets
- id="1"
- dashboard_id="1"
- widget_key="code_coverage"
- name="[null]"
- description="[null]"
- column_index="[null]"
- row_index="[null]"
- configured="[true]"
- created_at="[null]"
- updated_at="[null]"
- resource_id="[null]"
- />
-
- <widget_properties
- id="1"
- widget_id="1"
- kee="[null]"
- text_value="[null]"
- />
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <dashboards
- id="1"
- user_id="6"
- name="SQALE"
- description="User SQALE dashboard"
- column_layout="100%"
- shared="[true]"
- />
-
- <dashboards
- id="2"
- user_id="[null]"
- name="SQALE"
- description="Global SQALE dashboard"
- column_layout="100%"
- shared="[true]"
- />
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <widgets id="1" dashboard_id="1" widget_key="polop" name="Polop" description="Palap"
- column_index="1" row_index="1" configured="[true]" created_at="[null]" updated_at="[null]" resource_id="[null]"/>
-
- <widgets id="2" dashboard_id="1" widget_key="false_positive_reviews" name="Polop" description="Palap"
- column_index="1" row_index="2" configured="[true]" created_at="[null]" updated_at="[null]" resource_id="[null]"/>
-
- <widgets id="3" dashboard_id="1" widget_key="my_reviews" name="Polop" description="Palap"
- column_index="1" row_index="3" configured="[true]" created_at="[null]" updated_at="[null]" resource_id="[null]"/>
-
- <widgets id="4" dashboard_id="1" widget_key="reviews_per_developer" name="Polop" description="Palap"
- column_index="1" row_index="4" configured="[true]" created_at="[null]" updated_at="[null]" resource_id="[null]"/>
-
- <widgets id="5" dashboard_id="1" widget_key="unresolved_issues_statuses" name="Polop" description="Palap"
- column_index="1" row_index="5" configured="[true]" created_at="[null]" updated_at="[null]" resource_id="[null]"/>
-
-</dataset>