group111

19
6.1-6.2 by Group111

Upload: shahriar-robbani

Post on 23-Feb-2017

230 views

Category:

Engineering


0 download

TRANSCRIPT

Page 1: Group111

6.1-6.2by Group111

Page 2: Group111

Solution – Exercise 6.1 (Frameworks)

Chosen Pattern: Factory Design Pattern

Properties of the pattern:• Define the class of an object at run time. In our case, the UI component like comboBox are created in run time. If for further cases its required to use any other component like radio box, we can easily add the class and the class will be loaded at the run time.

• It also allows to encapsulate object creation so that you can keep all object creation code in one place.In our case, to create the comboBox we write newComboBox.OrderComponent. If we have to

create the radio box then we will define the newRadioBox.OrderComponent.

• Generally its has a method named factory methods which returns one of several possible classes that share a common super class.

For our scenario, the name of the method is orderComponent which returns the component as per as requested.

• It obeys the “DEPENDENCY INVERSION PRINCIPLE” means depend upon abstraction. Do not depend upon concrete classes.

In this class, the abstraction class is javax.swing.Jcomponent. This class acts as a bridge between the creator and product.

Page 3: Group111
Page 4: Group111
Page 5: Group111

Followed Principles • HollyWood Principle:

In our code, user will call the calculationOfFree Spaces, and the framework will automatically call the corresponding class for executing the method.

• Open For Extension but not for modification:We can extend the code CalculationOfFlat but we can not modify the existing code.

Page 6: Group111

Solution – Exercise 6.2 (RESTful Webservices)

1. We edit the ImageResource class in the given prototype application. addImage() function will receive the image url via GET method. After getting the file path it stores the file path in the Image object and then save it to the list which was provided.

Page 7: Group111

c…

It returns 1 that means this url has successfully added.

Page 8: Group111

Publish from the clint2. We add a publish button in our SWCArchitect interior design application. That application is act like a client. Client would also verify if publish is successful. A popup message is shown according to response. In addition, we do some url decoding and encoding techniques for passing file url via REST.

Page 9: Group111

When publish a design

Page 10: Group111

PublishTool.java• File file = new File("img" + File.separator + "pub.png");• int count = 0;• while (file.exists()) {• file = new File("img" + File.separator + "pub" + count + ".png");• count++;• }• String path = file.getPath();

• ImageOutputFormat outputFormat = new ImageOutputFormat();• try {• for (DrawingView drawingView : this.editor.getDrawingViews()) {• outputFormat.write(file, drawingView.getDrawing());• }• } catch (Exception e) {• e.printStackTrace();• }

Page 11: Group111

c…..• final String USER_AGENT = "Mozilla/5.0";• String url = "http://localhost:8080/image/pub/";• String loc = file.getAbsolutePath().replace(String.valueOf(File.separatorChar), "-").replace(".png", "");• String param = "?format=image";• URL obj;• try {• String urlFull = url + loc + param;• obj = new URL(urlFull);• HttpURLConnection con = (HttpURLConnection) obj.openConnection();• System.out.println(urlFull);• con.setRequestMethod("GET");• con.setRequestProperty("User-Agent", USER_AGENT);• int responseCode = con.getResponseCode();• BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));• String inputLine;• StringBuffer response = new StringBuffer();• while ((inputLine = in.readLine()) != null) {• response.append(inputLine);• }• if (Integer.parseInt(response.toString())==1) {• JOptionPane.showMessageDialog(editor.getActiveView().getComponent(), "Successfully Published!");• } else {• JOptionPane.showMessageDialog(editor.getActiveView().getComponent(), "Cannot Published!!");

Page 12: Group111

Image.java

Page 13: Group111

Implement approve and deny

3. We wrote different functions for deny and allow operations and also they have their own request mapping. Initially when an image is published, it would not be shown in the Home page. Initially pictures can be seen in admin tab. Then if you allow a picture it is shown in the home page. And also there is a option to deny the images again. If the application restart the previous published images will remove.

Page 14: Group111

Admin.js

Page 15: Group111

Admin.html

Page 16: Group111

Initially no image is approved

Page 17: Group111

What is in admin tab?

Page 18: Group111

After Approve

Page 19: Group111

Approved image can be deny again