Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: Stepan Kiryakov <[email protected]>
  • Loading branch information
Stepan-Kirjakov committed Jan 28, 2025
1 parent b36d755 commit 67b0e73
Show file tree
Hide file tree
Showing 18 changed files with 515 additions and 47 deletions.
27 changes: 27 additions & 0 deletions api-gateway/src/middlewares/validation/schemas/formulas.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ export class FormulaDTO {
@IsString()
owner?: string;

@ApiProperty({
type: 'string',
required: false,
example: Examples.MESSAGE_ID
})
@IsOptional()
@IsString()
messageId?: string;

@ApiProperty({
type: 'string',
required: false,
Expand All @@ -67,6 +76,24 @@ export class FormulaDTO {
@IsString()
policyId?: string;

@ApiProperty({
type: 'string',
required: false,
example: Examples.ACCOUNT_ID
})
@IsOptional()
@IsString()
policyTopicId?: string;

@ApiProperty({
type: 'string',
required: false,
example: Examples.ACCOUNT_ID
})
@IsOptional()
@IsString()
policyInstanceTopicId?: string;

@ApiProperty({
type: 'string',
required: false,
Expand Down
15 changes: 15 additions & 0 deletions common/src/entity/formula.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ export class Formula extends BaseEntity implements IFormula {
@Property({ nullable: true })
status?: EntityStatus;

/**
* Message id
*/
@Property({ nullable: true })
messageId?: string;

/**
* Policy id
*/
Expand All @@ -64,6 +70,15 @@ export class Formula extends BaseEntity implements IFormula {
})
policyTopicId?: string;

/**
* Policy Instance Topic id
*/
@Property({
nullable: true,
index: true
})
policyInstanceTopicId?: string;

/**
* Config
*/
Expand Down
202 changes: 202 additions & 0 deletions common/src/hedera-modules/message/formula-message.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
import { Message } from './message.js';
import { IURL, UrlType } from './url.interface.js';
import { MessageAction } from './message-action.js';
import { MessageType } from './message-type.js';
import { FormulaMessageBody } from './message-body.interface.js';
import { Formula } from '../../entity/index.js';
import { IPFS } from '../../helpers/index.js';

/**
* Formula message
*/
export class FormulaMessage extends Message {
/**
* Name
*/
public name: string;
/**
* Description
*/
public description: string;
/**
* Owner
*/
public owner: string;
/**
* UUID
*/
public uuid: string;
/**
* Policy topic id
*/
public policyTopicId: string;
/**
* Policy Instance topic id
*/
public policyInstanceTopicId: string;

/**
* Document
*/
public config: ArrayBuffer;

constructor(action: MessageAction) {
super(action, MessageType.Formula);
}

/**
* Set document
* @param item
*/
public setDocument(item: Formula, zip: ArrayBuffer): void {
this.name = item.name;
this.description = item.description;
this.owner = item.owner;
this.uuid = item.uuid;
this.policyTopicId = item.policyTopicId;
this.policyInstanceTopicId = item.policyInstanceTopicId;
this.config = zip;
}

/**
* Get document
*/
public getDocument(): ArrayBuffer {
return this.config;
}

/**
* To message object
*/
public override toMessageObject(): FormulaMessageBody {
return {
id: null,
status: null,
type: this.type,
action: this.action,
lang: this.lang,
name: this.name,
description: this.description,
owner: this.owner,
uuid: this.uuid,
policyTopicId: this.policyTopicId,
policyInstanceTopicId: this.policyInstanceTopicId,
cid: this.getDocumentUrl(UrlType.cid),
uri: this.getDocumentUrl(UrlType.url),
};
}

/**
* To documents
*/
public async toDocuments(): Promise<ArrayBuffer[]> {
if (this.config) {
return [this.config];
}
return [];
}

/**
* Load documents
* @param documents
*/
public loadDocuments(documents: string[]): FormulaMessage {
if (documents && documents.length === 1) {
this.config = Buffer.from(documents[0]);
}
return this;
}

/**
* From message
* @param message
*/
public static fromMessage(message: string): FormulaMessage {
if (!message) {
throw new Error('Message Object is empty');
}

const json = JSON.parse(message);
return FormulaMessage.fromMessageObject(json);
}

/**
* From message object
* @param json
*/
public static fromMessageObject(json: FormulaMessageBody): FormulaMessage {
if (!json) {
throw new Error('JSON Object is empty');
}

let message = new FormulaMessage(json.action);
message = Message._fromMessageObject(message, json);
message._id = json.id;
message._status = json.status;
message.name = json.name;
message.description = json.description;
message.owner = json.owner;
message.uuid = json.uuid;
message.policyTopicId = json.policyTopicId;
message.policyInstanceTopicId = json.policyInstanceTopicId;
const urls = [
{
cid: json.cid,
url: IPFS.IPFS_PROTOCOL + json.cid,
},
];
message.setUrls(urls);
return message;
}

/**
* Get URL
*/
public override getUrl(): IURL[] {
return this.getUrls();
}

/**
* Get document URL
* @param type
*/
public getDocumentUrl(type: UrlType): string | null {
return this.getUrlValue(0, type);
}

/**
* Get context URL
* @param type
*/
public getContextUrl(type: UrlType): string | null {
return this.getUrlValue(1, type);
}

/**
* Validate
*/
public override validate(): boolean {
return true;
}

/**
* To JSON
*/
public override toJson(): any {
const result = super.toJson();
result.name = this.name;
result.description = this.description;
result.owner = this.owner;
result.uuid = this.uuid;
result.policyTopicId = this.policyTopicId;
result.policyInstanceTopicId = this.policyInstanceTopicId;
result.config = this.config;
}

/**
* Get User DID
*/
public override getOwner(): string {
return this.owner;
}
}
3 changes: 2 additions & 1 deletion common/src/hedera-modules/message/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ export { UserPermissionsMessage } from './user-permissions-message.js';
export { StatisticMessage } from './statistic-message.js';
export { StatisticAssessmentMessage } from './statistic-assessment-message.js';
export { LabelMessage } from './label-message.js';
export { LabelDocumentMessage } from './label-document-message.js';
export { LabelDocumentMessage } from './label-document-message.js';
export { FormulaMessage } from './formula-message.js';
1 change: 1 addition & 0 deletions common/src/hedera-modules/message/message-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ export enum MessageAction {
CreateStatisticAssessment = 'create-assessment-document',
PublishPolicyLabel = 'publish-policy-label',
CreateLabelDocument = 'create-label-document',
PublishFormula = 'publish-formula',
}
38 changes: 38 additions & 0 deletions common/src/hedera-modules/message/message-body.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,44 @@ export interface LabelMessageBody extends MessageBody {
uri: string;
}

/**
* Formula message body
*/
export interface FormulaMessageBody extends MessageBody {
/**
* UUID
*/
uuid: string;
/**
* Name
*/
name: string;
/**
* Description
*/
description: string;
/**
* Owner
*/
owner: string;
/**
* Policy topic ID
*/
policyTopicId: string;
/**
* Policy instance topic ID
*/
policyInstanceTopicId: string;
/**
* CID
*/
cid: string;
/**
* URI
*/
uri: string;
}

/**
* Statistic Assessment message body
*/
Expand Down
4 changes: 4 additions & 0 deletions common/src/hedera-modules/message/message-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { GuardianRoleMessage } from './guardian-role-message.js';
import { UserPermissionsMessage } from './user-permissions-message.js';
import { StatisticMessage } from './statistic-message.js';
import { LabelMessage } from './label-message.js';
import { FormulaMessage } from './formula-message.js';

/**
* Message server
Expand Down Expand Up @@ -315,6 +316,9 @@ export class MessageServer {
case MessageType.PolicyLabel:
message = LabelMessage.fromMessageObject(json);
break;
case MessageType.Formula:
message = FormulaMessage.fromMessageObject(json);
break;
// Default schemas
case 'schema-document':
message = SchemaMessage.fromMessageObject(json);
Expand Down
3 changes: 2 additions & 1 deletion common/src/hedera-modules/message/message-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ export enum MessageType {
Contract = 'Contract',
UserPermissions = 'User-Permissions',
PolicyStatistic = 'Policy-Statistic',
PolicyLabel = 'Policy-Label'
PolicyLabel = 'Policy-Label',
Formula = 'Formula'
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p-dropdown
#dropdown
*ngIf="!disabled"
[(ngModel)]="value"
[options]="list"
[showClear]="false"
class="guardian-dropdown guardian-dropdown-status status-{{status}}"
Expand All @@ -9,9 +9,10 @@
optionValue="value"
[placeholder]="label"
panelStyleClass="guardian-dropdown-panel guardian-dropdown-status-panel"
(onChange)="onChange()"
(onChange)="onChange($event, dropdown)"
>
<ng-template pTemplate="selectedItem">
{{label}}
</ng-template>
<ng-template let-option pTemplate="item">
<div>
Expand Down
Loading

0 comments on commit 67b0e73

Please sign in to comment.