diff --git a/config/alfresco/model/slidesharePublishingModel.xml b/config/alfresco/model/slidesharePublishingModel.xml index 95ae9d7001..cbdac0c783 100644 --- a/config/alfresco/model/slidesharePublishingModel.xml +++ b/config/alfresco/model/slidesharePublishingModel.xml @@ -38,16 +38,7 @@ SlideShare Asset Applied to a node that has been published to SlideShare - - - SlideShare Asset Id - d:text - - - SlideShare Asset URL - d:text - - + pub:AssetAspect diff --git a/config/alfresco/model/youtubePublishingModel.xml b/config/alfresco/model/youtubePublishingModel.xml index 9b2d2ff807..3aa3fce3ce 100644 --- a/config/alfresco/model/youtubePublishingModel.xml +++ b/config/alfresco/model/youtubePublishingModel.xml @@ -38,16 +38,7 @@ YouTube Asset Applied to a node that has been published to YouTube - - - YouTube Video Id - d:text - - - YouTube Player URL - d:text - - + pub:AssetAspect diff --git a/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/Flickr.java b/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/Flickr.java index f18c6521fc..02f89ba2fd 100644 --- a/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/Flickr.java +++ b/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/Flickr.java @@ -1,17 +1,20 @@ /* - * Copyright 2010 the original author or authors. + * Copyright (C) 2005-2011 Alfresco Software Limited. * - * 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 + * This file is part of Alfresco * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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. * - * 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. + * 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 . */ package org.alfresco.repo.publishing.flickr.springsocial.api; diff --git a/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/GraphApi.java b/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/GraphApi.java deleted file mode 100644 index 093d7162ed..0000000000 --- a/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/GraphApi.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright 2011 the original author or authors. - * - * 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. - */ -package org.alfresco.repo.publishing.flickr.springsocial.api; - -import org.springframework.social.facebook.api.ImageType; -import org.springframework.util.MultiValueMap; -import org.springframework.web.client.ResponseExtractor; - -/** - * Defines low-level operations against Facebook's Graph API - * @author Craig Walls - */ -public interface GraphApi { - - /** - * Fetches an object, extracting it into the type via the given {@link ResponseExtractor}. - * Requires appropriate permission to fetch the object. - * @param objectId the Facebook object's ID - * @param type the Java type to fetch - * @return an Java object representing the requested Facebook object. - */ - T fetchObject(String objectId, Class type); - - /** - * Fetches an object, extracting it into the type via the given {@link ResponseExtractor}. - * Requires appropriate permission to fetch the object. - * @param objectId the Facebook object's ID - * @param type the Java type to fetch - * @param queryParameters query parameters to include in the request - * @return an Java object representing the requested Facebook object. - */ - T fetchObject(String objectId, Class type, MultiValueMap queryParameters); - - /** - * Fetches connections, extracting them into a Java type via the given {@link ResponseExtractor}. - * Requires appropriate permission to fetch the object connection. - * @param objectId the ID of the object to retrieve the connections for. - * @param connectionType the connection type. - * @param type the Java type to fetch - * @param fields the fields to include in the response. - * @return a list of Java objects representing the Facebook objects in the connections. - */ - T fetchConnections(String objectId, String connectionType, Class type, String... fields); - - /** - * Fetches connections, extracting them into a Java type via the given {@link ResponseExtractor}. - * Requires appropriate permission to fetch the object connection. - * @param objectId the ID of the object to retrieve the connections for. - * @param connectionType the connection type. - * @param type the Java type to fetch - * @param queryParameters query parameters to include in the request - * @return a list of Java objects representing the Facebook objects in the connections. - */ - T fetchConnections(String objectId, String connectionType, Class type, MultiValueMap queryParameters); - - /** - * Fetches an image as an array of bytes. - * @param objectId the object ID - * @param connectionType the connection type - * @param imageType the type of image to retrieve (eg., small, normal, large, or square) - * @return an image as an array of bytes. - */ - byte[] fetchImage(String objectId, String connectionType, ImageType imageType); - - /** - * Publishes data to an object's connection. - * Requires appropriate permission to publish to the object connection. - * @param objectId the object ID to publish to. - * @param connectionType the connection type to publish to. - * @param data the data to publish to the connection. - * @return the ID of the newly published object. - */ - String publish(String objectId, String connectionType, MultiValueMap data); - - /** - * Publishes data to an object's connection. - * Requires appropriate permission to publish to the object connection. - * This differs from publish() only in that it doesn't attempt to extract the ID from the response. - * This is because some publish operations do not return an ID in the response. - * @param objectId the object ID to publish to. - * @param connectionType the connection type to publish to. - * @param data the data to publish to the connection. - */ - void post(String objectId, String connectionType, MultiValueMap data); - - /** - * Deletes an object. - * Requires appropriate permission to delete the object. - * @param objectId the object ID - */ - void delete(String objectId); - - /** - * Deletes an object connection. - * Requires appropriate permission to delete the object connection. - * @param objectId the object ID - * @param connectionType the connection type - */ - void delete(String objectId, String connectionType); - - static final String GRAPH_API_URL = "https://graph.facebook.com/"; - - static final String OBJECT_URL = GRAPH_API_URL + "{objectId}"; - - static final String CONNECTION_URL = OBJECT_URL + "/{connection}"; - - -} diff --git a/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/MediaOperations.java b/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/MediaOperations.java index 83d40ca884..1e3273bb60 100644 --- a/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/MediaOperations.java +++ b/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/MediaOperations.java @@ -1,42 +1,30 @@ /* - * Copyright 2011 the original author or authors. + * Copyright (C) 2005-2011 Alfresco Software Limited. * - * 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 + * This file is part of Alfresco * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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. * - * 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. + * 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 . */ package org.alfresco.repo.publishing.flickr.springsocial.api; -import org.springframework.core.io.ClassPathResource; -import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.Resource; -import org.springframework.social.ApiException; -import org.springframework.social.InsufficientPermissionException; -import org.springframework.social.MissingAuthorizationException; +public interface MediaOperations +{ -public interface MediaOperations { + PhotoMetadata createPhotoMetadata(); + + String postPhoto(Resource photo, PhotoMetadata metadata); - PhotoMetadata createPhotoMetadata(); - - /** - * Uploads a photo to an album created specifically for the application. - * Requires "publish_stream" permission. - * If no album exists for the application, it will be created. - * @param photo A {@link Resource} for the photo data. The given Resource must implement the getFilename() method (such as {@link FileSystemResource} or {@link ClassPathResource}). - * @return the ID of the photo. - * @throws ApiException if there is an error while communicating with Facebook. - * @throws InsufficientPermissionException if the user has not granted "publish_stream" permission. - * @throws MissingAuthorizationException if FacebookTemplate was not created with an access token. - */ - String postPhoto(Resource photo, PhotoMetadata metadata); - } diff --git a/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/PhotoMetadata.java b/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/PhotoMetadata.java index 593e056842..d57f0cd68c 100644 --- a/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/PhotoMetadata.java +++ b/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/PhotoMetadata.java @@ -1,3 +1,21 @@ +/* + * 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 . + */ package org.alfresco.repo.publishing.flickr.springsocial.api; public interface PhotoMetadata diff --git a/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/UserOperations.java b/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/UserOperations.java index cfb11d8c61..2ff1641688 100644 --- a/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/UserOperations.java +++ b/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/UserOperations.java @@ -1,23 +1,24 @@ /* - * Copyright 2011 the original author or authors. + * Copyright (C) 2005-2011 Alfresco Software Limited. * - * 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 + * This file is part of Alfresco * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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. * - * 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. + * 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 . */ package org.alfresco.repo.publishing.flickr.springsocial.api; +public interface UserOperations +{ - - -public interface UserOperations { - } diff --git a/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/impl/AbstractFlickrOperations.java b/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/impl/AbstractFlickrOperations.java index d6f9e7da08..0781f3b40e 100644 --- a/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/impl/AbstractFlickrOperations.java +++ b/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/impl/AbstractFlickrOperations.java @@ -1,34 +1,41 @@ /* - * Copyright 2011 the original author or authors. + * Copyright (C) 2005-2011 Alfresco Software Limited. * - * 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 + * This file is part of Alfresco * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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. * - * 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. + * 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 . */ package org.alfresco.repo.publishing.flickr.springsocial.api.impl; import org.springframework.social.MissingAuthorizationException; -class AbstractFlickrOperations { - - private final boolean isAuthorized; +class AbstractFlickrOperations +{ + + private final boolean isAuthorized; + + public AbstractFlickrOperations(boolean isAuthorized) + { + this.isAuthorized = isAuthorized; + } + + protected void requireAuthorization() + { + if (!isAuthorized) + { + throw new MissingAuthorizationException(); + } + } - public AbstractFlickrOperations(boolean isAuthorized) { - this.isAuthorized = isAuthorized; - } - - protected void requireAuthorization() { - if (!isAuthorized) { - throw new MissingAuthorizationException(); - } - } - } diff --git a/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/impl/FlickrErrorHandler.java b/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/impl/FlickrErrorHandler.java index f20a24dd28..7facadc3ba 100644 --- a/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/impl/FlickrErrorHandler.java +++ b/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/impl/FlickrErrorHandler.java @@ -1,17 +1,20 @@ /* - * Copyright 2011 the original author or authors. + * Copyright (C) 2005-2011 Alfresco Software Limited. * - * 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 + * This file is part of Alfresco * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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. * - * 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. + * 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 . */ package org.alfresco.repo.publishing.flickr.springsocial.api.impl; @@ -36,109 +39,167 @@ import org.springframework.social.facebook.api.NotAFriendException; import org.springframework.social.facebook.api.ResourceOwnershipException; import org.springframework.web.client.DefaultResponseErrorHandler; -/** - * Subclass of {@link DefaultResponseErrorHandler} that handles errors from Facebook's - * Graph API, interpreting them into appropriate exceptions. - * @author Craig Walls - */ -class FlickrErrorHandler extends DefaultResponseErrorHandler { +class FlickrErrorHandler extends DefaultResponseErrorHandler +{ - @Override - public void handleError(ClientHttpResponse response) throws IOException { - Map errorDetails = extractErrorDetailsFromResponse(response); - if (errorDetails == null) { - handleUncategorizedError(response, errorDetails); - } + @Override + public void handleError(ClientHttpResponse response) throws IOException + { + Map errorDetails = extractErrorDetailsFromResponse(response); + if (errorDetails == null) + { + handleUncategorizedError(response, errorDetails); + } - handleFacebookError(response.getStatusCode(), errorDetails); - - // if not otherwise handled, do default handling and wrap with UncategorizedApiException - handleUncategorizedError(response, errorDetails); - } - - @Override - public boolean hasError(ClientHttpResponse response) throws IOException { - BufferedReader reader = new BufferedReader(new InputStreamReader(response.getBody())); - return super.hasError(response) || (reader.ready() && reader.readLine().startsWith("{\"error\":")); - } + handleFlickrError(response.getStatusCode(), errorDetails); - /** - * Examines the error data returned from Facebook and throws the most applicable exception. - * @param errorDetails a Map containing a "type" and a "message" corresponding to the Graph API's error response structure. - */ - void handleFacebookError(HttpStatus statusCode, Map errorDetails) { - // Can't trust the type to be useful. It's often OAuthException, even for things not OAuth-related. - // Can rely only on the message (which itself isn't very consistent). - String message = errorDetails.get("message"); + // if not otherwise handled, do default handling and wrap with + // UncategorizedApiException + handleUncategorizedError(response, errorDetails); + } - if (statusCode == HttpStatus.OK) { - if (message.contains("Some of the aliases you requested do not exist")) { - throw new ResourceNotFoundException(message); - } - } else if (statusCode == HttpStatus.BAD_REQUEST) { - if (message.contains("Unknown path components")) { - throw new ResourceNotFoundException(message); - } else if (message.equals("An access token is required to request this resource.")) { - throw new MissingAuthorizationException(); - } else if (message.equals("An active access token must be used to query information about the current user.")) { - throw new MissingAuthorizationException(); - } else if (message.startsWith("Error validating access token")) { - if (message.contains("Session has expired at unix time")) { - throw new ExpiredAuthorizationException(); - } else if (message.contains("The session has been invalidated because the user has changed the password.")) { - throw new RevokedAuthorizationException(); - } else if (message.contains("The session is invalid because the user logged out.")) { - throw new RevokedAuthorizationException(); - } else if (message.contains("has not authorized application")) { - // Per https://developers.facebook.com/blog/post/500/, this could be in the message when the user removes the application. - // In reality, "The session has been invalidated because the user has changed the password." is what you get in that case. - // Leaving this check in place in case there FB does return this message (could be a bug in FB?) - throw new RevokedAuthorizationException(); - } else { - throw new InvalidAuthorizationException(message); - } - } else if (message.equals("Error validating application.")) { // Access token with incorrect app ID - throw new InvalidAuthorizationException(message); - } else if (message.equals("Invalid access token signature.")) { // Access token that fails signature validation - throw new InvalidAuthorizationException(message); - } - } else if (statusCode == HttpStatus.UNAUTHORIZED) { - throw new NotAuthorizedException(message); - } else if (statusCode == HttpStatus.FORBIDDEN) { - if (message.contains("Requires extended permission")) { - String requiredPermission = message.split(": ")[1]; - throw new InsufficientPermissionException(requiredPermission); - } else { - throw new OperationNotPermittedException(message); - } - } else if (statusCode == HttpStatus.INTERNAL_SERVER_ERROR) { - if (message.equals("User must be an owner of the friendlist")) { // watch for pattern in similar message in other resources - throw new ResourceOwnershipException(message); - } else if (message.equals("The member must be a friend of the current user.")) { - throw new NotAFriendException(message); - } else { - throw new InternalServerErrorException(message); - } - } - } + @Override + public boolean hasError(ClientHttpResponse response) throws IOException + { + BufferedReader reader = new BufferedReader(new InputStreamReader(response.getBody())); + return super.hasError(response) || (reader.ready() && reader.readLine().startsWith("{\"error\":")); + } - private void handleUncategorizedError(ClientHttpResponse response, Map errorDetails) { - try { - super.handleError(response); - } catch (Exception e) { - if (errorDetails != null) { - throw new UncategorizedApiException(errorDetails.get("message"), e); - } else { - throw new UncategorizedApiException("No error details from Facebook", e); - } - } - } + /** + * Examines the error data returned from Facebook and throws the most + * applicable exception. + * + * @param errorDetails + * a Map containing a "type" and a "message" corresponding to the + * Graph API's error response structure. + */ + void handleFlickrError(HttpStatus statusCode, Map errorDetails) + { + // Can't trust the type to be useful. It's often OAuthException, even + // for things not OAuth-related. + // Can rely only on the message (which itself isn't very consistent). + String message = errorDetails.get("message"); - /* - * Attempts to extract Facebook error details from the response. - * Returns null if the response doesn't match the expected JSON error response. - */ - private Map extractErrorDetailsFromResponse(ClientHttpResponse response) throws IOException { - return null; - } + if (statusCode == HttpStatus.OK) + { + if (message.contains("Some of the aliases you requested do not exist")) + { + throw new ResourceNotFoundException(message); + } + } + else if (statusCode == HttpStatus.BAD_REQUEST) + { + if (message.contains("Unknown path components")) + { + throw new ResourceNotFoundException(message); + } + else if (message.equals("An access token is required to request this resource.")) + { + throw new MissingAuthorizationException(); + } + else if (message.equals("An active access token must be used to query information about the current user.")) + { + throw new MissingAuthorizationException(); + } + else if (message.startsWith("Error validating access token")) + { + if (message.contains("Session has expired at unix time")) + { + throw new ExpiredAuthorizationException(); + } + else if (message + .contains("The session has been invalidated because the user has changed the password.")) + { + throw new RevokedAuthorizationException(); + } + else if (message.contains("The session is invalid because the user logged out.")) + { + throw new RevokedAuthorizationException(); + } + else if (message.contains("has not authorized application")) + { + // Per https://developers.facebook.com/blog/post/500/, this + // could be in the message when the user removes the + // application. + // In reality, + // "The session has been invalidated because the user has changed the password." + // is what you get in that case. + // Leaving this check in place in case there FB does return + // this message (could be a bug in FB?) + throw new RevokedAuthorizationException(); + } + else + { + throw new InvalidAuthorizationException(message); + } + } + else if (message.equals("Error validating application.")) + { // Access token with incorrect app ID + throw new InvalidAuthorizationException(message); + } + else if (message.equals("Invalid access token signature.")) + { // Access token that fails signature validation + throw new InvalidAuthorizationException(message); + } + } + else if (statusCode == HttpStatus.UNAUTHORIZED) + { + throw new NotAuthorizedException(message); + } + else if (statusCode == HttpStatus.FORBIDDEN) + { + if (message.contains("Requires extended permission")) + { + String requiredPermission = message.split(": ")[1]; + throw new InsufficientPermissionException(requiredPermission); + } + else + { + throw new OperationNotPermittedException(message); + } + } + else if (statusCode == HttpStatus.INTERNAL_SERVER_ERROR) + { + if (message.equals("User must be an owner of the friendlist")) + { // watch for pattern in similar message in other resources + throw new ResourceOwnershipException(message); + } + else if (message.equals("The member must be a friend of the current user.")) + { + throw new NotAFriendException(message); + } + else + { + throw new InternalServerErrorException(message); + } + } + } + + private void handleUncategorizedError(ClientHttpResponse response, Map errorDetails) + { + try + { + super.handleError(response); + } + catch (Exception e) + { + if (errorDetails != null) + { + throw new UncategorizedApiException(errorDetails.get("message"), e); + } + else + { + throw new UncategorizedApiException("No error details from Facebook", e); + } + } + } + + /* + * Attempts to extract Facebook error details from the response. Returns + * null if the response doesn't match the expected JSON error response. + */ + private Map extractErrorDetailsFromResponse(ClientHttpResponse response) throws IOException + { + return null; + } } diff --git a/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/impl/FlickrTemplate.java b/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/impl/FlickrTemplate.java index 5bb53cf314..65500db573 100644 --- a/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/impl/FlickrTemplate.java +++ b/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/impl/FlickrTemplate.java @@ -1,17 +1,20 @@ /* - * Copyright 2010 the original author or authors. + * Copyright (C) 2005-2011 Alfresco Software Limited. * - * 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 + * This file is part of Alfresco * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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. * - * 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. + * 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 . */ package org.alfresco.repo.publishing.flickr.springsocial.api.impl; @@ -31,7 +34,9 @@ import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; /** - *

This is the central class for interacting with Facebook.

+ *

+ * This is the central class for interacting with Facebook. + *

*

* There are some operations, such as searching, that do not require OAuth * authentication. In those cases, you may use a {@link FlickrTemplate} that is @@ -39,65 +44,81 @@ import org.springframework.util.MultiValueMap; * Attempts to perform secured operations through such an instance, however, * will result in {@link NotAuthorizedException} being thrown. *

+ * * @author Craig Walls */ -public class FlickrTemplate extends AbstractOAuth1ApiBinding implements Flickr { +public class FlickrTemplate extends AbstractOAuth1ApiBinding implements Flickr +{ private final String REST_ENDPOINT = "http://api.flickr.com/services/rest/"; private String consumerKey; - - private MediaOperations mediaOperations; - /** - * Create a new instance of FacebookTemplate. - * This constructor creates a new FacebookTemplate able to perform unauthenticated operations against Facebook's Graph API. - * Some operations do not require OAuth authentication. - * For example, retrieving a specified user's profile or feed does not require authentication (although the data returned will be limited to what is publicly available). - * A FacebookTemplate created with this constructor will support those operations. - * Those operations requiring authentication will throw {@link NotAuthorizedException}. - */ - public FlickrTemplate() { - initialize(); - } + private MediaOperations mediaOperations; - /** - * Create a new instance of FacebookTemplate. - * This constructor creates the FacebookTemplate using a given access token. - * @param accessToken An access token given by Facebook after a successful OAuth 2 authentication (or through Facebook's JS library). - */ - public FlickrTemplate(String consumerKey, String consumerSecret, String accessToken, String accessTokenSecret) { - super(consumerKey, consumerSecret, accessToken, accessTokenSecret); - this.consumerKey = consumerKey; - initialize(); - } + /** + * Create a new instance of FacebookTemplate. This constructor creates a new + * FacebookTemplate able to perform unauthenticated operations against + * Facebook's Graph API. Some operations do not require OAuth + * authentication. For example, retrieving a specified user's profile or + * feed does not require authentication (although the data returned will be + * limited to what is publicly available). A FacebookTemplate created with + * this constructor will support those operations. Those operations + * requiring authentication will throw {@link NotAuthorizedException}. + */ + public FlickrTemplate() + { + initialize(); + } - private void initSubApis() { - mediaOperations = new MediaTemplate(consumerKey, getRestTemplate(), isAuthorized()); - } - - @Override - public void setRequestFactory(ClientHttpRequestFactory requestFactory) { - // Wrap the request factory with a BufferingClientHttpRequestFactory so that the error handler can do repeat reads on the response.getBody() - super.setRequestFactory(ClientHttpRequestFactorySelector.bufferRequests(requestFactory)); - } + /** + * Create a new instance of FacebookTemplate. This constructor creates the + * FacebookTemplate using a given access token. + * + * @param accessToken + * An access token given by Facebook after a successful OAuth 2 + * authentication (or through Facebook's JS library). + */ + public FlickrTemplate(String consumerKey, String consumerSecret, String accessToken, String accessTokenSecret) + { + super(consumerKey, consumerSecret, accessToken, accessTokenSecret); + this.consumerKey = consumerKey; + initialize(); + } - public MediaOperations mediaOperations() { - return mediaOperations; - } - - @Override - protected List> getMessageConverters() { - List> messageConverters = super.getMessageConverters(); - messageConverters.add(new ByteArrayHttpMessageConverter()); - return messageConverters; - } - - // private helpers - private void initialize() { - getRestTemplate().setErrorHandler(new FlickrErrorHandler()); - // Wrap the request factory with a BufferingClientHttpRequestFactory so that the error handler can do repeat reads on the response.getBody() - super.setRequestFactory(ClientHttpRequestFactorySelector.bufferRequests(getRestTemplate().getRequestFactory())); - initSubApis(); - } + private void initSubApis() + { + mediaOperations = new MediaTemplate(consumerKey, getRestTemplate(), isAuthorized()); + } + + @Override + public void setRequestFactory(ClientHttpRequestFactory requestFactory) + { + // Wrap the request factory with a BufferingClientHttpRequestFactory so + // that the error handler can do repeat reads on the response.getBody() + super.setRequestFactory(ClientHttpRequestFactorySelector.bufferRequests(requestFactory)); + } + + public MediaOperations mediaOperations() + { + return mediaOperations; + } + + @Override + protected List> getMessageConverters() + { + List> messageConverters = super.getMessageConverters(); + messageConverters.add(new ByteArrayHttpMessageConverter()); + return messageConverters; + } + + // private helpers + private void initialize() + { + getRestTemplate().setErrorHandler(new FlickrErrorHandler()); + // Wrap the request factory with a BufferingClientHttpRequestFactory so + // that the error handler can do repeat reads on the response.getBody() + super.setRequestFactory(ClientHttpRequestFactorySelector.bufferRequests(getRestTemplate().getRequestFactory())); + initSubApis(); + } @Override public boolean test() diff --git a/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/impl/MediaTemplate.java b/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/impl/MediaTemplate.java index 238fdfaf26..19ed0c0c95 100644 --- a/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/impl/MediaTemplate.java +++ b/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/impl/MediaTemplate.java @@ -1,17 +1,20 @@ /* - * Copyright 2011 the original author or authors. + * Copyright (C) 2005-2011 Alfresco Software Limited. * - * 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 + * This file is part of Alfresco * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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. * - * 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. + * 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 . */ package org.alfresco.repo.publishing.flickr.springsocial.api.impl; diff --git a/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/impl/PhotoMetadataImpl.java b/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/impl/PhotoMetadataImpl.java index bbbffc21d1..61ad04d708 100644 --- a/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/impl/PhotoMetadataImpl.java +++ b/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/impl/PhotoMetadataImpl.java @@ -1,3 +1,21 @@ +/* + * 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 . + */ package org.alfresco.repo.publishing.flickr.springsocial.api.impl; import org.alfresco.repo.publishing.flickr.springsocial.api.PhotoMetadata; diff --git a/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/impl/UserTemplate.java b/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/impl/UserTemplate.java index 5c27899844..7f797d6611 100644 --- a/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/impl/UserTemplate.java +++ b/source/java/org/alfresco/repo/publishing/flickr/springsocial/api/impl/UserTemplate.java @@ -1,23 +1,27 @@ /* - * Copyright 2011 the original author or authors. + * Copyright (C) 2005-2011 Alfresco Software Limited. * - * 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 + * This file is part of Alfresco * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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. * - * 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. + * 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 . */ package org.alfresco.repo.publishing.flickr.springsocial.api.impl; import org.alfresco.repo.publishing.flickr.springsocial.api.UserOperations; -class UserTemplate extends AbstractFlickrOperations implements UserOperations { +class UserTemplate extends AbstractFlickrOperations implements UserOperations +{ public UserTemplate(boolean isAuthorized) { diff --git a/source/java/org/alfresco/repo/publishing/flickr/springsocial/connect/FlickrAdapter.java b/source/java/org/alfresco/repo/publishing/flickr/springsocial/connect/FlickrAdapter.java index 21068b2e6a..593eb7e071 100644 --- a/source/java/org/alfresco/repo/publishing/flickr/springsocial/connect/FlickrAdapter.java +++ b/source/java/org/alfresco/repo/publishing/flickr/springsocial/connect/FlickrAdapter.java @@ -1,17 +1,20 @@ /* - * Copyright 2011 the original author or authors. + * Copyright (C) 2005-2011 Alfresco Software Limited. * - * 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 + * This file is part of Alfresco * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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. * - * 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. + * 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 . */ package org.alfresco.repo.publishing.flickr.springsocial.connect; @@ -22,11 +25,6 @@ import org.springframework.social.connect.ConnectionValues; import org.springframework.social.connect.UserProfile; import org.springframework.social.connect.UserProfileBuilder; -/** - * Facebook ApiAdapter implementation. - * - * @author Keith Donald - */ public class FlickrAdapter implements ApiAdapter { diff --git a/source/java/org/alfresco/repo/publishing/flickr/springsocial/connect/FlickrConnectionFactory.java b/source/java/org/alfresco/repo/publishing/flickr/springsocial/connect/FlickrConnectionFactory.java index 973dceaeae..7a07ed6f1c 100644 --- a/source/java/org/alfresco/repo/publishing/flickr/springsocial/connect/FlickrConnectionFactory.java +++ b/source/java/org/alfresco/repo/publishing/flickr/springsocial/connect/FlickrConnectionFactory.java @@ -1,17 +1,20 @@ /* - * Copyright 2011 the original author or authors. + * Copyright (C) 2005-2011 Alfresco Software Limited. * - * 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 + * This file is part of Alfresco * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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. * - * 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. + * 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 . */ package org.alfresco.repo.publishing.flickr.springsocial.connect; @@ -19,10 +22,12 @@ import org.alfresco.repo.publishing.flickr.springsocial.api.Flickr; import org.alfresco.repo.publishing.flickr.springsocial.connect.FlickrAdapter; import org.springframework.social.connect.support.OAuth1ConnectionFactory; -public class FlickrConnectionFactory extends OAuth1ConnectionFactory { +public class FlickrConnectionFactory extends OAuth1ConnectionFactory +{ - public FlickrConnectionFactory(String consumerKey, String consumerSecret) { - super("flickr", new FlickrServiceProvider(consumerKey, consumerSecret), new FlickrAdapter()); - } + public FlickrConnectionFactory(String consumerKey, String consumerSecret) + { + super("flickr", new FlickrServiceProvider(consumerKey, consumerSecret), new FlickrAdapter()); + } } diff --git a/source/java/org/alfresco/repo/publishing/flickr/springsocial/connect/FlickrServiceProvider.java b/source/java/org/alfresco/repo/publishing/flickr/springsocial/connect/FlickrServiceProvider.java index 394eea4aca..258e562f4b 100644 --- a/source/java/org/alfresco/repo/publishing/flickr/springsocial/connect/FlickrServiceProvider.java +++ b/source/java/org/alfresco/repo/publishing/flickr/springsocial/connect/FlickrServiceProvider.java @@ -1,17 +1,20 @@ /* - * Copyright 2010 the original author or authors. + * Copyright (C) 2005-2011 Alfresco Software Limited. * - * 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 + * This file is part of Alfresco * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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. * - * 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. + * 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 . */ package org.alfresco.repo.publishing.flickr.springsocial.connect; @@ -20,17 +23,19 @@ import org.alfresco.repo.publishing.flickr.springsocial.api.impl.FlickrTemplate; import org.springframework.social.oauth1.AbstractOAuth1ServiceProvider; import org.springframework.social.oauth1.OAuth1Template; -public class FlickrServiceProvider extends AbstractOAuth1ServiceProvider { +public class FlickrServiceProvider extends AbstractOAuth1ServiceProvider +{ - public FlickrServiceProvider(String consumerKey, String consumerSecret) { + public FlickrServiceProvider(String consumerKey, String consumerSecret) + { super(consumerKey, consumerSecret, new OAuth1Template(consumerKey, consumerSecret, - "http://www.flickr.com/services/oauth/request_token", - "http://www.flickr.com/services/oauth/authorize", + "http://www.flickr.com/services/oauth/request_token", "http://www.flickr.com/services/oauth/authorize", "http://www.flickr.com/services/oauth/access_token")); - } + } + + public Flickr getApi(String accessToken, String secret) + { + return new FlickrTemplate(getConsumerKey(), getConsumerSecret(), accessToken, secret); + } - public Flickr getApi(String accessToken, String secret) { - return new FlickrTemplate(getConsumerKey(), getConsumerSecret(), accessToken, secret); - } - } \ No newline at end of file diff --git a/source/java/org/alfresco/repo/publishing/slideshare/SlideShareChannelType.java b/source/java/org/alfresco/repo/publishing/slideshare/SlideShareChannelType.java index cc5bdb0669..a5bfecc434 100644 --- a/source/java/org/alfresco/repo/publishing/slideshare/SlideShareChannelType.java +++ b/source/java/org/alfresco/repo/publishing/slideshare/SlideShareChannelType.java @@ -24,6 +24,7 @@ import java.util.Map; import java.util.Set; import org.alfresco.repo.publishing.AbstractChannelType; +import org.alfresco.repo.publishing.PublishingModel; import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ActionService; import org.alfresco.service.cmr.publishing.channels.Channel; @@ -121,7 +122,7 @@ public class SlideShareChannelType extends AbstractChannelType String url = null; if (node != null && nodeService.exists(node) && nodeService.hasAspect(node, SlideSharePublishingModel.ASPECT_ASSET)) { - url = (String)nodeService.getProperty(node, SlideSharePublishingModel.PROP_ASSET_URL); + url = (String)nodeService.getProperty(node, PublishingModel.PROP_ASSET_URL); } return url; } diff --git a/source/java/org/alfresco/repo/publishing/slideshare/SlideSharePublishAction.java b/source/java/org/alfresco/repo/publishing/slideshare/SlideSharePublishAction.java index 6aec28dfdc..2524d1e45b 100644 --- a/source/java/org/alfresco/repo/publishing/slideshare/SlideSharePublishAction.java +++ b/source/java/org/alfresco/repo/publishing/slideshare/SlideSharePublishAction.java @@ -24,6 +24,7 @@ import java.util.List; import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.model.ContentModel; import org.alfresco.repo.action.executer.ActionExecuterAbstractBase; +import org.alfresco.repo.publishing.PublishingModel; import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ParameterDefinition; import org.alfresco.service.cmr.repository.ContentReader; @@ -135,8 +136,9 @@ public class SlideSharePublishAction extends ActionExecuterAbstractBase { log.info("File " + name + " has been published to SlideShare with id " + assetId + " at URL " + url); } - nodeService.setProperty(nodeRef, SlideSharePublishingModel.PROP_ASSET_ID, assetId); - nodeService.setProperty(nodeRef, SlideSharePublishingModel.PROP_ASSET_URL, url); + nodeService.addAspect(nodeRef, SlideSharePublishingModel.ASPECT_ASSET, null); + nodeService.setProperty(nodeRef, PublishingModel.PROP_ASSET_ID, assetId); + nodeService.setProperty(nodeRef, PublishingModel.PROP_ASSET_URL, url); if (deleteContentFileOnCompletion) { diff --git a/source/java/org/alfresco/repo/publishing/slideshare/SlideSharePublishingModel.java b/source/java/org/alfresco/repo/publishing/slideshare/SlideSharePublishingModel.java index 3705493ef7..2260023afa 100644 --- a/source/java/org/alfresco/repo/publishing/slideshare/SlideSharePublishingModel.java +++ b/source/java/org/alfresco/repo/publishing/slideshare/SlideSharePublishingModel.java @@ -35,6 +35,4 @@ public interface SlideSharePublishingModel public static final QName ASPECT_DELIVERY_CHANNEL = QName.createQName(NAMESPACE, "DeliveryChannelAspect"); public static final QName ASPECT_ASSET = QName.createQName(NAMESPACE, "AssetAspect"); - public static final QName PROP_ASSET_ID = QName.createQName(NAMESPACE, "assetId"); - public static final QName PROP_ASSET_URL = QName.createQName(NAMESPACE, "assetUrl"); } diff --git a/source/java/org/alfresco/repo/publishing/slideshare/SlideShareTest.java b/source/java/org/alfresco/repo/publishing/slideshare/SlideShareTest.java index de0e86b7f9..e878a2bccb 100644 --- a/source/java/org/alfresco/repo/publishing/slideshare/SlideShareTest.java +++ b/source/java/org/alfresco/repo/publishing/slideshare/SlideShareTest.java @@ -134,10 +134,10 @@ public class SlideShareTest extends BaseSpringTest actionService.executeAction(publishAction, node); Map props = nodeService.getProperties(node); Assert.assertTrue(nodeService.hasAspect(node, SlideSharePublishingModel.ASPECT_ASSET)); - Assert.assertNotNull(props.get(SlideSharePublishingModel.PROP_ASSET_ID)); + Assert.assertNotNull(props.get(PublishingModel.PROP_ASSET_ID)); // Assert.assertNotNull(props.get(SlideSharePublishingModel.PROP_ASSET_URL)); - System.out.println("SlideShare id: " + props.get(SlideSharePublishingModel.PROP_ASSET_ID)); + System.out.println("SlideShare id: " + props.get(PublishingModel.PROP_ASSET_ID)); // Action unpublishAction = actionService.createAction(SlideShareUnpublishAction.NAME); // actionService.executeAction(unpublishAction, node); diff --git a/source/java/org/alfresco/repo/publishing/youtube/YouTubeChannelType.java b/source/java/org/alfresco/repo/publishing/youtube/YouTubeChannelType.java index 615fc2a9c3..71eebc1c8a 100644 --- a/source/java/org/alfresco/repo/publishing/youtube/YouTubeChannelType.java +++ b/source/java/org/alfresco/repo/publishing/youtube/YouTubeChannelType.java @@ -24,6 +24,7 @@ import java.util.Map; import java.util.Set; import org.alfresco.repo.publishing.AbstractChannelType; +import org.alfresco.repo.publishing.PublishingModel; import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ActionService; import org.alfresco.service.cmr.publishing.channels.Channel; @@ -113,9 +114,9 @@ public class YouTubeChannelType extends AbstractChannelType public String getNodeUrl(NodeRef node) { String url = null; - if (node != null && nodeService.exists(node) && nodeService.hasAspect(node, YouTubePublishingModel.ASPECT_ASSET)) + if (node != null && nodeService.exists(node) && nodeService.hasAspect(node, PublishingModel.ASPECT_ASSET)) { - url = (String)nodeService.getProperty(node, YouTubePublishingModel.PROP_PLAYER_URL); + url = (String)nodeService.getProperty(node, PublishingModel.PROP_ASSET_URL); } return url; } diff --git a/source/java/org/alfresco/repo/publishing/youtube/YouTubePublishAction.java b/source/java/org/alfresco/repo/publishing/youtube/YouTubePublishAction.java index fcbc57e663..c8593be0f0 100644 --- a/source/java/org/alfresco/repo/publishing/youtube/YouTubePublishAction.java +++ b/source/java/org/alfresco/repo/publishing/youtube/YouTubePublishAction.java @@ -27,6 +27,7 @@ import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.model.ContentModel; import org.alfresco.repo.action.executer.ActionExecuterAbstractBase; import org.alfresco.repo.content.filestore.FileContentReader; +import org.alfresco.repo.publishing.PublishingModel; import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ParameterDefinition; import org.alfresco.service.cmr.repository.ContentReader; @@ -183,8 +184,9 @@ public class YouTubePublishAction extends ActionExecuterAbstractBase log.debug("YouTube content URL is " + contentUrl); log.debug("YouTube video player URL is " + playerUrl); } - nodeService.setProperty(nodeRef, YouTubePublishingModel.PROP_ASSET_ID, videoId); - nodeService.setProperty(nodeRef, YouTubePublishingModel.PROP_PLAYER_URL, playerUrl); + nodeService.addAspect(nodeRef, YouTubePublishingModel.ASPECT_ASSET, null); + nodeService.setProperty(nodeRef, PublishingModel.PROP_ASSET_ID, videoId); + nodeService.setProperty(nodeRef, PublishingModel.PROP_ASSET_URL, playerUrl); break; case CLIENT_ERROR: log.error("Video content failed to upload: " + videoName); diff --git a/source/java/org/alfresco/repo/publishing/youtube/YouTubePublishingModel.java b/source/java/org/alfresco/repo/publishing/youtube/YouTubePublishingModel.java index 8fc0f64438..783b880c65 100644 --- a/source/java/org/alfresco/repo/publishing/youtube/YouTubePublishingModel.java +++ b/source/java/org/alfresco/repo/publishing/youtube/YouTubePublishingModel.java @@ -35,6 +35,4 @@ public interface YouTubePublishingModel public static final QName ASPECT_DELIVERY_CHANNEL = QName.createQName(NAMESPACE, "DeliveryChannelAspect"); public static final QName ASPECT_ASSET = QName.createQName(NAMESPACE, "AssetAspect"); - public static final QName PROP_ASSET_ID = QName.createQName(NAMESPACE, "assetId"); - public static final QName PROP_PLAYER_URL = QName.createQName(NAMESPACE, "playerUrl"); } diff --git a/source/java/org/alfresco/repo/publishing/youtube/YouTubeTest.java b/source/java/org/alfresco/repo/publishing/youtube/YouTubeTest.java index c4d370660a..597e9c1f17 100644 --- a/source/java/org/alfresco/repo/publishing/youtube/YouTubeTest.java +++ b/source/java/org/alfresco/repo/publishing/youtube/YouTubeTest.java @@ -47,13 +47,8 @@ import org.alfresco.service.namespace.QName; import org.alfresco.util.BaseSpringTest; import org.alfresco.util.GUID; import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Brian @@ -90,6 +85,11 @@ public class YouTubeTest extends BaseSpringTest docLib = siteService.createContainer(siteId, SiteService.DOCUMENT_LIBRARY, ContentModel.TYPE_FOLDER, null); } + public void onTearDown() + { + siteService.deleteSite(siteId); + } + public void testBlank() { @@ -133,17 +133,17 @@ public class YouTubeTest extends BaseSpringTest actionService.executeAction(publishAction, vidNode); Map props = nodeService.getProperties(vidNode); Assert.assertTrue(nodeService.hasAspect(vidNode, YouTubePublishingModel.ASPECT_ASSET)); - Assert.assertNotNull(props.get(YouTubePublishingModel.PROP_ASSET_ID)); - Assert.assertNotNull(props.get(YouTubePublishingModel.PROP_PLAYER_URL)); + Assert.assertNotNull(props.get(PublishingModel.PROP_ASSET_ID)); + Assert.assertNotNull(props.get(PublishingModel.PROP_ASSET_URL)); - System.out.println("YouTube video: " + props.get(YouTubePublishingModel.PROP_ASSET_ID)); + System.out.println("YouTube video: " + props.get(PublishingModel.PROP_ASSET_ID)); Action unpublishAction = actionService.createAction(YouTubeUnpublishAction.NAME); actionService.executeAction(unpublishAction, vidNode); props = nodeService.getProperties(vidNode); Assert.assertFalse(nodeService.hasAspect(vidNode, YouTubePublishingModel.ASPECT_ASSET)); - Assert.assertNull(props.get(YouTubePublishingModel.PROP_ASSET_ID)); - Assert.assertNull(props.get(YouTubePublishingModel.PROP_PLAYER_URL)); + Assert.assertNull(props.get(PublishingModel.PROP_ASSET_ID)); + Assert.assertNull(props.get(PublishingModel.PROP_ASSET_URL)); return null; } }); diff --git a/source/java/org/alfresco/repo/publishing/youtube/YouTubeUnpublishAction.java b/source/java/org/alfresco/repo/publishing/youtube/YouTubeUnpublishAction.java index 18a82e9d9e..f7f5b51a8c 100644 --- a/source/java/org/alfresco/repo/publishing/youtube/YouTubeUnpublishAction.java +++ b/source/java/org/alfresco/repo/publishing/youtube/YouTubeUnpublishAction.java @@ -25,6 +25,7 @@ import java.util.List; import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.repo.action.executer.ActionExecuterAbstractBase; +import org.alfresco.repo.publishing.PublishingModel; import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ParameterDefinition; import org.alfresco.service.cmr.repository.NodeRef; @@ -64,7 +65,7 @@ public class YouTubeUnpublishAction extends ActionExecuterAbstractBase { removeVideo(service, actionedUponNodeRef); } - catch(Exception ex) + catch (Exception ex) { log.error("Failed to remove asset from YouTube", ex); throw new AlfrescoRuntimeException("exception.publishing.youtube.unpublishFailed", ex); @@ -72,15 +73,19 @@ public class YouTubeUnpublishAction extends ActionExecuterAbstractBase } } - private void removeVideo(YouTubeService service, NodeRef nodeRef) throws MalformedURLException, IOException, ServiceException + private void removeVideo(YouTubeService service, NodeRef nodeRef) throws MalformedURLException, IOException, + ServiceException { - String youtubeId = (String) nodeService.getProperty(nodeRef, YouTubePublishingModel.PROP_ASSET_ID); - if (youtubeId != null) + if (nodeService.hasAspect(nodeRef, YouTubePublishingModel.ASPECT_ASSET)) { - String videoEntryUrl = "https://gdata.youtube.com/feeds/api/users/default/uploads/" + youtubeId; - VideoEntry videoEntry = service.getEntry(new URL(videoEntryUrl), VideoEntry.class); - videoEntry.delete(); - nodeService.removeAspect(nodeRef, YouTubePublishingModel.ASPECT_ASSET); + String youtubeId = (String) nodeService.getProperty(nodeRef, PublishingModel.PROP_ASSET_ID); + if (youtubeId != null) + { + String videoEntryUrl = "https://gdata.youtube.com/feeds/api/users/default/uploads/" + youtubeId; + VideoEntry videoEntry = service.getEntry(new URL(videoEntryUrl), VideoEntry.class); + videoEntry.delete(); + nodeService.removeAspect(nodeRef, YouTubePublishingModel.ASPECT_ASSET); + } } }