Skip to content

Commit

Permalink
Add rich text (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
mariobodemann authored Nov 12, 2018
1 parent 3a0bd22 commit e7a0c41
Show file tree
Hide file tree
Showing 93 changed files with 3,464 additions and 485 deletions.
2 changes: 1 addition & 1 deletion .buildscript/deploy_snapshot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ else
fi

echo "Deploying snapshot to jitpack ..."
curl https://jitpack.io/com/github/contentful/contentful.java/${TRAVIS_BRANCH}-SNAPSHOT
curl --verbose --location "https://jitpack.io/com/github/contentful/contentful.java/${TRAVIS_BRANCH}-SNAPSHOT/"
echo "Snapshot deployed to jitpack!"

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ language: java
sudo: false

jdk:
- openjdk7
- openjdk8
- oraclejdk8
- oraclejdk9

script:
- mvn jacoco:prepare-agent test jacoco:report
Expand Down
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## Version [10.2.0] - (2018-11-12)
- Add [rich text](https://www.contentful.com/developers/docs/concepts/rich-text/) to entry types.

## Version [10.1.0] - (2018-05-22)
- Add `png8` image option for returning images in png with up to 256 colours.
- Make `sync` environment aware.
Expand Down Expand Up @@ -221,8 +224,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## Version 1.0.0 - 2014-08-13
Initial release.

[unreleased]: https://github.com/contentful/contentful.java/compare/java-sdk-10.1.0...HEAD
[10.0.0]: https://github.com/contentful/contentful.java/compare/java-sdk-10.0.0...java-sdk-10.1.0
[unreleased]: https://github.com/contentful/contentful.java/compare/java-sdk-10.2.0...HEAD
[10.2.0]: https://github.com/contentful/contentful.java/compare/java-sdk-10.1.0...java-sdk-10.2.0
[10.1.0]: https://github.com/contentful/contentful.java/compare/java-sdk-10.0.0...java-sdk-10.1.0
[10.0.0]: https://github.com/contentful/contentful.java/compare/java-sdk-9.1.1...java-sdk-10.0.0
[9.1.1]: https://github.com/contentful/contentful.java/compare/java-sdk-9.1.0...java-sdk-9.1.1
[9.1.0]: https://github.com/contentful/contentful.java/compare/java-sdk-9.0.1...java-sdk-9.1.0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Install the Contentful dependency:
compile 'com.contentful.java:java-sdk:10.0.0'
```

This SDK requires Java 7 (or higher version) or Android 5.
This SDK requires Java 8 (or higher version) or Android 5.

Client Creation
---------------
Expand Down
18 changes: 6 additions & 12 deletions checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
<!-- Checks for common coding problems -->
<!-- See http://checkstyle.sf.net/config_coding.html -->
<module name="CovariantEquals"/>
<module name="DoubleCheckedLocking"/>
<module name="EmptyStatement"/>
<module name="EqualsAvoidNull"/>
<module name="EqualsHashCode"/>
Expand All @@ -107,10 +106,6 @@
<property name="ignoreNumbers" value="-1,0,1,2,10,100,255,16777215"/>
</module>
<module name="MissingSwitchDefault"/>
<module name="RedundantThrows">
<property name="allowUnchecked" value="true"/>
<property name="allowSubclasses" value="true"/>
</module>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>

Expand All @@ -126,13 +121,12 @@
<module name="TodoComment"/>
<module name="UpperEll"/>

<module name="FileContentsHolder"/>
</module>

<!-- Disable checkstyle for to long lines of code -->
<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="BEGIN TO LONG CODE LINES"/>
<property name="onCommentFormat" value="END TO LONG CODE LINES"/>
<property name="checkFormat" value="LineLengthCheck"/>
<!-- Disable checkstyle for to long lines of code -->
<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="BEGIN TO LONG CODE LINES"/>
<property name="onCommentFormat" value="END TO LONG CODE LINES"/>
<property name="checkFormat" value="LineLengthCheck"/>
</module>
</module>
</module>
15 changes: 11 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>com.contentful.java</groupId>
<artifactId>java-sdk</artifactId>
<version>10.1.1-SNAPSHOT</version>
<version>10.2.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>${project.groupId}:${project.artifactId}</name>
Expand Down Expand Up @@ -45,7 +45,7 @@
<project.reporting.sourceEncoding>UTF-8</project.reporting.sourceEncoding>

<!-- Compilation -->
<java.version>1.6</java.version>
<java.version>1.8</java.version>

<!-- Dependencies -->
<retrofit.version>2.3.0</retrofit.version>
Expand Down Expand Up @@ -220,8 +220,15 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<version>3.0.0</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.12</version>
</dependency>
</dependencies>
<configuration>
<failsOnError>true</failsOnError>
<configLocation>checkstyle.xml</configLocation>
<consoleOutput>true</consoleOutput>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/contentful/java/cda/AbsQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public abstract class AbsQuery<

final CDAClient client;

final Map<String, String> params = new HashMap<String, String>();
final Map<String, String> params = new HashMap<>();

AbsQuery(Class<Resource> type, CDAClient client) {
this.type = type;
Expand Down Expand Up @@ -357,7 +357,7 @@ public Query reverseOrderBy(String key) {
* Limits the amount of elements to a given number.
* <p>
* If more then the number given elements are present, you can use {@link #skip(int)} and
* {@link #limit(int)} for pagination.
* {@see #limit(int)} for pagination.
*
* @param limit a non negative number less than 1001 to include elements.
* @return the calling query for chaining.
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/contentful/java/cda/ArrayResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
*
* @see CDAResource
*/
abstract class ArrayResource extends CDAResource {
public abstract class ArrayResource extends CDAResource {
private static final long serialVersionUID = -2702554830040250962L;
List<CDAResource> items;

Map<String, CDAAsset> assets;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/contentful/java/cda/CDAArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Collection of CDA resources.
*/
public class CDAArray extends ArrayResource {
private static final long serialVersionUID = 6596224363025698245L;
int total;

int skip;
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/contentful/java/cda/CDAAsset.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*/
public class CDAAsset extends LocalizedResource {

private static final long serialVersionUID = -4645571481643616657L;

/**
* @return title of this asset.
*/
Expand Down Expand Up @@ -53,7 +55,7 @@ public String urlForImageWith(ImageOption... options) {
}

final Map<String, ImageOption> mappedOptions
= new LinkedHashMap<String, ImageOption>(options.length);
= new LinkedHashMap<>(options.length);

for (final ImageOption option : options) {
mappedOptions.put(option.getOperation(), option);
Expand Down
87 changes: 33 additions & 54 deletions src/main/java/com/contentful/java/cda/CDAClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import io.reactivex.functions.Function;
import okhttp3.Call;
import okhttp3.OkHttpClient;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
Expand Down Expand Up @@ -126,7 +125,7 @@ private static CDAService createService(Builder clientBuilder) {
* @see #fetchSpace()
*/
public <T extends CDAResource> FetchQuery<T> fetch(Class<T> type) {
return new FetchQuery<T>(type, this);
return new FetchQuery<>(type, this);
}

/**
Expand All @@ -140,7 +139,7 @@ public <T extends CDAResource> FetchQuery<T> fetch(Class<T> type) {
* @see #observeSpace()
*/
public <T extends CDAResource> ObserveQuery<T> observe(Class<T> type) {
return new ObserveQuery<T>(type, this);
return new ObserveQuery<>(type, this);
}

/**
Expand Down Expand Up @@ -223,7 +222,7 @@ public Flowable<Integer> observeContentTypeCachePopulation(final int limit) {
.all()
.map(
new Function<CDAArray, CDAArray>() {
@Override public CDAArray apply(CDAArray array) throws Exception {
@Override public CDAArray apply(CDAArray array) {
if (array.skip() + array.limit() < array.total()) {
return nextPage(array);
} else {
Expand All @@ -250,20 +249,18 @@ private CDAArray nextPage(CDAArray array) {
}
)
.map(
new Function<CDAArray, Integer>() {
@Override public Integer apply(CDAArray array) throws Exception {
for (CDAResource resource : array.items) {
if (resource instanceof CDAContentType) {
cache.types().put(resource.id(), (CDAContentType) resource);
} else {
throw new IllegalStateException(
"Requesting a list of content types should not return "
+ "any other type.");
}
array -> {
for (CDAResource resource : array.items) {
if (resource instanceof CDAContentType) {
cache.types().put(resource.id(), (CDAContentType) resource);
} else {
throw new IllegalStateException(
"Requesting a list of content types should not return "
+ "any other type.");
}

return array.total;
}

return array.total;
}
);
}
Expand Down Expand Up @@ -363,40 +360,26 @@ public <C extends CDACallback<CDASpace>> C fetchSpace(C callback) {
* @return an {@link Flowable} that fetches the space for this client.
*/
public Flowable<CDASpace> observeSpace() {
return service.space(spaceId).map(new Function<Response<? extends CDASpace>, CDASpace>() {
@Override public CDASpace apply(Response<? extends CDASpace> response) throws Exception {
return fromResponse(response);
}
});
return service.space(spaceId).map(ResourceFactory::fromResponse);
}

/**
* Caching
*/
Flowable<Cache> cacheAll(final boolean invalidate) {
return cacheLocales(invalidate)
.flatMap(new Function<List<CDALocale>, Flowable<Map<String, CDAContentType>>>() {
@Override public Flowable<Map<String, CDAContentType>> apply(List<CDALocale> locales) {
return cacheTypes(invalidate);
}
})
.map(new Function<Map<String, CDAContentType>, Cache>() {
@Override public Cache apply(Map<String, CDAContentType> stringCDAContentTypeMap) {
return cache;
}
});
.flatMap(locales -> cacheTypes(invalidate))
.map(stringCDAContentTypeMap -> cache);
}

Flowable<List<CDALocale>> cacheLocales(boolean invalidate) {
List<CDALocale> locales = invalidate ? null : cache.locales();
if (locales == null) {
return service.array(spaceId, environmentId, PATH_LOCALES, new HashMap<String, String>())
.map(new Function<Response<CDAArray>, List<CDALocale>>() {
@Override public List<CDALocale> apply(Response<CDAArray> localesResponse) {
final List<CDALocale> locales = fromArrayToItems(fromResponse(localesResponse));
cache.setLocales(locales);
return locales;
}
return service.array(spaceId, environmentId, PATH_LOCALES, new HashMap<>())
.map(localesResponse -> {
final List<CDALocale> locales1 = fromArrayToItems(fromResponse(localesResponse));
cache.setLocales(locales1);
return locales1;
});
}
return Flowable.just(locales);
Expand All @@ -409,18 +392,16 @@ Flowable<Map<String, CDAContentType>> cacheTypes(boolean invalidate) {
spaceId,
environmentId,
PATH_CONTENT_TYPES,
new HashMap<String, String>()
new HashMap<>()
).map(
new Function<Response<CDAArray>, Map<String, CDAContentType>>() {
@Override public Map<String, CDAContentType> apply(Response<CDAArray> arrayResponse) {
CDAArray array = ResourceFactory.array(arrayResponse, CDAClient.this);
Map<String, CDAContentType> tmp = new ConcurrentHashMap<String, CDAContentType>();
for (CDAResource resource : array.items()) {
tmp.put(resource.id(), (CDAContentType) resource);
}
cache.setTypes(tmp);
return tmp;
arrayResponse -> {
CDAArray array = ResourceFactory.array(arrayResponse, CDAClient.this);
Map<String, CDAContentType> tmp = new ConcurrentHashMap<>();
for (CDAResource resource : array.items()) {
tmp.put(resource.id(), (CDAContentType) resource);
}
cache.setTypes(tmp);
return tmp;
});
}
return Flowable.just(types);
Expand All @@ -432,13 +413,11 @@ Flowable<CDAContentType> cacheTypeWithId(String id) {
return observe(CDAContentType.class)
.one(id)
.map(
new Function<CDAContentType, CDAContentType>() {
@Override public CDAContentType apply(CDAContentType resource) {
if (resource != null) {
cache.types().put(resource.id(), resource);
}
return resource;
resource -> {
if (resource != null) {
cache.types().put(resource.id(), resource);
}
return resource;
}
);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/contentful/java/cda/CDAContentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Represents a single content type.
*/
public class CDAContentType extends CDAResource {
private static final long serialVersionUID = 7901798878659781364L;
List<CDAField> fields;

String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*/
public class CDAContentTypeNotFoundException extends RuntimeException {

private static final long serialVersionUID = -5839900656195732862L;

/**
* Create a new exception.
*
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/contentful/java/cda/CDAEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* The class represents a basic entry in the space.
*/
public class CDAEntry extends LocalizedResource {
private static final long serialVersionUID = 5902790363045498307L;
private CDAContentType contentType;

/**
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/contentful/java/cda/CDAField.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

/** Represents a single content type field. */
public class CDAField implements Serializable {
private static final long serialVersionUID = -2852530837647669035L;
String name;

String id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* This class will represent known Contentful exceptions
*/
public class CDAHttpException extends RuntimeException {
private static final long serialVersionUID = 637581021148308658L;
private final Request request;
private final Response response;
private final String responseBody;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/contentful/java/cda/CDALocale.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Represents a single locale.
*/
public class CDALocale extends CDAResource {
private static final long serialVersionUID = -5710267672379169621L;
String code;

String name;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/contentful/java/cda/CDAResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* for CDAContentType, CDASpace and, indirectly, for CDAEntry.
*/
public abstract class CDAResource implements Serializable {
private static final long serialVersionUID = -160701290783423915L;
@SerializedName("sys")
Map<String, Object> attrs;

Expand Down
Loading

0 comments on commit e7a0c41

Please sign in to comment.