1
|
/**
|
2
|
* Copyright (C) 2015 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.cdm.io.common;
|
10
|
|
11
|
import java.io.Serializable;
|
12
|
|
13
|
import eu.etaxonomy.cdm.common.IoResultBase;
|
14
|
|
15
|
|
16
|
/**
|
17
|
* @author cmathew
|
18
|
* @since 31 Jul 2015
|
19
|
*/
|
20
|
public class ExportResult extends IoResultBase implements Serializable {
|
21
|
|
22
|
private static final long serialVersionUID = 6843406252245776806L;
|
23
|
|
24
|
private ExportResultState state;
|
25
|
|
26
|
//resulting files
|
27
|
private ExportDataWrapper<?> data ;
|
28
|
|
29
|
private ExportType exportType;
|
30
|
|
31
|
|
32
|
// **************************** FACTORY ****************************************/
|
33
|
|
34
|
public static ExportResult NewInstance(ExportResultType type){
|
35
|
return new ExportResult(type);
|
36
|
}
|
37
|
|
38
|
public static ExportResult NewNoDataInstance(ExportResultType type){
|
39
|
ExportResult result = new ExportResult(type);
|
40
|
result.state = ExportResultState.SUCCESS_BUT_NO_DATA;
|
41
|
return result;
|
42
|
}
|
43
|
|
44
|
|
45
|
// *********************** CONSTRUCTOR *****************************************/
|
46
|
|
47
|
private ExportResult(ExportResultType type) {
|
48
|
if (type == null){
|
49
|
type = ExportResultType.LIST_BYTE_ARRAY;
|
50
|
}
|
51
|
state = ExportResultState.SUCCESS;
|
52
|
if (type.equals(ExportResultType.BYTE_ARRAY)){
|
53
|
data = ExportDataWrapper.NewByteArrayInstance();
|
54
|
}else if (type.equals(ExportResultType.LIST_BYTE_ARRAY)){
|
55
|
data = ExportDataWrapper.NewListByteArrayInstance();
|
56
|
}else if (type.equals(ExportResultType.MAP_BYTE_ARRAY)){
|
57
|
data = ExportDataWrapper.NewMapByteArrayInstance();
|
58
|
}
|
59
|
}
|
60
|
|
61
|
public enum ExportResultState{
|
62
|
SUCCESS_BUT_NO_DATA, //Only if NO data at all is exported, if only 1 class is exported use SUCCESS
|
63
|
SUCCESS, //All configured data exported, no warning, no errors
|
64
|
SUCCESS_WITH_WARNING, //All data exported but with some warnings
|
65
|
FINISHED_WITH_ERROR, //Probably all data exported but with errors
|
66
|
INCOMPLETE_WITH_ERROR, //Run to the end, but in the middle there might be "larger" amounts of data missing, e.g. some parts did not run to the end
|
67
|
CANCELED, //Export canceled by the user
|
68
|
ABORTED, //An handled exception occurred that lead to abort the export
|
69
|
;
|
70
|
}
|
71
|
|
72
|
// **************** GETTER /SETTER *********************/
|
73
|
|
74
|
public boolean isSuccess(){
|
75
|
return state == ExportResultState.SUCCESS || state == ExportResultState.SUCCESS_WITH_WARNING;
|
76
|
}
|
77
|
|
78
|
public ExportResultState getState() {return state;}
|
79
|
public void setState(ExportResultState state) {this.state = state;}
|
80
|
|
81
|
|
82
|
|
83
|
public ExportDataWrapper<?> getExportData() {return data;}
|
84
|
public void setExportData(ExportDataWrapper<?> data) {this.data = data;}
|
85
|
public void addExportData(byte[] exportData) {
|
86
|
data.addExportData(exportData);
|
87
|
}
|
88
|
public void putExportData(String tableName, byte[] exportData) {
|
89
|
data.putExportData(tableName, exportData);
|
90
|
}
|
91
|
|
92
|
|
93
|
@Override
|
94
|
protected void setExceptionState() {
|
95
|
state = ExportResultState.INCOMPLETE_WITH_ERROR;
|
96
|
}
|
97
|
|
98
|
@Override
|
99
|
public void setAborted() {this.state = ExportResultState.ABORTED;}
|
100
|
|
101
|
|
102
|
@Override
|
103
|
public String toString() {
|
104
|
return state.toString();
|
105
|
}
|
106
|
|
107
|
/**
|
108
|
* @param invoke
|
109
|
*/
|
110
|
public void merge(ExportResult invoke) {
|
111
|
// TODO implemented
|
112
|
}
|
113
|
|
114
|
/**
|
115
|
* @param message
|
116
|
* @param dwcaTypesExport
|
117
|
* @param string
|
118
|
*/
|
119
|
public void addError(String message, CdmExportBase<?,?,?,?> exportBase, String location) {
|
120
|
this.addError(message, exportBase.getClass().getSimpleName() + "." + location);
|
121
|
|
122
|
}
|
123
|
|
124
|
/**
|
125
|
* @return the exportType
|
126
|
*/
|
127
|
public ExportType getExportType() {
|
128
|
return exportType;
|
129
|
}
|
130
|
|
131
|
/**
|
132
|
* @param exportType the exportType to set
|
133
|
*/
|
134
|
public void setExportType(ExportType exportType) {
|
135
|
this.exportType = exportType;
|
136
|
}
|
137
|
|
138
|
/**
|
139
|
* @param report
|
140
|
*/
|
141
|
@Override
|
142
|
protected void addShortDescription(StringBuffer report) {
|
143
|
if (this.isSuccess()){
|
144
|
report.append("\n" + "Export was successfull.");
|
145
|
}
|
146
|
|
147
|
if (!this.isSuccess()){
|
148
|
report.append("\n" + "Export had some problems.");
|
149
|
}
|
150
|
|
151
|
}
|
152
|
|
153
|
|
154
|
|
155
|
}
|