<commit_before>package com.itranswarp.shici.service;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.persistence.EntityNotFoundException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.itranswarp.shici.bean.CategoryBean;
import com.itranswarp.shici.bean.CategoryPoemBean;
import com.itranswarp.shici.bean.FeaturedBean;
import com.itranswarp.shici.bean.PoemBean;
import com.itranswarp.shici.bean.PoetBean;
import com.itranswarp.shici.exception.APIArgumentException;
import com.itranswarp.shici.json.LocalDateDeserializer;
import com.itranswarp.shici.json.LocalDateSerializer;
import com.itranswarp.shici.model.BaseEntity;
import com.itranswarp.shici.model.Category;
import com.itranswarp.shici.model.CategoryPoem;
import com.itranswarp.shici.model.Dynasty;
import com.itranswarp.shici.model.FeaturedPoem;
import com.itranswarp.shici.model.Poem;
import com.itranswarp.shici.model.Poet;
import com.itranswarp.shici.model.Resource;
import com.itranswarp.shici.util.HttpUtil;
import com.itranswarp.shici.util.IdUtils;
import com.itranswarp.warpdb.PagedResults;
import com.itranswarp.wxapi.util.MapUtil;

@RestController
@Transactional
public class PoemService extends AbstractService {

	@Autowired
	HanziService hanziService;

	// dynasty ////////////////////////////////////////////////////////////////

	@RequestMapping(value = "/api/dynasties", method = RequestMethod.GET)
	public Map<String, List<Dynasty>> restGetDynasties() {
		return MapUtil.createMap("results", getDynasties());
	}

	public List<Dynasty> getDynasties() {
		return warpdb.from(Dynasty.class).orderBy("displayOrder").list();
	}

	public Dynasty getDynasty(String dynastyId) {
		return warpdb.get(Dynasty.class, dynastyId);
	}

	// poet ///////////////////////////////////////////////////////////////////

	@RequestMapping(value = "/api/{id}/poets", method = RequestMethod.GET)
	public Map<String, List<Poet>> restGetPoets(@PathVariable("id") String dynastyId) {
		return MapUtil.createMap("results", getPoets(dynastyId));
	}

	public List<Poet> getPoets(String dynastyId) {
		return warpdb.from(Poet.class).where("dynastyId=?", dynastyId).orderBy("name").list();
	}

	@RequestMapping(value = "/api/poets/{id}", method = RequestMethod.GET)
	public Poet getPoet(@PathVariable("id") String poetId) {
		return warpdb.get(Poet.class, poetId);
	}

	@RequestMapping(value = "/api/poets", method = RequestMethod.POST)
	public Poet createPoet(@RequestBody PoetBean bean) {
		// check:
		assertEditorRole();
		bean.validate();
		getDynasty(bean.dynastyId);
		// create:
		Poet poet = new Poet();
		copyToPoet(poet, bean);
		warpdb.save(poet);<commit_msg>fix url<commit_after>package com.itranswarp.shici.service;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.persistence.EntityNotFoundException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.itranswarp.shici.bean.CategoryBean;
import com.itranswarp.shici.bean.CategoryPoemBean;
import com.itranswarp.shici.bean.FeaturedBean;
import com.itranswarp.shici.bean.PoemBean;
import com.itranswarp.shici.bean.PoetBean;
import com.itranswarp.shici.exception.APIArgumentException;
import com.itranswarp.shici.json.LocalDateDeserializer;
import com.itranswarp.shici.json.LocalDateSerializer;
import com.itranswarp.shici.model.BaseEntity;
import com.itranswarp.shici.model.Category;
import com.itranswarp.shici.model.CategoryPoem;
import com.itranswarp.shici.model.Dynasty;
import com.itranswarp.shici.model.FeaturedPoem;
import com.itranswarp.shici.model.Poem;
import com.itranswarp.shici.model.Poet;
import com.itranswarp.shici.model.Resource;
import com.itranswarp.shici.util.HttpUtil;
import com.itranswarp.shici.util.IdUtils;
import com.itranswarp.warpdb.PagedResults;
import com.itranswarp.wxapi.util.MapUtil;

@RestController
@Transactional
public class PoemService extends AbstractService {

	@Autowired
	HanziService hanziService;

	// dynasty ////////////////////////////////////////////////////////////////

	@RequestMapping(value = "/api/dynasties", method = RequestMethod.GET)
	public Map<String, List<Dynasty>> restGetDynasties() {
		return MapUtil.createMap("results", getDynasties());
	}

	public List<Dynasty> getDynasties() {
		return warpdb.from(Dynasty.class).orderBy("displayOrder").list();
	}

	public Dynasty getDynasty(String dynastyId) {
		return warpdb.get(Dynasty.class, dynastyId);
	}

	// poet ///////////////////////////////////////////////////////////////////

	@RequestMapping(value = "/api/dynasties/{id}/poets", method = RequestMethod.GET)
	public Map<String, List<Poet>> restGetPoets(@PathVariable("id") String dynastyId) {
		return MapUtil.createMap("results", getPoets(dynastyId));
	}

	public List<Poet> getPoets(String dynastyId) {
		return warpdb.from(Poet.class).where("dynastyId=?", dynastyId).orderBy("name").list();
	}

	@RequestMapping(value = "/api/poets/{id}", method = RequestMethod.GET)
	public Poet getPoet(@PathVariable("id") String poetId) {
		return warpdb.get(Poet.class, poetId);
	}

	@RequestMapping(value = "/api/poets", method = RequestMethod.POST)
	public Poet createPoet(@RequestBody PoetBean bean) {
		// check:
		assertEditorRole();
		bean.validate();
		getDynasty(bean.dynastyId);
		// create:
		Poet poet = new Poet();
		copyToPoet(poet, bean);
		warpdb.save(poet);
{'fraction_non_alphanumeric': 0.15730851388465059, 'fraction_numerical': 0.0, 'mean_word_length': 4.795755968169761, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '6035738', 'n_tokens_mistral': 2176, 'n_tokens_neox': 2091, 'n_words': 320}