Project

General

Profile

Download (4.07 KB) Statistics
| Branch: | Tag: | Revision:
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
 */
21
public class ExportResult extends IoResultBase implements Serializable {
22

    
23
    private static final long serialVersionUID = 6843406252245776806L;
24

    
25
    private ExportResultState state;
26

    
27
    //resulting files
28
    private ExportDataWrapper<?> data ;
29

    
30
    private ExportType exportType;
31

    
32

    
33
// **************************** FACTORY ****************************************/
34

    
35

    
36

    
37
    public static ExportResult NewInstance(ExportResultType type){
38
        return new ExportResult(type);
39
    }
40

    
41
    public static ExportResult NewNoDataInstance(ExportResultType type){
42
        ExportResult result = new ExportResult(type);
43
        result.state = ExportResultState.SUCCESS_BUT_NO_DATA;
44
        return result;
45
    }
46

    
47

    
48
// *********************** CONSTRUCTOR *****************************************/
49

    
50
    private ExportResult(ExportResultType type) {
51
        if (type == null){
52
            type = ExportResultType.LIST_BYTE_ARRAY;
53
        }
54
        state = ExportResultState.SUCCESS;
55
        if (type.equals(ExportResultType.BYTE_ARRAY)){
56
            data = ExportDataWrapper.NewByteArrayInstance();
57
        }else if (type.equals(ExportResultType.LIST_BYTE_ARRAY)){
58
            data = ExportDataWrapper.NewListByteArrayInstance();
59
        }else if (type.equals(ExportResultType.MAP_BYTE_ARRAY)){
60
            data = ExportDataWrapper.NewMapByteArrayInstance();
61
        }
62
    }
63

    
64
    public enum ExportResultState{
65
        SUCCESS_BUT_NO_DATA,   //Only if NO data at all is exported, if only 1 class is exported use SUCCESS
66
        SUCCESS,               //All configured data exported, no warning, no errors
67
        SUCCESS_WITH_WARNING,   //All data exported but with some warnings
68
        FINISHED_WITH_ERROR,    //Probably all data exported but with errors
69
        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
70
        CANCELED,              //Export canceled by the user
71
        ABORTED,                //An handled exception occurred that lead to abort the export
72
        ;
73
    }
74

    
75
// **************** GETTER /SETTER *********************/
76

    
77
    public boolean isSuccess(){
78
        return state == ExportResultState.SUCCESS || state == ExportResultState.SUCCESS_WITH_WARNING;
79
    }
80

    
81
    public ExportResultState getState() {return state;}
82
    public void setState(ExportResultState state) {this.state = state;}
83

    
84

    
85

    
86
    public ExportDataWrapper<?> getExportData() {return data;}
87
    public void setExportData(ExportDataWrapper<?> data) {this.data = data;}
88
    public void addExportData(byte[] exportData) {
89
        data.addExportData(exportData);
90
    }
91
    public void putExportData(String tableName, byte[] exportData) {
92
        data.putExportData(tableName, exportData);
93
    }
94

    
95

    
96
    @Override
97
    protected void setExceptionState() {
98
        state = ExportResultState.INCOMPLETE_WITH_ERROR;
99
    }
100

    
101
    @Override
102
    public void setAborted() {this.state = ExportResultState.ABORTED;}
103

    
104

    
105
    @Override
106
    public String toString() {
107
        return state.toString();
108
    }
109

    
110
    /**
111
     * @param invoke
112
     */
113
    public void merge(ExportResult invoke) {
114
        // TODO implemented
115
    }
116

    
117
    /**
118
     * @param message
119
     * @param dwcaTypesExport
120
     * @param string
121
     */
122
    public void addError(String message, CdmExportBase<?,?,?,?> exportBase, String location) {
123
        this.addError(message,  exportBase.getClass().getSimpleName() + "." + location);
124

    
125
    }
126

    
127
    /**
128
     * @return the exportType
129
     */
130
    public ExportType getExportType() {
131
        return exportType;
132
    }
133

    
134
    /**
135
     * @param exportType the exportType to set
136
     */
137
    public void setExportType(ExportType exportType) {
138
        this.exportType = exportType;
139
    }
140

    
141
}
(20-20/63)