001: package example;
002:
003: import java.util.*;
004: import java.util.logging.*;
005: import javax.jws.*;
006: import javax.xml.bind.*;
007: import example.data.*;
008:
009: @WebService(endpointInterface="example.FlickrAPI")
010: public class FlickrImpl implements FlickrAPI {
011: private static final Logger log = Logger.getLogger(FlickrImpl.class
012: .getName());
013:
014: private HashMap<String, FlickrUser> _emailToUserMap = new HashMap<String, FlickrUser>();
015:
016: private HashMap<String, FlickrUser> _usernameToUserMap = new HashMap<String, FlickrUser>();
017:
018: private HashMap<String, FlickrPerson> _infoMap = new HashMap<String, FlickrPerson>();
019:
020: private HashMap<String, FlickrGroups> _groupsMap = new HashMap<String, FlickrGroups>();
021:
022: private HashMap<String, ArrayList<FlickrPhotos.Photo>> _photoMap = new HashMap<String, ArrayList<FlickrPhotos.Photo>>();
023:
024: public FlickrImpl() {
025: FlickrUser user1 = new FlickrUser();
026: user1.nsid = "12345678901@N01";
027: user1.username = "resin-caucho";
028:
029: _emailToUserMap.put("resin@caucho.com", user1);
030: _usernameToUserMap.put("resin-caucho", user1);
031:
032: FlickrPerson person1 = new FlickrPerson();
033: person1.nsid = "12345678901@N01";
034: person1.isadmin = 0;
035: person1.ispro = 0;
036: person1.iconserver = 2;
037: person1.realname = "Resin Caucho";
038: person1.mbox_sha1sum = "a11fc34be47a7ad1da8f670a26fa2b29f293c9fd";
039: person1.location = "La Jolla, California";
040: person1.photosurl = "http://www.flickr.com/photos/resin-caucho/";
041: person1.profileurl = "http://www.flickr.com/people/resin-caucho/";
042: person1.photos = new FlickrPerson.Photos();
043: person1.photos.firstdate = 1053200573;
044: person1.photos.firstdatetaken = "2003-10-08 17:32:04";
045: person1.photos.count = 342;
046:
047: _infoMap.put("12345678901@N01", person1);
048:
049: FlickrGroups groups1 = new FlickrGroups();
050:
051: FlickrGroups.Group group1 = new FlickrGroups.Group();
052: group1.nsid = "23456789012@N01";
053: group1.name = "Flowers";
054: group1.admin = 0;
055: group1.eighteenplus = 0;
056: groups1.groups.add(group1);
057:
058: FlickrGroups.Group group2 = new FlickrGroups.Group();
059: group2.nsid = "34567890123@N01";
060: group2.name = "Architecture";
061: group2.admin = 0;
062: group2.eighteenplus = 0;
063: groups1.groups.add(group2);
064:
065: _groupsMap.put("12345678901@N01", groups1);
066:
067: ArrayList<FlickrPhotos.Photo> photoList1 = new ArrayList<FlickrPhotos.Photo>();
068:
069: FlickrPhotos.Photo photo1 = new FlickrPhotos.Photo();
070: photo1.id = "3041";
071: photo1.owner = "12345678901@N01";
072: photo1.secret = "x123456";
073: photo1.server = 2;
074: photo1.title = "Our wedding";
075: photo1.ispublic = 1;
076: photo1.isfriend = 0;
077: photo1.isfamily = 0;
078: photoList1.add(photo1);
079:
080: FlickrPhotos.Photo photo2 = new FlickrPhotos.Photo();
081: photo2.id = "3042";
082: photo2.owner = "12345678901@N01";
083: photo2.secret = "y123456";
084: photo2.server = 1;
085: photo2.title = "Best friends";
086: photo2.ispublic = 0;
087: photo2.isfriend = 1;
088: photo2.isfamily = 0;
089: photoList1.add(photo2);
090:
091: _photoMap.put("12345678901@N01", photoList1);
092: }
093:
094: @WebMethod(operationName="flickr.people.findByEmail")
095: public FlickrResponse findByEmail(@WebParam(name="api_key")
096: String api_key, @WebParam(name="find_email")
097: String find_email) {
098: FlickrResponse response = new FlickrResponse();
099: response.payload = _emailToUserMap.get(find_email);
100:
101: if (response.payload == null) {
102: response.stat = "fail";
103: response.payload = new FlickrError();
104: }
105:
106: return response;
107: }
108:
109: @WebMethod(operationName="flickr.people.findByUsername")
110: public FlickrResponse findByUsername(@WebParam(name="api_key")
111: String api_key, @WebParam(name="username")
112: String username) {
113: FlickrResponse response = new FlickrResponse();
114: response.payload = _usernameToUserMap.get(username);
115:
116: if (response.payload == null) {
117: response.stat = "fail";
118: response.payload = new FlickrError();
119: }
120:
121: return response;
122: }
123:
124: @WebMethod(operationName="flickr.people.getInfo")
125: public FlickrResponse getInfo(@WebParam(name="api_key")
126: String api_key, @WebParam(name="user_id")
127: String user_id) {
128: FlickrResponse response = new FlickrResponse();
129: response.payload = _infoMap.get(user_id);
130:
131: if (response.payload == null) {
132: response.stat = "fail";
133: response.payload = new FlickrError();
134: }
135:
136: return response;
137: }
138:
139: @WebMethod(operationName="flickr.people.getPublicGroups")
140: public FlickrResponse getPublicGroups(@WebParam(name="api_key")
141: String api_key, @WebParam(name="user_id")
142: String user_id) {
143: FlickrResponse response = new FlickrResponse();
144: response.payload = _groupsMap.get(user_id);
145:
146: if (response.payload == null) {
147: response.stat = "fail";
148: response.payload = new FlickrError();
149: }
150:
151: return response;
152: }
153:
154: @WebMethod(operationName="flickr.people.getPublicPhotos")
155: public FlickrResponse getPublicPhotos(@WebParam(name="api_key")
156: String api_key, @WebParam(name="user_id")
157: String user_id, @WebParam(name="extras")
158: String extras, @WebParam(name="per_page")
159: int per_page, @WebParam(name="page")
160: int page) {
161: FlickrResponse response = new FlickrResponse();
162:
163: ArrayList<FlickrPhotos.Photo> photoList = _photoMap
164: .get(user_id);
165:
166: if (photoList != null) {
167: FlickrPhotos photos = new FlickrPhotos();
168: photos.page = page;
169: photos.pages = (photoList.size() / per_page)
170: + (photoList.size() % per_page > 0 ? 1 : 0);
171: photos.perpage = per_page;
172: photos.total = photoList.size();
173:
174: int startPhoto = (page - 1) * per_page;
175: int endPhoto = Math.min(page * per_page, photos.total);
176:
177: for (int i = startPhoto; i < endPhoto; i++)
178: photos.photos.add(photoList.get(i));
179:
180: response.payload = photos;
181: }
182:
183: if (response.payload == null) {
184: response.stat = "fail";
185: response.payload = new FlickrError();
186: }
187:
188: return response;
189: }
190: }
|