org.kles.m3.service.M3ConnectorBuilderService.java Source code

Java tutorial

Introduction

Here is the source code for org.kles.m3.service.M3ConnectorBuilderService.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.kles.m3.service;

import org.kles.m3.*;
import com.intentia.mak.core.m3.classpath.M3ClassPathEntry;
import com.intentia.mak.core.m3.foundation.M3ConfigurationInfo;
import com.intentia.mak.util.MAKException;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.concurrent.Service;
import javafx.concurrent.Task;
import org.apache.commons.io.FilenameUtils;
import resources.Resource;
import znio.ProcessFile;

/**
 *
 * @author Jeremy.CHAUT
 */
public class M3ConnectorBuilderService extends Service<Void> {

    private M3Connector m3Connector;
    private long beginTime;

    public M3ConnectorBuilderService(M3Connector m3) {
        this.m3Connector = m3;
    }

    public long getTime() {
        return System.currentTimeMillis() - beginTime;
    }

    @Override
    protected Task<Void> createTask() {
        return new Task<Void>() {

            @Override
            protected Void call() throws MAKException, InterruptedException {
                beginTime = System.currentTimeMillis();
                updateMessage("Initialisation des donnes de " + m3Connector.getEnv().getName());
                m3Connector.getMapEntityByConfiguration().entrySet().stream()
                        .forEach((Map.Entry<M3ConfigurationInfo, M3ConfigurationDetail> key) -> {

                            if (key.getKey().getName().equals(m3Connector.getMainConfig().getName())
                                    && !m3Connector.getMainConfig().getName().equals("MVX")) {
                                ArrayList<M3ClassPathEntry> l = new ArrayList<>();
                                for (Map.Entry<String, M3Component> component : key.getValue().getListComponent()
                                        .entrySet()) {
                                    if (m3Connector.getListComponentSelect().contains(component.getValue())
                                            && !component.getValue().getNameComponent().equals("MVX")) {
                                        l.addAll(component.getValue().getListComponentPath());
                                    }
                                }
                                key.getValue().setConfigClassPath(l);
                            } else {
                                key.getValue().setConfigClassPath(key.getValue().getCompleteClassPath());
                            }
                            ArrayList<Path> arrayPath = new ArrayList<>();
                            ProcessFile fileProcessor = new ProcessFile();
                            fileProcessor.setExtFilter(".class");
                            for (M3ClassPathEntry cl1 : key.getValue().getConfigClassPath()) {
                                try {
                                    if (new File(cl1.getPath().toOSString()).exists()) {
                                        updateMessage("Recherche d'objets dans " + cl1.getPath().toOSString());
                                        Files.walkFileTree(Paths.get(cl1.getPath().toString()), fileProcessor);
                                    }
                                } catch (IOException ex) {
                                    Logger.getLogger(Process.class.getName()).log(Level.SEVERE, null, ex);
                                }
                                arrayPath.addAll(fileProcessor.getList());
                            }

                            int cpt = 0;
                            for (Path p : arrayPath) {
                                updateMessage("Traitement des objets de " + p.toString());
                                LinkedHashMap<String, SourceObject> entity = key.getValue().getMapEntity()
                                        .get(M3Utils.getPgmType(p.toFile().getAbsolutePath()));
                                if (entity != null) {
                                    String name = FilenameUtils.getBaseName(p.toString());
                                    if (!entity.containsKey(name)) {
                                        if (M3Utils.getPgmType(p.toFile().getAbsolutePath()).equals(Resource.DB)
                                                && name.contains("$")) {
                                            continue;
                                        }
                                        SourceObject obj = new SourceObject();
                                        obj.setObjectPath(p);
                                        entity.put(name, obj);
                                        cpt++;
                                    }
                                }
                            }
                            updateMessage(cpt + " objets trouvs appartenant  la configuration "
                                    + key.getKey().getName() + "(" + key.getKey().getName() + ")");
                        });
                updateMessage("Fin de la recherche d'objet");
                Thread.sleep(2000);
                return null;
                /*beginTime = System.currentTimeMillis();
                 updateMessage("Initialisation des donnes");
                 m3Connector.getMapEntityByConfiguration().entrySet().stream().forEach((key) -> {
                    
                 ArrayList<Path> arrayPath = new ArrayList<>();
                 ProcessFile fileProcessor = new ProcessFile();
                 fileProcessor.setExtFilter(".class");
                 for (M3ClassPathEntry cl1 : key.getValue().getConfigClassPath()) {
                 try {
                 if (new File(cl1.getPath().toOSString()).exists()) {
                 updateMessage("Recherche d'objets dans " + cl1.getPath().toOSString());
                 Files.walkFileTree(Paths.get(cl1.getPath().toString()), fileProcessor);
                 }
                 } catch (IOException ex) {
                 Logger.getLogger(Process.class.getName()).log(Level.SEVERE, null, ex);
                 }
                 arrayPath.addAll(fileProcessor.getList());
                 }
                    
                 int cpt = 0;
                 for (Path p : arrayPath) {
                 updateMessage("Traitement des objets de " + p.toString());
                 LinkedHashMap<String, SourceObject> entity = key.getValue().getMapEntity().get(M3Utils.getPgmType(p.toFile().getAbsolutePath()));
                 if (entity != null) {
                 String name = FilenameUtils.getBaseName(p.toString());
                 if (!entity.containsKey(name)) {
                 if (M3Utils.getPgmType(p.toFile().getAbsolutePath()).equals(Resource.DB) && name.contains("$")) {
                 continue;
                 }
                 SourceObject obj = new SourceObject();
                 obj.setObjectPath(p);
                 entity.put(name, obj);
                 cpt++;
                 }
                 }
                 }
                 updateMessage(cpt + " objets trouvs appartenant  la configuration " + key.getKey().getName() + "(" + key.getKey().getName() + ")");
                 });
                 updateMessage("Fin de la recherche d'objet");
                 Thread.sleep(2000);
                 return null;*/
            }
        };
    }

    public M3Connector getM3Connector() {
        return m3Connector;
    }

    public void setM3Connector(M3Connector m3) {
        this.m3Connector = m3;
    }

}