ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1477106 - in /ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin: AddArtifactWindow.java ResourceTable.java
Date Mon, 29 Apr 2013 14:35:55 GMT
Author: bramk
Date: Mon Apr 29 14:35:55 2013
New Revision: 1477106

URL: http://svn.apache.org/r1477106
Log:
ACE-217 Added (unchecked) purge option to OBR resources view


Added:
    ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/ResourceTable.java
Modified:
    ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/AddArtifactWindow.java

Modified: ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/AddArtifactWindow.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/AddArtifactWindow.java?rev=1477106&r1=1477105&r2=1477106&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/AddArtifactWindow.java
(original)
+++ ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/AddArtifactWindow.java
Mon Apr 29 14:35:55 2013
@@ -24,6 +24,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
@@ -31,6 +32,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
 
+import javax.servlet.http.HttpServletResponse;
 import javax.xml.xpath.XPath;
 import javax.xml.xpath.XPathConstants;
 import javax.xml.xpath.XPathExpressionException;
@@ -304,7 +306,7 @@ abstract class AddArtifactWindow extends
         setModal(true);
         setWidth("50em");
 
-        m_artifactsTable = new ArtifactTable();
+        m_artifactsTable = new ResourceTable();
         m_artifactsTable.setCaption("Artifacts in repository");
 
         final IndexedContainer dataSource = (IndexedContainer) m_artifactsTable.getContainerDataSource();
@@ -623,17 +625,19 @@ abstract class AddArtifactWindow extends
         }
 
         // Create a list of all bundle names
-        for (OBREntry s : obrList) {
-            String uri = s.getUri();
-            String name = s.getName();
-            String version = s.getVersion();
+        for (final OBREntry entry : obrList) {
+            
+            String uri = entry.getUri();
+            String name = entry.getName();
+            String version = entry.getVersion();
 
             Item item = dataSource.addItem(uri);
-            item.getItemProperty(ArtifactTable.PROPERTY_SYMBOLIC_NAME).setValue(name);
-            item.getItemProperty(ArtifactTable.PROPERTY_VERSION).setValue(version);
+            item.getItemProperty(ResourceTable.PROPERTY_SYMBOLIC_NAME).setValue(name);
+            item.getItemProperty(ResourceTable.PROPERTY_VERSION).setValue(version);
+            item.getItemProperty(ResourceTable.PROPERTY_PURGE).setValue(createDeleteOBREntryButton(entry));
         }
     }
-
+    
     /**
      * Builds a list of all OBR artifacts currently in use.
      * 
@@ -777,4 +781,71 @@ abstract class AddArtifactWindow extends
 
         return obrList;
     }
+    
+    /**
+     * Delete an entry from the OBR.
+     * 
+     * @param entry
+     *            The OBREntry
+     * @param obrBaseUrl
+     *            The OBR base url
+     * @return The HTTP response code
+     * @throws IOException
+     *             If the HTTP operation fails
+     */
+    private int deleteOBREntry(OBREntry entry, URL obrBaseUrl) throws IOException {
+
+        HttpURLConnection connection = null;
+        try {
+            URL endpointUrl = new URL(obrBaseUrl, entry.getUri());
+            connection = (HttpURLConnection) openConnection(endpointUrl);
+            connection.setDoInput(true);
+            connection.setDoOutput(false);
+            connection.setInstanceFollowRedirects(false);
+            connection.setRequestMethod("DELETE");
+            connection.connect();
+            return connection.getResponseCode();
+        }
+        finally {
+            if (connection != null) {
+                connection.disconnect();
+            }
+        }
+    }
+    
+    /**
+     * Create a new button that delete an OBREntry on-click.
+     * 
+     * @param entry
+     *            The entry
+     * @return The button
+     */
+    private Button createDeleteOBREntryButton(final OBREntry entry) {
+
+        return new Button("X", new ClickListener() {
+
+            @Override
+            public void buttonClick(ClickEvent event) {
+
+                try {
+                    int code = deleteOBREntry(entry, m_obrUrl);
+                    if (code == HttpServletResponse.SC_OK) {
+                        m_artifactsTable.removeItem(entry.getUri());
+                        m_artifactsTable.refreshRowCache();
+                    }
+                    else {
+                        getWindow().showNotification("The OBR returned an unexpected response
code: " + code,
+                            Notification.TYPE_ERROR_MESSAGE);
+
+                    }
+                }
+                catch (IOException e) {
+                    getWindow().showNotification("Failed to delete resource!", "<br/>Reason:
" + e.getMessage(),
+                        Notification.TYPE_ERROR_MESSAGE);
+                    e.printStackTrace();
+                }
+
+            }
+        });
+    }
 }
\ No newline at end of file

Added: ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/ResourceTable.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/ResourceTable.java?rev=1477106&view=auto
==============================================================================
--- ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/ResourceTable.java
(added)
+++ ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/ResourceTable.java
Mon Apr 29 14:35:55 2013
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ace.webui.vaadin;
+
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Table;
+
+/**
+ * Provides a custom table for displaying OBR resources by their symbolic name and version.
+ */
+public class ResourceTable extends Table {
+
+    public static final String PROPERTY_SYMBOLIC_NAME = "symbolic name";
+    public static final String PROPERTY_VERSION = "version";
+    public static final String PROPERTY_PURGE = "purge";
+
+    public ResourceTable() {
+        super("Artifacts");
+
+        addContainerProperty(PROPERTY_SYMBOLIC_NAME, String.class, null);
+        addContainerProperty(PROPERTY_VERSION, String.class, null);
+        addContainerProperty(PROPERTY_PURGE, Button.class, null);
+
+        setSizeFull();
+
+        setSelectable(true);
+        setMultiSelect(true);
+        setImmediate(true);
+
+        setHeight("15em");
+    }
+}



Mime
View raw message