Project

General

Profile

Revision 9232c7e7

ID9232c7e7d78463b2a3e544ce7a878a71c5b82906
Parent b52b1b9d
Child 98a11dec

Added by Andreas Müller over 3 years ago

ref #6636: try to improve debugging for RIS import

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/IoResultBase.java
61 61
    public void addError(String message, int location) {
62 62
        errors.add(new IoInfo(message, null, String.valueOf(location)));
63 63
    }
64
    public void addError(String message, String location) {
65
        errors.add(new IoInfo(message, null, location));
66
    }
64 67

  
65 68
    public List<IoInfo> getWarnings() {return warnings;}
66 69
    public void setWarnings(List<IoInfo> warnings) {this.warnings = warnings;}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/reference/ris/in/RisRecordReader.java
58 58
    public Map<RisReferenceTag, List<RisValue>> readRecord(){
59 59
        try {
60 60
            Map<RisReferenceTag, List<RisValue>> result = new HashMap<>();
61
            String line;
61
            String lineOrig;
62 62
            int count = 0;
63 63
            RisReferenceTag lastType = null;
64
            while ((line = lineReader.readLine()) != null) {
64
            boolean startedWithTY = false;
65
            while ((lineOrig = lineReader.readLine()) != null) {
66
                String line = lineOrig;
65 67
                lineNo++;
68
                String lineNoStr = "line " + lineNo;
66 69
                if (isBlank(line)){
67 70
                   continue;
68 71
               }
......
77 80
                       type = RisReferenceTag.TY;
78 81
                       addTaggedValue(type, result, line, lineNo);
79 82
                       count++;
80
                   }else if (isErLine(line)){
81
                       addTaggedValue(RisReferenceTag.ER, result, line, lineNo);
82
                       return result;
83
                       startedWithTY = true;
83 84
                   }else{
84
                       //TODO
85
                       try {
86
                           type = RisReferenceTag.valueOf(line.substring(0, 2));
87
                       } catch (Exception e) {
88
                            //type stays null
85
                       if (!startedWithTY){
86
                           continue;
89 87
                       }
90
                       if (type == null){
91
                           //TODO
92
                           //Sollte aber als als extension trotzdem übergeben werden
93
                           String message = "Unknown reference type %s . Reference attribute could not be added";
94
                           state.getResult().addWarning(message, lineNo);
88
                       if (isErLine(line)){
89
                           addTaggedValue(RisReferenceTag.ER, result, line, lineNo);
90
                           startedWithTY = false;
91
                           return result;
95 92
                       }else{
96
                           addTaggedValue(type, result, line, lineNo);
93
                           //TODO
94
                           try {
95
                               type = RisReferenceTag.valueOf(line.substring(0, 2));
96
                           } catch (Exception e) {
97
                                //type stays null
98
                           }
99
                           if (type == null){
100
                               //TODO
101
                               //Sollte aber als als extension trotzdem übergeben werden
102
                               String message = "Unknown reference type %s . Reference attribute could not be added. Line was: " + lineOrig ;
103
                               state.getResult().addWarning(message, lineNo);
104
                           }else{
105
                               addTaggedValue(type, result, line, lineNo);
106
                           }
107
                           count++;
97 108
                       }
98
                       count++;
99 109
                   }
100 110
                   if (type != null){
101 111
                       lastType = type;
102 112
                   }
103 113
               }else{
104
                   if (result.size() > 0){
114
                   if (startedWithTY){
105 115
                       //add to prior
106 116
                       List<RisValue> priorList = result.get(lastType);
107 117
                       RisValue priorValue = priorList.get(priorList.size()-1);
108 118
                       priorValue.value = priorValue + NL + line;
109 119
                   }else{
110
                       String message = "RIS record does not start with TY. Can't create record";
111
                       state.getResult().addError(message, lineNo);
120
                       String message = "RIS record does not start with TY. Can't create record. ";
121
                       state.getResult().addError(message, lineNoStr);
122
                       return null;
112 123
                   }
113 124

  
114 125
               }

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)