Search in sources :

Example 1 with PropertyJsonBean

use of org.ff4j.property.util.PropertyJsonBean in project ff4j by ff4j.

the class PropertyJsonParser method parsePropertyMap.

/**
 * Map of property.
 *
 * @param fMap
 *      map of properties
 * @return
 *      property
 */
@SuppressWarnings("unchecked")
public static Property<?> parsePropertyMap(Map<String, Object> fMap) {
    PropertyJsonBean pf = new PropertyJsonBean();
    pf.setName((String) fMap.get("name"));
    pf.setDescription((String) fMap.get("description"));
    pf.setType((String) fMap.get("type"));
    pf.setValue((String) fMap.get("value"));
    if (fMap.containsKey(FIXED_VALUES)) {
        List<String> dbList = (ArrayList<String>) fMap.get(FIXED_VALUES);
        if (dbList != null) {
            for (Object item : dbList) {
                pf.addFixedValue((String) item);
            }
        }
    }
    return pf.asProperty();
}
Also used : ArrayList(java.util.ArrayList) PropertyJsonBean(org.ff4j.property.util.PropertyJsonBean)

Example 2 with PropertyJsonBean

use of org.ff4j.property.util.PropertyJsonBean in project ff4j by ff4j.

the class MongoPropertyMapper method fromStore.

/**
 * Map a property.
 *
 * @param dbObject
 *      db object
 * @return
 *      list of property
 */
public Property<?> fromStore(DBObject dbObject) {
    PropertyJsonBean pf = new PropertyJsonBean();
    pf.setName((String) dbObject.get(PROPERTY_NAME));
    pf.setDescription((String) dbObject.get(PROPERTY_DESCRIPTION));
    pf.setType((String) dbObject.get(PROPERTY_TYPE));
    pf.setValue((String) dbObject.get(PROPERTY_VALUE));
    if (dbObject.containsField(PROPERTY_FIXEDVALUES)) {
        BasicDBList dbList = (BasicDBList) dbObject.get(PROPERTY_FIXEDVALUES);
        if (dbList != null) {
            for (Object item : dbList) {
                pf.addFixedValue((String) item);
            }
        }
    }
    return pf.asProperty();
}
Also used : BasicDBList(com.mongodb.BasicDBList) DBObject(com.mongodb.DBObject) PropertyJsonBean(org.ff4j.property.util.PropertyJsonBean)

Example 3 with PropertyJsonBean

use of org.ff4j.property.util.PropertyJsonBean in project ff4j by ff4j.

the class PropertyTest method testPropertyJsonBeanFromScratchBis.

@Test
public void testPropertyJsonBeanFromScratchBis() {
    PropertyJsonBean jb = new PropertyJsonBean();
    jb.setName("name");
    jb.setType(PropertyString.class.getName());
    jb.setFixedValues(null);
    jb.addFixedValue("AMER");
    jb.addFixedValue("XRZ");
    jb.setValue("AMER");
    Assert.assertNotNull(jb.toString());
}
Also used : PropertyString(org.ff4j.property.PropertyString) PropertyJsonBean(org.ff4j.property.util.PropertyJsonBean) Test(org.junit.Test)

Example 4 with PropertyJsonBean

use of org.ff4j.property.util.PropertyJsonBean in project ff4j by ff4j.

the class FeatureDBObjectMapper method mapProperty.

/**
 * Map a property.
 *
 * @param dbObject
 *      db object
 * @return
 *      list of property
 */
public Property<?> mapProperty(DBObject dbObject) {
    PropertyJsonBean pf = new PropertyJsonBean();
    pf.setName((String) dbObject.get(PROPERTY_NAME));
    pf.setDescription((String) dbObject.get(PROPERTY_DESCRIPTION));
    pf.setType((String) dbObject.get(PROPERTY_TYPE));
    pf.setValue((String) dbObject.get(PROPERTY_VALUE));
    if (dbObject.containsField(PROPERTY_FIXEDVALUES)) {
        BasicDBList dbList = (BasicDBList) dbObject.get(PROPERTY_FIXEDVALUES);
        if (dbList != null) {
            for (Object item : dbList) {
                pf.addFixedValue((String) item);
            }
        }
    }
    return pf.asProperty();
}
Also used : BasicDBList(com.mongodb.BasicDBList) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject) PropertyJsonBean(org.ff4j.property.util.PropertyJsonBean)

Example 5 with PropertyJsonBean

use of org.ff4j.property.util.PropertyJsonBean in project ff4j by ff4j.

the class FeatureJsonParserTest method assertMarshalling.

/**
 * Check serialized string against json serializer.
 *
 * @param json
 *            json value
 * @param feat
 *            feature
 */
private void assertMarshalling(Feature feat) throws Exception {
    Map<String, Property<?>> props = feat.getCustomProperties();
    if (props != null && !props.isEmpty()) {
        // Custom properties are unforce to PropertyJsonBean
        for (String pName : props.keySet()) {
            PropertyJsonBean pjb = new PropertyJsonBean(props.get(pName));
            Assert.assertEquals(marshallWithJackson(pjb), pjb.asJson());
        }
        feat.setCustomProperties(new HashMap<String, Property<?>>());
    }
    Assert.assertEquals(marshallWithJackson(feat), feat.toJson());
    feat.setCustomProperties(props);
}
Also used : Property(org.ff4j.property.Property) PropertyJsonBean(org.ff4j.property.util.PropertyJsonBean)

Aggregations

PropertyJsonBean (org.ff4j.property.util.PropertyJsonBean)9 PropertyString (org.ff4j.property.PropertyString)4 Test (org.junit.Test)4 DBObject (com.mongodb.DBObject)3 BasicDBList (com.mongodb.BasicDBList)2 ArrayList (java.util.ArrayList)2 BasicDBObject (com.mongodb.BasicDBObject)1 Property (org.ff4j.property.Property)1