package com.github.bfh.study.slb.imports;

import com.github.bfh.study.slb.imports.parser.ProcessingElement;

import java.util.List;

/**
 * Context of the import process.
 *
 * @author Dario Carosella
 */
public class ImportContext {

    private Import importer;

    private ImportContext(Import importer) {
        this.importer = importer;
    }

    public int executeImport(int number1, int number2) {
        return importer.doSomeStuff(number1, number2);
    }

    public List<ProcessingElement> getProcessingElements() {
        return importer.getProcessingElements();
    }

    /**
     * Import factory - create an import context decided by source name.
     *
     * @param sourceName Name of source
     * @return ImportContext import context
     * @throws SourceNotFoundException throw if no source was found
     */
    public static ImportContext importContextFactory(String sourceName)
        throws SourceNotFoundException {

        Import importer = null;
        switch (sourceName) {
            case "SECO":
                importer = new SecoProvider();
                break;
            default:
                throw new SourceNotFoundException(sourceName);
        }

        return new ImportContext(importer);
    }
}

@@ -125,16 +125,94 @@
 il.List;
+%0Aimport javax.persistence.EntityManager;%0Aimport javax.persistence.Persistence;
 %0A%0A/**%0A *
@@ -337,16 +337,64 @@
 orter;%0A%0A
+    private final EntityManager entityManager;%0A%0A
     priv
@@ -464,16 +464,131 @@
 porter;%0A
+        entityManager = Persistence.createEntityManagerFactory(%22defaultUnit%22)%0A            .createEntityManager();%0A%0A
     %7D%0A%0A 
@@ -762,24 +762,24 @@
 lements() %7B%0A
-
         retu
@@ -818,24 +818,107 @@
 s();%0A    %7D%0A%0A
+    public EntityManager getEntityManager() %7B%0A        return entityManager;%0A    %7D%0A%0A
     /**%0A    

add EntityManger to ImportContext