Skip to content

Commit

Permalink
Merge pull request Azure#28 from gcheng/listQuery
Browse files Browse the repository at this point in the history
Enable list query to pass query parameters.
  • Loading branch information
Albert Cheng committed Oct 16, 2012
2 parents 8c965a4 + 00bb3a6 commit b742e42
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ public AssetInfo getAsset(String assetId) throws ServiceException {
@Override
public List<AssetInfo> listAssets(ListAssetsOptions listAssetsOptions) {
WebResource resource = getResource("Assets");
if ((listAssetsOptions != null) && (listAssetsOptions.getQueryParameters() != null)) {
resource = resource.queryParams(listAssetsOptions.getQueryParameters());
}

return resource.type(MediaType.APPLICATION_ATOM_XML).accept(MediaType.APPLICATION_ATOM_XML)
.get(new GenericType<List<AssetInfo>>() {
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;

import javax.inject.Named;
import javax.ws.rs.core.UriBuilder;
Expand All @@ -35,10 +37,28 @@ public URI getBaseURI() {
}

public URI getRedirectedURI(URI originalURI) {
return UriBuilder.fromUri(baseURI).path(originalURI.getPath()).build();
UriBuilder uriBuilder = UriBuilder.fromUri(baseURI).path(originalURI.getPath());
String queryString = originalURI.getQuery();

if (queryString != null && !queryString.isEmpty()) {
uriBuilder.replaceQuery(queryString);
}
return uriBuilder.build();
}

public void setRedirectedURI(String newURI) throws URISyntaxException {
baseURI = new URI(newURI);
}

private Map<String, String> parseQueryString(String queryString) {
Map<String, String> map = new HashMap<String, String>();
String[] params = queryString.split("&");
for (String param : params) {
String key = param.split("=")[0];
String value = param.split("=")[1];
map.put(key, value);
}
return map;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
* Options class for listing access policies
* No options available at this time.
*/
public class ListAccessPolicyOptions {
public class ListAccessPolicyOptions extends ListOptions {

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
*/
package com.microsoft.windowsazure.services.media.models;

public class ListAssetsOptions {
public class ListAssetsOptions extends ListOptions {

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
/**
* The Class ListLocatorsOptions.
*/
public class ListLocatorsOptions {
public class ListLocatorsOptions extends ListOptions {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright 2012 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 javax.ws.rs.core.MultivaluedMap;
import com.sun.jersey.core.util.MultivaluedMapImpl;

/**
* The Class ListOptions.
*/
public class ListOptions {

/**
* Instantiates a new list options.
*/
public ListOptions() {
this.queryParameters = new MultivaluedMapImpl();
}

/** The query parameters. */
protected MultivaluedMap<String, String> queryParameters;

/**
* Gets the query parameters.
*
* @return the query parameters
*/
public MultivaluedMap<String, String> getQueryParameters() {
return this.queryParameters;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.microsoft.windowsazure.services.media.models.CreateAssetOptions;
import com.microsoft.windowsazure.services.media.models.CreateLocatorOptions;
import com.microsoft.windowsazure.services.media.models.EncryptionOption;
import com.microsoft.windowsazure.services.media.models.ListAssetsOptions;
import com.microsoft.windowsazure.services.media.models.ListLocatorsResult;
import com.microsoft.windowsazure.services.media.models.ListMediaProcessorsOptions;
import com.microsoft.windowsazure.services.media.models.ListMediaProcessorsResult;
Expand Down Expand Up @@ -226,6 +227,27 @@ public void listAssetSuccess() throws ServiceException {

}

@Test
public void listTopThreeAssetsSuccess() throws ServiceException {
// Arrange
Collection<AssetInfo> listAssetResultBaseLine = service.listAssets();
CreateAssetOptions createAssetOptions = new CreateAssetOptions();
service.createAsset(createAssetOptions.setName(testAssetPrefix + "assetA"));
service.createAsset(createAssetOptions.setName(testAssetPrefix + "assetB"));
service.createAsset(createAssetOptions.setName(testAssetPrefix + "assetC"));
service.createAsset(createAssetOptions.setName(testAssetPrefix + "assetD"));
ListAssetsOptions listAssetsOptions = new ListAssetsOptions();
listAssetsOptions.getQueryParameters().add("$top", "3");

// Act
Collection<AssetInfo> listAssetResult = service.listAssets(listAssetsOptions);

// Assert
assertNotNull("listAssetResult", listAssetResult);
assertEquals("listAssetResult.size", 3, listAssetResult.size());

}

@Ignore
// Bug https://github.com/WindowsAzure/azure-sdk-for-java-pr/issues/364
@Test
Expand Down

0 comments on commit b742e42

Please sign in to comment.