<commit_before>/**
 * JBoss, Home of Professional Open Source
 * Copyright Red Hat, Inc., and individual contributors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.aerogear.connectivity.rest;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Future;

import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;

import org.aerogear.connectivity.model.MobileApplicationInstance;
import org.aerogear.connectivity.model.PushApplication;
import org.aerogear.connectivity.model.SimplePushApplication;
import org.aerogear.connectivity.service.PushApplicationService;
import org.aerogear.connectivity.service.SenderService;
import org.aerogear.connectivity.service.SimplePushApplicationService;

import com.ning.http.client.AsyncHttpClient;

@Stateless
@Path("/sender")
@TransactionAttribute
public class SenderEndpoint {
    @Inject
    private PushApplicationService pushApplicationService;
    @Inject
    private SimplePushApplicationService simplePushApplicationService;


    @Inject
    private SenderService senderService;

    @POST
    @Path("/broadcast/{id}")
    @Consumes("application/json")
    public Response broadcast(Map<String, String> message, @PathParam("id") String pushApplicationId) {

        PushApplication pushApp = pushApplicationService.findPushApplicationById(pushApplicationId);
        senderService.broadcast(pushApp, message);

        return Response.status(200)
                .entity("Job submitted").build();
    }

    @Inject protected EntityManager entityManager;

    @POST
    @Path("/simplePush/broadcast/{id}") //TODO: URL name sucks
    @Consumes("application/json")
    public Response broadcastSimplePush(Map message, @PathParam("id") String simplePushId) {

        
        SimplePushApplication spa = simplePushApplicationService.findSimplePushApplicationById(simplePushId);
        String endpoint = spa.getPushNetworkURL();
        
        String version = (String) message.get("version");
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();

        Set<MobileApplicationInstance> instances = spa.getInstances();
        for (MobileApplicationInstance mobileApplicationInstance : instances) {
            
            if ("broadcast".equalsIgnoreCase(mobileApplicationInstance.getCategory())) {
                try {
                    Future<com.ning.http.client.Response> f =
                            asyncHttpClient.preparePut(endpoint + mobileApplicationInstance.getDeviceToken())
                              .addHeader("Accept", "application/x-www-form-urlencoded")
                              .setBody("version=" + Integer.parseInt(version))
                              .execute();

                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return Response.status(200)
                .entity("Job submitted").build();
    }
    
    

    @POST
    @Path("/simplePush/selected/{id}") //TODO: URL name sucks
    @Consumes("application/json")
    public Response notifyGivenChannels(Map message, @PathParam("id") String simplePushId) {
        
        
        SimplePushApplication spa = simplePushApplicationService.findSimplePushApplicationById(simplePushId);
        String endpoint = spa.getPushNetworkURL();
        
        String version = (String) message.get("version");
        List<String> channelIDList = (List<String>) message.get("channelIDs");
        
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
        
        for (String channelID : channelIDList) {

            try {
                Future<com.ning.http.client.Response> f =
                        asyncHttpClient.preparePut(endpoint + channelID)
                          .addHeader("Accept", "application/x-www-form-urlencoded")
                          .setBody("version=" + Integer.parseInt(version))
                          .execute();
                
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        asyncHttpClient.close();

        return Response.status(200)
                .entity("Job submitted").build();
    }
}
<commit_msg>Updating the selected endpoint for SimplePush<commit_after>/**
 * JBoss, Home of Professional Open Source
 * Copyright Red Hat, Inc., and individual contributors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.aerogear.connectivity.rest;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;

import org.aerogear.connectivity.model.MobileApplicationInstance;
import org.aerogear.connectivity.model.PushApplication;
import org.aerogear.connectivity.model.SimplePushApplication;
import org.aerogear.connectivity.service.PushApplicationService;
import org.aerogear.connectivity.service.SenderService;
import org.aerogear.connectivity.service.SimplePushApplicationService;

import com.ning.http.client.AsyncHttpClient;

@Stateless
@Path("/sender")
@TransactionAttribute
public class SenderEndpoint {
    @Inject
    private PushApplicationService pushApplicationService;
    @Inject
    private SimplePushApplicationService simplePushApplicationService;


    @Inject
    private SenderService senderService;

    @POST
    @Path("/broadcast/{id}")
    @Consumes("application/json")
    public Response broadcast(Map<String, String> message, @PathParam("id") String pushApplicationId) {

        PushApplication pushApp = pushApplicationService.findPushApplicationById(pushApplicationId);
        senderService.broadcast(pushApp, message);

        return Response.status(200)
                .entity("Job submitted").build();
    }

    @POST
    @Path("/simplePush/broadcast/{id}") //TODO: URL name sucks
    @Consumes("application/json")
    public Response broadcastSimplePush(Map message, @PathParam("id") String simplePushId) {

        
        SimplePushApplication spa = simplePushApplicationService.findSimplePushApplicationById(simplePushId);
        String endpoint = spa.getPushNetworkURL();
        
        String version = (String) message.get("version");
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();

        Set<MobileApplicationInstance> instances = spa.getInstances();
        for (MobileApplicationInstance mobileApplicationInstance : instances) {
            
            if ("broadcast".equalsIgnoreCase(mobileApplicationInstance.getCategory())) {
                try {
                            asyncHttpClient.preparePut(endpoint + mobileApplicationInstance.getDeviceToken())
                              .addHeader("Accept", "application/x-www-form-urlencoded")
                              .setBody("version=" + Integer.parseInt(version))
                              .execute();

                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return Response.status(200)
                .entity("Job submitted").build();
    }
    
    

    @POST
    @Path("/simplePush/selected/{id}") //TODO: URL name sucks
    @Consumes("application/json")
    public Response notifyGivenChannels(Map message, @PathParam("id") String simplePushId) {
        
        
        SimplePushApplication spa = simplePushApplicationService.findSimplePushApplicationById(simplePushId);
        String endpoint = spa.getPushNetworkURL();
        
        String version = (String) message.get("version");
        List<String> channelIDList = (List<String>) message.get("channelIDs");
        
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
        
        for (String channelID : channelIDList) {

            try {
                        asyncHttpClient.preparePut(endpoint + channelID)
                          .addHeader("Accept", "application/x-www-form-urlencoded")
                          .setBody("version=" + Integer.parseInt(version))
                          .execute();
                
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        return Response.status(200)
                .entity("Job submitted").build();
    }
}

{'fraction_non_alphanumeric': 0.09593398946217317, 'fraction_numerical': 0.0025847499751466348, 'mean_word_length': 2.6688548504741063, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, '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': '3871912', 'n_tokens_mistral': 2534, 'n_tokens_neox': 2468, 'n_words': 584}