Skip to content

Commit be9dd2c

Browse files
authored
feat: Add support for taxonomy (#319)
* Add support for taxonomies in metadata * Fix tests * [maven-release-plugin] prepare release java-sdk-10.5.22 * [maven-release-plugin] prepare for next development iteration * Fix tests * update readme.md
1 parent 2795502 commit be9dd2c

11 files changed

Lines changed: 79 additions & 262 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ Install the Contentful dependency:
7676
<dependency>
7777
<groupId>com.contentful.java</groupId>
7878
<artifactId>java-sdk</artifactId>
79-
<version>10.5.21</version>
79+
<version>10.5.22</version>
8080
</dependency>
8181
```
8282

8383
* _Gradle_
8484

8585
```groovy
86-
compile 'com.contentful.java:java-sdk:10.5.21'
86+
compile 'com.contentful.java:java-sdk:10.5.22'
8787
```
8888

8989
This library requires Java 8 (or higher version) or Android 21.

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>com.contentful.java</groupId>
55
<artifactId>java-sdk</artifactId>
6-
<version>10.5.22-SNAPSHOT</version>
6+
<version>10.5.23-SNAPSHOT</version>
77
<packaging>jar</packaging>
88

99
<name>${project.groupId}:${project.artifactId}</name>
@@ -191,7 +191,7 @@
191191
<id>simple-command</id>
192192
<phase>package</phase>
193193
<goals>
194-
<goal>attached</goal>
194+
<goal>single</goal>
195195
</goals>
196196
</execution>
197197
</executions>

src/main/java/com/contentful/java/cda/CDAEntry.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package com.contentful.java.cda;
22

3+
import com.google.gson.annotations.SerializedName;
4+
35
/**
46
* The class represents a basic entry in the space.
57
*/
68
public class CDAEntry extends LocalizedResource {
79
private static final long serialVersionUID = 5902790363045498307L;
810
protected CDAContentType contentType;
11+
@SerializedName("metadata")
912
private CDAMetadata metadata;
1013

1114
/**
@@ -30,6 +33,14 @@ protected void setContentType(CDAContentType contentType) {
3033
this.contentType = contentType;
3134
}
3235

36+
public CDAMetadata getMetadata() {
37+
return metadata;
38+
}
39+
40+
public void setMetadata(CDAMetadata metadata) {
41+
this.metadata = metadata;
42+
}
43+
3344
/**
3445
* Create a human readable string of this object.
3546
* @return a string, containing the id of this content type.

src/main/java/com/contentful/java/cda/CDAMetadata.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,23 @@
22

33
import java.io.Serializable;
44
import java.util.List;
5+
56
public class CDAMetadata implements Serializable {
67
private static final long serialVersionUID = -2852530837647649035L;
8+
private List<CDATag> tags;
9+
private List<CDATaxonomyConcept> concepts;
10+
711
public List<CDATag> getTags() {
812
return tags;
913
}
1014

11-
public void setTags(List<CDATag> tags) {
12-
this.tags = tags;
15+
public List<CDATaxonomyConcept> getConcepts() {
16+
return concepts;
17+
}
18+
19+
public void setConcepts(List<CDATaxonomyConcept> concepts) {
20+
this.concepts = concepts;
1321
}
14-
List<CDATag> tags;
1522

1623
@Override
1724
public String toString() {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.contentful.java.cda;
2+
3+
4+
public class CDATaxonomyConcept extends CDAResource {
5+
@Override
6+
public String toString() {
7+
return "CDATaxonomyConcept{"
8+
+ "attrs=" + attrs
9+
+ '}';
10+
}
11+
}

src/main/java/com/contentful/java/cda/CDAType.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ public enum CDAType {
1010
ENTRY,
1111
LOCALE,
1212
SPACE,
13-
TAG
13+
TAG,
14+
TAXONOMYCONCEPT,
1415
}

src/main/java/com/contentful/java/cda/Constants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@ class Constants {
2424

2525
static final String PATH_TAGS = "tags";
2626

27+
static final String PATH_TAXONOMY_CONCEPTS = "taxonomy/concepts";
28+
2729
static final String DEFAULT_ENVIRONMENT = "master";
2830
}

src/main/java/com/contentful/java/cda/Util.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import static com.contentful.java.cda.CDAType.SPACE;
1313
import static com.contentful.java.cda.CDAType.ENTRY;
1414
import static com.contentful.java.cda.CDAType.CONTENTTYPE;
15+
import static com.contentful.java.cda.CDAType.TAXONOMYCONCEPT;
1516

1617
final class Util {
1718
private Util() {
@@ -46,25 +47,29 @@ static String resourcePath(Class<?> clazz) {
4647
return Constants.PATH_LOCALES;
4748
} else if (CDATag.class.equals(clazz)) {
4849
return Constants.PATH_TAGS;
50+
} else if (CDATaxonomyConcept.class.equals(clazz)) {
51+
return Constants.PATH_TAXONOMY_CONCEPTS;
4952
}
5053
throw new IllegalArgumentException("Invalid type specified: " + clazz.getName());
5154
}
5255

5356
static Class<? extends CDAResource> classForType(CDAType type) {
54-
if (CDAType.ASSET.equals(type)) {
57+
if (ASSET.equals(type)) {
5558
return CDAAsset.class;
56-
} else if (CDAType.CONTENTTYPE.equals(type)) {
59+
} else if (CONTENTTYPE.equals(type)) {
5760
return CDAContentType.class;
58-
} else if (CDAType.ENTRY.equals(type)) {
61+
} else if (ENTRY.equals(type)) {
5962
return CDAEntry.class;
60-
} else if (CDAType.SPACE.equals(type)) {
63+
} else if (SPACE.equals(type)) {
6164
return CDASpace.class;
6265
} else if (LOCALE.equals(type)) {
6366
return CDALocale.class;
6467
} else if (DELETEDASSET.equals(type) || DELETEDENTRY.equals(type)) {
6568
return DeletedResource.class;
6669
} else if (TAG.equals(type)) {
6770
return CDATag.class;
71+
} else if (TAXONOMYCONCEPT.equals(type)) {
72+
return CDATaxonomyConcept.class;
6873
}
6974
throw new IllegalArgumentException("Invalid type provided: " + type);
7075
}
@@ -82,6 +87,8 @@ static CDAType typeForClass(Class<? extends CDAResource> clazz) {
8287
return LOCALE;
8388
} else if (CDATag.class.equals(clazz)) {
8489
return TAG;
90+
} else if (CDATaxonomyConcept.class.equals(clazz)) {
91+
return TAXONOMYCONCEPT;
8592
}
8693
throw new IllegalArgumentException("Invalid class provided: " + clazz.getName());
8794
}

src/test/java/com/contentful/java/cda/EntryTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
import java.util.concurrent.TimeUnit;
1313

1414
import static com.google.common.truth.Truth.assertThat;
15+
import static org.junit.Assert.assertEquals;
16+
import static org.junit.Assert.assertNotNull;
17+
18+
import java.util.ArrayList;
1519

1620
public class EntryTest extends BaseTest {
1721
@Test(expected = CDAResourceNotFoundException.class)
@@ -97,6 +101,17 @@ public void entryContentType() {
97101
assertThat(entry.contentType()).isNotNull();
98102
}
99103

104+
@Test
105+
@Enqueue("demo/entries.json")
106+
public void entryTaxonomy() {
107+
CDAEntry entry = client.fetch(CDAEntry.class).one("ge1xHyH3QOWucKWCCAgIG");
108+
assertThat(entry.contentType()).isNotNull();
109+
assertNotNull(entry.getMetadata());
110+
assertNotNull(entry.getMetadata().getConcepts());
111+
assertEquals(1, entry.getMetadata().getConcepts().size());
112+
}
113+
114+
100115
@Test
101116
@Enqueue("demo/entries_nyancat.json")
102117
public void fetchEntry() {

0 commit comments

Comments
 (0)