Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use queueCommandTasks feature #272

Merged
merged 14 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions generators/angular-audit/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { clientApplicationTemplatesBlock } from 'generator-jhipster/generators/c
export default class extends BaseApplicationGenerator {
ngxDiff;

constructor(args, opts, features) {
super(args, opts, { ...features, queueCommandTasks: true });
}

async beforeQueue() {
await this.dependsOnJHipster('bootstrap-application');
}
Expand Down
2 changes: 1 addition & 1 deletion generators/client/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import BaseApplicationGenerator from 'generator-jhipster/generators/base-applica

export default class extends BaseApplicationGenerator {
constructor(args, opts, features) {
super(args, opts, { ...features, sbsBlueprint: true });
super(args, opts, { ...features, queueCommandTasks: true, sbsBlueprint: true });
}

async beforeQueue() {
Expand Down
156 changes: 155 additions & 1 deletion generators/java-audit/__snapshots__/generator.spec.js.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,160 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`SubGenerator java-audit of entity-audit JHipster blueprint > run > should succeed 1`] = `
exports[`SubGenerator java-audit of entity-audit JHipster blueprint > run using auditFramework custom > should succeed 1`] = `
{
".jhipster/Audited.json": {
"stateCleared": "modified",
},
".yo-rc.json": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/GeneratedByJHipster.java": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/audit/AsyncEntityAuditEventWriter.java": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/audit/EntityAuditEventListener.java": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/audit/EntityAuditEventWriter.java": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/audit/package-info.java": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/domain/Audited.java": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/domain/Authority.java": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/domain/EntityAuditEvent.java": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/domain/enumeration/EntityAuditAction.java": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/domain/enumeration/package-info.java": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/domain/package-info.java": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/package-info.java": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/repository/EntityAuditEventRepository.java": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/repository/package-info.java": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/web/rest/EntityAuditResource.java": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/web/rest/package-info.java": {
"stateCleared": "modified",
},
"src/main/resources/config/liquibase/changelog/20220101000100_added_entity_EntityAuditEvent.xml": {
"stateCleared": "modified",
},
"src/test/java/com/mycompany/myapp/audit/TestEntityAuditEventWriter.java": {
"stateCleared": "modified",
},
"src/test/java/com/mycompany/myapp/domain/AssertUtils.java": {
"stateCleared": "modified",
},
"src/test/java/com/mycompany/myapp/domain/AuditedAsserts.java": {
"stateCleared": "modified",
},
"src/test/java/com/mycompany/myapp/domain/AuditedTest.java": {
"stateCleared": "modified",
},
"src/test/java/com/mycompany/myapp/domain/AuditedTestSamples.java": {
"stateCleared": "modified",
},
"src/test/java/com/mycompany/myapp/domain/AuthorityAsserts.java": {
"stateCleared": "modified",
},
"src/test/java/com/mycompany/myapp/domain/AuthorityTest.java": {
"stateCleared": "modified",
},
"src/test/java/com/mycompany/myapp/domain/AuthorityTestSamples.java": {
"stateCleared": "modified",
},
}
`;

exports[`SubGenerator java-audit of entity-audit JHipster blueprint > run using auditFramework javers > should succeed 1`] = `
{
".jhipster/Audited.json": {
"stateCleared": "modified",
},
".yo-rc.json": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/GeneratedByJHipster.java": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/config/audit/JaversAuthorProvider.java": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/config/audit/package-info.java": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/domain/Audited.java": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/domain/Authority.java": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/domain/package-info.java": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/package-info.java": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/web/rest/JaversEntityAuditResource.java": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/web/rest/dto/EntityAuditAction.java": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/web/rest/dto/EntityAuditEvent.java": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/web/rest/dto/package-info.java": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/web/rest/package-info.java": {
"stateCleared": "modified",
},
"src/test/java/com/mycompany/myapp/domain/AssertUtils.java": {
"stateCleared": "modified",
},
"src/test/java/com/mycompany/myapp/domain/AuditedAsserts.java": {
"stateCleared": "modified",
},
"src/test/java/com/mycompany/myapp/domain/AuditedTest.java": {
"stateCleared": "modified",
},
"src/test/java/com/mycompany/myapp/domain/AuditedTestSamples.java": {
"stateCleared": "modified",
},
"src/test/java/com/mycompany/myapp/domain/AuthorityAsserts.java": {
"stateCleared": "modified",
},
"src/test/java/com/mycompany/myapp/domain/AuthorityTest.java": {
"stateCleared": "modified",
},
"src/test/java/com/mycompany/myapp/domain/AuthorityTestSamples.java": {
"stateCleared": "modified",
},
}
`;

exports[`SubGenerator java-audit of entity-audit JHipster blueprint > run using auditFramework undefined > should succeed 1`] = `
{
".jhipster/Audited.json": {
"stateCleared": "modified",
Expand Down
72 changes: 71 additions & 1 deletion generators/java-audit/command.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,75 @@
import { asCommand } from 'generator-jhipster';

export default asCommand({
configs: {},
configs: {
auditFramework: {
description: 'Audit framework',
cli: {
type: String,
},
prompt: {
type: 'list',
message: 'Choose which audit framework you would like to use.',
default: 'custom',
},
choices: [
{
name: 'Custom JHipster auditing (works with SQL)',
value: 'custom',
},
{
name: 'Javers auditing framework (works with SQL and MongoDB)',
value: 'javers',
},
{
name: 'No auditing framework',
value: 'no',
},
],
scope: 'blueprint',
},
auditPage: {
description: 'Generate client page',
cli: {
type: Boolean,
},
prompt: {
type: 'confirm',
message: 'Do you want to add an audit log page for entities?',
default: true,
},
scope: 'blueprint',
},
auditUpdateType: {
cli: {
type: String,
},
prompt: generator => ({
when: answers => (generator.initialRun || generator.options.askAnswered) && ['javers', 'custom'].includes(answers.auditFramework),
type: 'list',
name: 'auditUpdateType',
message: 'Do you want to enable audit for all existing entities?',
choices: [
{ name: 'Yes, update all', value: 'all' },
{ name: 'No, let me choose the entities to update', value: 'selected' },
],
default: 'all',
}),
scope: 'generator',
},
auditedEntities: {
description: 'Entities to be audited',
cli: {
type: Array,
},
prompt: gen => ({
when: answers => answers.auditUpdateType === 'selected',
type: 'checkbox',
message: 'Please choose the entities to be audited',
choices: gen.getExistingEntities().map(e => e.name),
default: [],
}),
scope: 'generator',
},
},
});
56 changes: 20 additions & 36 deletions generators/java-audit/generator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import BaseApplicationGenerator from 'generator-jhipster/generators/base-application';
import { addJavaAnnotation, addJavaImport, javaMainPackageTemplatesBlock } from 'generator-jhipster/generators/java/support';
import { javaMainPackageTemplatesBlock } from 'generator-jhipster/generators/java/support';

const COMMON_ATTRIBUTES = {
// Hides form on create
Expand Down Expand Up @@ -38,8 +38,23 @@ const ADDITIONAL_FIELDS = [
];

export default class extends BaseApplicationGenerator {
auditUpdateType;
auditedEntities;

constructor(args, opts, features) {
super(args, opts, { ...features, queueCommandTasks: true });
}

async beforeQueue() {
await this.dependsOnJHipster('java');
await this.dependsOnJHipster('jhipster:java:domain');
}

get [BaseApplicationGenerator.INITIALIZING]() {
return this.asInitializingTaskGroup({
setInitialRun() {
this.initialRun = this.blueprintConfig.auditFramework === undefined;
},
});
}

get [BaseApplicationGenerator.COMPOSING]() {
Expand All @@ -49,48 +64,17 @@ export default class extends BaseApplicationGenerator {
await this.composeWithJHipster('jhipster-entity-audit:spring-boot-javers');
} else if (this.blueprintConfig.auditFramework === 'custom') {
await this.composeWithJHipster('jhipster-entity-audit:spring-boot-custom-audit');
} else {
this.cancelCancellableTasks();
}
},
});
}

get [BaseApplicationGenerator.LOADING]() {
return this.asLoadingTaskGroup({
prepareForTemplates({ application }) {
const { auditFramework, auditPage } = this.blueprintConfig;
application.auditFramework = auditFramework;
application.auditPage = auditPage;
},
});
}

get [BaseApplicationGenerator.PREPARING]() {
return this.asPreparingTaskGroup({
prepareForTemplates({ application }) {
const { auditFramework } = application;
application.auditFrameworkCustom = auditFramework === 'custom';
application.auditFrameworkJavers = auditFramework === 'javers';
application.auditFrameworkAny = auditFramework && auditFramework !== 'no';
},
editJavaFile({ source }) {
source.editJavaFile =
source.editJavaFile ??
((file, { staticImports = [], imports = [], annotations = [] }, ...editFileCallback) =>
this.editFile(
file,
...staticImports.map(classPath => addJavaImport(classPath, { staticImport: true })),
...imports.map(classPath => addJavaImport(classPath)),
...annotations.map(annotation => addJavaAnnotation(annotation)),
...editFileCallback,
));
},
});
}

get [BaseApplicationGenerator.CONFIGURING_EACH_ENTITY]() {
return this.asConfiguringEachEntityTaskGroup({
async configureEntity({ entityName, entityConfig }) {
const { auditedEntities } = this.options;
const auditedEntities = this.auditUpdateType === 'all' ? this.getExistingEntities().map(e => e.name) : this.auditedEntities;
entityConfig.enableAudit = auditedEntities?.includes(entityName) || entityConfig.enableAudit;
if (!entityConfig.enableAudit) return;

Expand Down
Loading
Loading