Developer Docs

SpringBot Sharing Attributes Across Entities

Client-side

Adding to the View

Attributes can be added to all entities by updating the abstract.model.ts file, which all entities inherit from. This can be found at clientside/src/app/lib/models/abstract.model.ts.

For example, to add a new string attribute called Name to every entity, we would do the following:

  1. Activate the protected region called Add any additional default model properties here in abstract.model.ts.
  2. Add the attribute:

     // % protected region % [Add any additional default model properties here] on begin
      {
          name: 'name',
          displayName: 'Name',
          type: ModelPropertyType.STRING,
      },
      // % protected region % [Add any additional default model properties here] end
    

You will now have a Name attribute visible on all entities, however, you will not be able to utilise it as it doesn’t exist within the persistence layer.

Adding to the Persistence Layer

  1. Activate the protected region called Add any additional class fields here in abstract.model.ts.
  2. Add the following:

     // % protected region % [Add any additional class fields here] on begin
      name: string;
      // % protected region % [Add any additional class fields here] end
    
  3. Activate the protected region called Add any additional assignments here in abstract.model.ts.
  4. Add the following into it:

     // % protected region % [Add any additional assignments here] on begin
      this.name = json.name;
      // % protected region % [Add any additional assignments here] end
    
  5. Activate the protected region called Add additional toJSON attributes here in abstract.model.ts.
  6. Add the following into it:

     // % protected region % [Add additional toJSON attributes here] on begin
      name: this.name,
      // % protected region % [Add additional toJSON attributes here] end
    
  7. Open the file clientside/src/app/lib/services/http/abstract-http.service.ts and activate the protected region called Add additional base properties here.
  8. Add the following:

     // % protected region % [Add additional base properties here] on begin
      extraBaseProperties += 'name';
      // % protected region % [Add additional base properties here] end
    

Server-side

Similar to the client-side, we can make use of our AbstractEntity.java to add additional attributes. This file can be found at serverside/src/main/java/[projectName]/entities/AbstractEntity.java

Following the example started in the client-side section, we will achieve this by completing the following steps:

  1. Activate the protected region called Add any additional class methods here in AbstractEntity.java.
  2. Add the attribute using the following code:

     // % protected region % [Add any additional class methods here] on begin
      @ApiModelProperty(notes = "The name.")
      @Column(name = "name")
      private String name;
      // % protected region % [Add any additional class methods here] end
    

    You will notice that we also add the API documentation to this attribute using the ApiModelProperty annotation. This is important to ensure that our API documentation stays up to date.
    References can be added in a similar manner, but be careful, since all entities inherit from the AbstractEntity you may end up adding a self reference to the source entity.

  3. Open serverside/src/main/resources/graphql/schemas/myuser.schema.graphql and activate the protected region called Add any additional field definition here.
  4. Add the following to it:

     # % protected region % [Add any additional field definition here] on begin
      name: String
      # % protected region % [Add any additional field definition here] end
    
  5. In the same file, activate the protected region called Add any additional field definition for input type here
  6. Add the following:

     # % protected region % [Add any additional field definition for input type here] on begin
      name: String
      # % protected region % [Add any additional field definition for input type here] end
    

Was this article helpful?

Thanks for your feedback!

If you would like to tell us more, please click on the link below to send us a message with more details.

Tool:

Generate

Iterate

Bot:

C#Bot

SpringBot

On this page

New to Codebots?

We know our software can be complicated, so we are always happy to have a chat if you have any questions.