package org.drools.workbench.jcr2vfsmigration.migrater;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

import org.drools.guvnor.client.rpc.Module;
import org.drools.guvnor.server.RepositoryModuleService;
import org.drools.workbench.jcr2vfsmigration.migrater.util.MigrationPathManager;
import org.kie.workbench.common.services.project.service.model.POM;
import org.kie.workbench.common.services.project.service.ProjectService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.uberfire.backend.vfs.Path;

@ApplicationScoped
public class ModuleMigrater {

    protected static final Logger logger = LoggerFactory.getLogger(ModuleMigrater.class);

    @Inject
    protected RepositoryModuleService jcrRepositoryModuleService;

    @Inject
    protected MigrationPathManager migrationPathManager;

    @Inject
    protected ProjectService projectService;

    public void migrateAll() {
        logger.info("  Module migration started");
        Module[] jcrModules = jcrRepositoryModuleService.listModules();
        for (Module jcrModule : jcrModules) {
            migrate(jcrModule);
            logger.debug("    Module ({}) migrated.", jcrModule.getName());
        }
        logger.info("  Module migration ended");
    }

    private void migrate(Module jcrModule) {
        //Set up project structure:
        POM pom = new POM();
        Path modulePath = migrationPathManager.generateRootPath();  
        projectService.newProject(modulePath, jcrModule.getName(), pom, "http://localhost");
    }

}

@@ -373,17 +373,22 @@
 ice.
-model.POM
+ProjectService
 ;%0Aim
@@ -438,38 +438,33 @@
 ect.service.
-ProjectService
+model.POM
 ;%0Aimport org
@@ -510,16 +510,81 @@
 actory;%0A
+import org.uberfire.backend.repositories.impl.git.GitRepository;%0A
 import o
@@ -731,16 +731,17 @@
 tLogger(
+ 
 ModuleMi
@@ -752,16 +752,17 @@
 er.class
+ 
 );%0A%0A    
@@ -1007,32 +1007,33 @@
     logger.info(
+ 
 %22  Module migrat
@@ -1044,16 +1044,17 @@
 started%22
+ 
 );%0A     
@@ -1133,16 +1133,17 @@
    for (
+ 
 Module j
@@ -1163,16 +1163,17 @@
 rModules
+ 
 ) %7B%0A    
@@ -1188,16 +1188,17 @@
 migrate(
+ 
 jcrModul
@@ -1198,16 +1198,17 @@
 crModule
+ 
 );%0A     
@@ -1227,16 +1227,17 @@
 r.debug(
+ 
 %22    Mod
@@ -1276,16 +1276,17 @@
 etName()
+ 
 );%0A     
@@ -1310,16 +1310,17 @@
 er.info(
+ 
 %22  Modul
@@ -1337,16 +1337,17 @@
 n ended%22
+ 
 );%0A    %7D
@@ -1373,16 +1373,17 @@
 migrate(
+ 
 Module j
@@ -1390,16 +1390,17 @@
 crModule
+ 
 ) %7B%0A    
@@ -1526,18 +1526,16 @@
 tPath();
-  
 %0A       
@@ -1565,65 +1565,460 @@
 ect(
-modulePath, jcrModule.getName(), pom, %22http://localhost%22)
+ makeRepository( modulePath ),%0A                                   jcrModule.getName(),%0A                                   pom,%0A                                   %22http://localhost%22 );%0A    %7D%0A%0A    private org.uberfire.backend.repositories.Repository makeRepository( final Path repositoryRoot ) %7B%0A        return new GitRepository() %7B%0A%0A            @Override%0A            public Path getRoot() %7B%0A                return repositoryRoot;%0A            %7D%0A        %7D
 ;%0A  

Fix following change to ProjectService