<commit_before>package org.axway.grapes.server.webapp.resources;

import com.yammer.dropwizard.auth.Auth;
import org.axway.grapes.commons.api.ServerAPI;
import org.axway.grapes.commons.datamodel.Artifact;
import org.axway.grapes.commons.datamodel.Dependency;
import org.axway.grapes.commons.datamodel.License;
import org.axway.grapes.commons.datamodel.Module;
import org.axway.grapes.server.config.GrapesServerConfig;
import org.axway.grapes.server.core.ArtifactHandler;
import org.axway.grapes.server.core.options.FiltersHolder;
import org.axway.grapes.server.core.options.filters.CorporateFilter;
import org.axway.grapes.server.core.reports.DependencyReport;
import org.axway.grapes.server.db.DataUtils;
import org.axway.grapes.server.db.RepositoryHandler;
import org.axway.grapes.server.db.datamodel.*;
import org.axway.grapes.server.db.datamodel.DbCredential.AvailableRoles;
import org.axway.grapes.server.webapp.DataValidator;
import org.axway.grapes.server.webapp.views.*;
import org.eclipse.jetty.http.HttpStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import java.net.URL;
import java.util.*;

/**
 * Module Resource
 *
 * <p>This server resource handles all the request about modules.<br/>
 * This resource extends DepManViews to holds its own documentation.
 * The documentation is available in ModuleResourceDocumentation.ftl file.</p>
 * @author jdcoffre
 */

@Path(ServerAPI.MODULE_RESOURCE)
public class ModuleResource extends AbstractResource{

    private static final Logger LOG = LoggerFactory.getLogger(ModuleResource.class);


    public ModuleResource(final RepositoryHandler repoHandler, final GrapesServerConfig dmConfig) {
        super(repoHandler, "ModuleResourceDocumentation.ftl", dmConfig);
    }

    /**
     * Handle the update/addition of a module in Grapes database
     *
     * @param credential DbCredential
     * @param module Module
     * @return Response
     */
    @POST
    @Produces(MediaType.TEXT_HTML)
    public Response postModule(@Auth final DbCredential credential, final Module module){
        if(!credential.getRoles().contains(AvailableRoles.DEPENDENCY_NOTIFIER)){
            throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).build());
        }

        LOG.info("Got a post Module request.");

        // Checks if the data is corrupted
        DataValidator.validate(module);

        // turn it into DbModel
        final DbModule dbModule = getModelMapper().getDbModule(module);<commit_msg>Updating the protection against module being null.<commit_after>package org.axway.grapes.server.webapp.resources;

import com.yammer.dropwizard.auth.Auth;
import org.axway.grapes.commons.api.ServerAPI;
import org.axway.grapes.commons.datamodel.Artifact;
import org.axway.grapes.commons.datamodel.Dependency;
import org.axway.grapes.commons.datamodel.License;
import org.axway.grapes.commons.datamodel.Module;
import org.axway.grapes.server.config.GrapesServerConfig;
import org.axway.grapes.server.core.ArtifactHandler;
import org.axway.grapes.server.core.options.FiltersHolder;
import org.axway.grapes.server.core.options.filters.CorporateFilter;
import org.axway.grapes.server.core.reports.DependencyReport;
import org.axway.grapes.server.db.DataUtils;
import org.axway.grapes.server.db.RepositoryHandler;
import org.axway.grapes.server.db.datamodel.*;
import org.axway.grapes.server.db.datamodel.DbCredential.AvailableRoles;
import org.axway.grapes.server.webapp.DataValidator;
import org.axway.grapes.server.webapp.views.*;
import org.eclipse.jetty.http.HttpStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import java.net.URL;
import java.util.*;

/**
 * Module Resource
 *
 * <p>This server resource handles all the request about modules.<br/>
 * This resource extends DepManViews to holds its own documentation.
 * The documentation is available in ModuleResourceDocumentation.ftl file.</p>
 * @author jdcoffre
 */

@Path(ServerAPI.MODULE_RESOURCE)
public class ModuleResource extends AbstractResource{

    private static final Logger LOG = LoggerFactory.getLogger(ModuleResource.class);


    public ModuleResource(final RepositoryHandler repoHandler, final GrapesServerConfig dmConfig) {
        super(repoHandler, "ModuleResourceDocumentation.ftl", dmConfig);
    }

    /**
     * Handle the update/addition of a module in Grapes database
     *
     * @param credential DbCredential
     * @param module Module
     * @return Response
     */
    @POST
    @Produces(MediaType.TEXT_HTML)
    public Response postModule(@Auth final DbCredential credential, final Module module){
        if(!credential.getRoles().contains(AvailableRoles.DEPENDENCY_NOTIFIER)){
            throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).build());
        }

        LOG.info(String.format("Got a post Module request [%s]", module == null ? "NULL" : module.getName()));

        // Checks if the data is corrupted
        DataValidator.validate(module);

        // turn it into DbModel
        final DbModule dbModule = getModelMapper().getDbModule(module);
{'fraction_non_alphanumeric': 0.10635155096011817, 'fraction_numerical': 0.0007385524372230429, 'mean_word_length': 4.4224224224224224, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '6819750', 'n_tokens_mistral': 1677, 'n_tokens_neox': 1670, 'n_words': 328}