private void exportElement(final ExportTransaction exportTransaction) throws CommandException { final ExportThread thread = new ExportThread(exportTransaction); configureThread(thread); thread.export(); getValuesFromThread(thread); exportChildren(exportTransaction); }
/** @param exportThread */ private void getValuesFromThread(final ExportThread exportThread) { linkSet.addAll(exportThread.getLinkSet()); attachmentSet.addAll(exportThread.getAttachmentSet()); exportedEntityTypes.addAll(exportThread.getExportedEntityTypes()); exportedTypes.addAll(exportThread.getExportedTypes()); changedElements.addAll(exportThread.getChangedElementList()); final CnATreeElement element = getElementFromThread(exportThread); if (element != null && FinishedRiskAnalysis.TYPE_ID.equals(element.getTypeId())) { riskAnalysisIdSet.add(element.getDbId()); } }
private void configureThread(final ExportThread thread) { thread.setCommandService(getCommandService()); thread.setCache(getCache()); thread.setDao(getDao()); thread.setAttachmentDao(getDaoFactory().getDAO(Attachment.class)); thread.setHuiTypeFactory(getHuiTypeFactory()); thread.setSourceId(sourceId); thread.setVeriniceArchive(isVeriniceArchive()); thread.setReImport(isReImport()); thread.setEntityTypesBlackList(getEntityTypesBlackList()); thread.setEntityClassBlackList(getEntityClassBlackList()); }
private void exportChildren(final ExportTransaction transaction) throws CommandException { final int timeOutFactor = 40; final CnATreeElement element = transaction.getElement(); final Set<CnATreeElement> children = element.getChildren(); if (FinishedRiskAnalysis.TYPE_ID.equals(element.getTypeId())) { children.addAll(getRiskAnalysisOrphanElements(element)); } final List<ExportTransaction> transactionList = new ArrayList<ExportTransaction>(); taskExecutor = Executors.newFixedThreadPool(getMaxNumberOfThreads()); if (!children.isEmpty()) { for (final CnATreeElement child : children) { final ExportTransaction childTransaction = new ExportTransaction(child); transactionList.add(childTransaction); final ExportThread thread = new ExportThread(childTransaction); configureThread(thread); // Multi thread: thread.addListener( new IThreadCompleteListener() { @Override public void notifyOfThreadComplete(final Thread thread) { final ExportThread exportThread = (ExportThread) thread; synchronized (LOCK) { if (exportThread.getSyncObject() != null) { transaction.getTarget().getChildren().add(exportThread.getSyncObject()); } getValuesFromThread(exportThread); } } }); taskExecutor.execute(thread); } } awaitTermination(transactionList.size() * timeOutFactor); if (getLog().isDebugEnabled() && transactionList.size() > 0) { getLog().debug(transactionList.size() + " export threads finished."); } for (final ExportTransaction childTransaction : transactionList) { if (checkElement(childTransaction.getElement())) { exportChildren(childTransaction); } } }
private CnATreeElement getElementFromThread(final ExportThread exportThread) { if (exportThread == null || exportThread.getTransaction() == null) { return null; } return exportThread.getTransaction().getElement(); }
public void onExportFinished(ExportThread task) { if (task.isCancelled()) { if (finish_after) finish(); return; } AlertDialog alertDialog = new AlertDialog.Builder(AdministrationFunctions.this).create(); alertDialog.setTitle(R.string.email_export); alertDialog.setIcon(android.R.drawable.ic_menu_send); alertDialog.setButton2( getResources().getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // setup the mail message final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE); emailIntent.setType("plain/text"); // emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, // context.getString(R.string.debug_email).split(";")); String subject = "[" + getString(R.string.app_name) + "] " + getString(R.string.export_data); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject); // emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, // context.getString(R.string.debug_body)); // has to be an ArrayList ArrayList<Uri> uris = new ArrayList<Uri>(); // Find all files of interest to send try { File fileIn = new File(StorageUtils.getSharedStoragePath() + "/" + "export.csv"); Uri u = Uri.fromFile(fileIn); uris.add(u); // Send it, if there are any files to send. emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); startActivity(Intent.createChooser(emailIntent, "Send mail...")); } catch (NullPointerException e) { Logger.logError(e); Toast.makeText( AdministrationFunctions.this, R.string.export_failed_sdcard, Toast.LENGTH_LONG) .show(); } dialog.dismiss(); } }); alertDialog.setButton( getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // do nothing dialog.dismiss(); } }); alertDialog.setOnDismissListener( new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { if (finish_after) finish(); } }); if (!isFinishing()) { try { // // Catch errors resulting from 'back' being pressed multiple times so that the activity is // destroyed // before the dialog can be shown. // See http://code.google.com/p/android/issues/detail?id=3953 // alertDialog.show(); } catch (Exception e) { Logger.logError(e); } } }
/** * Export all data to a CSV file * * <p>return void */ public void exportData() { ExportThread thread = new ExportThread(getTaskManager()); thread.start(); }