Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Bring API up to compatibility again
  • Loading branch information
Christian Holm committed Oct 5, 2014
commit 39a4e0a1e89240334555f468f638399677caa0c2
17 changes: 1 addition & 16 deletions src/main/java/com/podio/app/ApplicationFieldType.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ public enum ApplicationFieldType {
*/
NUMBER,

/**
* A field that can hold one or more state values.
*/
STATE,

/**
* Holds an image. Can currently only be used internally by Hoist.
*/
Expand Down Expand Up @@ -86,20 +81,10 @@ public enum ApplicationFieldType {
*/
CATEGORY,

/**
* A question
*/
QUESTION,

/**
* A generic file field to hold many kinds of files
*/
FILE,

/**
* An advanced calculation field
*/
ADVANCED_CALCULATION;
FILE;

@Override
@JsonValue
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/podio/common/ReferenceType.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public enum ReferenceType {
ALERT, APP, APP_FIELD, APP_REVISION, BULLETIN, COMMENT, CONVERSATION,
MESSAGE, FILE, ITEM, ITEM_REVISION, ITEM_VALUE, NOTIFICATION, ORG, PROFILE,
RATING, SPACE, SPACE_MEMBER, STATUS, TASK, USER, WIDGET, QUESTION, QUESTION_ANSWER,
ACTION, MEETING, GRANT, TASK_ACTION, ITEM_PARTICIPATION;
ACTION, MEETING, GRANT, TASK_ACTION, ITEM_PARTICIPATION, VOTE;

@Override
@JsonValue
Expand Down
63 changes: 63 additions & 0 deletions src/main/java/com/podio/item/map/converter/CategoryConverter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.podio.item.map.converter;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.beanutils.ConvertUtils;

import com.podio.app.CategoryOption;

public class CategoryConverter implements FieldConverter {

private final List<CategoryOption> options;

public CategoryConverter(List<CategoryOption> options) {
super();
this.options = options;
}

@Override
public Map<String, ?> fromModel(Object value) {
String stringValue;
if (value.getClass().isEnum()) {
stringValue = value.toString();
stringValue = stringValue.replace(' ', '_');
} else {
stringValue = (String) ConvertUtils.convert(value,
String.class);
}

CategoryOption option = getOptionByText(stringValue);
if (option != null) {
return Collections.singletonMap("value", option.getId());
}

throw new RuntimeException("No state with name " + stringValue
+ " found");
}

private CategoryOption getOptionByText(String text) {
for (CategoryOption option : options) {
if (option.getText().equalsIgnoreCase(text)) {
return option;
}
}

return null;
}

@Override
public Object toModel(Map<String, ?> map, Class modelClass) {
Map<String, Object> option = (Map<String, Object>) map.get("value");

String stringValue = (String) option.get("text");

if (modelClass.isEnum()) {
return Enum.valueOf(modelClass, stringValue.toUpperCase());
} else {
return ConvertUtils.convert(stringValue, modelClass);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
import com.podio.app.ApplicationField;
import com.podio.app.ApplicationFieldType;

public class StateConverterProvider implements FieldConverterProvider {
public class CategoryConverterProvider implements FieldConverterProvider {

@Override
public boolean isSupported(ApplicationFieldType fieldType) {
return fieldType == ApplicationFieldType.STATE;
return fieldType == ApplicationFieldType.CATEGORY;
}

@Override
public FieldConverter getConverter(ApplicationField field,
AnnotatedElement element) {
return new StateConverter(field.getConfiguration().getSettings()
.getAllowedValues());
return new CategoryConverter(field.getConfiguration().getSettings().getOptions());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class FieldConverterRegistry {

static {
REGISTRY.add(new MoneyConverterProvider());
REGISTRY.add(new StateConverterProvider());
REGISTRY.add(new CategoryConverterProvider());
REGISTRY.add(new NumberConverterProvider());
REGISTRY.add(new TextConverterProvider());
REGISTRY.add(new ProgressConverterProvider());
Expand Down
50 changes: 0 additions & 50 deletions src/main/java/com/podio/item/map/converter/StateConverter.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/com/podio/stream/StreamActivityType.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public enum StreamActivityType {

COMMENT, FILE, TASK, RATING, CREATION, UPDATE, ANSWER, MEETING, REFERENCE, GRANT, PARTICIPATION;
COMMENT, FILE, TASK, RATING, CREATION, UPDATE, ANSWER, MEETING, REFERENCE, GRANT, PARTICIPATION, VOTE;

@Override
@JsonValue
Expand Down
19 changes: 11 additions & 8 deletions src/test/java/com/podio/app/AppAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ public void getAppFull() throws JSONException {

ApplicationField stateField = app.getFields().get(0);
Assert.assertEquals(stateField.getStatus(), ApplicationFieldStatus.ACTIVE);
Assert.assertEquals(stateField.getType(), ApplicationFieldType.STATE);
Assert.assertEquals(stateField.getType(), ApplicationFieldType.CATEGORY);
Assert.assertEquals(stateField.getConfiguration().getLabel(),
"Is hired?");
Assert.assertEquals(stateField.getConfiguration().getSettings().getAllowedValues().get(0), "yes");
Assert.assertEquals(stateField.getConfiguration().getSettings().getOptions().get(0).getText(), "yes");

ApplicationField categoryField = app.getFields().get(15);
Assert.assertEquals(categoryField.getType(), ApplicationFieldType.CATEGORY);
Expand Down Expand Up @@ -98,12 +98,14 @@ public void getField() {
ApplicationField field = getAPI().getField(1, 1);

Assert.assertEquals(field.getId(), 1);
Assert.assertEquals(field.getType(), ApplicationFieldType.STATE);
Assert.assertEquals(field.getType(), ApplicationFieldType.CATEGORY);
Assert.assertEquals(field.getExternalId(), "is-hired");
Assert.assertEquals(field.getConfiguration().getLabel(), "Is hired?");
Assert.assertEquals(field.getConfiguration().getDelta(), 0);
Assert.assertEquals(field.getConfiguration().getSettings()
.getAllowedValues(), Arrays.asList("yes", "no"));
Assert.assertEquals(field.getConfiguration().getSettings().getOptions().get(0).getId(), 1);
Assert.assertEquals(field.getConfiguration().getSettings().getOptions().get(0).getStatus(), CategoryOptionStatus.ACTIVE);
Assert.assertEquals(field.getConfiguration().getSettings().getOptions().get(0).getText(), "yes");
Assert.assertEquals(field.getConfiguration().getSettings().getOptions().get(0).getColor(), "D2E4EB");
}

@Test
Expand Down Expand Up @@ -149,8 +151,9 @@ public void updateOrder() {
public void getAppsInSpace() {
List<Application> apps = getAPI().getAppsOnSpace(1);

Assert.assertEquals(apps.size(), 1);
Assert.assertEquals(apps.get(0).getId(), 1);
Assert.assertEquals(apps.size(), 2);
Assert.assertEquals(apps.get(0).getId(), 20);
Assert.assertEquals(apps.get(1).getId(), 1);
}

@Test
Expand All @@ -164,7 +167,7 @@ public void getTopApps() {
@Test
public void getApps() {
List<Application> apps = getAPI().getApps();
Assert.assertEquals(apps.size(), 2);
Assert.assertEquals(apps.size(), 3);

Assert.assertEquals(apps.get(0).getId(), 1);
}
Expand Down
1 change: 0 additions & 1 deletion src/test/java/com/podio/contact/ContactAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public void getContact() {
Assert.assertEquals(contact.getName(), "Christian Holm");
Assert.assertEquals(contact.getAvatar(), new Integer(9));
Assert.assertEquals(contact.getBirthdate(), new LocalDate(1978, 12, 11));
Assert.assertEquals(contact.getOrganization(), "Podio");
Assert.assertEquals(contact.getSkype(), "[email protected]");
Assert.assertEquals(contact.getAbout(), "King of the API, baby!");
Assert.assertEquals(contact.getAddresses().get(0),
Expand Down
15 changes: 8 additions & 7 deletions src/test/java/com/podio/item/ItemAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -110,12 +111,12 @@ public void getItem() {
FieldValuesView field = item.getFields().get(0);
Assert.assertEquals(field.getId(), 1);
Assert.assertEquals(field.getExternalId(), "is-hired");
Assert.assertEquals(field.getType(), ApplicationFieldType.STATE);
Assert.assertEquals(field.getType(), ApplicationFieldType.CATEGORY);
Assert.assertEquals(field.getLabel(), "Is hired?");
Assert.assertEquals(field.getValues().size(), 2);
Assert.assertEquals(field.getValues().get(0).get("value"), "no");
Assert.assertEquals(((Map<String, Object>) field.getValues().get(0).get("value")).get("text"), "no");
Assert.assertEquals(field.getValues().get(0).size(), 1);
Assert.assertEquals(field.getValues().get(1).get("value"), "yes");
Assert.assertEquals(((Map<String, Object>)field.getValues().get(1).get("value")).get("text"), "yes");
Assert.assertEquals(field.getValues().get(1).size(), 1);
Assert.assertEquals(item.getComments().size(), 2);
Assert.assertEquals(item.getRevisions().size(), 1);
Expand All @@ -129,7 +130,7 @@ public void getItem() {
Assert.assertEquals(item.getTags().get(0), "release");
Assert.assertEquals(item.getTags().get(1), "rollout");
Assert.assertEquals(item.isSubscribed(), true);
Assert.assertEquals(item.getUserRatings().size(), 4);
Assert.assertEquals(item.getUserRatings().size(), 5);
Assert.assertEquals(item.getUserRating(RatingType.APPROVED),
new Integer(RatingValue.APPROVED_APPROVES));
Assert.assertEquals(item.getUserRating(RatingType.FIVESTAR),
Expand Down Expand Up @@ -196,13 +197,13 @@ public void getItemRevisionDifference() {
Assert.assertEquals(differences.size(), 2);
Assert.assertEquals(differences.get(0).getId(), 1);
Assert.assertEquals(differences.get(0).getType(),
ApplicationFieldType.STATE);
ApplicationFieldType.CATEGORY);
Assert.assertEquals(differences.get(0).getLabel(), "Is hired?");
Assert.assertEquals(differences.get(0).getFrom().size(), 1);
Assert.assertEquals(differences.get(0).getFrom().get(0).get("value"),
Assert.assertEquals(((Map<String, Object>) differences.get(0).getFrom().get(0).get("value")).get("text"),
"yes");
Assert.assertEquals(differences.get(0).getTo().size(), 1);
Assert.assertEquals(differences.get(0).getTo().get(0).get("value"),
Assert.assertEquals(((Map<String, Object>) differences.get(0).getTo().get(0).get("value")).get("text"),
"no");
}

Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/podio/item/map/ItemMapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ CurrencyUnit.EUR, new BigDecimal("123.45")),
"A mexican in a bar", new BigDecimal("1.2"), 30,
"Ignored"));
Assert.assertEquals(create.getExternalId(), "1");
checkValue(create.getFields(), "is-hired", 0, "value", "yes");
checkValue(create.getFields(), "is-hired", 0, "value", 1);
checkValue(create.getFields(), "alotta-cash", 0, "value", "123.45");
checkValue(create.getFields(), "alotta-cash", 0, "currency", "EUR");
checkValue(create.getFields(), "write-a-joke", 0, "value",
Expand Down Expand Up @@ -57,7 +57,7 @@ public void mapTest2() {
new BugMap2(2, Collections.singletonList("yes"),
new BigDecimal("123.45"), 1.2d, (short) 30));
Assert.assertEquals(create.getExternalId(), "2");
checkValue(create.getFields(), "is-hired", 0, "value", "yes");
checkValue(create.getFields(), "is-hired", 0, "value", 1);
checkValue(create.getFields(), "alotta-cash", 0, "value", "123.45");
checkValue(create.getFields(), "alotta-cash", 0, "currency", "DKK");
checkValue(create.getFields(), "importance", 0, "value", "1.2");
Expand All @@ -78,7 +78,7 @@ public void mapTest3() {
ItemCreate create = getCreate(1,
new BugMap3("3", Collections.singleton("yes"), 123.45, 1.2f));
Assert.assertEquals(create.getExternalId(), "3");
checkValue(create.getFields(), "is-hired", 0, "value", "yes");
checkValue(create.getFields(), "is-hired", 0, "value", 1);
checkValue(create.getFields(), "alotta-cash", 0, "value", "123.45");
checkValue(create.getFields(), "alotta-cash", 0, "currency", "EUR");
checkValue(create.getFields(), "importance", 0, "value", "1.2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ private NotificationAPI getAPI() {
public void getInboxNewCount() {
int count = getAPI().getInboxNewCount();

Assert.assertEquals(count, 57);
Assert.assertEquals(count, 59);
}

@Test
Expand Down
17 changes: 9 additions & 8 deletions src/test/java/com/podio/space/SpaceAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,17 @@ public void endSpaceMembership() {
public void getActiveMembers() {
List<SpaceMember> members = getAPI().getActiveMembers(1);

Assert.assertEquals(members.size(), 3);
Assert.assertEquals(members.get(0).getUser().getUserId().intValue(), 4);
Assert.assertEquals(members.get(1).getUser().getUserId().intValue(), 2);
Assert.assertEquals(members.get(2).getUser().getUserId().intValue(), 1);
Assert.assertEquals(members.get(2).getRole(), Role.ADMIN);
Assert.assertEquals(members.get(2).getInvitedOn(), new DateTime(2010,
Assert.assertEquals(members.size(), 6);
Assert.assertEquals(members.get(0).getUser().getUserId().intValue(), 5);
Assert.assertEquals(members.get(1).getUser().getUserId().intValue(), 4);
Assert.assertEquals(members.get(2).getUser().getUserId().intValue(), 2);
Assert.assertEquals(members.get(3).getUser().getUserId().intValue(), 1);
Assert.assertEquals(members.get(3).getRole(), Role.ADMIN);
Assert.assertEquals(members.get(3).getInvitedOn(), new DateTime(2010,
8, 9, 15, 7, 0, 0, DateTimeZone.UTC));
Assert.assertEquals(members.get(2).getStartedOn(), new DateTime(2010,
Assert.assertEquals(members.get(3).getStartedOn(), new DateTime(2010,
8, 9, 15, 7, 0, 0, DateTimeZone.UTC));
Assert.assertEquals(members.get(2).getEndedOn(), null);
Assert.assertEquals(members.get(3).getEndedOn(), null);
}

@Test
Expand Down
Loading