Skip to content

Commit

Permalink
Merge branch 'develop' into feature/3966-database-access-layer-refact…
Browse files Browse the repository at this point in the history
…oring-tests
  • Loading branch information
ihar-tsykala authored Sep 8, 2024
2 parents 3e49692 + ba56dcf commit 8706ce7
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 71 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ The following steps need to be executed in order to start Guardian using docker:
3. Update BC access variables
4. Setup IPFS
5. Build and launch with Docker
6. Browse to [http://localhost:3000](http://localhost:3000)
6. Browse to http://localhost:3000

Here the steps description follows:

Expand Down Expand Up @@ -274,12 +274,12 @@ This will start the containers in detached mode (-d) and build them if necessary
> **_NOTE:_** From the end of June 2023 Compose V1 won’t be supported anymore and will be removed from all Docker Desktop versions. Make sure you use Docker Compose V2 (comes with Docker Desktop > 3.6.0) as at https://docs.docker.com/compose/install/
#### 7. Browse to <http://localhost:3000> and complete the setup.
#### 7. Browse to http://localhost:3000 and complete the setup.

for other examples go to:
* [Deploying Guardian using a specific environment( DEVELOP)](https://docs.hedera.com/guardian/guardian/readme/getting-started/installation/building-from-source-and-run-using-docker/deploying-guardian-using-a-specific-environment-develop.md)
* [Steps to deploy Guardian using a specific Environment ( QA)](https://docs.hedera.com/guardian/guardian/readme/getting-started/installation/building-from-source-and-run-using-docker/deploying-guardian-using-a-specific-environment-qa.md)
* [Steps to deploy Guardian using default Environment](https://docs.hedera.com/guardian/guardian/readme/getting-started/installation/building-from-source-and-run-using-docker/deploying-guardian-using-default-environment.md)
* [Deploying Guardian using a specific environment( DEVELOP)](https://docs.hedera.com/guardian/guardian/readme/getting-started/installation/building-from-source-and-run-using-docker/deploying-guardian-using-a-specific-environment-develop)
* [Steps to deploy Guardian using a specific Environment ( QA)](https://docs.hedera.com/guardian/guardian/readme/getting-started/installation/building-from-source-and-run-using-docker/deploying-guardian-using-a-specific-environment-qa)
* [Steps to deploy Guardian using default Environment](https://docs.hedera.com/guardian/guardian/readme/getting-started/installation/building-from-source-and-run-using-docker/deploying-guardian-using-default-environment)


## Manual installation
Expand Down Expand Up @@ -492,7 +492,7 @@ For setting up AI and Guided Search, we need to set OPENAI_API_KEY variable in `
```
Configure the service as previously described. Update **OPERATOR_ID** and **OPERATOR_KEY** values in `./guardian-service/configs/.env.worker` file as in the example above.

To start the service (found on <http://localhost:3002>):
To start the service (found on http://localhost:3002):

Yarn:
```shell
Expand All @@ -519,7 +519,7 @@ npm --workspace=guardian-service run build
Configure the service as previously described. Update **OPERATOR_ID** and **OPERATOR_KEY** values
in `./guardian-service/configs/.env.worker` file as in the example above.

To start the service (found on <http://localhost:3002>):
To start the service (found on http://localhost:3002):

Yarn:
```shell
Expand Down Expand Up @@ -547,7 +547,7 @@ npm --workspace=api-gateway run build

Configure the service as previously described. Do not need special configuration variables.

To start the service (found on <http://localhost:3002>):
To start the service (found on http://localhost:3002):

Yarn:
```shell
Expand All @@ -570,7 +570,7 @@ npm --workspace=api-gateway start

Configure the service as previously described. Do not need special configuration variables.

To start the service (found on <http://localhost:3005>):
To start the service (found on http://localhost:3005):

```shell
npm start
Expand Down Expand Up @@ -611,7 +611,7 @@ npm --workspace=ai-service start
npm run build
```

To start the service (found on <http://localhost:4200>):
To start the service (found on http://localhost:4200):

```shell
npm start
Expand Down Expand Up @@ -683,7 +683,7 @@ npm --workspace=ai-service start
docker compose -f docker-compose-dev.yml up --build
```

#### 3. Access local development using <http://localhost:3000> or <http://localhost:4200>
#### 3. Access local development using http://localhost:3000 or http://localhost:4200

## Troubleshoot

Expand Down
19 changes: 8 additions & 11 deletions analytics-service/src/analytics/document.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,8 @@ export class AnalyticsDocumentService {
instanceTopicId: instance.instanceTopicId,
timeStamp: data.id,
account: data.payer,
type: DocumentType.ROLE,
issuer: data.issuer,
role: data.role,
group: data.group,
type: DocumentType.DID,
issuer: data.did,
action: data.action,
ipfs: data.getUrlValue(0, UrlType.cid)
};
Expand All @@ -176,14 +174,13 @@ export class AnalyticsDocumentService {
policyUUID: instance.policyUUID,
policyTopicId: instance.policyTopicId,
instanceTopicId: instance.instanceTopicId,
timeStamp: data.id,
account: data.payer,
type: DocumentType.ROLE,
issuer: data.issuer,
role: data.role,
group: data.group,
action: data.action,
ipfs: data.getUrlValue(0, UrlType.cid)
timeStamp: data.id,
topicId: data.childId,
name: data.name,
description: data.description,
owner: data.owner,
action: data.action
};
const databaseServer = new DatabaseServer();

Expand Down
10 changes: 4 additions & 6 deletions analytics-service/src/analytics/policy.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,13 @@ export class AnalyticsPolicyService {
root: report.root,
account: data.payer,
timeStamp: data.id,
tagUUID: data.uuid,
name: data.name,
description: data.description,
owner: data.owner,
target: data.target,
operation: data.operation,
entity: data.entity,
date: data.date,
action: data.action
version: data.version,
owner: sr.did,
action: data.action,
ipfs: data.getDocumentUrl(UrlType.cid)
};
const databaseServer = new DatabaseServer();

Expand Down
6 changes: 3 additions & 3 deletions analytics-service/src/analytics/report.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ export class ReportService {
const modules = await databaseServer.find(Module, { uuid });
const users = await databaseServer.find(User, { uuid });
const tags = await databaseServer.find(Tag, { uuid, action: MessageAction.PublishTag });
const userTopicCount = await databaseServer.find(Topic, { uuid });
const schemaCount = await databaseServer.find(Schema, { uuid, action: MessageAction.PublishSchema });
const systemSchemaCount = await databaseServer.find(Schema, { uuid, action: MessageAction.PublishSystemSchema });
const userTopicCount = await databaseServer.count(Topic, { uuid });
const schemaCount = await databaseServer.count(Schema, { uuid, action: MessageAction.PublishSchema });
const systemSchemaCount = await databaseServer.count(Schema, { uuid, action: MessageAction.PublishSystemSchema });

const docByPolicy =
await databaseServer.aggregate(Document, databaseServer.getAnalyticsDocAggregationFilters(MAP_REPORT_ANALYTICS_AGGREGATION_FILTERS.DOC_BY_POLICY, uuid) as FilterObject<any>[])
Expand Down
25 changes: 11 additions & 14 deletions common/src/database-modules/database-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ export class DatabaseServer extends AbstractDatabaseServer {
*
* @virtual
*/
public async getPolicy(policyId: string): Promise<Policy | null> {
public async getPolicy(policyId: string | null): Promise<Policy | null> {
return await new DataBaseHelper(Policy).findOne(policyId);
}

Expand Down Expand Up @@ -2386,11 +2386,8 @@ export class DatabaseServer extends AbstractDatabaseServer {
* Get schema
* @param id
*/
public static async getSchemaById(id: string): Promise<SchemaCollection | null> {
if (id) {
return await new DataBaseHelper(SchemaCollection).findOne(id);
}
return null;
public static async getSchemaById(id: string | null): Promise<SchemaCollection | null> {
return await new DataBaseHelper(SchemaCollection).findOne(id);
}

/**
Expand Down Expand Up @@ -2461,7 +2458,7 @@ export class DatabaseServer extends AbstractDatabaseServer {
* Get policy by id
* @param policyId
*/
public static async getPolicyById(policyId: string): Promise<Policy | null> {
public static async getPolicyById(policyId: string | null): Promise<Policy | null> {
return await new DataBaseHelper(Policy).findOne(policyId);
}

Expand Down Expand Up @@ -2577,7 +2574,7 @@ export class DatabaseServer extends AbstractDatabaseServer {
* Get VC
* @param id
*/
public static async getVCById(id: string): Promise<VcDocumentCollection> | null {
public static async getVCById(id: string | null): Promise<VcDocumentCollection> | null {
return await new DataBaseHelper(VcDocumentCollection).findOne(id);
}

Expand All @@ -2603,7 +2600,7 @@ export class DatabaseServer extends AbstractDatabaseServer {
* Get VC
* @param id
*/
public static async getVPById(id: string): Promise<VpDocumentCollection | null> {
public static async getVPById(id: string | null): Promise<VpDocumentCollection | null> {
return await new DataBaseHelper(VpDocumentCollection).findOne(id);
}

Expand Down Expand Up @@ -3052,7 +3049,7 @@ export class DatabaseServer extends AbstractDatabaseServer {
* Get Token by ID
* @param id
*/
public static async getTokenById(id: string): Promise<TokenCollection | null> {
public static async getTokenById(id: string | null): Promise<TokenCollection | null> {
return await new DataBaseHelper(TokenCollection).findOne(id);
}

Expand All @@ -3069,7 +3066,7 @@ export class DatabaseServer extends AbstractDatabaseServer {
* Get Contract by ID
* @param id
*/
public static async getContractById(id: string): Promise<ContractCollection | null> {
public static async getContractById(id: string | null): Promise<ContractCollection | null> {
return await new DataBaseHelper(ContractCollection).findOne(id);
}

Expand Down Expand Up @@ -3145,9 +3142,9 @@ export class DatabaseServer extends AbstractDatabaseServer {

/**
* Get Module By ID
* @param uuid
* @param id
*/
public static async getModuleById(id: string): Promise<PolicyModule | null> {
public static async getModuleById(id: string | null): Promise<PolicyModule | null> {
return await new DataBaseHelper(PolicyModule).findOne(id);
}

Expand Down Expand Up @@ -3225,7 +3222,7 @@ export class DatabaseServer extends AbstractDatabaseServer {
* Get Tool By ID
* @param id
*/
public static async getToolById(id: string): Promise<PolicyTool | null> {
public static async getToolById(id: string | null): Promise<PolicyTool | null> {
return await new DataBaseHelper(PolicyTool).findOne(id);
}

Expand Down
6 changes: 5 additions & 1 deletion common/src/helpers/db-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,9 +628,13 @@ export class DataBaseHelper<T extends BaseEntity> extends AbstractDataBaseHelper
* @returns Entity
*/
@CreateRequestContext(() => DataBaseHelper.orm)
public async findOne(filters: FilterQuery<T> | string | ObjectId, options: FindOneOptions<object> = {}): Promise<T | null> {
public async findOne(filters: FilterQuery<T> | string | ObjectId | null, options: FindOneOptions<object> = {}): Promise<T | null> {
let query: FilterQuery<T>;

if(!filters) {
return null
}

if (typeof filters === 'string' || filters instanceof ObjectId) {
query = { _id: filters } as FilterQuery<T>;
} else {
Expand Down
46 changes: 46 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,49 @@
# 🌏 Getting Started

## **1. Introduction**

The Guardian is an innovative open-source platform that streamlines the creation, management, and verification of digital environmental assets. It leverages a customizable Policy Workflow Engine and Web3 technology to ensure transparent and fraud-proof operations, making it a key tool for transforming sustainability practices and carbon markets.

## **2. Prerequisites**

Before starting with Hedera Guardian, ensure that your environment meets the following requirements:

* [Install Git](https://git-scm.com/).
* [Docker](https://www.docker.com/) (To build with one command)
* [MongoDB](https://www.mongodb.com/)[ V6](https://www.mongodb.com/) , [NodeJS](https://nodejs.org/)[ v16](https://nodejs.org/en) and [Nats](https://nats.io/)[ 1.12.2](https://nats.io/) (If you build with docker these components will be installed automatically)
* [Hedera Testnet Account](https://portal.hedera.com/)
* [Web3.Storage Account](https://web3.storage/)
* [Filebase Account](https://filebase.com/)
* [Redict 7.3.0](https://redict.io/)

## **3. Installation**

There are multiple ways to Install Guardian:

1. [Using Docker](guardian/readme/getting-started/installation/building-from-source-and-run-using-docker/)
2. [Pre-Build Containers](guardian/readme/getting-started/installation/building-from-pre-build-containers.md)
3. [Manually](guardian/readme/getting-started/installation/build-executables-and-run-manually.md)

## **4. Troubleshooting**

* **Server not starting?** Ensure that Docker is running and all containers are up.
* **Cannot access the admin dashboard?** Check if the correct ports (3000) are open and not blocked by your firewall.
* **Issues with API calls?** Verify that your Hedera account ID and private key are correctly configured in the `.env` file.
* For additional help, visit the [Hedera Guardian GitHub Issues](https://github.com/hashgraph/guardian/issues).

## **7. Additional Resources**

* [Hedera Guardian Documentation](https://github.com/hashgraph/guardian/wiki)
* [Hedera Developer Portal](https://portal.hedera.com/login)
* [Community Forum](https://github.com/hashgraph/guardian/discussions)
* [Roadmap](guardian/readme/roadmap.md)
* [Youtube Channel](https://www.youtube.com/@envisionblockchain/featured)

## **8. Feedback and Support**

* For support, reach out via Hedera Discord Sustainability channel or email us at [email protected].
* Submit feedback or feature requests through the [GitHub repository](https://github.com/hashgraph/guardian/issues).

## **9. Legal and Licensing**

* Hedera Guardian is open-source and licensed under the Apache 2.0 License. Please review the [LICENSE](https://github.com/hashgraph/guardian/blob/main/LICENSE) file for more details.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

| Block Property | Definition | Example Input | Status |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------- | ------ |
| type | A type of the block which creates a well formed 'credential subject' part of a future VC Document. | **requestVCDocumentBlock** (Can't be changed). | |
| type | A type of the block which receives data in the format of a ‘credential subject part of a VC Document | **requestVCDocumentBlock** (Can't be changed). | |
| tag | Unique name for the logic block. | add\_new\_installer\_request. | |
| permissions | Which entity has rights to interact at this part of the workflow. | Standard Registry. | |
| defaultActive | Shows whether this block is active at this time and whether it needs to be shown. | Checked or unchecked. | |
Expand Down Expand Up @@ -43,20 +43,17 @@ To know more information about events, please look at [Events](events.md).

### API Parameters

{% swagger method="get" path="" baseUrl="/policies/{policyId}/blocks/{uuid}" summary="" %}
{% swagger-description %}
<mark style="color:blue;">`GET`</mark> `/policies/{policyId}/blocks/{uuid}`

{% endswagger-description %}
#### Path Parameters

{% swagger-parameter in="path" name="uuid" type="String" required="true" %}
Block ID
{% endswagger-parameter %}
| Name | Type | Description |
| ------------------------------------------ | ------ | ----------- |
| uuid<mark style="color:red;">\*</mark> | String | Block ID |
| policyId<mark style="color:red;">\*</mark> | String | Policy ID |

{% swagger-parameter in="path" name="policyId" type="String" required="true" %}
Policy ID
{% endswagger-parameter %}

{% swagger-response status="200: OK" description="Successful Operation" %}
{% tabs %}
{% tab title="200: OK Successful Operation" %}
```javascript
{
"id": "ef2a7742-68d4-407f-ada7-14cdce80e24d",
Expand Down Expand Up @@ -264,19 +261,14 @@ Policy ID
"$comment": "{\"term\":\"field6\",\"@id\":\"https://www.schema.org/text\",\"orderPosition\":6}"
.....
```
{% endswagger-response %}
{% endswagger %}
{% swagger method="post" path="" baseUrl="/policies/{policyId}/blocks/{uuid}" summary="" %}
{% swagger-description %}
{% endtab %}
{% endtabs %}
{% endswagger-description %}
<mark style="color:green;">`POST`</mark> `/policies/{policyId}/blocks/{uuid}`
{% swagger-parameter in="body" name="document" type="VC" required="true" %}
VC Document
{% endswagger-parameter %}
#### Request Body
{% swagger-parameter in="body" name="ref" type="String" required="false" %}
ID of linked VC
{% endswagger-parameter %}
{% endswagger %}
| Name | Type | Description |
| ------------------------------------------ | ------ | ------------------ |
| document<mark style="color:red;">\*</mark> | Object | Credential Subject |
| ref | String | ID of linked VC |

0 comments on commit 8706ce7

Please sign in to comment.