1

Error during the creation of Geofence

Тема: Error during the creation of Geofence

Hello,
I would like to create Geofence via the API WIALON Java. But after execution my code I receive the following error Invalid input  (error 4).
My code.

public final static int CLEANUP_SESSION_NOW = 0x1;
public final static int LOGOUT_SERVER = 0x2;
public final static int CLEAN_SESSION_AT_CALLBACK= 0x4;

public WialonGeoZone()
    {
        session = Session.getInstance();
        logger.info("session it is initialize");
        sessionId = null;
        resourceId = -1;
    }

    public void login()
    {
        // TODO : Change logic implementation of this method
        logger.info("Beginning loginToken Wialon SDK");
        boolean b = session.initSession("http://hst-api.wialon.com");
        session.loginToken("251a59d6b516d93194ebc406b8a79d192943B81D1D19C5C8BFAF6108D2562501AFA95CF7",
                new ResponseHandler()
                {
                    @Override
                    public void onSuccess(String response)
                    {
                        super.onSuccess(response);
                        System.out.println(response);
                        logger.info("Login is executed with success");
                        logger.info("User Wialon it is "+session.getCurrUser().getName());
                        obtainSessionId();
                        searchResourceId();
                    }

                    @Override
                    public void onFailure(int errorCode, Throwable throwableError)
                    {
                        super.onFailure(errorCode, throwableError);
                        System.out.println(errorCode);
                        logger.info("Login is execute with error");
                        logger.info("Error code it is "+errorCode);
                        if(throwableError != null)
                            logger.error("Error loginToken is caused by "+throwableError.getMessage());
                        else
                            logger.error("Error loginToken. ThrowableError it is null");
                    }
                });
    }

    public void logout(int flags)
    {
        session.logout(flags, new ResponseHandler()
        {
            @Override
            public void onSuccess(String response)
            {
                super.onSuccess(response);
                logger.info("Logout is executed with success");
                logger.info("User Wialon it is "+session.getCurrUser().getName());
                System.out.print("Thread is terminate");
            }

            @Override
            public void onFailure(int errorCode, Throwable throwableError)
            {
                super.onFailure(errorCode, throwableError);
                logger.info("Logout is execute with error");
                logger.info("Logout Error code is : "+errorCode);
                if(throwableError != null)
                    logger.error("Logout Error loginToken is caused by "+throwableError.getMessage());
                else
                    logger.info("Logout ThrowableError it is null");
            }
        });
    }

    private void obtainSessionId()
    {
        if(session.getId() != null)
        {
            sessionId = session.getId();
            logger.info("SessionId it is : "+sessionId);
        }
    }

    private void searchResourceId()
    {
        // TODO : Verify method with unit test
        SearchSpec searchSpec = new SearchSpec();
        searchSpec.setItemsType(Item.ItemType.avl_resource);
        searchSpec.setPropName("sys_id");
        searchSpec.setPropValueMask("*");
        searchSpec.setSortType("sys_id");
        session.searchItems(searchSpec,3,Item.dataFlag.base.getValue(),0,Integer.MAX_VALUE,
                new SearchResponseHandler()
                {
                    @Override
                    public void onSuccessSearch(Item... items)
                    {
                        super.onSuccessSearch(items);
                        if(items != null && items.length > 0)
                        {
                            for(Item  resId : items)
                            {
                                WialonGeoZone.this.resourceId = resId.getId();
                                logger.info("Name Item : "+resId.getName());
                                logger.info("the resource Id it is = "+resId.getId());
                            }
                            String params = createJson("5.351970","-3.700000","words");
                            createWithRemoteCall(params);
                        }
                        else
                        {
                            logger.info("Items resource it is null or the Items size = 0");
                        }
                    }

                    @Override
                    public void onFailure(int errorCode, Throwable throwableError)
                    {
                        super.onFailure(errorCode, throwableError);
                        logger.error("Search Exception it is throw");
                        logger.error("Search Error code it is "+errorCode);
                        if(throwableError != null)
                            logger.error("Search Error code it is "+throwableError.getMessage());
                    }
                });
    }

public String createJsonString(String lat,String lng,String word)
    {
        if(resourceId != -1)
        {
            restGeo(lat,lng);
            JsonObject jsonObject = new JsonObject();
            jsonObject.addProperty("itemId",resourceId);
            jsonObject.addProperty("id","");
            jsonObject.addProperty("callMode","create");
            jsonObject.addProperty("n",word);
            jsonObject.addProperty("d","");
            jsonObject.addProperty("t",3);
            jsonObject.addProperty("w",20); // change later
            jsonObject.addProperty("f","zone");
            jsonObject.addProperty("c","");
            jsonObject.addProperty("tc","");
            jsonObject.addProperty("ts","12"); // change later
            jsonObject.addProperty("min",5); // change later
            jsonObject.addProperty("maw",5); // change later
            jsonObject.addProperty("path",""); // value it is a path of Icon
            jsonObject.addProperty("libId",0); // value it is library id
           // jsonObject.addProperty("oldItemId","");
           // jsonObject.addProperty("oldZoneId","");
            JsonObject jsonPosition = new JsonObject();
            jsonPosition.addProperty("x",lng);
            jsonPosition.addProperty("y",lat);
            jsonPosition.addProperty("r",1); // change later
            JsonArray jsonArray = new JsonArray();
            jsonArray.add(jsonPosition);
            jsonObject.add("p",jsonArray);
            System.out.println(jsonObject.toString());
            return jsonObject.toString();
        }
        return null;
    }

    public void createWithRemoteCall(String params)
    {
        RemoteHttpClient remoteHttpClient = RemoteHttpClient.getInstance();
        remoteHttpClient.remoteCall("resource/update_zone", params, new ResponseHandler()
        {
            @Override
            public void onSuccess(String response)
            {
                super.onSuccess(response);
                logger.info(response);
                logout(LOGOUT_SERVER);
            }

            @Override
            public void onFailure(int errorCode, Throwable throwableError)
            {
                super.onFailure(errorCode, throwableError);
                logger.error("Create Geofence is fail.\nError code it is : "+errorCode);
                if(throwableError !=null)
                    logger.error("Error message it is : "+throwableError.getMessage());
                else
                    logger.error("Error message it is nulll");
                logout(LOGOUT_SERVER);
            }
        });
    }

public static void main(String... args)
{
        WialonGeoZone wialonGeoZone = new WialonGeoZone();
        wialonGeoZone.login();
 }
2

Error during the creation of Geofence

Re: Error during the creation of Geofence

christian.amani, there are errors in Your parameters:
            jsonObject.addProperty("f","zone"); // flags, should be uint number
            jsonObject.addProperty("c",""); // color, should be uint number
            jsonObject.addProperty("tc",""); // text color, should be uint number
            jsonObject.addProperty("maw",5); // should be max

Head of Wialon Local Department
Gurtam
3

Error during the creation of Geofence

Re: Error during the creation of Geofence

Thank you for the answer indeed the error was situated at the level of the parameters. But I have another problem, I would want to know if the field id can be automatically incremented at the level of the server.

jsonObject.addProperty("id",1); //Value, should long

When I fix the value of id to 1. I receive the error 7.

Can we generate the code id since the server ?

4

Error during the creation of Geofence

Re: Error during the creation of Geofence

christian.amani, parameter id is not necessary in callMode "create".
Parameter id is automatically incremented on server and it is returned in response.
You can't set your own id to items or propitems. They are assigning on server and can't be changed.

Head of Wialon Local Department
Gurtam
5

Error during the creation of Geofence

Re: Error during the creation of Geofence

But I always obtain the error 4 with these parameters.

Code for the creation of parameters.

public String createJson()
    {
        if(resourceId != -1)
        {
            String word = "word";
            String lng = -3.7134;
            String lat = 5.3519;
            JsonObject jsonObject = new JsonObject();
            jsonObject.addProperty("itemId",resourceId); // itemId it is 14047455
            jsonObject.addProperty("callMode","create");
            jsonObject.addProperty("n",word);
            jsonObject.addProperty("d","");
            jsonObject.addProperty("t",3);
            jsonObject.addProperty("w",20); 
            jsonObject.addProperty("f",0x20); // decimal it is 32
            jsonObject.addProperty("c",0102112255);
            jsonObject.addProperty("tc",0000); // A 0 R:0 G: 0 B: 0 color black
            jsonObject.addProperty("ts",12); // change later
            jsonObject.addProperty("min",1); // change later
            jsonObject.addProperty("max",5); // change later
            jsonObject.addProperty("path","");
            jsonObject.addProperty("libId","");
            JsonObject jsonPosition = new JsonObject();
            jsonPosition.addProperty("x",Double.valueOf(lng));  // x it is -3.7134
            jsonPosition.addProperty("y",Double.valueOf(lat)); // y it is 5.3519
            jsonPosition.addProperty("r",1);
            JsonArray jsonArray = new JsonArray();
            jsonArray.add(jsonPosition);
            jsonObject.add("p",jsonArray);
            System.out.println(jsonObject.toString());
            return jsonObject.toString();
        }
        return null;
    }

Code of request

public void createWithRemoteCall(String params)
    {
        final int LOGOUT_SERVER = 0x2;
        RemoteHttpClient remoteHttpClient = RemoteHttpClient.getInstance();
        remoteHttpClient.remoteCall("resource/update_zone", params, new ResponseHandler()
        {
            @Override
            public void onSuccess(String response)
            {
                super.onSuccess(response);
                logger.info(response);
                logout(LOGOUT_SERVER);
            }

            @Override
            public void onFailure(int errorCode, Throwable throwableError)
            {
                super.onFailure(errorCode, throwableError);
                logger.error("Create Geofence is fail.\nError code it is : "+errorCode);
                if(throwableError !=null)
                    logger.error("Error message it is : "+throwableError.getMessage());
                else
                    logger.error("Error message it is nulll");
                logout(LOGOUT_SERVER);
            }
        });
    }
6

Error during the creation of Geofence

Re: Error during the creation of Geofence

christian.amani, Your parameters are ok. Just add:
jsonObject.addProperty("id", 0)
Small clarification - parameter "id" is necessary but it's value doesn't matter in creation mode.

Head of Wialon Local Department
Gurtam
7

Error during the creation of Geofence

Re: Error during the creation of Geofence

One needs special accesses for the creation of Geofence or which type of account is necessary it to have to be able to create Geofence ?
I receive error 7.
My new code.

public String createJson()
    {
        if(resourceId != -1)
        {
            String word = "word";
            String lng = -3.7134;
            String lat = 5.3519;
            JsonObject jsonObject = new JsonObject();
            jsonObject.addProperty("itemId",resourceId); // itemId it is 14047455
            jsonObject.addProperty("id",0);
            jsonObject.addProperty("callMode","create");
            jsonObject.addProperty("n",word);
            jsonObject.addProperty("d","");
            jsonObject.addProperty("t",3);
            jsonObject.addProperty("w",20); 
            jsonObject.addProperty("f",0x20); // decimal it is 32
            jsonObject.addProperty("c",0102112255);
            jsonObject.addProperty("tc",0000); // A 0 R:0 G: 0 B: 0 color black
            jsonObject.addProperty("ts",12); // change later
            jsonObject.addProperty("min",1); // change later
            jsonObject.addProperty("max",5); // change later
            jsonObject.addProperty("path","");
            jsonObject.addProperty("libId","");
             JsonObject jsonPosition = new JsonObject();
            jsonPosition.addProperty("x",Double.valueOf(lng));  // x it is -3.7134
            jsonPosition.addProperty("y",Double.valueOf(lat)); // y it is 5.3519
            jsonPosition.addProperty("r",1);
            JsonArray jsonArray = new JsonArray();
            jsonArray.add(jsonPosition);
            jsonObject.add("p",jsonArray);
            System.out.println(jsonObject.toString());
            return jsonObject.toString();
        }
        return null;
    }

The json result.

{"itemId":14047455,"id":0,"callMode":"create","n":"words","d":"","t":3,"w":20,"f":32,"c":17339565,"tc":0,"ts":12,"min":1,"max":5,"path":"","libId":"","p":[{"x":-3.7134,"y":5.3519,"r":1}]}

I to create my token with an account signal manager.
The account which comes after that from the super account admin.

8

Error during the creation of Geofence

Re: Error during the creation of Geofence

christian.amani, first of all to create geofences Your user should have enough access rights to resource (at least 0x0001 - View item and its basic properties, 0x0000001000000 - View geofences, 0x0000002000000 - Create, edit, and delete geofences) http://sdk.wialon.com/wiki/en/sidebar/r … ms_billing
Also Your token should be created with at least 0x400 access_type flag.

Head of Wialon Local Department
Gurtam
9

Error during the creation of Geofence

Re: Error during the creation of Geofence

I receive a empty array.
That means you it that I do not have the right to create resources?
My code.

private void viewAccess()
    {
        JsonObject params = new JsonObject();
        JsonArray itemArray = new JsonArray();
        itemArray.add(resourceId);
        params.add("items",itemArray);
        params.addProperty("accessFlags",0x0000002000000);
        params.addProperty("serviceName","create_resources");
        System.out.println(params.toString());
        RemoteHttpClient remoteHttpClient = RemoteHttpClient.getInstance();
        remoteHttpClient.remoteCall("core/check_items_billing", params, new ResponseHandler()
        {
            @Override
            public void onSuccess(String response)
            {
                super.onSuccess(response);
                logger.info(response);
                logout(LOGOUT_SERVER);
            }

            @Override
            public void onFailure(int errorCode, Throwable throwableError)
            {
                super.onFailure(errorCode, throwableError);
                logger.error("Create Geofence is fail.\nError code it is : "+errorCode);
                if(throwableError !=null)
                    logger.error("Error message it is : "+throwableError.getMessage());
                else
                    logger.error("Error message it is nulll");
                logout(LOGOUT_SERVER);
            }
        });
    }

the result on consol.

[pool-1-thread-2] INFO transplus.services.WialonGeoZone - []

when I replace the value of item of the accessFlags by 0x0001

params.addProperty("accessFlags",0x0001);

I this value [ 14047455 ] obtains.

10

Error during the creation of Geofence

Re: Error during the creation of Geofence

I go asked the accesses to the which I have access in near the one who to create the account.
And I shall make for you a feedback.

11

Error during the creation of Geofence

(18/07/2016 17:26:01 отредактировано deal)

Re: Error during the creation of Geofence

christian.amani, if You had access rights to create geofences in this resource - resulting array would contain id of Your resource.

Head of Wialon Local Department
Gurtam
12

Error during the creation of Geofence

Re: Error during the creation of Geofence

Thank you for having helped me. I finally resolved my problem.

13

Error during the creation of Geofence

Re: Error during the creation of Geofence

This is the great solution you have provided. i appreciate you for this help. i have some doubts in other code. but i am trying to solve myself. If i could not solve it then i will post my code.

14

Error during the creation of Geofence

Re: Error during the creation of Geofence

christian.amani

Hi Christian.amani

I have the same problem, I have a question about position of code for have access a unit, help me please.

15

Error during the creation of Geofence

Re: Error during the creation of Geofence

You created Token with which flag ?
For more information on flags concerning Token I invite you to go on this page http://sdk.wialon.com/wiki/en/sidebar/r … cess_flags.

An example of search of unit to supply by Gurtam http://sdk.wialon.com/wiki/en/sidebar/j … les/search.
For the item search to go on this page http://sdk.wialon.com/wiki/en/sidebar/r … arch_items .

Describe better what you would want to make.

16

Error during the creation of Geofence

Re: Error during the creation of Geofence

christian.amani

I create Token with flag -1 but on moment of development the JsonObject the message that show is "Invalid service", some suggest, thanks for the answer.

17

Error during the creation of Geofence

Re: Error during the creation of Geofence

Please show your code.

18

Error during the creation of Geofence

Re: Error during the creation of Geofence

christian.amani

Thanks, I had a error of flag in URL but the problem was resolved.
Thank you very much, sorry.