@Override
public void update(Feature fp) {
if (fp == null) {
throw new IllegalArgumentException("Feature cannot be null nor empty");
}
Feature fpExist = read(fp.getUid());
String enable = "0";
if (fp.isEnable()) {
enable = "1";
}
String fStrategy = null;
String fExpression = null;
if (fp.getFlippingStrategy() != null) {
fStrategy = fp.getFlippingStrategy().getClass().getCanonicalName();
fExpression = ParameterUtils.fromMap(fp.getFlippingStrategy().getInitParams());
}
update(SQL_UPDATE, enable, fp.getDescription(), fStrategy, fExpression, fp.getGroup(), fp.getUid());
// To be deleted : not in second but in first
Set<String> toBeDeleted = new HashSet<String>();
toBeDeleted.addAll(fpExist.getPermissions());
toBeDeleted.removeAll(fp.getPermissions());
for (String roleToBeDelete : toBeDeleted) {
removeRoleFromFeature(fpExist.getUid(), roleToBeDelete);
}
// To be created : in second but not in first
Set<String> toBeAdded = new HashSet<String>();
toBeAdded.addAll(fp.getPermissions());
toBeAdded.removeAll(fpExist.getPermissions());
for (String addee : toBeAdded) {
grantRoleOnFeature(fpExist.getUid(), addee);
}
}