Compare commits

...

3 Commits

Author SHA1 Message Date
Michael Hoennig
56f316ef80 CaseDef extends ColumnValue 2024-04-07 13:20:44 +02:00
Michael Hoennig
1e6b19c337 re-generate RBAC diagrams 2024-04-07 13:17:39 +02:00
Michael Hoennig
25823342e7 avoid extra space in headline of generated Markdown 2024-04-07 13:13:49 +02:00
5 changed files with 24 additions and 26 deletions

View File

@ -394,7 +394,7 @@ public class RbacView {
}); });
importedRbacView.getGrantDefs().forEach(grantDef -> { importedRbacView.getGrantDefs().forEach(grantDef -> {
if ( grantDef.grantType() == RbacGrantDefinition.GrantType.ROLE_TO_ROLE && if ( grantDef.grantType() == RbacGrantDefinition.GrantType.ROLE_TO_ROLE &&
grantDef.matchesCase(forCase) ) { (grantDef.forCases == null || grantDef.matchesCase(forCase)) ) {
final var importedGrantDef = findOrCreateGrantDef( final var importedGrantDef = findOrCreateGrantDef(
findRbacRole( findRbacRole(
mapper.map(grantDef.getSubRoleDef().entityAlias.aliasName), mapper.map(grantDef.getSubRoleDef().entityAlias.aliasName),
@ -483,7 +483,7 @@ public class RbacView {
public void generateWithBaseFileName(final String baseFileName) { public void generateWithBaseFileName(final String baseFileName) {
if (allCases.size() > 1) { if (allCases.size() > 1) {
allCases.forEach(caseDef -> { allCases.forEach(caseDef -> {
final var fileName = baseFileName + (caseDef.isDefaultCase() ? "" : "-" + caseDef.val) + ".md"; final var fileName = baseFileName + (caseDef.isDefaultCase() ? "" : "-" + caseDef.value) + ".md";
new RbacViewMermaidFlowchartGenerator(this, caseDef) new RbacViewMermaidFlowchartGenerator(this, caseDef)
.generateToMarkdownFile(Path.of(OUTPUT_BASEDIR, fileName)); .generateToMarkdownFile(Path.of(OUTPUT_BASEDIR, fileName));
}); });
@ -596,22 +596,12 @@ public class RbacView {
} }
boolean matchesCase(final ColumnValue requestedCase) { boolean matchesCase(final ColumnValue requestedCase) {
if (forCases == null) {
return true;
}
final var noCasesDefined = forCases.isEmpty(); final var noCasesDefined = forCases.isEmpty();
final var generateForAllCases = requestedCase == null; final var generateForAllCases = requestedCase == null;
final boolean isGrantedForRequestedCase = forCases.stream().anyMatch(c -> c.isCase(requestedCase)); final boolean isGrantedForRequestedCase = forCases.stream().anyMatch(c -> c.isCase(requestedCase));
return noCasesDefined || generateForAllCases || isGrantedForRequestedCase; return noCasesDefined || generateForAllCases || isGrantedForRequestedCase;
} }
boolean matchesCase(final CaseDef requestedCase) {
final var noCasesDefined = forCases.isEmpty();
final var generateForAllCases = requestedCase == null;
final boolean isGrantedForRequestedCase = forCases.contains(requestedCase);
return noCasesDefined || generateForAllCases || isGrantedForRequestedCase;
}
boolean isToCreate() { boolean isToCreate() {
return toCreate; return toCreate;
} }
@ -1132,14 +1122,12 @@ public class RbacView {
} }
} }
// FIXME: subclass of ColumnValue public static class CaseDef extends ColumnValue {
public static class CaseDef {
final String val;
final Consumer<RbacView> def; final Consumer<RbacView> def;
private CaseDef(final String discriminatorColumnValue, final Consumer<RbacView> def) { private CaseDef(final String discriminatorColumnValue, final Consumer<RbacView> def) {
this.val = discriminatorColumnValue; super(discriminatorColumnValue);
this.def = def; this.def = def;
} }
@ -1154,7 +1142,7 @@ public class RbacView {
@Override @Override
public int hashCode() { public int hashCode() {
return ofNullable(val).map(String::hashCode).orElse(0); return ofNullable(value).map(String::hashCode).orElse(0);
} }
@Override @Override
@ -1164,22 +1152,22 @@ public class RbacView {
if (other == null || getClass() != other.getClass()) if (other == null || getClass() != other.getClass())
return false; return false;
final CaseDef caseDef = (CaseDef) other; final CaseDef caseDef = (CaseDef) other;
return Objects.equals(val, caseDef.val); return Objects.equals(value, caseDef.value);
} }
boolean isDefaultCase() { boolean isDefaultCase() {
return val == null; return value == null;
} }
@Override @Override
public String toString() { public String toString() {
return isDefaultCase() return isDefaultCase()
? "inOtherCases" ? "inOtherCases"
: "inCaseOf:" + val; : "inCaseOf:" + value;
} }
public boolean isCase(final ColumnValue requestedCase) { public boolean isCase(final ColumnValue requestedCase) {
return Objects.equals(requestedCase.value, this.val); return Objects.equals(requestedCase.value, this.value);
} }
} }

View File

@ -165,7 +165,7 @@ public class RbacViewMermaidFlowchartGenerator {
Files.writeString( Files.writeString(
path, path,
""" """
### rbac %{entityAlias} %{case} ### rbac %{entityAlias}%{case}
This code generated was by RbacViewMermaidFlowchartGenerator, do not amend manually. This code generated was by RbacViewMermaidFlowchartGenerator, do not amend manually.
@ -175,7 +175,7 @@ public class RbacViewMermaidFlowchartGenerator {
""" """
.replace("%{entityAlias}", rbacDef.getRootEntityAlias().aliasName()) .replace("%{entityAlias}", rbacDef.getRootEntityAlias().aliasName())
.replace("%{flowchart}", flowchart.toString()) .replace("%{flowchart}", flowchart.toString())
.replace("%{case}", forCase == null ? "" : (forCase.toString()) ), .replace("%{case}", forCase == null ? "" : " " + forCase),
StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
System.out.println("Markdown-File: " + path.toAbsolutePath()); System.out.println("Markdown-File: " + path.toAbsolutePath());
} }

View File

@ -197,8 +197,8 @@ class RolesGrantsAndPermissionsGenerator {
plPgSql.writeLn(); plPgSql.writeLn();
final var ifOrElsIf = new AtomicReference<>("IF "); final var ifOrElsIf = new AtomicReference<>("IF ");
rbacDef.getAllCases().forEach(caseDef -> { rbacDef.getAllCases().forEach(caseDef -> {
if (caseDef.val != null) { if (caseDef.value != null) {
plPgSql.writeLn(ifOrElsIf + "NEW." + rbacDef.getDiscriminatorColumName() + " = '" + caseDef.val + "' THEN"); plPgSql.writeLn(ifOrElsIf + "NEW." + rbacDef.getDiscriminatorColumName() + " = '" + caseDef.value + "' THEN");
} else { } else {
plPgSql.writeLn("ELSE"); plPgSql.writeLn("ELSE");
} }

View File

@ -1,4 +1,4 @@
### rbac partner ### rbac partner
This code generated was by RbacViewMermaidFlowchartGenerator, do not amend manually. This code generated was by RbacViewMermaidFlowchartGenerator, do not amend manually.

View File

@ -149,6 +149,16 @@ role:debitorRel.holderPerson:ADMIN -.-> role:debitorRel.holderPerson:REFERRER
role:global:ADMIN -.-> role:debitorRel.contact:OWNER role:global:ADMIN -.-> role:debitorRel.contact:OWNER
role:debitorRel.contact:OWNER -.-> role:debitorRel.contact:ADMIN role:debitorRel.contact:OWNER -.-> role:debitorRel.contact:ADMIN
role:debitorRel.contact:ADMIN -.-> role:debitorRel.contact:REFERRER role:debitorRel.contact:ADMIN -.-> role:debitorRel.contact:REFERRER
role:global:ADMIN -.-> role:debitorRel:OWNER
role:debitorRel:OWNER -.-> role:debitorRel:ADMIN
role:debitorRel:ADMIN -.-> role:debitorRel:AGENT
role:debitorRel:AGENT -.-> role:debitorRel:TENANT
role:debitorRel.contact:ADMIN -.-> role:debitorRel:TENANT
role:debitorRel:TENANT -.-> role:debitorRel.anchorPerson:REFERRER
role:debitorRel:TENANT -.-> role:debitorRel.holderPerson:REFERRER
role:debitorRel:TENANT -.-> role:debitorRel.contact:REFERRER
role:debitorRel.anchorPerson:ADMIN -.-> role:debitorRel:OWNER
role:debitorRel.holderPerson:ADMIN -.-> role:debitorRel:AGENT
role:global:ADMIN -.-> role:refundBankAccount:OWNER role:global:ADMIN -.-> role:refundBankAccount:OWNER
role:refundBankAccount:OWNER -.-> role:refundBankAccount:ADMIN role:refundBankAccount:OWNER -.-> role:refundBankAccount:ADMIN
role:refundBankAccount:ADMIN -.-> role:refundBankAccount:REFERRER role:refundBankAccount:ADMIN -.-> role:refundBankAccount:REFERRER