Skip to content

Commit b807877

Browse files
author
Dominik Frantisek Bucik
committed
feat: 🎸 Allow multiple reg. modules to be configured
Instead of specifying single registrar module, allow to specify multiple. When storign in database, specified names are concatenated using `,` as separator. In from handling (any), instead of operating with single module, loop over all specified modules and try to process appropriate action (e.g. call `beforeApprove(...)`). Also updates Perl libs. BREAKING CHANGE: 🧨 ApplicationForm bean property `moduleClassName` replaced with `moduleClassNames`. Type has changed from String to List<String>. Includes database version update and column `module_name` of `application_form` table being renamed to `module_names`. DEPLOYMENT NOTE: requires database update. UI version have to work with updated model of ApplicationForm (`moduleClassName` replaced with field `moduleClassNames`).
1 parent d0f59bf commit b807877

File tree

13 files changed

+158
-106
lines changed

13 files changed

+158
-106
lines changed

‎perun-base/src/main/java/cz/metacentrum/perun/registrar/model/ApplicationForm.java‎

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
import cz.metacentrum.perun.core.api.Group;
44
import cz.metacentrum.perun.core.api.Vo;
5+
import org.springframework.util.StringUtils;
6+
7+
import java.util.ArrayList;
8+
import java.util.List;
59

610
/**
711
* Application form of a VO. Use {@link cz.metacentrum.perun.registrar.RegistrarManager#getFormItems} for items.
@@ -16,7 +20,7 @@ public class ApplicationForm {
1620
private boolean automaticApproval;
1721
private boolean automaticApprovalExtension;
1822
private boolean automaticApprovalEmbedded;
19-
private String moduleClassName;
23+
private final List<String> moduleClassNames = new ArrayList<>();
2024

2125
public ApplicationForm() {
2226
}
@@ -69,12 +73,29 @@ public void setAutomaticApprovalEmbedded(boolean automaticApprovalEmbedded) {
6973
this.automaticApprovalEmbedded = automaticApprovalEmbedded;
7074
}
7175

72-
public String getModuleClassName() {
73-
return moduleClassName;
76+
public List<String> getModuleClassNames() {
77+
return new ArrayList<>(moduleClassNames);
78+
}
79+
80+
public void setModuleClassNames(List<String> moduleClassNames) {
81+
this.moduleClassNames.clear();
82+
for (String moduleClassName : moduleClassNames) {
83+
if (StringUtils.hasText(moduleClassName)) {
84+
this.moduleClassNames.add(moduleClassName);
85+
}
86+
}
87+
}
88+
89+
public void addModuleClassName(String moduleClassName) {
90+
if (StringUtils.hasText(moduleClassName)) {
91+
this.moduleClassNames.add(moduleClassName);
92+
}
7493
}
7594

76-
public void setModuleClassName(String moduleClassName) {
77-
this.moduleClassName = moduleClassName;
95+
public void removeModuleClassName(String moduleClassName) {
96+
if (StringUtils.hasText(moduleClassName)) {
97+
this.moduleClassNames.remove(moduleClassName);
98+
}
7899
}
79100

80101
/**
@@ -94,7 +115,7 @@ public String toString() {
94115
", group='" + getGroup() + '\'' +
95116
", automaticApproval='" + isAutomaticApproval() + '\'' +
96117
", automaticApprovalExtension='" + isAutomaticApprovalExtension() + '\'' +
97-
", moduleClassName='" + getModuleClassName() + '\'' +
118+
", moduleClassNames='" + getModuleClassNames() + '\'' +
98119
"]";
99120
}
100121

‎perun-base/src/test/resources/test-schema.sql‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- database version 3.2.17 (don't forget to update insert statement at the end of file)
1+
-- database version 3.2.18 (don't forget to update insert statement at the end of file)
22
CREATE EXTENSION IF NOT EXISTS "unaccent";
33
CREATE EXTENSION IF NOT EXISTS "pgcrypto";
44

@@ -539,7 +539,7 @@ create table application_form (
539539
automatic_approval boolean default false not null, --approval of application is automatic
540540
automatic_approval_extension boolean default false not null, --approval of extension is automatic
541541
automatic_approval_embedded boolean default false not null, --approval of embedded application is automatic
542-
module_name varchar, --name of module which processes application
542+
module_names varchar, --name of modules (separated by comma) which are called when processing application
543543
group_id integer, --identifier of group (groups.id) if application is for group
544544
created_by_uid integer,
545545
modified_by_uid integer,
@@ -1908,7 +1908,7 @@ create index idx_fk_attr_critops ON attribute_critical_actions(attr_id);
19081908
create index app_state_idx ON application (state);
19091909

19101910
-- set initial Perun DB version
1911-
insert into configurations values ('DATABASE VERSION','3.2.17');
1911+
insert into configurations values ('DATABASE VERSION','3.2.18');
19121912
-- insert membership types
19131913
insert into membership_types (id, membership_type, description) values (1, 'DIRECT', 'Member is directly added into group');
19141914
insert into membership_types (id, membership_type, description) values (2, 'INDIRECT', 'Member is added indirectly through UNION relation');

‎perun-cli/Perun/beans/ApplicationForm.pm‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ sub TO_JSON
5959
$automaticApprovalExtension = undef;
6060
}
6161

62-
my $moduleClassName;
63-
if (defined($self->{_moduleClassName})) {
64-
$moduleClassName = "$self->{_moduleClassName}";
62+
my @moduleClassNames;
63+
if (defined($self->{_moduleClassNames})) {
64+
@moduleClassNames = @{$self->{_moduleClassNames}};
6565
} else {
66-
$moduleClassName = undef;
66+
@moduleClassNames = undef;
6767
}
6868

69-
return { id => $id, vo => $vo, group => $group, automaticApproval => $automaticApproval, automaticApprovalExtension => $automaticApprovalExtension, moduleClassName => $moduleClassName };
69+
return { id => $id, vo => $vo, group => $group, automaticApproval => $automaticApproval, automaticApprovalExtension => $automaticApprovalExtension, moduleClassNames => \@moduleClassNames };
7070
}
7171

7272
sub getId
@@ -138,17 +138,17 @@ sub setAutomaticApprovalExtension
138138

139139
}
140140

141-
sub getModuleClassName
141+
sub getModuleClassNames
142142
{
143143
my $self = shift;
144144

145-
return $self->{_moduleClassName};
145+
return $self->{_moduleClassNames};
146146
}
147147

148-
sub setModuleClassName
148+
sub setModuleClassNames
149149
{
150150
my $self = shift;
151-
$self->{_moduleClassName} = shift;
151+
$self->{_moduleClassNames} = shift;
152152
}
153153

154154
1;

‎perun-cli/updateForm‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,25 @@ sub help {
1616
--groupId | -g group id
1717
--autApproval | -a automatic approval (1/0)
1818
--autApprovalExt | -e automatic approval extension (1/0)
19-
--moduleName | -n name of module
19+
--moduleNames | -n name of module, can be specified multiple times
2020
--batch | -b batch
2121
--help | -h prints this help
2222
2323
};
2424
}
2525

2626
our $batch;
27-
my ($voId, $groupId, $moduleName, $app, $appE);
27+
my ($voId, $groupId, @moduleNames, $app, $appE);
2828
GetOptions ("help|h" => sub {
2929
print help();
3030
exit 0;
3131
},
32-
"batch|b" => \$batch,
33-
"voId|g=i" => \$voId,
34-
"groupId|g=i" => \$groupId,
35-
"autApproval|a=s" => \$app,
36-
"autApprovalExt|e=s" => \$appE,
37-
"moduleName|n=s" => \$moduleName ) || die help();
32+
"batch|b" => \$batch,
33+
"voId|g=i" => \$voId,
34+
"groupId|g=i" => \$groupId,
35+
"autApproval|a=s" => \$app,
36+
"autApprovalExt|e=s" => \$appE,
37+
'moduleNames|n=s@{1,}' => \@moduleNames ) || die help();
3838

3939
# Check options
4040
if (not defined $groupId and not defined $voId) { die "ERROR: voId or groupId is required \n";}
@@ -56,9 +56,9 @@ if (defined $app) {
5656
if (defined $appE) {
5757
$applicationForm->setAutomaticApprovalExtension($appE);
5858
}
59-
if (defined $moduleName) {
60-
$applicationForm->setModuleClassName($moduleName);
61-
}
59+
if (defined \@moduleNames) {
60+
$applicationForm->setModuleClassNames(\@moduleNames);
61+
}
6262

6363
$registrarAgent->updateForm( form => $applicationForm );
6464

‎perun-core/src/main/java/cz/metacentrum/perun/core/impl/GroupsManagerImpl.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import java.sql.Array;
5454
import java.sql.ResultSet;
5555
import java.util.ArrayList;
56+
import java.util.Arrays;
5657
import java.util.HashMap;
5758
import java.util.HashSet;
5859
import java.util.List;
@@ -89,7 +90,7 @@ public class GroupsManagerImpl implements GroupsManagerImplApi {
8990
protected final static String assignedGroupMappingSelectQuery = groupMappingSelectQuery + ", groups_resources_state.status as groups_resources_state_status, " +
9091
"groups_resources_automatic.auto_assign_subgroups as auto_assign_subgroups, groups_resources_state.failure_cause as groups_resources_state_failure_cause, groups_resources_automatic.source_group_id as groups_resources_automatic_source_group_id";
9192

92-
private static final String applicationFormMappingSelectQuery = "id,vo_id,group_id,automatic_approval,automatic_approval_extension,automatic_approval_embedded,module_name from application_form";
93+
private static final String applicationFormMappingSelectQuery = "id,vo_id,group_id,automatic_approval,automatic_approval_extension,automatic_approval_embedded,module_names from application_form";
9394

9495
// http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/jdbc.html
9596
private final JdbcPerunTemplate jdbc;
@@ -1405,7 +1406,9 @@ public ApplicationForm getParentApplicationFormForAutoRegistrationGroup(Group gr
14051406
form.setAutomaticApproval(resultSet.getBoolean("automatic_approval"));
14061407
form.setAutomaticApprovalExtension(resultSet.getBoolean("automatic_approval_extension"));
14071408
form.setAutomaticApprovalEmbedded(resultSet.getBoolean("automatic_approval_embedded"));
1408-
form.setModuleClassName(resultSet.getString("module_name"));
1409+
if (resultSet.getString("module_names") != null) {
1410+
form.setModuleClassNames(Arrays.asList(resultSet.getString("module_names").split(",")));
1411+
}
14091412
Vo vo = new Vo();
14101413
vo.setId(resultSet.getInt("vo_id"));
14111414
form.setVo(vo);

‎perun-core/src/main/resources/postgresChangelog.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
-- Directly under version number should be version commands. They will be executed in the order they are written here.
77
-- Comments are prefixed with -- and can be written only between version blocks, that means not in the lines with commands. They have to be at the start of the line.
88

9+
3.2.18
10+
ALTER TABLE application_form RENAME COLUMN module_name TO module_names;
11+
UPDATE configurations SET value='3.2.18' WHERE property='DATABASE VERSION';
12+
913
3.2.17
1014
ALTER TABLE attribute_critical_actions ADD COLUMN global boolean default false not null;
1115
UPDATE configurations SET value='3.2.17' WHERE property='DATABASE VERSION';

‎perun-db/postgres.sql‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- database version 3.2.17 (don't forget to update insert statement at the end of file)
1+
-- database version 3.2.18 (don't forget to update insert statement at the end of file)
22

33
-- VOS - virtual organizations
44
create table vos (
@@ -537,7 +537,7 @@ create table application_form (
537537
automatic_approval boolean default false not null, --approval of application is automatic
538538
automatic_approval_extension boolean default false not null, --approval of extension is automatic
539539
automatic_approval_embedded boolean default false not null, --approval of embedded application is automatic
540-
module_name varchar, --name of module which processes application
540+
module_names varchar, --name of modules (separated by comma) which are called when processing application
541541
group_id integer, --identifier of group (groups.id) if application is for group
542542
created_by_uid integer,
543543
modified_by_uid integer,
@@ -2017,7 +2017,7 @@ grant all on blocked_logins to perun;
20172017
grant all on auto_registration_groups to perun;
20182018

20192019
-- set initial Perun DB version
2020-
insert into configurations values ('DATABASE VERSION','3.2.17');
2020+
insert into configurations values ('DATABASE VERSION','3.2.18');
20212021

20222022
-- insert membership types
20232023
insert into membership_types (id, membership_type, description) values (1, 'DIRECT', 'Member is directly added into group');

‎perun-openapi/openapi.yml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,10 @@ components:
10211021
automaticApproval: { type: boolean }
10221022
automaticApprovalExtension: { type: boolean }
10231023
automaticApprovalEmbedded: { type: boolean }
1024-
moduleClassName: { type: string }
1024+
moduleClassNames:
1025+
type: array
1026+
items:
1027+
type: string
10251028

10261029
Type:
10271030
type: string

0 commit comments

Comments
 (0)