Skip to content

Commit

Permalink
Merge branch 'master' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
Johaney-s committed Dec 9, 2022
2 parents bc2d474 + 6e8e1cb commit 87c46f4
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 14 deletions.
37 changes: 33 additions & 4 deletions gen/denbi_portal_compute_center
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ my $data = perunServicesInit::getHashedDataWithGroups;
sub processUsers;
sub processGroups;
sub processMemberships;
sub getDenbiMembersForGroup;

#Constants
our $A_USER_ID; *A_USER_ID = \'urn:perun:user:attribute-def:core:id';
our $A_USER_STATUS; *A_USER_STATUS = \'urn:perun:member:attribute-def:core:status';
our $A_USER_EMAIL; *A_USER_EMAIL = \'urn:perun:user:attribute-def:def:preferredMail';
our $A_USER_LOGIN; *A_USER_LOGIN = \'urn:perun:user:attribute-def:virt:login-namespace:elixir-persistent';
our $A_USER_LOGIN_PERSISTENT; *A_USER_LOGIN_PERSISTENT = \'urn:perun:user:attribute-def:virt:login-namespace:elixir-persistent';
our $A_USER_LOGIN; *A_USER_LOGIN = \'urn:perun:user:attribute-def:def:login-namespace:elixir';
our $A_USER_MAIL; *A_USER_MAIL = \'urn:perun:user:attribute-def:def:preferredMail';

our $A_GROUP_ID; *A_GROUP_ID = \'urn:perun:group:attribute-def:core:id';
our $A_GROUP_NAME; *A_GROUP_NAME = \'urn:perun:group:attribute-def:core:name';
Expand Down Expand Up @@ -57,8 +60,11 @@ our $STATUS_SUSPENDED; *STATUS_SUSPENDED = \'SUSPENDED';
#urn:perun:user:attribute-def:virt:login-namespace:elixir-persistent | string | ELIXIR login | Login to ELIXIR. It is set automatically with first call. |
#urn:perun:user_facility:attribute-def:opt:denbiVmsRunning | hash | Machines Running | Collection of user-generated running VMs |



#attr friendly names
our $idFriendlyName = "id";
our $mailFriendlyName = "preferredMail";
our $loginFriendlyName = "login-namespace:elixir";
our $persLoginFriendlyName = "login-namespace:elixir-persistent";

my $userStruc = {};
my $groupStruc = {};
Expand Down Expand Up @@ -174,7 +180,9 @@ sub processGroups {
my $gid = $groupAttributes{$A_GROUP_ID};

#convert attributes data
$groupAttributes{$A_GROUP_DENBI_PROJECT_MEMBERS} = decode_json $groupAttributes{$A_GROUP_DENBI_PROJECT_MEMBERS};
#$groupAttributes{$A_GROUP_DENBI_PROJECT_MEMBERS} = decode_json $groupAttributes{$A_GROUP_DENBI_PROJECT_MEMBERS};

$groupAttributes{$A_GROUP_DENBI_PROJECT_MEMBERS} = getDenbiMembersForGroup( $groupId, $resourceId );

unless(exists $groupStruc->{$gid}) {
%groupAttributes = map { convertToFriendlyName($_) => $groupAttributes{$_} } keys %groupAttributes;
Expand All @@ -186,6 +194,27 @@ sub processGroups {
}
}

sub getDenbiMembersForGroup {
my ($groupId, $resourceId) = @_;

my @denbiMembers = ();

foreach my $memberId ( $data->getMemberIdsForResourceAndGroup( group=> $groupId, resource => $resourceId ) ) {
my $userId = $data->getUserAttributeValue( member => $memberId, attrName => $A_USER_ID );
my $email = $data->getUserAttributeValue( member => $memberId, attrName => $A_USER_MAIL );
my $login = $data->getUserAttributeValue( member => $memberId, attrName => $A_USER_LOGIN );
my $persistentLogin = $data->getUserAttributeValue( member => $memberId, attrName => $A_USER_LOGIN_PERSISTENT );
my $member = {};
$member->{$idFriendlyName} = $userId;
$member->{$mailFriendlyName} = $email;
$member->{$loginFriendlyName} = $login;
$member->{$persLoginFriendlyName} = $persistentLogin;
push @denbiMembers, $member;
}

return \@denbiMembers;
}

## creates structure for memberships
sub processMemberships {
my ($gid, $uid) = @_;
Expand Down
44 changes: 34 additions & 10 deletions gen/scs_it4i
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,30 @@ use File::Basename;

our $SERVICE_NAME = basename($0);
our $PROTOCOL_VERSION = "3.0.0";
my $SCRIPT_VERSION = "3.0.0";
my $SCRIPT_VERSION = "3.0.1";

perunServicesInit::init;
my $DIRECTORY = perunServicesInit::getDirectory;
my $data = perunServicesInit::getHashedHierarchicalData;

#Constants
our $A_USER_LOGIN_EINFRA; *A_USER_LOGIN_EINFRA = \'urn:perun:user:attribute-def:def:login-namespace:einfra';
our $A_ORGANIZATION; *A_ORGANIZATION = \'urn:perun:user:attribute-def:def:organization';
our $A_BLOCK_COLLISION; *A_BLOCK_COLLISION = \'urn:perun:user:attribute-def:def:it4iBlockCollision';

our $A_USER_LOGIN_EINFRA_PERSIST; *A_USER_LOGIN_EINFRA_PERSIST = \'urn:perun:user:attribute-def:virt:login-namespace:einfraid-persistent';
our $A_ORGANIZATION; *A_ORGANIZATION = \'urn:perun:user:attribute-def:def:organization';
our $A_BLOCK_COLLISION; *A_BLOCK_COLLISION = \'urn:perun:user:attribute-def:def:it4iBlockCollision';
our $A_COMMON_NAME; *A_COMMON_NAME = \'urn:perun:user:attribute-def:core:commonName';
our $A_DISPLAY_NAME; *A_DISPLAY_NAME = \'urn:perun:user:attribute-def:core:displayName';
our $A_FIRST_NAME; *A_FIRST_NAME = \'urn:perun:user:attribute-def:core:firstName';
our $A_LAST_NAME; *A_LAST_NAME = \'urn:perun:user:attribute-def:core:lastName';
our $A_MIDDLE_NAME; *A_MIDDLE_NAME = \'urn:perun:user:attribute-def:core:middleName';
our $A_TITLE_AFTER; *A_TITLE_AFTER = \'urn:perun:user:attribute-def:core:titleAfter';
our $A_TITLE_BEFORE; *A_TITLE_BEFORE = \'urn:perun:user:attribute-def:core:titleBefore';
our $A_UUID; *A_UUID = \'urn:perun:user:attribute-def:core:uuid';
our $A_COUNTRY; *A_COUNTRY = \'urn:perun:user:attribute-def:def:country';
our $A_PREF_LANGUAGE; *A_PREF_LANGUAGE = \'urn:perun:user:attribute-def:def:preferredLanguage';
our $A_PREF_MAIL; *A_PREF_MAIL = \'urn:perun:user:attribute-def:def:preferredMail';
our $A_INSTIT_COUNTRIES; *A_INSTIT_COUNTRIES = \'urn:perun:user:attribute-def:virt:institutionsCountries';


my $service_file_name = "$DIRECTORY/$::SERVICE_NAME";

Expand All @@ -25,17 +39,27 @@ my $users;
foreach my $memberId ($data->getMemberIdsForFacility()) {

my $collision = $data->getUserAttributeValue( member => $memberId, attrName => $A_BLOCK_COLLISION );
my $login = $data->getUserAttributeValue( member => $memberId, attrName => $A_USER_LOGIN_EINFRA );
my $org = $data->getUserAttributeValue( member => $memberId, attrName => $A_ORGANIZATION ) || "";
my $login = $data->getUserAttributeValue( member => $memberId, attrName => $A_USER_LOGIN_EINFRA_PERSIST ) || "";

# Check if user is not prohibited in IT4I !!
if (defined $collision) {
die "Login '$login' has collision with old IT4I data. Propagations was stopped for safety."
}

$users->{$login}->{"uuid"} = $data->getUserAttributeValue( member => $memberId, attrName => $A_UUID) || "";
$users->{$login}->{"login"} = $login;
$users->{$login}->{"organization"} = $org;
$users->{$login}->{"citizenship"} = ""; # TODO
$users->{$login}->{"commonName"} = $data->getUserAttributeValue( member => $memberId, attrName => $A_COMMON_NAME ) || "";
$users->{$login}->{"displayName"} = $data->getUserAttributeValue( member => $memberId, attrName => $A_DISPLAY_NAME ) || "";
$users->{$login}->{"firstName"} = $data->getUserAttributeValue( member => $memberId, attrName => $A_FIRST_NAME ) || "";
$users->{$login}->{"lastName"} = $data->getUserAttributeValue( member => $memberId, attrName => $A_LAST_NAME ) || "";
$users->{$login}->{"middleName"} = $data->getUserAttributeValue( member => $memberId, attrName => $A_MIDDLE_NAME) || "";
$users->{$login}->{"titleAfter"} = $data->getUserAttributeValue( member => $memberId, attrName => $A_TITLE_AFTER ) || "";
$users->{$login}->{"titleBefore"} = $data->getUserAttributeValue( member => $memberId, attrName => $A_TITLE_BEFORE ) || "";
$users->{$login}->{"citizenship"} = "";
$users->{$login}->{"country"} = $data->getUserAttributeValue( member => $memberId, attrName => $A_COUNTRY ) || "";
$users->{$login}->{"organization"} = $data->getUserAttributeValue( member => $memberId, attrName => $A_ORGANIZATION ) || "";
$users->{$login}->{"preferredLanguage"} = $data->getUserAttributeValue( member => $memberId, attrName => $A_PREF_LANGUAGE ) || "";
$users->{$login}->{"preferredMail"} = $data->getUserAttributeValue( member => $memberId, attrName => $A_PREF_MAIL ) || "";
$users->{$login}->{"institutionsCountries"} = $data->getUserAttributeValue( member => $memberId, attrName => $A_INSTIT_COUNTRIES ) || [];

}

Expand All @@ -46,7 +70,7 @@ foreach my $login (sort keys %{$users}) {
}

####### output file ######################
open SERVICE_FILE, ">:encoding(UTF-8)", "$service_file_name" or die "Cannot open $service_file_name: $! \n";
open SERVICE_FILE, ">$service_file_name" or die "Cannot open $service_file_name: $! \n";
print SERVICE_FILE JSON::XS->new->utf8->pretty->canonical->encode(\@result);
close(SERVICE_FILE);
#####################################################
Expand Down
24 changes: 24 additions & 0 deletions send/vsup_web
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ foreach my $uco (sort keys %$dataByUco) {

my $updatePerson = $dbh->prepare(qq{UPDATE $tableName SET LOGIN=? , EMAIL_SKOLNI=? , TITUL_PRED=? , JMENO=? , PRIJMENI=? , TITUL_ZA=? , TEL_PRAC_LINKA=? , TEL_PRAC_MOB=? , EMAIL_SOUKR=? , TEL_SOUKR=? , FOTO=? , ZMENENO_KDY=NOW() WHERE UCO=?});
$updatePerson->execute($LOGIN, $EMAIL, $TITLE_BEFORE, $FIRST_NAME, $LAST_NAME, $TITLE_AFTER, $PHONE, $MOBILE, $EMAIL_PRIV, $PHONE_PRIV, $FOTO, $uco);
$updatePerson->finish();
if($DEBUG == 1) { print "UPDATING EXISTING RECORD: $uco\n"; }
$foundAndUpdated++;

Expand All @@ -142,6 +143,7 @@ foreach my $uco (sort keys %$dataByUco) {
$foundAndSkipped++;

}
$recordAreEquals->finish();

} else {

Expand All @@ -150,8 +152,11 @@ foreach my $uco (sort keys %$dataByUco) {
# we will do insert
my $insertPerson = $dbh->prepare(qq{INSERT INTO $tableName (UCO, LOGIN, EMAIL_SKOLNI, TITUL_PRED, JMENO, PRIJMENI, TITUL_ZA, TEL_PRAC_LINKA, TEL_PRAC_MOB, EMAIL_SOUKR, TEL_SOUKR, FOTO, ZMENENO_KDY) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,NOW())});
$insertPerson->execute($uco, $LOGIN, $EMAIL, $TITLE_BEFORE, $FIRST_NAME, $LAST_NAME, $TITLE_AFTER, $PHONE, $MOBILE, $EMAIL_PRIV, $PHONE_PRIV, $FOTO);
$insertPerson->finish();

}
$personExists->finish();

}

##########################
Expand Down Expand Up @@ -198,8 +203,10 @@ while(my $line = <FILE>) {
# we will do insert
my $insertCao = $dbh->prepare(qq{INSERT INTO $tableName_cao (UCO, VZTAH_TYP, CAO_ORGAN, CAO_FUNKCE_NAZEV, CAO_FUNKCE_ID, ZMENENO_KDY) VALUES (?,?,?,?,?,NOW())});
$insertCao->execute($UCO, 'CAO', $CAO_ORGAN, $CAO_FUNKCE, $CAO_FUNKCE_ID);
$insertCao->finish();

}
$caoExist->finish();

}
close FILE;
Expand Down Expand Up @@ -281,6 +288,7 @@ while(my $line = <FILE>) {

my $updatePerson = $dbh->prepare(qq{UPDATE $tableName_ext SET VZTAH_TYP=? , ZAM_FUNKCE_NAZEV=? , ZAM_FUNKCE_CISLO=? , NS=? , ZMENENO_KDY=NOW() WHERE UCO=? and VZTAH_ID=?});
$updatePerson->execute($VZTAH_TYP, $ZAM_FCE_NAZ, $ZAM_FCE_CIS, $NS, $UCO, $VZTAH_ID);
$updatePerson->finish();
if($DEBUG == 1) { print "UPDATING EXISTING RECORD: $UCO\n"; }
$foundAndUpdatedExt++;

Expand All @@ -290,6 +298,7 @@ while(my $line = <FILE>) {
$foundAndSkippedExt++;

}
$recordAreEquals->finish();

} else {

Expand All @@ -298,8 +307,10 @@ while(my $line = <FILE>) {
# we will do insert
my $insertExt = $dbh->prepare(qq{INSERT INTO $tableName_ext (UCO, VZTAH_ID, VZTAH_TYP, ZAM_FUNKCE_CISLO, ZAM_FUNKCE_NAZEV, NS, ZMENENO_KDY) VALUES (?,?,?,?,?,?,NOW())});
$insertExt->execute($UCO, $VZTAH_ID, $VZTAH_TYP, $ZAM_FCE_CIS, $ZAM_FCE_NAZ, $NS);
$insertExt->finish();

}
$extExist->finish();

}
close FILE;
Expand Down Expand Up @@ -384,6 +395,7 @@ while(my $line = <FILE>) {

my $updatePerson = $dbh->prepare(qq{UPDATE $tableName_pass SET STUDIUM_ID=? , STUDIUM_OD=STR_TO_DATE(?,'%Y-%m-%d') , PRIHLASKA_KOD=? , DR=? , ROCNIK=? , ZMENENO_KDY=NOW() WHERE UCO=?});
$updatePerson->execute($STUDY_ID, $STUDY_SINCE, $STUDY_PRIHLASKA, $DR, $STUDY_ROCNIK, $UCO);
$updatePerson->finish();
if($DEBUG == 1) { print "UPDATING EXISTING PASS RECORD: $UCO\n"; }
$foundAndUpdatedPass++;

Expand All @@ -393,6 +405,7 @@ while(my $line = <FILE>) {
$foundAndSkippedPass++;

}
$recordAreEquals->finish();

} else {

Expand All @@ -404,6 +417,8 @@ while(my $line = <FILE>) {
}

}
$passExist->finish();
$insertExt->finish();
close FILE;

#####
Expand Down Expand Up @@ -458,6 +473,7 @@ foreach my $NS_KOD (sort keys %$dataByNs) {
# we will do insert
my $insertPerson = $dbh->prepare(qq{INSERT INTO $tableName_ns (NS_KOD, NS_NAZEV, UCO) VALUES (?,?,?)});
$insertPerson->execute($NS_KOD, $NS_NAZEV, $UCO);
$insertPerson->finish();

}

Expand Down Expand Up @@ -496,6 +512,14 @@ foreach my $uco (@web_ucos) {
}
}

$deleteUser->finish();
$deleteCao->finish();
$deletePass->finish();
$deleteExt->finish();
$deleteNs->finish();
$deleteDC2->finish();
$deleteKOS->finish();

commit $dbh;
$dbh->disconnect();

Expand Down

0 comments on commit 87c46f4

Please sign in to comment.