Exemplo n.º 1
0
     public JSONStructIterator(JSONEntry oEntry)
     {
 	    m_object = oEntry.getObject();
         m_enumStruct = m_object.GetEnumerator();
         if (m_enumStruct.MoveNext())
             m_strCurKey = m_enumStruct.Current.Key;
     }
Exemplo n.º 2
0
     public JSONStructIterator(JSONEntry oEntry, String strName)
     {
 	    m_object = (Dictionary<string, object>)oEntry.getObject(strName);
         m_enumStruct = m_object.GetEnumerator();
         if (m_enumStruct.MoveNext())
             m_strCurKey = m_enumStruct.Current.Key;
     }
Exemplo n.º 3
0
 public JSONStructIterator(JSONEntry oEntry)
 {
     m_object     = oEntry.getObject();
     m_enumStruct = m_object.GetEnumerator();
     if (m_enumStruct.MoveNext())
     {
         m_strCurKey = m_enumStruct.Current.Key;
     }
 }
Exemplo n.º 4
0
 public JSONStructIterator(JSONEntry oEntry, String strName)
 {
     m_object     = (Dictionary <string, object>)oEntry.getObject(strName);
     m_enumStruct = m_object.GetEnumerator();
     if (m_enumStruct.MoveNext())
     {
         m_strCurKey = m_enumStruct.Current.Key;
     }
 }
Exemplo n.º 5
0
 public JSONArrayIterator(JSONEntry oEntry, String strName)
 {
     m_array    = (List <Object>)oEntry.getObject(strName);
     m_nCurItem = 0;
 }
Exemplo n.º 6
0
	    void processSyncCommand(String strCmd, JSONEntry oCmdEntry, boolean bCheckUIRequest)
	    {
	        JSONStructIterator objIter = new JSONStructIterator(oCmdEntry);

	        for( ; !objIter.isEnd() && getSync().isContinueSync(); objIter.next() )
	        {
	            String strObject = objIter.getCurKey();
	            JSONStructIterator attrIter = new JSONStructIterator( objIter.getCurValue() );
	        
	            try
	            {
		            if ( m_bSchemaSource )
		                processServerCmd_Ver3_Schema(strCmd,strObject,attrIter);
		            else
		            {
		                for( ; !attrIter.isEnd() && getSync().isContinueSync(); attrIter.next() )
		                {
		                    String strAttrib = attrIter.getCurKey();
		                    String strValue = attrIter.getCurString();
	
		                    processServerCmd_Ver3(strCmd,strObject,strAttrib,strValue);
		                }
		            }
	            }catch(DBException exc)
		        {
		    	    LOG.ERROR("Sync of server changes failed for " + getName() + ";object: " + strObject, exc);
		        }
		    
	            if ( getSyncType().compareTo("none") == 0 )
	        	    continue;
	        
	            if ( bCheckUIRequest )
	            {
		            int nSyncObjectCount  = getNotify().incLastSyncObjectCount(getID());
		            if ( getProgressStep() > 0 && (nSyncObjectCount%getProgressStep() == 0) )
		                getNotify().fireSyncNotification(this, false, RhoAppAdapter.ERR_NONE, "");
		        
		            if ( getDB().isUIWaitDB() )
		            {
			            LOG.INFO("Commit transaction because of UI request.");
		                getDB().endTransaction();
		                SyncThread.sleep(1000);
		                getDB().startTransaction();
		            }
	            }
	        }
	    }
Exemplo n.º 7
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;
	    }
Exemplo n.º 8
0
        public void applyChangedValues()
	    {
	        String strBody = makePushBody_Ver3("create", false);
	        if ( strBody != null && strBody.length() > 0 )
	        {
	            JSONEntry oEntry = new JSONEntry(strBody);
	            processSyncCommand("insert", oEntry, false );
	        }

	        strBody = makePushBody_Ver3("delete", false);
	        if ( strBody != null && strBody.length() > 0 )
	        {
	            JSONEntry oEntry = new JSONEntry(strBody);
	            processSyncCommand("delete", oEntry, false );
	        }

	        strBody = makePushBody_Ver3("update", false);
	        if ( strBody != null && strBody.length() > 0 )
	        {
	            JSONEntry oEntry = new JSONEntry(strBody);
	            processSyncCommand("insert", oEntry, false );
	        }
	    }
Exemplo n.º 9
0
	    public JSONArrayIterator(JSONEntry oEntry, String strName)
	    {
	        m_array = (List<Object>)oEntry.getObject(strName);
	        m_nCurItem = 0;
	    }
Exemplo n.º 10
0
	    void loadBulkPartition(String strPartition )
	    {
		    DBAdapter dbPartition = getDB(strPartition); 		
	        String serverUrl = RhoConf.getInstance().getPath("syncserver");
	        String strUrl = serverUrl + "bulk_data";
	        String strQuery = "?client_id=" + m_clientID + "&partition=" + strPartition;
	        String strDataUrl = "", strCmd = "", strCryptKey = "";

	        getNotify().fireBulkSyncNotification(false, "start", strPartition, RhoAppAdapter.ERR_NONE);
	    
	        while(strCmd.length() == 0&&isContinueSync())
	        {	    
	            NetResponse resp = getNet().pullData(strUrl+strQuery, this);
	            if ( !resp.isOK() || resp.getCharData() == null )
	            {
	    	        LOG.ERROR( "Bulk sync failed: server return an error." );
	    	        stopSync();
	    	        getNotify().fireBulkSyncNotification(true, "", strPartition,RhoAppAdapter.getErrorFromResponse(resp));
	    	        return;
	            }

		        LOG.INFO("Bulk sync: got response from server: " + resp.getCharData() );
	    	
	            String szData = resp.getCharData();
	            JSONEntry oJsonEntry = new JSONEntry(szData);
	            strCmd = oJsonEntry.getString("result");
	            if ( oJsonEntry.hasName("url") )
	   	            strDataUrl = oJsonEntry.getString("url");
	        
	            if ( strCmd.compareTo("wait") == 0)
	            {
	                int nTimeout = RhoConf.getInstance().getInt("bulksync_timeout_sec");
	                if ( nTimeout == 0 )
	                    nTimeout = 5;

	                SyncThread.getInstance().wait(nTimeout);
	                strCmd = "";
	            }
	        }

	        if ( strCmd.compareTo("nop") == 0)
	        {
		        LOG.INFO("Bulk sync return no data.");
		        getNotify().fireBulkSyncNotification(true, "", strPartition, RhoAppAdapter.ERR_NONE);		    
		        return;
	        }

            if ( !isContinueSync() )
                return;

	        getNotify().fireBulkSyncNotification(false, "download", strPartition, RhoAppAdapter.ERR_NONE);

            String fDataName = makeBulkDataFileName(strDataUrl, dbPartition.getDBPath(), "");
            String strZip = ".rzip";
            String strSqlDataUrl = CFilePath.join(getHostFromUrl(serverUrl), strDataUrl) +strZip;
            LOG.INFO("Bulk sync: download data from server: " + strSqlDataUrl);
            {
                NetResponse resp1 = getNet().pullFile(strSqlDataUrl, fDataName+strZip, this, null);
                if ( !resp1.isOK() )
                {
	                LOG.ERROR("Bulk sync failed: cannot download database file.");
	                stopSync();
	                getNotify().fireBulkSyncNotification(true, "", strPartition, RhoAppAdapter.getErrorFromResponse(resp1));
	                return;
                }
            }

            if ( !isContinueSync() )
                return;

            LOG.INFO("Bulk sync: unzip db");

            if ( !RHODESAPP().unzip_file(fDataName+strZip) )
            {
                CRhoFile.deleteFile(fDataName+strZip);
                LOG.ERROR("Bulk sync failed: cannot unzip database file.");
                stopSync();
                getNotify().fireBulkSyncNotification(true, "", strPartition, RhoAppAdapter.ERR_UNEXPECTEDSERVERRESPONSE);
                return;
            }
            CRhoFile.deleteFile(fDataName+strZip);

	        LOG.INFO("Bulk sync: start change db");
   	        getNotify().fireBulkSyncNotification(false, "change_db", strPartition, RhoAppAdapter.ERR_NONE);
    
            dbPartition.setBulkSyncDB(fDataName, strCryptKey);
            processServerSources("{\"partition\":\"" + strPartition + "\"}");

	        LOG.INFO("Bulk sync: end change db");
   	        getNotify().fireBulkSyncNotification(false, "", strPartition, RhoAppAdapter.ERR_NONE);
	    }
Exemplo n.º 11
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 "";
	    }