Beispiel #1
0
        String requestClientIDByNet()
        {
            //String strBody = "";
            //TODO: send client register info in client create
            //        if ( ClientRegister.getInstance() != null )
            //            strBody += ClientRegister.getInstance().getRegisterBody();

            NetResponse resp = getNetClientID().pullData(getProtocol().getClientCreateUrl(), this);

            if (resp.isOK() && resp.getCharData() != null)
            {
                String szData = resp.getCharData();

                JSONEntry oJsonEntry = new JSONEntry(szData);

                //if (oJsonEntry.hasName("sources") )
                //    processServerSources(szData);

                JSONEntry oJsonObject = oJsonEntry.getEntry("client");
                if (!oJsonObject.isEmpty())
                {
                    return(oJsonObject.getString("client_id"));
                }
            }
            else
            {
                m_nErrCode = RhoAppAdapter.getErrorFromResponse(resp);
                if (m_nErrCode == RhoAppAdapter.ERR_NONE)
                {
                    m_nErrCode = RhoAppAdapter.ERR_UNEXPECTEDSERVERRESPONSE;
                    m_strError = resp.getCharData();
                }
            }

            return("");
        }
Beispiel #2
0
        public void processServerResponse_ver3(JSONArrayIterator oJsonArr)
        {
            PROF.START("Data1");

            int nVersion = 0;

            if (!oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("version"))
            {
                nVersion = oJsonArr.getCurItem().getInt("version");
                oJsonArr.next();
            }

            if (nVersion != getProtocol().getVersion())
            {
                LOG.ERROR("Sync server send data with incompatible version. Client version: " + getProtocol().getVersion() +
                          "; Server response version: " + nVersion + ". Source name: " + getName());
                getSync().stopSync();
                m_nErrCode = RhoAppAdapter.ERR_UNEXPECTEDSERVERRESPONSE;
                return;
            }

            if (!oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("token"))
            {
                processToken(oJsonArr.getCurItem().getUInt64("token"));
                oJsonArr.next();
            }

            if (!oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("source"))
            {
                //skip it. it uses in search only
                oJsonArr.next();
            }

            if (!oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("count"))
            {
                setCurPageCount(oJsonArr.getCurItem().getInt("count"));
                oJsonArr.next();
            }

            if (!oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("refresh_time"))
            {
                setRefreshTime(oJsonArr.getCurItem().getInt("refresh_time"));
                oJsonArr.next();
            }

            if (!oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("progress_count"))
            {
                //TODO: progress_count
                //setTotalCount(oJsonArr.getCurItem().getInt("progress_count"));
                oJsonArr.next();
            }

            if (!oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("total_count"))
            {
                setTotalCount(oJsonArr.getCurItem().getInt("total_count"));
                oJsonArr.next();
            }

            //if ( getServerObjectsCount() == 0 )
            //    getNotify().fireSyncNotification(this, false, RhoAppAdapter.ERR_NONE, "");

            if (getToken() == 0)
            {
                //oo conflicts
                getDB().executeSQL("DELETE FROM changed_values where source_id=? and sent>=3", getID());
                //
            }

            LOG.INFO("Got " + getCurPageCount() + "(Processed: " + getServerObjectsCount() + ") records of " + getTotalCount() + " from server. Source: " + getName()
                     + ". Version: " + nVersion);

            PROF.STOP("Data1");
            if (!oJsonArr.isEnd() && getSync().isContinueSync())
            {
                JSONEntry oCmds = oJsonArr.getCurItem();
                PROF.START("Data");

                if (oCmds.hasName("schema-changed"))
                {
                    getSync().setSchemaChanged(true);
                }
                else if (!processServerErrors(oCmds))
                {
                    getDB().startTransaction();

                    if (SyncEngine.getSourceOptions().getBoolProperty(getID(), "pass_through"))
                    {
                        if (m_bSchemaSource)
                        {
                            getDB().executeSQL("DELETE FROM " + getName());
                        }
                        else
                        {
                            getDB().executeSQL("DELETE FROM object_values WHERE source_id=?", getID());
                        }
                    }

                    if (oCmds.hasName("metadata") && getSync().isContinueSync())
                    {
                        String strMetadata = oCmds.getString("metadata");
                        getDB().executeSQL("UPDATE sources SET metadata=? WHERE source_id=?", strMetadata, getID());
                    }
                    if (oCmds.hasName("links") && getSync().isContinueSync())
                    {
                        processSyncCommand("links", oCmds.getEntry("links"), true);
                    }
                    if (oCmds.hasName("delete") && getSync().isContinueSync())
                    {
                        processSyncCommand("delete", oCmds.getEntry("delete"), true);
                    }
                    if (oCmds.hasName("insert") && getSync().isContinueSync())
                    {
                        processSyncCommand("insert", oCmds.getEntry("insert"), true);
                    }

                    PROF.STOP("Data");

                    PROF.START("DB");
                    getDB().endTransaction();
                    PROF.STOP("DB");

                    getNotify().fireObjectsNotification();
                }
            }

            PROF.START("Data1");
            if (getCurPageCount() > 0)
            {
                getNotify().fireSyncNotification(this, false, RhoAppAdapter.ERR_NONE, "");
            }
            PROF.STOP("Data1");
        }
Beispiel #3
0
        //{"create-error":{"0_broken_object_id":{"name":"wrongname","an_attribute":"error create"},"0_broken_object_id-error":{"message":"error create"}}}
        boolean processServerErrors(JSONEntry oCmds)
        {
            String[] arErrTypes = { "source-error", "search-error", "create-error", "update-error", "delete-error", null };
            boolean  bRes       = false;

            for (int i = 0; ; i++)
            {
                if (arErrTypes[i] == null)
                {
                    break;
                }
                if (!oCmds.hasName(arErrTypes[i]))
                {
                    continue;
                }

                bRes       = true;
                m_nErrCode = RhoAppAdapter.ERR_CUSTOMSYNCSERVER;

                JSONEntry          errSrc  = oCmds.getEntry(arErrTypes[i]);
                JSONStructIterator errIter = new JSONStructIterator(errSrc);
                for ( ; !errIter.isEnd(); errIter.next())
                {
                    String strKey = errIter.getCurKey();

                    if (i == 0 || i == 1)      //"source-error", "search-error"
                    {
                        if (errIter.getCurValue().hasName("message"))
                        {
                            if (m_strServerError.length() > 0)
                            {
                                m_strServerError += "&";
                            }

                            m_strServerError += "server_errors[" + URI.urlEncode(strKey) + "][message]=" + URI.urlEncode(errIter.getCurValue().getString("message"));
                        }
                    }
                    else
                    {
                        //"create-error", "update-error", "delete-error"
                        String strObject = strKey;

                        if (strObject.endsWith("-error"))
                        {
                            strObject = strObject.substring(0, strKey.length() - 6);
                            if (m_strServerError.length() > 0)
                            {
                                m_strServerError += "&";
                            }

                            m_strServerError += "server_errors[" + arErrTypes[i] + "][" + URI.urlEncode(strObject) + "][message]=" + URI.urlEncode(errIter.getCurValue().getString("message"));
                        }
                        else
                        {
                            JSONStructIterator attrIter = new JSONStructIterator(errIter.getCurValue());
                            for ( ; !attrIter.isEnd(); attrIter.next())
                            {
                                String strAttrName  = attrIter.getCurKey();
                                String strAttrValue = attrIter.getCurString();

                                if (m_strServerError.length() > 0)
                                {
                                    m_strServerError += "&";
                                }

                                m_strServerError += "server_errors[" + arErrTypes[i] + "][" + URI.urlEncode(strObject) + "][attributes][" + URI.urlEncode(strAttrName) + "]=" + URI.urlEncode(strAttrValue);
                            }
                        }
                    }
                }
            }

            return(bRes);
        }