Skip to content

create a ralation ship object #112

@hadesgrid

Description

@hadesgrid

Hello Stephen

I am tryind to create a ralation ship object

Relationship usesRel = Relationship.builder()
	                .relationshipType("uses")
	                .created(Instant.now())
	                .sourceRef(AttackPattern.builder()
	                        .name("Some Attack Pattern 1")
	                        .build())
	                .targetRef(Malware.builder()
	                        .name("dog")
	                        .addLabels("worm")
	                        .build())
	                .build();

the Relationship class is


ackage io.digitalstate.stix.sro.objects;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;

import io.digitalstate.stix.bundle.Bundle;
import io.digitalstate.stix.sdo.DomainObject;

@JsonDeserialize(builder = Relationship.Builder.class)
public class Relationship {
	
	private String relationshipType;
	private String description;
	private DomainObject sourceRef;
	private DomainObject targetRef;
	
	private Relationship(String relationshipType,	String description,	DomainObject sourceRef,	DomainObject targetRef) {
		this.relationshipType=relationshipType;
		this.description=description;
		this.sourceRef=sourceRef;
		this.targetRef=targetRef;
		
	}
	
	@JsonPOJOBuilder
	public static class Builder{
		String relationshipType1;
		String description;
		DomainObject sourceRef;
		DomainObject targetRef;
		
		Builder setRelationshipType (String relationshipType) {
            this.relationshipType1 = relationshipType;
            return this;
        }
		
		Builder setDescription (String description) {
            this.description = description;
            return this;
        }
		
		Builder setSourceRef (DomainObject sourceRef) {
            this.sourceRef = sourceRef;
            return this;
        }
		
		Builder setTargetRef (DomainObject targetRef) {
            this.targetRef = targetRef;
            return this;
        }
		
		public Relationship build() {
            return new Relationship(relationshipType1,description,sourceRef,targetRef);
        }
	}

}

my question is ¿how do you implement the method builder() in the Relationship class?
many thanks in advance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions