Example usage for java.util AbstractMap put

List of usage examples for java.util AbstractMap put

Introduction

In this page you can find the example usage for java.util AbstractMap put.

Prototype

public V put(K key, V value) 

Source Link

Usage

From source file:MainClass.java

public static void main(String args[]) {
    AbstractMap map = new ArrayMap(13);
    map.put("Virginia", "Richmond");
    map.put("Massachusetts", "Boston");
    map.put("New York", "Albany");
    System.out.println(map);//from  www . j a  v a 2 s  .co  m
    System.out.println(map.keySet());
    System.out.println(map.values());
}

From source file:com.sse.abtester.VariationAssignerTest.java

/**
 * Test n variants./*  w w w  .  j a  va  2 s  .  c o  m*/
 *
 * @param num_variants the num_variants
 */
public void testNVariants(int num_variants) {
    // make up some variants
    AbstractMap<String, IVariant<VariantBean>> coll = new HashMap<String, IVariant<VariantBean>>();

    for (int i = 0; i < num_variants; i++) {
        String name = "Bean_" + i;
        IVariant<VariantBean> vb = new VariantBean(name);
        vb.setDispatchable(true); // else non of the bean is
        // copied into normalized/weighted collections
        vb.setTargetFreq(1.0 / num_variants);
        vb.setVariationStrategy(new Default());
        coll.put(name, vb);
    }
    VariationAssigner<VariantBean> va = new VariationAssigner<VariantBean>();

    va.setIVariantCollection(coll);
    Frequency f = new Frequency();
    MockHttpServletRequest req = new MockHttpServletRequest();
    int TEST_LOOPS = 1000;
    double ALLOWABLE_DELTA = 100.0 / TEST_LOOPS; // rough check
    for (int i = 0; i < TEST_LOOPS; i++) {
        IVariant<VariantBean> assigned = va.enrollRequest(req);
        if (assigned != null)
            f.addValue(assigned.getName());
    }
    for (IVariant<VariantBean> vrb : coll.values()) {
        assertEquals(1.0 / num_variants, f.getPct(vrb.getName()), // NaN here can mean unknown name
                ALLOWABLE_DELTA);
    }
}

From source file:com.searchcode.app.jobs.IndexSvnRepoJob.java

public void execute(JobExecutionContext context) throws JobExecutionException {
    if (this.ENABLED == false) {
        return;/*from w  w  w.j av  a2  s .c  o  m*/
    }

    Thread.currentThread().setPriority(Thread.MIN_PRIORITY);

    while (CodeIndexer.shouldPauseAdding()) {
        Singleton.getLogger().info("Pausing parser.");
        return;
    }

    // Pull the next repo to index from the queue
    UniqueRepoQueue repoQueue = Singleton.getUniqueSvnRepoQueue();

    RepoResult repoResult = repoQueue.poll();
    AbstractMap<String, Integer> runningIndexRepoJobs = Singleton.getRunningIndexRepoJobs();

    if (repoResult != null && !runningIndexRepoJobs.containsKey(repoResult.getName())) {
        Singleton.getLogger().info("Indexing " + repoResult.getName());
        try {
            runningIndexRepoJobs.put(repoResult.getName(), (int) (System.currentTimeMillis() / 1000));

            JobDataMap data = context.getJobDetail().getJobDataMap();

            String repoName = repoResult.getName();
            String repoRemoteLocation = repoResult.getUrl();
            String repoUserName = repoResult.getUsername();
            String repoPassword = repoResult.getPassword();

            String repoLocations = data.get("REPOLOCATIONS").toString();
            this.LOWMEMORY = Boolean.parseBoolean(data.get("LOWMEMORY").toString());

            // Check if sucessfully cloned, and if not delete and restart
            boolean cloneSucess = checkCloneUpdateSucess(repoLocations + repoName);
            if (cloneSucess == false) {
                // Delete the folder
                try {
                    FileUtils.deleteDirectory(new File(repoLocations + repoName + "/"));
                    CodeIndexer.deleteByReponame(repoName);
                } catch (IOException ex) {
                    Singleton.getLogger().warning("ERROR - caught a " + ex.getClass() + " in " + this.getClass()
                            + "\n with message: " + ex.getMessage());
                    return;
                }
            }
            deleteCloneUpdateSuccess(repoLocations + repoName);

            String repoGitLocation = repoLocations + repoName + "/.svn/";

            File f = new File(repoGitLocation);
            boolean existingRepo = f.exists();
            boolean useCredentials = repoUserName != null && !repoUserName.isEmpty();
            RepositoryChanged repositoryChanged;

            if (existingRepo) {
                repositoryChanged = this.updateSvnRepository(repoName, repoRemoteLocation, repoUserName,
                        repoPassword, repoLocations, useCredentials);
            } else {
                repositoryChanged = this.checkoutSvnRepository(repoName, repoRemoteLocation, repoUserName,
                        repoPassword, repoLocations, useCredentials);
            }

            // Write file indicating we have sucessfully cloned
            createCloneUpdateSuccess(repoLocations + repoName);

            if (repositoryChanged.isChanged()) {
                Singleton.getLogger().info("Update found indexing " + repoRemoteLocation);
                this.updateIndex(repoName, repoLocations, repoRemoteLocation, existingRepo, repositoryChanged);
            }
        } finally {
            // Clean up the job
            runningIndexRepoJobs.remove(repoResult.getName());
        }
    }
}

From source file:com.searchcode.app.jobs.IndexGitRepoJob.java

public void execute(JobExecutionContext context) throws JobExecutionException {
    Thread.currentThread().setPriority(Thread.MIN_PRIORITY);

    while (CodeIndexer.shouldPauseAdding()) {
        Singleton.getLogger().info("Pausing parser.");
        return;/* ww  w  .  j a v a  2  s  . c  om*/
    }

    // Pull the next repo to index from the queue
    UniqueRepoQueue repoQueue = Singleton.getUniqueGitRepoQueue();

    RepoResult repoResult = repoQueue.poll();
    AbstractMap<String, Integer> runningIndexGitRepoJobs = Singleton.getRunningIndexRepoJobs();

    if (repoResult != null && !runningIndexGitRepoJobs.containsKey(repoResult.getName())) {
        Singleton.getLogger().info("Indexing " + repoResult.getName());
        try {
            runningIndexGitRepoJobs.put(repoResult.getName(), (int) (System.currentTimeMillis() / 1000));

            JobDataMap data = context.getJobDetail().getJobDataMap();

            String repoName = repoResult.getName();
            String repoRemoteLocation = repoResult.getUrl();
            String repoUserName = repoResult.getUsername();
            String repoPassword = repoResult.getPassword();
            String repoBranch = repoResult.getBranch();

            String repoLocations = data.get("REPOLOCATIONS").toString();
            this.LOWMEMORY = Boolean.parseBoolean(data.get("LOWMEMORY").toString());

            // Check if sucessfully cloned, and if not delete and restart
            boolean cloneSucess = checkCloneUpdateSucess(repoLocations + repoName);
            if (cloneSucess == false) {
                // Delete the folder and delete from the index
                try {
                    FileUtils.deleteDirectory(new File(repoLocations + "/" + repoName + "/"));
                    CodeIndexer.deleteByReponame(repoName);
                } catch (IOException ex) {
                    Singleton.getLogger().warning("ERROR - caught a " + ex.getClass() + " in " + this.getClass()
                            + "\n with message: " + ex.getMessage());
                }
            }
            deleteCloneUpdateSuccess(repoLocations + "/" + repoName);

            String repoGitLocation = repoLocations + "/" + repoName + "/.git/";

            File f = new File(repoGitLocation);
            boolean existingRepo = f.exists();
            boolean useCredentials = repoUserName != null && !repoUserName.isEmpty();
            RepositoryChanged repositoryChanged = null;

            if (existingRepo) {
                repositoryChanged = this.updateGitRepository(repoName, repoRemoteLocation, repoUserName,
                        repoPassword, repoLocations, repoBranch, useCredentials);
            } else {
                repositoryChanged = this.cloneGitRepository(repoName, repoRemoteLocation, repoUserName,
                        repoPassword, repoLocations, repoBranch, useCredentials);
            }

            // Write file indicating we have sucessfully cloned
            createCloneUpdateSuccess(repoLocations + "/" + repoName);
            // If the last index was not sucessful, then trigger full index
            boolean indexsuccess = checkIndexSucess(repoGitLocation);

            if (repositoryChanged.isChanged() || indexsuccess == false) {
                Singleton.getLogger().info("Update found indexing " + repoRemoteLocation);
                this.updateIndex(repoName, repoLocations, repoRemoteLocation, existingRepo, repositoryChanged);
            }
        } finally {
            // Clean up the job
            runningIndexGitRepoJobs.remove(repoResult.getName());
        }
    }
}

From source file:com.metaparadigm.jsonrpc.MapSerializer.java

public Object unmarshall(SerializerState state, Class clazz, Object o) throws UnmarshallException {
    JSONObject jso = (JSONObject) o;/*  w  ww  .  j  a va 2s  .  co m*/
    String java_class = null;
    try {
        java_class = jso.getString("javaClass");
    } catch (JSONException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    if (java_class == null)
        throw new UnmarshallException("no type hint");
    AbstractMap abmap = null;
    if (java_class.equals("java.util.Map") || java_class.equals("java.util.AbstractMap")
            || java_class.equals("java.util.HashMap")) {
        abmap = new HashMap();
    } else if (java_class.equals("java.util.TreeMap")) {
        abmap = new TreeMap();
    } else if (java_class.equals("java.util.LinkedHashMap")) {
        abmap = new LinkedHashMap();
    } else {
        throw new UnmarshallException("not a Map");
    }
    JSONObject jsonmap = null;
    try {
        jsonmap = jso.getJSONObject("map");
    } catch (JSONException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    if (jsonmap == null)
        throw new UnmarshallException("map missing");
    Iterator i = jsonmap.keys();
    String key = null;
    try {
        while (i.hasNext()) {
            key = (String) i.next();
            abmap.put(key, ser.unmarshall(state, null, jsonmap.get(key)));
        }
    } catch (UnmarshallException e) {
        throw new UnmarshallException("key " + key + " " + e.getMessage());
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return abmap;
}

From source file:org.agnitas.web.NewImportWizardAction.java

private ActionForward prepareResultPage(ActionMapping mapping, HttpServletRequest req,
        NewImportWizardForm aForm, AbstractMap<String, Object> futureHolder, String futureKeyProcess) {
    if (!aForm.isResultPagePrepared()) {

        if (!futureHolder.containsKey(futureKeyProcess) && aForm.getErrorsDuringImport() == null) {

            futureHolder.put(futureKeyProcess, assignMailinglists(aForm, req));
            aForm.setAction(NewImportWizardAction.ACTION_MLISTS);
            return mapping.findForward("progress");

        }//from  ww w.j  a va  2 s.  co  m
        if (futureHolder.containsKey(futureKeyProcess)
                && ((Future) futureHolder.get(futureKeyProcess)).isDone()) {
            removeTemporaryTable(req, aForm);
            removeStoredCsvFile(req);
            aForm.setResultPagePrepared(true);

            futureHolder.remove(futureKeyProcess);
            aForm.setRefreshMillis(RecipientForm.DEFAULT_REFRESH_MILLIS);
            NewImportWizardService importWizardHelper = aForm.getImportWizardHelper();
            if (importWizardHelper != null) {
                destroyTemporaryConnection(importWizardHelper.getImportRecipientsDao());
            }

            FormFile file = aForm.getCsvFile();
            Admin admin = AgnUtils.getAdmin(req);
            String userName = admin != null ? admin.getUsername() : "";
            String fileName = file != null ? file.getFileName() : "";
            AgnUtils.userlogger().info(userName + ": do import from file " + fileName);
            return mapping.findForward("result_page");
        } else {
            if (aForm.getRefreshMillis() < 100000) { // raise the refresh time
                aForm.setRefreshMillis(aForm.getRefreshMillis() + 50);
            }
        }
        aForm.setAction(NewImportWizardAction.ACTION_MLISTS);
        return mapping.findForward("progress");
    }

    NewImportWizardService importWizardHelper = aForm.getImportWizardHelper();
    if (importWizardHelper != null) {
        destroyTemporaryConnection(importWizardHelper.getImportRecipientsDao());
    }
    return mapping.findForward("result_page");
}

From source file:org.jabsorb.serializer.impl.MapSerializer.java

public Object unmarshall(SerializerState state, Class clazz, Object o) throws UnmarshallException {
    JSONObject jsonmap = (JSONObject) o;
    AbstractMap abmap = new HashMap();
    /*String java_class;
    try//from ww  w  . j a va  2  s  . c  o  m
    {
      java_class = jso.getString("javaClass");
    }
    catch (JSONException e)
    {
      throw new UnmarshallException("Could not read javaClass", e);
    }
    if (java_class == null)
    {
      throw new UnmarshallException("no type hint");
    }
    AbstractMap abmap;
    if (java_class.equals("java.util.Map")
        || java_class.equals("java.util.AbstractMap")
        || java_class.equals("java.util.HashMap"))
    {
      abmap = new HashMap();
    }
    else if (java_class.equals("java.util.TreeMap"))
    {
      abmap = new TreeMap();
    }
    else if (java_class.equals("java.util.LinkedHashMap"))
    {
      abmap = new LinkedHashMap();
    }
    else
    {
      throw new UnmarshallException("not a Map");
    }*/
    /*JSONObject jsonmap;
    try
    {
      jsonmap = jso.getJSONObject("map");
    }
    catch (JSONException e)
    {
      throw new UnmarshallException("Could not read map: " + e.getMessage(), e);
    }
    if (jsonmap == null)
    {
      throw new UnmarshallException("map missing");
    }*/
    state.setSerialized(o, abmap);
    Iterator i = jsonmap.keys();
    String key = null;
    try {
        while (i.hasNext()) {
            key = (String) i.next();
            abmap.put(key, ser.unmarshall(state, null, jsonmap.get(key)));
        }
    } catch (UnmarshallException e) {
        throw new UnmarshallException("key " + key + " " + e.getMessage(), e);
    } catch (JSONException e) {
        throw new UnmarshallException("key " + key + " " + e.getMessage(), e);
    }

    return abmap;
}

From source file:jetbrains.exodus.env.Reflect.java

public void traverseAll(List<DatabaseRoot> roots) {
    final LongSet traversed = new LongHashSet();
    final BTreeBalancePolicy strategy = env.getBTreeBalancePolicy();
    final MetaTree fallbackMetaTree = env.getMetaTree(null);
    final AbstractMap<Integer, Long> storeRoots = new IntHashMap<>();
    final int[] ids = new int[roots.size()]; // whatever
    int processed = 0;
    long totalLength = 0;
    for (final DatabaseRoot root : roots) {
        processed++;/*from   w w w .  ja v a 2  s.c o  m*/
        System.out.println(
                String.format("Processing root: %d, %d addresses traversed", processed, traversed.size()));
        int size = 0;
        final LongHashMap<TreeMetaInfo> meta = new LongHashMap<>();
        final BTree metaTree = new BTree(log, strategy, root.getRootAddress(), false,
                EnvironmentImpl.META_TREE_ID);
        try (ITreeCursor cursor = metaTree.openCursor()) {
            while (cursor.getNext()) {
                try {
                    cursor.getNext();
                } catch (ExodusException e) {
                    logging.error("Can't traverse meta tree");
                    break;
                }
                final ArrayByteIterable key = new ArrayByteIterable(cursor.getKey());
                if (MetaTree.isStringKey(key)) {
                    final TreeMetaInfo metaInfo = TreeMetaInfo.load(env, cursor.getValue());
                    meta.put(metaInfo.getStructureId(), metaInfo);
                } else {
                    final long address = CompressedUnsignedLongByteIterable.getLong(cursor.getValue());
                    final int structureId = (int) LongBinding.compressedEntryToLong(key);
                    final Long currentAddress = storeRoots.get(structureId);
                    if (currentAddress == null || currentAddress != address) {
                        ids[size++] = structureId;
                        storeRoots.put(structureId, address);
                    }
                }
            }
        }
        for (int i = 0; i < size; ++i) {
            final int id = ids[i];
            final Long currentRoot = storeRoots.get(id);
            TreeMetaInfo currentInfo = meta.get(id);

            if (currentInfo == null) {
                // try falling back to up-to-date meta-info
                final String name = fallbackMetaTree.getStoreNameByStructureId(id, env);
                if (name != null) {
                    currentInfo = fallbackMetaTree.getMetaInfo(name, env);
                }
                if (currentInfo == null) {
                    logging.error("No meta info for id: " + id);
                    continue;
                }
            }

            try {
                final BTree tree = new BTree(log, currentRoot, currentInfo.hasDuplicates(), id);

                final AddressIterator itr = tree.addressIterator();

                while (itr.hasNext()) {
                    final long address = itr.next();

                    if (traversed.contains(address)) {
                        itr.skipSubTree();
                    } else {
                        final RandomAccessLoggable loggable = log.read(address);
                        final int length = loggable.length();
                        totalLength += length;
                        traversed.add(address);
                    }
                }
            } catch (BlockNotFoundException ignored) {
            }
        }
        System.out.println(String.format("Total data processed: %10.2fk", (double) totalLength / 1024));
    }
}

From source file:org.agnitas.web.NewImportWizardAction.java

/**
  * Process the specified HTTP request, and create the corresponding HTTP
 * response (or forward to another web component that will create it).
 * Return an <code>ActionForward</code> instance describing where and how
 * control should be forwarded, or <code>null</code> if the response has
 * already been completed.<br>/*from  w w  w  . j  a  va  2s . c o m*/
 * Error and success messages are set during the action to give the user
 * a feedback in the forwarded web component.<br>
 * <br>
 * ACTION_START: Loads the list of all available profiles for import and ID of default import profile for current user.<br>
  *     Resets import status and resultPagePrepared property of form. Forwards to "start".
 * <br><br>
 * ACTION_PREVIEW: performs general validation before starting recipients import.<br>
  *     Initializes import helper with initial values; <br>
  *     Created unique import ID and sets it to import profile; <br>
  *     If csv-file is missing or there are no import profiles in system - forwards to "start" with corresponding
  *     error messages.<br>
  *     If import profile doesn't match the csv-file or has no key column in its column mappings forwards to
  *     "profile_edit" with corresponding error messages.<br>
  *     If validation is passed loads first 20 recipients from csv-file for preview, loads mailinglists into form,
  *     chooses mailinglist message according to import mode, forwards to "preview".<br>
  *     If the session parameter "IMPORT_KEY_COLUMNS" is set - import ignores key column from import profile and uses
  *     list of key columns from "IMPORT_KEY_COLUMNS" (example "email, firstname, lastname"). The values from this
  *     session parameter is set to import profile.
  * <br><br>
 * ACTION_PROCEED:<br>
  *     In general performs recipient import using settings from selected import profile.<br><br>
  *     If the FutureHolder doesn't contain yet the recipient import worker:<br>
  *     Checks if there are mailinglists selected. If the current import mode needs mailinglists and no list is
  *     selected - forwards to "preview" with appropriate error message. Stores the list of mailinglists to assign in
  *     form. Creates import recipient worker and puts it to FutureHolder. Stores import parameters (importMode,
  *     separator, delimiter etc.) to status property of form.<br><br>
  *     If FutureHolder is finished and there are errors for edit error page - forwards to error editing page and
  *     also checks for import limits.<br><br>
  *     If FutureHolder is finished and there are no errors for edit error page: puts worker for assigning
  *     mailinglists into FutureHolder (and forwards to "progress"), if that FutureHolder is finished - removes
  *     temporary table of import recipients from DB, removes stored csv, forwards to "result_page"; if it is still
  *     running - increases refresh rate and forwards to "progress". Also checks for import limits.<br><br>
  *     If FutureHolder is still running - increases refresh time and forwards to "progress"<br><br>
  *     If there were errors during the import - removed the recipient import worker from the FutureHolder and
  *     forwards to "preview" page with error messages.
 * <br><br>
  * ACTION_ERROR_EDIT:
  *     If the FutureHolder doesn't have task running and there's attribute "recipientsInCurrentTable" in request -
  *     validates recipient fixed on error edit page and performs the import for fixed recipients.<br>
  *     If there are still errors for error-edit-page - forwards to error-edit page. If there are no errors left -
  *     prepares result page: calls future holder for assigning mailing lists and forwards to "progress" or
  *     "result_page" depending on FutureHolder finished or not.
 * <br><br>
  * ACTION_MLISTS: puts worker for assigning mailinglists into FutureHolder (and forwards to "progress"), if that
  *     FutureHolder is finished - removes temporary table of import recipients from DB, removes stored csv,
  *     forwards to "result_page"; if it is still running - increases refresh rate and forwards to "progress".
 * <br><br>
  * ACTION_DOWNLOAD_CSV_FILE: checks what type of file user wants to download. Gets the file depending on that type.
  *     Writes that file to response (for user to download). Forwards to null destination.
 * <br><br>
 * Any other ACTION_* would cause a forward to null
 * <br><br>
  * If current destination is "error_edit":<br>
  * If the FutureHolder is not running yet - puts there a worker for getting invalid recipients from temporary table
  * containing beans of import-recipients from csv-file<br>
  * If the FutureHolder is not finished yet - increases refresh time and forwards to "loading"<br>
  * If FutureHolder is finished - puts found invalid recipients to request and to session attribute
  * "recipientsInCurrentTable", sets the total number of invalid recipients to form, removes current task from
  * FutureHolder
  * <br><br>
 * @param form data for the action filled by the jsp
 * @param req request from jsp <br>
  *   If the request parameter "start_proceed" is set - changes action to ACTION_PREVIEW.<br>
  *   If the request parameter "preview_back" is set - changes action to ACTION_START.<br>
  *   If the request parameter "preview_proceed" is set - changes action to ACTION_PROCEED.<br>
  *   If the request parameter "edit_page_save" is set - changes action to ACTION_ERROR_EDIT.<br>
 * @param res response
 * @param mapping
 *            The ActionMapping used to select this instance
 * @exception IOException
 *                if an input/output error occurs
 * @exception ServletException
 *                if a servlet exception occurs
 * @return destination specified in struts-config.xml to forward to next jsp
*/

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest req,
        HttpServletResponse res) throws IOException, ServletException {
    super.execute(mapping, form, req, res);

    AbstractMap<String, Object> futureHolder = (AbstractMap<String, Object>) getBean("futureHolder");
    String futureKeyList = FUTURE_TASK1 + "@" + req.getSession(false).getId();
    String futureKeyProcess = FUTURE_TASK2 + "@" + req.getSession(false).getId();
    String futureKeyWorker = FUTURE_TASK3 + "@" + req.getSession(false).getId();

    // Validate the request parameters specified by the user
    NewImportWizardForm aForm = null;
    ActionMessages errors = new ActionMessages();
    ActionForward destination = null;
    ApplicationContext aContext = this.getWebApplicationContext();

    if (!AgnUtils.isUserLoggedIn(req)) {
        return mapping.findForward("logon");
    }

    if (form != null) {
        aForm = (NewImportWizardForm) form;
    } else {
        aForm = new NewImportWizardForm();
    }

    if (logger.isInfoEnabled())
        logger.info("NewImportWizard action: " + aForm.getAction());

    if (AgnUtils.parameterNotEmpty(req, "start_proceed")) {
        aForm.setAction(NewImportWizardAction.ACTION_PREVIEW);
    }
    if (AgnUtils.parameterNotEmpty(req, "preview_back")) {
        aForm.setAction(NewImportWizardAction.ACTION_START);
    }
    if (AgnUtils.parameterNotEmpty(req, "preview_proceed")) {
        aForm.setAction(NewImportWizardAction.ACTION_PROCEED);
    }
    if (req.getParameter("edit_page_save") != null) {
        aForm.setAction(NewImportWizardAction.ACTION_ERROR_EDIT);
    }

    if (!allowed("wizard.import", req)) {
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.permissionDenied"));
        saveErrors(req, errors);
        return null;
    }

    try {
        NewImportWizardService importWizardHelper = aForm.getImportWizardHelper();
        switch (aForm.getAction()) {

        case NewImportWizardAction.ACTION_START:
            final Map<Integer, String> importProfiles = new HashMap<Integer, String>();
            aForm.setDefaultProfileId(AgnUtils.getAdmin(req).getDefaultImportProfileID());

            final List<ImportProfile> importProfileList = getProfileList(req);
            for (ImportProfile importProfile : importProfileList) {
                importProfiles.put(importProfile.getId(), importProfile.getName());
            }
            aForm.setImportProfiles(importProfiles);
            aForm.setStatus((CustomerImportStatus) getWebApplicationContext().getBean("CustomerImportStatus"));
            destination = mapping.findForward("start");
            aForm.setResultPagePrepared(false);

            break;

        case NewImportWizardAction.ACTION_PREVIEW:
            if (!aForm.getHasFile()
                    && (aForm.getCsvFile() == null || StringUtils.isEmpty(aForm.getCsvFile().getFileName()))) {
                errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.import.no_file"));
                destination = mapping.findForward("start");
            } else if (aForm.getImportProfiles().size() == 0) {
                errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.import.no_profile"));
                destination = mapping.findForward("start");
            } else {
                boolean profileFits = initImportWizardHelper(req, aForm, errors);
                boolean keyColumnValid = isProfileKeyColumnValid(aForm, errors);
                logImportStart(aForm);
                if ((!profileFits || !keyColumnValid) && !errors.isEmpty()) {
                    HttpSession session = req.getSession();
                    session.setAttribute(ImportProfileAction.IMPORT_PROFILE_ERRORS_KEY, errors);
                    session.setAttribute(ImportProfileAction.IMPORT_PROFILE_ID_KEY,
                            aForm.getDefaultProfileId());
                    destination = mapping.findForward("profile_edit");
                } else if (!errors.isEmpty()) {
                    destination = mapping.findForward("start");
                } else {
                    aForm.setPreviewParsedContent(importWizardHelper.getPreviewParsedContent(errors));
                    if (!errors.isEmpty()) {
                        destination = mapping.findForward("start");
                        break;
                    }

                    aForm.setAllMailingLists(getAllMailingLists(req));
                    aForm.setMailinglistAddMessage(createMailinglistAddMessage(aForm));

                    destination = mapping.findForward("preview");
                }
            }
            break;

        case NewImportWizardAction.ACTION_PROCEED:
            aForm.setAction(NewImportWizardAction.ACTION_PROCEED);
            destination = mapping.findForward("progress");
            if (!futureHolder.containsKey(futureKeyProcess) && aForm.getErrorsDuringImport() == null) {
                List<Integer> assignedLists = getAssignedMailingLists(req, aForm);
                if (!ignoreEmptyAssignedList()) {
                    int importMode = aForm.getImportWizardHelper().getImportProfile().getImportMode();
                    if ((importMode == ImportMode.ADD.getIntValue()
                            || importMode == ImportMode.ADD_AND_UPDATE.getIntValue())
                            && assignedLists.size() == 0) {
                        errors.add(ActionMessages.GLOBAL_MESSAGE,
                                new ActionMessage("error.import.no_mailinglist"));
                        destination = mapping.findForward("preview");
                        break;
                    }
                }

                aForm.setListsToAssign(assignedLists);
                final ImportRecipientsProcessWorker worker = new ImportRecipientsProcessWorker(
                        importWizardHelper);
                ImportProfile importProfile = aForm.getImportWizardHelper().getImportProfile();
                futureHolder.put(futureKeyProcess,
                        importRecipientsProcess(aForm, req, aContext, worker, importProfile));
                futureHolder.put(futureKeyWorker, worker);

                String charset = Charset.getPublicValue(importProfile.getCharset());
                String separator = Separator.getValue(importProfile.getSeparator());
                int mode = importProfile.getImportMode();
                int doublette = importProfile.getCheckForDuplicates();
                int nullValues = importProfile.getNullValuesAction();
                String recognitionChar = TextRecognitionChar.getValue(importProfile.getTextRecognitionChar());

                aForm.getStatus().setCharset(charset);
                aForm.getStatus().setSeparator(separator);
                aForm.getStatus().setMode(mode);
                aForm.getStatus().setDoubleCheck(doublette);
                aForm.getStatus().setIgnoreNull(nullValues);
                aForm.getStatus().setDelimiter(recognitionChar);
            }
            if (aForm.getErrorsDuringImport() != null) {
                errors.add(aForm.getErrorsDuringImport());
                destination = mapping.findForward("preview");
                futureHolder.remove(futureKeyProcess);
                futureHolder.remove(futureKeyWorker);
                aForm.setRefreshMillis(RecipientForm.DEFAULT_REFRESH_MILLIS);
                aForm.setErrorsDuringImport(null);
                break;
            }
            if (futureHolder.containsKey(futureKeyWorker) && futureHolder.get(futureKeyWorker) != null) {
                final ActionMessage message = ((ImportRecipientsProcessWorker) futureHolder
                        .get(futureKeyWorker)).getMessage();
                if (message != null) {
                    errors.add(ActionMessages.GLOBAL_MESSAGE, message);
                    futureHolder.remove(futureKeyProcess);
                    futureHolder.remove(futureKeyWorker);
                    aForm.setRefreshMillis(RecipientForm.DEFAULT_REFRESH_MILLIS);
                    destination = mapping.findForward("preview");
                    break;
                }
            }
            if (futureHolder.containsKey(futureKeyProcess)
                    && ((Future) futureHolder.get(futureKeyProcess)).isDone()) {
                futureHolder.remove(futureKeyProcess);
                futureHolder.remove(futureKeyWorker);
                if (importWizardHelper.isPresentErrorForErrorEditPage()) {
                    destination = mapping.findForward("error_edit");
                } else {
                    destination = prepareResultPage(mapping, req, aForm, futureHolder, futureKeyProcess);
                }
                destination = checkImportLimits(mapping, errors, destination, importWizardHelper, aForm, req,
                        futureHolder, futureKeyProcess);

                if ("start".equals(destination.getName())) {
                    futureHolder.remove(futureKeyProcess);
                    futureHolder.remove(futureKeyWorker);
                }

                aForm.setRefreshMillis(RecipientForm.DEFAULT_REFRESH_MILLIS);
            } else {
                if (aForm.getRefreshMillis() < 100000) { // raise the refresh time
                    aForm.setRefreshMillis(aForm.getRefreshMillis() + 50);
                }
                //aForm.set
            }
            break;
        case NewImportWizardAction.ACTION_ERROR_EDIT:
            if (!futureHolder.containsKey(futureKeyList)
                    && (PaginatedList) req.getSession().getAttribute("recipientsInCurrentTable") != null) {
                final HashMap<String, ProfileRecipientFields> mapRecipientsFromTable = new HashMap<String, ProfileRecipientFields>();
                final PaginatedList recipientsFromTable = (PaginatedList) req.getSession()
                        .getAttribute("recipientsInCurrentTable");
                for (Object object : recipientsFromTable.getList()) {
                    final Map dynaBean = (Map) object;
                    final ProfileRecipientFields recipient = (ProfileRecipientFields) dynaBean
                            .get(NewImportWizardService.ERROR_EDIT_RECIPIENT_EDIT_RESERVED);
                    mapRecipientsFromTable.put(recipient.getTemporaryId(), recipient);
                }
                final Map<String, String> changedRecipients = getChangedRecipients(req);
                for (String key : changedRecipients.keySet()) {
                    final String temporaryId = key.substring(0, key.indexOf("/RESERVED/"));
                    final String propertyName = key.substring(key.indexOf("/RESERVED/") + 10, key.length());
                    final ProfileRecipientFields recipient = mapRecipientsFromTable.get(temporaryId);
                    Toolkit.setValueFromBean(recipient, propertyName, changedRecipients.get(key));
                }

                importWizardHelper.setBeansAfterEditOnErrorEditPage(
                        new ArrayList<ProfileRecipientFields>(mapRecipientsFromTable.values()));
                importWizardHelper.doValidate(true);
            }
            if (importWizardHelper.isPresentErrorForErrorEditPage()) {
                destination = mapping.findForward("error_edit");
            } else {
                destination = prepareResultPage(mapping, req, aForm, futureHolder, futureKeyProcess);
            }
            destination = checkImportLimits(mapping, errors, destination, importWizardHelper, aForm, req,
                    futureHolder, futureKeyProcess);
            break;
        case NewImportWizardAction.ACTION_MLISTS:
            destination = prepareResultPage(mapping, req, aForm, futureHolder, futureKeyProcess);
            break;

        case NewImportWizardAction.ACTION_DOWNLOAD_CSV_FILE:
            File outfile = null;
            if (aForm.getDownloadFileType() == NewImportWizardService.RECIPIENT_TYPE_VALID) {
                outfile = aForm.getValidRecipientsFile();
            } else if (aForm.getDownloadFileType() == NewImportWizardService.RECIPIENT_TYPE_INVALID) {
                outfile = aForm.getInvalidRecipientsFile();
            } else if (aForm.getDownloadFileType() == NewImportWizardService.RECIPIENT_TYPE_FIXED_BY_HAND) {
                outfile = aForm.getFixedRecipientsFile();
            } else if (aForm
                    .getDownloadFileType() == NewImportWizardService.RECIPIENT_TYPE_DUPLICATE_RECIPIENT) {
                outfile = aForm.getDuplicateRecipientsFile();
            } else if (aForm.getDownloadFileType() == NewImportWizardService.RESULT_TYPE) {
                outfile = aForm.getResultFile();
            }
            transferFile(res, errors, outfile);
            destination = null;
            break;
        }

    } catch (Exception e) {
        logger.error("execute: " + e + "\n" + AgnUtils.getStackTrace(e));
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.exception"));
    }

    if (destination != null && "error_edit".equals(destination.getName())) {
        try {
            setNumberOfRows(req, aForm);
            destination = mapping.findForward("loading");

            if (!futureHolder.containsKey(futureKeyList)) {
                futureHolder.put(futureKeyList, getRecipientListFuture(req, aContext, aForm));
            }

            if (futureHolder.containsKey(futureKeyList)
                    && ((Future) futureHolder.get(futureKeyList)).isDone()) {
                req.setAttribute("recipientList", ((Future) futureHolder.get(futureKeyList)).get());
                req.getSession().setAttribute("recipientsInCurrentTable",
                        ((Future) futureHolder.get(futureKeyList)).get());
                destination = mapping.findForward("error_edit");
                aForm.setAll(
                        ((PaginatedList) ((Future) futureHolder.get(futureKeyList)).get()).getFullListSize());
                futureHolder.remove(futureKeyList);
                aForm.setRefreshMillis(RecipientForm.DEFAULT_REFRESH_MILLIS);
            } else {
                if (aForm.getRefreshMillis() < 1000) { // raise the refresh time
                    aForm.setRefreshMillis(aForm.getRefreshMillis() + 50);
                }
                aForm.setError(false);
            }

        } catch (Exception e) {
            logger.error("recipientList: " + e + "\n" + AgnUtils.getStackTrace(e));
            errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.exception"));
            aForm.setError(true); // do not refresh when an error has been occurred
        }
    }

    // Report any errors we have discovered back to the original form
    if (!errors.isEmpty() && destination != null)

    {
        saveErrors(req, errors);
        if (destination.getName().equals("progress")) {
            aForm.setErrorsDuringImport(errors);
        }
        // return new ActionForward(mapping.getForward());
    }

    return destination;
}