Android Open Source - Munin-for-Android S Q Lite






From Project

Back to project page Munin-for-Android.

License

The source code is released under:

GNU General Public License

If you think the Android project Munin-for-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.chteuchteu.munin.hlpr;
//from   w  ww  .  ja  v  a2 s .c om
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.chteuchteu.munin.BuildConfig;
import com.chteuchteu.munin.MuninFoo;
import com.chteuchteu.munin.obj.Grid;
import com.chteuchteu.munin.obj.GridItem;
import com.chteuchteu.munin.obj.Label;
import com.chteuchteu.munin.obj.MuninMaster;
import com.chteuchteu.munin.obj.MuninPlugin;
import com.chteuchteu.munin.obj.MuninServer;
import com.chteuchteu.munin.obj.MuninServer.AuthType;

import java.util.ArrayList;

public class SQLite {
  private MuninFoo muninFoo;
  public DatabaseHelper dbHlpr;
  
  public SQLite(Context c, MuninFoo m) {
    this.muninFoo = m;
    this.dbHlpr = new DatabaseHelper(c);
  }
  
  public void insertMuninMaster(MuninMaster master) {
    // Update servers positions
    for (MuninServer server : master.getChildren())
      server.setPosition(master.getChildren().indexOf(server));
    
    // Insert master
    dbHlpr.insertMuninMaster(master);
    // Insert servers
    for (MuninServer server : master.getChildren()) {
      dbHlpr.insertMuninServer(server);
      for (MuninPlugin plugin : server.getPlugins())
        dbHlpr.insertMuninPlugin(plugin);
    }
  }
  
  public void saveLabels() {
    // Simpler way of doing it!
    dbHlpr.deleteLabels();
    dbHlpr.deleteLabelsRelations();
    for (Label l : muninFoo.labels) {
      dbHlpr.insertLabel(l);
      
      for (MuninPlugin p : l.plugins)
        dbHlpr.insertLabelRelation(p, l);
    }
  }
  
  public void saveGridItemRelations(Grid g) {
    // Simplest way of doing it ;)
    dbHlpr.deleteGridItemRelations(g);
    for (GridItem i : g.items)
      dbHlpr.insertGridItemRelation(i);
  }
  
  public void migrateTo3() {
    // Here, columns have already been created.
    // Let's check if there are some MuninMaster (_not default_)
    // whose attributes needs to be filled
    
    for (MuninMaster master : muninFoo.getMasters()) {
      // DefaultMaster groups several heterogeneous servers.
      // We can't easily group credentials here
      if (!master.defaultMaster && !master.isEmpty()) {
        // Get the first server
        MuninServer model = master.getChildAt(0);
        
        getOldAuthInformation(model.getId(), master, true);
      }
    }
    
    // Merge defaultMaster childrens by host name. If necessary get old auth information.
    // Find default master
    MuninMaster defaultMaster = null;
    for (MuninMaster master : muninFoo.getMasters()) {
      if (master.defaultMaster) {
        defaultMaster = master;
        break;
      }
    }
    
    // We don't necessarily have a default master
    if (defaultMaster != null) {
      ArrayList<MuninMaster> newMasters = new ArrayList<>();
      
      for (MuninServer server : defaultMaster.getChildren()) {
        // Check if there already is a master for this server in newMasters
        String masterUrl = Util.URLManipulation.ascendDirectory(2, server.getServerUrl());
        
        MuninMaster parent = null;
        boolean contains = false;
        for (MuninMaster master : newMasters) {
          if (master.getUrl().equals(masterUrl)) {
            contains = true;
            parent = master;
            break;
          }
        }
        
        // Doesn't contains => add
        if (!contains) {
          String masterName = Util.URLManipulation.getHostFromUrl(server.getServerUrl());
          
          parent = new MuninMaster();
          parent.setName(masterName);
          parent.setUrl(masterUrl);
          newMasters.add(parent);
        }
        
        // Attach server to parent
        parent.addChild(server);
        
        if (!contains) {
          // Get auth ids if needed. Only needed to be done the first time
          // (since all the servers should have the same auth ids)
          getOldAuthInformation(server.getId(), parent, false);
        }
      }
      
      // Insert masters and update children
      for (MuninMaster master : newMasters) {
        dbHlpr.insertMuninMaster(master);
        for (MuninServer server : master.getChildren())
          dbHlpr.updateMuninServer(server);
      }
      
      // Delete default master
      dbHlpr.deleteMaster(defaultMaster, false);
    }
  }
  
  /**
   * Before Munin for Android 3.0, auth ids were attached to MuninServer.
   * Those auth information weren't deleting during update so they can
   * be fetched back for migration purposes.
   * @param muninServerId Information source (MuninServer id)
   * @param attachTo Information destination
   * @param saveChanges boolean
   */
  private void getOldAuthInformation(long muninServerId, MuninMaster attachTo, boolean saveChanges) {
    String KEY_MUNINSERVERS_AUTHLOGIN = "authLogin";
    String KEY_MUNINSERVERS_AUTHPASSWORD = "authPassword";
    String KEY_MUNINSERVERS_SSL = "SSL";
    String KEY_MUNINSERVERS_AUTHTYPE = "authType";
    String KEY_MUNINSERVERS_AUTHSTRING = "authString";
    
    String selectQuery = "SELECT * FROM " + DatabaseHelper.TABLE_MUNINSERVERS
        + " WHERE " + DatabaseHelper.KEY_ID + " = " + muninServerId;
    
    SQLiteDatabase db = dbHlpr.getReadableDatabase();
    Cursor c = db.rawQuery(selectQuery, null);
    
    if (c != null && c.moveToFirst()) { // The server has been found (which should always be the case)
      AuthType authType = AuthType.get(c.getInt(c.getColumnIndex(KEY_MUNINSERVERS_AUTHTYPE)));
      
      attachTo.setAuthType(authType);
      if (authType == AuthType.BASIC || authType == AuthType.DIGEST) {
        String authLogin = c.getString(c.getColumnIndex(KEY_MUNINSERVERS_AUTHLOGIN));
        String authPassword = c.getString(c.getColumnIndex(KEY_MUNINSERVERS_AUTHPASSWORD));
        String authString = c.getString(c.getColumnIndex(KEY_MUNINSERVERS_AUTHSTRING));
        
        attachTo.setAuthIds(authLogin, authPassword);
        attachTo.setAuthString(authString);
      }
      
      boolean ssl = c.getInt(c.getColumnIndex(KEY_MUNINSERVERS_SSL)) == 1;
      attachTo.setSSL(ssl);
      
      DatabaseHelper.close(c, db);
      
      if (saveChanges)
        dbHlpr.saveMuninMaster(attachTo);
    }
  }
  
    public void logMasters() {
      if (!BuildConfig.DEBUG)
        return;

        MuninFoo.log("");
        logLine(60);
        for (MuninMaster m : this.muninFoo.masters) {
          MuninFoo.log("[" + m.getName() + "] - " + m.getUrl());
            for (MuninServer s : m.getChildren())
              MuninFoo.log("  - " + s.getName() + " - " + s.getServerUrl());
        }
        logLine(60);
    }
    private void logLine(int nb) {
        if (nb == 0)
            logLine(88);
        else {
            String s = "";
            for (int i=0; i<nb; i++)
                s += "=";
          MuninFoo.log(s);
        }
    }
}




Java Source Code List

com.chteuchteu.munin.BootReceiver.java
com.chteuchteu.munin.CustomSSLFactory.java
com.chteuchteu.munin.MuninFoo.java
com.chteuchteu.munin.Service_Notifications.java
com.chteuchteu.munin.adptr.Adapter_ExpandableListView.java
com.chteuchteu.munin.adptr.Adapter_GraphView.java
com.chteuchteu.munin.adptr.Adapter_IconList.java
com.chteuchteu.munin.adptr.Adapter_SeparatedList.java
com.chteuchteu.munin.exc.ImportExportWebserviceException.java
com.chteuchteu.munin.exc.NullMuninFooException.java
com.chteuchteu.munin.exc.TrialExpirationDateReached.java
com.chteuchteu.munin.hlpr.BillingService.java
com.chteuchteu.munin.hlpr.DatabaseHelper.java
com.chteuchteu.munin.hlpr.DigestUtils.java
com.chteuchteu.munin.hlpr.DocumentationHelper.java
com.chteuchteu.munin.hlpr.DrawerHelper.java
com.chteuchteu.munin.hlpr.DynazoomHelper.java
com.chteuchteu.munin.hlpr.EncryptionHelper.java
com.chteuchteu.munin.hlpr.GridDownloadHelper.java
com.chteuchteu.munin.hlpr.I18nHelper.java
com.chteuchteu.munin.hlpr.ImportExportHelper.java
com.chteuchteu.munin.hlpr.JSONHelper.java
com.chteuchteu.munin.hlpr.MediaScannerUtil.java
com.chteuchteu.munin.hlpr.NetHelper.java
com.chteuchteu.munin.hlpr.SQLite.java
com.chteuchteu.munin.hlpr.Util.java
com.chteuchteu.munin.obj.AlertsWidget.java
com.chteuchteu.munin.obj.GraphWidget.java
com.chteuchteu.munin.obj.GridItem.java
com.chteuchteu.munin.obj.Grid.java
com.chteuchteu.munin.obj.HTTPResponse_Bitmap.java
com.chteuchteu.munin.obj.HTTPResponse.java
com.chteuchteu.munin.obj.Label.java
com.chteuchteu.munin.obj.MuninMaster.java
com.chteuchteu.munin.obj.MuninPlugin.java
com.chteuchteu.munin.obj.MuninServer.java
com.chteuchteu.munin.obj.SearchResult.java
com.chteuchteu.munin.ui.Activity_About.java
com.chteuchteu.munin.ui.Activity_AlertsPluginSelection.java
com.chteuchteu.munin.ui.Activity_Alerts.java
com.chteuchteu.munin.ui.Activity_GoPremium.java
com.chteuchteu.munin.ui.Activity_GraphView.java
com.chteuchteu.munin.ui.Activity_Grid.java
com.chteuchteu.munin.ui.Activity_Grids.java
com.chteuchteu.munin.ui.Activity_Label.java
com.chteuchteu.munin.ui.Activity_Labels.java
com.chteuchteu.munin.ui.Activity_Main.java
com.chteuchteu.munin.ui.Activity_Notifications.java
com.chteuchteu.munin.ui.Activity_Plugins.java
com.chteuchteu.munin.ui.Activity_Server.java
com.chteuchteu.munin.ui.Activity_ServersEdit.java
com.chteuchteu.munin.ui.Activity_Servers.java
com.chteuchteu.munin.ui.Activity_Settings.java
com.chteuchteu.munin.ui.HackyDrawerLayout.java
com.chteuchteu.munin.ui.MuninActivity.java
com.chteuchteu.munin.wdget.Widget_AlertsWidget_Configure.java
com.chteuchteu.munin.wdget.Widget_AlertsWidget_ViewsFactory.java
com.chteuchteu.munin.wdget.Widget_AlertsWidget_WidgetProvider.java
com.chteuchteu.munin.wdget.Widget_AlertsWidget_WidgetService.java
com.chteuchteu.munin.wdget.Widget_GraphWidget_Configure.java
com.chteuchteu.munin.wdget.Widget_GraphWidget_WidgetProvider.java
com.mobeta.android.dslv.DragSortController.java
com.mobeta.android.dslv.DragSortCursorAdapter.java
com.mobeta.android.dslv.DragSortItemViewCheckable.java
com.mobeta.android.dslv.DragSortItemView.java
com.mobeta.android.dslv.DragSortListView.java
com.mobeta.android.dslv.ResourceDragSortCursorAdapter.java
com.mobeta.android.dslv.SimpleDragSortCursorAdapter.java
com.mobeta.android.dslv.SimpleFloatViewManager.java
org.taptwo.android.widget.CircleFlowIndicator.java
org.taptwo.android.widget.FlowIndicator.java
org.taptwo.android.widget.TitleFlowIndicator.java
org.taptwo.android.widget.TitleProvider.java
org.taptwo.android.widget.ViewFlow.java
uk.co.senab.photoview.Compat.java
uk.co.senab.photoview.IPhotoView.java
uk.co.senab.photoview.PhotoViewAttacher.java
uk.co.senab.photoview.PhotoView.java
uk.co.senab.photoview.SDK16.java
uk.co.senab.photoview.ScrollerProxy.java
uk.co.senab.photoview.VersionedGestureDetector.java