Skip to content

Commit

Permalink
Support search queries
Browse files Browse the repository at this point in the history
  • Loading branch information
tomxor committed Jun 10, 2015
1 parent a3ab57b commit b4bc45d
Show file tree
Hide file tree
Showing 19 changed files with 229 additions and 100 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## Version [1.0.0][unreleased] - (in development)

- New: Add support for search queries via fetchAll() methods.
- Fixed: Add missing description attribute to `CMAContentType`.

## Version [0.9.7] - 2015-02-23
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<commonsio.version>2.4</commonsio.version>
<junit.version>4.11</junit.version>
<kotlin.version>0.11.91.4</kotlin.version>
<okhttp.version>2.3.0</okhttp.version>
<okhttp.version>2.4.0</okhttp.version>
<rxjava.version>1.0.11</rxjava.version>
<mockito.version>1.10.8</mockito.version>
<android.version>4.1.1.4</android.version>
Expand Down
37 changes: 31 additions & 6 deletions src/main/java/com/contentful/java/cma/ModuleAssets.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.contentful.java.cma.model.CMAArray;
import com.contentful.java.cma.model.CMAAsset;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executor;
import retrofit.RestAdapter;
import retrofit.RetrofitError;
Expand Down Expand Up @@ -50,7 +51,7 @@ public CMAAsset archive(CMAAsset asset) {
assertNotNull(asset, "asset");
String assetId = getResourceIdOrThrow(asset, "asset");
String spaceId = getSpaceIdOrThrow(asset, "asset");
return service.archive(spaceId, assetId);
return service.archive(spaceId, assetId, new Byte[0]);
}

/**
Expand Down Expand Up @@ -107,8 +108,19 @@ public Response delete(String spaceId, String assetId) {
* @return {@link CMAArray} result instance
*/
public CMAArray<CMAAsset> fetchAll(String spaceId) {
return fetchAll(spaceId, null);
}

/**
* Fetch all Assets from a Space with a query.
*
* @param spaceId Space ID
* @param query Query
* @return {@link CMAArray} result instance
*/
public CMAArray<CMAAsset> fetchAll(String spaceId, Map<String, String> query) {
assertNotNull(spaceId, "spaceId");
return service.fetchAll(spaceId);
return service.fetchAll(spaceId, query);
}

/**
Expand All @@ -135,7 +147,7 @@ public Response process(CMAAsset asset, String locale) {
assertNotNull(asset, "asset");
String assetId = getResourceIdOrThrow(asset, "asset");
String spaceId = getSpaceIdOrThrow(asset, "asset");
return service.process(spaceId, assetId, locale);
return service.process(spaceId, assetId, locale, new Byte[0]);
}

/**
Expand All @@ -148,7 +160,7 @@ public CMAAsset publish(CMAAsset asset) {
assertNotNull(asset, "asset");
String assetId = getResourceIdOrThrow(asset, "asset");
String spaceId = getSpaceIdOrThrow(asset, "asset");
return service.publish(asset.getVersion(), spaceId, assetId);
return service.publish(asset.getVersion(), spaceId, assetId, new Byte[0]);
}

/**
Expand Down Expand Up @@ -264,11 +276,24 @@ public CMACallback<Response> delete(final String spaceId, final String assetId,
* @param callback Callback
* @return the given {@code CMACallback} instance
*/
public CMACallback<CMAArray<CMAAsset>> fetchAll(final String spaceId,
public CMACallback<CMAArray<CMAAsset>> fetchAll(String spaceId,
CMACallback<CMAArray<CMAAsset>> callback) {
return fetchAll(spaceId, null, callback);
}

/**
* Fetch all Assets from a Space with a query.
*
* @param spaceId Space ID
* @param query Query
* @param callback Callback
* @return the given {@code CMACallback} instance
*/
public CMACallback<CMAArray<CMAAsset>> fetchAll(final String spaceId,
final Map<String, String> query, CMACallback<CMAArray<CMAAsset>> callback) {
return defer(new DefFunc<CMAArray<CMAAsset>>() {
@Override CMAArray<CMAAsset> method() {
return ModuleAssets.this.fetchAll(spaceId);
return ModuleAssets.this.fetchAll(spaceId, query);
}
}, callback);
}
Expand Down
32 changes: 29 additions & 3 deletions src/main/java/com/contentful/java/cma/ModuleContentTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.contentful.java.cma.model.CMAArray;
import com.contentful.java.cma.model.CMAContentType;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executor;
import retrofit.RestAdapter;
import retrofit.RetrofitError;
Expand Down Expand Up @@ -95,8 +96,19 @@ public Response delete(String spaceId, String contentTypeId) {
* @return {@link CMAArray} result instance
*/
public CMAArray<CMAContentType> fetchAll(String spaceId) {
return fetchAll(spaceId, null);
}

/**
* Fetch all Content Types from a Space with a query.
*
* @param spaceId Space ID
* @param query Query
* @return {@link CMAArray} result instance
*/
public CMAArray<CMAContentType> fetchAll(String spaceId, Map<String, String> query) {
assertNotNull(spaceId, "spaceId");
return service.fetchAll(spaceId);
return service.fetchAll(spaceId, query);
}

/**
Expand All @@ -122,7 +134,7 @@ public CMAContentType publish(CMAContentType contentType) {
assertNotNull(contentType, "contentType");
String contentTypeId = getResourceIdOrThrow(contentType, "contentType");
String spaceId = getSpaceIdOrThrow(contentType, "contentType");
return service.publish(contentType.getVersion(), spaceId, contentTypeId);
return service.publish(contentType.getVersion(), spaceId, contentTypeId, new Byte[0]);
}

/**
Expand Down Expand Up @@ -210,9 +222,23 @@ public CMACallback<Response> delete(final String spaceId, final String contentTy
*/
public CMACallback<CMAArray<CMAContentType>> fetchAll(final String spaceId,
CMACallback<CMAArray<CMAContentType>> callback) {
return fetchAll(spaceId, null, callback);
}

/**
* Fetch all Content Types from a Space with a query.
*
* @param spaceId Space ID
* @param query Query
* @param callback Callback
* @return the given {@code CMACallback} instance
*/
public CMACallback<CMAArray<CMAContentType>> fetchAll(final String spaceId,
final Map<String, String> query,
CMACallback<CMAArray<CMAContentType>> callback) {
return defer(new DefFunc<CMAArray<CMAContentType>>() {
@Override CMAArray<CMAContentType> method() {
return ModuleContentTypes.this.fetchAll(spaceId);
return ModuleContentTypes.this.fetchAll(spaceId, query);
}
}, callback);
}
Expand Down
33 changes: 29 additions & 4 deletions src/main/java/com/contentful/java/cma/ModuleEntries.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.contentful.java.cma.model.CMAArray;
import com.contentful.java.cma.model.CMAEntry;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executor;
import retrofit.RestAdapter;
import retrofit.RetrofitError;
Expand Down Expand Up @@ -49,7 +50,7 @@ public CMAEntry archive(CMAEntry entry) {
assertNotNull(entry, "entry");
String entryId = getResourceIdOrThrow(entry, "entry");
String spaceId = getSpaceIdOrThrow(entry, "entry");
return service.archive(spaceId, entryId);
return service.archive(spaceId, entryId, new Byte[0]);
}

/**
Expand Down Expand Up @@ -107,8 +108,19 @@ public Response delete(String spaceId, String entryId) {
* @return {@link CMAArray} result instance
*/
public CMAArray<CMAEntry> fetchAll(String spaceId) {
return fetchAll(spaceId, null);
}

/**
* Fetch all Entries from a Space with a query.
*
* @param spaceId Space ID
* @param query Query
* @return {@link CMAArray} result instance
*/
public CMAArray<CMAEntry> fetchAll(String spaceId, Map<String, String> query) {
assertNotNull(spaceId, "spaceId");
return service.fetchAll(spaceId);
return service.fetchAll(spaceId, query);
}

/**
Expand All @@ -134,7 +146,7 @@ public CMAEntry publish(CMAEntry entry) {
assertNotNull(entry, "entry");
String entryId = getResourceIdOrThrow(entry, "entry");
String spaceId = getSpaceIdOrThrow(entry, "entry");
return service.publish(entry.getVersion(), spaceId, entryId);
return service.publish(entry.getVersion(), spaceId, entryId, new Byte[0]);
}

/**
Expand Down Expand Up @@ -253,9 +265,22 @@ public CMACallback<Response> delete(final String spaceId, final String entryId,
*/
public CMACallback<CMAArray<CMAEntry>> fetchAll(final String spaceId,
CMACallback<CMAArray<CMAEntry>> callback) {
return fetchAll(spaceId, null, callback);
}

/**
* Fetch all Entries from a Space with a query.
*
* @param spaceId Space ID
* @param query Query
* @param callback Callback
* @return the given {@code CMACallback} instance
*/
public CMACallback<CMAArray<CMAEntry>> fetchAll(final String spaceId,
final Map<String, String> query, CMACallback<CMAArray<CMAEntry>> callback) {
return defer(new RxExtensions.DefFunc<CMAArray<CMAEntry>>() {
@Override CMAArray<CMAEntry> method() {
return ModuleEntries.this.fetchAll(spaceId);
return ModuleEntries.this.fetchAll(spaceId, query);
}
}, callback);
}
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/com/contentful/java/cma/ServiceAssets.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.contentful.java.cma.model.CMAArray;
import com.contentful.java.cma.model.CMAAsset;
import java.util.Map;
import retrofit.client.Response;
import retrofit.http.Body;
import retrofit.http.DELETE;
Expand All @@ -26,6 +27,7 @@
import retrofit.http.POST;
import retrofit.http.PUT;
import retrofit.http.Path;
import retrofit.http.QueryMap;

/**
* Assets Service.
Expand All @@ -34,7 +36,8 @@ interface ServiceAssets {
@PUT("/spaces/{space}/assets/{asset}/archived")
CMAAsset archive(
@Path("space") String spaceId,
@Path("asset") String assetId);
@Path("asset") String assetId,
@Body Object body);

@POST("/spaces/{space}/assets")
CMAAsset create(
Expand All @@ -54,7 +57,8 @@ Response delete(

@GET("/spaces/{space}/assets")
CMAArray<CMAAsset> fetchAll(
@Path("space") String spaceId);
@Path("space") String spaceId,
@QueryMap Map<String, String> query);

@GET("/spaces/{space}/assets/{asset}")
CMAAsset fetchOne(
Expand All @@ -65,13 +69,15 @@ CMAAsset fetchOne(
Response process(
@Path("space") String spaceId,
@Path("asset") String assetId,
@Path("locale") String locale);
@Path("locale") String locale,
@Body Object body);

@PUT("/spaces/{space}/assets/{asset}/published")
CMAAsset publish(
@Header("X-Contentful-Version") Integer version,
@Path("space") String spaceId,
@Path("asset") String assetId);
@Path("asset") String assetId,
@Body Object body);

@DELETE("/spaces/{space}/assets/{asset}/archived")
CMAAsset unArchive(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.contentful.java.cma.model.CMAArray;
import com.contentful.java.cma.model.CMAContentType;
import java.util.Map;
import retrofit.client.Response;
import retrofit.http.Body;
import retrofit.http.DELETE;
Expand All @@ -26,6 +27,7 @@
import retrofit.http.POST;
import retrofit.http.PUT;
import retrofit.http.Path;
import retrofit.http.QueryMap;

/**
* ContentTypes Service.
Expand All @@ -49,7 +51,8 @@ Response delete(

@GET("/spaces/{space}/content_types")
CMAArray<CMAContentType> fetchAll(
@Path("space") String spaceId);
@Path("space") String spaceId,
@QueryMap Map<String, String> query);

@GET("/spaces/{space}/content_types/{content_type}")
CMAContentType fetchOne(
Expand All @@ -60,7 +63,8 @@ CMAContentType fetchOne(
CMAContentType publish(
@Header("X-Contentful-Version") Integer version,
@Path("space") String spaceId,
@Path("content_type") String contentTypeId);
@Path("content_type") String contentTypeId,
@Body Object body);

@DELETE("/spaces/{space}/content_types/{content_type}/published")
CMAContentType unPublish(
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/com/contentful/java/cma/ServiceEntries.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.contentful.java.cma.model.CMAArray;
import com.contentful.java.cma.model.CMAEntry;
import java.util.Map;
import retrofit.client.Response;
import retrofit.http.Body;
import retrofit.http.DELETE;
Expand All @@ -26,6 +27,7 @@
import retrofit.http.POST;
import retrofit.http.PUT;
import retrofit.http.Path;
import retrofit.http.QueryMap;

/**
* Entries Service.
Expand All @@ -34,7 +36,8 @@ interface ServiceEntries {
@PUT("/spaces/{space}/entries/{entry}/archived")
CMAEntry archive(
@Path("space") String spaceId,
@Path("entry") String entryId);
@Path("entry") String entryId,
@Body Object body);

@POST("/spaces/{space}/entries")
CMAEntry create(
Expand All @@ -61,13 +64,15 @@ CMAEntry fetchOne(

@GET("/spaces/{space}/entries")
CMAArray<CMAEntry> fetchAll(
@Path("space") String spaceId);
@Path("space") String spaceId,
@QueryMap Map<String, String> query);

@PUT("/spaces/{space}/entries/{entry}/published")
CMAEntry publish(
@Header("X-Contentful-Version") Integer version,
@Path("space") String spaceId,
@Path("entry") String entryId);
@Path("entry") String entryId,
@Body Object body);

@DELETE("/spaces/{space}/entries/{entry}/archived")
CMAEntry unArchive(
Expand Down

0 comments on commit b4bc45d

Please sign in to comment.