Skip to content

Commit 61b0931

Browse files
committed
Merge pull request Azure#523 from rnrneverdies/master
Azure Media Services, bug fixing and missing update methods
2 parents c5477e1 + ca3b44b commit 61b0931

File tree

4 files changed

+166
-12
lines changed

4 files changed

+166
-12
lines changed

services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/StreamingEndpointCacheControlType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class StreamingEndpointCacheControlType {
1111
private Integer maxAge;
1212

1313
public int getMaxAge() {
14-
return maxAge;
14+
return maxAge == null ? 0 : maxAge.intValue();
1515
}
1616

1717
public void setMaxAge(int maxRange) {

services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/models/AssetDeliveryPolicy.java

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
import com.microsoft.windowsazure.services.media.entityoperations.EntityCreateOperation;
2525
import com.microsoft.windowsazure.services.media.entityoperations.EntityDeleteOperation;
2626
import com.microsoft.windowsazure.services.media.entityoperations.EntityGetOperation;
27+
import com.microsoft.windowsazure.services.media.entityoperations.EntityOperationBase;
2728
import com.microsoft.windowsazure.services.media.entityoperations.EntityOperationSingleResultBase;
29+
import com.microsoft.windowsazure.services.media.entityoperations.EntityUpdateOperation;
2830
import com.microsoft.windowsazure.services.media.implementation.content.AssetDeliveryPolicyRestType;
2931
import com.sun.jersey.api.client.GenericType;
3032

@@ -169,4 +171,76 @@ public static DefaultListOperation<AssetDeliveryPolicyInfo> list(LinkInfo<AssetD
169171
public static EntityDeleteOperation delete(String assetDeliveryPolicyId) {
170172
return new DefaultDeleteOperation(ENTITY_SET, assetDeliveryPolicyId);
171173
}
174+
175+
/**
176+
* Create an operation that will update the given asset delivery policy.
177+
*
178+
* @param assetDeliveryPolicyId
179+
* id of the asset delivery policy to update
180+
* @return the update operation
181+
*/
182+
public static Updater update(String assetDeliveryPolicyId) {
183+
return new Updater(assetDeliveryPolicyId);
184+
}
185+
186+
/**
187+
* The Class Updater.
188+
*/
189+
public static class Updater extends EntityOperationBase implements EntityUpdateOperation {
190+
191+
private EnumSet<AssetDeliveryProtocol> assetDeliveryProtocol;
192+
private AssetDeliveryPolicyType assetDeliveryPolicyType;
193+
private Map<AssetDeliveryPolicyConfigurationKey, String> assetDeliveryConfiguration;
194+
195+
protected Updater(String assetDeliveryPolicyId) {
196+
super(new EntityOperationBase.EntityIdUriBuilder(ENTITY_SET, assetDeliveryPolicyId));
197+
198+
}
199+
200+
@Override
201+
public Object getRequestContents() {
202+
return new AssetDeliveryPolicyRestType()
203+
.setAssetDeliveryConfiguration(assetDeliveryConfiguration)
204+
.setAssetDeliveryPolicyType(assetDeliveryPolicyType.getCode())
205+
.setAssetDeliveryProtocol(AssetDeliveryProtocol.bitsFromProtocols(assetDeliveryProtocol));
206+
}
207+
208+
/**
209+
* Set the protocol of the Asset Delivery Policy to be created.
210+
*
211+
* @param assetDeliveryProtocol
212+
* The protocol
213+
* @return The creator object (for call chaining)
214+
*/
215+
public Updater setAssetDeliveryProtocol(EnumSet<AssetDeliveryProtocol> assetDeliveryProtocol) {
216+
this.assetDeliveryProtocol = assetDeliveryProtocol;
217+
return this;
218+
}
219+
220+
/**
221+
* Set the type of the Asset Delivery Policy to be created.
222+
*
223+
* @param assetDeliveryPolicyType
224+
* The type
225+
* @return The creator object (for call chaining)
226+
*/
227+
public Updater setAssetDeliveryPolicyType(AssetDeliveryPolicyType assetDeliveryPolicyType) {
228+
this.assetDeliveryPolicyType = assetDeliveryPolicyType;
229+
return this;
230+
}
231+
232+
/**
233+
* Set the configuration of the Asset Delivery Policy to be created.
234+
*
235+
* @param assetDeliveryPolicyConfiguration
236+
* The configuration
237+
* @return The creator object (for call chaining)
238+
*/
239+
public Updater setAssetDeliveryConfiguration(
240+
Map<AssetDeliveryPolicyConfigurationKey, String> assetDeliveryPolicyConfiguration) {
241+
this.assetDeliveryConfiguration = assetDeliveryPolicyConfiguration;
242+
return this;
243+
}
244+
245+
}
172246
}

services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/models/AssetDeliveryProtocol.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
22
* Copyright Microsoft Corporation
3-
*
3+
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
* http://www.apache.org/licenses/LICENSE-2.0
8-
*
8+
*
99
* Unless required by applicable law or agreed to in writing, software
1010
* distributed under the License is distributed on an "AS IS" BASIS,
1111
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -18,9 +18,9 @@
1818
import java.util.EnumSet;
1919

2020
/**
21-
*
21+
*
2222
* Specifies the protocol of an AssetDeliveryPolicy.
23-
*
23+
*
2424
*/
2525
public enum AssetDeliveryProtocol {
2626

@@ -42,7 +42,7 @@ public enum AssetDeliveryProtocol {
4242

4343
/**
4444
* Instantiates a new content key type.
45-
*
45+
*
4646
* @param contentKeyTypeCode
4747
* the content key type code
4848
*/
@@ -52,7 +52,7 @@ private AssetDeliveryProtocol(int falgValue) {
5252

5353
/**
5454
* Gets the flags value.
55-
*
55+
*
5656
* @return the flags value
5757
*/
5858
public int getFlagValue() {
@@ -63,7 +63,7 @@ public int getFlagValue() {
6363
* Given an integer representing the protocols as a bit vector, convert it
6464
* into an <code>EnumSet&lt;AssetDeliveryProtocol&gt;</code> object
6565
* containing the correct protocols *
66-
*
66+
*
6767
* @param bits
6868
* The bit vector of protocols
6969
* @return The set of protocols in an <code>EnumSet</code> object.
@@ -73,7 +73,7 @@ public static EnumSet<AssetDeliveryProtocol> protocolsFromBits(int bits) {
7373
.of(AssetDeliveryProtocol.None);
7474

7575
for (AssetDeliveryProtocol p : AssetDeliveryProtocol.values()) {
76-
if ((bits & p.getFlagValue()) != 0) {
76+
if ((bits & p.getFlagValue()) == p.getFlagValue()) {
7777
perms.remove(AssetDeliveryProtocol.None);
7878
perms.add(p);
7979
}
@@ -85,18 +85,18 @@ public static EnumSet<AssetDeliveryProtocol> protocolsFromBits(int bits) {
8585
/**
8686
* Convert an <code>EnumSet</code> containing protocols into the
8787
* corresponding integer bit vector to be passed to Media services.
88-
*
88+
*
8989
* @param perms
9090
* The protocols
9191
* @return The bit vector to go out over the wire.
9292
*/
9393
public static int bitsFromProtocols(EnumSet<AssetDeliveryProtocol> protos) {
9494
int result = 0;
95-
95+
9696
for (AssetDeliveryProtocol p : protos) {
9797
result |= p.getFlagValue();
9898
}
99-
99+
100100
return result;
101101
}
102102
}

services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/models/ContentKeyAuthorizationPolicyOption.java

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
import com.microsoft.windowsazure.services.media.entityoperations.EntityCreateOperation;
2525
import com.microsoft.windowsazure.services.media.entityoperations.EntityDeleteOperation;
2626
import com.microsoft.windowsazure.services.media.entityoperations.EntityGetOperation;
27+
import com.microsoft.windowsazure.services.media.entityoperations.EntityOperationBase;
2728
import com.microsoft.windowsazure.services.media.entityoperations.EntityOperationSingleResultBase;
29+
import com.microsoft.windowsazure.services.media.entityoperations.EntityUpdateOperation;
2830
import com.microsoft.windowsazure.services.media.implementation.content.ContentKeyAuthorizationPolicyOptionType;
2931
import com.microsoft.windowsazure.services.media.implementation.content.ContentKeyAuthorizationPolicyRestrictionType;
3032
import com.sun.jersey.api.client.GenericType;
@@ -149,4 +151,82 @@ public static DefaultListOperation<ContentKeyAuthorizationPolicyOptionInfo> list
149151
public static EntityDeleteOperation delete(String contentKeyAuthorizationPolicyOptionId) {
150152
return new DefaultDeleteOperation(ENTITY_SET, contentKeyAuthorizationPolicyOptionId);
151153
}
154+
155+
/**
156+
* Create an operation that will update the given content key authorization policy option.
157+
*
158+
* @param contentKeyAuthorizationPolicyOptionId
159+
* id of the acontent key authorization policy option to update
160+
* @return the update operation
161+
*/
162+
public static Updater update(String contentKeyAuthorizationPolicyOptionId) {
163+
return new Updater(contentKeyAuthorizationPolicyOptionId);
164+
}
165+
166+
/**
167+
* The Class Updater.
168+
*/
169+
public static class Updater extends EntityOperationBase implements EntityUpdateOperation {
170+
171+
private int keyDeliveryType;
172+
private String keyDeliveryConfiguration;
173+
private List<ContentKeyAuthorizationPolicyRestrictionType> restrictions;
174+
175+
protected Updater(String contentKeyAuthorizationPolicyOptionId) {
176+
super(new EntityOperationBase.EntityIdUriBuilder(ENTITY_SET,
177+
contentKeyAuthorizationPolicyOptionId));
178+
179+
}
180+
181+
@Override
182+
public Object getRequestContents() {
183+
return new ContentKeyAuthorizationPolicyOptionType().setKeyDeliveryType(keyDeliveryType)
184+
.setKeyDeliveryConfiguration(keyDeliveryConfiguration).setRestrictions(restrictions);
185+
186+
}
187+
188+
/**
189+
* Set the protocol of the Asset Delivery Policy to be created.
190+
*
191+
* @param assetDeliveryProtocol
192+
* The protocol
193+
* @return The creator object (for call chaining)
194+
*/
195+
public Updater setKeyDeliveryType(int keyDeliveryType) {
196+
this.keyDeliveryType = keyDeliveryType;
197+
return this;
198+
}
199+
200+
/**
201+
* Set the type of the Asset Delivery Policy to be created.
202+
*
203+
* @param assetDeliveryPolicyType
204+
* The type
205+
* @return The creator object (for call chaining)
206+
*/
207+
public Updater setKeyDeliveryConfiguration(String keyDeliveryConfiguration) {
208+
this.keyDeliveryConfiguration = keyDeliveryConfiguration;
209+
return this;
210+
}
211+
212+
/**
213+
* Set the configuration of the Asset Delivery Policy to be created.
214+
*
215+
* @param assetDeliveryPolicyConfiguration
216+
* The configuration
217+
* @return The creator object (for call chaining)
218+
*/
219+
public Updater setRestrictions(
220+
List<ContentKeyAuthorizationPolicyRestriction> restrictions) {
221+
222+
this.restrictions = new ArrayList<ContentKeyAuthorizationPolicyRestrictionType>();
223+
for (ContentKeyAuthorizationPolicyRestriction restriction : restrictions) {
224+
this.restrictions.add(new ContentKeyAuthorizationPolicyRestrictionType()
225+
.setName(restriction.getName())
226+
.setKeyRestrictionType(restriction.getKeyRestrictionType())
227+
.setRequirements(restriction.getRequirements()));
228+
}
229+
return this;
230+
}
231+
}
152232
}

0 commit comments

Comments
 (0)