From f432b63413df719e305f3ed65f3142a425ae49d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Zl=C3=A1mal?= Date: Wed, 25 May 2022 10:46:48 +0200 Subject: [PATCH] feat(arcgis_licenses_mu): sort json output to be comparable - Make sure JSON output is sorted in order to easily compare it between script runs when implementation changes. - Sort entries by UCO. - Trailing whitespace cleanup. --- gen/arcgis_licenses_mu | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/gen/arcgis_licenses_mu b/gen/arcgis_licenses_mu index b1da29e5..b21f828f 100755 --- a/gen/arcgis_licenses_mu +++ b/gen/arcgis_licenses_mu @@ -24,7 +24,7 @@ our $A_RESOURCE_ARCGIS_AFFILIATION; *A_RESOURCE_ARCGIS_AFFILIATION = \'urn:perun #Headers my $firstNameHeader = "firstName"; -my $lastNameHeader = "lastName"; +my $lastNameHeader = "lastName"; my $loginHeader = "UCO"; my $rolesHeader = "roles"; my $affiliationHeader = "isActive"; @@ -37,16 +37,16 @@ my $usersWithRoles = {}; my $facilityId = $data->getFacilityId; foreach my $resourceId ( $data->getResourceIds() ) { - + my $roleOnResource = $data->getResourceAttributeValue( attrName => $A_RESOURCE_ARCGIS_ROLE, resource => $resourceId ); my $isResourceActiveForAffiliation = $data->getResourceAttributeValue( attrName => $A_RESOURCE_ARCGIS_AFFILIATION, resource => $resourceId ); - #process all members on resource + #process all members on resource foreach my $memberId ($data->getMemberIdsForResource( resource => $resourceId )) { #skip not VALID members in VO my $statusInVo = $data->getMemberAttributeValue( attrName => $A_MEMBER_STATUS, member => $memberId ); if( $statusInVo ne $statusValid ) { next; } - + my $UCO = $data->getUserFacilityAttributeValue( attrName => $A_USER_LOGIN, member => $memberId, facility => $facilityId ); #if user not exists, create record for him first @@ -87,11 +87,14 @@ for my $key (keys %{$usersWithRoles}) { push @data, $userRecord; } +# order all entries by UCO +@data = sort { $a->{$loginHeader} <=> $b->{$loginHeader} } @data; + #print json to the file my $file = "$DIRECTORY/$::SERVICE_NAME.json"; open FILE,">$file" or die "Cannot open $file: $! \n"; binmode(FILE); -print FILE JSON::XS->new->utf8->pretty->encode(\@data); +print FILE JSON::XS->new->utf8->pretty->canonical->encode(\@data); close (FILE) or die "Cannot close $file: $! \n"; perunServicesInit::finalize;