private Set<String> loadUserOrganizations(@Nullable UserDto assignee) { if (assignee == null) { return Collections.emptySet(); } try (DbSession dbSession = dbClient.openSession(false)) { return dbClient.organizationMemberDao().selectOrganizationUuidsByUser(dbSession, assignee.getId()); } }
/** * Load from database */ private static StartupMetadata load(DbClient dbClient) { try (DbSession dbSession = dbClient.openSession(false)) { String startedAt = selectProperty(dbClient, dbSession, SERVER_STARTTIME); return new StartupMetadata(DateUtils.parseDateTime(startedAt).getTime()); } }
@Override public void handle(Request request, Response response) throws Exception { String eventP = request.mandatoryParam(PARAM_EVENT); try (DbSession dbSession = dbClient.openSession(false)) { Stream.of(getEvent(dbSession, eventP)) .peek(checkPermissions()) .peek(checkModifiable()) .forEach(event -> deleteEvent(dbSession, event)); } response.noContent(); }
@Override public void indexOnStartup(Set<IndexType> uninitializedIndexTypes) { try (DbSession dbSession = dbClient.openSession(false)) { Map<String, String> viewAndProjectViewUuidMap = newHashMap(); for (UuidWithProjectUuidDto uuidWithProjectUuidDto : dbClient.componentDao().selectAllViewsAndSubViews(dbSession)) { viewAndProjectViewUuidMap.put(uuidWithProjectUuidDto.getUuid(), uuidWithProjectUuidDto.getProjectUuid()); } index(dbSession, viewAndProjectViewUuidMap, false, Size.LARGE); } }
@Override public void write(String propertyKey, @Nullable String value) { checkPropertyKey(propertyKey); try (DbSession dbSession = dbClient.openSession(false)) { if (value == null || value.isEmpty()) { dbClient.internalPropertiesDao().saveAsEmpty(dbSession, propertyKey); } else { dbClient.internalPropertiesDao().save(dbSession, propertyKey, value); } dbSession.commit(); } }
@Before public void setUp() throws Exception { when(dbClient.openSession(false)).thenReturn(dbSession); when(dbClient.internalPropertiesDao()).thenReturn(internalPropertiesDao); }
private void doHandle(JsonWriter json, Request request) { try (DbSession dbSession = dbClient.openSession(true)) { Optional<ComponentDto> component = loadComponent(dbSession, request); String key = request.param(PARAM_ID); List<PropertyDto> propertyDtos = loadProperties(dbSession, component, Optional.ofNullable(key)); new ResponseBuilder(propertyDtos).build(json); } }
@Override public Metric findById(int id) { try (DbSession session = dbClient.openSession(false)) { MetricDto dto = dbClient.metricDao().selectById(session, id); if (dto != null && dto.isEnabled()) { return ToMetric.INSTANCE.apply(dto); } return null; } }
private void assertThatEsTableContainsOnly(EsQueueDto... expected) { try (DbSession otherSession = db.getDbClient().openSession(false)) { List<String> uuidsInDb = db.getDbClient().esQueueDao().selectForRecovery(otherSession, Long.MAX_VALUE, 10) .stream().map(EsQueueDto::getUuid).collect(toList()); String expectedUuids[] = Arrays.stream(expected).map(EsQueueDto::getUuid).toArray(String[]::new); assertThat(uuidsInDb).containsExactlyInAnyOrder(expectedUuids); } } }
@Before public void setUp() throws Exception { when(dbClient.openSession(anyBoolean())).thenReturn(dbSession); when(dbClient.ruleDao()).thenReturn(ruleDao); when(ruleDao.selectAll(any(DbSession.class), eq(ORGANIZATION_UUID))).thenReturn(ImmutableList.of(AB_RULE)); DeprecatedRuleKeyDto abDeprecatedRuleKey1 = deprecatedRuleKeyOf(AB_RULE, AB_RULE_DEPRECATED_KEY_1); DeprecatedRuleKeyDto abDeprecatedRuleKey2 = deprecatedRuleKeyOf(AB_RULE, AB_RULE_DEPRECATED_KEY_2); DeprecatedRuleKeyDto deprecatedRuleOfNonExistingRule = deprecatedRuleKeyOf(77777, DEPRECATED_KEY_OF_NON_EXITING_RULE); when(ruleDao.selectAllDeprecatedRuleKeys(any(DbSession.class))).thenReturn(ImmutableSet.of( abDeprecatedRuleKey1, abDeprecatedRuleKey2, deprecatedRuleOfNonExistingRule)); }
@Override public void handle(Request request, Response response) throws Exception { long id = request.mandatoryParamAsLong(PARAM_ID); try (DbSession dbSession = dbClient.openSession(false)) { CustomMeasureDto customMeasure = dbClient.customMeasureDao().selectById(dbSession, id); checkArgument(customMeasure != null, "Custom measure with id '%s' does not exist", id); checkPermission(dbSession, customMeasure); dbClient.customMeasureDao().delete(dbSession, id); dbSession.commit(); } response.noContent(); }
private SearchResponseData setTags(String issueKey, List<String> tags) { userSession.checkLoggedIn(); try (DbSession session = dbClient.openSession(false)) { IssueDto issueDto = issueFinder.getByKey(session, issueKey); DefaultIssue issue = issueDto.toDefaultIssue(); IssueChangeContext context = IssueChangeContext.createUser(new Date(), userSession.getUuid()); if (issueFieldsSetter.setTags(issue, tags, context)) { return issueUpdater.saveIssueAndPreloadSearchResponseData(session, issue, context, null, false); } return new SearchResponseData(issueDto); } }
@Override public void handle(Request request, Response response) throws Exception { userSession.checkLoggedIn(); String issueKey = request.mandatoryParam(PARAM_ISSUE); RuleType ruleType = RuleType.valueOf(request.mandatoryParam(PARAM_TYPE)); try (DbSession session = dbClient.openSession(false)) { SearchResponseData preloadedSearchResponseData = setType(session, issueKey, ruleType); responseWriter.write(issueKey, preloadedSearchResponseData, request, response); } }
@Override public void handle(Request request, Response response) { try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganization(dbSession, request); QualityGateDto defaultQualityGate = finder.getDefault(dbSession, organization); Collection<QualityGateDto> qualityGates = dbClient.qualityGateDao().selectAll(dbSession, organization); writeProtobuf(buildResponse(organization, qualityGates, defaultQualityGate), request, response); } }
private void execute(Component root) { try (DbSession dbSession = dbClient.openSession(true)) { IdUuidPair idUuidPair = new IdUuidPair(dbIdsRepository.getComponentId(root), root.getUuid()); projectCleaner.purge(dbSession, idUuidPair, configRepository.getConfiguration(), disabledComponentsHolder.getUuids()); dbSession.commit(); } }
public void enable(String login) { String defaultOrganizationUuid = defaultOrganizationProvider.get().getUuid(); try (DbSession dbSession = dbClient.openSession(false)) { if (!organizationFlags.isEnabled(dbSession)) { flagAdminUserAsRoot(dbSession, login); createDefaultMembersGroup(dbSession, defaultOrganizationUuid); List<Integer> disabledTemplateAndCustomRuleIds = disableTemplateRulesAndCustomRules(dbSession); enableFeature(dbSession); ruleIndexer.commitAndIndex(dbSession, disabledTemplateAndCustomRuleIds); } } }
@Override public void execute(ComputationStep.Context context) { boolean supportUpsert = dbClient.getDatabase().getDialect().supportsUpsert(); try (DbSession dbSession = dbClient.openSession(supportUpsert)) { Component root = treeRootHolder.getRoot(); MeasureVisitor visitor = new MeasureVisitor(dbSession, supportUpsert); new DepthTraversalTypeAwareCrawler(visitor).visit(root); context.getStatistics().add("insertsOrUpdates", visitor.insertsOrUpdates); } }
private void doHandle(String id) { try (DbSession dbSession = dbClient.openSession(false)) { ProjectLinkDto link = dbClient.projectLinkDao().selectByUuid(dbSession, id); link = WsUtils.checkFound(link, "Link with id '%s' not found", id); checkProjectAdminPermission(link); checkNotProvided(link); dbClient.projectLinkDao().delete(dbSession, link.getUuid()); dbSession.commit(); } }
private CreateTemplateWsResponse doHandle(CreateTemplateRequest request) { try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto org = wsSupport.findOrganization(dbSession, request.getOrganization()); checkGlobalAdmin(userSession, org.getUuid()); validateTemplateNameForCreation(dbSession, org, request.getName()); RequestValidator.validateProjectPattern(request.getProjectKeyPattern()); PermissionTemplateDto permissionTemplate = insertTemplate(dbSession, org, request); return buildResponse(permissionTemplate); } }
@Override public void handle(Request request, Response response) throws Exception { try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganizationByKey(dbSession, request.param(PARAM_ORGANIZATION)); QProfileDto profile = wsSupport.getProfile(dbSession, organization, request.mandatoryParam(PARAM_QUALITY_PROFILE), request.mandatoryParam(PARAM_LANGUAGE)); wsSupport.checkCanEdit(dbSession, organization, profile); UserDto user = wsSupport.getUser(dbSession, organization, request.mandatoryParam(PARAM_LOGIN)); addUser(dbSession, profile, user); } response.noContent(); }