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:04 UTC

[68/95] [abbrv] git commit: changed sub collections to connections

changed sub collections to connections


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

Branch: refs/heads/import-feature
Commit: d9e0bbd214da15b6cb33dadf07b5a6d95c15da19
Parents: a26716d
Author: Pooja Jain <pj...@apigee.com>
Authored: Wed Jul 30 15:55:54 2014 -0700
Committer: Pooja Jain <pj...@apigee.com>
Committed: Wed Jul 30 15:55:54 2014 -0700

----------------------------------------------------------------------
 .../management/importUG/ImportService.java      |  8 +--
 .../management/importUG/ImportServiceImpl.java  | 54 +++++++++++++-------
 2 files changed, 36 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d9e0bbd2/stack/services/src/main/java/org/apache/usergrid/management/importUG/ImportService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/importUG/ImportService.java b/stack/services/src/main/java/org/apache/usergrid/management/importUG/ImportService.java
index d0be747..5e1b079 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/importUG/ImportService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/importUG/ImportService.java
@@ -18,7 +18,6 @@
 package org.apache.usergrid.management.importUG;
 
 import org.apache.usergrid.batch.JobExecution;
-import org.apache.usergrid.persistence.EntityRef;
 import org.apache.usergrid.persistence.entities.FileImport;
 import org.apache.usergrid.persistence.entities.Import;
 
@@ -38,11 +37,6 @@ public interface ImportService {
     UUID schedule(Map<String, Object> json) throws Exception;
 
     /**
-     * Schedules the import to execute
-     */
-    UUID scheduleFile(File fileName,EntityRef importRef) throws Exception;
-
-    /**
      * Perform the import from the external resource
      */
     void doImport(JobExecution jobExecution) throws Exception;
@@ -76,7 +70,7 @@ public interface ImportService {
     /**
      *
      * @param jobExecution
-     * @return getImportEntity
+     * @return ImportEntity
      * @throws Exception
      */
     Import getImportEntity( final JobExecution jobExecution ) throws Exception;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d9e0bbd2/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 340b058..e247d94 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
@@ -65,6 +65,8 @@ public class ImportServiceImpl implements ImportService {
     private JsonFactory jsonFactory = new JsonFactory();
 
     private int entityCount=0;
+    private File file;
+    private EntityRef importRef;
 
     /**
      *
@@ -132,26 +134,20 @@ public class ImportServiceImpl implements ImportService {
      * @return it returns the UUID of the scheduled job
      * @throws Exception
      */
-    @Override
-    public UUID scheduleFile(File file,EntityRef importRef) throws Exception {
+    public UUID scheduleFile(File file, EntityRef importRef) throws Exception {
 
         ApplicationInfo defaultImportApp = null;
 
         EntityManager em = null;
-        Set<String> collections=new HashSet<String>();
+
         try {
             em = emf.getEntityManager( MANAGEMENT_APPLICATION_ID );
-            collections = em.getApplicationCollections();
-            if ( !collections.contains( "importFiles" ) ) {
-                em.createApplicationCollection( "importFiles" );
-            }
         }
         catch ( Exception e ) {
             logger.error( "application doesn't exist within the current context" );
             return null;
         }
 
-        RelationManager rm = em.getRelationManager(importRef);
         FileImport fileImport = new FileImport();
 
         fileImport.setFileName(file.getName());
@@ -159,13 +155,10 @@ public class ImportServiceImpl implements ImportService {
         fileImport.setLastUpdatedUUID("");
         fileImport.setErrorMessage("");
         fileImport.setState(FileImport.State.CREATED);
-
         fileImport = em.create(fileImport);
-        EntityRef fileRef = em.getRef(fileImport.getUuid());
 
-        //update state
         try {
-            rm.addToCollection("importFiles",fileRef);
+            em.createConnection(importRef,"includes",fileImport);
         }
         catch ( Exception e ) {
             logger.error(e.getMessage());
@@ -176,7 +169,7 @@ public class ImportServiceImpl implements ImportService {
 
         //set data to be transferred to importInfo
         JobData jobData = new JobData();
-        jobData.setProperty( "File ", file );
+        jobData.setProperty( "File", file );
         jobData.setProperty( "fileImportId", fileImport.getUuid() );
         jobData.setProperty("importUUID",importRef);
 
@@ -356,10 +349,30 @@ public class ImportServiceImpl implements ImportService {
                 importCollectionFromOrgApp((UUID) config.get("applicationId"), config, jobExecution, s3Import);
             }
 
-            Map<String,Object> FileJobID = new HashMap<String,Object>();
-            for(File eachfile: files) {
-                UUID jobID = scheduleFile(eachfile, em.getRef(importId));
-                FileJobID.put(eachfile.getName(), jobID.toString());
+            if(files.size() == 0)
+            {
+                importUG.setState(Import.State.FINISHED);
+                importUG.setErrorMessage("no files found in the bucket with the relevant context");
+                em.update(importUG);
+            }
+            else
+            {
+                Map<String,Object> fileMetadata = new HashMap<String, Object>();
+
+                ArrayList<Map<String,Object>> value = new ArrayList<Map<String, Object>>();
+
+                for(File eachfile: files) {
+
+                    UUID jobID = scheduleFile(eachfile, em.getRef(importId));
+                    Map<String,Object> fileJobID = new HashMap<String,Object>();
+                    fileJobID.put("FileName",eachfile.getName());
+                    fileJobID.put("JobID", jobID.toString());
+                    value.add(fileJobID);
+                }
+
+                fileMetadata.put("files", value);
+                importUG.addProperties(fileMetadata);
+                em.update(importUG);
             }
             return;
         }
@@ -499,6 +512,7 @@ public class ImportServiceImpl implements ImportService {
         EntityManager rootEm = emf.getEntityManager(MANAGEMENT_APPLICATION_ID);
 
         boolean completed = fileImport.getCompleted();
+
         // on resume, completed files will not be traversed again
         if(!completed) {
 
@@ -560,11 +574,13 @@ public class ImportServiceImpl implements ImportService {
                     fileImport.setCompleted(true);
                     fileImport.setState(FileImport.State.FINISHED);
                     rootEm.update(fileImport);
+
                     //check other files status and mark the status of import Job.
-                    Results filesCollection = rootEm.getCollection(MANAGEMENT_APPLICATION_ID,"importFiles",null, Results.Level.ALL_PROPERTIES);
-                    List<Entity> entities = filesCollection.getEntities();
+
                     UUID importId = UUID.fromString(jobExecution.getJobData().getProperty("importUUID").toString());
                     Import importUG = rootEm.get(importId, Import.class);
+                    List<Entity> entities = importUG.getConnections("includes");
+
                     int count = 0;
                     for(Entity eachEntity: entities) {