2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.io
.e4
.out
.cdmlight
;
12 import java
.text
.SimpleDateFormat
;
13 import java
.util
.Calendar
;
14 import java
.util
.HashSet
;
15 import java
.util
.List
;
16 import java
.util
.UUID
;
18 import javax
.inject
.Inject
;
19 import javax
.inject
.Named
;
21 import org
.apache
.commons
.lang
.StringUtils
;
22 import org
.eclipse
.e4
.core
.contexts
.IEclipseContext
;
23 import org
.eclipse
.e4
.core
.di
.annotations
.Optional
;
24 import org
.eclipse
.e4
.ui
.services
.IServiceConstants
;
25 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
26 import org
.eclipse
.jface
.viewers
.TreeSelection
;
27 import org
.eclipse
.swt
.widgets
.Combo
;
29 import eu
.etaxonomy
.cdm
.ext
.geo
.CondensedDistributionRecipe
;
30 import eu
.etaxonomy
.cdm
.filter
.TaxonNodeFilter
;
31 import eu
.etaxonomy
.cdm
.io
.cdmLight
.CdmLightExportConfigurator
;
32 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
33 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
34 import eu
.etaxonomy
.cdm
.persistence
.dto
.TaxonNodeDto
;
35 import eu
.etaxonomy
.taxeditor
.io
.e4
.out
.AbstractExportWizardE4
;
36 import eu
.etaxonomy
.taxeditor
.io
.wizard
.ExportToFileDestinationWizardPage
;
37 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
38 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
45 public class CdmLightExportWizardE4
extends
46 AbstractExportWizardE4
<CdmLightExportConfigurator
> {
49 private CdmLightExportConfigurator configurator
;
50 private ExportToFileDestinationWizardPage page
;
51 private MetaDataConfigurationWizardPage metaDataPage
;
52 public static final String DATE_FORMAT_NOW
= "yyyyMMddHHmm";
53 TaxonNodeDto selectedNode
;
56 public CdmLightExportWizardE4(IEclipseContext context
,
57 @Optional@Named(IServiceConstants
.ACTIVE_SELECTION
)IStructuredSelection selection
) {
58 super(context
, selection
);
63 configurator
= new CdmLightExportConfigurator(null);
64 configurator
.setCreateCondensedDistributionString(PreferencesUtil
.getBooleanValue(PreferencePredicate
.CdmLightExportCondensedDistributionString
.getKey()));
65 if (configurator
.isCreateCondensedDistributionString()){
66 String recipeString
= PreferencesUtil
.getStringValue(PreferencePredicate
.CondensedDistributionRecipe
.getKey());
67 if (StringUtils
.isNotBlank(recipeString
)){
68 configurator
.setCondensedDistributionRecipe(CondensedDistributionRecipe
.valueOf(recipeString
));
71 if (selection
instanceof TreeSelection
&& !selection
.isEmpty() && selection
.getFirstElement() instanceof TaxonNodeDto
){
72 selectedNode
= (TaxonNodeDto
)selection
.getFirstElement();
74 if (selectedNode
.getParentUUID() == null){
75 configurator
.setTaxonNodeFilter(TaxonNodeFilter
.NewClassificationInstance(selectedNode
.getClassificationUUID()));
77 configurator
.setTaxonNodeFilter(TaxonNodeFilter
.NewSubtreeInstance(selectedNode
.getUuid()));
85 public CdmLightExportConfigurator
getConfigurator() {
91 public boolean performFinish() {
92 String urlString
= page
.getFolderText() + File
.separator
;
93 if (configurator
.isCreateZipFile()){
94 SimpleDateFormat sdf
= new SimpleDateFormat(DATE_FORMAT_NOW
);
95 Calendar cal
= Calendar
.getInstance();
97 if (!configurator
.getTaxonNodeFilter().getSubtreeFilter().isEmpty()){
98 urlString
+= selectedNode
.getNameCache()+"_cdmLight_"+sdf
.format(cal
.getTime());
99 }else if (!configurator
.getTaxonNodeFilter().getClassificationFilter().isEmpty()){
100 urlString
+= page
.getSelectedClassification().getTitleCache()+"_cdmLight_"+sdf
.format(cal
.getTime());
101 page
.getSelectedClassification();
106 //+ page.getExportFileName();
108 final Combo combo
= page
.getCombo();
109 if (metaDataPage
!= null){
110 metaDataPage
.fillConfig();
111 configurator
= metaDataPage
.configurator
;
114 final List
<Classification
> listClassifications
= CdmStore
.getCurrentApplicationConfiguration().getClassificationService().listClassifications(null, null, null, null);
116 int selectionIndex
= combo
.getSelectionIndex();
117 HashSet
<UUID
> set
= new HashSet
<UUID
>();
118 if(selectionIndex
== -1){
119 for(Classification c
:listClassifications
){
120 set
.add(c
.getUuid());
123 for(Classification c
:listClassifications
){
124 if(c
.getTitleCache().equalsIgnoreCase(combo
.getItem(selectionIndex
))){
125 set
.add(c
.getUuid());
127 if (!page
.getCheckUseSelectedTaxonNode()){
128 configurator
.setTaxonNodeFilter(TaxonNodeFilter
.NewClassificationInstance(c
.getUuid()));
136 configurator
.getTaxonNodeFilter().setIncludeUnpublished(page
.isExportUnpublishedData());
137 CdmStore
.getExportManager().runMoniteredOperation(configurator
, urlString
);
139 // Job job = CdmStore.getExportManager().createIOServiceJob(configurator, urlString);
140 // // configure the job
141 // job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
142 // job.setUser(true);
145 PreferencesUtil
.setStringValue("exportFolder", page
.getFolderText());
150 public void addPages() {
152 page
= ExportToFileDestinationWizardPage
.OutputModel(configurator
);
156 if (PreferencesUtil
.showGfbioMetaData()){
157 metaDataPage
= new MetaDataConfigurationWizardPage("Add Meta Data", configurator
);
158 addPage(metaDataPage
);