package fi.nls.oskari.control.myplaces.handler;

import fi.nls.oskari.annotation.OskariActionRoute;
import fi.nls.oskari.control.ActionException;
import fi.nls.oskari.control.ActionParameters;
import fi.nls.oskari.control.RestActionHandler;
import fi.nls.oskari.domain.User;
import fi.nls.oskari.log.LogFactory;
import fi.nls.oskari.log.Logger;
import fi.nls.oskari.myplaces.MyPlacesService;
import fi.nls.oskari.service.OskariComponentManager;
import fi.nls.oskari.util.ConversionHelper;
import fi.nls.oskari.util.ResponseHelper;

@OskariActionRoute("PublishMyPlaceLayer")
public class PublishMyPlaceLayerHandler extends RestActionHandler {

    private MyPlacesService myPlaceService = null;
    private static final Logger log = LogFactory.getLogger(PublishMyPlaceLayerHandler.class);

    public void init() {
        myPlaceService = OskariComponentManager.getComponentOfType(MyPlacesService.class);
    }
    @Override
    public void handlePost(ActionParameters params) throws ActionException {
        final User user = params.getUser();
        final long id = ConversionHelper.getLong(params.getRequest().getParameter("id"), -1);
        if(id == -1) {
            throw new ActionException("Missing id for category publish");
        }
        
        final String makePublicStr = params.getHttpParam("makePublic");
        if(makePublicStr == null) {
            throw new ActionException("Missing boolean for category publish");
        }
        
        final String uuid = user.getUuid();
        String name = null;
        if (ConversionHelper.getBoolean(makePublicStr, false)) {
            name = user.getScreenname();
        }
        
        // SQL update checks that the categories id matches the users
        // to unpublish the name is left as null
        final long updatedRows = myPlaceService.updatePublisherName(id, uuid, name);
        log.debug("Published category:", id, "- uuid:", uuid, "- name", name, " -> updated rows", updatedRows);
        
        ResponseHelper.writeResponse(params, updatedRows == 1);
    }
}

@@ -1035,24 +1035,25 @@
 .getUser();%0A
+%0A
         fina
@@ -1068,193 +1068,42 @@
 d = 
-ConversionHelper.getLong(params.getRequest().getParameter(%22id%22), -1);%0A        if(id == -1) %7B%0A            throw new ActionException(%22Missing id for category publish%22);%0A        %7D%0A        
+params.getRequiredParamLong(%22id%22);
 %0A   
@@ -1150,12 +1150,16 @@
 .get
-Http
+Required
 Para
@@ -1179,133 +1179,8 @@
 %22);%0A
-        if(makePublicStr == null) %7B%0A            throw new ActionException(%22Missing boolean for category publish%22);%0A        %7D%0A
     

Use existing param checks