Project

General

Profile

Revision 17d2281a

ID17d2281ae2b6ca2f5735d475120932da8b689e72
Parent 3fcbef80
Child 11b2f52a

Added by Katja Luther over 3 years ago

ref #6636: adapt RIS Import for use in Editor

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/IoResultBase.java
8 8
*/
9 9
package eu.etaxonomy.cdm.io.common;
10 10

  
11
import java.io.Serializable;
11 12
import java.util.ArrayList;
12 13
import java.util.List;
13 14

  
......
24 25
    private List<IoInfo> warnings = new ArrayList<>();
25 26
    private List<IoInfo> exceptions = new ArrayList<>();
26 27

  
27
    public class IoInfo{
28
    public class IoInfo implements Serializable{
28 29
        String message;
29 30
        Exception exception;
30 31
        String location;
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/reference/ris/in/RisReferenceImport.java
8 8
*/
9 9
package eu.etaxonomy.cdm.io.reference.ris.in;
10 10

  
11
import java.io.ByteArrayInputStream;
11 12
import java.io.InputStreamReader;
12 13
import java.net.URI;
13 14
import java.util.ArrayList;
......
56 57
        RisReferenceImportConfigurator config = state.getConfig();
57 58
        try {
58 59
//            new FileReader(file)
59
            InputStreamReader inputReader = config.getSource();
60
            RisRecordReader risReader = new RisRecordReader(state, inputReader);
60
            byte[] data = config.getStream();
61

  
62
            ByteArrayInputStream stream = new ByteArrayInputStream(data);
63
            InputStreamReader reader = new InputStreamReader(stream);
64
            RisRecordReader risReader = new RisRecordReader(state, reader);
61 65

  
62 66
            Set<Reference> referencesToSave = new HashSet<>();
63 67

  
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/reference/ris/in/RisReferenceImportConfigurator.java
15 15
import java.net.URI;
16 16
import java.net.URL;
17 17

  
18
import org.apache.commons.io.IOUtils;
19

  
18 20
import eu.etaxonomy.cdm.database.ICdmDataSource;
19
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
20
import eu.etaxonomy.cdm.io.common.ImportConfiguratorBase;
21 21
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
22
import eu.etaxonomy.cdm.io.excel.common.ExcelImportConfiguratorBase;
22 23
import eu.etaxonomy.cdm.model.reference.Reference;
23 24
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
24 25

  
......
28 29
 *
29 30
 */
30 31
public class RisReferenceImportConfigurator
31
        extends ImportConfiguratorBase<RisReferenceImportState, InputStreamReader>{
32
        extends ExcelImportConfiguratorBase{
32 33

  
33 34
    private static final long serialVersionUID = -5982826645441621962L;
34 35
    private static IInputTransformer defaultTransformer = null;
......
40 41
     * @throws IOException
41 42
     * @throws MalformedURLException
42 43
     */
43
    public static IImportConfigurator NewInstance(URI uri, ICdmDataSource cdm) throws MalformedURLException, IOException {
44
        return NewInstance(uri.toURL(), cdm);
44
    public static RisReferenceImportConfigurator NewInstance(URI uri, ICdmDataSource cdm) throws MalformedURLException, IOException {
45
        RisReferenceImportConfigurator result = new RisReferenceImportConfigurator(uri, cdm);
46
        return result;
45 47
    }
46 48

  
47 49
    /**
48
     * @param url
50
     * @param uri
49 51
     * @param object
50 52
     * @return
51 53
     * @throws IOException
54
     * @throws MalformedURLException
52 55
     */
53
    public static IImportConfigurator NewInstance(URL url, ICdmDataSource cdm) throws IOException {
56

  
57
    public static RisReferenceImportConfigurator NewInstance(URL url, ICdmDataSource cdm) throws IOException {
54 58
        InputStream stream = url.openStream();
55 59
        InputStreamReader reader = new InputStreamReader(stream, "UTF8");
56
        RisReferenceImportConfigurator result = new RisReferenceImportConfigurator(reader, cdm);
60

  
61
        RisReferenceImportConfigurator result = new RisReferenceImportConfigurator();
62
        result.setStream(IOUtils.toByteArray(stream));
57 63
        return result;
58 64
    }
59 65

  
66
    public static RisReferenceImportConfigurator NewInstance()  {
67
        RisReferenceImportConfigurator result = new RisReferenceImportConfigurator(null, null);
68

  
69
        return result;
70
    }
71

  
72

  
73

  
60 74
    /**
61 75
     * @param transformer
62 76
     */
63 77
    protected RisReferenceImportConfigurator() {
64
        super(defaultTransformer);
78
        super(null,null);
65 79
    }
66 80

  
67
    protected RisReferenceImportConfigurator(InputStreamReader source, ICdmDataSource cdm) {
68
        super(defaultTransformer);
69
        this.setSource(source);
70
        this.setDestination(cdm);
81
    protected RisReferenceImportConfigurator(URI uri, ICdmDataSource cdm) {
82
        super(uri, cdm, null);
71 83
    }
72 84

  
73 85

  
......
107 119
        return sourceReference;
108 120
    }
109 121

  
122
    @Override
123
    public boolean isValid(){
124
        return true;
125
    }
126

  
110 127

  
111 128
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/service/IIOService.java
20 20
import eu.etaxonomy.cdm.io.common.SetSecundumForSubtreeConfigurator;
21 21
import eu.etaxonomy.cdm.io.common.SortIndexUpdaterConfigurator;
22 22
import eu.etaxonomy.cdm.io.distribution.excelupdate.ExcelDistributionUpdateConfigurator;
23
import eu.etaxonomy.cdm.io.reference.ris.in.RisReferenceImportConfigurator;
23 24
import eu.etaxonomy.cdm.io.specimen.SpecimenImportConfiguratorBase;
24 25
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
25 26

  
......
118 119
     */
119 120
    UUID monitExportData(IExportConfigurator configurator);
120 121

  
122

  
123
    /**
124
     * @param configurator
125
     * @return
126
     */
127
    ImportResult importRISData(RisReferenceImportConfigurator configurator);
128

  
121 129
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/service/IOServiceImpl.java
38 38
import eu.etaxonomy.cdm.io.common.SetSecundumForSubtreeConfigurator;
39 39
import eu.etaxonomy.cdm.io.common.SortIndexUpdaterConfigurator;
40 40
import eu.etaxonomy.cdm.io.distribution.excelupdate.ExcelDistributionUpdateConfigurator;
41
import eu.etaxonomy.cdm.io.excel.taxa.NormalExplicitImportConfigurator;
41
import eu.etaxonomy.cdm.io.excel.common.ExcelImportConfiguratorBase;
42
import eu.etaxonomy.cdm.io.reference.ris.in.RisReferenceImportConfigurator;
42 43
import eu.etaxonomy.cdm.io.specimen.SpecimenImportConfiguratorBase;
43 44
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
44 45

  
......
191 192
        ImportConfiguratorBase config = (ImportConfiguratorBase)configurator;
192 193
        ImportResult result;
193 194
        try {
194
            if (config instanceof NormalExplicitImportConfigurator){
195
                NormalExplicitImportConfigurator excelConfig = (NormalExplicitImportConfigurator)config;
195
            if (config instanceof ExcelImportConfiguratorBase){
196
                ExcelImportConfiguratorBase excelConfig = (ExcelImportConfiguratorBase)config;
196 197
                //excelConfig.setStream(importData);
197 198
            }else{
198 199
                config.setSource(new ByteArrayInputStream(importData));
......
256 257
        return result;
257 258
    }
258 259

  
260
    /**
261
     * {@inheritDoc}
262
     */
263
    @Override
264
    public ImportResult importRISData(RisReferenceImportConfigurator configurator) {
265
        ImportResult result = new ImportResult();
266
        result = cdmImport.invoke(configurator);
267
        return result;
268
    }
269

  
259 270

  
260 271

  
261 272

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)