From 3341746b5859f00e2216c589a9363e7acd651c8c Mon Sep 17 00:00:00 2001 From: Chris Tavares Date: Tue, 14 Aug 2012 22:54:27 -0700 Subject: [PATCH 1/9] Starting to sketch out contract --- .../services/media/MediaServicesContract.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesContract.java diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesContract.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesContract.java new file mode 100644 index 0000000000000..9ebd7901d3504 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesContract.java @@ -0,0 +1,48 @@ +/** + * Copyright 2011 Microsoft Corporation + * + * 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 com.microsoft.windowsazure.services.serviceBus; + +import com.microsoft.windowsazure.services.core.FilterableService; +import com.microsoft.windowsazure.services.core.ServiceException; + +/** + * + * Defines the Media contract. + * + */ +public interface MediaServicesContract extends FilterableService { + /** + * The set of operations to support. Will uncomment as they get added + * + * CreateAssetResult createAsset(String name) throws ServiceException; + * + * CreateAccessPolicyResult createAccessPolicy(String name, + * int durationInMinutes, + * AccessPolicyPermissions permissions) + * throws ServiceException; + * + * CreateLocatorResult createLocator(AssetId asset, + * AccessPolicyId accessPolicy, + * DateTime startTime, + * LocatorType type) + * throws ServiceException; + * + * Add overload that defaults locatorType to SAS, and defaults startTime to now - 5 minutes. + * + * We need to upload blobs from here - do we go through blobservice, or do we just do it + * directly? I'm leaning towards direct - blob container is encoded in locator. + * + */ +} From 00aa5b6366f4f0b00f0ea6b290763b84a7341279 Mon Sep 17 00:00:00 2001 From: Chris Tavares Date: Wed, 15 Aug 2012 12:05:01 -0700 Subject: [PATCH 2/9] Working on contract --- .../services/media/MediaServicesContract.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesContract.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesContract.java index 9ebd7901d3504..19f598d9a67c9 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesContract.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesContract.java @@ -24,7 +24,7 @@ */ public interface MediaServicesContract extends FilterableService { /** - * The set of operations to support. Will uncomment as they get added + * // The set of operations to support. Will uncomment as they get added * * CreateAssetResult createAsset(String name) throws ServiceException; * @@ -39,10 +39,23 @@ public interface MediaServicesContract extends FilterableService Date: Thu, 16 Aug 2012 22:39:20 -0700 Subject: [PATCH 3/9] Building out contract, including model classes --- .../services/media/MediaServicesContract.java | 31 +++++++++-- .../services/media/models/AssetInfo.java | 45 ++++++++++++++++ .../media/models/CreateAssetResult.java | 54 +++++++++++++++++++ 3 files changed, 127 insertions(+), 3 deletions(-) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAssetResult.java diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesContract.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesContract.java index 19f598d9a67c9..992194ba908ef 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesContract.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesContract.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.microsoft.windowsazure.services.serviceBus; +package com.microsoft.windowsazure.services.media; import com.microsoft.windowsazure.services.core.FilterableService; import com.microsoft.windowsazure.services.core.ServiceException; @@ -23,11 +23,36 @@ * */ public interface MediaServicesContract extends FilterableService { + + /** + * Creates a new media service asset + * + * @param name + * A String specifying the name of the asset to create. + * + * @return A CreateAssetResult object that represents the result. + * + * @exception ServiceException + * If a service exception is encountered. + * + */ + CreateAssetResult createAsset(String name) throws ServiceException; + + /** + * Deletes a media service asset + * + * @param asset + * A AssetInfo object specifying the asset to delete. + * + * @exception ServiceException + * If a service exception is encountered. + * + */ + void deleteAsset(AssetInfo asset) throws ServiceException; + /** * // The set of operations to support. Will uncomment as they get added * - * CreateAssetResult createAsset(String name) throws ServiceException; - * * CreateAccessPolicyResult createAccessPolicy(String name, * int durationInMinutes, * AccessPolicyPermissions permissions) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java new file mode 100644 index 0000000000000..800f7bf14674e --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java @@ -0,0 +1,45 @@ +/** + * Copyright 2011 Microsoft Corporation + * + * 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 com.microsoft.windowsazure.services.media.models; + +/** + * Represents an asset + */ +public class AssetInfo { + // TODO: Turn this into a serializable class, EntryModel thing + private String id; + + /** + * Create a new AssetInfo for the given Asset Id. + */ + public AssetInfo(String id) { + this.id = id; + } + + /** + * Retrieve the id + */ + public String getId() { + return id; + } + + /** + * Set the id. Do we really need this? + */ + public AssetInfo setId(String newId) { + id = newId; + return this; + } +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAssetResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAssetResult.java new file mode 100644 index 0000000000000..0867c5af7b10d --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAssetResult.java @@ -0,0 +1,54 @@ +/** + * Copyright 2011 Microsoft Corporation + * + * 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 com.microsoft.windowsazure.services.media.models; + +/** + * Represents the result of a createAsset operation. + */ +public class GetAssetResult { + private AssetInfo value; + + /** + * Creates an instance of the GetAssetResult class. + * + * @param value + * A {@link AssetInfo} object assigned as the value of the + * result. + */ + public GetAssetResult(AssetInfo value) { + this.setValue(value); + } + + /** + * Specfies the value of the result. + * + * @param value + * A {@link AssetInfo} object assigned as the value of the + * result. + */ + public AssetInfo getValue() { + return value; + } + + /** + * Returns the value of the result. + * + * @return A {@link AssetInfo} object that represents the value of the + * result. + */ + public void setValue(AssetInfo newValue) { + value = newValue; + } +} From de259da20dfaea53fd716c5eea91f9583936f243 Mon Sep 17 00:00:00 2001 From: Chris Tavares Date: Fri, 17 Aug 2012 11:28:38 -0700 Subject: [PATCH 4/9] Building out access policy contract --- .gitignore | 2 + .../services/media/MediaServicesContract.java | 141 ++++++++++-------- .../media/models/AccessPolicyInfo.java | 37 +++++ .../media/models/AccessPolicyPermission.java | 12 ++ .../models/CreateAccessPolicyResult.java | 55 +++++++ .../media/models/CreateAssetResult.java | 40 ++--- 6 files changed, 201 insertions(+), 86 deletions(-) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfo.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyPermission.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAccessPolicyResult.java diff --git a/.gitignore b/.gitignore index 11a721777fdd7..940d90fcccc71 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ .project target node_modules +.settings + diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesContract.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesContract.java index 992194ba908ef..35c702de42e09 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesContract.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesContract.java @@ -2,85 +2,94 @@ * Copyright 2011 Microsoft Corporation * * 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 + * 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. + * 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 com.microsoft.windowsazure.services.media; +import java.util.EnumSet; + import com.microsoft.windowsazure.services.core.FilterableService; import com.microsoft.windowsazure.services.core.ServiceException; +import com.microsoft.windowsazure.services.media.models.AccessPolicyPermission; +import com.microsoft.windowsazure.services.media.models.AssetInfo; +import com.microsoft.windowsazure.services.media.models.CreateAccessPolicyResult; +import com.microsoft.windowsazure.services.media.models.CreateAssetResult; /** * - * Defines the Media contract. + * Defines the Media contract. * */ public interface MediaServicesContract extends FilterableService { - /** - * Creates a new media service asset - * - * @param name - * A String specifying the name of the asset to create. - * - * @return A CreateAssetResult object that represents the result. - * - * @exception ServiceException - * If a service exception is encountered. - * - */ - CreateAssetResult createAsset(String name) throws ServiceException; + /** + * Creates a new media service asset + * + * @param name + * A String specifying the name of the asset to create. + * + * @return A CreateAssetResult object that represents the result. + * + * @exception ServiceException + * If a service exception is encountered. + * + */ + CreateAssetResult createAsset(String name) throws ServiceException; + + /** + * Deletes a media service asset + * + * @param asset + * A AssetInfo object specifying the asset to delete. + * + * @exception ServiceException + * If a service exception is encountered. + * + */ + void deleteAsset(AssetInfo asset) throws ServiceException; - /** - * Deletes a media service asset - * - * @param asset - * A AssetInfo object specifying the asset to delete. - * - * @exception ServiceException - * If a service exception is encountered. - * - */ - void deleteAsset(AssetInfo asset) throws ServiceException; + CreateAccessPolicyResult createAccessPolicy(String name, int durationInMinutes, + EnumSet permissions) throws ServiceException; - /** - * // The set of operations to support. Will uncomment as they get added - * - * CreateAccessPolicyResult createAccessPolicy(String name, - * int durationInMinutes, - * AccessPolicyPermissions permissions) - * throws ServiceException; - * - * CreateLocatorResult createLocator(AssetId asset, - * AccessPolicyId accessPolicy, - * DateTime startTime, - * LocatorType type) - * throws ServiceException; - * - * // Add overload that defaults locatorType to SAS, and defaults startTime to now - 5 minutes. - * - * // We need to upload blobs from here - do we go through blobservice, or do we just do it - * // directly? I'm leaning towards direct - blob container is encoded in locator. - * - * UploadResult uploadFile(Locator locator, string content, UploadOptions options); - * UploadResult uploadFile(Locator locator, InputStream sream, UploadOptions options); - * - * // UploadOptions - do we need this? Look at blob client for what's in this. Can we reuse? - * // Probably shouldn't, in case they diverge. - * - * DeleteLocatorResult deleteLocator(Locator locator) - * throws ServiceException; - * - * CreateFileInfosResponse createFileInfos(Asset asset) - * throws ServiceException; - * - * - */ + /** + * // The set of operations to support. Will uncomment as they get added + * + * CreateAccessPolicyResult createAccessPolicy(String name, + * int durationInMinutes, + * AccessPolicyPermissions permissions) + * throws ServiceException; + * + * CreateLocatorResult createLocator(AssetId asset, + * AccessPolicyId accessPolicy, + * DateTime startTime, + * LocatorType type) + * throws ServiceException; + * + * // Add overload that defaults locatorType to SAS, and defaults startTime to now - 5 minutes. + * + * // We need to upload blobs from here - do we go through blobservice, or do we just do it + * // directly? I'm leaning towards direct - blob container is encoded in locator. + * + * UploadResult uploadFile(Locator locator, string content, UploadOptions options); + * UploadResult uploadFile(Locator locator, InputStream sream, UploadOptions options); + * + * // UploadOptions - do we need this? Look at blob client for what's in this. Can we reuse? + * // Probably shouldn't, in case they diverge. + * + * DeleteLocatorResult deleteLocator(Locator locator) + * throws ServiceException; + * + * CreateFileInfosResponse createFileInfos(Asset asset) + * throws ServiceException; + * + * + */ } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfo.java new file mode 100644 index 0000000000000..4874dd6cd1740 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfo.java @@ -0,0 +1,37 @@ +/** + * Copyright 2011 Microsoft Corporation + * + * 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 com.microsoft.windowsazure.services.media.models; + +import java.util.Date; + +/** + * Class representing an AccessPolicy entity + * + * + */ +public class AccessPolicyInfo { + // TODO: Rework this as needed once we have a serialization + // solution decided on. + + private String id; + private Date created; + private Date lastModified; + private String name; + private double durationInMinutes; + // TODO: Figure out best way to represent these. EnumSet? + // private AccessPolicyPermissions permissions; + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyPermission.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyPermission.java new file mode 100644 index 0000000000000..546af4e25cc96 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyPermission.java @@ -0,0 +1,12 @@ +/** + * + */ +package com.microsoft.windowsazure.services.media.models; + +/** + * Permissions available to an access policy + * + */ +public enum AccessPolicyPermission { + NONE, READ, WRITE, DELETE, LIST +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAccessPolicyResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAccessPolicyResult.java new file mode 100644 index 0000000000000..7889da14326d4 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAccessPolicyResult.java @@ -0,0 +1,55 @@ +/** + * Copyright 2011 Microsoft Corporation + * + * 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 com.microsoft.windowsazure.services.media.models; + +/** + * Class representing the result of a CreateAccessPolicy REST operation + * + */ +public class CreateAccessPolicyResult { + private AccessPolicyInfo value; + + /** + * Creates an instance of the GetAssetResult class. + * + * @param value + * A {@link AccessPolicyInfo} object assigned as the value of the + * result. + */ + public CreateAccessPolicyResult(AccessPolicyInfo value) { + this.setValue(value); + } + + /** + * Specfies the value of the result. + * + * @param value + * A {@link AccessPolicyInfo} object assigned as the value of the + * result. + */ + public AccessPolicyInfo getValue() { + return value; + } + + /** + * Returns the value of the result. + * + * @return A {@link AccessPolicyInfo} object that represents the value of the + * result. + */ + public void setValue(AccessPolicyInfo newValue) { + value = newValue; + } +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAssetResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAssetResult.java index 0867c5af7b10d..0411e8e18895e 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAssetResult.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAssetResult.java @@ -2,34 +2,34 @@ * Copyright 2011 Microsoft Corporation * * 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 + * 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. + * 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 com.microsoft.windowsazure.services.media.models; /** * Represents the result of a createAsset operation. */ -public class GetAssetResult { - private AssetInfo value; +public class CreateAssetResult { + private AssetInfo value; - /** + /** * Creates an instance of the GetAssetResult class. * * @param value * A {@link AssetInfo} object assigned as the value of the * result. */ - public GetAssetResult(AssetInfo value) { - this.setValue(value); - } + public CreateAssetResult(AssetInfo value) { + this.setValue(value); + } /** * Specfies the value of the result. @@ -38,9 +38,9 @@ public GetAssetResult(AssetInfo value) { * A {@link AssetInfo} object assigned as the value of the * result. */ - public AssetInfo getValue() { - return value; - } + public AssetInfo getValue() { + return value; + } /** * Returns the value of the result. @@ -48,7 +48,7 @@ public AssetInfo getValue() { * @return A {@link AssetInfo} object that represents the value of the * result. */ - public void setValue(AssetInfo newValue) { - value = newValue; - } + public void setValue(AssetInfo newValue) { + value = newValue; + } } From 7d3fcfd9303d7a430d97004ca7277045602c947c Mon Sep 17 00:00:00 2001 From: Chris Tavares Date: Fri, 17 Aug 2012 12:18:03 -0700 Subject: [PATCH 5/9] Defining AccessPolicyPermission as an enum, plus helpful conversion functions --- .../media/models/AccessPolicyPermission.java | 69 +++++++++++++++- .../models/AccessPolicyPermissionTest.java | 79 +++++++++++++++++++ 2 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AccessPolicyPermissionTest.java diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyPermission.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyPermission.java index 546af4e25cc96..a1abc4a25587b 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyPermission.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyPermission.java @@ -1,12 +1,79 @@ /** + * Copyright 2011 Microsoft Corporation * + * 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 com.microsoft.windowsazure.services.media.models; +import java.util.EnumSet; + /** * Permissions available to an access policy * */ public enum AccessPolicyPermission { - NONE, READ, WRITE, DELETE, LIST + NONE(0), READ(1), WRITE(2), DELETE(4), LIST(8); + + private int flagValue; + + private AccessPolicyPermission(int value) { + flagValue = value; + } + + /** + * Get the flag bit value associated with this permission + * + * @return The integer permission value + */ + public int getFlagValue() { + return flagValue; + } + + /** + * Given an integer representing the permissions as a bit vector, + * convert it into an EnumSet<AccessPolicyPermission> object containing the correct permissions + * * + * + * @param bits + * The bit vector of permissions + * @return The set of permissions in an EnumSet object. + */ + public static EnumSet permissionsFromBits(int bits) { + EnumSet perms = EnumSet.of(AccessPolicyPermission.NONE); + + for (AccessPolicyPermission p : AccessPolicyPermission.values()) { + if ((bits & p.getFlagValue()) != 0) { + perms.remove(AccessPolicyPermission.NONE); + perms.add(p); + } + } + + return perms; + } + + /** + * Convert an EnumSet containing permissions into the + * corresponding integer bit vector to be passed to Media services. + * + * @param perms + * The permissions + * @return The bit vector to go out over the wire. + */ + public static int bitsFromPermissions(EnumSet perms) { + int result = 0; + for (AccessPolicyPermission p : perms) { + result |= p.getFlagValue(); + } + + return result; + } } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AccessPolicyPermissionTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AccessPolicyPermissionTest.java new file mode 100644 index 0000000000000..2ff5a68665294 --- /dev/null +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AccessPolicyPermissionTest.java @@ -0,0 +1,79 @@ +package com.microsoft.windowsazure.services.media.models; + +import static org.junit.Assert.*; + +import java.util.EnumSet; + +import org.junit.Test; + +public class AccessPolicyPermissionTest { + + @Test + public void testGetFlagValue() { + assertEquals(0, AccessPolicyPermission.NONE.getFlagValue()); + assertEquals(1, AccessPolicyPermission.READ.getFlagValue()); + assertEquals(2, AccessPolicyPermission.WRITE.getFlagValue()); + assertEquals(4, AccessPolicyPermission.DELETE.getFlagValue()); + assertEquals(8, AccessPolicyPermission.LIST.getFlagValue()); + } + + @Test + public void testZeroResultsInNonePermission() { + EnumSet perms = AccessPolicyPermission.permissionsFromBits(0); + assertTrue(perms.contains(AccessPolicyPermission.NONE)); + } + + @Test + public void testAllBitsSetResultsInAllPermissions() { + EnumSet perms = AccessPolicyPermission.permissionsFromBits(1 + 2 + 4 + 8); + + assertFalse(perms.contains(AccessPolicyPermission.NONE)); + assertTrue(perms.contains(AccessPolicyPermission.READ)); + assertTrue(perms.contains(AccessPolicyPermission.WRITE)); + assertTrue(perms.contains(AccessPolicyPermission.DELETE)); + assertTrue(perms.contains(AccessPolicyPermission.LIST)); + } + + @Test + public void testWriteBitsResultsInOnlyWritePermissions() { + EnumSet perms = AccessPolicyPermission.permissionsFromBits(2); + + assertFalse(perms.contains(AccessPolicyPermission.NONE)); + assertFalse(perms.contains(AccessPolicyPermission.READ)); + assertTrue(perms.contains(AccessPolicyPermission.WRITE)); + assertFalse(perms.contains(AccessPolicyPermission.DELETE)); + assertFalse(perms.contains(AccessPolicyPermission.LIST)); + } + + @Test + public void testEmptyPermissionsResultsInZeroBits() { + EnumSet perms = EnumSet.noneOf(AccessPolicyPermission.class); + int bits = AccessPolicyPermission.bitsFromPermissions(perms); + + assertEquals(0, bits); + } + + @Test + public void allPermissionsInSetResultsInCorrectValue() { + EnumSet perms = EnumSet.of(AccessPolicyPermission.READ, AccessPolicyPermission.WRITE, + AccessPolicyPermission.DELETE, AccessPolicyPermission.LIST, AccessPolicyPermission.NONE); + int bits = AccessPolicyPermission.bitsFromPermissions(perms); + + assertEquals(1 + 2 + 4 + 8, bits); + } + + @Test + public void writePermissionsInSetResultsInCorrectValue() { + EnumSet perms = EnumSet.of(AccessPolicyPermission.WRITE); + int bits = AccessPolicyPermission.bitsFromPermissions(perms); + + assertEquals(2, bits); + } + + @Test + public void unknownPermissionBitsAreIgnored() { + EnumSet perms = AccessPolicyPermission.permissionsFromBits(16 + 32); + + assertTrue(perms.contains(AccessPolicyPermission.NONE)); + } +} From 84075724c878c347cb10238ec142bfef6968a49c Mon Sep 17 00:00:00 2001 From: Chris Tavares Date: Fri, 17 Aug 2012 15:13:53 -0700 Subject: [PATCH 6/9] Building out contract - access policies using permissions enum --- .../services/media/MediaServicesContract.java | 4 - .../media/models/AccessPolicyInfo.java | 96 ++++++++++++++++++- 2 files changed, 94 insertions(+), 6 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesContract.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesContract.java index 35c702de42e09..3c8c744a05064 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesContract.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesContract.java @@ -62,10 +62,6 @@ CreateAccessPolicyResult createAccessPolicy(String name, int durationInMinutes, /** * // The set of operations to support. Will uncomment as they get added * - * CreateAccessPolicyResult createAccessPolicy(String name, - * int durationInMinutes, - * AccessPolicyPermissions permissions) - * throws ServiceException; * * CreateLocatorResult createLocator(AssetId asset, * AccessPolicyId accessPolicy, diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfo.java index 4874dd6cd1740..1728075c704b9 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfo.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfo.java @@ -16,6 +16,7 @@ package com.microsoft.windowsazure.services.media.models; import java.util.Date; +import java.util.EnumSet; /** * Class representing an AccessPolicy entity @@ -31,7 +32,98 @@ public class AccessPolicyInfo { private Date lastModified; private String name; private double durationInMinutes; - // TODO: Figure out best way to represent these. EnumSet? - // private AccessPolicyPermissions permissions; + private final EnumSet permissions = EnumSet.noneOf(AccessPolicyPermission.class); + + public AccessPolicyInfo(String id, String Name, Date created, Date lastModified, double durationInMinutes, + int permissionBits) { + + this.id = id; + this.created = created; + this.lastModified = lastModified; + this.durationInMinutes = durationInMinutes; + permissions.addAll(AccessPolicyPermission.permissionsFromBits(permissionBits)); + } + + /** + * @return the id + */ + public String getId() { + return id; + } + + /** + * @param id + * the id to set + */ + public void setId(String id) { + this.id = id; + } + + /** + * @return the created + */ + public Date getCreated() { + return created; + } + + /** + * @param created + * the created to set + */ + public void setCreated(Date created) { + this.created = created; + } + + /** + * @return the lastModified + */ + public Date getLastModified() { + return lastModified; + } + + /** + * @param lastModified + * the lastModified to set + */ + public void setLastModified(Date lastModified) { + this.lastModified = lastModified; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name + * the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the durationInMinutes + */ + public double getDurationInMinutes() { + return durationInMinutes; + } + + /** + * @param durationInMinutes + * the durationInMinutes to set + */ + public void setDurationInMinutes(double durationInMinutes) { + this.durationInMinutes = durationInMinutes; + } + + /** + * @return the permissions + */ + public EnumSet getPermissions() { + return permissions; + } } From dc5d1301a8fb6edd1c580b6db1c743444c5bff9e Mon Sep 17 00:00:00 2001 From: Chris Tavares Date: Fri, 17 Aug 2012 17:43:12 -0700 Subject: [PATCH 7/9] Putting in initial implementation of contract, including rest proxies, MediaServicesService, etc. Hooked up exports to configuration. --- .../windowsazure/services/media/Exports.java | 9 ++ .../services/media/MediaConfiguration.java | 2 +- .../services/media/MediaServicesService.java | 67 +++++++++++ .../MediaServicesExceptionProcessor.java | 104 ++++++++++++++++++ .../MediaServicesRestProxy.java | 96 ++++++++++++++++ .../implementation/OAuthTokenManager.java | 9 +- .../ResourceLocationManager.java | 5 +- ...windowsazure.services.core.Builder$Exports | 2 + .../services/media/ExportsTest.java | 32 ++++++ .../services/media/IntegrationTestBase.java | 26 +++++ 10 files changed, 348 insertions(+), 4 deletions(-) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesService.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaServicesExceptionProcessor.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaServicesRestProxy.java create mode 100644 microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/ExportsTest.java create mode 100644 microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/IntegrationTestBase.java diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/Exports.java index a981bbde293b0..b28f86e89d1b3 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/Exports.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/Exports.java @@ -15,10 +15,14 @@ package com.microsoft.windowsazure.services.media; import com.microsoft.windowsazure.services.core.Builder; +import com.microsoft.windowsazure.services.media.implementation.MediaServicesExceptionProcessor; +import com.microsoft.windowsazure.services.media.implementation.MediaServicesRestProxy; import com.microsoft.windowsazure.services.media.implementation.OAuthContract; import com.microsoft.windowsazure.services.media.implementation.OAuthFilter; import com.microsoft.windowsazure.services.media.implementation.OAuthRestProxy; import com.microsoft.windowsazure.services.media.implementation.OAuthTokenManager; +import com.microsoft.windowsazure.services.media.implementation.RedirectFilter; +import com.microsoft.windowsazure.services.media.implementation.ResourceLocationManager; public class Exports implements Builder.Exports { @@ -27,9 +31,14 @@ public class Exports implements Builder.Exports { */ @Override public void register(Builder.Registry registry) { + registry.add(MediaServicesContract.class, MediaServicesExceptionProcessor.class); + registry.add(MediaServicesExceptionProcessor.class); + registry.add(MediaServicesRestProxy.class); registry.add(OAuthContract.class, OAuthRestProxy.class); registry.add(OAuthTokenManager.class); registry.add(OAuthFilter.class); + registry.add(ResourceLocationManager.class); + registry.add(RedirectFilter.class); } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaConfiguration.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaConfiguration.java index 0c4c703fb1dd7..ac7464c570018 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaConfiguration.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaConfiguration.java @@ -17,7 +17,7 @@ import com.microsoft.windowsazure.services.core.Configuration; /** - * Provides functionality to create a service bus configuration. + * Provides functionality to create a media services configuration. * */ public class MediaConfiguration { diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesService.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesService.java new file mode 100644 index 0000000000000..8b91c17a666ca --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesService.java @@ -0,0 +1,67 @@ +/** + * Copyright 2011 Microsoft Corporation + * + * 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 com.microsoft.windowsazure.services.media; + +import com.microsoft.windowsazure.services.core.Configuration; + +/** + * + * Access media services functionality. + * + */ +public class MediaServicesService { + + private MediaServicesService() { + // class is not instantiated + } + + /** + * Creates an instance of the MediaServicesContract API. + * + */ + public static MediaServicesContract create() { + return Configuration.getInstance().create(MediaServicesContract.class); + } + + /** + * Creates an instance of the MediaServicesContract API using the specified configuration. + * + * @param config + * A Configuration object that represents the configuration for the service bus service. + * + */ + public static MediaServicesContract create(Configuration config) { + return config.create(MediaServicesContract.class); + } + + /** + * Creates an instance of the MediaServicesContract API. + * + */ + public static MediaServicesContract create(String profile) { + return Configuration.getInstance().create(profile, MediaServicesContract.class); + } + + /** + * Creates an instance of the MediaServicesContract API using the specified configuration. + * + * @param config + * A Configuration object that represents the configuration for the service bus service. + * + */ + public static MediaServicesContract create(String profile, Configuration config) { + return config.create(profile, MediaServicesContract.class); + } +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaServicesExceptionProcessor.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaServicesExceptionProcessor.java new file mode 100644 index 0000000000000..9b7d00f2fa4c2 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaServicesExceptionProcessor.java @@ -0,0 +1,104 @@ +/** + * Copyright 2011 Microsoft Corporation + * + * 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 com.microsoft.windowsazure.services.media.implementation; + +import java.util.EnumSet; + +import javax.inject.Inject; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import com.microsoft.windowsazure.services.core.ServiceException; +import com.microsoft.windowsazure.services.core.ServiceFilter; +import com.microsoft.windowsazure.services.core.utils.ServiceExceptionFactory; +import com.microsoft.windowsazure.services.media.MediaServicesContract; +import com.microsoft.windowsazure.services.media.models.AccessPolicyPermission; +import com.microsoft.windowsazure.services.media.models.AssetInfo; +import com.microsoft.windowsazure.services.media.models.CreateAccessPolicyResult; +import com.microsoft.windowsazure.services.media.models.CreateAssetResult; +import com.sun.jersey.api.client.ClientHandlerException; +import com.sun.jersey.api.client.UniformInterfaceException; + +/** + * Wrapper implementation of MediaServicesContract that + * translates exceptions into ServiceExceptions. + * + */ +public class MediaServicesExceptionProcessor implements MediaServicesContract { + + private final MediaServicesContract next; + static Log log = LogFactory.getLog(MediaServicesContract.class); + + public MediaServicesExceptionProcessor(MediaServicesContract next) { + this.next = next; + } + + @Inject + public MediaServicesExceptionProcessor(MediaServicesRestProxy next) { + this.next = next; + } + + @Override + public MediaServicesContract withFilter(ServiceFilter filter) { + return new MediaServicesExceptionProcessor(next.withFilter(filter)); + } + + private ServiceException processCatch(ServiceException e) { + log.warn(e.getMessage(), e.getCause()); + return ServiceExceptionFactory.process("MediaServices", e); + } + + @Override + public CreateAssetResult createAsset(String name) throws ServiceException { + try { + return next.createAsset(name); + } + catch (UniformInterfaceException e) { + throw processCatch(new ServiceException(e)); + } + catch (ClientHandlerException e) { + throw processCatch(new ServiceException(e)); + } + } + + @Override + public void deleteAsset(AssetInfo asset) throws ServiceException { + try { + next.deleteAsset(asset); + } + catch (UniformInterfaceException e) { + throw processCatch(new ServiceException(e)); + } + catch (ClientHandlerException e) { + throw processCatch(new ServiceException(e)); + } + } + + @Override + public CreateAccessPolicyResult createAccessPolicy(String name, int durationInMinutes, + EnumSet permissions) throws ServiceException { + try { + return next.createAccessPolicy(name, durationInMinutes, permissions); + } + catch (UniformInterfaceException e) { + throw processCatch(new ServiceException(e)); + } + catch (ClientHandlerException e) { + throw processCatch(new ServiceException(e)); + } + } +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaServicesRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaServicesRestProxy.java new file mode 100644 index 0000000000000..bb298f1b701e2 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaServicesRestProxy.java @@ -0,0 +1,96 @@ +/** + * Copyright 2011 Microsoft Corporation + * + * 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 com.microsoft.windowsazure.services.media.implementation; + +import java.util.Arrays; +import java.util.EnumSet; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import com.microsoft.windowsazure.services.core.ServiceException; +import com.microsoft.windowsazure.services.core.ServiceFilter; +import com.microsoft.windowsazure.services.core.utils.pipeline.ClientFilterAdapter; +import com.microsoft.windowsazure.services.media.MediaServicesContract; +import com.microsoft.windowsazure.services.media.models.AccessPolicyPermission; +import com.microsoft.windowsazure.services.media.models.AssetInfo; +import com.microsoft.windowsazure.services.media.models.CreateAccessPolicyResult; +import com.microsoft.windowsazure.services.media.models.CreateAssetResult; +import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.WebResource; + +public class MediaServicesRestProxy implements MediaServicesContract { + + private Client channel; + static Log log = LogFactory.getLog(MediaServicesContract.class); + + ServiceFilter[] filters; + + public MediaServicesRestProxy(Client channel, OAuthFilter authFilter, RedirectFilter redirectFilter) { + this.channel = channel; + this.filters = new ServiceFilter[0]; + channel.addFilter(redirectFilter); + channel.addFilter(authFilter); + } + + public MediaServicesRestProxy(Client channel, ServiceFilter[] filters) { + this.channel = channel; + this.filters = filters; + } + + @Override + public MediaServicesContract withFilter(ServiceFilter filter) { + ServiceFilter[] newFilters = Arrays.copyOf(filters, filters.length + 1); + newFilters[filters.length] = filter; + return new MediaServicesRestProxy(channel, newFilters); + } + + public Client getChannel() { + return channel; + } + + public void setChannel(Client channel) { + this.channel = channel; + } + + private WebResource getResource(String entityName) { + WebResource resource = getChannel().resource(entityName); + for (ServiceFilter filter : filters) { + resource.addFilter(new ClientFilterAdapter(filter)); + } + return resource; + } + + @Override + public CreateAssetResult createAsset(String name) throws ServiceException { + // TODO Auto-generated method stub + return null; + } + + @Override + public void deleteAsset(AssetInfo asset) throws ServiceException { + // TODO Auto-generated method stub + + } + + @Override + public CreateAccessPolicyResult createAccessPolicy(String name, int durationInMinutes, + EnumSet permissions) throws ServiceException { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthTokenManager.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthTokenManager.java index 9a5ffcf59afb3..473bd9d60bb60 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthTokenManager.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthTokenManager.java @@ -19,10 +19,12 @@ import java.net.URISyntaxException; import java.util.Date; +import javax.inject.Named; import javax.management.timer.Timer; import com.microsoft.windowsazure.services.core.ServiceException; import com.microsoft.windowsazure.services.core.utils.DateFactory; +import com.microsoft.windowsazure.services.media.MediaConfiguration; /** * An OAuth token manager class. @@ -59,8 +61,11 @@ public class OAuthTokenManager { * A String object instance that represents the client secret. * */ - public OAuthTokenManager(OAuthContract contract, DateFactory dateFactory, URI acsBaseUri, String clientId, - String clientSecret, String scope) { + public OAuthTokenManager(OAuthContract contract, DateFactory dateFactory, + @Named(MediaConfiguration.OAUTH_URI) URI acsBaseUri, + @Named(MediaConfiguration.OAUTH_CLIENT_ID) String clientId, + @Named(MediaConfiguration.OAUTH_CLIENT_SECRET) String clientSecret, + @Named(MediaConfiguration.OAUTH_SCOPE) String scope) { this.contract = contract; this.dateFactory = dateFactory; this.acsBaseUri = acsBaseUri; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ResourceLocationManager.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ResourceLocationManager.java index 773b6c27847d1..75b5c12ad6dc6 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ResourceLocationManager.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ResourceLocationManager.java @@ -18,12 +18,15 @@ import java.net.URI; import java.net.URISyntaxException; +import javax.inject.Named; import javax.ws.rs.core.UriBuilder; +import com.microsoft.windowsazure.services.media.MediaConfiguration; + public class ResourceLocationManager { private URI baseURI; - public ResourceLocationManager(String baseUri) throws URISyntaxException { + public ResourceLocationManager(@Named(MediaConfiguration.URI) String baseUri) throws URISyntaxException { this.baseURI = new URI(baseUri); } diff --git a/microsoft-azure-api/src/main/resources/META-INF/services/com.microsoft.windowsazure.services.core.Builder$Exports b/microsoft-azure-api/src/main/resources/META-INF/services/com.microsoft.windowsazure.services.core.Builder$Exports index 07fdb1c4e7b67..e49188d4c09af 100644 --- a/microsoft-azure-api/src/main/resources/META-INF/services/com.microsoft.windowsazure.services.core.Builder$Exports +++ b/microsoft-azure-api/src/main/resources/META-INF/services/com.microsoft.windowsazure.services.core.Builder$Exports @@ -5,3 +5,5 @@ com.microsoft.windowsazure.services.serviceBus.Exports com.microsoft.windowsazure.services.serviceBus.implementation.Exports com.microsoft.windowsazure.services.core.utils.Exports com.microsoft.windowsazure.services.core.utils.pipeline.Exports +com.microsoft.windowsazure.services.media.Exports + diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/ExportsTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/ExportsTest.java new file mode 100644 index 0000000000000..c21063c48e261 --- /dev/null +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/ExportsTest.java @@ -0,0 +1,32 @@ +package com.microsoft.windowsazure.services.media; + +import static org.junit.Assert.*; + +import java.net.URI; + +import org.junit.Test; + +import com.microsoft.windowsazure.services.media.implementation.RedirectFilter; +import com.microsoft.windowsazure.services.media.implementation.ResourceLocationManager; + +/** + * Tests to verify the items exported from media services + * can be resolved from configuration. + * + */ +public class ExportsTest extends IntegrationTestBase { + + @Test + public void canResolveLocationManagerFromConfig() throws Exception { + ResourceLocationManager rlm = config.create(ResourceLocationManager.class); + URI rootUri = new URI((String) config.getProperty(MediaConfiguration.URI)); + + assertEquals(rootUri, rlm.getBaseURI()); + } + + @Test + public void canResolveRedirectFilterFromConfig() throws Exception { + RedirectFilter filter = config.create(RedirectFilter.class); + assertNotNull(filter); + } +} diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/IntegrationTestBase.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/IntegrationTestBase.java new file mode 100644 index 0000000000000..113d1ff2b2c50 --- /dev/null +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/IntegrationTestBase.java @@ -0,0 +1,26 @@ +package com.microsoft.windowsazure.services.media; + +import org.junit.Before; + +import com.microsoft.windowsazure.services.core.Configuration; + +public abstract class IntegrationTestBase { + protected Configuration config; + + @Before + public void beforeEachTest() { + config = Configuration.getInstance(); + overrideWithEnv(config, MediaConfiguration.URI); + overrideWithEnv(config, MediaConfiguration.OAUTH_URI); + overrideWithEnv(config, MediaConfiguration.OAUTH_CLIENT_ID); + overrideWithEnv(config, MediaConfiguration.OAUTH_CLIENT_SECRET); + } + + protected static void overrideWithEnv(Configuration config, String key) { + String value = System.getenv(key); + if (value == null) + return; + + config.setProperty(key, value); + } +} From 7e2815b3f44d7c920215d4a195d59f5294d50b1a Mon Sep 17 00:00:00 2001 From: Chris Tavares Date: Mon, 17 Sep 2012 10:19:31 -0700 Subject: [PATCH 8/9] Cleaning up media service proxy work, removed premature model objects (mostly) --- .../services/media/MediaServicesContract.java | 65 +------------------ .../MediaServicesExceptionProcessor.java | 47 -------------- .../MediaServicesRestProxy.java | 28 +------- .../services/media/models/AssetInfo.java | 45 ------------- .../models/CreateAccessPolicyResult.java | 55 ---------------- .../media/models/CreateAssetResult.java | 54 --------------- .../OAuthRestProxyIntegrationTest.java | 16 +---- 7 files changed, 6 insertions(+), 304 deletions(-) delete mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java delete mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAccessPolicyResult.java delete mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAssetResult.java diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesContract.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesContract.java index 3c8c744a05064..e14cbc59e5757 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesContract.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesContract.java @@ -14,14 +14,7 @@ */ package com.microsoft.windowsazure.services.media; -import java.util.EnumSet; - import com.microsoft.windowsazure.services.core.FilterableService; -import com.microsoft.windowsazure.services.core.ServiceException; -import com.microsoft.windowsazure.services.media.models.AccessPolicyPermission; -import com.microsoft.windowsazure.services.media.models.AssetInfo; -import com.microsoft.windowsazure.services.media.models.CreateAccessPolicyResult; -import com.microsoft.windowsazure.services.media.models.CreateAssetResult; /** * @@ -30,62 +23,6 @@ */ public interface MediaServicesContract extends FilterableService { - /** - * Creates a new media service asset - * - * @param name - * A String specifying the name of the asset to create. - * - * @return A CreateAssetResult object that represents the result. - * - * @exception ServiceException - * If a service exception is encountered. - * - */ - CreateAssetResult createAsset(String name) throws ServiceException; - - /** - * Deletes a media service asset - * - * @param asset - * A AssetInfo object specifying the asset to delete. - * - * @exception ServiceException - * If a service exception is encountered. - * - */ - void deleteAsset(AssetInfo asset) throws ServiceException; - - CreateAccessPolicyResult createAccessPolicy(String name, int durationInMinutes, - EnumSet permissions) throws ServiceException; + // TODO: Fill in as we define the REST operations - /** - * // The set of operations to support. Will uncomment as they get added - * - * - * CreateLocatorResult createLocator(AssetId asset, - * AccessPolicyId accessPolicy, - * DateTime startTime, - * LocatorType type) - * throws ServiceException; - * - * // Add overload that defaults locatorType to SAS, and defaults startTime to now - 5 minutes. - * - * // We need to upload blobs from here - do we go through blobservice, or do we just do it - * // directly? I'm leaning towards direct - blob container is encoded in locator. - * - * UploadResult uploadFile(Locator locator, string content, UploadOptions options); - * UploadResult uploadFile(Locator locator, InputStream sream, UploadOptions options); - * - * // UploadOptions - do we need this? Look at blob client for what's in this. Can we reuse? - * // Probably shouldn't, in case they diverge. - * - * DeleteLocatorResult deleteLocator(Locator locator) - * throws ServiceException; - * - * CreateFileInfosResponse createFileInfos(Asset asset) - * throws ServiceException; - * - * - */ } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaServicesExceptionProcessor.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaServicesExceptionProcessor.java index 9b7d00f2fa4c2..ce7c3d56f2890 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaServicesExceptionProcessor.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaServicesExceptionProcessor.java @@ -15,8 +15,6 @@ package com.microsoft.windowsazure.services.media.implementation; -import java.util.EnumSet; - import javax.inject.Inject; import org.apache.commons.logging.Log; @@ -26,12 +24,6 @@ import com.microsoft.windowsazure.services.core.ServiceFilter; import com.microsoft.windowsazure.services.core.utils.ServiceExceptionFactory; import com.microsoft.windowsazure.services.media.MediaServicesContract; -import com.microsoft.windowsazure.services.media.models.AccessPolicyPermission; -import com.microsoft.windowsazure.services.media.models.AssetInfo; -import com.microsoft.windowsazure.services.media.models.CreateAccessPolicyResult; -import com.microsoft.windowsazure.services.media.models.CreateAssetResult; -import com.sun.jersey.api.client.ClientHandlerException; -import com.sun.jersey.api.client.UniformInterfaceException; /** * Wrapper implementation of MediaServicesContract that @@ -62,43 +54,4 @@ private ServiceException processCatch(ServiceException e) { return ServiceExceptionFactory.process("MediaServices", e); } - @Override - public CreateAssetResult createAsset(String name) throws ServiceException { - try { - return next.createAsset(name); - } - catch (UniformInterfaceException e) { - throw processCatch(new ServiceException(e)); - } - catch (ClientHandlerException e) { - throw processCatch(new ServiceException(e)); - } - } - - @Override - public void deleteAsset(AssetInfo asset) throws ServiceException { - try { - next.deleteAsset(asset); - } - catch (UniformInterfaceException e) { - throw processCatch(new ServiceException(e)); - } - catch (ClientHandlerException e) { - throw processCatch(new ServiceException(e)); - } - } - - @Override - public CreateAccessPolicyResult createAccessPolicy(String name, int durationInMinutes, - EnumSet permissions) throws ServiceException { - try { - return next.createAccessPolicy(name, durationInMinutes, permissions); - } - catch (UniformInterfaceException e) { - throw processCatch(new ServiceException(e)); - } - catch (ClientHandlerException e) { - throw processCatch(new ServiceException(e)); - } - } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaServicesRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaServicesRestProxy.java index bb298f1b701e2..4a40e8dc3929e 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaServicesRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaServicesRestProxy.java @@ -16,19 +16,15 @@ package com.microsoft.windowsazure.services.media.implementation; import java.util.Arrays; -import java.util.EnumSet; + +import javax.inject.Inject; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import com.microsoft.windowsazure.services.core.ServiceException; import com.microsoft.windowsazure.services.core.ServiceFilter; import com.microsoft.windowsazure.services.core.utils.pipeline.ClientFilterAdapter; import com.microsoft.windowsazure.services.media.MediaServicesContract; -import com.microsoft.windowsazure.services.media.models.AccessPolicyPermission; -import com.microsoft.windowsazure.services.media.models.AssetInfo; -import com.microsoft.windowsazure.services.media.models.CreateAccessPolicyResult; -import com.microsoft.windowsazure.services.media.models.CreateAssetResult; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.WebResource; @@ -39,6 +35,7 @@ public class MediaServicesRestProxy implements MediaServicesContract { ServiceFilter[] filters; + @Inject public MediaServicesRestProxy(Client channel, OAuthFilter authFilter, RedirectFilter redirectFilter) { this.channel = channel; this.filters = new ServiceFilter[0]; @@ -74,23 +71,4 @@ private WebResource getResource(String entityName) { return resource; } - @Override - public CreateAssetResult createAsset(String name) throws ServiceException { - // TODO Auto-generated method stub - return null; - } - - @Override - public void deleteAsset(AssetInfo asset) throws ServiceException { - // TODO Auto-generated method stub - - } - - @Override - public CreateAccessPolicyResult createAccessPolicy(String name, int durationInMinutes, - EnumSet permissions) throws ServiceException { - // TODO Auto-generated method stub - return null; - } - } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java deleted file mode 100644 index 800f7bf14674e..0000000000000 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright 2011 Microsoft Corporation - * - * 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 com.microsoft.windowsazure.services.media.models; - -/** - * Represents an asset - */ -public class AssetInfo { - // TODO: Turn this into a serializable class, EntryModel thing - private String id; - - /** - * Create a new AssetInfo for the given Asset Id. - */ - public AssetInfo(String id) { - this.id = id; - } - - /** - * Retrieve the id - */ - public String getId() { - return id; - } - - /** - * Set the id. Do we really need this? - */ - public AssetInfo setId(String newId) { - id = newId; - return this; - } -} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAccessPolicyResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAccessPolicyResult.java deleted file mode 100644 index 7889da14326d4..0000000000000 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAccessPolicyResult.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Copyright 2011 Microsoft Corporation - * - * 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 com.microsoft.windowsazure.services.media.models; - -/** - * Class representing the result of a CreateAccessPolicy REST operation - * - */ -public class CreateAccessPolicyResult { - private AccessPolicyInfo value; - - /** - * Creates an instance of the GetAssetResult class. - * - * @param value - * A {@link AccessPolicyInfo} object assigned as the value of the - * result. - */ - public CreateAccessPolicyResult(AccessPolicyInfo value) { - this.setValue(value); - } - - /** - * Specfies the value of the result. - * - * @param value - * A {@link AccessPolicyInfo} object assigned as the value of the - * result. - */ - public AccessPolicyInfo getValue() { - return value; - } - - /** - * Returns the value of the result. - * - * @return A {@link AccessPolicyInfo} object that represents the value of the - * result. - */ - public void setValue(AccessPolicyInfo newValue) { - value = newValue; - } -} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAssetResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAssetResult.java deleted file mode 100644 index 0411e8e18895e..0000000000000 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAssetResult.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright 2011 Microsoft Corporation - * - * 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 com.microsoft.windowsazure.services.media.models; - -/** - * Represents the result of a createAsset operation. - */ -public class CreateAssetResult { - private AssetInfo value; - - /** - * Creates an instance of the GetAssetResult class. - * - * @param value - * A {@link AssetInfo} object assigned as the value of the - * result. - */ - public CreateAssetResult(AssetInfo value) { - this.setValue(value); - } - - /** - * Specfies the value of the result. - * - * @param value - * A {@link AssetInfo} object assigned as the value of the - * result. - */ - public AssetInfo getValue() { - return value; - } - - /** - * Returns the value of the result. - * - * @return A {@link AssetInfo} object that represents the value of the - * result. - */ - public void setValue(AssetInfo newValue) { - value = newValue; - } -} diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/OAuthRestProxyIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/OAuthRestProxyIntegrationTest.java index da1153cae4015..13bede0a0db30 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/OAuthRestProxyIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/OAuthRestProxyIntegrationTest.java @@ -20,18 +20,14 @@ import org.junit.Test; -import com.microsoft.windowsazure.services.core.Configuration; +import com.microsoft.windowsazure.services.media.IntegrationTestBase; import com.microsoft.windowsazure.services.media.MediaConfiguration; import com.sun.jersey.api.client.Client; -public class OAuthRestProxyIntegrationTest { +public class OAuthRestProxyIntegrationTest extends IntegrationTestBase { @Test public void serviceCanBeCalledToCreateAccessToken() throws Exception { // Arrange - Configuration config = Configuration.getInstance(); - overrideWithEnv(config, MediaConfiguration.OAUTH_URI); - overrideWithEnv(config, MediaConfiguration.OAUTH_CLIENT_ID); - overrideWithEnv(config, MediaConfiguration.OAUTH_CLIENT_SECRET); OAuthContract oAuthContract = new OAuthRestProxy(config.create(Client.class)); // Act @@ -45,12 +41,4 @@ public void serviceCanBeCalledToCreateAccessToken() throws Exception { assertNotNull(result); assertNotNull(result.getAccessToken()); } - - private static void overrideWithEnv(Configuration config, String key) { - String value = System.getenv(key); - if (value == null) - return; - - config.setProperty(key, value); - } } From 17a4ca29df4e58974fe905eca273685d9577b170 Mon Sep 17 00:00:00 2001 From: Chris Tavares Date: Mon, 17 Sep 2012 11:48:01 -0700 Subject: [PATCH 9/9] Responding to code review feedback. --- .../windowsazure/services/media/Exports.java | 10 +- ...rvicesContract.java => MediaContract.java} | 56 ++++---- ...ServicesService.java => MediaService.java} | 24 ++-- ...ssor.java => MediaExceptionProcessor.java} | 16 +-- ...icesRestProxy.java => MediaRestProxy.java} | 14 +- .../media/models/AccessPolicyInfo.java | 129 ------------------ 6 files changed, 60 insertions(+), 189 deletions(-) rename microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/{MediaServicesContract.java => MediaContract.java} (77%) rename microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/{MediaServicesService.java => MediaService.java} (70%) rename microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/{MediaServicesExceptionProcessor.java => MediaExceptionProcessor.java} (71%) rename microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/{MediaServicesRestProxy.java => MediaRestProxy.java} (78%) delete mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfo.java diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/Exports.java index b28f86e89d1b3..791ed56f87555 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/Exports.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/Exports.java @@ -15,8 +15,8 @@ package com.microsoft.windowsazure.services.media; import com.microsoft.windowsazure.services.core.Builder; -import com.microsoft.windowsazure.services.media.implementation.MediaServicesExceptionProcessor; -import com.microsoft.windowsazure.services.media.implementation.MediaServicesRestProxy; +import com.microsoft.windowsazure.services.media.implementation.MediaExceptionProcessor; +import com.microsoft.windowsazure.services.media.implementation.MediaRestProxy; import com.microsoft.windowsazure.services.media.implementation.OAuthContract; import com.microsoft.windowsazure.services.media.implementation.OAuthFilter; import com.microsoft.windowsazure.services.media.implementation.OAuthRestProxy; @@ -31,9 +31,9 @@ public class Exports implements Builder.Exports { */ @Override public void register(Builder.Registry registry) { - registry.add(MediaServicesContract.class, MediaServicesExceptionProcessor.class); - registry.add(MediaServicesExceptionProcessor.class); - registry.add(MediaServicesRestProxy.class); + registry.add(MediaContract.class, MediaExceptionProcessor.class); + registry.add(MediaExceptionProcessor.class); + registry.add(MediaRestProxy.class); registry.add(OAuthContract.class, OAuthRestProxy.class); registry.add(OAuthTokenManager.class); registry.add(OAuthFilter.class); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesContract.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaContract.java similarity index 77% rename from microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesContract.java rename to microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaContract.java index e14cbc59e5757..3e92ac300dae0 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesContract.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaContract.java @@ -1,28 +1,28 @@ -/** - * Copyright 2011 Microsoft Corporation - * - * 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 com.microsoft.windowsazure.services.media; - -import com.microsoft.windowsazure.services.core.FilterableService; - -/** - * - * Defines the Media contract. - * - */ -public interface MediaServicesContract extends FilterableService { - - // TODO: Fill in as we define the REST operations - -} +/** + * Copyright 2011 Microsoft Corporation + * + * 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 com.microsoft.windowsazure.services.media; + +import com.microsoft.windowsazure.services.core.FilterableService; + +/** + * + * Defines the methods available for Windows Azure Media Services + * + */ +public interface MediaContract extends FilterableService { + + // Will fill in as we implement the various Media Services entities + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesService.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaService.java similarity index 70% rename from microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesService.java rename to microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaService.java index 8b91c17a666ca..413dae44c8d41 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaServicesService.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaService.java @@ -18,21 +18,21 @@ /** * - * Access media services functionality. + * Access media services functionality. This class cannot + * be instantiated. * */ -public class MediaServicesService { +public class MediaService { - private MediaServicesService() { - // class is not instantiated + private MediaService() { } /** * Creates an instance of the MediaServicesContract API. * */ - public static MediaServicesContract create() { - return Configuration.getInstance().create(MediaServicesContract.class); + public static MediaContract create() { + return Configuration.getInstance().create(MediaContract.class); } /** @@ -42,16 +42,16 @@ public static MediaServicesContract create() { * A Configuration object that represents the configuration for the service bus service. * */ - public static MediaServicesContract create(Configuration config) { - return config.create(MediaServicesContract.class); + public static MediaContract create(Configuration config) { + return config.create(MediaContract.class); } /** * Creates an instance of the MediaServicesContract API. * */ - public static MediaServicesContract create(String profile) { - return Configuration.getInstance().create(profile, MediaServicesContract.class); + public static MediaContract create(String profile) { + return Configuration.getInstance().create(profile, MediaContract.class); } /** @@ -61,7 +61,7 @@ public static MediaServicesContract create(String profile) { * A Configuration object that represents the configuration for the service bus service. * */ - public static MediaServicesContract create(String profile, Configuration config) { - return config.create(profile, MediaServicesContract.class); + public static MediaContract create(String profile, Configuration config) { + return config.create(profile, MediaContract.class); } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaServicesExceptionProcessor.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaExceptionProcessor.java similarity index 71% rename from microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaServicesExceptionProcessor.java rename to microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaExceptionProcessor.java index ce7c3d56f2890..d9c3141d52064 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaServicesExceptionProcessor.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaExceptionProcessor.java @@ -23,30 +23,30 @@ import com.microsoft.windowsazure.services.core.ServiceException; import com.microsoft.windowsazure.services.core.ServiceFilter; import com.microsoft.windowsazure.services.core.utils.ServiceExceptionFactory; -import com.microsoft.windowsazure.services.media.MediaServicesContract; +import com.microsoft.windowsazure.services.media.MediaContract; /** * Wrapper implementation of MediaServicesContract that * translates exceptions into ServiceExceptions. * */ -public class MediaServicesExceptionProcessor implements MediaServicesContract { +public class MediaExceptionProcessor implements MediaContract { - private final MediaServicesContract next; - static Log log = LogFactory.getLog(MediaServicesContract.class); + private final MediaContract next; + static Log log = LogFactory.getLog(MediaContract.class); - public MediaServicesExceptionProcessor(MediaServicesContract next) { + public MediaExceptionProcessor(MediaContract next) { this.next = next; } @Inject - public MediaServicesExceptionProcessor(MediaServicesRestProxy next) { + public MediaExceptionProcessor(MediaRestProxy next) { this.next = next; } @Override - public MediaServicesContract withFilter(ServiceFilter filter) { - return new MediaServicesExceptionProcessor(next.withFilter(filter)); + public MediaContract withFilter(ServiceFilter filter) { + return new MediaExceptionProcessor(next.withFilter(filter)); } private ServiceException processCatch(ServiceException e) { diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaServicesRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaRestProxy.java similarity index 78% rename from microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaServicesRestProxy.java rename to microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaRestProxy.java index 4a40e8dc3929e..9b1dfc25e5a60 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaServicesRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaRestProxy.java @@ -24,35 +24,35 @@ import com.microsoft.windowsazure.services.core.ServiceFilter; import com.microsoft.windowsazure.services.core.utils.pipeline.ClientFilterAdapter; -import com.microsoft.windowsazure.services.media.MediaServicesContract; +import com.microsoft.windowsazure.services.media.MediaContract; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.WebResource; -public class MediaServicesRestProxy implements MediaServicesContract { +public class MediaRestProxy implements MediaContract { private Client channel; - static Log log = LogFactory.getLog(MediaServicesContract.class); + static Log log = LogFactory.getLog(MediaContract.class); ServiceFilter[] filters; @Inject - public MediaServicesRestProxy(Client channel, OAuthFilter authFilter, RedirectFilter redirectFilter) { + public MediaRestProxy(Client channel, OAuthFilter authFilter, RedirectFilter redirectFilter) { this.channel = channel; this.filters = new ServiceFilter[0]; channel.addFilter(redirectFilter); channel.addFilter(authFilter); } - public MediaServicesRestProxy(Client channel, ServiceFilter[] filters) { + public MediaRestProxy(Client channel, ServiceFilter[] filters) { this.channel = channel; this.filters = filters; } @Override - public MediaServicesContract withFilter(ServiceFilter filter) { + public MediaContract withFilter(ServiceFilter filter) { ServiceFilter[] newFilters = Arrays.copyOf(filters, filters.length + 1); newFilters[filters.length] = filter; - return new MediaServicesRestProxy(channel, newFilters); + return new MediaRestProxy(channel, newFilters); } public Client getChannel() { diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfo.java deleted file mode 100644 index 1728075c704b9..0000000000000 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfo.java +++ /dev/null @@ -1,129 +0,0 @@ -/** - * Copyright 2011 Microsoft Corporation - * - * 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 com.microsoft.windowsazure.services.media.models; - -import java.util.Date; -import java.util.EnumSet; - -/** - * Class representing an AccessPolicy entity - * - * - */ -public class AccessPolicyInfo { - // TODO: Rework this as needed once we have a serialization - // solution decided on. - - private String id; - private Date created; - private Date lastModified; - private String name; - private double durationInMinutes; - private final EnumSet permissions = EnumSet.noneOf(AccessPolicyPermission.class); - - public AccessPolicyInfo(String id, String Name, Date created, Date lastModified, double durationInMinutes, - int permissionBits) { - - this.id = id; - this.created = created; - this.lastModified = lastModified; - this.durationInMinutes = durationInMinutes; - permissions.addAll(AccessPolicyPermission.permissionsFromBits(permissionBits)); - } - - /** - * @return the id - */ - public String getId() { - return id; - } - - /** - * @param id - * the id to set - */ - public void setId(String id) { - this.id = id; - } - - /** - * @return the created - */ - public Date getCreated() { - return created; - } - - /** - * @param created - * the created to set - */ - public void setCreated(Date created) { - this.created = created; - } - - /** - * @return the lastModified - */ - public Date getLastModified() { - return lastModified; - } - - /** - * @param lastModified - * the lastModified to set - */ - public void setLastModified(Date lastModified) { - this.lastModified = lastModified; - } - - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @param name - * the name to set - */ - public void setName(String name) { - this.name = name; - } - - /** - * @return the durationInMinutes - */ - public double getDurationInMinutes() { - return durationInMinutes; - } - - /** - * @param durationInMinutes - * the durationInMinutes to set - */ - public void setDurationInMinutes(double durationInMinutes) { - this.durationInMinutes = durationInMinutes; - } - - /** - * @return the permissions - */ - public EnumSet getPermissions() { - return permissions; - } - -}