Added metric insertion method.
@@ -4,6 +4,7 @@ import eu.fasten.core.plugins.KafkaPlugin;
import eu.fasten.core.plugins.DBConnector;
import eu.fasten.core.data.metadatadb.MetadataDao;
+import org.json.JSONObject;
import org.pf4j.Extension;
import org.pf4j.Plugin;
import org.pf4j.PluginWrapper;
@@ -30,6 +31,14 @@ public class QualityAnalyzerPlugin extends Plugin {
private String consumerTopic = "fasten.RapidPlugin.out";
private static DSLContext dslContext;
private final Logger logger = LoggerFactory.getLogger(QualityAnalyzer.class.getName());
+ private Throwable pluginError = null;
+ private String artifact = null;
+ private String group = null;
+ private String version = null;
+ private long date = -1L;
+ private boolean restartTransaction = false;
+ private final int transactionRestartLimit = 3;
+ private boolean processedRecord = false;
@Override
public void setDBConnection(DSLContext dslContext) {
@@ -48,10 +57,28 @@ public class QualityAnalyzerPlugin extends Plugin {
@Override
public void consume(String record) {
- }
-
- public long saveToDatabase(String product, String version, MetadataDao metadataDao) {
- return 0;
+ pluginError = null;
+ artifact = null;
+ group = null;
+ version = null;
+ date = -1L;
+ this.processedRecord = false;
+ this.restartTransaction = false;
+ logger.info("Consumed: " + record);
+ var jsonRecord = new JSONObject(record);
+ var payload = new JSONObject();
+ if (jsonRecord.has("payload")) {
+ payload = jsonRecord.getJSONObject("payload");
+ }
+ }
+
+ public long saveToDatabase(String product, String version, String repoUrl, JSONObject metrics, MetadataDao metadataDao) {
+ final var packageId = metadataDao.insertPackage(product, "mvn", null, repoUrl, null);
+ var packageVersionMetadata = new JSONObject();
+ packageVersionMetadata.put("metrics", metrics != null ? metrics : null);
+ final var packageVersionId = metadataDao.insertPackageVersion(packageId,
+ null, version, null, packageVersionMetadata);
+ return packageVersionId;
}
@Override
