<commit_before>package com.ctrip.hermes.portal.resource;

import io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.inject.Singleton;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;

import org.codehaus.plexus.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.unidal.dal.jdbc.DalException;
import org.unidal.dal.jdbc.DalNotFoundException;
import org.unidal.lookup.annotation.Inject;

import com.alibaba.fastjson.JSON;
import com.ctrip.hermes.meta.dal.meta.Schema;
import com.ctrip.hermes.meta.entity.Codec;
import com.ctrip.hermes.meta.entity.Storage;
import com.ctrip.hermes.meta.entity.Topic;
import com.ctrip.hermes.portal.pojo.SchemaView;
import com.ctrip.hermes.portal.pojo.TopicView;
import com.ctrip.hermes.portal.server.RestException;
import com.ctrip.hermes.portal.service.CodecService;
import com.ctrip.hermes.portal.service.SchemaService;
import com.ctrip.hermes.portal.service.TopicService;
import com.ctrip.hermes.portal.service.storage.TopicStorageService;
import com.ctrip.hermes.portal.service.storage.exception.TopicAlreadyExistsException;

@Path("/topics/")
@Singleton
@Produces(MediaType.APPLICATION_JSON)
public class TopicResource {

	private static final Logger logger = LoggerFactory.getLogger(TopicResource.class);

	@Inject
	private TopicService topicService;

	@Inject
	private SchemaService schemaService;

	@Inject
	private CodecService codecService;
	
	@Inject
	private TopicStorageService service;

	@POST
	public Response createTopic(String content) {
		logger.debug("create topic, content {}", content);
		if (StringUtils.isEmpty(content)) {
			throw new RestException("HTTP POST body is empty", Status.BAD_REQUEST);
		}
		TopicView topicView = null;
		try {
			topicView = JSON.parseObject(content, TopicView.class);
		} catch (Exception e) {
			logger.warn("parse topic failed, content: {}", content);
			throw new RestException(e, Status.BAD_REQUEST);
		}

		Topic topic = topicView.toMetaTopic();

		if (topicService.getTopic(topic.getName()) != null) {
			throw new RestException("Topic already exists.", Status.CONFLICT);
		}
		try {
			topic = topicService.createTopic(topic);
			topicView = new TopicView(topic);
		} catch (Exception e) {
			logger.warn("create topic failed", e);
			throw new RestException(e, Status.INTERNAL_SERVER_ERROR);
		}
		return Response.status(Status.CREATED).entity(topicView).build();
	}

	@GET
	@Path("{name}/createdb")
	@Produces(MediaType.APPLICATION_JSON)
	public Boolean createNewTopic(@QueryParam("ds") String ds,
											@PathParam("name") String topicName) {
		try {
			return service.createNewTopic(ds, topicName);
		} catch (TopicAlreadyExistsException e) {
			throw new RuntimeException(e);
		}
	}

	@GET
	public List<TopicView> findTopics(@QueryParam("pattern") String pattern) {
		logger.debug("find topics, pattern {}", pattern);
		if (StringUtils.isEmpty(pattern)) {
			pattern = ".*";
		}
<commit_msg>fix outdate mistake<commit_after>package com.ctrip.hermes.portal.resource;

import io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.inject.Singleton;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;

import org.codehaus.plexus.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.unidal.dal.jdbc.DalException;
import org.unidal.dal.jdbc.DalNotFoundException;

import com.alibaba.fastjson.JSON;
import com.ctrip.hermes.core.utils.PlexusComponentLocator;
import com.ctrip.hermes.meta.dal.meta.Schema;
import com.ctrip.hermes.meta.entity.Codec;
import com.ctrip.hermes.meta.entity.Storage;
import com.ctrip.hermes.meta.entity.Topic;
import com.ctrip.hermes.portal.pojo.SchemaView;
import com.ctrip.hermes.portal.pojo.TopicView;
import com.ctrip.hermes.portal.server.RestException;
import com.ctrip.hermes.portal.service.CodecService;
import com.ctrip.hermes.portal.service.SchemaService;
import com.ctrip.hermes.portal.service.TopicService;
import com.ctrip.hermes.portal.service.storage.TopicStorageService;
import com.ctrip.hermes.portal.service.storage.exception.TopicAlreadyExistsException;

@Path("/topics/")
@Singleton
@Produces(MediaType.APPLICATION_JSON)
public class TopicResource {

	private static final Logger logger = LoggerFactory.getLogger(TopicResource.class);

	private TopicService topicService = PlexusComponentLocator.lookup(TopicService.class);

	private SchemaService schemaService = PlexusComponentLocator.lookup(SchemaService.class);

	private CodecService codecService = PlexusComponentLocator.lookup(CodecService.class);

	private TopicStorageService service = PlexusComponentLocator.lookup(TopicStorageService.class);

	@POST
	public Response createTopic(String content) {
		logger.debug("create topic, content {}", content);
		if (StringUtils.isEmpty(content)) {
			throw new RestException("HTTP POST body is empty", Status.BAD_REQUEST);
		}
		TopicView topicView = null;
		try {
			topicView = JSON.parseObject(content, TopicView.class);
		} catch (Exception e) {
			logger.warn("parse topic failed, content: {}", content);
			throw new RestException(e, Status.BAD_REQUEST);
		}

		Topic topic = topicView.toMetaTopic();

		if (topicService.getTopic(topic.getName()) != null) {
			throw new RestException("Topic already exists.", Status.CONFLICT);
		}
		try {
			topic = topicService.createTopic(topic);
			topicView = new TopicView(topic);
		} catch (Exception e) {
			logger.warn("create topic failed", e);
			throw new RestException(e, Status.INTERNAL_SERVER_ERROR);
		}
		return Response.status(Status.CREATED).entity(topicView).build();
	}

	@GET
	@Path("{name}/createdb")
	@Produces(MediaType.APPLICATION_JSON)
	public Boolean createNewTopic(@QueryParam("ds") String ds, @PathParam("name") String topicName) {
		try {
			return service.createNewTopic(ds, topicName);
		} catch (TopicAlreadyExistsException e) {
			throw new RuntimeException(e);
		}
	}

	@GET
	public List<TopicView> findTopics(@QueryParam("pattern") String pattern) {
		logger.debug("find topics, pattern {}", pattern);
		if (StringUtils.isEmpty(pattern)) {
			pattern = ".*";
		}

{'fraction_non_alphanumeric': 0.1218727139722019, 'fraction_numerical': 0.0005852231163130944, 'mean_word_length': 5.388785046728972, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5110196', 'n_tokens_mistral': 2306, 'n_tokens_neox': 2209, 'n_words': 408}