Hi App42 Response app42 Response = gameService.delete Game ("Game_Name"); This code will cause an error. Please check!.

0 votes
Hi
App42 Response app42 Response = gameService.delete Game ("Game_Name");
This code will cause an error.
Please check!.
related to an answer for: Custom Code Management
asked Jan 12, 2016 in App42 Cloud API-BaaS by airfighter.pilot (10 points)
Hello,

Could you please share the error message which you are getting while running this method. It will help us to provide better support to you.

Regards.
Himanshu Sharma
Game Create Delete the entire code.
It should be deleted.
---------------------------------------------------
package com.shephertz.app42.paas.customcode.feelent;

import java.util.*;

import org.json.JSONException;
import org.json.JSONObject;

import com.shephertz.app42.paas.customcode.Executor;
import com.shephertz.app42.paas.customcode.HttpRequestObject;
import com.shephertz.app42.paas.customcode.HttpResponseObject;
import com.shephertz.app42.paas.sdk.java.App42Exception;
import com.shephertz.app42.paas.sdk.java.App42Response;
import com.shephertz.app42.paas.sdk.java.ServiceAPI;
import com.shephertz.app42.paas.sdk.java.log.LogService;
import com.shephertz.app42.paas.sdk.java.game.Game;
import com.shephertz.app42.paas.sdk.java.game.GameService;


public class GameCreateDeleteTest implements Executor
{

    private ServiceAPI sp = new ServiceAPI(    Constants.App42ApiKey, Constants.App42ApiSecret);
    private final int HTTP_STATUS_SUCCESS = 200;
    private String moduleName = "GameCreateDeleteTest";

   
    /**
     * Write your custom code inside this method
     */
    @Override
    public HttpResponseObject execute(HttpRequestObject request)
    {
        JSONObject body = request.getBody();

        // Build Log Service For logging in Your Code
        LogService logger = sp.buildLogService();
        logger.debug("Recieved Request Body :" + body.toString(), moduleName);       
       
        Game game = null;
        String rankName = "testGame";
        GameService gameService = sp.buildGameService();
           
        ArrayList<Game> gameList = gameService.getAllGames();
        for( int i = 0; i<gameList.size(); i++)
        {
            if( gameList.get(i).name.equals(rankName) )
            {
                try{
                    App42Response app42Response = gameService.deleteGame(rankName);
                    logger.debug("app42Response : " + app42Response.toString(), moduleName);
                }catch (App42Exception ee)
                {
                    logger.debug("App42Exception deleteGame: " + ee.toString(), moduleName);
                }
            }
        }
       
       
        try{               
            game = gameService.createGame( rankName, "des: " + rankName );
            logger.debug("game : " + game, moduleName);
        }
        catch (App42Exception ee)
        {
            logger.debug("App42Exception : " + ee.toString(), moduleName);
        }
           
               
        logger.debug("gameService : " + gameService, moduleName);
        logger.info("Running Custom Code Game Create Delete  ", moduleName);
       
        // Create JSON Response Based on Your business logic
        JSONObject jsonResponse = new JSONObject();
        try {
            jsonResponse.put("moduleName",  moduleName );
            //....//
        } catch (JSONException e) {
            // Do exception Handling for JSON Parsing
        }
        // Return JSON Response and Status Code
        return new HttpResponseObject(HTTP_STATUS_SUCCESS, jsonResponse);
    }
}

1 Answer

0 votes

Hello Developer,

 

Could you please call delete game function from this java file and let us know if it resolved your issue. 

In order to call function from attached java file, please use below code snippet:

App42GameService app42GameService = new App42GameService("APIKey","SecretKey");
app42GameService.deleteGame("Game Name");
 

Regards,

Himanshu Sharma

answered Jan 14, 2016 by hs00105 (2,005 points) 1 flag
It works fine.

Thank you very much.
Hi,

Great to know that your query has been resolved. Please let us know if you need any other help from my side.  I will be happy to address your concern.

Regards,
Himanshu Sharma
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...