<commit_before>package org.kie.guvnor.jcr2vfsmigration.migrater.util;

import java.util.HashMap;
import java.util.Map;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Named;

import org.drools.guvnor.client.common.AssetFormats;
import org.drools.guvnor.client.rpc.Asset;
import org.drools.guvnor.client.rpc.Module;
import org.drools.repository.AssetItem;
import org.kie.commons.java.nio.file.FileSystem;
import org.uberfire.backend.server.util.Paths;
import org.uberfire.backend.vfs.Path;
import org.uberfire.backend.vfs.PathFactory;

/**
 * Generates a Path for every object that needs to be migrated.
 * Guarantees uniqueness. Supports look ups.
 */
@ApplicationScoped
public class MigrationPathManager {
    @Inject
    private Paths paths;

    @Inject
    @Named("migrationFS")
    private FileSystem fs;
    
    private Map<String, Path> uuidToPathMap = new HashMap<String, Path>();
    private Map<Path, String> pathToUuidMap = new HashMap<Path, String>();

    // Generate methods

    public Path generateRootPath() {

        final org.kie.commons.java.nio.file.Path _path = fs.getPath( "/" + escapePathEntry( "project" ));

        final Path path = PathFactory.newPath( paths.convert( _path.getFileSystem() ), _path.getFileName().toString(), _path.toUri().toString() );

        return path;
    }
    
    public Path generatePathForModule( Module jcrModule ) {
        final org.kie.commons.java.nio.file.Path modulePath = fs.getPath( "/" + escapePathEntry( jcrModule.getName() ) );

        final Path path = PathFactory.newPath( paths.convert( modulePath.getFileSystem() ), modulePath.getFileName().toString(), modulePath.toUri().toString() );

        register( jcrModule.getUuid(), path );
        return path;
    }

    public Path generatePathForAsset( Module jcrModule,
                                      Asset jcrAsset,
                                      boolean hasDSL) {
        final org.kie.commons.java.nio.file.Path modulePath = fs.getPath( "/" + escapePathEntry( jcrModule.getName() ) );
        
        //final org.kie.commons.java.nio.file.Path directory = getPomDirectoryPath(pathToPom);
        org.kie.commons.java.nio.file.Path assetPath = null;
        if(AssetFormats.BUSINESS_RULE.equals(jcrAsset.getFormat()) && !hasDSL) {
            assetPath = modulePath.resolve("src/main/resources/" + jcrAsset.getName() + ".gre.drl");
        } else if (AssetFormats.BUSINESS_RULE.equals(jcrAsset.getFormat()) && hasDSL) {
            assetPath = modulePath.resolve("src/main/resources/" + jcrAsset.getName() + ".gre.dslr");
        } else {
            assetPath = modulePath.resolve("src/main/resources/" + jcrAsset.getName() + "." + jcrAsset.getFormat());           
        }
        
        //final org.kie.commons.java.nio.file.Path _path = fs.getPath( "/" + escapePathEntry( jcrModule.getName() ) + "/" + escapePathEntry( jcrAsset.getName() ) + "." + jcrAsset.getFormat() );

        final Path path = PathFactory.newPath( paths.convert( assetPath.getFileSystem() ), assetPath.getFileName().toString(), assetPath.toUri().toString() );

        register( jcrAsset.getUuid(), path );
        return path;
    }

    public Path generatePathForAsset(Module jcrModule, Asset jcrAsset) {        
        return  generatePathForAsset( jcrModule, jcrAsset, false );
    } 

    public Path generatePathForAsset(Module jcrModule, AssetItem jcrAssetItem, boolean hasDSL) {
        final org.kie.commons.java.nio.file.Path modulePath = fs.getPath("/" + escapePathEntry(jcrModule.getName()));

        org.kie.commons.java.nio.file.Path assetPath = null;
        if (AssetFormats.BUSINESS_RULE.equals(jcrAssetItem.getFormat()) && !hasDSL) {
            assetPath = modulePath.resolve("src/main/resources/" + jcrAssetItem.getName() + ".gre.drl");
        } else if (AssetFormats.BUSINESS_RULE.equals(jcrAssetItem.getFormat()) && hasDSL) {
            assetPath = modulePath.resolve("src/main/resources/" + jcrAssetItem.getName() + ".gre.dslr");
        } else {
            assetPath = modulePath.resolve("src/main/resources/" + jcrAssetItem.getName() + "." + jcrAssetItem.getFormat());
        }

        final Path path = PathFactory.newPath(paths.convert(assetPath.getFileSystem()), assetPath.getFileName().toString(), assetPath.toUri().toString());

        register(jcrAssetItem.getUUID(), path);
        return path;
    }
    
    public Path generatePathForAsset(Module jcrModule, AssetItem jcrAssetItem) {        <commit_msg>jcr2vfs migration tool. TestScenario path<commit_after>package org.kie.guvnor.jcr2vfsmigration.migrater.util;

import java.util.HashMap;
import java.util.Map;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Named;

import org.drools.guvnor.client.common.AssetFormats;
import org.drools.guvnor.client.rpc.Asset;
import org.drools.guvnor.client.rpc.Module;
import org.drools.repository.AssetItem;
import org.kie.commons.java.nio.file.FileSystem;
import org.uberfire.backend.server.util.Paths;
import org.uberfire.backend.vfs.Path;
import org.uberfire.backend.vfs.PathFactory;

/**
 * Generates a Path for every object that needs to be migrated.
 * Guarantees uniqueness. Supports look ups.
 */
@ApplicationScoped
public class MigrationPathManager {
    @Inject
    private Paths paths;

    @Inject
    @Named("migrationFS")
    private FileSystem fs;
    
    private Map<String, Path> uuidToPathMap = new HashMap<String, Path>();
    private Map<Path, String> pathToUuidMap = new HashMap<Path, String>();

    // Generate methods

    public Path generateRootPath() {

        final org.kie.commons.java.nio.file.Path _path = fs.getPath( "/" + escapePathEntry( "project" ));

        final Path path = PathFactory.newPath( paths.convert( _path.getFileSystem() ), _path.getFileName().toString(), _path.toUri().toString() );

        return path;
    }
    
    public Path generatePathForModule( Module jcrModule ) {
        final org.kie.commons.java.nio.file.Path modulePath = fs.getPath( "/" + escapePathEntry( jcrModule.getName() ) );

        final Path path = PathFactory.newPath( paths.convert( modulePath.getFileSystem() ), modulePath.getFileName().toString(), modulePath.toUri().toString() );

        register( jcrModule.getUuid(), path );
        return path;
    }

    public Path generatePathForAsset( Module jcrModule,
                                      Asset jcrAsset,
                                      boolean hasDSL) {
        final org.kie.commons.java.nio.file.Path modulePath = fs.getPath( "/" + escapePathEntry( jcrModule.getName() ) );
        
        //final org.kie.commons.java.nio.file.Path directory = getPomDirectoryPath(pathToPom);
        org.kie.commons.java.nio.file.Path assetPath = null;
        if(AssetFormats.BUSINESS_RULE.equals(jcrAsset.getFormat()) && !hasDSL) {
            assetPath = modulePath.resolve("src/main/resources/" + jcrAsset.getName() + ".gre.drl");
        } else if (AssetFormats.BUSINESS_RULE.equals(jcrAsset.getFormat()) && hasDSL) {
            assetPath = modulePath.resolve("src/main/resources/" + jcrAsset.getName() + ".gre.dslr");
        } else {
            assetPath = modulePath.resolve("src/main/resources/" + jcrAsset.getName() + "." + jcrAsset.getFormat());           
        }
        
        //final org.kie.commons.java.nio.file.Path _path = fs.getPath( "/" + escapePathEntry( jcrModule.getName() ) + "/" + escapePathEntry( jcrAsset.getName() ) + "." + jcrAsset.getFormat() );

        final Path path = PathFactory.newPath( paths.convert( assetPath.getFileSystem() ), assetPath.getFileName().toString(), assetPath.toUri().toString() );

        register( jcrAsset.getUuid(), path );
        return path;
    }

    public Path generatePathForAsset(Module jcrModule, Asset jcrAsset) {        
        return  generatePathForAsset( jcrModule, jcrAsset, false );
    } 

    public Path generatePathForAsset(Module jcrModule, AssetItem jcrAssetItem, boolean hasDSL) {
        final org.kie.commons.java.nio.file.Path modulePath = fs.getPath("/" + escapePathEntry(jcrModule.getName()));

        org.kie.commons.java.nio.file.Path assetPath = null;
        if (AssetFormats.BUSINESS_RULE.equals(jcrAssetItem.getFormat()) && !hasDSL) {
            assetPath = modulePath.resolve("src/main/resources/" + jcrAssetItem.getName() + ".gre.drl");
        } else if (AssetFormats.BUSINESS_RULE.equals(jcrAssetItem.getFormat()) && hasDSL) {
            assetPath = modulePath.resolve("src/main/resources/" + jcrAssetItem.getName() + ".gre.dslr");
        } else if (AssetFormats.TEST_SCENARIO.equals(jcrAssetItem.getFormat())) {
            assetPath = modulePath.resolve("src/test/resources/" + jcrAssetItem.getName() + "." + jcrAssetItem.getFormat());
        } else {
            assetPath = modulePath.resolve("src/main/resources/" + jcrAssetItem.getName() + "." + jcrAssetItem.getFormat());
        }

        final Path path = PathFactory.newPath(paths.convert(assetPath.getFileSystem()), assetPath.getFileName().toString(), assetPath.toUri().toString());

        register(jcrAssetItem.getUUID(), path);
        return path;
    }
    
    public Path generatePathForAsset(Module jcrModule, AssetItem jcrAssetItem) {        
{'fraction_non_alphanumeric': 0.13245604573400926, 'fraction_numerical': 0.00032358968827526696, 'mean_word_length': 3.157847533632287, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2660446', 'n_tokens_mistral': 2820, 'n_tokens_neox': 2756, 'n_words': 495}