ALF-10105: PUB: Improved handling of errors reported from Flickr service

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@30626 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Brian Remmington
2011-09-20 09:37:20 +00:00
parent cd2167de85
commit 2f08b645e6
7 changed files with 89 additions and 10 deletions

View File

@@ -109,7 +109,7 @@ public class FlickrTest extends BaseSpringTest
props.put(PublishingModel.PROP_OAUTH1_TOKEN_SECRET, "YOUR_OAUTH_TOKEN_SECRET");
props.put(PublishingModel.PROP_AUTHORISATION_COMPLETE, Boolean.TRUE);
Channel channel = channelService.createChannel(FlickrChannelType.ID, "FlickrTestChannel", props);
Channel channel = channelService.createChannel(FlickrChannelType.ID, "FlickrTestChannel_" + GUID.generate(), props);
//This looks a little odd, but a new channel always has its "authorisation complete" flag
//forced off initially. This will force it on for this channel...
channelService.updateChannel(channel, props);

View File

@@ -28,8 +28,6 @@ import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.social.connect.Connection;
public class FlickrUnpublishAction extends ActionExecuterAbstractBase

View File

@@ -0,0 +1,37 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.publishing.flickr.springsocial.api;
public class FlickrException extends RuntimeException
{
private static final long serialVersionUID = 7938720115597007302L;
private String code;
public FlickrException(String errorCode, String message)
{
super(message);
this.code = errorCode;
}
public String getCode()
{
return code;
}
}

View File

@@ -23,9 +23,9 @@ import org.springframework.core.io.Resource;
public interface MediaOperations
{
String postPhoto(Resource photo, String title, String description, String... tags);
String postPhoto(Resource photo, String title, String description, String... tags) throws FlickrException;
PhotoInfo getPhoto(String id);
PhotoInfo getPhoto(String id) throws FlickrException;
void deletePhoto(String id);
void deletePhoto(String id) throws FlickrException;
}

View File

@@ -18,15 +18,15 @@
*/
package org.alfresco.repo.publishing.flickr.springsocial.api.impl;
import org.alfresco.repo.publishing.flickr.springsocial.api.FlickrException;
import org.alfresco.repo.publishing.flickr.springsocial.api.FlickrHelper;
import org.alfresco.repo.publishing.flickr.springsocial.api.MediaOperations;
import org.alfresco.repo.publishing.flickr.springsocial.api.PhotoInfo;
import org.alfresco.repo.publishing.flickr.springsocial.api.impl.xml.FlickrError;
import org.alfresco.repo.publishing.flickr.springsocial.api.impl.xml.FlickrPayload;
import org.alfresco.repo.publishing.flickr.springsocial.api.impl.xml.FlickrResponse;
import org.alfresco.repo.publishing.flickr.springsocial.api.impl.xml.Photo;
import org.alfresco.repo.publishing.flickr.springsocial.api.impl.xml.PhotoId;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.io.Resource;
import org.springframework.social.support.URIBuilder;
import org.springframework.util.LinkedMultiValueMap;
@@ -35,7 +35,6 @@ import org.springframework.web.client.RestTemplate;
class MediaTemplate extends AbstractFlickrOperations implements MediaOperations
{
private final static Log log = LogFactory.getLog(MediaTemplate.class);
private final RestTemplate restTemplate;
private FlickrHelper helper;
@@ -78,6 +77,7 @@ class MediaTemplate extends AbstractFlickrOperations implements MediaOperations
helper.addStandardParams(uriBuilder);
FlickrResponse response = restTemplate.postForObject(uriBuilder.build(), parts, FlickrResponse.class);
FlickrPayload payload = response.payload;
checkError(payload);
if (PhotoId.class.isAssignableFrom(payload.getClass()))
{
id = ((PhotoId)payload).id;
@@ -95,13 +95,14 @@ class MediaTemplate extends AbstractFlickrOperations implements MediaOperations
uriBuilder.queryParam("photo_id", id);
FlickrResponse response = restTemplate.getForObject(uriBuilder.build(), FlickrResponse.class);
FlickrPayload payload = response.payload;
checkError(payload);
if (Photo.class.isAssignableFrom(payload.getClass()))
{
result = (Photo)payload;
}
return result;
}
public void deletePhoto(String id)
{
requireAuthorization();
@@ -111,5 +112,15 @@ class MediaTemplate extends AbstractFlickrOperations implements MediaOperations
parts.add("photo_id", id);
FlickrResponse response = restTemplate.postForObject(helper.getRestEndpoint(), parts, FlickrResponse.class);
FlickrPayload payload = response.payload;
checkError(payload);
}
private void checkError(FlickrPayload payload) throws FlickrException
{
if (payload != null && FlickrError.class.isAssignableFrom(payload.getClass()))
{
FlickrError error = (FlickrError) payload;
throw new FlickrException(error.code, error.msg);
}
}
}

View File

@@ -0,0 +1,32 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.publishing.flickr.springsocial.api.impl.xml;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "err")
public class FlickrError implements FlickrPayload
{
@XmlAttribute
public String code;
@XmlAttribute
public String msg;
}

View File

@@ -1,3 +1,4 @@
FlickrResponse
Photo
PhotoId
FlickrError