Skip to content

Commit 03f1831

Browse files
author
Quim
committed
2 parents d39b8a4 + 8474aa5 commit 03f1831

File tree

19 files changed

+321
-221
lines changed

19 files changed

+321
-221
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@
4141
<artifactId>spring-boot-starter-tomcat</artifactId>
4242
<scope>provided</scope>
4343
</dependency>
44+
<dependency>
45+
<groupId>javax.xml.bind</groupId>
46+
<artifactId>jaxb-api</artifactId>
47+
<version>2.3.1</version>
48+
</dependency>
4449
<!-- <dependency>
4550
<groupId>org.springframework.boot</groupId>
4651
<artifactId>spring-boot-starter-jdbc</artifactId>
@@ -97,6 +102,7 @@
97102
<dependency>
98103
<groupId>com.h2database</groupId>
99104
<artifactId>h2</artifactId>
105+
<scope>runtime</scope>
100106
</dependency>
101107

102108
<!-- Jackson -->

src/main/java/com/essi/dependency/components/Bug.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ public Bug(String id, String summary, String description, List<String> comments)
2828
this.comments = comments;
2929
}
3030

31-
public Bug(List<String> components) {
32-
this.id = components.get(0);
33-
this.summary = components.get(1);
34-
this.description = components.get(2);
35-
}
36-
3731
public String getId() {
3832
return id;
3933
}
@@ -46,26 +40,10 @@ public String getDescription() {
4640
return description;
4741
}
4842

49-
public void setSummary(String summary) {
50-
this.summary = summary;
51-
}
52-
53-
public void setDescription(String description) {
54-
this.description = description;
55-
}
56-
57-
public void setId(String id) {
58-
this.id = id;
59-
}
60-
6143
public List<String> getComments() {
6244
return comments;
6345
}
6446

65-
public void setComments(List<String> comments) {
66-
this.comments = comments;
67-
}
68-
6947
@Override
7048
public String toString() {
7149
return "Bug [id=" + id + ",\n summary=" + summary + ",\n description=" + description

src/main/java/com/essi/dependency/components/Clause.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,6 @@ public Clause(String doc, String vol, String part, String sect, String subsect,
3232
this.id = id;
3333
}
3434

35-
public Clause(List<String> components) {
36-
this.id = Integer.parseInt(components.get(0));
37-
this.clauseString = components.get(1);
38-
this.doc = components.get(2);
39-
this.vol = components.get(3);
40-
this.part = components.get(4);
41-
this.sect = components.get(5);
42-
this.subsect = components.get(6);
43-
this.parag = components.get(7);
44-
this.subparg = components.get(8);
45-
}
46-
4735
@ApiModelProperty(value = "Document")
4836
public String getDoc() {
4937
return doc;

src/main/java/com/essi/dependency/components/DependencyType.java

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,4 @@ public enum DependencyType {
1616
CROSS_REFERENCE, @JsonProperty("external-cross-reference")
1717
EXTERNAL_CROSS_REFERENCE;
1818

19-
public DependencyType find(String elem) {
20-
switch (elem.toUpperCase()) {
21-
case "CONTRIBUTES":
22-
return DependencyType.CONTRIBUTES;
23-
case "DAMAGES":
24-
return DependencyType.DAMAGES;
25-
case "REFINES":
26-
return DependencyType.REFINES;
27-
case "REQUIRES":
28-
return DependencyType.REQUIRES;
29-
case "INCOMPATIBLE":
30-
return DependencyType.INCOMPATIBLE;
31-
case "DECOMPOSITION":
32-
return DependencyType.DECOMPOSITION;
33-
case "SIMILAR":
34-
return DependencyType.SIMILAR;
35-
case "DUPLICATES":
36-
return DependencyType.DUPLICATES;
37-
case "REPLACES":
38-
return DependencyType.REPLACES;
39-
case "CROSS_REFERENCE":
40-
return DependencyType.CROSS_REFERENCE;
41-
case "EXTERNAL_CROSS_REFERENCE":
42-
return DependencyType.EXTERNAL_CROSS_REFERENCE;
43-
default:
44-
//error
45-
break;
46-
}
47-
return null;
48-
}
49-
5019
}

src/main/java/com/essi/dependency/components/ExternalDependency.java

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/main/java/com/essi/dependency/controller/Controller.java

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import javax.servlet.http.HttpServletRequest;
1111

1212
import com.essi.dependency.functionalities.JSONHandler;
13+
import com.essi.dependency.service.StorageException;
1314
import com.essi.dependency.util.Control;
1415
import org.springframework.beans.factory.annotation.Autowired;
1516
import org.springframework.http.HttpStatus;
@@ -111,14 +112,9 @@ public ResponseEntity crossReferenceDetector(
111112
objN = jh.storeDependencies("", dependencies);
112113
node = jh.storeRequirements(objN, clauseList);
113114
node = jh.createProject(node, clauseList);
114-
} catch (FileFormatException e) {
115+
} catch (StorageException | FileFormatException e) {
115116
// show the error with an entity format.
116-
LinkedHashMap<String, String> result = new LinkedHashMap<>();
117-
result.put("status", "500");
118-
result.put("error", "Internal Server Error");
119-
result.put("exception", e.toString());
120-
result.put("message", "The format file must be htm or html.");
121-
return new ResponseEntity<>(result, HttpStatus.INTERNAL_SERVER_ERROR);
117+
return createException(500,"Internal Server Error",e.toString(),"The format file must be htm or html.");
122118
}
123119

124120
// Delete the input data file and folder.
@@ -200,33 +196,13 @@ public ResponseEntity crossReferenceDetector(
200196
objN = jh.storeRequirements(objN, clauseList);
201197
objN = jh.createProject(objN, clauseList);
202198
} catch (FileFormatException e) {
203-
LinkedHashMap<String, String> result = new LinkedHashMap<>();
204-
result.put("status", "500");
205-
result.put("error", "Internal Server Error");
206-
result.put("exception", e.toString());
207-
result.put("message", "The format file must be htm or html.");
208-
return new ResponseEntity<>(result, HttpStatus.INTERNAL_SERVER_ERROR);
199+
return createException(500,"Internal Server Error",e.toString(),"The format file must be htm or html.");
209200
} catch (IndexOutOfBoundsException e) {
210-
LinkedHashMap<String, String> result = new LinkedHashMap<>();
211-
result.put("status", "500");
212-
result.put("error", "Internal Server Error");
213-
result.put("exception", e.toString());
214-
result.put("message", "Index exceeds the bounds.");
215-
return new ResponseEntity<>(result, HttpStatus.INTERNAL_SERVER_ERROR);
201+
return createException(500,"Internal Server Error",e.toString(),"Index exceeds the bounds.");
216202
} catch (NumberFormatException e) {
217-
LinkedHashMap<String, String> result = new LinkedHashMap<>();
218-
result.put("status", "500");
219-
result.put("error", "Internal Server Error");
220-
result.put("exception", e.toString());
221-
result.put("message", "The parameters 'n' and 'm' must be Integers.");
222-
return new ResponseEntity<>(result, HttpStatus.INTERNAL_SERVER_ERROR);
203+
return createException(500,"Internal Server Error",e.toString(),"The parameters 'n' and 'm' must be Integers.");
223204
} catch (IllegalArgumentException e) {
224-
LinkedHashMap<String, String> result = new LinkedHashMap<>();
225-
result.put("status", "500");
226-
result.put("error", "Internal Server Error");
227-
result.put("exception", e.toString());
228-
result.put("message", "The parameter 'n' must be bigger than 0 and lower than 'm' ( 0 < n < m ).");
229-
return new ResponseEntity<>(result, HttpStatus.INTERNAL_SERVER_ERROR);
205+
return createException(500,"Internal Server Error",e.toString(),"The parameter 'n' must be bigger than 0 and lower than 'm' ( 0 < n < m ).");
230206
}
231207
return new ResponseEntity<>(objN, HttpStatus.OK);
232208
}
@@ -278,13 +254,7 @@ public ResponseEntity crossReferenceDetectorJson(
278254
List<List<String>> clauseList = jh.readRequirement(depService.getJson(), projectId);
279255
depService.storeClauseList(clauseList);
280256
} catch (Exception e) {
281-
Control.getInstance().showErrorMessage(e.getMessage());
282-
LinkedHashMap<String, String> result = new LinkedHashMap<>();
283-
result.put("status", "500");
284-
result.put("error", "Internal Server Error");
285-
result.put("exception", e.toString());
286-
result.put("message", "");
287-
return new ResponseEntity<>(result, HttpStatus.INTERNAL_SERVER_ERROR);
257+
return createException(500,"Internal Server Error",e.toString(),"");
288258

289259
}
290260

@@ -354,12 +324,7 @@ public ResponseEntity crossReferenceDetectorJson(
354324
List<List<String>> clauseList = jh.readRequirement(depService.getJson(), projectId);
355325
depService.storeClauseList(clauseList);
356326
} catch (Exception e) {
357-
LinkedHashMap<String, String> result = new LinkedHashMap<>();
358-
result.put("status", "500");
359-
result.put("error", "Internal Server Error");
360-
result.put("exception", e.toString());
361-
result.put("message", "");
362-
return new ResponseEntity<>(result, HttpStatus.INTERNAL_SERVER_ERROR);
327+
return createException(500,"Internal Server Error",e.toString(),"");
363328

364329
}
365330

@@ -376,4 +341,13 @@ public ResponseEntity<?> handleStorageFileNotFound(StorageFileNotFoundException
376341
return ResponseEntity.notFound().build();
377342
}
378343

344+
private ResponseEntity createException(int status, String error, String exception, String message) {
345+
LinkedHashMap<String, String> result = new LinkedHashMap<>();
346+
result.put("status", status+"");
347+
result.put("error", error);
348+
result.put("exception", exception);
349+
result.put("message", message);
350+
return new ResponseEntity<>(result, HttpStatus.valueOf(status));
351+
}
352+
379353
}

src/main/java/com/essi/dependency/functionalities/ClauseExtraction.java

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -266,42 +266,4 @@ private void extractClauses(List<Object> clauseList, String line, String doc, St
266266
}
267267
}
268268
}
269-
270-
/**
271-
* Write the expressions (clauses, bugs) into an external document.
272-
*
273-
* @param filename
274-
* @param printID
275-
* @throws IOException
276-
*/
277-
public void writeClauses(String filename, Boolean printID) throws IOException {
278-
try(BufferedWriter outputWriter = new BufferedWriter(new FileWriter(filename))) {
279-
for (Object c : clauseList) {
280-
if (printID) {
281-
outputWriter.write(((Clause) c).getId() + "- ");
282-
}
283-
outputWriter.write(((Clause) c).printMe());
284-
outputWriter.write("\n");
285-
outputWriter.newLine();
286-
}
287-
outputWriter.flush();
288-
}
289-
}
290-
291-
/**
292-
* Write all list into an external document.
293-
*
294-
* @param filename
295-
* @param list
296-
* @throws IOException
297-
*/
298-
public <T> void writeList(String filename, List<T> list) throws IOException {
299-
try(BufferedWriter outputWriter = new BufferedWriter(new FileWriter(filename))) {
300-
for (T object : list) {
301-
outputWriter.write(object.toString());
302-
outputWriter.newLine();
303-
}
304-
outputWriter.flush();
305-
}
306-
}
307269
}

src/main/java/com/essi/dependency/functionalities/Grammar.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public List<Object> applyGrammar(com.essi.dependency.components.Grammar grammarO
212212
dep = (ArrayList<Object>) task.get(30, TimeUnit.SECONDS);
213213

214214
} catch (Exception e) {
215-
Control.getInstance().showErrorMessage("[EXCEPTION] " + e + ": " + ((Bug) expression).toString());
215+
Control.getInstance().showErrorMessage("[EXCEPTION] " + e.getMessage());
216216
}
217217

218218
executor.shutdown();
@@ -488,7 +488,7 @@ public List<Object> resolvingCrossReference(Clause clause, Matcher matcher, List
488488
} else if (terms[i + 1].matches(markerTerm)) {
489489
tmpNextTerm = terms[i + 2].replaceAll("\\(|\\)", "");
490490
}
491-
if (tmpNextTerm.matches("\\d+(\\.\\d(\\.)?)*")) {
491+
if (tmpNextTerm.matches("\\d+(\\.\\d(\\.)?)*") && currentLoc!=-1) {
492492
String tail = "";
493493
String head = "";
494494
String point = "";

src/main/java/com/essi/dependency/service/DependencyService.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,6 @@ public String getJson() {
5555
return json;
5656
}
5757

58-
public String getFilename() {
59-
return this.filename;
60-
}
61-
62-
public String getFilenamePath() {
63-
return load(this.filename).toString();
64-
}
65-
6658
/**
6759
* Store requirements into the list
6860
* @param clauseList
@@ -95,7 +87,7 @@ public void storeClauseList(List<List<String>> clauseList) {
9587
*
9688
* @param file
9789
*/
98-
public void store(MultipartFile file) {
90+
public void store(MultipartFile file) throws StorageException {
9991
this.filename = StringUtils.cleanPath(file.getOriginalFilename());
10092
try {
10193
if (file.isEmpty()) {

src/main/java/com/essi/dependency/service/FileFormatException.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,4 @@ public FileFormatException() {
66
super();
77
}
88

9-
public FileFormatException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
10-
super(message, cause, enableSuppression, writableStackTrace);
11-
}
12-
13-
public FileFormatException(String message, Throwable cause) {
14-
super(message, cause);
15-
}
16-
17-
public FileFormatException(String message) {
18-
super(message);
19-
}
20-
21-
public FileFormatException(Throwable cause) {
22-
super(cause);
23-
}
24-
259
}

0 commit comments

Comments
 (0)