You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/08/22 16:16:13 UTC

[77/95] [abbrv] git commit: fixed status changed error

fixed status changed error


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/11d2e0cf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/11d2e0cf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/11d2e0cf

Branch: refs/heads/import-feature
Commit: 11d2e0cf0baf0dd98c5b50a10a41650b3a1fc290
Parents: 3416050
Author: Pooja Jain <pj...@apigee.com>
Authored: Mon Aug 4 14:30:42 2014 -0700
Committer: Pooja Jain <pj...@apigee.com>
Committed: Mon Aug 4 14:30:42 2014 -0700

----------------------------------------------------------------------
 .../management/importUG/ImportServiceImpl.java  | 35 ++++++++++++--------
 1 file changed, 21 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/11d2e0cf/stack/services/src/main/java/org/apache/usergrid/management/importUG/ImportServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/importUG/ImportServiceImpl.java b/stack/services/src/main/java/org/apache/usergrid/management/importUG/ImportServiceImpl.java
index edaaf5a..5881528 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/importUG/ImportServiceImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/importUG/ImportServiceImpl.java
@@ -512,8 +512,6 @@ public class ImportServiceImpl implements ImportService {
         // add properties to the import entity
         FileImport fileImport = getFileImportEntity(jobExecution);
 
-        fileImport.setState(FileImport.State.STARTED);
-
         File file = new File(jobExecution.getJobData().getProperty("File").toString());
 
         EntityManager rootEm = emf.getEntityManager(MANAGEMENT_APPLICATION_ID);
@@ -526,6 +524,8 @@ public class ImportServiceImpl implements ImportService {
 
             if (isValidJSON(file, rootEm, fileImport)) {
 
+                fileImport.setState(FileImport.State.STARTED);
+
                 String applicationName = file.getPath().split("\\.")[0];
 
                 logger.error(applicationName);
@@ -556,11 +556,18 @@ public class ImportServiceImpl implements ImportService {
 
                 EntityManager em = emf.getEntityManager(application.getId());
                 try {
+
+                    String uuid=" ";
                     while (jp.nextToken() != JsonToken.END_ARRAY) {
-                        importEntityStuff(jp, em, rootEm, fileImport);
+                        uuid = importEntityStuff(jp, em, rootEm, fileImport);
                     }
+
                     //one file completed
                     //TODO: update last updated UUID
+                    if(!uuid.equals(" "))
+                    {
+                        fileImport.setLastUpdatedUUID(uuid);
+                    }
                     jp.close();
                 }
                 catch (OrganizationNotFoundException e) {
@@ -653,12 +660,12 @@ public class ImportServiceImpl implements ImportService {
      *
      * @param jp JsonPrser pointing to the beginning of the object.
      */
-    private void importEntityStuff( JsonParser jp, EntityManager em, EntityManager rootEm, FileImport fileImport) throws Exception {
+    private String importEntityStuff( JsonParser jp, EntityManager em, EntityManager rootEm, FileImport fileImport) throws Exception {
 
         Entity entity = null;
-        EntityRef ownerEntityRef=null;
-        String entityUuid="";
-        String entityType="";
+        EntityRef ownerEntityRef = null;
+        String entityUuid = "";
+        String entityType = "";
 
         // Go inside the value after getting the owner entity id.
         while (jp.nextToken() != JsonToken.END_OBJECT) {
@@ -693,7 +700,7 @@ public class ImportServiceImpl implements ImportService {
 
                         jp.nextToken();
 
-                        @SuppressWarnings("unchecked") Map<String, Object> dictionary = jp.readValueAs(HashMap.class);
+                        Map<String, Object> dictionary = jp.readValueAs(HashMap.class);
 
                         em.addMapToDictionary(ownerEntityRef, dictionaryName, dictionary);
                     }
@@ -724,13 +731,11 @@ public class ImportServiceImpl implements ImportService {
                     entity = em.create(UUID.fromString(entityUuid), entityType, properties);
                     ownerEntityRef = em.getRef(UUID.fromString(entityUuid));
                 }
-            }
-            catch (IllegalArgumentException e) {
+            } catch (IllegalArgumentException e) {
                 // skip illegal entity UUID and go to next one
                 fileImport.setErrorMessage(e.getMessage());
                 rootEm.update(fileImport);
-            }
-            catch (Exception e) {
+            } catch (Exception e) {
                 // skip illegal entity and go to next one
                 fileImport.setErrorMessage(e.getMessage());
                 rootEm.update(fileImport);
@@ -738,14 +743,16 @@ public class ImportServiceImpl implements ImportService {
         }
 
         // update the last updated entity
-        if(entity != null) {
+        if (entity != null) {
             entityCount++;
-            if(entityCount == 1000) {
+            if (entityCount == 1000) {
                 fileImport.setLastUpdatedUUID(entityUuid);
                 rootEm.update(fileImport);
                 entityCount = 0;
             }
+            return entityUuid;
         }
+        return new String(" ");
     }
 }