private void appendComponent( JsonWriter json, ComponentDto component, UserSession userSession, DbSession session) { List<PropertyDto> propertyDtos = dbClient .propertiesDao() .selectByQuery( PropertyQuery.builder() .setKey("favourite") .setComponentId(component.getId()) .setUserId(userSession.getUserId()) .build(), session); boolean isFavourite = propertyDtos.size() == 1; json.prop("key", component.key()); json.prop("uuid", component.uuid()); json.prop("path", component.path()); json.prop("name", component.name()); json.prop("longName", component.longName()); json.prop("q", component.qualifier()); ComponentDto parentProject = retrieveRootIfNotCurrentComponent(component, session); ComponentDto project = dbClient.componentDao().selectOrFailByUuid(session, component.projectUuid()); // Do not display parent project if parent project and project are the same boolean displayParentProject = parentProject != null && !parentProject.uuid().equals(project.uuid()); json.prop("subProject", displayParentProject ? parentProject.key() : null); json.prop("subProjectName", displayParentProject ? parentProject.longName() : null); json.prop("project", project.key()); json.prop("projectName", project.longName()); json.prop("fav", isFavourite); }
private void addCurrentUserToGroup(DbSession dbSession, GroupDto group) { dbClient .userGroupDao() .insert( dbSession, new UserGroupDto() .setGroupId(group.getId()) .setUserId(userSession.getUserId().longValue())); }
@Override public void handle(Request request, Response response) { String query = request.mandatoryParam(Param.TEXT_QUERY); if (query.length() < MINIMUM_SEARCH_CHARACTERS) { throw new IllegalArgumentException( String.format("Minimum search is %s characters", MINIMUM_SEARCH_CHARACTERS)); } String componentUuid = request.mandatoryParam(PARAM_COMPONENT_UUID); JsonWriter json = response.newJsonWriter(); json.beginObject(); DbSession session = dbClient.openSession(false); try { ComponentDto componentDto = componentFinder.getByUuid(session, componentUuid); userSession.checkProjectUuidPermission(UserRole.USER, componentDto.projectUuid()); Set<Long> projectIds = newLinkedHashSet( dbClient .componentIndexDao() .selectProjectIdsFromQueryAndViewOrSubViewUuid( session, query, componentDto.uuid())); Collection<Long> authorizedProjectIds = dbClient .authorizationDao() .keepAuthorizedProjectIds( session, projectIds, userSession.getUserId(), UserRole.USER); SearchOptions options = new SearchOptions(); options.setPage(request.mandatoryParamAsInt(PAGE), request.mandatoryParamAsInt(PAGE_SIZE)); Set<Long> pagedProjectIds = pagedProjectIds(authorizedProjectIds, options); List<ComponentDto> projects = dbClient.componentDao().selectByIds(session, pagedProjectIds); options.writeJson(json, authorizedProjectIds.size()); json.name("components").beginArray(); for (ComponentDto project : projects) { json.beginObject(); json.prop("uuid", project.uuid()); json.prop("name", project.name()); json.endObject(); } json.endArray(); } finally { MyBatis.closeQuietly(session); } json.endObject(); json.close(); }
@Override public void handle(Request request, Response response) throws Exception { DbSession dbSession = dbClient.openSession(false); try { Integer userId = userSession.getUserId(); DashboardDto dashboard = dbClient .dashboardDao() .selectAllowedByKey( dbSession, request.mandatoryParamAsLong(PARAM_KEY), userId != null ? userId.longValue() : null); if (dashboard == null) { throw new NotFoundException(); } JsonWriter json = response.newJsonWriter(); json.beginObject(); json.prop("key", dashboard.getKey()); json.prop("name", dashboard.getName()); json.prop("layout", dashboard.getColumnLayout()); json.prop("desc", dashboard.getDescription()); json.prop("global", dashboard.getGlobal()); json.prop("shared", dashboard.getShared()); if (dashboard.getUserId() != null) { UserDto user = dbClient.userDao().selectUserById(dashboard.getUserId()); if (user != null) { json.name("owner").beginObject(); // TODO to be shared and extracted from here json.prop("login", user.getLogin()); json.prop("name", user.getName()); json.endObject(); } } // load widgets and related properties json.name("widgets").beginArray(); Collection<WidgetDto> widgets = dbClient.widgetDao().findByDashboard(dbSession, dashboard.getKey()); ListMultimap<Long, WidgetPropertyDto> propertiesByWidget = WidgetPropertyDto.groupByWidgetId( dbClient.widgetPropertyDao().selectByDashboard(dbSession, dashboard.getKey())); for (WidgetDto widget : widgets) { json.beginObject(); json.prop("id", widget.getId()); json.prop("key", widget.getWidgetKey()); json.prop("name", widget.getName()); json.prop("desc", widget.getDescription()); json.prop("col", widget.getColumnIndex()); json.prop("row", widget.getRowIndex()); json.prop("configured", widget.getConfigured()); json.prop("componentId", widget.getResourceId()); json.name("props").beginArray(); for (WidgetPropertyDto prop : propertiesByWidget.get(widget.getId())) { json.beginObject(); json.prop("key", prop.getPropertyKey()); json.prop("val", prop.getTextValue()); json.endObject(); } json.endArray().endObject(); } json.endArray(); json.endObject(); json.close(); } finally { dbSession.close(); } }