private void autoWiredFeature(Object bean, Field field) { // Find the required and name parameters AutowiredFF4JFeature annFeature = field.getAnnotation(AutowiredFF4JFeature.class); String featureName = StringUtils.hasLength(annFeature.value()) ? annFeature.value() : field.getName(); Feature feature = readFeature(field, featureName, annFeature.required()); if (feature != null) { if (Feature.class.isAssignableFrom(field.getType())) { injectValue(field, bean, featureName, feature); } else if (Boolean.class.isAssignableFrom(field.getType())) { injectValue(field, bean, featureName, new Boolean(feature.isEnable())); } else if (boolean.class.isAssignableFrom(field.getType())) { injectValue(field, bean, featureName, feature.isEnable()); } else { throw new IllegalArgumentException( "Field annotated with @AutowiredFF4JFeature" + " must inherit from org.ff4j.Feature or be boolean " + field.getType() + " [class=" + bean.getClass().getName() + ", field=" + field.getName() + "]"); } } }
/** {@inheritDoc} */ @Override public void update(Feature fp) { if (fp == null) { throw new IllegalArgumentException("Feature cannot be null nor empty"); } Feature fpExist = read(fp.getUid()); collection.save(MAPPER.toDBObject(fp)); // enable/disable if (fp.isEnable() != fpExist.isEnable()) { if (fp.isEnable()) { enable(fp.getUid()); } else { disable(fp.getUid()); } } }
/** {@inheritDoc} */ @Override public void update(Feature fp) { if (fp == null) { throw new IllegalArgumentException("Feature cannot be null nor empty"); } Feature fpExist = read(fp.getUid()); collection.updateOne( BUILDER.getFeatUid(fp.getUid()), new Document(MONGO_SET, MAPPER.toDocument(fp))); // enable/disable if (fp.isEnable() != fpExist.isEnable()) { if (fp.isEnable()) { enable(fp.getUid()); } else { disable(fp.getUid()); } } }