diff --git a/gen/vsup_is b/gen/vsup_is index 8a42a29c..a96c84ca 100755 --- a/gen/vsup_is +++ b/gen/vsup_is @@ -3,10 +3,12 @@ use strict; use warnings; use perunServicesInit; use perunServicesUtils; +use Time::Piece; +sub resolveExpiration; local $::SERVICE_NAME = "vsup_is"; local $::PROTOCOL_VERSION = "3.0.0"; -my $SCRIPT_VERSION = "3.0.0"; +my $SCRIPT_VERSION = "3.0.1"; perunServicesInit::init; my $DIRECTORY = perunServicesInit::getDirectory; @@ -31,6 +33,7 @@ our $A_BIRTH_NUMBER; *A_BIRTH_NUMBER = \'urn:perun:user:attribute-def:def:birth our $A_GENDER; *A_GENDER = \'urn:perun:user:attribute-def:def:gender'; our $A_JOB; *A_JOB = \'urn:perun:user:attribute-def:def:job'; our $A_EXPIRATION_DC2; *A_EXPIRATION_DC2 = \'urn:perun:user:attribute-def:def:expirationDc2'; +our $A_EXPIRATION_MANUAL; *A_EXPIRATION_MANUAL = \'urn:perun:user:attribute-def:def:expirationManual'; our $A_PHONE; *A_PHONE = \'urn:perun:user:attribute-def:def:phoneDc2'; our $A_EMAIL_PRIV; *A_EMAIL_PRIV = \'urn:perun:user:attribute-def:opt:privateMail'; @@ -73,6 +76,7 @@ foreach my $resourceId ($data->getResourceIds()) { my $gender = $data->getUserAttributeValue(member => $memberId, attrName => $A_GENDER); my $job = $data->getUserAttributeValue(member => $memberId, attrName => $A_JOB); my $expirationDC2 = $data->getUserAttributeValue(member => $memberId, attrName => $A_EXPIRATION_DC2); + my $expirationManual = $data->getUserAttributeValue(member => $memberId, attrName => $A_EXPIRATION_MANUAL); my $phone = $data->getUserAttributeValue(member => $memberId, attrName => $A_PHONE); my $emailPriv = $data->getUserAttributeValue(member => $memberId, attrName => $A_EMAIL_PRIV); my $emailPrivKOS = $data->getUserAttributeValue(member => $memberId, attrName => $A_EMAIL_PRIV_KOS); @@ -94,7 +98,7 @@ foreach my $resourceId ($data->getResourceIds()) { $users->{$key}->{$A_BIRTH_NUMBER} = $birthNumber || ''; $users->{$key}->{$A_GENDER} = $gender || ''; $users->{$key}->{$A_JOB} = $job || ''; - $users->{$key}->{$A_EXPIRATION_DC2} = $expirationDC2 || ''; + $users->{$key}->{$A_EXPIRATION_DC2} = resolveExpiration($expirationDC2, $expirationManual); $users->{$key}->{$A_PHONE} = $phone || ''; $users->{$key}->{$A_EMAIL_PRIV} = $emailPriv || ($emailPrivKOS || ''); @@ -131,3 +135,36 @@ for my $key (@keys) { close(FILE); perunServicesInit::finalize; + +# +# Return latest of two expiration dates (DC2 / Manual) +# +sub resolveExpiration() { + + # read input + my $expirationDc2 = shift; + my $expirationMan = shift; + # parse to time or undef + my $expirationDc2Time = (defined $expirationDc2 and length($expirationDc2) > 0) ? Time::Piece->strptime($expirationDc2,"%Y-%m-%d") : undef; + my $expirationManTime = (defined $expirationMan and length($expirationMan) > 0) ? Time::Piece->strptime($expirationMan,"%Y-%m-%d") : undef; + + my @expirations = (); + if (defined $expirationDc2Time) { push(@expirations, $expirationDc2Time->epoch); } + if (defined $expirationManTime) { push(@expirations, $expirationManTime->epoch); } + + # sort all expirations + my @sorted_expirations = sort { $a <=> $b } @expirations; + my $latest_expiration = $sorted_expirations[$#sorted_expirations]; + + if (defined $latest_expiration) { + if (defined $expirationDc2Time and ($latest_expiration == $expirationDc2Time->epoch)) { + return $expirationDc2; + } + if (defined $expirationManTime and ($latest_expiration == $expirationManTime->epoch)) { + return $expirationMan; + } + } + # expiration not set + return ''; + +}