<commit_before>/*
 * JBoss, Home of Professional Open Source
 * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
 * as indicated by the @authors tag. All rights reserved.
 */
package org.jboss.dcp.api.service;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import javax.annotation.PostConstruct;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import javax.inject.Named;

import org.jboss.dcp.api.util.SearchUtils;

/**
 * Service for persistence backend.<br/>
 * Now persistence storage is implemented as embedded elasticsearch node
 * 
 * @author <NAME>
 * 
 */
@Named
@Singleton
@ApplicationScoped
@Startup
public class PersistanceBackendService extends ElasticsearchClientService {

	@Inject
	protected AppConfigurationService appConfigurationService;

	// Everything is stored in one index
	protected static final String INDEX_NAME = "data";
	protected static final String INDEX_TYPE_PROVIDER = "provider";

	@PostConstruct
	public void init() throws Exception {
		Properties settings = SearchUtils.loadProperties("/persistance_settings.properties");

		node = createEmbeddedNode("persistance", settings);
		client = node.client();
	}

	@Produces
	@Named("providerServiceBackend")
	public ElasticsearchEntityService produceProviderService() {
		ElasticsearchEntityService serv = new ElasticsearchEntityService(client, INDEX_NAME, INDEX_TYPE_PROVIDER, false);

		if (appConfigurationService.getAppConfiguration().isProviderCreateInitData()) {

			if (!client.admin().indices().prepareExists(INDEX_NAME).execute().actionGet().exists()) {
				log.info("Provider entity doesn't exists. Creating initial entity for first authentication.");

				client.admin().indices().prepareCreate(INDEX_NAME).execute().actionGet();
				Map<String, Object> jbossorgEntity = new HashMap<String, Object>();
				jbossorgEntity.put(ProviderService.NAME, "jbossorg");
				jbossorgEntity.put(ProviderService.PASSWORD_HASH, "<PASSWORD>");
				jbossorgEntity.put(ProviderService.SUPER_PROVIDER, true);

				serv.create("jbossorg", jbossorgEntity);
			}
		}

		return serv;
	}

	@Produces
	@Named("projectServiceBackend")
	public EntityService produceProjectService() {
		return new ElasticsearchEntityService(client, INDEX_NAME, "project", false);
	}

	@Produces
	@Named("contributorServiceBackend")
	public EntityService produceContributorService() {
		return new ElasticsearchEntityService(client, INDEX_NAME, "contributor", false);
	}

}<commit_msg>changed initial password to <PASSWORD><commit_after>/*
 * JBoss, Home of Professional Open Source
 * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
 * as indicated by the @authors tag. All rights reserved.
 */
package org.jboss.dcp.api.service;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import javax.annotation.PostConstruct;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import javax.inject.Named;

import org.jboss.dcp.api.util.SearchUtils;

/**
 * Service for persistence backend.<br/>
 * Now persistence storage is implemented as embedded elasticsearch node
 * 
 * @author <NAME>
 * 
 */
@Named
@Singleton
@ApplicationScoped
@Startup
public class PersistanceBackendService extends ElasticsearchClientService {

	@Inject
	protected AppConfigurationService appConfigurationService;

	// Everything is stored in one index
	protected static final String INDEX_NAME = "data";
	protected static final String INDEX_TYPE_PROVIDER = "provider";

	@PostConstruct
	public void init() throws Exception {
		Properties settings = SearchUtils.loadProperties("/persistance_settings.properties");

		node = createEmbeddedNode("persistance", settings);
		client = node.client();
	}

	@Produces
	@Named("providerServiceBackend")
	public ElasticsearchEntityService produceProviderService() {
		ElasticsearchEntityService serv = new ElasticsearchEntityService(client, INDEX_NAME, INDEX_TYPE_PROVIDER, false);

		if (appConfigurationService.getAppConfiguration().isProviderCreateInitData()) {

			if (!client.admin().indices().prepareExists(INDEX_NAME).execute().actionGet().exists()) {
				log.info("Provider entity doesn't exists. Creating initial entity for first authentication.");

				client.admin().indices().prepareCreate(INDEX_NAME).execute().actionGet();
				Map<String, Object> jbossorgEntity = new HashMap<String, Object>();
				jbossorgEntity.put(ProviderService.NAME, "jbossorg");
				// initial password: <PASSWORD>
				jbossorgEntity.put(ProviderService.PASSWORD_HASH, "<PASSWORD>");
				jbossorgEntity.put(ProviderService.SUPER_PROVIDER, true);

				serv.create("jbossorg", jbossorgEntity);
			}
		}

		return serv;
	}

	@Produces
	@Named("projectServiceBackend")
	public EntityService produceProjectService() {
		return new ElasticsearchEntityService(client, INDEX_NAME, "project", false);
	}

	@Produces
	@Named("contributorServiceBackend")
	public EntityService produceContributorService() {
		return new ElasticsearchEntityService(client, INDEX_NAME, "contributor", false);
	}

}
{'fraction_non_alphanumeric': 0.10463576158940398, 'fraction_numerical': 0.0015137180700094607, 'mean_word_length': 5.838292367399741, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2405872', 'n_tokens_mistral': 1586, 'n_tokens_neox': 1479, 'n_words': 359}