Move default Sones to own method.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / Core.java
index c3bacac..e35e644 100644 (file)
@@ -505,6 +505,7 @@ public class Core extends AbstractService {
                                                } else {
                                                        addSone(parsedSone);
                                                }
+                                               setSoneStatus(parsedSone, SoneStatus.idle);
                                        }
                                } catch (MalformedURLException mue1) {
                                        logger.log(Level.INFO, "Could not create URI from “" + requestUri + "”.", mue1);
@@ -711,12 +712,33 @@ public class Core extends AbstractService {
        //
 
        /**
+        * Adds some default Sones.
+        */
+       private void addDefaultSones() {
+               /* Sone’s Sone. */
+               loadSone("USK@eRHt0ceFsHjRZ11j6dd68RSdIvfd8f9YjJLZ9lnhEyo,iJWjIWh6TkMZm1NY8qBranKTIuwsCPkVPG6T6c6ft-I,AQACAAE/Sone/0");
+               /* Bombe’s Sone. */
+               loadSone("USK@RuW~uAO35Ipne896-1OmaVJNPuYE4ZIB5oZ5ziaU57A,7rV3uiyztXBDt03DCoRiNwiGjgFCJuznM9Okc1opURU,AQACAAE/Sone/15");
+       }
+
+       /**
         * Loads the configuration.
         */
        @SuppressWarnings("unchecked")
        private void loadConfiguration() {
                logger.entering(Core.class.getName(), "loadConfiguration()");
 
+               boolean firstStart = configuration.getBooleanValue("FirstStart").getValue(true);
+               if (firstStart) {
+                       logger.log(Level.INFO, "First start of Sone, adding a couple of default Sones…");
+                       addDefaultSones();
+                       try {
+                               configuration.getBooleanValue("FirstStart").setValue(false);
+                       } catch (ConfigurationException ce1) {
+                               logger.log(Level.WARNING, "Could not clear “first start” flag!");
+                       }
+               }
+
                options.addIntegerOption("InsertionDelay", new DefaultOption<Integer>(60, new OptionWatcher<Integer>() {
 
                        @Override
@@ -726,9 +748,15 @@ public class Core extends AbstractService {
 
                }));
 
-               options.addBooleanOption("ClearOnNextRestart", new DefaultOption<Boolean>(false)).set(configuration.getBooleanValue("Option/ClearOnNextRestart").getValue(null));
-               options.addBooleanOption("ReallyClearOnNextRestart", new DefaultOption<Boolean>(false)).set(configuration.getBooleanValue("Option/ReallyClearOnNextRestart").getValue(null));
+               options.addBooleanOption("ClearOnNextRestart", new DefaultOption<Boolean>(false));
+               options.addBooleanOption("ReallyClearOnNextRestart", new DefaultOption<Boolean>(false));
+
+               if (firstStart) {
+                       return;
+               }
 
+               options.getBooleanOption("ClearOnNextRestart").set(configuration.getBooleanValue("Option/ClearOnNextRestart").getValue(null));
+               options.getBooleanOption("ReallyClearOnNextRestart").set(configuration.getBooleanValue("Option/ReallyClearOnNextRestart").getValue(null));
                boolean clearConfiguration = options.getBooleanOption("ClearOnNextRestart").get() && options.getBooleanOption("ReallyClearOnNextRestart").get();
                options.getBooleanOption("ClearOnNextRestart").set(null);
                options.getBooleanOption("ReallyClearOnNextRestart").set(null);
@@ -999,7 +1027,7 @@ public class Core extends AbstractService {
                                configuration.getStringValue(blacklistedSonePrefix + "/ID").setValue(blacklistedSone.getId());
                                configuration.getStringValue(blacklistedSonePrefix + "/Name").setValue(blacklistedSone.getName());
                                configuration.getStringValue(blacklistedSonePrefix + "/Key").setValue(blacklistedSone.getRequestUri().toString());
-                               configuration.getStringValue(blacklistedSonePrefix + "/InsertKey").setValue(blacklistedSone.getInsertUri().toString());
+                               configuration.getStringValue(blacklistedSonePrefix + "/InsertKey").setValue((blacklistedSone.getInsertUri() != null) ? blacklistedSone.getInsertUri().toString() : null);
                                /* TODO - store all known stuff? */
                        }
                        configuration.getStringValue("BlacklistedSone." + blacklistedSonesCounter + "/ID").setValue(null);