Example usage for java.util AbstractMap containsKey

List of usage examples for java.util AbstractMap containsKey

Introduction

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

Prototype

public boolean containsKey(Object key) 

Source Link

Usage

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

public void execute(JobExecutionContext context) throws JobExecutionException {
    if (this.ENABLED == false) {
        return;/*from   ww w.j  a  va 2  s . com*/
    }

    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;/*w  ww  .  j a  v  a2s. com*/
    }

    // 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: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  v a 2 s  .c om*/
 * 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;
}

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 w  ww  .j ava 2 s  . c  o  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.apache.hadoop.dfs.DFSClient.java

/**
 * Pick the best node from which to stream the data.
 * Entries in <i>nodes</i> are already in the priority order
 *///from  w  ww.j  a v  a2 s  .  c o m
private DatanodeInfo bestNode(DatanodeInfo nodes[], AbstractMap<DatanodeInfo, DatanodeInfo> deadNodes)
        throws IOException {
    if (nodes != null) {
        for (int i = 0; i < nodes.length; i++) {
            if (!deadNodes.containsKey(nodes[i])) {
                return nodes[i];
            }
        }
    }
    throw new IOException("No live nodes contain current block");
}

From source file:org.apache.hadoop.hdfs.DFSInputStream.java

/**
 * Pick the best node from which to stream the data.
 * Entries in <i>nodes</i> are already in the priority order
 *///from w w  w.  j a v  a  2 s.co m
static DatanodeInfo bestNode(DatanodeInfo nodes[], AbstractMap<DatanodeInfo, DatanodeInfo> deadNodes,
        Collection<DatanodeInfo> ignoredNodes) throws IOException {
    if (nodes != null) {
        for (int i = 0; i < nodes.length; i++) {
            if (!deadNodes.containsKey(nodes[i])
                    && (ignoredNodes == null || !ignoredNodes.contains(nodes[i]))) {
                return nodes[i];
            }
        }
    }
    throw new IOException("No live nodes contain current block");
}

From source file:org.apache.hadoop.hdfs.DFSInputStream.java

/**
 * Pick the best node from which to stream the data.
 * Entries in <i>nodes</i> are already in the priority order
 *///  w w w.  ja  v  a2  s  . c o m
static DatanodeInfo bestNode(DatanodeInfo nodes[], AbstractMap<DatanodeInfo, DatanodeInfo> deadNodes)
        throws IOException {
    if (nodes != null) {
        for (int i = 0; i < nodes.length; i++) {
            if (!deadNodes.containsKey(nodes[i])) {
                return nodes[i];
            }
        }
    }
    throw new IOException("No live nodes contain current block");
}