@Override public void execute(ComputationStep.Context context) { List<AnalysisPropertyDto> analysisPropertyDtos = new ArrayList<>(); try (CloseableIterator<ScannerReport.ContextProperty> it = reportReader.readContextProperties()) { it.forEachRemaining( contextProperty -> { String propertyKey = contextProperty.getKey(); if (propertyKey.startsWith(SONAR_ANALYSIS) || propertyKey.startsWith(SONAR_PULL_REQUEST)) { analysisPropertyDtos.add(new AnalysisPropertyDto() .setUuid(uuidFactory.create()) .setKey(propertyKey) .setValue(contextProperty.getValue()) .setSnapshotUuid(analysisMetadataHolder.getUuid())); } }); } analysisMetadataHolder.getScmRevisionId().ifPresent(scmRevisionId -> analysisPropertyDtos.add(new AnalysisPropertyDto() .setUuid(uuidFactory.create()) .setKey(SCM_REVISION_ID) .setValue(scmRevisionId) .setSnapshotUuid(analysisMetadataHolder.getUuid()))); if (analysisPropertyDtos.isEmpty()) { return; } try (DbSession dbSession = dbClient.openSession(false)) { dbClient.analysisPropertiesDao().insert(dbSession, analysisPropertyDtos); dbSession.commit(); } }
private void insertPropertiesFor(String snapshotUuid, Map<String, String> properties) { List<AnalysisPropertyDto> analysisProperties = properties.entrySet().stream() .map(entry -> new AnalysisPropertyDto() .setUuid(UuidFactoryFast.getInstance().create()) .setSnapshotUuid(snapshotUuid) .setKey(entry.getKey()) .setValue(entry.getValue())) .collect(toArrayList(properties.size())); dbTester.getDbClient().analysisPropertiesDao().insert(dbTester.getSession(), analysisProperties); dbTester.getSession().commit(); }
@Test public void null_snapshot_uuid_should_throw_NPE() { underTest = new AnalysisPropertyDto(); expectedException.expect(NullPointerException.class); expectedException.expectMessage("snapshotUuid cannot be null"); underTest.setSnapshotUuid(null); }
@Test public void insert_with_null_uuid_throws_NPE() { AnalysisPropertyDto analysisPropertyDto = new AnalysisPropertyDto() .setSnapshotUuid(randomAlphanumeric(10)) .setKey(randomAlphanumeric(10)) .setValue(randomAlphanumeric(10)); expectedException.expect(NullPointerException.class); expectedException.expectMessage("uuid cannot be null"); underTest.insert(dbSession, analysisPropertyDto); }
@Test public void insert_with_null_key_throws_NPE() { AnalysisPropertyDto analysisPropertyDto = new AnalysisPropertyDto() .setSnapshotUuid(randomAlphanumeric(10)) .setUuid(randomAlphanumeric(10)) .setValue(randomAlphanumeric(10)); expectedException.expect(NullPointerException.class); expectedException.expectMessage("key cannot be null"); underTest.insert(dbSession, analysisPropertyDto); }
@Test public void insert_with_null_value_throws_NPE() { AnalysisPropertyDto analysisPropertyDto = new AnalysisPropertyDto() .setSnapshotUuid(randomAlphanumeric(10)) .setUuid(randomAlphanumeric(10)) .setKey(randomAlphanumeric(10)); expectedException.expect(NullPointerException.class); expectedException.expectMessage("value cannot be null"); underTest.insert(dbSession, analysisPropertyDto); }
underTest = new AnalysisPropertyDto() .setUuid(randomAlphanumeric(40)) .setSnapshotUuid(randomAlphanumeric(40)) .setKey(randomAlphanumeric(512)) .setValue(randomAlphanumeric(10000)); new AnalysisPropertyDto() .setUuid(underTest.getUuid()) .setSnapshotUuid(underTest.getSnapshotUuid()) .setKey(underTest.getKey()) .setValue(underTest.getValue())); new AnalysisPropertyDto() .setUuid("1" + underTest.getUuid()) .setSnapshotUuid(underTest.getSnapshotUuid()) .setKey(underTest.getKey()) .setValue(underTest.getValue())); new AnalysisPropertyDto() .setUuid(underTest.getUuid()) .setSnapshotUuid("1" + underTest.getSnapshotUuid()) .setKey(underTest.getKey()) .setValue(underTest.getValue())); new AnalysisPropertyDto() .setUuid(underTest.getUuid()) .setSnapshotUuid(underTest.getSnapshotUuid()) .setKey("1" + underTest.getKey()) .setValue(underTest.getValue()));
underTest = new AnalysisPropertyDto() .setUuid(randomAlphanumeric(40)) .setSnapshotUuid(randomAlphanumeric(40)) .setKey(randomAlphanumeric(512)) .setValue(randomAlphanumeric(10000)); new AnalysisPropertyDto() .setUuid(underTest.getUuid()) .setSnapshotUuid(underTest.getSnapshotUuid()) .setKey(underTest.getKey()) .setValue(underTest.getValue()) new AnalysisPropertyDto() .setUuid("1" + underTest.getUuid()) .setSnapshotUuid(underTest.getSnapshotUuid()) .setKey(underTest.getKey()) .setValue(underTest.getValue()) new AnalysisPropertyDto() .setUuid(underTest.getUuid()) .setSnapshotUuid("1" + underTest.getSnapshotUuid()) .setKey(underTest.getKey()) .setValue(underTest.getValue()) new AnalysisPropertyDto() .setUuid(underTest.getUuid()) .setSnapshotUuid(underTest.getSnapshotUuid()) .setKey("1" + underTest.getKey()) .setValue(underTest.getValue())
@Override public void execute() { final List<AnalysisPropertyDto> analysisPropertyDtos = new ArrayList<>(); reportReader.readContextProperties().forEachRemaining( contextProperty -> { String propertyKey = contextProperty.getKey(); if (propertyKey.startsWith(SONAR_ANALYSIS) || propertyKey.startsWith(SONAR_PULL_REQUEST)) { analysisPropertyDtos.add(new AnalysisPropertyDto() .setUuid(uuidFactory.create()) .setKey(propertyKey) .setValue(contextProperty.getValue()) .setSnapshotUuid(analysisMetadataHolder.getUuid())); } }); if (analysisPropertyDtos.isEmpty()) { return; } try (DbSession dbSession = dbClient.openSession(false)) { dbClient.analysisPropertiesDao().insert(dbSession, analysisPropertyDtos); dbSession.commit(); } }