<commit_before>package ch.uzh.csg.reimbursement.rest;

import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.OK;
import static org.springframework.web.bind.annotation.RequestMethod.DELETE;
import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;
import static org.springframework.web.bind.annotation.RequestMethod.PUT;

import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
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.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import ch.uzh.csg.reimbursement.dto.AccessRights;
import ch.uzh.csg.reimbursement.dto.ExpenseItemDto;
import ch.uzh.csg.reimbursement.dto.SearchExpenseDto;
import ch.uzh.csg.reimbursement.model.Document;
import ch.uzh.csg.reimbursement.model.Expense;
import ch.uzh.csg.reimbursement.model.ExpenseItem;
import ch.uzh.csg.reimbursement.model.Token;
import ch.uzh.csg.reimbursement.service.ExpenseItemService;
import ch.uzh.csg.reimbursement.service.ExpenseService;
import ch.uzh.csg.reimbursement.service.TokenService;
import ch.uzh.csg.reimbursement.view.View;
import ch.uzh.csg.reimbursement.view.View.DashboardSummary;
import ch.uzh.csg.reimbursement.view.View.Summary;
import ch.uzh.csg.reimbursement.view.View.SummaryWithUid;

import com.fasterxml.jackson.annotation.JsonView;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/expenses")
@PreAuthorize("hasRole('USER')")
@Api(value = "Expense", description = "Authorization depends on state.")
public class ExpenseResource {

	@Autowired
	private ExpenseService expenseService;

	@Autowired
	private ExpenseItemService expenseItemService;

	@Autowired
	private TokenService tokenService;

	@PreAuthorize("hasRole('USER')")
	@JsonView(SummaryWithUid.class)
	@RequestMapping(method = POST)
	@ApiOperation(value = "Creates a new expense for currently logged in user")
	@ResponseStatus(CREATED)
	public Expense createExpense(@RequestParam("accounting") String accounting) {

		return expenseService.create(accounting);
	}

	@PreAuthorize("hasRole('USER')")
	@JsonView(DashboardSummary.class)
	@RequestMapping(method = GET)
	@ApiOperation(value = "Find all expenses for the currently logged in user")
	public Set<Expense> getExpenses() {

		return expenseService.findAllByCurrentUser();
	}

	@PreAuthorize("hasRole('USER')")
	@JsonView(Summary.class)
	@RequestMapping(value = "/{expense-uid}", method = GET)
	@ApiOperation(value = "Find expense by uid")
	@ResponseStatus(OK)
	public Expense getExpenseByUid(@PathVariable("expense-uid") String uid) {

		return expenseService.findByUid(uid);
	}

	@PreAuthorize("hasRole('USER')")
	@RequestMapping(value = "/{expense-uid}", method = PUT)
	@ApiOperation(value = "Update the expense with the given uid.")
	@ResponseStatus(OK)
	public void updateExpense(@PathVariable("expense-uid") String uid, @RequestParam("accounting") String accounting) {

		expenseService.updateExpense(uid, accounting);
	}

	@PreAuthorize("hasRole('USER')")
	@RequestMapping(value = "/{expense-uid}", method = DELETE)
	@ApiOperation(value = "Delete the expense with the given uid", notes = "Delete the expense with the given uid.")
	@ResponseStatus(OK)
	public void deleteExpense(@PathVariable("expense-uid") String uid) {

		expenseService.delete(uid);
	}

	@PreAuthorize("hasAnyRole('PROF', 'FINANCE_ADMIN')")
	@RequestMapping(value = "/{expense-uid}/accept", method = PUT)
	@ApiOperation(value = "Accept the expense with the given uid.")
	@ResponseStatus(OK)
	public void acceptExpense(@PathVariable("expense-uid") String uid) {

		expenseService.acceptExpense(uid);
	}

	@PreAuthorize("hasRole('USER')")
	@RequestMapping(value = "/{expense-uid}/assign-to-prof", method = PUT)
	@ApiOperation(value = "Assign the expense with the given uid to the manager.")
	@ResponseStatus(OK)
	public void assignExpenseToProf(@PathVariable("expense-uid") String uid) {

		expenseService.assignExpenseToProf(uid);
	}

	@PreAuthorize("hasRole('FINANCE_ADMIN')")
	@RequestMapping(value = "/{expense-uid}/assign-to-me", method = PUT)
	@ApiOperation(value = "Assign the expense to the logged in user.")
	@ResponseStatus(OK)
	public void assignExpenseToMe(@PathVariable("expense-uid") String uid) {

		expenseService.assignExpenseToMe(uid);
	}

	@PreAuthorize("hasAnyRole('PROF', 'FINANCE_ADMIN')")
	@RequestMapping(value = "/{expense-uid}/reject", method = PUT)
	@ApiOperation(value = "Decline the expense with the given.")
	@ResponseStatus(OK)
	public void rejectExpense(@PathVariable("expense-uid") String uid, @RequestParam("comment") String comment) {

		expenseService.rejectExpense(uid, comment);
	}

	@PreAuthorize("hasRole('USER')")
	@RequestMapping(value = "/{expense-uid}/access-rights", method = GET)
	@ApiOperation(value = "Update the expense with the given uid.")
	@ResponseStatus(OK)
	public AccessRights getPermission(@PathVariable("expense-uid") String uid) {

		return expenseService.getAccessRights(uid);
	}

	@PreAuthorize("hasRole('USER')")
	@RequestMapping(value = "/{expense-uid}/expense-items", method = GET)
	@ApiOperation(value = "Find all expense-items of an expense for the currently logged in user")
	public Set<ExpenseItem> getAllExpenseItems(@PathVariable("expense-uid") String uid) {

		return expenseItemService.getExpenseItemsByExpenseUid(uid);
	}

	@PreAuthorize("hasRole('USER')")
	@JsonView(SummaryWithUid.class)
	@RequestMapping(value = "/{expense-uid}/expense-items", method = POST)
	@ApiOperation(value = "Create new expenseItem", notes = "Creates a new expenseItem for the specified expense. yyyy-MM-dd'T'HH:mm:ss.SSSZ, yyyy-MM-dd'T'HH:mm:ss.SSS'Z', EEE, dd MMM yyyy HH:mm:ss zzz, yyyy-MM-dd<br><br>{  \"date\": \"2015-06-06\",  \"costCategoryUid\": \"a353602d-50d0-4007-b134-7fdb42f23542\",  \"explanation\": \"blub\",  \"currency\": \"CHF\",  \"originalAmount\": 200,  \"project\": \"Testing of chuncks\"}")
	@ResponseStatus(CREATED)
	public ExpenseItem createExpenseItem(@PathVariable("expense-uid") String uid, @RequestBody ExpenseItemDto dto) {

		return expenseItemService.create(uid, dto);
	}
<commit_msg>accessRights method has to be public<commit_after>package ch.uzh.csg.reimbursement.rest;

import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.OK;
import static org.springframework.web.bind.annotation.RequestMethod.DELETE;
import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;
import static org.springframework.web.bind.annotation.RequestMethod.PUT;

import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
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.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import ch.uzh.csg.reimbursement.dto.AccessRights;
import ch.uzh.csg.reimbursement.dto.ExpenseItemDto;
import ch.uzh.csg.reimbursement.dto.SearchExpenseDto;
import ch.uzh.csg.reimbursement.model.Document;
import ch.uzh.csg.reimbursement.model.Expense;
import ch.uzh.csg.reimbursement.model.ExpenseItem;
import ch.uzh.csg.reimbursement.model.Token;
import ch.uzh.csg.reimbursement.service.ExpenseItemService;
import ch.uzh.csg.reimbursement.service.ExpenseService;
import ch.uzh.csg.reimbursement.service.TokenService;
import ch.uzh.csg.reimbursement.view.View;
import ch.uzh.csg.reimbursement.view.View.DashboardSummary;
import ch.uzh.csg.reimbursement.view.View.Summary;
import ch.uzh.csg.reimbursement.view.View.SummaryWithUid;

import com.fasterxml.jackson.annotation.JsonView;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/expenses")
@PreAuthorize("hasRole('USER')")
@Api(value = "Expense", description = "Authorization depends on state.")
public class ExpenseResource {

	@Autowired
	private ExpenseService expenseService;

	@Autowired
	private ExpenseItemService expenseItemService;

	@Autowired
	private TokenService tokenService;

	@PreAuthorize("hasRole('USER')")
	@JsonView(SummaryWithUid.class)
	@RequestMapping(method = POST)
	@ApiOperation(value = "Creates a new expense for currently logged in user")
	@ResponseStatus(CREATED)
	public Expense createExpense(@RequestParam("accounting") String accounting) {

		return expenseService.create(accounting);
	}

	@PreAuthorize("hasRole('USER')")
	@JsonView(DashboardSummary.class)
	@RequestMapping(method = GET)
	@ApiOperation(value = "Find all expenses for the currently logged in user")
	public Set<Expense> getExpenses() {

		return expenseService.findAllByCurrentUser();
	}

	@PreAuthorize("hasRole('USER')")
	@JsonView(Summary.class)
	@RequestMapping(value = "/{expense-uid}", method = GET)
	@ApiOperation(value = "Find expense by uid")
	@ResponseStatus(OK)
	public Expense getExpenseByUid(@PathVariable("expense-uid") String uid) {

		return expenseService.findByUid(uid);
	}

	@PreAuthorize("hasRole('USER')")
	@RequestMapping(value = "/{expense-uid}", method = PUT)
	@ApiOperation(value = "Update the expense with the given uid.")
	@ResponseStatus(OK)
	public void updateExpense(@PathVariable("expense-uid") String uid, @RequestParam("accounting") String accounting) {

		expenseService.updateExpense(uid, accounting);
	}

	@PreAuthorize("hasRole('USER')")
	@RequestMapping(value = "/{expense-uid}", method = DELETE)
	@ApiOperation(value = "Delete the expense with the given uid", notes = "Delete the expense with the given uid.")
	@ResponseStatus(OK)
	public void deleteExpense(@PathVariable("expense-uid") String uid) {

		expenseService.delete(uid);
	}

	@PreAuthorize("hasAnyRole('PROF', 'FINANCE_ADMIN')")
	@RequestMapping(value = "/{expense-uid}/accept", method = PUT)
	@ApiOperation(value = "Accept the expense with the given uid.")
	@ResponseStatus(OK)
	public void acceptExpense(@PathVariable("expense-uid") String uid) {

		expenseService.acceptExpense(uid);
	}

	@PreAuthorize("hasRole('USER')")
	@RequestMapping(value = "/{expense-uid}/assign-to-prof", method = PUT)
	@ApiOperation(value = "Assign the expense with the given uid to the manager.")
	@ResponseStatus(OK)
	public void assignExpenseToProf(@PathVariable("expense-uid") String uid) {

		expenseService.assignExpenseToProf(uid);
	}

	@PreAuthorize("hasRole('FINANCE_ADMIN')")
	@RequestMapping(value = "/{expense-uid}/assign-to-me", method = PUT)
	@ApiOperation(value = "Assign the expense to the logged in user.")
	@ResponseStatus(OK)
	public void assignExpenseToMe(@PathVariable("expense-uid") String uid) {

		expenseService.assignExpenseToMe(uid);
	}

	@PreAuthorize("hasAnyRole('PROF', 'FINANCE_ADMIN')")
	@RequestMapping(value = "/{expense-uid}/reject", method = PUT)
	@ApiOperation(value = "Decline the expense with the given.")
	@ResponseStatus(OK)
	public void rejectExpense(@PathVariable("expense-uid") String uid, @RequestParam("comment") String comment) {

		expenseService.rejectExpense(uid, comment);
	}

	@RequestMapping(value = "/{expense-uid}/access-rights", method = GET)
	@ApiOperation(value = "Update the expense with the given uid.")
	@ResponseStatus(OK)
	public AccessRights getPermission(@PathVariable("expense-uid") String uid) {

		return expenseService.getAccessRights(uid);
	}

	@PreAuthorize("hasRole('USER')")
	@RequestMapping(value = "/{expense-uid}/expense-items", method = GET)
	@ApiOperation(value = "Find all expense-items of an expense for the currently logged in user")
	public Set<ExpenseItem> getAllExpenseItems(@PathVariable("expense-uid") String uid) {

		return expenseItemService.getExpenseItemsByExpenseUid(uid);
	}

	@PreAuthorize("hasRole('USER')")
	@JsonView(SummaryWithUid.class)
	@RequestMapping(value = "/{expense-uid}/expense-items", method = POST)
	@ApiOperation(value = "Create new expenseItem", notes = "Creates a new expenseItem for the specified expense. yyyy-MM-dd'T'HH:mm:ss.SSSZ, yyyy-MM-dd'T'HH:mm:ss.SSS'Z', EEE, dd MMM yyyy HH:mm:ss zzz, yyyy-MM-dd<br><br>{  \"date\": \"2015-06-06\",  \"costCategoryUid\": \"a353602d-50d0-4007-b134-7fdb42f23542\",  \"explanation\": \"blub\",  \"currency\": \"CHF\",  \"originalAmount\": 200,  \"project\": \"Testing of chuncks\"}")
	@ResponseStatus(CREATED)
	public ExpenseItem createExpenseItem(@PathVariable("expense-uid") String uid, @RequestBody ExpenseItemDto dto) {

		return expenseItemService.create(uid, dto);
	}

{'fraction_non_alphanumeric': 0.135522838807097, 'fraction_numerical': 0.005285013212533031, 'mean_word_length': 6.50907029478458, 'pattern_counts': {'":': 12, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '4669576', 'n_tokens_mistral': 4409, 'n_tokens_neox': 4266, 'n_words': 804}