Skip to content
Browse files

Hack fix for short url bug in current API

  • Loading branch information...
1 parent 346d200 commit b0411e003563a2ed2c659ab6f77d50e3c96ba63d Matthew Wall committed Sep 3, 2010
View
2 client/src/main/java/com/gu/openplatform/contentapi/Content.java
@@ -69,7 +69,7 @@ public boolean hasField(String fieldName) {
}
public boolean hasField(FieldType fieldType) {
- return fields.containsKey(fieldType.asApiUrlParameter());
+ return fields.containsKey(fieldType.getName());
}
public String getField(String fieldName) {
View
28 client/src/main/java/com/gu/openplatform/contentapi/FieldType.java
@@ -16,26 +16,52 @@
package com.gu.openplatform.contentapi;
+import java.util.HashMap;
+import java.util.Map;
+
public class FieldType implements ApiUrlParameter {
+ // TODO: Hack for short URLs. Remove when API is fixed!
+ private static final Map<String, String> overrides = new HashMap<String, String>();
+
+ static {
+ overrides.put("shortUrl", "short-url");
+ }
+
public static final FieldType headline = typeFor("headline");
public static final FieldType byline = typeFor("byline");
public static final FieldType shortUrl = typeFor("shortUrl");
public static final FieldType showAllFields = typeFor("all");
static FieldType typeFor(String name) {
- return new FieldType(name);
+ String override = overrides.get(name);
+
+ if (override == null)
+ return new FieldType(name);
+
+ return new FieldType(name, override);
}
private final String name;
+ private final String override;
+
+ private FieldType(String name, String override) {
+ this.name = name;
+ this.override = override;
+ }
private FieldType(String name) {
this.name = name;
+ this.override = name;
}
@Override
public String asApiUrlParameter() {
+ return override;
+ }
+
+ public String getName() {
return name;
}
View
3 client/src/test/java/com/gu/example/ExampleContentSearchTest.java
@@ -252,7 +252,10 @@ public void testCanSearchForShortUrls() throws Exception {
.showField(FieldType.shortUrl)
.execute();
+ System.out.println(results.getContent());
+
checkResponseOK();
+
for (Content content : results.getContent())
assertTrue(content.hasField(FieldType.shortUrl));
}
View
2 client/src/test/java/com/gu/openplatform/contentapi/FirstItemInIndexAwareTest.java
@@ -38,7 +38,7 @@ public static void setUpClass() throws Exception {
.getFirst();
assertThat(firstItemInIndex, notNullValue());
- // assertTrue(firstItemInIndex.hasField("shortUrl"));
+ assertTrue(firstItemInIndex.hasField("shortUrl"));
firstItemInIndexApiUrl = firstItemInIndex.getApiUrl().toString();
firstItemInIndexWebUrl = firstItemInIndex.getWebUrl().toString();

0 comments on commit b0411e0

Please sign in to comment.
Something went wrong with that request. Please try again.