group111
TRANSCRIPT
6.1-6.2by 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.
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.
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.
c…
It returns 1 that means this url has successfully added.
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.
When publish a design
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();• }
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!!");
Image.java
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.
Admin.js
Admin.html
Initially no image is approved
What is in admin tab?
After Approve
Approved image can be deny again