Skip to content

Commit f56c727

Browse files
author
Quim
committed
Merge branch 'devel'
2 parents 6af6819 + 7358d4c commit f56c727

File tree

12 files changed

+424
-89
lines changed

12 files changed

+424
-89
lines changed

pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@
100100
<artifactId>jackson-core</artifactId>
101101
<version>2.9.6</version>
102102
</dependency>
103+
<dependency>
104+
<groupId>org.springframework.boot</groupId>
105+
<artifactId>spring-boot-starter</artifactId>
106+
</dependency>
107+
<dependency>
108+
<groupId>org.springframework.boot</groupId>
109+
<artifactId>spring-boot-starter-data-jpa</artifactId>
110+
</dependency>
111+
<dependency>
112+
<groupId>org.mariadb.jdbc</groupId>
113+
<artifactId>mariadb-java-client</artifactId>
114+
</dependency>
103115
</dependencies>
104116

105117

src/main/java/com/essi/Dependency/Application.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
import com.essi.Dependency.Service.DependencyService;
1212
import com.essi.Dependency.Service.StorageProperties;
1313

14+
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
15+
1416
@SpringBootApplication
17+
// @PropertySource({"classpath:application.properties"})
18+
@EnableJpaRepositories("com.essi.Dependency.Repository")
1519
@EnableConfigurationProperties(StorageProperties.class)
1620
public class Application {
1721
public static void main(String[] args) {
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.essi.Dependency.Components;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnore;
4+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
5+
6+
import javax.persistence.*;
7+
import java.io.Serializable;
8+
import java.util.Arrays;
9+
import java.util.List;
10+
import java.util.stream.Collectors;
11+
12+
@JsonIgnoreProperties(ignoreUnknown = true)
13+
@Entity
14+
@Table(name = "grammar")
15+
public class Grammar implements Serializable {
16+
17+
@Id
18+
@GeneratedValue(strategy = GenerationType.AUTO)
19+
@JsonIgnore
20+
private Integer id;
21+
@Column(unique=true)
22+
@JsonIgnore
23+
private String company;
24+
private String prefixes;
25+
26+
public Grammar() {
27+
28+
}
29+
30+
public Grammar(String company, List<String> prefixes) {
31+
this.company = company;
32+
this.prefixes = prefixes.stream().collect(Collectors.joining(","));
33+
}
34+
35+
public Integer getId() {
36+
return id;
37+
}
38+
39+
public void setId(Integer id) {
40+
this.id = id;
41+
}
42+
43+
public String getCompany() {
44+
return company;
45+
}
46+
47+
public void setCompany(String company) {
48+
this.company = company;
49+
}
50+
51+
public List<String> getPrefixes() {
52+
return Arrays.asList(prefixes.split(","));
53+
}
54+
55+
public void setPrefixes(List<String> prefixes) {
56+
this.prefixes = prefixes.stream().collect(Collectors.joining(","));
57+
}
58+
}

src/main/java/com/essi/Dependency/Controller/Controller.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,15 @@
99

1010
import javax.servlet.http.HttpServletRequest;
1111

12+
import com.essi.Dependency.Components.Grammar;
13+
import com.essi.Dependency.Service.GrammarService;
1214
import org.springframework.beans.factory.annotation.Autowired;
15+
import org.springframework.http.HttpEntity;
1316
import org.springframework.http.HttpStatus;
1417
import org.springframework.http.MediaType;
1518
import org.springframework.http.ResponseEntity;
1619
//import org.springframework.jdbc.core.JdbcTemplate;
17-
import org.springframework.web.bind.annotation.ExceptionHandler;
18-
import org.springframework.web.bind.annotation.PathVariable;
19-
import org.springframework.web.bind.annotation.PostMapping;
20-
import org.springframework.web.bind.annotation.RequestBody;
21-
import org.springframework.web.bind.annotation.RequestMapping;
22-
import org.springframework.web.bind.annotation.RequestMethod;
23-
import org.springframework.web.bind.annotation.RequestParam;
24-
import org.springframework.web.bind.annotation.RestController;
20+
import org.springframework.web.bind.annotation.*;
2521
import org.springframework.web.multipart.MultipartFile;
2622
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
2723

@@ -46,6 +42,7 @@ public class Controller {
4642
private static final String TABLE = "requirement";
4743
private static final String COLS = "id.text.document.volume.part.sect.subsect.parag.subparag.";
4844
private final DependencyService depService;
45+
4946
// @Autowired
5047
// private JdbcTemplate jdbcTemplate;
5148

@@ -99,6 +96,7 @@ public Controller(DependencyService depService) {
9996
public ResponseEntity<?> crossReferenceDetector(
10097
@ApiParam(value = "The file to upload (HTML format)",
10198
required = true) @RequestParam("file") MultipartFile file,
99+
@ApiParam(value = "Company") @RequestParam(required = false) String company,
102100
RedirectAttributes redirectAttributes) throws IOException, InterruptedException {
103101

104102
long startTime = System.currentTimeMillis();
@@ -121,7 +119,7 @@ public ResponseEntity<?> crossReferenceDetector(
121119

122120
// extract clauses and locations from the input file (Clause.class)
123121
ArrayList<Object> clauseList = depService.extractClauseList();
124-
dependencies = depService.getDependencies();
122+
dependencies = depService.getDependencies(company);
125123

126124
// Create the new JSON to be returned (Project, requirements, dependencies).
127125
JSONHandler jh = new JSONHandler();
@@ -293,6 +291,7 @@ public ResponseEntity<?> crossReferenceDetector(
293291
public ResponseEntity<?> crossReferenceDetector(
294292
@ApiParam(value = "The file to upload (HTML fromat)",
295293
required = true) @RequestParam("file") MultipartFile file,
294+
@ApiParam(value = "Company") @RequestParam(required = false) String company,
296295
RedirectAttributes redirectAttributes,
297296
@ApiParam(value = "First index of the clause list that will be analysed (included)",
298297
required = true) @PathVariable("n") String n,
@@ -323,7 +322,7 @@ public ResponseEntity<?> crossReferenceDetector(
323322

324323
// extract clauses and locations (Clause.class)
325324
ArrayList<Object> clauseList = depService.extractClauseList();
326-
dependencies = depService.getNMDependencies(n, m);
325+
dependencies = depService.getNMDependencies(company, n, m);
327326
depService.deleteAll();
328327

329328
// Create the new Json (project, requirements, dependencies)
@@ -398,7 +397,8 @@ public ResponseEntity<?> crossReferenceDetector(
398397
message = "Internal Server Error. For more information see ‘message’ in the Response Body.") })
399398
public ResponseEntity<?> crossReferenceDetectorJson(
400399
@ApiParam(value = "The json object to upload.", required = true, example = "") @RequestBody String json,
401-
RedirectAttributes redirectAttributes,
400+
@ApiParam(value = "Company") @RequestParam(required = false) String company,
401+
RedirectAttributes redirectAttributes,
402402
@ApiParam(value = "Id of the project where the requirements to analize are.",
403403
required = true) @PathVariable("projectId") String projectId,
404404
HttpServletRequest request)
@@ -428,7 +428,7 @@ public ResponseEntity<?> crossReferenceDetectorJson(
428428
}
429429

430430
// Exrtact the dependencies from the bug requirements
431-
ArrayList<Object> dependencies = depService.getDependencies();
431+
ArrayList<Object> dependencies = depService.getDependencies(company);
432432

433433
// Save the detected cross-reference dependencies within the intput JSON
434434
ObjectNode objN = depService.storeDependenciesJson(dependencies);
@@ -473,7 +473,8 @@ public ResponseEntity<?> crossReferenceDetectorJson(
473473
message = "Internal Server Error. For more information see ‘message’ in the Response Body.") })
474474
public ResponseEntity<?> crossReferenceDetectorJson(
475475
@ApiParam(value = "The json object to upload.", required = true) @RequestBody String json,
476-
RedirectAttributes redirectAttributes,
476+
@ApiParam(value = "Company") @RequestParam(required = false) String company,
477+
RedirectAttributes redirectAttributes,
477478
@ApiParam(value = "Id of the project where the requirements to analize are.",
478479
required = true) @PathVariable("projectId") String projectId,
479480
@ApiParam(value = "First index of the requirement list that will be analysed (included)",
@@ -511,7 +512,7 @@ public ResponseEntity<?> crossReferenceDetectorJson(
511512
}
512513

513514
// Get the dependencies from the bug requirements
514-
ArrayList<Object> dependencies = depService.getNMDependencies(n, m);
515+
ArrayList<Object> dependencies = depService.getNMDependencies(company, n, m);
515516

516517
// Save the dependencies into the input JSON
517518
ObjectNode objN = depService.storeDependenciesJson(dependencies);
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
package com.essi.Dependency.Controller;
2+
3+
import com.essi.Dependency.Components.Grammar;
4+
import com.essi.Dependency.Service.GrammarService;
5+
import io.swagger.annotations.*;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.http.HttpEntity;
8+
import org.springframework.http.HttpStatus;
9+
import org.springframework.http.MediaType;
10+
import org.springframework.http.ResponseEntity;
11+
import org.springframework.web.bind.annotation.*;
12+
13+
@RestController
14+
@RequestMapping("/upc/cross-reference-detection")
15+
@Api(value = "GrammarControllerAPI", produces = MediaType.APPLICATION_JSON_VALUE)
16+
public class GrammarController {
17+
18+
@Autowired
19+
private GrammarService grammarService;
20+
21+
@PostMapping("/grammar")
22+
@ApiOperation(value = "Store grammar",
23+
notes = "Given a company, stores its list of prefixes to use as grammar rules to extract requirement cross-references",
24+
response = String.class)
25+
@ApiResponses(value = { @ApiResponse(code = 0, message = "Non content: There is no content to submit."),
26+
@ApiResponse(code = 200, message = "OK: The request has succeeded."),
27+
@ApiResponse(code = 201,
28+
message = "Created: The request has been fulfilled and has resulted in one or more new resources being created.",
29+
response = String.class),
30+
@ApiResponse(code = 401,
31+
message = "Unauthorized: The request has not been applied because it lacks valid authentication credentials for the target resource."),
32+
@ApiResponse(code = 403,
33+
message = "Forbidden: The server understood the request but refuses to authorize it."),
34+
@ApiResponse(code = 404,
35+
message = "Not Found: The server could not find what was requested by the client."),
36+
@ApiResponse(code = 500,
37+
message = "Internal Server Error. For more information see ‘message’ in the Response Body.") })
38+
public ResponseEntity<?> uploadGrammar(
39+
@ApiParam(value = "The grammar",
40+
required = true) @RequestBody Grammar grammar,
41+
@ApiParam(value = "Company", required = true) @RequestParam("company") String company) {
42+
try {
43+
grammarService.uploadGrammar(company, grammar);
44+
return new ResponseEntity<>(HttpStatus.OK);
45+
} catch (Exception e) {
46+
e.printStackTrace();
47+
return new ResponseEntity<>(new HttpEntity<>(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
48+
}
49+
}
50+
51+
@PutMapping("/grammar")
52+
@ApiOperation(value = "Update grammar",
53+
notes = "Given a company, updates its existing list of prefixes to use as grammar rules to extract requirement cross-references",
54+
response = String.class)
55+
@ApiResponses(value = { @ApiResponse(code = 0, message = "Non content: There is no content to submit."),
56+
@ApiResponse(code = 200, message = "OK: The request has succeeded."),
57+
@ApiResponse(code = 201,
58+
message = "Created: The request has been fulfilled and has resulted in one or more new resources being created.",
59+
response = String.class),
60+
@ApiResponse(code = 401,
61+
message = "Unauthorized: The request has not been applied because it lacks valid authentication credentials for the target resource."),
62+
@ApiResponse(code = 403,
63+
message = "Forbidden: The server understood the request but refuses to authorize it."),
64+
@ApiResponse(code = 404,
65+
message = "Not Found: The server could not find what was requested by the client."),
66+
@ApiResponse(code = 500,
67+
message = "Internal Server Error. For more information see ‘message’ in the Response Body.") })
68+
public ResponseEntity<?> updateGrammar(
69+
@ApiParam(value = "The grammar",
70+
required = true) @RequestBody Grammar grammar,
71+
@ApiParam(value = "Company", required = true) @RequestParam("company") String company) {
72+
try {
73+
grammarService.updateGrammar(company, grammar);
74+
return new ResponseEntity<>(HttpStatus.OK);
75+
} catch (Exception e) {
76+
e.printStackTrace();
77+
return new ResponseEntity<>(new HttpEntity<>(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
78+
}
79+
}
80+
81+
@DeleteMapping("/grammar")
82+
@ApiOperation(value = "Delete grammar",
83+
notes = "Deletes grammar rules of a given company",
84+
response = String.class)
85+
@ApiResponses(value = { @ApiResponse(code = 0, message = "Non content: There is no content to submit."),
86+
@ApiResponse(code = 200, message = "OK: The request has succeeded."),
87+
@ApiResponse(code = 201,
88+
message = "Created: The request has been fulfilled and has resulted in one or more new resources being created.",
89+
response = String.class),
90+
@ApiResponse(code = 401,
91+
message = "Unauthorized: The request has not been applied because it lacks valid authentication credentials for the target resource."),
92+
@ApiResponse(code = 403,
93+
message = "Forbidden: The server understood the request but refuses to authorize it."),
94+
@ApiResponse(code = 404,
95+
message = "Not Found: The server could not find what was requested by the client."),
96+
@ApiResponse(code = 500,
97+
message = "Internal Server Error. For more information see ‘message’ in the Response Body.") })
98+
public ResponseEntity<?> deleteGrammar(
99+
@ApiParam(value = "Company", required = true) @RequestParam String company) {
100+
try {
101+
grammarService.deleteGrammar(company);
102+
return new ResponseEntity<>(HttpStatus.OK);
103+
} catch (Exception e) {
104+
e.printStackTrace();
105+
return new ResponseEntity<>(new HttpEntity<>(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
106+
}
107+
}
108+
109+
@GetMapping("/grammar")
110+
@ApiOperation(value = "Get grammar",
111+
notes = "Gets the list of prefixes of a given company",
112+
response = String.class)
113+
@ApiResponses(value = { @ApiResponse(code = 0, message = "Non content: There is no content to submit."),
114+
@ApiResponse(code = 200, message = "OK: The request has succeeded."),
115+
@ApiResponse(code = 201,
116+
message = "Created: The request has been fulfilled and has resulted in one or more new resources being created.",
117+
response = String.class),
118+
@ApiResponse(code = 401,
119+
message = "Unauthorized: The request has not been applied because it lacks valid authentication credentials for the target resource."),
120+
@ApiResponse(code = 403,
121+
message = "Forbidden: The server understood the request but refuses to authorize it."),
122+
@ApiResponse(code = 404,
123+
message = "Not Found: The server could not find what was requested by the client."),
124+
@ApiResponse(code = 500,
125+
message = "Internal Server Error. For more information see ‘message’ in the Response Body.") })
126+
public Object getGrammar(
127+
@ApiParam(value = "Company", required = true) @RequestParam String company) {
128+
try {
129+
Grammar grammar = grammarService.getGrammar(company);
130+
return grammar;
131+
} catch (Exception e) {
132+
e.printStackTrace();
133+
return new ResponseEntity<>(new HttpEntity<>(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
134+
}
135+
}
136+
137+
}

src/main/java/com/essi/Dependency/Functionalities/CallableTask.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ public class CallableTask implements Callable<ArrayList<Object>> {
2626
* @param pattern
2727
* @param dep
2828
*/
29-
CallableTask(Object expression, ArrayList<Object> expressionList, Pattern pattern, ArrayList<Object> dep) {
29+
CallableTask(com.essi.Dependency.Components.Grammar grammarObj, Object expression, ArrayList<Object> expressionList, Pattern pattern, ArrayList<Object> dep) {
3030
this.expression = expression;
3131
this.expressionList = expressionList;
3232
this.pattern = pattern;
3333
this.dep = dep;
34-
grammar = new Grammar();
34+
grammar = new Grammar(grammarObj);
3535
}
3636

3737
/**

0 commit comments

Comments
 (0)