<commit_before>package fi.nls.oskari.control.layer;

import org.oskari.service.util.ServiceFactory;

import fi.nls.oskari.annotation.OskariActionRoute;
import fi.nls.oskari.control.ActionDeniedException;
import fi.nls.oskari.control.ActionException;
import fi.nls.oskari.control.ActionHandler;
import fi.nls.oskari.control.ActionParameters;
import fi.nls.oskari.log.LogFactory;
import fi.nls.oskari.log.Logger;
import fi.nls.oskari.map.layer.DataProviderService;
import fi.nls.oskari.util.ConversionHelper;

/**
 * Admin WMS organization layer delete
 * 
 * 
 */
@OskariActionRoute("DeleteOrganization")
public class DeleteOrganizationHandler extends ActionHandler {

    private DataProviderService groupService = ServiceFactory.getDataProviderService();
    private static final Logger log = LogFactory.getLogger(DeleteOrganizationHandler.class);
    private static final String PARAM_GROUP_ID = "id";

    @Override
    public void handleAction(ActionParameters params) throws ActionException {

        final int groupId = ConversionHelper.getInt(params.getRequiredParam(PARAM_GROUP_ID), -1);
        
        if(!groupService.hasPermissionToUpdate(params.getUser(), groupId)) {
            throw new ActionDeniedException("Unauthorized user tried to remove layer group and its map layers - group id=" + groupId);
        }
       
        try {
            // cascade in db will handle that layers are deleted
            groupService.delete(groupId);
        } catch (Exception e) {
            throw new ActionException("Couldn't delete layer group and its map layers - id:" + groupId,
                    e);
        }
    }

}<commit_msg>Delete to respond with deleted dataprovider<commit_after>package fi.nls.oskari.control.layer;

import fi.nls.oskari.control.*;
import fi.nls.oskari.domain.map.DataProvider;
import fi.nls.oskari.util.ResponseHelper;
import org.oskari.service.util.ServiceFactory;

import fi.nls.oskari.annotation.OskariActionRoute;
import fi.nls.oskari.map.layer.DataProviderService;
import fi.nls.oskari.util.ConversionHelper;
import static fi.nls.oskari.control.ActionConstants.PARAM_ID;

/**
 * For deleting a dataprovider/organization
 */
@OskariActionRoute("DeleteOrganization")
public class DeleteOrganizationHandler extends ActionHandler {

    private DataProviderService groupService = ServiceFactory.getDataProviderService();

    @Override
    public void handleAction(ActionParameters params) throws ActionException {

        final int groupId = params.getRequiredParamInt(PARAM_ID);
        
        if(!groupService.hasPermissionToUpdate(params.getUser(), groupId)) {
            throw new ActionDeniedException("Unauthorized user tried to remove layer group and its map layers - group id=" + groupId);
        }

        try {
            DataProvider organization = groupService.find(groupId);
            if(organization == null) {
                throw new ActionParamsException("Dataprovider not found with id " + groupId);
            }
            // cascade in db will handle that layers are deleted
            groupService.delete(groupId);

            // write deleted organization as response
            ResponseHelper.writeResponse(params, organization.getAsJSON());
        } catch (Exception e) {
            throw new ActionException("Couldn't delete layer group and its map layers - id:" + groupId, e);
        }
    }

}
{'fraction_non_alphanumeric': 0.0874963050546852, 'fraction_numerical': 0.0002955956251847473, 'mean_word_length': 3.4293193717277486, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7664248', 'n_tokens_mistral': 940, 'n_tokens_neox': 917, 'n_words': 220}