PHOTARK-61 Add Album Subscription backend to trunk from photark-rest
git-svn-id: https://svn.apache.org/repos/asf/incubator/photark/trunk@1004524 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/photark-flickr/DISCLAIMER b/photark-flickr/DISCLAIMER
new file mode 100644
index 0000000..2e42279
--- /dev/null
+++ b/photark-flickr/DISCLAIMER
@@ -0,0 +1,7 @@
+Apache PhotArk is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Incubator PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
\ No newline at end of file
diff --git a/photark-flickr/LICENSE b/photark-flickr/LICENSE
new file mode 100644
index 0000000..8aa906c
--- /dev/null
+++ b/photark-flickr/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed 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.
+
+
+
diff --git a/photark-flickr/NOTICE b/photark-flickr/NOTICE
new file mode 100644
index 0000000..1495c45
--- /dev/null
+++ b/photark-flickr/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2008 - 2009 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/photark-flickr/pom.xml b/photark-flickr/pom.xml
new file mode 100644
index 0000000..b10de41
--- /dev/null
+++ b/photark-flickr/pom.xml
@@ -0,0 +1,115 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.photark</groupId>
+ <artifactId>photark-parent</artifactId>
+ <version>1.0-incubating-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>photark-flickr</artifactId>
+ <name>Apache PhotArk Flickr Photo Album Subscription</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-sca-api</artifactId>
+ <version>${tuscany.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.photark</groupId>
+ <artifactId>photark</artifactId>
+ <version>1.0-incubating-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.abdera</groupId>
+ <artifactId>abdera-core</artifactId>
+ <version>1.0</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-activation_1.0.2_spec</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.abdera</groupId>
+ <artifactId>abdera-parser</artifactId>
+ <version>1.0</version>
+ <!-- exclusions>
+ <exclusion>
+ <groupId>stax</groupId>
+ <artifactId>stax-api</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>xom</groupId>
+ <artifactId>xom</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.ws.commons.axiom</groupId>
+ <artifactId>axiom-impl</artifactId>
+ </exclusion>
+ </exclusions-->
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.abdera</groupId>
+ <artifactId>abdera-client</artifactId>
+ <version>1.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.abdera</groupId>
+ <artifactId>abdera-extensions-main</artifactId>
+ <version>1.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.abdera</groupId>
+ <artifactId>abdera-extensions-json</artifactId>
+ <version>1.0</version>
+ </dependency>
+
+ <!-- marking dependency as provided to exclude from war file -->
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8.1</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <finalName>${artifactId}</finalName>
+ </build>
+
+</project>
diff --git a/photark-flickr/src/main/java/org/apache/photark/album/flickr/FlickrAlbumImpl.java b/photark-flickr/src/main/java/org/apache/photark/album/flickr/FlickrAlbumImpl.java
new file mode 100644
index 0000000..6851c9e
--- /dev/null
+++ b/photark-flickr/src/main/java/org/apache/photark/album/flickr/FlickrAlbumImpl.java
@@ -0,0 +1,83 @@
+/*
+ * 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.photark.album.flickr;
+
+import org.apache.photark.Image;
+
+
+public class FlickrAlbumImpl implements org.apache.photark.services.album.Album {
+
+ public void addPicture(Image picture) {
+ throw new UnsupportedOperationException("Can't upload image to Album subscription");
+ }
+
+ public void deletePicture(Image picture) {
+ throw new UnsupportedOperationException("Can't upload image to Album subscription");
+ }
+
+ public void deletePicture(String picture) {
+ throw new UnsupportedOperationException("Can't upload image to Album subscription");
+ }
+
+ public void addOwner(String owner){
+
+ }
+
+ public String[] getOwners(){
+ throw new UnsupportedOperationException("Can't upload image to Album subscription");
+ }
+
+
+ public String getDescription() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getLocation() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String[] getPictures() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void setDescription(String description) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setLocation(String location) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setName(String name) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/photark-flickr/src/main/java/org/apache/photark/album/flickr/FlickrPhotoStream.java b/photark-flickr/src/main/java/org/apache/photark/album/flickr/FlickrPhotoStream.java
new file mode 100644
index 0000000..c29b749
--- /dev/null
+++ b/photark-flickr/src/main/java/org/apache/photark/album/flickr/FlickrPhotoStream.java
@@ -0,0 +1,140 @@
+/*
+ * 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.photark.album.flickr;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.xml.ws.http.HTTPException;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.parser.Parser;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpConnectionManager;
+import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.photark.Image;
+import org.apache.tuscany.sca.data.collection.Collection;
+import org.apache.tuscany.sca.data.collection.Entry;
+import org.apache.tuscany.sca.data.collection.NotFoundException;
+
+public class FlickrPhotoStream implements Collection<String, Image> {
+ private static final Logger logger = Logger.getLogger(FlickrPhotoStream.class.getName());
+
+ private static final Parser abderaParser = Abdera.getNewParser();
+
+ private final String feedURI;
+
+ private HttpClient httpClient;
+
+ public FlickrPhotoStream(String feedURI) {
+ this.feedURI = feedURI;
+
+ // Create an HTTP client
+ HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
+ connectionManager.getParams().setDefaultMaxConnectionsPerHost(10);
+ connectionManager.getParams().setConnectionTimeout(60000);
+ httpClient = new HttpClient(connectionManager);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Entry<String, Image>[] getAll() {
+ List<Entry<String, Image>> images = null;
+ GetMethod getMethod = new GetMethod(feedURI);
+
+ try {
+ httpClient.executeMethod(getMethod);
+ int status = getMethod.getStatusCode();
+
+ // Read the Atom entry
+ if (status == 200) {
+ Document<org.apache.abdera.model.Feed> doc = abderaParser.parse(new InputStreamReader(getMethod.getResponseBodyAsStream()));
+ org.apache.abdera.model.Feed feed = null;
+ try {
+ feed = doc.getRoot();
+ } catch(Exception e) {
+ throw new IllegalArgumentException("Error parsing feed: " + e.getMessage());
+ }
+
+ images = new ArrayList<Entry<String, Image>>();
+ for (org.apache.abdera.model.Entry feedEntry : feed.getEntries()) {
+ Image image = fromEntry(feedEntry);
+ images.add(new Entry<String, Image>(image.getName(), image));
+ }
+
+ } else {
+ throw new IllegalArgumentException("Invalid photo stream uri:" + feedURI);
+ }
+ } catch (IOException ioe) {
+ logger.log(Level.WARNING, "Error retrieving photo stream from '" + feedURI + "' :" + ioe.getMessage(), ioe);
+ } catch (HTTPException he) {
+ logger.log(Level.WARNING, "Error retrieving photo stream from '" + feedURI + "' :" + he.getMessage(), he);
+ }
+
+ Entry<String, Image>[] imageArray = new Entry[images.size()];
+ images.toArray(imageArray);
+ return imageArray;
+ }
+
+ public Image get(String key) throws NotFoundException {
+ throw new java.lang.UnsupportedOperationException("Operation not supported in album subscriptions");
+ }
+
+ public String post(String key, Image value) {
+ throw new java.lang.UnsupportedOperationException("Operation not supported in album subscriptions");
+ }
+
+ public void put(String key, Image value) throws NotFoundException {
+ throw new java.lang.UnsupportedOperationException("Operation not supported in album subscriptions");
+ }
+
+ public void delete(String key) throws NotFoundException {
+ throw new java.lang.UnsupportedOperationException("Operation not supported in album subscriptions");
+ }
+
+ public Entry<String, Image>[] query(String query) {
+ throw new java.lang.UnsupportedOperationException("Operation not supported in album subscriptions");
+ }
+
+ private static Image fromEntry(org.apache.abdera.model.Entry entry) {
+
+ if(logger.isLoggable(Level.FINEST)) {
+ logger.log(Level.FINEST, ">>>>>>>>>>>>>");
+ logger.log(Level.FINEST, ">> ID : " + entry.getId().toString());
+ logger.log(Level.FINEST, ">> Title : " + entry.getTitle());
+ logger.log(Level.FINEST, ">> Link : " + entry.getEnclosureLinkResolvedHref().toString());
+ }
+
+ Image image = new Image();
+ String id = entry.getId().toString();
+ image.setId(id.substring(id.lastIndexOf("/") + 1));
+ image.setTitle(entry.getTitle());
+ image.setLocation(entry.getEnclosureLinkResolvedHref().toString());
+
+ return image;
+ }
+
+
+}
diff --git a/photark-flickr/src/main/resources/META-INF/sca-contribution.xml b/photark-flickr/src/main/resources/META-INF/sca-contribution.xml
new file mode 100644
index 0000000..de02dae
--- /dev/null
+++ b/photark-flickr/src/main/resources/META-INF/sca-contribution.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<contribution xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903"
+ xmlns:photark="http://org.apache.photoark">
+ <export.java package="org.apache.photark.services.album"/>
+ <export.java package="org.apache.photark.services.gallery"/>
+</contribution>
\ No newline at end of file
diff --git a/photark-flickr/src/test/java/org/apache/photark/album/flickr/FlickrSubscriptionTestCase.java b/photark-flickr/src/test/java/org/apache/photark/album/flickr/FlickrSubscriptionTestCase.java
new file mode 100644
index 0000000..bb18ee2
--- /dev/null
+++ b/photark-flickr/src/test/java/org/apache/photark/album/flickr/FlickrSubscriptionTestCase.java
@@ -0,0 +1,49 @@
+/*
+ * 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.photark.album.flickr;
+
+import org.apache.photark.Image;
+import org.apache.tuscany.sca.data.collection.Entry;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class FlickrSubscriptionTestCase {
+ private static final String SUBSCRIPTION_URL = "http://api.flickr.com/services/feeds/photos_public.gne?id=24662369@N07&lang=en-us&format=atom";
+ private static FlickrPhotoStream photoStream;
+
+ @BeforeClass
+ public static void BeforeClass() {
+ photoStream = new FlickrPhotoStream(SUBSCRIPTION_URL);
+ }
+
+ @Test
+ public void testDiscoverAlbums() {
+ Entry<String, Image>[] images = photoStream.getAll();
+
+ for(Entry<String, Image> image : images) {
+ Image i = image.getData();
+
+ System.out.println(">>>>>>>>>>>>>");
+ System.out.println(">> ID : " + i.getId());
+ System.out.println(">> Title : " + i.getTitle());
+ System.out.println(">> Location : " + i.getLocation());
+ }
+ }
+}
diff --git a/photark-picasa/pom.xml b/photark-picasa/pom.xml
new file mode 100644
index 0000000..3308b05
--- /dev/null
+++ b/photark-picasa/pom.xml
@@ -0,0 +1,119 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.photark</groupId>
+ <artifactId>photark-parent</artifactId>
+ <version>1.0-incubating-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>photark-picasa</artifactId>
+ <name>Apache PhotArk Google Picasa Photo Album Subscription</name>
+
+ <repositories>
+ <repository>
+ <id>com.google.gdata</id>
+ <url>http://svn.apache.org/repos/asf/tuscany/maven/</url>
+ </repository>
+ </repositories>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-sca-api</artifactId>
+ <version>${tuscany.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.photark</groupId>
+ <artifactId>photark</artifactId>
+ <version>1.0-incubating-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.google.collections</groupId>
+ <artifactId>google-collections</artifactId>
+ <version>1.0-rc1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.google.gdata</groupId>
+ <artifactId>gdata-client</artifactId>
+ <version>1.41.4</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.google.gdata</groupId>
+ <artifactId>gdata-client-meta</artifactId>
+ <version>1.41.4</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.google.gdata</groupId>
+ <artifactId>gdata-core</artifactId>
+ <version>1.41.4</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.google.gdata</groupId>
+ <artifactId>gdata-media</artifactId>
+ <version>1.41.4</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.google.gdata</groupId>
+ <artifactId>gdata-photos</artifactId>
+ <version>1.41.4</version>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.mail</groupId>
+ <artifactId>mail</artifactId>
+ <version>1.4</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.google.gdata</groupId>
+ <artifactId>gdata-photos-meta</artifactId>
+ <version>1.41.4</version>
+ </dependency>
+
+ <!-- marking dependency as provided to exclude from war file -->
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>${artifactId}</finalName>
+ </build>
+
+</project>
diff --git a/photark-picasa/src/main/java/org/apache/photark/album/picasa/PicasaPhotoStream.java b/photark-picasa/src/main/java/org/apache/photark/album/picasa/PicasaPhotoStream.java
new file mode 100644
index 0000000..3aba957
--- /dev/null
+++ b/photark-picasa/src/main/java/org/apache/photark/album/picasa/PicasaPhotoStream.java
@@ -0,0 +1,167 @@
+/*
+ * 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.photark.album.picasa;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.photark.Image;
+import org.apache.tuscany.sca.data.collection.Collection;
+import org.apache.tuscany.sca.data.collection.Entry;
+import org.apache.tuscany.sca.data.collection.NotFoundException;
+
+import com.google.gdata.client.photos.PicasawebService;
+import com.google.gdata.data.Feed;
+import com.google.gdata.data.photos.AlbumFeed;
+import com.google.gdata.data.photos.PhotoEntry;
+import com.google.gdata.util.AuthenticationException;
+import com.google.gdata.util.ServiceException;
+
+public class PicasaPhotoStream implements Collection<String, Image> {
+ private static final Logger logger = Logger.getLogger(PicasaPhotoStream.class.getName());
+
+ private static final String APPLICATION_NAME = "photark";
+ private static final String PICASA_SERVICE_TYPE = "lh2";
+
+ private final String feedURI;
+ private final String username;
+ private final String password;
+
+ private boolean initialized = false;
+
+ private PicasawebService picasaService;
+
+ public PicasaPhotoStream(String feedURI) {
+ this.feedURI = feedURI;
+ this.username = null;
+ this.password= null;
+ }
+
+ public PicasaPhotoStream(String feedURI, String username, String password) {
+ this.feedURI = feedURI;
+ this.username = username;
+ this.password = password;
+
+ }
+
+ private void initialize() {
+ logger.log(Level.FINE, "Initializing Google services to retrieve Picasa photo stream");
+ picasaService = new PicasawebService(APPLICATION_NAME);
+ if(this.username != null & this.password != null) {
+ logger.log(Level.FINE, "Authenticating user");
+ try {
+ picasaService.setUserCredentials(username, password);
+ } catch (AuthenticationException e) {
+ throw new IllegalArgumentException(
+ "Illegal username/password combination.");
+ }
+ }
+ initialized = true;
+ }
+
+
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public Entry<String, Image>[] getAll() {
+
+ List<Entry<String, Image>> images = new ArrayList<Entry<String, Image>>();
+
+ if(!initialized) {
+ try {
+ initialize();
+ } catch(Exception ae) {
+ logger.log(Level.FINE, "Error initializing service: " + ae.getMessage(), ae);
+ return new Entry[0];
+ }
+ }
+
+ // retrieve list of photos
+
+
+ try {
+ AlbumFeed feed = picasaService.getFeed(new URL(feedURI), AlbumFeed.class);
+ for(PhotoEntry photo : feed.getPhotoEntries()) {
+ Image image = fromEntry(photo);
+ images.add(new Entry(image.getId(), image));
+ }
+ } catch (MalformedURLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (ServiceException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ Entry<String, Image>[] imageArray = new Entry[images.size()];
+ images.toArray(imageArray);
+ return imageArray;
+ }
+
+ public Image get(String key) throws NotFoundException {
+ throw new java.lang.UnsupportedOperationException("Operation not supported in album subscriptions");
+ }
+
+ public String post(String key, Image value) {
+ throw new java.lang.UnsupportedOperationException("Operation not supported in album subscriptions");
+ }
+
+ public void put(String key, Image value) throws NotFoundException {
+ throw new java.lang.UnsupportedOperationException("Operation not supported in album subscriptions");
+ }
+
+ public void delete(String key) throws NotFoundException {
+ throw new java.lang.UnsupportedOperationException("Operation not supported in album subscriptions");
+ }
+
+ public Entry<String, Image>[] query(String query) {
+ throw new java.lang.UnsupportedOperationException("Operation not supported in album subscriptions");
+ }
+
+ private static Image fromEntry(PhotoEntry photo) {
+
+ if(logger.isLoggable(Level.FINEST)) {
+ logger.log(Level.FINEST, ">>>>>>>>>>>>>");
+ logger.log(Level.FINEST, ">> ID : " + photo.getId());
+ logger.log(Level.FINEST, ">> Title : " + photo.getTitle().getPlainText());
+ logger.log(Level.FINEST, ">> Link : " + photo.getLinks().get(0).getHref());
+ }
+
+ Image image = new Image();
+
+ // further documentation available at
+ // http://code.google.com/apis/picasaweb/docs/2.0/developers_guide_java.html
+
+ image.setId(photo.getGphotoId());
+ image.setName(photo.getTitle().getPlainText());
+ image.setTitle(photo.getTitle().getPlainText());
+ image.setLocation(photo.getMediaContents().get(0).getUrl());
+
+ return image;
+ }
+
+}
diff --git a/photark-picasa/src/test/java/org/apache/photark/album/picasa/PicasaSubscriptionTestCase.java b/photark-picasa/src/test/java/org/apache/photark/album/picasa/PicasaSubscriptionTestCase.java
new file mode 100644
index 0000000..c86fb64
--- /dev/null
+++ b/photark-picasa/src/test/java/org/apache/photark/album/picasa/PicasaSubscriptionTestCase.java
@@ -0,0 +1,49 @@
+/*
+ * 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.photark.album.picasa;
+
+import org.apache.photark.Image;
+import org.apache.tuscany.sca.data.collection.Entry;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class PicasaSubscriptionTestCase {
+ private static final String SUBSCRIPTION_URL = "http://picasaweb.google.com/data/feed/api/featured";
+ private static PicasaPhotoStream photoStream;
+
+ @BeforeClass
+ public static void BeforeClass() {
+ photoStream = new PicasaPhotoStream(SUBSCRIPTION_URL);
+ }
+
+ @Test
+ public void testDiscoverAlbums() {
+ Entry<String, Image>[] images = photoStream.getAll();
+
+ for(Entry<String, Image> image : images) {
+ Image i = image.getData();
+
+ System.out.println(">>>>>>>>>>>>>");
+ System.out.println(">> ID : " + i.getId());
+ System.out.println(">> Title : " + i.getTitle());
+ System.out.println(">> Location : " + i.getLocation());
+ }
+ }
+}
diff --git a/photark/src/main/java/org/apache/photark/Image.java b/photark/src/main/java/org/apache/photark/Image.java
index 09cd4cd..9dc85fd 100644
--- a/photark/src/main/java/org/apache/photark/Image.java
+++ b/photark/src/main/java/org/apache/photark/Image.java
@@ -34,11 +34,14 @@
public class Image implements Serializable {
private static final long serialVersionUID = 2681872730283844321L;
-
+ private String id;
+ private String name;
+ private String title;
private String imageName;
private Date datePosted;
private transient InputStream imageStream;
-
+ private String url;
+ private String urlThumb;
private List<ImageMetadata> imageAttributes;
public Image() {
@@ -72,6 +75,33 @@
this.imageStream = imageStream;
}
+
+ /**
+ * Set image file name
+ * @param name image file name
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+
+ /**
+ * Get image Id
+ * @return image id
+ */
+ public String getId() {
+ return this.id;
+ }
+
+ /**
+ * Set image id
+ * @param id image id
+ */
+ public void setId(String id) {
+ this.id = id;
+ }
+
+
/**
* Get image file name
* @return image file name
@@ -87,6 +117,39 @@
public Date getDatePosted() {
return datePosted;
}
+
+ /**
+ * Get image title
+ * @return image title
+ */
+ public String getTitle() {
+ return title;
+ }
+
+ /**
+ * Set image title
+ * @param title image title
+ */
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ /**
+ * Get Image URL
+ * @return the image URL
+ */
+ public String getLocation() {
+ return url;
+ }
+
+ /**
+ * Set Image URL
+ * @param url Image URL
+ */
+ public void setLocation(String location) {
+ this.url = location;
+ }
+
/**
* Return image content as stream
diff --git a/pom.xml b/pom.xml
index d93ea5e..3f837ed 100644
--- a/pom.xml
+++ b/pom.xml
@@ -210,8 +210,10 @@
<modules>
<module>photark</module>
<module>photark-security</module>
- <module>photark-filesystem</module>
+ <module>photark-filesystem</module>
+ <module>photark-flickr</module>
<module>photark-jcr</module>
+ <module>photark-picasa</module>
<module>photark-search</module>
<module>photark-ui</module>
<module>photark-ui-admin</module>
@@ -230,8 +232,10 @@
<module>distribution</module>
<module>photark</module>
<module>photark-security</module>
- <module>photark-filesystem</module>
+ <module>photark-filesystem</module>
+ <module>photark-flickr</module>
<module>photark-jcr</module>
+ <module>photark-picasa</module>
<module>photark-search</module>
<module>photark-ui</module>
<module>photark-ui-admin</module>
@@ -250,8 +254,10 @@
<module>distribution</module>
<module>photark</module>
<module>photark-security</module>
- <module>photark-filesystem</module>
+ <module>photark-filesystem</module>
+ <module>photark-flickr</module>
<module>photark-jcr</module>
+ <module>photark-picasa</module>
<module>photark-search</module>
<module>photark-ui</module>
<module>photark-ui-admin</module>