Skip to content

Commit

Permalink
Version 7.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
nsteenbeek committed Mar 1, 2023
2 parents 6643423 + 0eec98b commit ccbd8e9
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 90 deletions.
2 changes: 1 addition & 1 deletion bin/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hso/d365-cli",
"version": "7.0.1",
"version": "7.0.2",
"author": "HSO Innovation <[email protected]> (https://www.hso.com)",
"description": "Dynamics 365 Command Line Interface for TypeScript projects for Dataverse",
"repository": {
Expand Down
49 changes: 38 additions & 11 deletions src/commands/SetFormCustomizable.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {MsalRouter} from '../routers/MsalRouter';
import {SolutionService} from '../node/Solution/Solution.service';
import {SolutionComponentService} from '../node/SolutionComponent/SolutionComponent.service';
import {SystemFormService} from '../node/SystemForm/SystemForm.service';
import {SolutionModel} from '../node/Solution/Solution.model';
import {SolutionComponentModel} from '../node/SolutionComponent/SolutionComponent.model';
import {SystemFormModel} from '../node/SystemForm/SystemForm.model';
import {WebresourcesCrmJson} from '../root/Webresources/CrmJson';
import fs from 'fs';
import {SolutionComponentSummaryService} from '../node/SolutionComponentSummary/SolutionComponentSummary.service';
import {SolutionComponentSummaryModel} from '../node/SolutionComponentSummary/SolutionComponentSummary.model';

export class SetFormCustomizable extends MsalRouter {
private readonly customizable: boolean;
Expand All @@ -28,7 +28,7 @@ export class SetFormCustomizable extends MsalRouter {
console.log(`Solution id: ${solution.solutionid}`);
const solutionSystemFormComponents = await this.getSolutionSystemFormComponents(solution);
for (const solutionSystemFormComponent of solutionSystemFormComponents) {
console.log(`SolutionComponent: ${solutionSystemFormComponent.objectid}`);
console.log(`SolutionComponent: ${solutionSystemFormComponent.msdyn_objectid}`);
const systemForm = await this.getSystemForm(solutionSystemFormComponent);
await this.setForm(systemForm, this.customizable);
}
Expand All @@ -55,23 +55,50 @@ export class SetFormCustomizable extends MsalRouter {
console.log(`---------------------------`);
}

private getSolutionSystemFormComponents(solution: SolutionModel): Promise<SolutionComponentModel[]> {
return SolutionComponentService.retrieveMultipleRecords({
select: ['objectid'],
private async getSolutionEntityComponents(solution: SolutionModel): Promise<SolutionComponentSummaryModel[]> {
return SolutionComponentSummaryService.retrieveMultipleRecords({
select: ['msdyn_objectid', 'msdyn_name'],
filters: [{
conditions: [{
attribute: '_solutionid_value',
attribute: 'msdyn_solutionid',
value: solution.solutionid
}, {
attribute: 'componenttype',
value: 60
attribute: 'msdyn_componenttype',
value: 1
}]
}]
}, this.bearer);
}

private getSystemForm(solutionComponent: SolutionComponentModel): Promise<SystemFormModel> {
return SystemFormService.getSystemForm(solutionComponent.objectid,
private async getSolutionSystemFormComponents(solution: SolutionModel): Promise<SolutionComponentSummaryModel[]> {
const entitySummaries = await this.getSolutionEntityComponents(solution);
const conditions: Condition[] = [];
for (const entitySummary of entitySummaries) {
conditions.push({
attribute: 'msdyn_primaryentityname',
value: entitySummary.msdyn_name
});
}
const filters: Filter[] = [{
type: 'or',
conditions: conditions
},{
conditions: [{
attribute: 'msdyn_solutionid',
value: solution.solutionid
}, {
attribute: 'msdyn_componenttype',
value: 60
}]
}];
return SolutionComponentSummaryService.retrieveMultipleRecords({
select: ['msdyn_objectid'],
filters: filters,
}, this.bearer);
}

private getSystemForm(solutionComponentSummary: SolutionComponentSummaryModel): Promise<SystemFormModel> {
return SystemFormService.getSystemForm(solutionComponentSummary.msdyn_objectid,
['name', 'objecttypecode', 'iscustomizable', 'canbedeleted'], this.bearer);
}
}
16 changes: 8 additions & 8 deletions src/commands/generators/CustomApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import fs from 'fs';
import {WebresourcesCrmJson} from '../../root/Webresources/CrmJson';
import {SolutionService} from '../../node/Solution/Solution.service';
import {CustomApiService} from '../../node/CustomApi/CustomApi.service';
import {SolutionComponentService} from '../../node/SolutionComponent/SolutionComponent.service';
import {CustomApiRequestParameterService} from '../../node/CustomApiRequestParameter/CustomApiRequestParameter.service';
import {CustomApiResponsePropertyService} from '../../node/CustomApiResponseProperty/CustomApiResponseProperty.service';
import {CustomApiModel} from '../../node/CustomApi/CustomApi.model';
import {CustomApiRequestParameterModel} from '../../node/CustomApiRequestParameter/CustomApiRequestParameter.model';
import {CustomApiResponsePropertyModel} from '../../node/CustomApiResponseProperty/CustomApiResponseProperty.model';
import {SolutionComponentSummaryService} from '../../node/SolutionComponentSummary/SolutionComponentSummary.service';

export class CustomApis {
private readonly bearer: string;
Expand Down Expand Up @@ -87,27 +87,27 @@ export class CustomApis {
const settings: WebresourcesCrmJson = JSON.parse(fs.readFileSync('./crm.json', 'utf8'));
const {solution_name_generate} = settings.crm;
const solution = await SolutionService.getSolution(solution_name_generate, ['solutionid'], this.bearer);
const solutionComponents = await SolutionComponentService.retrieveMultipleRecords({
select: ['objectid'],
const solutionComponentSummaries = await SolutionComponentSummaryService.retrieveMultipleRecords({
select: ['msdyn_objectid'],
filters: [{
conditions: [{
attribute: '_solutionid_value',
attribute: 'msdyn_solutionid',
value: solution.solutionid
}]
}, {
type: 'or',
conditions: [{
attribute: 'componenttype',
attribute: 'msdyn_componenttype',
value: 10051 // CustomApis
}]
}]
}, this.bearer);
const conditions: Condition[] = [];
for (const solutionComponent of solutionComponents) {
const objectid = solutionComponent.objectid;
for (const solutionComponentSummary of solutionComponentSummaries) {
const msdyn_objectid = solutionComponentSummary.msdyn_objectid;
conditions.push({
attribute: 'customapiid',
value: objectid,
value: msdyn_objectid,
});
}
return CustomApiService.retrieveMultipleRecords({
Expand Down
41 changes: 28 additions & 13 deletions src/commands/generators/Entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,35 @@ export class Entity {
}

public async generate(): Promise<void> {
await this.generateEntityFiles();
console.log(`Generating files for Entity '${this.entityName}'`);
console.log(`Using entityLogicalName '${this.entityLogicalName}'`);
const model = new Model(this.bearer, this.entityName);
await model.generate();
await Enum.generateEnum(this.bearer, this.entityName, this.entityLogicalName);
if (!this.options.skipForms) {
await AttributeTypings.generate(this.bearer, this.entityName, this.entityLogicalName);
await AttributeFormContext.generateFormContext(this.bearer, this.entityName, this.entityLogicalName);
await Form.generateFormFiles(this.bearer, this.entityName, this.entityLogicalName);
} else {
console.log('Skip generate form files');
try {
await this.generateEntityFiles();
console.log(`Generating files for Entity '${this.entityName}'`);
console.log(`Using entityLogicalName '${this.entityLogicalName}'`);
const model = new Model(this.bearer, this.entityName);
await model.generate();
await Enum.generateEnum(this.bearer, this.entityName, this.entityLogicalName);
if (!this.options.skipForms) {
await AttributeTypings.generate(this.bearer, this.entityName, this.entityLogicalName);
await AttributeFormContext.generateFormContext(this.bearer, this.entityName, this.entityLogicalName);
await Form.generateFormFiles(this.bearer, this.entityName, this.entityLogicalName);
} else {
console.log('Skip generate form files');
}
console.log('Generating files finished');
} catch (e) {
console.log(colors.red(`Form.generateFormFiles failed for ${this.entityName} ${JSON.stringify(e)}`));
await this.wait();
console.log(colors.red(`New try for failed ${this.entityName}`));
await this.generate();
}
console.log('Generating files finished');
}

private wait(): Promise<void> {
return new Promise(resolve => {
setTimeout(() => {
resolve();
}, 5000);
});
}

private async generateEntityFiles(): Promise<void> {
Expand Down
16 changes: 8 additions & 8 deletions src/commands/generators/EnvironmentVariable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import * as shell from 'shelljs';
import * as fs from 'fs';
import {PublisherService} from '../../node/Publisher/Publisher.service';
import {SolutionService} from '../../node/Solution/Solution.service';
import {SolutionComponentService} from '../../node/SolutionComponent/SolutionComponent.service';
import {EnvironmentVariableDefinitionService} from '../../node/EnvironmentVariableDefinition/EnvironmentVariableDefinition.service';
import {EnvironmentVariableDefinitionModel} from '../../node/EnvironmentVariableDefinition/EnvironmentVariableDefinition.model';
import {WebresourcesCrmJson} from '../../root/Webresources/CrmJson';
import {SolutionComponentSummaryService} from '../../node/SolutionComponentSummary/SolutionComponentSummary.service';

export class EnvironmentVariable {
private readonly bearer: string;
Expand Down Expand Up @@ -92,29 +92,29 @@ export class EnvironmentVariable {
const settings: WebresourcesCrmJson = JSON.parse(fs.readFileSync('./crm.json', 'utf8'));
const {solution_name_generate} = settings.crm;
const solution = await SolutionService.getSolution(solution_name_generate, ['solutionid'], this.bearer);
const solutionComponents = await SolutionComponentService.retrieveMultipleRecords({
select: ['objectid'],
const solutionComponentSummaries = await SolutionComponentSummaryService.retrieveMultipleRecords({
select: ['msdyn_objectid'],
filters: [{
conditions: [{
attribute: '_solutionid_value',
attribute: 'msdyn_solutionid',
value: solution.solutionid
}]
}, {
type: 'or',
conditions: [{
attribute: 'componenttype',
attribute: 'msdyn_componenttype',
value: 380
}]
}]
}, this.bearer);
for (const solutionComponent of solutionComponents) {
const objectid = solutionComponent.objectid;
for (const solutionComponentSummary of solutionComponentSummaries) {
const msdyn_objectid = solutionComponentSummary.msdyn_objectid;
const envVariableDefinitions = await EnvironmentVariableDefinitionService.retrieveMultipleRecords( {
select: ['defaultvalue', 'schemaname', 'type'],
filters: [{
conditions: [{
attribute: 'environmentvariabledefinitionid',
value: objectid
value: msdyn_objectid
}]
}]
}, this.bearer);
Expand Down
38 changes: 15 additions & 23 deletions src/commands/generators/Form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {SystemFormService} from '../../node/SystemForm/SystemForm.service';
import {FormTypings} from './FormTypings';
import {WebresourcesCrmJson} from '../../root/Webresources/CrmJson';
import {SolutionService} from '../../node/Solution/Solution.service';
import {SolutionComponentService} from '../../node/SolutionComponent/SolutionComponent.service';
import {SolutionComponentSummaryService} from '../../node/SolutionComponentSummary/SolutionComponentSummary.service';

export class Form {
private readonly bearer: string;
Expand Down Expand Up @@ -104,56 +104,48 @@ export class Form {
private async getSystemForms(): Promise<SystemFormModel[]> {
const settings: WebresourcesCrmJson = JSON.parse(fs.readFileSync('./crm.json', 'utf8'));
const {solution_name_generate, only_solution_forms} = settings.crm;
const solution = await SolutionService.getSolution(solution_name_generate, ['solutionid'], this.bearer);
const filters: Filter[] = [{
type: 'or',
conditions: [{
attribute: 'componenttype',
attribute: 'msdyn_componenttype',
value: 24 // Form
}, {
attribute: 'componenttype',
attribute: 'msdyn_componenttype',
value: 60 // System Form
}]
}, {
conditions: [{
attribute: 'msdyn_primaryentityname',
value: this.entityLogicalName
}]
}];
if (only_solution_forms) {
const solution = await SolutionService.getSolution(solution_name_generate, ['solutionid'], this.bearer);
filters.push({
conditions: [{
attribute: '_solutionid_value',
attribute: 'msdyn_solutionid',
value: solution.solutionid
}]
});
}
const solutionComponents = await SolutionComponentService.retrieveMultipleRecords({
select: ['objectid'],
const solutionComponentSummaries = await SolutionComponentSummaryService.retrieveMultipleRecords({
select: ['msdyn_objectid'],
filters: filters,
}, this.bearer);
const conditions: Condition[] = [];
for (const solutionComponent of solutionComponents) {
const objectid = solutionComponent.objectid;
for (const solutionComponentSummary of solutionComponentSummaries) {
const msdyn_objectid = solutionComponentSummary.msdyn_objectid;
conditions.push({
attribute: 'formid',
value: objectid,
value: msdyn_objectid,
});
}
return SystemFormService.retrieveMultipleRecords({
select: ['formid', 'description', 'name', 'objecttypecode', 'formjson'],
filters: [{
type: 'or',
conditions: conditions
}, {
conditions: [{
attribute: 'objecttypecode',
value: this.entityLogicalName
}]
}]
}, this.bearer);
}

// private async getSystemForms(): Promise<SystemFormModel[]> {
// const systemForms = await SystemFormService.getSystemForms(this.entityLogicalName, ['objecttypecode', 'name', 'formjson'], this.bearer);
// for (const systemForm of systemForms) {
// console.log(colors.blue(`Form '${systemForm.name}' found`));
// }
// return systemForms;
// }
}
28 changes: 14 additions & 14 deletions src/commands/generators/Regenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {GlobalOptionSet} from './GlobalOptionSet';
import {EnvironmentVariable} from './EnvironmentVariable';
import {WebresourcesCrmJson} from '../../root/Webresources/CrmJson';
import {SolutionService} from '../../node/Solution/Solution.service';
import {SolutionComponentService} from '../../node/SolutionComponent/SolutionComponent.service';
import {EntityService} from '../../node/Entity/Entity.service';
import { EntityModel } from '../../node/Entity/Entity.model';
import {SolutionComponentSummaryService} from '../../node/SolutionComponentSummary/SolutionComponentSummary.service';

export class Regenerator {
private readonly bearer: string;
Expand All @@ -15,21 +15,21 @@ export class Regenerator {
this.bearer = bearer;
}

public async generate(): Promise<void> {
public generate(): void {
console.log('Regenerating. This may take some time...');
await this.regenerateEntities();
await this.regenerateGlobalOptionSets();
await this.regenerateEnvironmentVariable();
this.regenerateEntities().then();
this.regenerateGlobalOptionSets().then();
this.regenerateEnvironmentVariable().then();
console.log('Generated');
}

private async regenerateEntities(): Promise<void> {
const entityModels = await this.getEntities();
for (const entityModel of entityModels) {
const physicalName = entityModel.originallocalizedname || entityModel.physicalname;
const folderName = physicalName.replaceAll(' ', '');
const folderName = physicalName.replaceAll(/\W/g, '');
const entity = new Entity(this.bearer, folderName, entityModel.logicalname, {});
await entity.generate();
entity.generate().then();
}
}

Expand All @@ -41,25 +41,25 @@ export class Regenerator {
const filters: Filter[] = [{
type: 'or',
conditions: [{
attribute: 'componenttype',
attribute: 'msdyn_componenttype',
value: 1 // Entity
}]
}, {
conditions: [{
attribute: '_solutionid_value',
attribute: 'msdyn_solutionid',
value: solution.solutionid
}]
}];
const solutionComponents = await SolutionComponentService.retrieveMultipleRecords({
select: ['objectid'],
const solutionComponentSummaries = await SolutionComponentSummaryService.retrieveMultipleRecords({
select: ['msdyn_objectid'],
filters: filters,
}, this.bearer);
const conditions: Condition[] = [];
for (const solutionComponent of solutionComponents) {
const objectid = solutionComponent.objectid;
for (const solutionComponentSummary of solutionComponentSummaries) {
const msdyn_objectid = solutionComponentSummary.msdyn_objectid;
conditions.push({
attribute: 'entityid',
value: objectid,
value: msdyn_objectid,
});
}
return EntityService.retrieveMultipleRecords({
Expand Down
Loading

0 comments on commit ccbd8e9

Please sign in to comment.