<commit_before>package org.jvalue.ceps.data;

import com.fasterxml.jackson.databind.JsonNode;
import com.google.inject.Inject;
import com.google.inject.name.Named;

import org.jvalue.ceps.db.OdsRegistrationRepository;
import org.jvalue.ceps.esper.DataUpdateListener;
import org.jvalue.ceps.main.ConfigModule;
import org.jvalue.ceps.ods.OdsDataSourceService;
import org.jvalue.ceps.ods.OdsNotificationService;
import org.jvalue.ceps.ods.OdsClient;
import org.jvalue.ceps.ods.OdsDataSource;
import org.jvalue.ceps.rest.RestModule;
import org.jvalue.ceps.utils.Assert;
import org.jvalue.ceps.utils.Log;

import java.util.List;

import io.dropwizard.lifecycle.Managed;

import static org.jvalue.ceps.ods.OdsNotificationService.OdsClientDescription;


public final class DataManager implements Managed, DataSink {

	// Name of this HTTP client on the ODS. Might need more dynamic approach in the future.
	private static final String ODS_CLIENT_ID = "ceps";

	private final OdsDataSourceService odsDataSourceService;
	private final OdsNotificationService odsNotificationService;

	private final OdsRegistrationRepository registrationRepository;
	private final DataUpdateListener dataListener;

	private final String cepsDataCallbackUrl;


	@Inject
	DataManager(
			OdsDataSourceService odsDataSourceService,
			OdsNotificationService odsNotificationService,
			OdsRegistrationRepository registrationRepository,
			DataUpdateListener dataListener,
			@Named(ConfigModule.CEPS_BASE_URL) String cepsBaseUrl,
			@Named(RestModule.URL_DATA) String dataUrl) {

		this.odsDataSourceService = odsDataSourceService;
		this.odsNotificationService = odsNotificationService;
		this.registrationRepository = registrationRepository;
		this.dataListener = dataListener;
		this.cepsDataCallbackUrl = cepsBaseUrl + dataUrl;
	}


	public void startMonitoring(String sourceId) {
		Assert.assertNotNull(sourceId);
		Assert.assertTrue(isBeingMonitored(sourceId), "source already being monitored");

		// get source / schema
		OdsDataSource source = odsDataSourceService.get(sourceId);

		// register for updates
		OdsClientDescription clientDescription = new OdsClientDescription(cepsDataCallbackUrl, true);
		OdsClient client = odsNotificationService.register(sourceId, ODS_CLIENT_ID, clientDescription);

		// store result in db
		OdsRegistration registration = new OdsRegistration(source, client);
		registrationRepository.add(registration);
	}

<commit_msg>data: fixed wrong monitoring check in DataManager<commit_after>package org.jvalue.ceps.data;

import com.fasterxml.jackson.databind.JsonNode;
import com.google.inject.Inject;
import com.google.inject.name.Named;

import org.jvalue.ceps.db.OdsRegistrationRepository;
import org.jvalue.ceps.esper.DataUpdateListener;
import org.jvalue.ceps.main.ConfigModule;
import org.jvalue.ceps.ods.OdsDataSourceService;
import org.jvalue.ceps.ods.OdsNotificationService;
import org.jvalue.ceps.ods.OdsClient;
import org.jvalue.ceps.ods.OdsDataSource;
import org.jvalue.ceps.rest.RestModule;
import org.jvalue.ceps.utils.Assert;
import org.jvalue.ceps.utils.Log;

import java.util.List;

import io.dropwizard.lifecycle.Managed;

import static org.jvalue.ceps.ods.OdsNotificationService.OdsClientDescription;


public final class DataManager implements Managed, DataSink {

	// Name of this HTTP client on the ODS. Might need more dynamic approach in the future.
	private static final String ODS_CLIENT_ID = "ceps";

	private final OdsDataSourceService odsDataSourceService;
	private final OdsNotificationService odsNotificationService;

	private final OdsRegistrationRepository registrationRepository;
	private final DataUpdateListener dataListener;

	private final String cepsDataCallbackUrl;


	@Inject
	DataManager(
			OdsDataSourceService odsDataSourceService,
			OdsNotificationService odsNotificationService,
			OdsRegistrationRepository registrationRepository,
			DataUpdateListener dataListener,
			@Named(ConfigModule.CEPS_BASE_URL) String cepsBaseUrl,
			@Named(RestModule.URL_DATA) String dataUrl) {

		this.odsDataSourceService = odsDataSourceService;
		this.odsNotificationService = odsNotificationService;
		this.registrationRepository = registrationRepository;
		this.dataListener = dataListener;
		this.cepsDataCallbackUrl = cepsBaseUrl + dataUrl;
	}


	public void startMonitoring(String sourceId) {
		Assert.assertNotNull(sourceId);
		Assert.assertFalse(isBeingMonitored(sourceId), "source already being monitored");

		// get source / schema
		OdsDataSource source = odsDataSourceService.get(sourceId);

		// register for updates
		OdsClientDescription clientDescription = new OdsClientDescription(cepsDataCallbackUrl, true);
		OdsClient client = odsNotificationService.register(sourceId, ODS_CLIENT_ID, clientDescription);

		// store result in db
		OdsRegistration registration = new OdsRegistration(source, client);
		registrationRepository.add(registration);
	}


{'fraction_non_alphanumeric': 0.07482161060142711, 'fraction_numerical': 0.0, 'mean_word_length': 6.183016105417277, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2397509', 'n_tokens_mistral': 1498, 'n_tokens_neox': 1389, 'n_words': 306}