List of usage examples for java.util AbstractMap get
public V get(Object key)
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 va 2s . 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 ww w .ja 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; }
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 www . ja v a 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"); }