private void validateAnalysisDate(Optional<ComponentDto> baseProject) { if (baseProject.isPresent()) { Optional<SnapshotDto> snapshotDto = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(session, baseProject.get().uuid()); long currentAnalysisDate = analysisMetadataHolder.getAnalysisDate(); Long lastAnalysisDate = snapshotDto.map(SnapshotDto::getCreatedAt).orElse(null); if (lastAnalysisDate != null && currentAnalysisDate <= lastAnalysisDate) { validationMessages.add(format("Date of analysis cannot be older than the date of the last known analysis on this project. Value: \"%s\". " + "Latest analysis: \"%s\". It's only possible to rebuild the past in a chronological order.", formatDateTime(new Date(currentAnalysisDate)), formatDateTime(new Date(lastAnalysisDate)))); } } }
private ProjectAndSnapshot getProjectThenSnapshot(DbSession dbSession, String projectId, String projectKey) { ComponentDto projectDto = componentFinder.getByUuidOrKey(dbSession, projectId, projectKey, ParamNames.PROJECT_ID_AND_KEY); Optional<SnapshotDto> snapshot = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, projectDto.projectUuid()); return new ProjectAndSnapshot(projectDto, snapshot.orElse(null)); }
@Test public void selectLastSnapshotByRootComponentUuid_returns_snapshot_flagged_as_last() { db.prepareDbUnit(getClass(), "snapshots.xml"); Optional<SnapshotDto> snapshot = underTest.selectLastAnalysisByRootComponentUuid(db.getSession(), "uuid_2"); assertThat(snapshot.get().getId()).isEqualTo(4L); }
@Test public void selectLastSnapshotByRootComponentUuid_returns_absent_when_no_last_snapshot() { Optional<SnapshotDto> snapshot = underTest.selectLastAnalysisByRootComponentUuid(db.getSession(), "uuid_123"); assertThat(snapshot).isNotPresent(); }
@Test public void selectLastSnapshotByRootComponentUuid_returns_absent_if_only_unprocessed_snapshots() { db.prepareDbUnit(getClass(), "snapshots.xml"); Optional<SnapshotDto> snapshot = underTest.selectLastAnalysisByRootComponentUuid(db.getSession(), "uuid_5"); assertThat(snapshot).isNotPresent(); }
private ComponentWsResponse doHandle(ComponentRequest request) { try (DbSession dbSession = dbClient.openSession(false)) { ComponentDto component = loadComponent(dbSession, request); Optional<ComponentDto> refComponent = getReferenceComponent(dbSession, component); checkPermissions(component); SnapshotDto analysis = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, component.projectUuid()).orElse(null); List<MetricDto> metrics = searchMetrics(dbSession, request); List<Measures.Period> periods = snapshotToWsPeriods(analysis); List<LiveMeasureDto> measures = searchMeasures(dbSession, component, metrics); return buildResponse(request, component, refComponent, measures, metrics, periods); } }
BranchDto branch = loadBranch(dbSession, project); Optional<SnapshotDto> lastAnalysis = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, project.uuid()); if (!lastAnalysis.isPresent()) { return Optional.empty();
ComponentDto baseComponent = loadComponent(dbSession, wsRequest); checkPermissions(baseComponent); Optional<SnapshotDto> baseSnapshot = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, baseComponent.projectUuid()); if (!baseSnapshot.isPresent()) { return ComponentTreeData.builder()
Optional<SnapshotDto> analysis = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(session, component.projectUuid());
private void validateAnalysisDate(Optional<ComponentDto> baseProject) { if (baseProject.isPresent()) { java.util.Optional<SnapshotDto> snapshotDto = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(session, baseProject.get().uuid()); long currentAnalysisDate = analysisMetadataHolder.getAnalysisDate(); Long lastAnalysisDate = snapshotDto.map(SnapshotDto::getCreatedAt).orElse(null); if (lastAnalysisDate != null && currentAnalysisDate <= lastAnalysisDate) { validationMessages.add(format("Date of analysis cannot be older than the date of the last known analysis on this project. Value: \"%s\". " + "Latest analysis: \"%s\". It's only possible to rebuild the past in a chronological order.", formatDateTime(new Date(currentAnalysisDate)), formatDateTime(new Date(lastAnalysisDate)))); } } }
private ProjectAndSnapshot getProjectThenSnapshot(DbSession dbSession, String projectId, String projectKey) { ComponentDto projectDto = componentFinder.getByUuidOrKey(dbSession, projectId, projectKey, ParamNames.PROJECT_ID_AND_KEY); Optional<SnapshotDto> snapshot = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, projectDto.projectUuid()); return new ProjectAndSnapshot(projectDto, snapshot.orElse(null)); }
private ComponentWsResponse doHandle(ComponentRequest request) { try (DbSession dbSession = dbClient.openSession(false)) { ComponentDto component = loadComponent(dbSession, request); Optional<ComponentDto> refComponent = getReferenceComponent(dbSession, component); checkPermissions(component); SnapshotDto analysis = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, component.projectUuid()).orElse(null); List<MetricDto> metrics = searchMetrics(dbSession, request); List<Measures.Period> periods = snapshotToWsPeriods(analysis); List<LiveMeasureDto> measures = searchMeasures(dbSession, component, metrics); return buildResponse(request, component, refComponent, measures, metrics, periods); } }
BranchDto branch = loadBranch(dbSession, project); Optional<SnapshotDto> lastAnalysis = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, project.uuid()); if (!lastAnalysis.isPresent()) { return Optional.empty();
ComponentDto baseComponent = loadComponent(dbSession, wsRequest); checkPermissions(baseComponent); Optional<SnapshotDto> baseSnapshot = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, baseComponent.projectUuid()); if (!baseSnapshot.isPresent()) { return ComponentTreeData.builder()
@Override public void handle(Request request, Response response) throws Exception { String componentKey = request.mandatoryParam(PARAM_COMPONENT); try (DbSession session = dbClient.openSession(false)) { String branch = request.param(PARAM_BRANCH); String pullRequest = request.param(PARAM_PULL_REQUEST); ComponentDto component = componentFinder.getByKeyAndOptionalBranchOrPullRequest(session, componentKey, branch, pullRequest); ComponentDto project = component.getMainBranchProjectUuid() == null ? component : componentFinder.getByUuid(session, component.getMainBranchProjectUuid()); if (!userSession.hasComponentPermission(USER, component) && !userSession.hasComponentPermission(ADMIN, component) && !userSession.isSystemAdministrator()) { throw insufficientPrivilegesException(); } OrganizationDto org = componentFinder.getOrganization(session, component); Optional<SnapshotDto> analysis = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(session, component.projectUuid()); JsonWriter json = response.newJsonWriter(); json.beginObject(); writeComponent(json, session, component, org, analysis.orElse(null)); writeProfiles(json, session, component); writeQualityGate(json, session, org, project); if (userSession.hasComponentPermission(ADMIN, component) || userSession.hasPermission(ADMINISTER_QUALITY_PROFILES, org) || userSession.hasPermission(ADMINISTER_QUALITY_GATES, org)) { writeConfiguration(json, component, org); } writeBreadCrumbs(json, session, component); json.endObject().close(); } }