<commit_before>/**
 * Copyright (C) 2011 <NAME> <<EMAIL>>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.artivisi.belajar.restful.ui.controller;

import java.io.File;
import java.net.URI;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
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.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.util.UriTemplate;

import com.artivisi.belajar.restful.domain.ApplicationConfig;
import com.artivisi.belajar.restful.service.BelajarRestfulService;
import com.artivisi.belajar.restful.ui.helper.Range;
import com.google.common.io.Files;

@Controller
@RequestMapping("/config")
public class ApplicationConfigController {
	
	@Autowired private BelajarRestfulService belajarRestfulService;
	
	private Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@RequestMapping("/{id}/files")
	@ResponseBody
	public Map<String, String> uploadFiles(
			@PathVariable String id,
			@RequestParam String keterangan, 
			@RequestParam MultipartFile cv, 
			@RequestParam MultipartFile foto
			) throws Exception {
		ApplicationConfig config = belajarRestfulService.findApplicationConfigById(id);
		if(config == null){
			throw new IllegalStateException();
		}
		
		Map<String, String> result = new HashMap<String, String>();
		
		logger.info("CV => Content-Type : {}, Filename : {}, Size : {}", new Object[]{
				cv.getContentType(), cv.getOriginalFilename(), cv.getSize()});
		
		logger.info("Foto => Content-Type : {}, Filename : {}, Size : {}", new Object[]{
				foto.getContentType(), foto.getOriginalFilename(), foto.getSize()});
		
		File cvTarget = File.createTempFile(cv.getOriginalFilename().split("\\.")[0], "."+cv.getOriginalFilename().split("\\.")[1]);
		File fotoTarget = File.createTempFile(foto.getOriginalFilename().split("\\.")[0], "."+foto.getOriginalFilename().split("\\.")[1]);
		cv.transferTo(cvTarget);
		foto.transferTo(fotoTarget);
		
		logger.info("CV disimpan ke {}",cvTarget.getAbsolutePath());
		logger.info("Foto disimpan ke {}",fotoTarget.getAbsolutePath());
		
		if(cv.getSize() == 51987l) {
			result.put("cv", "success");
		} else {
			result.put("cv", "error size");
		}
		
		if(foto.getSize() == 583738l) {
			result.put("foto", "success");
		} else {
			result.put("foto", "error size");
		}
		
		if("File Endy".equals(keterangan)) {
			result.put("keterangan", "success");
		} else {
			result.put("keterangan", "salah content");
		}
		
		return result;
	}
	
	@RequestMapping("/{id}")
	@ResponseBody
	public ApplicationConfig findApplicationConfigById(@PathVariable String id){<commit_msg>fix sonar violations, refactor magic string menjadi constant<commit_after>/**
 * Copyright (C) 2011 <NAME> <<EMAIL>>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.artivisi.belajar.restful.ui.controller;

import java.io.File;
import java.net.URI;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
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.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.util.UriTemplate;

import com.artivisi.belajar.restful.domain.ApplicationConfig;
import com.artivisi.belajar.restful.service.BelajarRestfulService;
import com.artivisi.belajar.restful.ui.helper.Range;
import com.google.common.io.Files;

@Controller
@RequestMapping("/config")
public class ApplicationConfigController {
    private static final String ESC_CHAR_TITIK = "\\.";
    private static final long UKURAN_FILE_CV = 51987l;
    private static final long UKURAN_FILE_FOTO = 583738l;
	
	@Autowired private BelajarRestfulService belajarRestfulService;
	
	private Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@RequestMapping("/{id}/files")
	@ResponseBody
	public Map<String, String> uploadFiles(
			@PathVariable String id,
			@RequestParam String keterangan, 
			@RequestParam MultipartFile cv, 
			@RequestParam MultipartFile foto
			) throws Exception {
		ApplicationConfig config = belajarRestfulService.findApplicationConfigById(id);
		if(config == null){
			throw new IllegalStateException();
		}
		
		Map<String, String> result = new HashMap<String, String>();
		
		logger.info("CV => Content-Type : {}, Filename : {}, Size : {}", new Object[]{
				cv.getContentType(), cv.getOriginalFilename(), cv.getSize()});
		
		logger.info("Foto => Content-Type : {}, Filename : {}, Size : {}", new Object[]{
				foto.getContentType(), foto.getOriginalFilename(), foto.getSize()});
		
		File cvTarget = File.createTempFile(cv.getOriginalFilename().split(ESC_CHAR_TITIK)[0], "."+cv.getOriginalFilename().split(ESC_CHAR_TITIK)[1]);
		File fotoTarget = File.createTempFile(foto.getOriginalFilename().split(ESC_CHAR_TITIK)[0], "."+foto.getOriginalFilename().split(ESC_CHAR_TITIK)[1]);
		cv.transferTo(cvTarget);
		foto.transferTo(fotoTarget);
		
		logger.info("CV disimpan ke {}",cvTarget.getAbsolutePath());
		logger.info("Foto disimpan ke {}",fotoTarget.getAbsolutePath());
		
		if(cv.getSize() == UKURAN_FILE_CV) {
			result.put("cv", "success");
		} else {
			result.put("cv", "error size");
		}
		
		if(foto.getSize() == UKURAN_FILE_FOTO) {
			result.put("foto", "success");
		} else {
			result.put("foto", "error size");
		}
		
		if("File Endy".equals(keterangan)) {
			result.put("keterangan", "success");
		} else {
			result.put("keterangan", "salah content");
		}
		
		return result;
	}
	
	@RequestMapping("/{id}")
	@ResponseBody
	public ApplicationConfig findApplicationConfigById(@PathVariable String id){
{'fraction_non_alphanumeric': 0.12817784084190612, 'fraction_numerical': 0.005912262031453234, 'mean_word_length': 5.209985315712188, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7065378', 'n_tokens_mistral': 2679, 'n_tokens_neox': 2492, 'n_words': 551}