Skip to content

Commit

Permalink
refactor: remove direct usage of couchDB client (#2757)
Browse files Browse the repository at this point in the history
* refactor: remove direct usage of couchDB client

* chore: remove lightcouch dependency

* Revert "chore: remove lightcouch dependency"

This reverts commit 6723351.

* refactor: restructure code

* style: adapt formatting
  • Loading branch information
bossenti authored Apr 26, 2024
1 parent 6a1da8d commit 60a3494
Showing 1 changed file with 11 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,7 @@
import org.apache.streampipes.model.datalake.DataLakeMeasureSchemaUpdateStrategy;
import org.apache.streampipes.model.schema.EventProperty;
import org.apache.streampipes.storage.api.IDataLakeStorage;
import org.apache.streampipes.storage.couchdb.utils.Utils;

import com.google.gson.JsonObject;
import org.lightcouch.CouchDbClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
Expand All @@ -41,8 +34,6 @@

public class DataExplorerSchemaManagement implements IDataExplorerSchemaManagement {

private static final Logger LOG = LoggerFactory.getLogger(DataExplorerSchemaManagement.class);

IDataLakeStorage dataLakeStorage;

public DataExplorerSchemaManagement(IDataLakeStorage dataLakeStorage) {
Expand Down Expand Up @@ -80,7 +71,7 @@ public DataLakeMeasure createOrUpdateMeasurement(DataLakeMeasure measure) {
}

/**
* Destiguishes between the update straregy for existing measurments
* Distinguishes between the update strategy for existing measurements
*/
private void handleExistingMeasurement(
DataLakeMeasure measure,
Expand Down Expand Up @@ -125,36 +116,17 @@ public void deleteMeasurement(String elementId) {

@Override
public boolean deleteMeasurementByName(String measureName) {
boolean isSuccess = false;
CouchDbClient couchDbClient = Utils.getCouchDbDataLakeClient();
List<JsonObject> docs = couchDbClient.view("_all_docs")
.includeDocs(true)
.query(JsonObject.class);

for (JsonObject document : docs) {
if (document.get("measureName")
.toString()
.replace("\"", "")
.equals(measureName)) {
couchDbClient.remove(
document.get("_id")
.toString()
.replace("\"", ""),
document.get("_rev")
.toString()
.replace("\"", "")
);
isSuccess = true;
break;
}
}

try {
couchDbClient.close();
} catch (IOException e) {
LOG.error("Could not close CouchDB client", e);
var measureToDeleteOpt = dataLakeStorage.getAllDataLakeMeasures()
.stream()
.filter(measurement -> measurement.getMeasureName()
.equals(measureName))
.findFirst();

return measureToDeleteOpt.map(measure -> {
dataLakeStorage.deleteDataLakeMeasure(measure.getElementId());
return true;
}
return isSuccess;
).orElse(false);
}

@Override
Expand Down

0 comments on commit 60a3494

Please sign in to comment.