<commit_before>package org.cru.godtools.api.v2;

import com.google.common.base.Optional;
import org.ccci.util.time.Clock;
import org.cru.godtools.api.v2.functions.DraftTranslation;
import org.cru.godtools.domain.authentication.AuthorizationRecord;
import org.cru.godtools.domain.authentication.AuthorizationService;
import org.cru.godtools.domain.languages.Language;
import org.cru.godtools.domain.languages.LanguageService;
import org.cru.godtools.domain.packages.Package;
import org.cru.godtools.domain.packages.PackageService;

import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.UUID;

@Path("/v2/languages")
public class LanguageResource
{

	@Inject
	AuthorizationService authorizationService;
	@Inject
	LanguageService languageService;
	@Inject
	PackageService packageService;

	@Inject
	DraftTranslation draftTranslation;

	@Inject
	Clock clock;

	@POST
	@Consumes(MediaType.APPLICATION_JSON)
	public Response addLanguage(Language language, @HeaderParam("Authorization") String authorization)
	{
		Optional<AuthorizationRecord> authorizationRecord = authorizationService.getAuthorizationRecord(authorization, null);

		AuthorizationRecord.checkAdminAccess(authorizationRecord, clock.currentDateTime());

		if(languageService.languageExists(language))
		{
			return Response
					.status(400)
					.build();
		}

		language.setId(UUID.randomUUID());

		languageService.insert(language);

		for(Package gtPackage : packageService.selectAllPackages())
		{
			draftTranslation.create(language.getCode(), gtPackage.getCode());
		}<commit_msg>Return 400 if language is not passed on create language<commit_after>package org.cru.godtools.api.v2;

import com.google.common.base.Optional;
import org.ccci.util.time.Clock;
import org.cru.godtools.api.v2.functions.DraftTranslation;
import org.cru.godtools.domain.authentication.AuthorizationRecord;
import org.cru.godtools.domain.authentication.AuthorizationService;
import org.cru.godtools.domain.languages.Language;
import org.cru.godtools.domain.languages.LanguageService;
import org.cru.godtools.domain.packages.Package;
import org.cru.godtools.domain.packages.PackageService;

import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.UUID;

@Path("/v2/languages")
public class LanguageResource
{

	@Inject
	AuthorizationService authorizationService;
	@Inject
	LanguageService languageService;
	@Inject
	PackageService packageService;

	@Inject
	DraftTranslation draftTranslation;

	@Inject
	Clock clock;

	@POST
	@Consumes(MediaType.APPLICATION_JSON)
	public Response addLanguage(Language language, @HeaderParam("Authorization") String authorization)
	{
		if(language == null)
		{
			return Response
					.status(Response.Status.BAD_REQUEST)
					.entity("Language was missing")
					.build();
		}

		Optional<AuthorizationRecord> authorizationRecord = authorizationService.getAuthorizationRecord(authorization, null);

		AuthorizationRecord.checkAdminAccess(authorizationRecord, clock.currentDateTime());

		if(languageService.languageExists(language))
		{
			return Response
					.status(400)
					.build();
		}

		language.setId(UUID.randomUUID());

		languageService.insert(language);

		for(Package gtPackage : packageService.selectAllPackages())
		{
			draftTranslation.create(language.getCode(), gtPackage.getCode());
		}
{'fraction_non_alphanumeric': 0.10770505385252693, 'fraction_numerical': 0.004142502071251036, 'mean_word_length': 5.833962264150943, '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': '5561456', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1081, 'n_words': 182}