<commit_before>package internal.org.springframework.content.rest.controllers;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;

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

import internal.org.springframework.content.rest.annotations.ContentRestController;
import internal.org.springframework.content.rest.io.RenderableResource;
import internal.org.springframework.content.rest.io.RenderedResource;
import internal.org.springframework.content.rest.mappings.StoreByteRangeHttpRequestHandler;
import internal.org.springframework.content.rest.utils.HeaderUtils;
import internal.org.springframework.content.rest.utils.RepositoryUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.content.commons.storeservice.ContentStoreService;
import org.springframework.content.rest.controllers.ContentService;
import org.springframework.context.ApplicationContext;
import org.springframework.core.io.Resource;
import org.springframework.data.repository.core.RepositoryInformation;
import org.springframework.data.repository.support.DefaultRepositoryInvokerFactory;
import org.springframework.data.repository.support.Repositories;
import org.springframework.data.repository.support.RepositoryInvokerFactory;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.util.ReflectionUtils;
import org.springframework.web.HttpRequestMethodNotSupportedException;
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.context.request.ServletWebRequest;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.server.ResponseStatusException;

import static java.lang.String.format;

import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

@ContentRestController
public class StoreRestController implements InitializingBean  {

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

    private static final String STORE_REQUEST_MAPPING = "/{store}/**";

    @Autowired
    ApplicationContext context;
    @Autowired(required=false)
    private Repositories repositories;
    @Autowired
    private ContentStoreService storeService;
    @Autowired
    private StoreByteRangeHttpRequestHandler handler;
    @Autowired(required=false)
    private RepositoryInvokerFactory repoInvokerFactory;
    @Autowired(required=false)
    private PlatformTransactionManager ptm;

    public StoreRestController() {
    }

    @RequestMapping(value = STORE_REQUEST_MAPPING, method = RequestMethod.GET)
    public void getContent(HttpServletRequest request,
            HttpServletResponse response,
            @RequestHeader(value = "Accept", required = false) String requestedMimeTypes,
            Resource resource,
            MediaType resourceType,
            Object resourceETag) {

        if (resource == null || resource.exists() == false) {
            throw new ResourceNotFoundException();
        }

        long lastModified = -1;
        try {
            lastModified = resource.lastModified();
        } catch (IOException e) {}
        if(new ServletWebRequest(request, response).checkNotModified(resourceETag != null ? resourceETag.toString() : null, lastModified)) {
            return;
        }


        TransactionStatus status = null;
        try {
            if (ptm != null) {
                status = ptm.getTransaction(new DefaultTransactionDefinition());
            }

            // if a rendition was requested, prep it now
            MediaType renderedResourceType = resourceType;
            if (resource instanceof RenderableResource) {

                List<MediaType> mimeTypes = new ArrayList<>(MediaType.parseMediaTypes(requestedMimeTypes));
                if (mimeTypes.size() == 0) {
                    mimeTypes.add(MediaType.ALL);
                }

                MediaType.sortBySpecificityAndQuality(mimeTypes);
                for (MediaType requestedMimeType : mimeTypes) {
                    if (((RenderableResource) resource).isRenderableAs(requestedMimeType)) {
                        resource = new RenderedResource(((RenderableResource) resource).renderAs(requestedMimeType), resource);
                        renderedResourceType = requestedMimeType;
                        break;
                    } else if (requestedMimeType.includes(resourceType)) {
                        renderedResourceType = resourceType;
                        break;
                    }
                }
            }

            request.setAttribute("SPRING_CONTENT_RESOURCE", resource);
            request.setAttribute("SPRING_CONTENT_CONTENTTYPE", renderedResourceType);

            if (status != null && status.isCompleted() == false) {
                ptm.commit(status);
            }
        } catch (Exception e) {
            
            logger.error("Unable to retrieve rendition", e);
            
            if (status != null) {
                ptm.rollback(status);
            }
<commit_msg>Refactor variable names to clarify code<commit_after>package internal.org.springframework.content.rest.controllers;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;

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

import internal.org.springframework.content.rest.annotations.ContentRestController;
import internal.org.springframework.content.rest.io.RenderableResource;
import internal.org.springframework.content.rest.io.RenderedResource;
import internal.org.springframework.content.rest.mappings.StoreByteRangeHttpRequestHandler;
import internal.org.springframework.content.rest.utils.HeaderUtils;
import internal.org.springframework.content.rest.utils.RepositoryUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.content.commons.storeservice.ContentStoreService;
import org.springframework.content.rest.controllers.ContentService;
import org.springframework.context.ApplicationContext;
import org.springframework.core.io.Resource;
import org.springframework.data.repository.core.RepositoryInformation;
import org.springframework.data.repository.support.DefaultRepositoryInvokerFactory;
import org.springframework.data.repository.support.Repositories;
import org.springframework.data.repository.support.RepositoryInvokerFactory;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.util.ReflectionUtils;
import org.springframework.web.HttpRequestMethodNotSupportedException;
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.context.request.ServletWebRequest;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.server.ResponseStatusException;

import static java.lang.String.format;

import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

@ContentRestController
public class StoreRestController implements InitializingBean  {

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

    private static final String STORE_REQUEST_MAPPING = "/{store}/**";

    @Autowired
    ApplicationContext context;
    @Autowired(required=false)
    private Repositories repositories;
    @Autowired
    private ContentStoreService storeService;
    @Autowired
    private StoreByteRangeHttpRequestHandler handler;
    @Autowired(required=false)
    private RepositoryInvokerFactory repoInvokerFactory;
    @Autowired(required=false)
    private PlatformTransactionManager ptm;

    public StoreRestController() {
    }

    @RequestMapping(value = STORE_REQUEST_MAPPING, method = RequestMethod.GET)
    public void getContent(HttpServletRequest request,
            HttpServletResponse response,
            @RequestHeader(value = "Accept", required = false) String requestedMimeTypes,
            Resource resource,
            MediaType resourceType,
            Object resourceETag) {

        if (resource == null || resource.exists() == false) {
            throw new ResourceNotFoundException();
        }

        long lastModified = -1;
        try {
            lastModified = resource.lastModified();
        } catch (IOException e) {}
        if(new ServletWebRequest(request, response).checkNotModified(resourceETag != null ? resourceETag.toString() : null, lastModified)) {
            return;
        }


        TransactionStatus status = null;
        try {
            if (ptm != null) {
                status = ptm.getTransaction(new DefaultTransactionDefinition());
            }

            // if a rendition was requested, prep it now
            MediaType producedResourceType = resourceType;
            if (resource instanceof RenderableResource) {

                List<MediaType> acceptedMimeTypes = new ArrayList<>(MediaType.parseMediaTypes(requestedMimeTypes));
                if (acceptedMimeTypes.size() == 0) {
                    acceptedMimeTypes.add(MediaType.ALL);
                }

                MediaType.sortBySpecificityAndQuality(acceptedMimeTypes);
                for (MediaType acceptedMimeType : acceptedMimeTypes) {
                    if (((RenderableResource) resource).isRenderableAs(acceptedMimeType)) {
                        resource = new RenderedResource(((RenderableResource) resource).renderAs(acceptedMimeType), resource);
                        producedResourceType = acceptedMimeType;
                        break;
                    } else if (acceptedMimeType.includes(resourceType)) {
                        producedResourceType = resourceType;
                        break;
                    }
                }
            }

            request.setAttribute("SPRING_CONTENT_RESOURCE", resource);
            request.setAttribute("SPRING_CONTENT_CONTENTTYPE", producedResourceType);

            if (status != null && status.isCompleted() == false) {
                ptm.commit(status);
            }
        } catch (Exception e) {
            
            logger.error("Unable to retrieve rendition", e);
            
            if (status != null) {
                ptm.rollback(status);
            }

{'fraction_non_alphanumeric': 0.08395188123880215, 'fraction_numerical': 0.0006825356198276597, 'mean_word_length': 3.4200603318250375, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5665828', 'n_tokens_mistral': 2829, 'n_tokens_neox': 2779, 'n_words': 525}