Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Quim committed Nov 18, 2019
2 parents d39b8a4 + 8474aa5 commit 03f1831
Show file tree
Hide file tree
Showing 19 changed files with 321 additions and 221 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
Expand Down Expand Up @@ -97,6 +102,7 @@
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>

<!-- Jackson -->
Expand Down
22 changes: 0 additions & 22 deletions src/main/java/com/essi/dependency/components/Bug.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ public Bug(String id, String summary, String description, List<String> comments)
this.comments = comments;
}

public Bug(List<String> components) {
this.id = components.get(0);
this.summary = components.get(1);
this.description = components.get(2);
}

public String getId() {
return id;
}
Expand All @@ -46,26 +40,10 @@ public String getDescription() {
return description;
}

public void setSummary(String summary) {
this.summary = summary;
}

public void setDescription(String description) {
this.description = description;
}

public void setId(String id) {
this.id = id;
}

public List<String> getComments() {
return comments;
}

public void setComments(List<String> comments) {
this.comments = comments;
}

@Override
public String toString() {
return "Bug [id=" + id + ",\n summary=" + summary + ",\n description=" + description
Expand Down
12 changes: 0 additions & 12 deletions src/main/java/com/essi/dependency/components/Clause.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,6 @@ public Clause(String doc, String vol, String part, String sect, String subsect,
this.id = id;
}

public Clause(List<String> components) {
this.id = Integer.parseInt(components.get(0));
this.clauseString = components.get(1);
this.doc = components.get(2);
this.vol = components.get(3);
this.part = components.get(4);
this.sect = components.get(5);
this.subsect = components.get(6);
this.parag = components.get(7);
this.subparg = components.get(8);
}

@ApiModelProperty(value = "Document")
public String getDoc() {
return doc;
Expand Down
31 changes: 0 additions & 31 deletions src/main/java/com/essi/dependency/components/DependencyType.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,4 @@ public enum DependencyType {
CROSS_REFERENCE, @JsonProperty("external-cross-reference")
EXTERNAL_CROSS_REFERENCE;

public DependencyType find(String elem) {
switch (elem.toUpperCase()) {
case "CONTRIBUTES":
return DependencyType.CONTRIBUTES;
case "DAMAGES":
return DependencyType.DAMAGES;
case "REFINES":
return DependencyType.REFINES;
case "REQUIRES":
return DependencyType.REQUIRES;
case "INCOMPATIBLE":
return DependencyType.INCOMPATIBLE;
case "DECOMPOSITION":
return DependencyType.DECOMPOSITION;
case "SIMILAR":
return DependencyType.SIMILAR;
case "DUPLICATES":
return DependencyType.DUPLICATES;
case "REPLACES":
return DependencyType.REPLACES;
case "CROSS_REFERENCE":
return DependencyType.CROSS_REFERENCE;
case "EXTERNAL_CROSS_REFERENCE":
return DependencyType.EXTERNAL_CROSS_REFERENCE;
default:
//error
break;
}
return null;
}

}

This file was deleted.

62 changes: 18 additions & 44 deletions src/main/java/com/essi/dependency/controller/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import javax.servlet.http.HttpServletRequest;

import com.essi.dependency.functionalities.JSONHandler;
import com.essi.dependency.service.StorageException;
import com.essi.dependency.util.Control;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -111,14 +112,9 @@ public ResponseEntity crossReferenceDetector(
objN = jh.storeDependencies("", dependencies);
node = jh.storeRequirements(objN, clauseList);
node = jh.createProject(node, clauseList);
} catch (FileFormatException e) {
} catch (StorageException | FileFormatException e) {
// show the error with an entity format.
LinkedHashMap<String, String> result = new LinkedHashMap<>();
result.put("status", "500");
result.put("error", "Internal Server Error");
result.put("exception", e.toString());
result.put("message", "The format file must be htm or html.");
return new ResponseEntity<>(result, HttpStatus.INTERNAL_SERVER_ERROR);
return createException(500,"Internal Server Error",e.toString(),"The format file must be htm or html.");
}

// Delete the input data file and folder.
Expand Down Expand Up @@ -200,33 +196,13 @@ public ResponseEntity crossReferenceDetector(
objN = jh.storeRequirements(objN, clauseList);
objN = jh.createProject(objN, clauseList);
} catch (FileFormatException e) {
LinkedHashMap<String, String> result = new LinkedHashMap<>();
result.put("status", "500");
result.put("error", "Internal Server Error");
result.put("exception", e.toString());
result.put("message", "The format file must be htm or html.");
return new ResponseEntity<>(result, HttpStatus.INTERNAL_SERVER_ERROR);
return createException(500,"Internal Server Error",e.toString(),"The format file must be htm or html.");
} catch (IndexOutOfBoundsException e) {
LinkedHashMap<String, String> result = new LinkedHashMap<>();
result.put("status", "500");
result.put("error", "Internal Server Error");
result.put("exception", e.toString());
result.put("message", "Index exceeds the bounds.");
return new ResponseEntity<>(result, HttpStatus.INTERNAL_SERVER_ERROR);
return createException(500,"Internal Server Error",e.toString(),"Index exceeds the bounds.");
} catch (NumberFormatException e) {
LinkedHashMap<String, String> result = new LinkedHashMap<>();
result.put("status", "500");
result.put("error", "Internal Server Error");
result.put("exception", e.toString());
result.put("message", "The parameters 'n' and 'm' must be Integers.");
return new ResponseEntity<>(result, HttpStatus.INTERNAL_SERVER_ERROR);
return createException(500,"Internal Server Error",e.toString(),"The parameters 'n' and 'm' must be Integers.");
} catch (IllegalArgumentException e) {
LinkedHashMap<String, String> result = new LinkedHashMap<>();
result.put("status", "500");
result.put("error", "Internal Server Error");
result.put("exception", e.toString());
result.put("message", "The parameter 'n' must be bigger than 0 and lower than 'm' ( 0 < n < m ).");
return new ResponseEntity<>(result, HttpStatus.INTERNAL_SERVER_ERROR);
return createException(500,"Internal Server Error",e.toString(),"The parameter 'n' must be bigger than 0 and lower than 'm' ( 0 < n < m ).");
}
return new ResponseEntity<>(objN, HttpStatus.OK);
}
Expand Down Expand Up @@ -278,13 +254,7 @@ public ResponseEntity crossReferenceDetectorJson(
List<List<String>> clauseList = jh.readRequirement(depService.getJson(), projectId);
depService.storeClauseList(clauseList);
} catch (Exception e) {
Control.getInstance().showErrorMessage(e.getMessage());
LinkedHashMap<String, String> result = new LinkedHashMap<>();
result.put("status", "500");
result.put("error", "Internal Server Error");
result.put("exception", e.toString());
result.put("message", "");
return new ResponseEntity<>(result, HttpStatus.INTERNAL_SERVER_ERROR);
return createException(500,"Internal Server Error",e.toString(),"");

}

Expand Down Expand Up @@ -354,12 +324,7 @@ public ResponseEntity crossReferenceDetectorJson(
List<List<String>> clauseList = jh.readRequirement(depService.getJson(), projectId);
depService.storeClauseList(clauseList);
} catch (Exception e) {
LinkedHashMap<String, String> result = new LinkedHashMap<>();
result.put("status", "500");
result.put("error", "Internal Server Error");
result.put("exception", e.toString());
result.put("message", "");
return new ResponseEntity<>(result, HttpStatus.INTERNAL_SERVER_ERROR);
return createException(500,"Internal Server Error",e.toString(),"");

}

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

private ResponseEntity createException(int status, String error, String exception, String message) {
LinkedHashMap<String, String> result = new LinkedHashMap<>();
result.put("status", status+"");
result.put("error", error);
result.put("exception", exception);
result.put("message", message);
return new ResponseEntity<>(result, HttpStatus.valueOf(status));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -266,42 +266,4 @@ private void extractClauses(List<Object> clauseList, String line, String doc, St
}
}
}

/**
* Write the expressions (clauses, bugs) into an external document.
*
* @param filename
* @param printID
* @throws IOException
*/
public void writeClauses(String filename, Boolean printID) throws IOException {
try(BufferedWriter outputWriter = new BufferedWriter(new FileWriter(filename))) {
for (Object c : clauseList) {
if (printID) {
outputWriter.write(((Clause) c).getId() + "- ");
}
outputWriter.write(((Clause) c).printMe());
outputWriter.write("\n");
outputWriter.newLine();
}
outputWriter.flush();
}
}

/**
* Write all list into an external document.
*
* @param filename
* @param list
* @throws IOException
*/
public <T> void writeList(String filename, List<T> list) throws IOException {
try(BufferedWriter outputWriter = new BufferedWriter(new FileWriter(filename))) {
for (T object : list) {
outputWriter.write(object.toString());
outputWriter.newLine();
}
outputWriter.flush();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public List<Object> applyGrammar(com.essi.dependency.components.Grammar grammarO
dep = (ArrayList<Object>) task.get(30, TimeUnit.SECONDS);

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

executor.shutdown();
Expand Down Expand Up @@ -488,7 +488,7 @@ public List<Object> resolvingCrossReference(Clause clause, Matcher matcher, List
} else if (terms[i + 1].matches(markerTerm)) {
tmpNextTerm = terms[i + 2].replaceAll("\\(|\\)", "");
}
if (tmpNextTerm.matches("\\d+(\\.\\d(\\.)?)*")) {
if (tmpNextTerm.matches("\\d+(\\.\\d(\\.)?)*") && currentLoc!=-1) {
String tail = "";
String head = "";
String point = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,6 @@ public String getJson() {
return json;
}

public String getFilename() {
return this.filename;
}

public String getFilenamePath() {
return load(this.filename).toString();
}

/**
* Store requirements into the list
* @param clauseList
Expand Down Expand Up @@ -95,7 +87,7 @@ public void storeClauseList(List<List<String>> clauseList) {
*
* @param file
*/
public void store(MultipartFile file) {
public void store(MultipartFile file) throws StorageException {
this.filename = StringUtils.cleanPath(file.getOriginalFilename());
try {
if (file.isEmpty()) {
Expand Down
16 changes: 0 additions & 16 deletions src/main/java/com/essi/dependency/service/FileFormatException.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,4 @@ public FileFormatException() {
super();
}

public FileFormatException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}

public FileFormatException(String message, Throwable cause) {
super(message, cause);
}

public FileFormatException(String message) {
super(message);
}

public FileFormatException(Throwable cause) {
super(cause);
}

}
Loading

0 comments on commit 03f1831

Please sign in to comment.