1
|
/**
|
2
|
* Copyright (C) 2017 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.io.e4.out.cdmlight;
|
10
|
|
11
|
import java.io.File;
|
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;
|
17
|
|
18
|
import javax.inject.Inject;
|
19
|
import javax.inject.Named;
|
20
|
|
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;
|
28
|
|
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;
|
39
|
|
40
|
/**
|
41
|
* @author k.luther
|
42
|
* @date 21.03.2017
|
43
|
*/
|
44
|
public class CdmLightExportWizardE4 extends
|
45
|
AbstractExportWizardE4<CdmLightExportConfigurator> {
|
46
|
|
47
|
|
48
|
private CdmLightExportConfigurator configurator;
|
49
|
private ExportToFileDestinationWizardPage page;
|
50
|
private MetaDataConfigurationWizardPage metaDataPage;
|
51
|
public static final String DATE_FORMAT_NOW = "yyyyMMddHHmm";
|
52
|
TaxonNodeDto selectedNode;
|
53
|
|
54
|
@Inject
|
55
|
public CdmLightExportWizardE4(IEclipseContext context,
|
56
|
@Optional@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection) {
|
57
|
super(context, selection);
|
58
|
}
|
59
|
|
60
|
@Override
|
61
|
public void init() {
|
62
|
configurator = CdmLightExportConfigurator.NewInstance();
|
63
|
String recipeString = PreferencesUtil.getStringValue(PreferencePredicate.CondensedDistributionRecipe.getKey());
|
64
|
if (StringUtils.isNotBlank(recipeString)){
|
65
|
configurator.setCondensedDistributionConfiguration(CondensedDistributionRecipe.valueOf(recipeString).toConfiguration());
|
66
|
}
|
67
|
if (selection instanceof TreeSelection && !selection.isEmpty() && selection.getFirstElement() instanceof TaxonNodeDto){
|
68
|
selectedNode = (TaxonNodeDto)selection.getFirstElement();
|
69
|
|
70
|
if (selectedNode.getParentUUID() == null){
|
71
|
configurator.setTaxonNodeFilter(TaxonNodeFilter.NewClassificationInstance(selectedNode.getClassificationUUID()));
|
72
|
}else{
|
73
|
configurator.setTaxonNodeFilter(TaxonNodeFilter.NewSubtreeInstance(selectedNode.getUuid()));
|
74
|
}
|
75
|
}
|
76
|
}
|
77
|
|
78
|
|
79
|
@Override
|
80
|
public CdmLightExportConfigurator getConfigurator() {
|
81
|
return configurator;
|
82
|
}
|
83
|
|
84
|
@Override
|
85
|
public boolean performFinish() {
|
86
|
String urlString = page.getFolderText() + File.separator ;
|
87
|
if (configurator.isCreateZipFile()){
|
88
|
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
|
89
|
Calendar cal = Calendar.getInstance();
|
90
|
|
91
|
if (!configurator.getTaxonNodeFilter().getSubtreeFilter().isEmpty()){
|
92
|
urlString += selectedNode.getNameCache().replace(" ", "_")+"_cdmLight_"+sdf.format(cal.getTime());
|
93
|
}else if (!configurator.getTaxonNodeFilter().getClassificationFilter().isEmpty()){
|
94
|
urlString += page.getSelectedClassification().getTitleCache().replace(" ", "_")+"_cdmLight_"+sdf.format(cal.getTime());
|
95
|
page.getSelectedClassification();
|
96
|
}
|
97
|
|
98
|
}
|
99
|
|
100
|
//+ page.getExportFileName();
|
101
|
|
102
|
final Combo combo = page.getCombo();
|
103
|
if (metaDataPage != null){
|
104
|
metaDataPage.fillConfig();
|
105
|
configurator = metaDataPage.configurator;
|
106
|
}
|
107
|
|
108
|
final List<Classification> listClassifications = CdmStore.getCurrentApplicationConfiguration().getClassificationService().listClassifications(null, null, null, null);
|
109
|
if(combo != null){
|
110
|
int selectionIndex = combo.getSelectionIndex();
|
111
|
HashSet<UUID> set = new HashSet<UUID>();
|
112
|
if(selectionIndex == -1){
|
113
|
for(Classification c:listClassifications){
|
114
|
set.add(c.getUuid());
|
115
|
}
|
116
|
}else{
|
117
|
for(Classification c:listClassifications){
|
118
|
if(c.getTitleCache().equalsIgnoreCase(combo.getItem(selectionIndex))){
|
119
|
set.add(c.getUuid());
|
120
|
|
121
|
if (!page.getCheckUseSelectedTaxonNode()){
|
122
|
configurator.setTaxonNodeFilter(TaxonNodeFilter.NewClassificationInstance(c.getUuid()));
|
123
|
}
|
124
|
}
|
125
|
}
|
126
|
|
127
|
|
128
|
}
|
129
|
}
|
130
|
configurator.getTaxonNodeFilter().setIncludeUnpublished(page.isExportUnpublishedData());
|
131
|
CdmStore.getExportManager().runMoniteredOperation(configurator, urlString);
|
132
|
// create job
|
133
|
// Job job = CdmStore.getExportManager().createIOServiceJob(configurator, urlString);
|
134
|
// // configure the job
|
135
|
// job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
|
136
|
// job.setUser(true);
|
137
|
// // schedule job
|
138
|
// job.schedule();
|
139
|
PreferencesUtil.setStringValue("exportFolder", page.getFolderText());
|
140
|
return true;
|
141
|
}
|
142
|
|
143
|
@Override
|
144
|
public void addPages() {
|
145
|
//standard page
|
146
|
page = ExportToFileDestinationWizardPage.OutputModel(configurator);
|
147
|
|
148
|
addPage(page);
|
149
|
super.addPages();
|
150
|
if (PreferencesUtil.showGfbioMetaData()){
|
151
|
metaDataPage = new MetaDataConfigurationWizardPage("Add Meta Data", configurator);
|
152
|
addPage(metaDataPage);
|
153
|
}
|
154
|
|
155
|
}
|
156
|
|
157
|
}
|