fix intent issues yuta observed

Change-Id: I7dc4a19d49a1b3fc18ecce02a4018cbc9a3043fc
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/IntentBatchService.java b/core/api/src/main/java/org/onlab/onos/net/intent/IntentBatchService.java
index 762bbb8..8a58aa2 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/IntentBatchService.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/IntentBatchService.java
@@ -56,8 +56,8 @@
      * Return true if this instance is the local leader for batch
      * processing a given application id.
      *
-     * @param applicationId
-     * @return
+     * @param applicationId an application id
+     * @return true if this instance is the local leader for batch
      */
     boolean isLocalLeader(ApplicationId applicationId);
 
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/IntentEvent.java b/core/api/src/main/java/org/onlab/onos/net/intent/IntentEvent.java
index 6d7a3b0..495f3ea 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/IntentEvent.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/IntentEvent.java
@@ -67,4 +67,32 @@
         super(type, intent);
     }
 
+    public static IntentEvent getEvent(IntentState state, Intent intent) {
+        Type type;
+        switch (state) {
+            case SUBMITTED:
+                type = Type.SUBMITTED;
+                break;
+            case INSTALLED:
+                type = Type.INSTALLED;
+                break;
+            case WITHDRAWN:
+                type = Type.WITHDRAWN;
+                break;
+            case FAILED:
+                type = Type.FAILED;
+                break;
+
+            //fallthrough to default from here
+            case COMPILING:
+            case INSTALLING:
+            case RECOMPILING:
+            case WITHDRAWING:
+            default:
+                throw new IllegalArgumentException(
+                        "Intent event cannot have transient state: " + state);
+        }
+        return new IntentEvent(type, intent);
+    }
+
 }
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/IntentStore.java b/core/api/src/main/java/org/onlab/onos/net/intent/IntentStore.java
index 8dc70d8..442a247 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/IntentStore.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/IntentStore.java
@@ -15,7 +15,6 @@
  */
 package org.onlab.onos.net.intent;
 
-import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 
 import org.onlab.onos.net.intent.IntentStore.BatchWrite.Operation;
@@ -42,16 +41,16 @@
      * mechanism.
      *
      * @param intent intent to be submitted
-     * @return event indicating the intent was submitted or null if no
-     * change resulted, e.g. duplicate intent
      */
-    IntentEvent createIntent(Intent intent);
+    @Deprecated
+    void createIntent(Intent intent);
 
     /**
      * Removes the specified intent from the inventory.
      *
      * @param intentId intent identification
      */
+    @Deprecated
     void removeIntent(IntentId intentId);
 
     /**
@@ -89,9 +88,8 @@
      *
      * @param intent   intent whose state is to be changed
      * @param newState new state
-     * @return state transition event
      */
-    IntentEvent setState(Intent intent, IntentState newState);
+    void setState(Intent intent, IntentState newState);
 
     /**
      * Sets the installable intents which resulted from compilation of the
@@ -129,64 +127,13 @@
         return new BatchWrite();
     }
 
-    // default implementation simply executes them sequentially.
-    // Store implementation should override and implement actual batch write.
     /**
      * Execute writes in a batch.
      *
      * @param batch BatchWrite to execute
      * @return failed operations
      */
-    default List<Operation> batchWrite(BatchWrite batch) {
-        List<Operation> failed = new ArrayList<>();
-        for (Operation op : batch.operations) {
-            switch (op.type) {
-            case CREATE_INTENT:
-                checkArgument(op.args.size() == 1,
-                              "CREATE_INTENT takes 1 argument. %s", op);
-                Intent intent = (Intent) op.args.get(0);
-                if (createIntent(intent) == null) {
-                    failed.add(op);
-                }
-                break;
-
-            case REMOVE_INTENT:
-                checkArgument(op.args.size() == 1,
-                              "REMOVE_INTENT takes 1 argument. %s", op);
-                IntentId intentId = (IntentId) op.args.get(0);
-                removeIntent(intentId);
-                break;
-
-            case REMOVE_INSTALLED:
-                checkArgument(op.args.size() == 1,
-                              "REMOVE_INSTALLED takes 1 argument. %s", op);
-                intentId = (IntentId) op.args.get(0);
-                removeInstalledIntents(intentId);
-                break;
-
-            case SET_INSTALLABLE:
-                checkArgument(op.args.size() == 2,
-                              "SET_INSTALLABLE takes 2 arguments. %s", op);
-                intentId = (IntentId) op.args.get(0);
-                @SuppressWarnings("unchecked")
-                List<Intent> installableIntents = (List<Intent>) op.args.get(1);
-                setInstallableIntents(intentId, installableIntents);
-                break;
-
-            case SET_STATE:
-                checkArgument(op.args.size() == 2,
-                              "SET_STATE takes 2 arguments. %s", op);
-                intent = (Intent) op.args.get(0);
-                IntentState newState = (IntentState) op.args.get(1);
-                setState(intent, newState);
-                break;
-
-            default:
-                break;
-            }
-        }
-        return failed;
-    }
+     List<Operation> batchWrite(BatchWrite batch);
 
     public static class BatchWrite {