private Optional<SnapshotDto> findFirstSnapshot(DbSession session, SnapshotQuery query) { return dbClient.snapshotDao().selectAnalysesByQuery(session, query) .stream() .findFirst(); }
private Map<String, SnapshotDto> getSnapshots(DbSession dbSession, SearchProjectsRequest request, List<String> projectUuids) { if (request.getAdditionalFields().contains(ANALYSIS_DATE) || request.getAdditionalFields().contains(LEAK_PERIOD_DATE)) { return dbClient.snapshotDao().selectLastAnalysesByRootComponentUuids(dbSession, projectUuids) .stream() .collect(MoreCollectors.uniqueIndex(SnapshotDto::getComponentUuid)); } return emptyMap(); }
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)))); } } }
public SnapshotDto insertSnapshot(SnapshotDto snapshotDto) { SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, snapshotDto); db.commit(); return snapshot; }
private void verifyAnalysis(String uuid, String expectedStatus, boolean expectedLastFlag) { Optional<SnapshotDto> analysis = db.getDbClient().snapshotDao().selectByUuid(db.getSession(), uuid); assertThat(analysis.get().getStatus()).isEqualTo(expectedStatus); assertThat(analysis.get().getLast()).isEqualTo(expectedLastFlag); }
private void assertDataInDb(DbData data, boolean exists) { assertThat(dbClient.componentDao().selectByUuid(dbSession, data.project.uuid()).isPresent()).isEqualTo(exists); assertThat(dbClient.snapshotDao().selectByUuid(dbSession, data.snapshot.getUuid()).isPresent()).isEqualTo(exists); assertThat(dbClient.issueDao().selectByKey(dbSession, data.issue.getKey()).isPresent()).isEqualTo(exists); }
private SnapshotDto getUnprocessedSnapshot(String componentUuid) { List<SnapshotDto> projectSnapshots = dbClient.snapshotDao().selectAnalysesByQuery(dbTester.getSession(), new SnapshotQuery().setComponentUuid(componentUuid).setIsLast(false).setStatus(SnapshotDto.STATUS_UNPROCESSED)); assertThat(projectSnapshots).hasSize(1); return projectSnapshots.get(0); }
private SnapshotDto getUnprocessedSnapshot(String componentUuid) { List<SnapshotDto> projectSnapshots = dbClient.snapshotDao().selectAnalysesByQuery(dbTester.getSession(), new SnapshotQuery().setComponentUuid(componentUuid).setIsLast(false).setStatus(SnapshotDto.STATUS_UNPROCESSED)); assertThat(projectSnapshots).hasSize(1); return projectSnapshots.get(0); }
private SnapshotDto createProjectSnapshot(ComponentDto project) { SnapshotDto projectSnapshot = SnapshotTesting.newAnalysis(project); dbClient.snapshotDao().insert(dbSession, projectSnapshot); dbSession.commit(); return projectSnapshot; }
private Consumer<EventDto> updateInDb(DbSession dbSession) { return event -> { dbClient.eventDao().update(dbSession, event.getUuid(), event.getName(), event.getDescription()); if (VERSION.getLabel().equals(event.getCategory())) { SnapshotDto analysis = getAnalysis(dbSession, event); analysis.setVersion(event.getName()); dbClient.snapshotDao().update(dbSession, analysis); } dbSession.commit(); }; }
private EventDto insertDbEvent(DbSession dbSession, CreateEventRequest request, SnapshotDto analysis) { EventDto dbEvent = dbClient.eventDao().insert(dbSession, toDbEvent(request, analysis)); if (VERSION.equals(request.getCategory())) { analysis.setVersion(request.getName()); dbClient.snapshotDao().update(dbSession, analysis); } dbSession.commit(); return dbEvent; }
@Override public void execute(ComputationStep.Context context) { try (DbSession dbSession = dbClient.openSession(false)) { Component project = treeRootHolder.getRoot(); dbClient.snapshotDao().switchIsLastFlagAndSetProcessedStatus(dbSession, project.getUuid(), analysisMetadataHolder.getUuid()); dbClient.componentDao().applyBChangesForRootComponentUuid(dbSession, project.getUuid()); dbSession.commit(); } }
private SnapshotDto insertSnapshot(SnapshotDto snapshot) { dbClient.snapshotDao().insert(dbTester.getSession(), snapshot); dbTester.getSession().commit(); return snapshot; }
@Test public void do_not_return_unprocessed_analyses() { dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setStatus(STATUS_UNPROCESSED)); db.commit(); SearchHistoryResponse result = call(); // one analysis in setUp method assertThat(result.getPaging().getTotal()).isEqualTo(1); }
private SnapshotDto insertComponentAndSnapshot(ComponentDto component) { dbClient.componentDao().insert(dbSession, component); SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(component)); db.commit(); return snapshot; }
@Test public void update_VERSION_event_update_analysis_version() { SnapshotDto analysis = createAnalysisAndLogInAsProjectAdministrator("5.6"); db.events().insertEvent(newEvent(analysis).setUuid("E1").setCategory(VERSION.getLabel())); call("E1", "6.3"); SnapshotDto updatedAnalysis = dbClient.snapshotDao().selectByUuid(dbSession, analysis.getUuid()).get(); assertThat(updatedAnalysis.getVersion()).isEqualTo("6.3"); }
@Test public void return_project_without_analysis() { ComponentDto project = dbTester.components().insertComponent(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert())); dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setLast(false)); dbSession.commit(); Map<String, ProjectMeasures> docsById = createResultSetAndReturnDocsById(); assertThat(docsById).hasSize(1); ProjectMeasures doc = docsById.get(project.uuid()); assertThat(doc.getProject().getAnalysisDate()).isNull(); }
@Test public void delete_version_event() { ComponentDto project = db.components().insertPrivateProject(); SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project).setVersion("5.6.3").setLast(false)); db.events().insertEvent(newEvent(analysis).setUuid("E1").setCategory(VERSION.getLabel())); logInAsProjectAdministrator(project); call("E1"); SnapshotDto newAnalysis = dbClient.snapshotDao().selectByUuid(dbSession, analysis.getUuid()).get(); assertThat(newAnalysis.getVersion()).isNull(); }
@Test public void fail_if_project_is_not_found() { userSession.logIn(); SnapshotDto analysis = dbClient.snapshotDao().insert(dbSession, newSnapshot().setUuid("A1")); db.commit(); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Project of analysis 'A1' is not found"); call(VERSION.name(), "5.6.3", analysis.getUuid()); }
@Test public void not_fail_if_analysis_date_is_after_last_analysis() { ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert(), "ABCD").setDbKey(PROJECT_KEY); dbClient.componentDao().insert(dbTester.getSession(), project); dbClient.snapshotDao().insert(dbTester.getSession(), SnapshotTesting.newAnalysis(project).setCreatedAt(1420088400000L)); // 2015-01-01 dbTester.getSession().commit(); treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).build()); underTest.execute(new TestComputationStepContext()); }