Skip to content

Commit

Permalink
Merge remote-tracking branch 'vienin/fix-altered-policies' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
vienin committed Feb 2, 2015
2 parents aa7c3b2 + fd069fe commit 217d9bf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
11 changes: 7 additions & 4 deletions lib/service/Entity/Policy.pm
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,8 @@ sub handlePolicyDefAttribute {

# If the id of the manager defined but do not corresponding to a available value,
# it is an old value, so delete it.
if (not $manager_options->{$args{params}->{$args{attrname}}}) {
if (defined $args{params}->{$args{attrname}} &&
! $manager_options->{$args{params}->{$args{attrname}}}) {
delete $args{params}->{$args{attrname}};
}
# If no manager id defined and and attr is mandatory, use the first one as value
Expand All @@ -440,8 +441,10 @@ sub handlePolicyDefAttribute {
my $managerparams = $manager->$paramsmethod(params => $args{params});

# Add the dynamic attr of the manager to the policy attr def
my @dynamic_attrs = sort { $managerparams->{$a}->{order} <=> $managerparams->{$b}->{order} }
my @dynamic_attrs = sort { ($managerparams->{$a}->{order} || 0)
<=> ($managerparams->{$b}->{order} || 0) }
keys (%{ $managerparams });

for my $dynamic_attrname (@dynamic_attrs) {
$attrdef->{$dynamic_attrname} = $managerparams->{$dynamic_attrname};

Expand All @@ -453,8 +456,8 @@ sub handlePolicyDefAttribute {
}

# Handle the dynamic attr as the static ones, if not done by a manager
# TODO: With the folliwing grep, we do not detect relations single_multi
# handle at the beguining of the merthod
# TODO: With the following grep, we do not detect relations single_multi
# handled at the beguining of the method
if (! scalar(grep { $_ eq $dynamic_attrname } @{ $args{attributes}->{displayed} })) {
$class->handlePolicyDefAttribute(%args, attrname => $dynamic_attrname);
}
Expand Down
7 changes: 4 additions & 3 deletions lib/service/Entity/ServiceTemplate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,14 @@ sub processAlteredPolicies {
# Browse the policy definition and create a derivated policy
# if some empty attributes has been filled.
my $altered = 0;
my $policyattrs = $policyclass->toJSON(params => $json)->{attributes};
my $policyattrs = $policyclass->toJSON(params => $merge->merge($json, \%args))->{attributes};
for my $attrname (keys %{ $policyattrs }) {
my $is_alterable = (defined $args{$attrname} &&
! $policyattrs->{$attrname}->{is_virtual} &&
! exists $policyclass->getPolicySelectorAttrDef->{$attrname});
my $is_altered_scalar = (ref($args{$attrname}) ne "ARRAY" &&
"$args{$attrname}" ne "$json->{$attrname}");
my $is_altered_scalar = ((ref($args{$attrname}) || "") ne "ARRAY" &&
(defined $args{$attrname} ? "$args{$attrname}" : "") ne
(defined $json->{$attrname} ? "$json->{$attrname}" : ""));
my $is_altered_array = (ref($args{$attrname}) eq "ARRAY" &&
General::isArrayDiffers(left => $args{$attrname},
right => $json->{$attrname} || []));
Expand Down

0 comments on commit 217d9bf

Please sign in to comment.