Skip to content

Commit

Permalink
Locator relationships added
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Tavares committed Dec 15, 2012
1 parent a11747d commit d9dc999
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,35 @@

package com.microsoft.windowsazure.services.media.implementation.entities;


/**
* Generic implementation of the get operation usable for most entities
*
*/
public class DefaultGetOperation<T> extends EntityOperationSingleResultBase<T> implements EntityGetOperation<T> {

/**
* @param uri
* Construct a new DefaultGetOperation to return the given entity id
*
* @param entityTypeUri
* Entity set URI
* @param entityId
* id of entity
* @param responseClass
* class to return from the get operation
*/
public DefaultGetOperation(String entityTypeUri, String entityId, Class<T> responseClass) {
super(new EntityOperationBase.EntityIdUriBuilder(entityTypeUri, entityId), responseClass);
}

/**
* Construct a new DefaultGetOperation to return the entity from the given uri
*
* @param uri
* Uri for entity
* @param responseClass
* class to return from the get operation
*/
public DefaultGetOperation(String uri, Class<T> responseClass) {
super(uri, responseClass);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ public static EntityGetOperation<AccessPolicyInfo> get(String accessPolicyId) {
return new DefaultGetOperation<AccessPolicyInfo>(ENTITY_SET, accessPolicyId, AccessPolicyInfo.class);
}

/**
* Create an operation that will retrieve the access policy at the given link
*
* @param link
* the link
* @return the operation
*/
public static EntityGetOperation<AccessPolicyInfo> get(LinkInfo link) {
return new DefaultGetOperation<AccessPolicyInfo>(link.getHref(), AccessPolicyInfo.class);
}

/**
* Create an operation that will retrieve all access policies
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,17 @@ public static EntityGetOperation<AssetInfo> get(String assetId) {
return new DefaultGetOperation<AssetInfo>(ENTITY_SET, assetId, AssetInfo.class);
}

/**
* Get the asset at the given link
*
* @param link
* the link
* @return the get operation
*/
public static EntityGetOperation<AssetInfo> get(LinkInfo link) {
return new DefaultGetOperation<AssetInfo>(link.getHref(), AssetInfo.class);
}

/**
* Create an operation that will list all the assets.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,22 @@ public String getBaseUri() {
public String getContentAccessToken() {
return this.getContent().getContentAccessComponent();
}

/**
* Return a link that gets this locator's access policy
*
* @return the link
*/
public LinkInfo getAccessPolicyLink() {
return getRelationLink("AccessPolicy");
}

/**
* Return a link that gets this locator's asset
*
* @return the link
*/
public LinkInfo getAssetLink() {
return getRelationLink("Asset");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,25 @@ public void canGetLocatorBackFromAsset() throws Exception {
assertEquals(locator.getId(), locators.get(0).getId());

}

@Test
public void canGetAssetFromLocator() throws Exception {
LocatorInfo locator = service.create(Locator.create(accessPolicyInfo.getId(), assetInfo.getId(),
LocatorType.SAS));

AssetInfo asset = service.get(Asset.get(locator.getAssetLink()));

assertEquals(assetInfo.getId(), asset.getId());
}

@Test
public void canGetAccessPolicyFromLocator() throws Exception {
LocatorInfo locator = service.create(Locator.create(accessPolicyInfo.getId(), assetInfo.getId(),
LocatorType.SAS));

AccessPolicyInfo accessPolicy = service.get(AccessPolicy.get(locator.getAccessPolicyLink()));

assertEquals(accessPolicyInfo.getId(), accessPolicy.getId());

}
}

0 comments on commit d9dc999

Please sign in to comment.