Added FaceBookfriendFinder impl and add it to the composite with a gallery UI button to call the service
git-svn-id: https://svn.apache.org/repos/asf/incubator/photark/trunk@1138583 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/photark-face-recognition/src/main/java/org/apache/photark/face/services/applications/facebook/FacebookFriendFinder.java b/photark-face-recognition/src/main/java/org/apache/photark/face/services/applications/facebook/FacebookFriendFinder.java
new file mode 100644
index 0000000..24ace0d
--- /dev/null
+++ b/photark-face-recognition/src/main/java/org/apache/photark/face/services/applications/facebook/FacebookFriendFinder.java
@@ -0,0 +1,19 @@
+package org.apache.photark.face.services.applications.facebook;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: subash
+ * Date: Jun 14, 2011
+ * Time: 11:53:30 PM
+ * To change this template use File | Settings | File Templates.
+ */
+@Remotable
+public interface FacebookFriendFinder {
+
+ public String[] getAllMyFBFriendsInThisPicture(String pathToFile);
+
+ public void setFacebookAuth(String facebookId, String fbAccessToken);
+
+}
diff --git a/photark-face-recognition/src/main/java/org/apache/photark/face/services/applications/facebook/FacebookFriendFinderImpl.java b/photark-face-recognition/src/main/java/org/apache/photark/face/services/applications/facebook/FacebookFriendFinderImpl.java
new file mode 100644
index 0000000..91ee2ff
--- /dev/null
+++ b/photark-face-recognition/src/main/java/org/apache/photark/face/services/applications/facebook/FacebookFriendFinderImpl.java
@@ -0,0 +1,54 @@
+package org.apache.photark.face.services.applications.facebook;
+
+import com.github.mhendred.face4j.exception.FaceClientException;
+import com.github.mhendred.face4j.exception.FaceServerException;
+import com.github.mhendred.face4j.model.Face;
+import com.github.mhendred.face4j.model.Photo;
+import org.apache.photark.face.services.FaceRecognitionService;
+import org.oasisopen.sca.annotation.Reference;
+import org.oasisopen.sca.annotation.Scope;
+
+import java.io.File;
+
+@Scope("COMPOSITE")
+public class FacebookFriendFinderImpl implements FacebookFriendFinder {
+
+ private FaceRecognitionService faceRecognitionService;
+
+ @Reference(name = "faceRecognitionService")
+ protected void setFaceRecognitionService(FaceRecognitionService faceRecognitionService) {
+ this.faceRecognitionService = faceRecognitionService;
+ }
+
+
+ public String[] getAllMyFBFriendsInThisPicture(String pathToFile) {
+ return new String[0];
+ }
+
+ public void setFacebookAuth(String facebookId, String fbAccessToken) {
+ faceRecognitionService.setFacebookOauth2(facebookId,fbAccessToken);
+ }
+
+ private String[] processFBFriends(String filePath) {
+
+ try {
+
+ Photo p = faceRecognitionService.recognizeFromFile(new File(filePath),"friends@facebook.com");
+
+ for(Face face : p.getFaces()) {
+ if(face.getGuess() != null) {
+ System.out.println("***Identified*** "+face.getGuess().toString());
+ } else {
+ System.out.println("??? Unidentified ..");
+ }
+ }
+
+ } catch (FaceClientException e) {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ } catch (FaceServerException e) {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+ return null; //TODO return Facebook IDs of recognized friends
+ }
+
+}
diff --git a/photark-face-recognition/src/main/resources/META-INF/sca-contribution.xml b/photark-face-recognition/src/main/resources/META-INF/sca-contribution.xml
index 52fe591..307a36e 100644
--- a/photark-face-recognition/src/main/resources/META-INF/sca-contribution.xml
+++ b/photark-face-recognition/src/main/resources/META-INF/sca-contribution.xml
@@ -20,8 +20,6 @@
<contribution xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
xmlns:photark="http://org.apache.photoark">
<export.java package="org.apache.photark.face.services"/>
- <export.java package="com.github.mhendred.face4j.exception"/>
- <export.java package="com.github.mhendred.face4j.model"/>
- <export.java package="om.github.mhendred.face4j.response"/>
+ <export.java package="org.apache.photark.face.services.applications.facebook"/>
</contribution>
diff --git a/photark-ui/src/main/webapp/gallery.html b/photark-ui/src/main/webapp/gallery.html
index 376375b..243c8b9 100644
--- a/photark-ui/src/main/webapp/gallery.html
+++ b/photark-ui/src/main/webapp/gallery.html
@@ -112,7 +112,7 @@
</td>
<td align="left">
<div id="tags">
- <input id="addtag-input" style="width:20;" type="text" style="display:inline;" value="" size="20" alt="add tag..."/><input type="button" onclick="addTag();" style="display:inline;" value="Add Tag"/>
+ <input id="addtag-input" style="width:20;" type="text" style="display:inline;" value="" size="20" alt="add tag..."/><input type="button" onclick="addTag();" style="display:inline;" value="Add Tag"/><input type="button" onclick="showFacebookFriends();" style="display:inline;" value="facebook"/>
<table id='tableTags' style="margin-left:auto; margin-right:auto;width:150;" border="0"
cellspacing="0" cellpadding="1">
</table>
diff --git a/photark-ui/src/main/webapp/js/constants.js b/photark-ui/src/main/webapp/js/constants.js
index ec78c2a..b0946e3 100644
--- a/photark-ui/src/main/webapp/js/constants.js
+++ b/photark-ui/src/main/webapp/js/constants.js
@@ -28,6 +28,7 @@
photark.constants.contextRoot = "/photark/";
photark.constants.adminContextRoot = "/photark/admin/";
+photark.constants.FacebookFriendFinder = photark.constants.contextRoot + "FacebookFriendFinder?smd";
photark.constants.FaceRecognitionService = photark.constants.contextRoot + "FaceRecognitionService?smd";
photark.constants.RemoteAlbumSubscription = photark.constants.contextRoot + "RemoteAlbumSubscriptionManager?smd";
photark.constants.GalleryServiceEndpoint = photark.constants.contextRoot + "GalleryService?smd";
diff --git a/photark-ui/src/main/webapp/js/gallery.js b/photark-ui/src/main/webapp/js/gallery.js
index d958713..7feddc7 100644
--- a/photark-ui/src/main/webapp/js/gallery.js
+++ b/photark-ui/src/main/webapp/js/gallery.js
@@ -57,8 +57,9 @@
var permissions = new Array();
var albumImageToBeLoaded = null;
-var FACE_API_KEY = "";
-var FACE_API_SECRET = "";
+var FACE_API_KEY = "5ae7a7ddcba07b5d4731930bfe06f4c7";
+var FACE_API_SECRET = "6877f93df2c2bcef2a1ddb6ba26a0d6c";
+var facebook_ff;
dojo.addOnLoad(function() {
dojo.require("dojo._base.xhr");
@@ -96,8 +97,8 @@
gallery = new dojo.rpc.JsonService( photark.constants.GalleryServiceEndpoint );
remoteGallery = new dojo.rpc.JsonService(photark.constants.RemoteGalleryServiceEndpoint);
faceService = new dojo.rpc.JsonService(photark.constants.FaceRecognitionService);
-// faceService.createNewDefaultFaceClient(FACE_API_KEY,FACE_API_SECRET).addCallback(face_callback);
-
+ faceService.createNewDefaultFaceClient(FACE_API_KEY,FACE_API_SECRET).addCallback(face_callback);
+ facebook_ff = new dojo.rpc.JsonService(photark.constants.FacebookFriendFinder);
}
function initGallery() {
@@ -277,6 +278,10 @@
}
+function showFacebookFriends(){
+ facebook_ff.getAllMyFBFriendsInThisPicture().addCallback(facebook_ff_callback);
+}
+
function face_callback(items, exception) {
if(exception) {
// alert(exception.msg);
@@ -287,6 +292,17 @@
}
+function facebook_ff_callback(items, exception) {
+ if(exception) {
+ // alert(exception.msg);
+ displayGallery();
+ logout();
+ // return;
+ }
+ alert(items[0]);
+
+}
+
function initializeRemoteGallery() {
var table=document.getElementById('remoteTableGallery');
diff --git a/photark-webapp/src/main/webapp/WEB-INF/web.composite b/photark-webapp/src/main/webapp/WEB-INF/web.composite
index bf0bd9f..15b1557 100644
--- a/photark-webapp/src/main/webapp/WEB-INF/web.composite
+++ b/photark-webapp/src/main/webapp/WEB-INF/web.composite
@@ -177,6 +177,17 @@
<tuscany:binding.jsonrpc uri="/FaceRecognitionService"/>
</service>
</component>
+
+ <component name="FacebookFriendFinder">
+ <implementation.java class="org.apache.photark.face.services.applications.facebook.FacebookFriendFinderImpl"/>
+
+ <service name="FacebookFriendFinder">
+ <interface.java interface="org.apache.photark.face.services.applications.facebook.FacebookFriendFinder"/>
+ <binding.sca name="local"/>
+ <tuscany:binding.jsonrpc uri="/FacebookFriendFinder"/>
+ </service>
+ <reference name="faceRecognitionService" target="FaceRecognitionService"/>
+ </component>
</composite>