Skip to content

Commit 254878b

Browse files
committed
cleaning code
1 parent fcaa12f commit 254878b

File tree

16 files changed

+93
-31
lines changed

16 files changed

+93
-31
lines changed

jsondiscoverer.examples/src/jsondiscoverer/zoo/test/ExampleZooDiscoverer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
package jsondiscoverer.zoo.test;
1313

1414
import java.io.File;
15+
import java.io.FileNotFoundException;
1516

1617
import jsondiscoverer.zoo.ModelDrawer;
1718
import jsondiscoverer.zoo.ZooDiscoverer;
@@ -28,11 +29,11 @@ public class ExampleZooDiscoverer {
2829
private static final String DOT_EXE = "C:/Program Files (x86)/Graphviz 2.28/bin/dot.exe"; // Path to DOT executable
2930
private static final String WORKING_DIR = "./exampleData/workingDir";
3031

31-
public static void main(String[] args) {
32+
public static void main(String[] args) throws FileNotFoundException {
3233
ExampleZooDiscoverer.exampleDiscover();
3334
}
3435

35-
public static void exampleDiscover() {
36+
public static void exampleDiscover() throws FileNotFoundException {
3637
ZooDiscoverer zooDiscoverer = new ZooDiscoverer(new File("./exampleData/zooDiscoverer"));
3738
zooDiscoverer.discover(true);
3839

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1+
# The URL where the web application will be deployed.
2+
# Used for CORS, i.e., only requests from this URL will be accepted
13
serverURL=http://localhost:8080
4+
# A temp folder where all the pictures will be generated
25
workingDir=C:/Users/jcanovasi/git/jsonDiscoverer/jsondiscoverer.web/WebContent/workingDir
6+
# Temp files generated by the injector will be located in this folder (sub-folder of workingDir folder)
37
IdInjector=injector
4-
IdDiscoverer=discoverer
5-
IdMultiDiscoverer=multidiscoverer
8+
# Temp files generated by the simple discoverer will be located in this folder (sub-folder of workingDir folder)
9+
SubfolderSimpleDiscoverer=simpleDiscoverer
10+
# Temp files generated by the advanced discoverer will be located in this folder (sub-folder of workingDir folder)
11+
SubfolderAdvancedDiscoverer=advancedDiscoverer
12+
# Path to DOT executable (used to generate the pictures
613
dotExePath=C:/Program Files (x86)/Graphviz 2.28/bin/dot.exe
14+
# The parameter where the JSON will be included (DO NOT CHANGE)
715
JsonParameter=json
16+
# The parameter where the proxy will take the URL from.
17+
# (used in the Simple discoverer when the user gives an URL as in put)
818
UrlParameter=url
19+
# Max. number of bytes to read by the proxy
920
LimitChars=16384
21+
# Version of the tool deployed
1022
version=2.0.0
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1+
# The URL where the web application will be deployed.
2+
# Used for CORS, i.e., only requests from this URL will be accepted
13
serverURL=http://localhost:8080
4+
# A temp folder where all the pictures will be generated
25
workingDir=C:/Users/jcanovasi/git/jsonDiscoverer/jsondiscoverer.web/WebContent/workingDir
6+
# Temp files generated by the injector will be located in this folder (sub-folder of workingDir folder)
37
IdInjector=injector
4-
IdDiscoverer=discoverer
5-
IdMultiDiscoverer=multidiscoverer
8+
# Temp files generated by the simple discoverer will be located in this folder (sub-folder of workingDir folder)
9+
SubfolderSimpleDiscoverer=simpleDiscoverer
10+
# Temp files generated by the advanced discoverer will be located in this folder (sub-folder of workingDir folder)
11+
SubfolderAdvancedDiscoverer=advancedDiscoverer
12+
# Path to DOT executable (used to generate the pictures
613
dotExePath=C:/Program Files (x86)/Graphviz 2.28/bin/dot.exe
14+
# The parameter where the JSON will be included (DO NOT CHANGE)
715
JsonParameter=json
16+
# The parameter where the proxy will take the URL from.
17+
# (used in the Simple discoverer when the user gives an URL as in put)
818
UrlParameter=url
19+
# Max. number of bytes to read by the proxy
920
LimitChars=16384
21+
# Version of the tool deployed
1022
version=2.0.0
Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
1+
# The URL where the web application will be deployed.
2+
# Used for CORS, i.e., only requests from this URL will be accepted
13
serverURL=http://som-research.uoc.edu
4+
# A temp folder where all the pictures will be generated
25
workingDir=/opt/local/webapps/jsonDiscoverer/workingDir
6+
# Temp files generated by the injector will be located in this folder (sub-folder of workingDir folder)
37
IdInjector=injector
4-
IdDiscoverer=discoverer
5-
IdMultiDiscoverer=multidiscoverer
8+
# Temp files generated by the simple discoverer will be located in this folder (sub-folder of workingDir folder)
9+
SubfolderSimpleDiscoverer=simpleDiscoverer
10+
# Temp files generated by the advanced discoverer will be located in this folder (sub-folder of workingDir folder)
11+
SubfolderAdvancedDiscoverer=advancedDiscoverer
12+
# Path to DOT executable (used to generate the pictures
613
dotExePath=/usr/bin/dot
14+
# The parameter where the JSON will be included (DO NOT CHANGE)
715
JsonParameter=json
16+
# The parameter where the proxy will take the URL from.
17+
# (used in the Simple discoverer when the user gives an URL as in put)
818
UrlParameter=url
19+
# Max. number of bytes to read by the proxy
920
LimitChars=16384
21+
# Version of the tool deployed
1022
version=2.0.0
23+
Binary file not shown.

jsondiscoverer.web/WebContent/app/partials/documentation.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ <h2 id="doc-why">Why this?</h2>
2121
With the emergence of the Web 2.0, asynchronous-based web technologies are becoming mainstream mainly thanks to their ability to provide richer, faster and more interactive web experiences. For a long time, these applications have been using XML as interchange format, however, in the last years the JavaScript Object Notation (<a href="http://json.org/>">JSON</a>) has been gaining in popularity since it provides a lightweigth data exchange format with a significant performance improvement.
2222
</p>
2323
<p>
24-
JSON consists in sets of Object described by name/value pairs. It is <strong>schemaless</strong>, i.e., there is no a structural defition of JSON objects, instead it is implicit. Schemaless data is particularly <a href="http://martinfowler.com/articles/schemaless">interesting in cases dealing with non-uniform data or in schema migration</a>, however, it can become a burden in data integration scenarios (e.g., consuming JSONbased APIs) where it becomes necessary to discover at least partially the underlying structure in order to properly process the data.
24+
JSON consists in sets of Object described by name/value pairs. It is <strong>schemaless</strong>, i.e., there is no a structural definition of JSON objects, instead it is implicit. Schemaless data is particularly <a href="http://martinfowler.com/articles/schemaless">interesting in cases dealing with non-uniform data or in schema migration</a>, however, it can become a burden in data integration scenarios (e.g., consuming JSONbased APIs) where it becomes necessary to discover at least partially the underlying structure in order to properly process the data.
2525
</p>
2626
<p>
2727
Nowadays, a considerable number of web applications provide an external API consisting in a set of JSON-based services where all services are interrelated. Indeed, each service gives access to a subset of the application domain and developers must combine them to build any kind of non-trivial functionality on top of that API. Since JSON data is a schemaless format, deducing the right way of combining those services is not a trivial task. JSONDiscoverer aims at discovering (and visualizing) the implicit schema of the JSON data as well as the possible composition links among JSON-based Web APIs.

jsondiscoverer.web/WebContent/images/doc-architecture.svg

Lines changed: 2 additions & 2 deletions
Loading

jsondiscoverer.web/src/jsondiscoverer/web/AbstractJsonDiscoverer.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ public abstract class AbstractJsonDiscoverer extends HttpServlet {
5858
public static String dotExePath = null;
5959

6060
// Version of the app
61-
String version = "";
61+
public static String version = "";
6262

6363
// The jsonParam used for discovery (where the json code is stored)
6464
static String jsonParam = null;
6565

6666
// Server for the CORS
67-
String serverURL = "";
67+
static String serverURL = "";
6868

6969
Properties properties = null;
7070

@@ -83,7 +83,6 @@ public void init() throws ServletException {
8383
workingDirString = properties.getProperty("workingDir");
8484
dotExePath = properties.getProperty("dotExePath");
8585
jsonParam = properties.getProperty("JsonParameter");
86-
8786
serverURL = properties.getProperty("serverURL");
8887
version = properties.getProperty("version");
8988
if(serverURL == null)
@@ -106,6 +105,9 @@ public void init() throws ServletException {
106105
* @throws IOException
107106
*/
108107
String encodeToString(File imagePath) throws IOException {
108+
if(imagePath == null)
109+
throw new IllegalArgumentException("imagePath cannot be null");
110+
109111
BufferedImage image = ImageIO.read(imagePath);
110112

111113
String imageString = null;
@@ -134,6 +136,11 @@ String encodeToString(File imagePath) throws IOException {
134136
* @throws ServletException
135137
*/
136138
String encodeToString(EPackage ePackage, String uniqueId) throws ServletException {
139+
if(ePackage == null)
140+
throw new IllegalArgumentException("ePackage cannot be null");
141+
if(uniqueId == null)
142+
throw new IllegalArgumentException("uniqueId cannot be null");
143+
137144
File uniqueWorkingDir = new File(workingDir.getAbsolutePath() + File.separator + uniqueId);
138145
if(!uniqueWorkingDir.isDirectory()) throw new ServletException("The working dir could not be set:" + uniqueWorkingDir.getAbsolutePath());
139146

@@ -179,6 +186,11 @@ String encodeToString(EPackage ePackage, String uniqueId) throws ServletExcepti
179186
* @throws ServletException
180187
*/
181188
String encodeToString(List<EObject> elements, String uniqueId) throws ServletException {
189+
if(elements == null)
190+
throw new IllegalArgumentException("elements cannot be null");
191+
if(uniqueId == null)
192+
throw new IllegalArgumentException("uniqueId cannot be null");
193+
182194
File uniqueWorkingDir = new File(workingDir.getAbsolutePath() + File.separator + uniqueId);
183195
if(!uniqueWorkingDir.isDirectory()) throw new ServletException("The working dir could not be set:" + uniqueWorkingDir.getAbsolutePath());
184196

@@ -225,6 +237,11 @@ String encodeToString(List<EObject> elements, String uniqueId) throws ServletEx
225237
* @throws ServletException
226238
*/
227239
File drawModel(List<EObject> elements, String uniqueId) throws ServletException {
240+
if(elements == null)
241+
throw new IllegalArgumentException("elements cannot be null");
242+
if(uniqueId == null)
243+
throw new IllegalArgumentException("uniqueId cannot be null");
244+
228245
EcorePackage.eINSTANCE.eClass();
229246
GraphdescPackage.eINSTANCE.eClass();
230247

@@ -253,14 +270,20 @@ File drawModel(List<EObject> elements, String uniqueId) throws ServletException
253270
* @param response
254271
*/
255272
protected void addResponseOptions(HttpServletResponse response) {
273+
if(response == null)
274+
throw new IllegalArgumentException("response cannot be null");
275+
256276
response.setHeader("Access-Control-Allow-Origin", serverURL);
257277
response.setHeader("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS");
258278
response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
259279
response.addHeader("Access-Control-Allow-Credentials", "true");
260280
}
261281

262282
@Override
263-
protected void doOptions(HttpServletRequest arg0, HttpServletResponse response) throws ServletException, IOException {
283+
protected void doOptions(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
284+
if(response == null)
285+
throw new IllegalArgumentException("response cannot be null");
286+
264287
addResponseOptions(response);
265288
}
266289
}

0 commit comments

Comments
 (0)