From 8e0bb79f6c5993df1e639f1cb12d9c7566fc9219 Mon Sep 17 00:00:00 2001 From: ZhangTerrence Date: Sat, 16 Nov 2024 18:43:50 -0500 Subject: [PATCH 01/28] added complete v3.1 entities --- pom.xml | 5 - .../orservice/OrserviceApplication.java | 3 - .../com/sarapis/orservice/dto/ServiceDTO.java | 23 ++++- .../orservice/entity/Accessibility.java | 24 +++-- .../com/sarapis/orservice/entity/Address.java | 38 ++++++-- .../sarapis/orservice/entity/Attribute.java | 32 ++++++- .../com/sarapis/orservice/entity/Contact.java | 32 +++++-- .../sarapis/orservice/entity/CostOption.java | 28 ++++-- .../sarapis/orservice/entity/ExtentType.java | 8 ++ .../com/sarapis/orservice/entity/Funding.java | 20 ++-- .../sarapis/orservice/entity/Language.java | 25 +++-- .../entity/MetaTableDescription.java | 21 +++-- .../sarapis/orservice/entity/Metadata.java | 19 ++-- .../entity/OrganizationIdentifier.java | 27 ++++-- .../com/sarapis/orservice/entity/Phone.java | 32 +++++-- .../com/sarapis/orservice/entity/Program.java | 20 ++-- .../orservice/entity/RequiredDocument.java | 22 +++-- .../sarapis/orservice/entity/Schedule.java | 55 ++++++++--- .../sarapis/orservice/entity/ServiceArea.java | 35 +++++-- .../orservice/entity/ServiceCapacity.java | 53 +++++++++++ .../sarapis/orservice/entity/Taxonomy.java | 18 ++-- .../orservice/entity/TaxonomyTerm.java | 36 ++++--- .../com/sarapis/orservice/entity/Unit.java | 43 +++++++++ .../com/sarapis/orservice/entity/Url.java | 18 ++-- .../orservice/entity/core/Location.java | 57 +++++++++--- .../orservice/entity/core/Organization.java | 64 +++++++++++-- .../orservice/entity/core/Service.java | 93 +++++++++++++++---- .../entity/core/ServiceAtLocation.java | 43 +++++++-- 28 files changed, 696 insertions(+), 198 deletions(-) create mode 100644 src/main/java/com/sarapis/orservice/entity/ExtentType.java create mode 100644 src/main/java/com/sarapis/orservice/entity/ServiceCapacity.java create mode 100644 src/main/java/com/sarapis/orservice/entity/Unit.java diff --git a/pom.xml b/pom.xml index a3146d1..5a9375d 100644 --- a/pom.xml +++ b/pom.xml @@ -38,7 +38,6 @@ org.springframework.boot spring-boot-starter-web - org.projectlombok lombok @@ -71,10 +70,6 @@ aws-java-sdk-cognitoidp 1.12.130 - - org.springframework.boot - spring-boot-starter-security - org.postgresql postgresql diff --git a/src/main/java/com/sarapis/orservice/OrserviceApplication.java b/src/main/java/com/sarapis/orservice/OrserviceApplication.java index a9d1fbe..018f24b 100644 --- a/src/main/java/com/sarapis/orservice/OrserviceApplication.java +++ b/src/main/java/com/sarapis/orservice/OrserviceApplication.java @@ -3,13 +3,10 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; -import org.springframework.context.annotation.ComponentScan; @SpringBootApplication(exclude = {SecurityAutoConfiguration.class}) public class OrserviceApplication { - public static void main(String[] args) { SpringApplication.run(OrserviceApplication.class, args); } - } diff --git a/src/main/java/com/sarapis/orservice/dto/ServiceDTO.java b/src/main/java/com/sarapis/orservice/dto/ServiceDTO.java index 610bc0a..3d36874 100644 --- a/src/main/java/com/sarapis/orservice/dto/ServiceDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/ServiceDTO.java @@ -1,24 +1,27 @@ package com.sarapis.orservice.dto; -import com.sarapis.orservice.entity.Program; +import com.sarapis.orservice.entity.*; import com.sarapis.orservice.entity.core.Organization; +import com.sarapis.orservice.entity.core.ServiceAtLocation; import com.sarapis.orservice.entity.core.Status; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import java.util.List; + @NoArgsConstructor @AllArgsConstructor @Setter @Getter public class ServiceDTO { private String id; - private OrganizationDTO organization; - private Program program; private String name; private String alternateName; + private String description; private String url; + private List additionalUrls; private String email; private Status status; private String interpretationServices; @@ -35,4 +38,18 @@ public class ServiceDTO { private String licenses; private String alert; private String lastModified; + private List phones; + private List schedules; + private List serviceAreas; + private List serviceAtLocations; + private List languages; + private Organization organization; + private List funding; + private List costOptions; + private Program program; + private List requiredDocuments; + private List contacts; + private List capacities; + private List attributes; + private List metadata; } diff --git a/src/main/java/com/sarapis/orservice/entity/Accessibility.java b/src/main/java/com/sarapis/orservice/entity/Accessibility.java index 822e469..d571310 100644 --- a/src/main/java/com/sarapis/orservice/entity/Accessibility.java +++ b/src/main/java/com/sarapis/orservice/entity/Accessibility.java @@ -1,19 +1,15 @@ package com.sarapis.orservice.entity; import com.sarapis.orservice.entity.core.Location; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.Table; +import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.UuidGenerator; +import java.util.List; + @Entity @Table(name = "accessibility") @Getter @@ -27,9 +23,23 @@ public class Accessibility { private String id; @ManyToOne + @JoinColumn(name = "location_id") private Location location; + @Column(name = "description") private String description; + + @Column(name = "details") private String details; + + @Column(name = "url") private String url; + + @OneToMany + @JoinColumn(name = "link_id") + private List attributes; + + @OneToMany + @JoinColumn(name = "resource_id") + private List metadata; } diff --git a/src/main/java/com/sarapis/orservice/entity/Address.java b/src/main/java/com/sarapis/orservice/entity/Address.java index 8c8b334..3966873 100644 --- a/src/main/java/com/sarapis/orservice/entity/Address.java +++ b/src/main/java/com/sarapis/orservice/entity/Address.java @@ -1,20 +1,15 @@ package com.sarapis.orservice.entity; import com.sarapis.orservice.entity.core.Location; -import jakarta.persistence.Entity; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.OneToOne; -import jakarta.persistence.Table; +import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import org.hibernate.annotations.UuidGenerator; +import java.util.List; + @Entity @Table(name = "address") @Getter @@ -27,18 +22,43 @@ public class Address { @UuidGenerator private String id; - @OneToOne + @ManyToOne + @JoinColumn(name = "location_id") private Location location; + @Column(name = "attention") private String attention; + + @Column(name = "address_1") private String address_1; + + @Column(name = "address_2") private String address_2; + + @Column(name = "city") private String city; + + @Column(name = "region") private String region; + + @Column(name = "state_province") private String stateProvince; + + @Column(name = "postal_code") private String postalCode; + + @Column(name = "country") private String country; @Enumerated(EnumType.STRING) + @Column(name = "address_type") private AddressType addressType; + + @OneToMany + @JoinColumn(name = "link_id") + private List attributes; + + @OneToMany + @JoinColumn(name = "resource_id") + private List metadata; } diff --git a/src/main/java/com/sarapis/orservice/entity/Attribute.java b/src/main/java/com/sarapis/orservice/entity/Attribute.java index 36da1b7..9503c3f 100644 --- a/src/main/java/com/sarapis/orservice/entity/Attribute.java +++ b/src/main/java/com/sarapis/orservice/entity/Attribute.java @@ -1,16 +1,14 @@ package com.sarapis.orservice.entity; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.Table; +import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import org.hibernate.annotations.UuidGenerator; +import java.util.List; + @Entity @Table(name = "attribute") @Getter @@ -22,4 +20,28 @@ public class Attribute { @GeneratedValue @UuidGenerator private String id; + + // FK Property + @Column(name = "link_id", nullable = false, unique = true) + private String linkId; + + @Column(name = "link_type") + private String linkType; + + @Column(name = "link_entity") + private String linkEntity; + + @Column(name = "value") + private String value; + + @OneToOne + @JoinColumn(name = "taxonomy_term_id") + private TaxonomyTerm taxonomyTerm; + + @OneToMany + @JoinColumn(name = "resource_id") + private List metadata; + + @Column(name = "label") + private String label; } diff --git a/src/main/java/com/sarapis/orservice/entity/Contact.java b/src/main/java/com/sarapis/orservice/entity/Contact.java index 8052bf7..77e2fb5 100644 --- a/src/main/java/com/sarapis/orservice/entity/Contact.java +++ b/src/main/java/com/sarapis/orservice/entity/Contact.java @@ -4,18 +4,15 @@ import com.sarapis.orservice.entity.core.Organization; import com.sarapis.orservice.entity.core.Service; import com.sarapis.orservice.entity.core.ServiceAtLocation; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.Table; +import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import org.hibernate.annotations.UuidGenerator; +import java.util.List; + @Entity @Table(name = "contact") @Setter @@ -29,19 +26,42 @@ public class Contact { private String id; @ManyToOne + @JoinColumn(name = "organization_id") private Organization organization; @ManyToOne + @JoinColumn(name = "service_id") private Service service; @ManyToOne + @JoinColumn(name = "service_at_location_id") private ServiceAtLocation serviceAtLocation; @ManyToOne + @JoinColumn(name = "location_id") private Location location; + @Column(name = "name") private String name; + + @Column(name = "title") private String title; + + @Column(name = "department") private String department; + + @Column(name = "email") private String email; + + @OneToMany + @JoinColumn(name = "contact_id") + private List phones; + + @OneToMany + @JoinColumn(name = "link_id") + private List attributes; + + @OneToMany + @JoinColumn(name = "resource_id") + private List metadata; } diff --git a/src/main/java/com/sarapis/orservice/entity/CostOption.java b/src/main/java/com/sarapis/orservice/entity/CostOption.java index 1224ecf..21c0513 100644 --- a/src/main/java/com/sarapis/orservice/entity/CostOption.java +++ b/src/main/java/com/sarapis/orservice/entity/CostOption.java @@ -1,24 +1,20 @@ package com.sarapis.orservice.entity; import com.sarapis.orservice.entity.core.Service; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.OneToOne; -import jakarta.persistence.Table; -import java.time.LocalDate; +import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import org.hibernate.annotations.UuidGenerator; +import java.time.LocalDate; +import java.util.List; + @Entity @Table(name = "cost_option") -@Setter @Getter +@Setter @NoArgsConstructor @AllArgsConstructor public class CostOption { @@ -28,6 +24,7 @@ public class CostOption { private String id; @OneToOne + @JoinColumn(name = "service_id") private Service service; @Column(name = "valid_from") @@ -36,10 +33,23 @@ public class CostOption { @Column(name = "valid_to") private LocalDate validTo; + @Column(name = "option") private String option; + + @Column(name = "currency") private String currency; + + @Column(name = "amount") private int amount; @Column(name = "amount_description") private String amountDescription; + + @OneToMany + @JoinColumn(name = "link_id") + private List attributes; + + @OneToMany + @JoinColumn(name = "resource_id") + private List metadata; } diff --git a/src/main/java/com/sarapis/orservice/entity/ExtentType.java b/src/main/java/com/sarapis/orservice/entity/ExtentType.java new file mode 100644 index 0000000..2dbe9fd --- /dev/null +++ b/src/main/java/com/sarapis/orservice/entity/ExtentType.java @@ -0,0 +1,8 @@ +package com.sarapis.orservice.entity; + +public enum ExtentType { + geojson, + topojson, + kml, + text +} diff --git a/src/main/java/com/sarapis/orservice/entity/Funding.java b/src/main/java/com/sarapis/orservice/entity/Funding.java index 1c2fb8f..3ebe7e2 100644 --- a/src/main/java/com/sarapis/orservice/entity/Funding.java +++ b/src/main/java/com/sarapis/orservice/entity/Funding.java @@ -2,22 +2,19 @@ import com.sarapis.orservice.entity.core.Organization; import com.sarapis.orservice.entity.core.Service; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.Table; +import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import org.hibernate.annotations.UuidGenerator; +import java.util.List; + @Entity @Table(name = "funding") -@Setter @Getter +@Setter @NoArgsConstructor @AllArgsConstructor public class Funding { @@ -27,12 +24,21 @@ public class Funding { private String id; @ManyToOne + @JoinColumn(name = "organization_id") private Organization organization; @ManyToOne + @JoinColumn(name = "service_id") private Service service; + @Column(name = "source") private String source; + @OneToMany + @JoinColumn(name = "link_id") + private List attributes; + @OneToMany + @JoinColumn(name = "resource_id") + private List metadata; } diff --git a/src/main/java/com/sarapis/orservice/entity/Language.java b/src/main/java/com/sarapis/orservice/entity/Language.java index 72d1032..ccae04f 100644 --- a/src/main/java/com/sarapis/orservice/entity/Language.java +++ b/src/main/java/com/sarapis/orservice/entity/Language.java @@ -2,18 +2,15 @@ import com.sarapis.orservice.entity.core.Location; import com.sarapis.orservice.entity.core.Service; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.Table; +import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import org.hibernate.annotations.UuidGenerator; +import java.util.List; + @Entity @Table(name = "language") @Getter @@ -27,15 +24,31 @@ public class Language { private String id; @ManyToOne + @JoinColumn(name = "service_id") private Service service; @ManyToOne + @JoinColumn(name = "location_id") private Location location; @ManyToOne + @JoinColumn(name = "phone_id") private Phone phone; + @Column(name = "name") private String name; + + @Column(name = "code") private String code; + + @Column(name = "note") private String note; + + @OneToMany + @JoinColumn(name = "link_id") + private List attributes; + + @OneToMany + @JoinColumn(name = "resource_id") + private List metadata; } diff --git a/src/main/java/com/sarapis/orservice/entity/MetaTableDescription.java b/src/main/java/com/sarapis/orservice/entity/MetaTableDescription.java index ae7a1e5..d9cf328 100644 --- a/src/main/java/com/sarapis/orservice/entity/MetaTableDescription.java +++ b/src/main/java/com/sarapis/orservice/entity/MetaTableDescription.java @@ -1,17 +1,14 @@ package com.sarapis.orservice.entity; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.Table; +import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import org.hibernate.annotations.UuidGenerator; +import java.util.List; + @Entity @Table(name = "meta_table_description") @Setter @@ -24,8 +21,20 @@ public class MetaTableDescription { @UuidGenerator private String id; + @Column(name = "name") private String name; + + @Column(name = "language") private String language; + @Column(name = "character_set") private String characterSet; + + @OneToMany + @JoinColumn(name = "link_id") + private List attributes; + + @OneToMany + @JoinColumn(name = "resource_id") + private List metadata; } diff --git a/src/main/java/com/sarapis/orservice/entity/Metadata.java b/src/main/java/com/sarapis/orservice/entity/Metadata.java index 47b7b92..6b5593e 100644 --- a/src/main/java/com/sarapis/orservice/entity/Metadata.java +++ b/src/main/java/com/sarapis/orservice/entity/Metadata.java @@ -1,21 +1,14 @@ package com.sarapis.orservice.entity; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.Table; -import java.time.LocalDate; -import java.util.UUID; +import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import org.hibernate.annotations.UuidGenerator; +import java.time.LocalDate; + @Entity @Table(name = "metadata") @Getter @@ -28,10 +21,12 @@ public class Metadata { @UuidGenerator private String id; + // FK Property @Column(name = "resource_id", nullable = false, unique = true) private String resourceId; @Enumerated(EnumType.STRING) + @Column(name = "resource_type") private ResourceType resourceType; @Column(name = "last_action_date") @@ -40,11 +35,15 @@ public class Metadata { @Column(name = "last_action_type") private String lastActionType; + @Column(name = "field_name") private String fieldName; + @Column(name = "previous_value") private String previousValue; + @Column(name = "replacement_value") private String replacementValue; + @Column(name = "updated_by") private String updatedBy; } diff --git a/src/main/java/com/sarapis/orservice/entity/OrganizationIdentifier.java b/src/main/java/com/sarapis/orservice/entity/OrganizationIdentifier.java index 0835995..0ded841 100644 --- a/src/main/java/com/sarapis/orservice/entity/OrganizationIdentifier.java +++ b/src/main/java/com/sarapis/orservice/entity/OrganizationIdentifier.java @@ -1,24 +1,19 @@ package com.sarapis.orservice.entity; import com.sarapis.orservice.entity.core.Organization; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.NamedAttributeNode; -import jakarta.persistence.OneToOne; -import jakarta.persistence.Table; +import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import org.hibernate.annotations.UuidGenerator; +import java.util.List; + @Entity @Table(name = "organization_identifier") -@Setter @Getter +@Setter @NoArgsConstructor @AllArgsConstructor public class OrganizationIdentifier { @@ -27,7 +22,8 @@ public class OrganizationIdentifier { @UuidGenerator private String id; - @OneToOne + @ManyToOne + @JoinColumn(name = "organization_id") private Organization organization; @Column(name = "identifier_scheme") @@ -35,4 +31,15 @@ public class OrganizationIdentifier { @Column(name = "identifier_type") private String identifierType; + + @Column(name = "identifier") + private String identifier; + + @OneToMany + @JoinColumn(name = "link_id") + private List attributes; + + @OneToMany + @JoinColumn(name = "resource_id") + private List metadata; } diff --git a/src/main/java/com/sarapis/orservice/entity/Phone.java b/src/main/java/com/sarapis/orservice/entity/Phone.java index 1410eae..a8dd020 100644 --- a/src/main/java/com/sarapis/orservice/entity/Phone.java +++ b/src/main/java/com/sarapis/orservice/entity/Phone.java @@ -3,18 +3,15 @@ import com.sarapis.orservice.entity.core.Location; import com.sarapis.orservice.entity.core.Service; import com.sarapis.orservice.entity.core.ServiceAtLocation; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.Table; +import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import org.hibernate.annotations.UuidGenerator; +import java.util.List; + @Entity @Table(name = "phone") @Getter @@ -28,19 +25,42 @@ public class Phone { private String id; @ManyToOne + @JoinColumn(name = "location_id") private Location location; @ManyToOne + @JoinColumn(name = "service_id") private Service service; @ManyToOne + @JoinColumn(name = "contact_id") private Contact contact; @ManyToOne + @JoinColumn(name = "service_at_location_id") private ServiceAtLocation serviceAtLocation; + @Column(name = "number") private String number; + + @Column(name = "extension") private String extension; + + @Column(name = "type") private String type; + + @Column(name = "description") private String description; + + @OneToMany + @JoinColumn(name = "phone_id") + private List languages; + + @OneToMany + @JoinColumn(name = "link_id") + private List attributes; + + @OneToMany + @JoinColumn(name = "resource_id") + private List metadata; } diff --git a/src/main/java/com/sarapis/orservice/entity/Program.java b/src/main/java/com/sarapis/orservice/entity/Program.java index 131e631..487ad07 100644 --- a/src/main/java/com/sarapis/orservice/entity/Program.java +++ b/src/main/java/com/sarapis/orservice/entity/Program.java @@ -1,18 +1,15 @@ package com.sarapis.orservice.entity; import com.sarapis.orservice.entity.core.Organization; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.Table; +import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import org.hibernate.annotations.UuidGenerator; +import java.util.List; + @Entity @Table @Getter @@ -26,12 +23,23 @@ public class Program { private String id; @ManyToOne + @JoinColumn(name = "organization_id") private Organization organization; + @Column(name = "name") private String name; @Column(name = "alternate_name") private String alternateName; + @Column(name = "description") private String description; + + @OneToMany + @JoinColumn(name = "link_id") + private List attributes; + + @OneToMany + @JoinColumn(name = "resource_id") + private List metadata; } diff --git a/src/main/java/com/sarapis/orservice/entity/RequiredDocument.java b/src/main/java/com/sarapis/orservice/entity/RequiredDocument.java index 2f23de7..6aa621c 100644 --- a/src/main/java/com/sarapis/orservice/entity/RequiredDocument.java +++ b/src/main/java/com/sarapis/orservice/entity/RequiredDocument.java @@ -1,18 +1,15 @@ package com.sarapis.orservice.entity; import com.sarapis.orservice.entity.core.Service; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.Table; +import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import org.hibernate.annotations.UuidGenerator; +import java.util.List; + @Entity @Table(name = "required_document") @Getter @@ -26,7 +23,20 @@ public class RequiredDocument { private String id; @ManyToOne + @JoinColumn(name = "service_id") private Service service; + + @Column(name = "document") private String document; + + @Column(name = "uri") private String uri; + + @OneToMany + @JoinColumn(name = "link_id") + private List attributes; + + @OneToMany + @JoinColumn(name = "resource_id") + private List metadata; } diff --git a/src/main/java/com/sarapis/orservice/entity/Schedule.java b/src/main/java/com/sarapis/orservice/entity/Schedule.java index 598b32d..8df64f3 100644 --- a/src/main/java/com/sarapis/orservice/entity/Schedule.java +++ b/src/main/java/com/sarapis/orservice/entity/Schedule.java @@ -1,23 +1,19 @@ package com.sarapis.orservice.entity; +import com.sarapis.orservice.entity.core.Location; import com.sarapis.orservice.entity.core.Service; import com.sarapis.orservice.entity.core.ServiceAtLocation; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.Table; -import java.sql.Date; -import java.sql.Time; +import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import org.hibernate.annotations.UuidGenerator; +import java.sql.Date; +import java.sql.Time; +import java.util.List; + @Entity @Table(name = "schedule") @Getter @@ -31,9 +27,15 @@ public class Schedule { private String id; @ManyToOne + @JoinColumn(name = "service_id") private Service service; @ManyToOne + @JoinColumn(name = "location_id") + private Location location; + + @ManyToOne + @JoinColumn(name = "service_at_location_id") private ServiceAtLocation serviceAtLocation; @Column(name = "valid_from") @@ -45,21 +47,39 @@ public class Schedule { @Column(name = "dtstart") private Date dtStart; - private int TimeZone; + @Column(name = "timezone") + private int timezone; + + @Column(name = "until") private Date until; + + @Column(name = "count") private int count; @Enumerated(EnumType.STRING) + @Column(name = "wkst") private WkSt wkst; @Enumerated(EnumType.STRING) + @Column(name = "freq") private Freq freq; + @Column(name = "interval") private int interval; + + @Column(name = "byday") private String byday; + + @Column(name = "byweekno") private String byweekno; + + @Column(name = "bymonthday") private String bymonthday; + + @Column(name = "byyearday") private String byyearday; + + @Column(name = "description") private String description; @Column(name = "opens_at") @@ -68,7 +88,20 @@ public class Schedule { @Column(name = "closes_at") private Time closesAt; + @Column(name = "schedule_link") private String scheduleLink; + + @Column(name = "attending_type") private String attendingType; + + @Column(name = "notes") private String notes; + + @OneToMany + @JoinColumn(name = "link_id") + private List attributes; + + @OneToMany + @JoinColumn(name = "resource_id") + private List metadata; } diff --git a/src/main/java/com/sarapis/orservice/entity/ServiceArea.java b/src/main/java/com/sarapis/orservice/entity/ServiceArea.java index 2f8afbe..808e9cb 100644 --- a/src/main/java/com/sarapis/orservice/entity/ServiceArea.java +++ b/src/main/java/com/sarapis/orservice/entity/ServiceArea.java @@ -1,18 +1,16 @@ package com.sarapis.orservice.entity; import com.sarapis.orservice.entity.core.Service; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.Table; +import com.sarapis.orservice.entity.core.ServiceAtLocation; +import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import org.hibernate.annotations.UuidGenerator; +import java.util.List; + @Entity @Table(name = "service_area") @Getter @@ -26,11 +24,34 @@ public class ServiceArea { private String id; @ManyToOne + @JoinColumn(name = "service_id") private Service service; + @ManyToOne + @JoinColumn(name = "service_at_location_id") + private ServiceAtLocation serviceAtLocation; + + @Column(name = "name") private String name; + + @Column(name = "description") private String description; + + @Column(name = "extent") private String extent; - private String extentType; + + @Enumerated(EnumType.STRING) + @Column(name = "extent_type") + private ExtentType extentType; + + @Column(name = "uri") private String uri; + + @OneToMany + @JoinColumn(name = "link_id") + private List attributes; + + @OneToMany + @JoinColumn(name = "resource_id") + private List metadata; } diff --git a/src/main/java/com/sarapis/orservice/entity/ServiceCapacity.java b/src/main/java/com/sarapis/orservice/entity/ServiceCapacity.java new file mode 100644 index 0000000..bf68a74 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/entity/ServiceCapacity.java @@ -0,0 +1,53 @@ +package com.sarapis.orservice.entity; + +import com.sarapis.orservice.entity.core.Service; +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import org.hibernate.annotations.UuidGenerator; + +import java.time.LocalDate; +import java.util.List; + +@Entity +@Table(name = "service_capacity") +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +public class ServiceCapacity { + @Id + @GeneratedValue + @UuidGenerator + private String id; + + @ManyToOne + @JoinColumn(name = "service_id") + private Service service; + + @OneToOne + @JoinColumn(name = "unit_id") + private Unit unit; + + @Column(name = "available") + private int available; + + @Column(name = "maximum") + private int maximum; + + @Column(name = "description") + private String description; + + @Column(name = "updated") + private LocalDate updated; + + @OneToMany + @JoinColumn(name = "link_id") + private List attributes; + + @OneToMany + @JoinColumn(name = "resource_id") + private List metadata; +} diff --git a/src/main/java/com/sarapis/orservice/entity/Taxonomy.java b/src/main/java/com/sarapis/orservice/entity/Taxonomy.java index 6827cbd..6129802 100644 --- a/src/main/java/com/sarapis/orservice/entity/Taxonomy.java +++ b/src/main/java/com/sarapis/orservice/entity/Taxonomy.java @@ -1,20 +1,18 @@ package com.sarapis.orservice.entity; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.Table; +import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import org.hibernate.annotations.UuidGenerator; +import java.util.List; + @Entity @Table(name = "taxonomy") -@Setter @Getter +@Setter @NoArgsConstructor @AllArgsConstructor public class Taxonomy { @@ -23,11 +21,19 @@ public class Taxonomy { @UuidGenerator private String id; + @Column(name = "name") private String name; + @Column(name = "description") private String description; + @Column(name = "uri") private String uri; + @Column(name = "version") private String version; + + @OneToMany + @JoinColumn(name = "resource_id") + private List metadata; } diff --git a/src/main/java/com/sarapis/orservice/entity/TaxonomyTerm.java b/src/main/java/com/sarapis/orservice/entity/TaxonomyTerm.java index d9bca73..44726b1 100644 --- a/src/main/java/com/sarapis/orservice/entity/TaxonomyTerm.java +++ b/src/main/java/com/sarapis/orservice/entity/TaxonomyTerm.java @@ -1,19 +1,14 @@ package com.sarapis.orservice.entity; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.OneToOne; -import jakarta.persistence.Table; -import lombok.AllArgsConstructor; +import jakarta.persistence.*; import lombok.Getter; -import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.NoArgsConstructor; +import lombok.AllArgsConstructor; import org.hibernate.annotations.UuidGenerator; +import java.util.List; + @Entity @Table(name = "taxonomy_term") @Setter @@ -26,21 +21,36 @@ public class TaxonomyTerm { @UuidGenerator private String id; + @Column(name = "code") private String code; + + @Column(name = "name") private String name; + + @Column(name = "description") private String description; @OneToOne + @JoinColumn(name = "parent_id") private TaxonomyTerm parent; @Column(name = "taxonomy") - private String taxonomyName; + private String taxonomy; - @ManyToOne - private Taxonomy taxonomy; + @OneToOne + @JoinColumn(name = "taxonomy_detail") + private Taxonomy taxonomyDetail; + + @Column(name = "language") private String language; + @Column(name = "taxonomy_id", nullable = false, unique = true) + private String taxonomyId; + @Column(name = "term_uri") private String termUri; + @OneToMany + @JoinColumn(name = "resource_id") + private List metadata; } diff --git a/src/main/java/com/sarapis/orservice/entity/Unit.java b/src/main/java/com/sarapis/orservice/entity/Unit.java new file mode 100644 index 0000000..a491a7b --- /dev/null +++ b/src/main/java/com/sarapis/orservice/entity/Unit.java @@ -0,0 +1,43 @@ +package com.sarapis.orservice.entity; + +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import org.hibernate.annotations.UuidGenerator; + +import java.util.List; + +@Entity +@Table(name = "unit") +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +public class Unit { + @Id + @GeneratedValue + @UuidGenerator + private String id; + + @Column(name = "name") + private String name; + + @Column(name = "scheme") + private String scheme; + + @Column(name = "identifier") + private String identifier; + + @Column(name = "uri") + private String uri; + + @OneToMany + @JoinColumn(name = "link_id") + private List attributes; + + @OneToMany + @JoinColumn(name = "resource_id") + private List metadata; +} diff --git a/src/main/java/com/sarapis/orservice/entity/Url.java b/src/main/java/com/sarapis/orservice/entity/Url.java index 0f2f95a..7ff5aac 100644 --- a/src/main/java/com/sarapis/orservice/entity/Url.java +++ b/src/main/java/com/sarapis/orservice/entity/Url.java @@ -2,18 +2,15 @@ import com.sarapis.orservice.entity.core.Organization; import com.sarapis.orservice.entity.core.Service; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.Table; +import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import org.hibernate.annotations.UuidGenerator; +import java.util.List; + @Entity @Table(name = "url") @Getter @@ -25,13 +22,22 @@ public class Url { @GeneratedValue @UuidGenerator private String id; + + @Column(name = "label") private String label; + + @Column(name = "url") private String url; @ManyToOne + @JoinColumn(name = "organization_id") private Organization organization; @ManyToOne + @JoinColumn(name = "service_id") private Service service; + @OneToMany + @JoinColumn(name = "resource_id") + private List metadata; } diff --git a/src/main/java/com/sarapis/orservice/entity/core/Location.java b/src/main/java/com/sarapis/orservice/entity/core/Location.java index ad2db94..d6e6856 100644 --- a/src/main/java/com/sarapis/orservice/entity/core/Location.java +++ b/src/main/java/com/sarapis/orservice/entity/core/Location.java @@ -1,54 +1,54 @@ package com.sarapis.orservice.entity.core; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.Lob; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.Table; +import com.sarapis.orservice.entity.*; +import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import org.hibernate.annotations.UuidGenerator; +import java.util.List; + @Entity @Table(name = "location") @Getter @Setter -@AllArgsConstructor @NoArgsConstructor +@AllArgsConstructor public class Location { @Id @GeneratedValue @UuidGenerator private String id; - @Column(name = "location_type") @Enumerated(EnumType.STRING) + @Column(name = "location_type") private LocationType locationType; @Column(name = "url") - private String Url; + private String url; @ManyToOne + @JoinColumn(name = "organization_id") private Organization organization; + @Column(name = "name") private String name; @Column(name = "alternate_name") private String alternateName; + @Column(name = "description") private String description; + @Column(name = "transportation") private String transportation; + @Column(name = "latitude") private int latitude; + @Column(name = "longitude") private int longitude; @Column(name = "external_identifier") @@ -57,4 +57,35 @@ public class Location { @Column(name = "external_identifier_type") private String externalIdentifierType; + @OneToMany + @JoinColumn(name = "location_id") + private List languages; + + @OneToMany + @JoinColumn(name = "location_id") + private List
addresses; + + @OneToMany + @JoinColumn(name = "location_id") + private List contacts; + + @OneToMany + @JoinColumn(name = "location_id") + private List accessibility; + + @OneToMany + @JoinColumn(name = "location_id") + private List phones; + + @OneToMany + @JoinColumn(name = "location_id") + private List schedules; + + @OneToMany + @JoinColumn(name = "link_id") + private List attributes; + + @OneToMany + @JoinColumn(name = "resource_id") + private List metadata; } diff --git a/src/main/java/com/sarapis/orservice/entity/core/Organization.java b/src/main/java/com/sarapis/orservice/entity/core/Organization.java index cb23587..f194760 100644 --- a/src/main/java/com/sarapis/orservice/entity/core/Organization.java +++ b/src/main/java/com/sarapis/orservice/entity/core/Organization.java @@ -1,55 +1,99 @@ package com.sarapis.orservice.entity.core; -import com.sarapis.orservice.entity.Url; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.OneToMany; -import jakarta.persistence.OneToOne; -import jakarta.persistence.Table; -import java.util.List; +import com.sarapis.orservice.entity.*; +import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import org.hibernate.annotations.UuidGenerator; +import java.util.List; + @Entity @Table(name = "organization") @Getter @Setter -@AllArgsConstructor @NoArgsConstructor +@AllArgsConstructor public class Organization { @Id @GeneratedValue @UuidGenerator private String id; + @Column(name = "name") private String name; @Column(name = "alternate_name") private String alternateName; + @Column(name = "description") private String description; + @Column(name = "email") private String email; + @Column(name = "website") private String website; @OneToMany + @JoinColumn(name = "organization_id") private List additionalWebsites; + // Deprecated + @Column(name = "tax_status") + private String taxStatus; + + // Deprecated + @Column(name = "tax_id") + private String taxId; + @Column(name = "year_incorporated") private int yearIncorporated; + @Column(name = "legal_status") private String legalStatus; + @Column(name = "logo") private String logo; + @Column(name = "uri") private String uri; @OneToOne + @JoinColumn(name = "parent_organization_id") private Organization parentOrganization; + + @OneToMany + @JoinColumn(name = "organization_id") + private List funding; + + @OneToMany + @JoinColumn(name = "organization_id") + private List contacts; + + @OneToMany + @JoinColumn(name = "organization_id") + private List phones; + + @OneToMany + @JoinColumn(name = "organization_id") + private List locations; + + @OneToMany + @JoinColumn(name = "organization_id") + private List programs; + + @OneToMany + @JoinColumn(name = "organization_id") + private List organizationIdentifiers; + + @OneToMany + @JoinColumn(name = "link_id") + private List attributes; + + @OneToMany + @JoinColumn(name = "resource_id") + private List metadata; } diff --git a/src/main/java/com/sarapis/orservice/entity/core/Service.java b/src/main/java/com/sarapis/orservice/entity/core/Service.java index 75a3153..5c0be89 100644 --- a/src/main/java/com/sarapis/orservice/entity/core/Service.java +++ b/src/main/java/com/sarapis/orservice/entity/core/Service.java @@ -1,23 +1,16 @@ package com.sarapis.orservice.entity.core; -import com.sarapis.orservice.entity.Program; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.Lob; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.Table; -import java.time.LocalDate; +import com.sarapis.orservice.entity.*; +import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import org.hibernate.annotations.UuidGenerator; +import java.time.LocalDate; +import java.util.List; + @Entity @Table(name = "service") @Getter @@ -30,24 +23,27 @@ public class Service { @UuidGenerator private String id; - @ManyToOne - private Organization organization; - - @ManyToOne - private Program program; - + @Column(name = "name") private String name; @Column(name = "alternate_name") private String alternateName; + @Column(name = "description") private String description; - private String Url; + @Column(name = "url") + private String url; + + @OneToMany + @JoinColumn(name = "service_id") + private List additionUrls; + @Column(name = "email") private String email; @Enumerated(EnumType.STRING) + @Column(name = "status") private Status status; @Column(name = "interpretation_services") @@ -62,8 +58,10 @@ public class Service { @Column(name = "wait_time") private String waitTime; + @Column(name = "fees") private String fees; + @Column(name = "accreditations") private String accreditations; @Column(name = "eligibility_description") @@ -81,11 +79,68 @@ public class Service { @Column(name = "assurer_email") private String assurerEmail; + @Column(name = "licenses") private String licenses; + @Column(name = "alert") private String alert; @Column(name = "last_modified") private LocalDate lastModified; + @OneToMany + @JoinColumn(name = "service_id") + private List phones; + + @OneToMany + @JoinColumn(name = "service_id") + private List schedules; + + @OneToMany + @JoinColumn(name = "service_id") + private List serviceAreas; + + @OneToMany + @JoinColumn(name = "service_id") + private List serviceAtLocations; + + @OneToMany + @JoinColumn(name = "service_id") + private List languages; + + @OneToOne + @JoinColumn(name = "organization_id") + private Organization organization; + + @OneToMany + @JoinColumn(name = "service_id") + private List funding; + + @OneToMany + @JoinColumn(name = "service_id") + private List costOptions; + + @OneToOne + @JoinColumn(name = "program_id") + private Program program; + + @OneToMany + @JoinColumn(name = "service_id") + private List requiredDocuments; + + @OneToMany + @JoinColumn(name = "service_id") + private List contacts; + + @OneToMany + @JoinColumn(name = "service_id") + private List capacities; + + @OneToMany + @JoinColumn(name = "link_id") + private List attributes; + + @OneToMany + @JoinColumn(name = "resource_id") + private List metadata; } diff --git a/src/main/java/com/sarapis/orservice/entity/core/ServiceAtLocation.java b/src/main/java/com/sarapis/orservice/entity/core/ServiceAtLocation.java index a3c91d3..fe73309 100644 --- a/src/main/java/com/sarapis/orservice/entity/core/ServiceAtLocation.java +++ b/src/main/java/com/sarapis/orservice/entity/core/ServiceAtLocation.java @@ -1,21 +1,19 @@ package com.sarapis.orservice.entity.core; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.Table; +import com.sarapis.orservice.entity.*; +import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import org.hibernate.annotations.UuidGenerator; +import java.util.List; + @Entity @Table(name = "service_at_location") -@Setter @Getter +@Setter @NoArgsConstructor @AllArgsConstructor public class ServiceAtLocation { @@ -25,10 +23,37 @@ public class ServiceAtLocation { private String id; @ManyToOne + @JoinColumn(name = "service_id") private Service service; - @ManyToOne + @Column(name = "description") + private String description; + + @OneToMany + @JoinColumn(name = "service_at_location_id") + private List serviceAreas; + + @OneToMany + @JoinColumn(name = "service_at_location_id") + private List contacts; + + @OneToMany + @JoinColumn(name = "service_at_location_id") + private List phones; + + @OneToMany + @JoinColumn(name = "service_at_location_id") + private List schedules; + + @OneToOne + @JoinColumn(name = "location_id") private Location location; - private String description; + @OneToMany + @JoinColumn(name = "link_id") + private List attributes; + + @OneToMany + @JoinColumn(name = "resource_id") + private List metadata; } From dee01cb8bda4f5f62bc18caee6881ce2fd86db87 Mon Sep 17 00:00:00 2001 From: ZhangTerrence Date: Sat, 16 Nov 2024 19:16:39 -0500 Subject: [PATCH 02/28] added missing table name --- src/main/java/com/sarapis/orservice/entity/Program.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/sarapis/orservice/entity/Program.java b/src/main/java/com/sarapis/orservice/entity/Program.java index 487ad07..a3c6733 100644 --- a/src/main/java/com/sarapis/orservice/entity/Program.java +++ b/src/main/java/com/sarapis/orservice/entity/Program.java @@ -11,7 +11,7 @@ import java.util.List; @Entity -@Table +@Table(name = "program") @Getter @Setter @AllArgsConstructor From 9178b8fc22eaf0643f05bc5237cb764614d94734 Mon Sep 17 00:00:00 2001 From: ZhangTerrence Date: Mon, 18 Nov 2024 12:48:55 -0500 Subject: [PATCH 03/28] changed relationship --- .../com/sarapis/orservice/entity/TaxonomyTerm.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/sarapis/orservice/entity/TaxonomyTerm.java b/src/main/java/com/sarapis/orservice/entity/TaxonomyTerm.java index 44726b1..c6453f5 100644 --- a/src/main/java/com/sarapis/orservice/entity/TaxonomyTerm.java +++ b/src/main/java/com/sarapis/orservice/entity/TaxonomyTerm.java @@ -35,18 +35,15 @@ public class TaxonomyTerm { private TaxonomyTerm parent; @Column(name = "taxonomy") - private String taxonomy; + private String taxonomyName; - @OneToOne - @JoinColumn(name = "taxonomy_detail") - private Taxonomy taxonomyDetail; + @ManyToOne + @JoinColumn(name = "taxonomy_id") + private Taxonomy taxonomy; @Column(name = "language") private String language; - @Column(name = "taxonomy_id", nullable = false, unique = true) - private String taxonomyId; - @Column(name = "term_uri") private String termUri; From 558c60eaeeed3fdd8bb71c71d4a180a24094fa57 Mon Sep 17 00:00:00 2001 From: Butter - ThinkWin Date: Wed, 20 Nov 2024 16:01:05 -0500 Subject: [PATCH 04/28] Attribute Entity Model --- .../com/sarapis/orservice/entity/Attribute.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/com/sarapis/orservice/entity/Attribute.java b/src/main/java/com/sarapis/orservice/entity/Attribute.java index 36da1b7..194d44c 100644 --- a/src/main/java/com/sarapis/orservice/entity/Attribute.java +++ b/src/main/java/com/sarapis/orservice/entity/Attribute.java @@ -4,6 +4,8 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.OneToOne; import jakarta.persistence.Table; import lombok.AllArgsConstructor; import lombok.Getter; @@ -22,4 +24,18 @@ public class Attribute { @GeneratedValue @UuidGenerator private String id; + + private String linkId; + private String linkType; + private String linkEntity; + private String value; + + @OneToOne + @JoinColumn(name="taxonomy_term_id") + private TaxonomyTerm taxonomyTerm; + + @OneToOne + private Metadata metadata; + + private String label; } From 78af3b1d15a32cc19e6007cf197bfe0f91b4a356 Mon Sep 17 00:00:00 2001 From: Butter - ThinkWin Date: Wed, 20 Nov 2024 17:07:05 -0500 Subject: [PATCH 05/28] Attribute Service and DTO --- .../java/com/sarapis/orservice/dto/AttributeDTO.java | 4 ++++ .../orservice/repository/AttributeRepository.java | 9 +++++++++ .../com/sarapis/orservice/service/AttributeService.java | 4 ++++ .../sarapis/orservice/service/AttributeServiceImpl.java | 4 ++++ 4 files changed, 21 insertions(+) create mode 100644 src/main/java/com/sarapis/orservice/dto/AttributeDTO.java create mode 100644 src/main/java/com/sarapis/orservice/repository/AttributeRepository.java create mode 100644 src/main/java/com/sarapis/orservice/service/AttributeService.java create mode 100644 src/main/java/com/sarapis/orservice/service/AttributeServiceImpl.java diff --git a/src/main/java/com/sarapis/orservice/dto/AttributeDTO.java b/src/main/java/com/sarapis/orservice/dto/AttributeDTO.java new file mode 100644 index 0000000..3e59052 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/AttributeDTO.java @@ -0,0 +1,4 @@ +package com.sarapis.orservice.dto; + +public class AttributeDTO { +} diff --git a/src/main/java/com/sarapis/orservice/repository/AttributeRepository.java b/src/main/java/com/sarapis/orservice/repository/AttributeRepository.java new file mode 100644 index 0000000..88b026d --- /dev/null +++ b/src/main/java/com/sarapis/orservice/repository/AttributeRepository.java @@ -0,0 +1,9 @@ +package com.sarapis.orservice.repository; + +import com.sarapis.orservice.entity.Attribute; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface AttributeRepository extends JpaRepository { +} diff --git a/src/main/java/com/sarapis/orservice/service/AttributeService.java b/src/main/java/com/sarapis/orservice/service/AttributeService.java new file mode 100644 index 0000000..bfc6d13 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/service/AttributeService.java @@ -0,0 +1,4 @@ +package com.sarapis.orservice.service; + +public interface AttributeService { +} diff --git a/src/main/java/com/sarapis/orservice/service/AttributeServiceImpl.java b/src/main/java/com/sarapis/orservice/service/AttributeServiceImpl.java new file mode 100644 index 0000000..b6d6a01 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/service/AttributeServiceImpl.java @@ -0,0 +1,4 @@ +package com.sarapis.orservice.service; + +public class AttributeServiceImpl { +} From 69a32b33041416d4ed6d32328fc0af3681aa04e4 Mon Sep 17 00:00:00 2001 From: Butter - ThinkWin Date: Wed, 20 Nov 2024 17:08:01 -0500 Subject: [PATCH 06/28] Implemented Attribute DTO and Service --- .../sarapis/orservice/dto/AttributeDTO.java | 19 ++++ .../orservice/service/AttributeService.java | 13 +++ .../service/AttributeServiceImpl.java | 91 ++++++++++++++++++- 3 files changed, 122 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/sarapis/orservice/dto/AttributeDTO.java b/src/main/java/com/sarapis/orservice/dto/AttributeDTO.java index 3e59052..b732fb6 100644 --- a/src/main/java/com/sarapis/orservice/dto/AttributeDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/AttributeDTO.java @@ -1,4 +1,23 @@ package com.sarapis.orservice.dto; +import com.sarapis.orservice.entity.Metadata; +import com.sarapis.orservice.entity.TaxonomyTerm; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor public class AttributeDTO { + private String id; + private String linkId; + private String linkType; + private String linkEntity; + private String value; + private TaxonomyTerm taxonomyTerm; + private Metadata metadata; + private String label; } diff --git a/src/main/java/com/sarapis/orservice/service/AttributeService.java b/src/main/java/com/sarapis/orservice/service/AttributeService.java index bfc6d13..56cfedb 100644 --- a/src/main/java/com/sarapis/orservice/service/AttributeService.java +++ b/src/main/java/com/sarapis/orservice/service/AttributeService.java @@ -1,4 +1,17 @@ package com.sarapis.orservice.service; +import com.sarapis.orservice.dto.AttributeDTO; + +import java.util.List; + public interface AttributeService { + List getAllAttributes(); + + AttributeDTO getAttributeById(String id); + + AttributeDTO createAttribute(AttributeDTO attributeDTO); + + AttributeDTO updateAttribute(String id, AttributeDTO attributeDTO); + + void deleteAttribute(String id); } diff --git a/src/main/java/com/sarapis/orservice/service/AttributeServiceImpl.java b/src/main/java/com/sarapis/orservice/service/AttributeServiceImpl.java index b6d6a01..22627ad 100644 --- a/src/main/java/com/sarapis/orservice/service/AttributeServiceImpl.java +++ b/src/main/java/com/sarapis/orservice/service/AttributeServiceImpl.java @@ -1,4 +1,93 @@ package com.sarapis.orservice.service; -public class AttributeServiceImpl { +import com.sarapis.orservice.dto.AttributeDTO; +import com.sarapis.orservice.entity.Attribute; +import com.sarapis.orservice.repository.AttributeRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.stream.Collectors; + +@Service +public class AttributeServiceImpl implements AttributeService { + + private final AttributeRepository attributeRepository; + + private AttributeDTO mapToDTO(Attribute attribute) { + return new AttributeDTO( + attribute.getId(), + attribute.getLinkId(), + attribute.getLinkType(), + attribute.getLinkEntity(), + attribute.getValue(), + attribute.getTaxonomyTerm(), + attribute.getMetadata(), + attribute.getLabel() + ); + } + + private Attribute mapToEntity(AttributeDTO attributeDTO) { + return new Attribute( + attributeDTO.getId(), + attributeDTO.getLinkId(), + attributeDTO.getLinkType(), + attributeDTO.getLinkEntity(), + attributeDTO.getValue(), + attributeDTO.getTaxonomyTerm(), + attributeDTO.getMetadata(), + attributeDTO.getLabel() + ); + } + + @Autowired + public AttributeServiceImpl(AttributeRepository attributeRepository) { + this.attributeRepository = attributeRepository; + } + + @Override + public List getAllAttributes() { + return this.attributeRepository.findAll() + .stream() + .map(this::mapToDTO) + .collect(Collectors.toList()); + } + + @Override + public AttributeDTO getAttributeById(String id) { + Attribute attr = this.attributeRepository.findById(Long.parseLong(id)) + .orElseThrow(() -> new RuntimeException("Attribute not found")); + return this.mapToDTO(attr); + } + + @Override + public AttributeDTO createAttribute(AttributeDTO attributeDTO) { + Attribute attr = this.mapToEntity(attributeDTO); + Attribute savedAttr = this.attributeRepository.save(attr); + return this.mapToDTO(savedAttr); + } + + @Override + public AttributeDTO updateAttribute(String id, AttributeDTO attributeDTO) { + Attribute oldAttr = this.attributeRepository.findById(Long.parseLong(id)) + .orElseThrow(() -> new RuntimeException("Attribute not found")); + oldAttr.setId(attributeDTO.getId()); + oldAttr.setLinkId(attributeDTO.getLinkId()); + oldAttr.setLinkType(attributeDTO.getLinkType()); + oldAttr.setLinkEntity(attributeDTO.getLinkEntity()); + oldAttr.setValue(attributeDTO.getValue()); + oldAttr.setTaxonomyTerm(attributeDTO.getTaxonomyTerm()); + oldAttr.setMetadata(attributeDTO.getMetadata()); + oldAttr.setLabel(attributeDTO.getLabel()); + + Attribute upAttr = this.attributeRepository.save(oldAttr); + return mapToDTO(upAttr); + } + + @Override + public void deleteAttribute(String id) { + Attribute target = this.attributeRepository.findById(Long.parseLong(id)) + .orElseThrow(() -> new RuntimeException("Attribute not found")); + this.attributeRepository.delete(target); + } } From 719f73a67c8f39f657b34d1c772605731b0bff9b Mon Sep 17 00:00:00 2001 From: miguel-merlin Date: Thu, 21 Nov 2024 02:00:50 -0500 Subject: [PATCH 07/28] added toDTO and toEntity in appropiate classes: --- .../orservice/dto/OrganizationDTO.java | 20 +++++++++ .../orservice/entity/core/Organization.java | 20 +++++++++ .../service/OrganizationServiceImpl.java | 44 +++---------------- 3 files changed, 45 insertions(+), 39 deletions(-) diff --git a/src/main/java/com/sarapis/orservice/dto/OrganizationDTO.java b/src/main/java/com/sarapis/orservice/dto/OrganizationDTO.java index ce947d7..1f346f9 100644 --- a/src/main/java/com/sarapis/orservice/dto/OrganizationDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/OrganizationDTO.java @@ -4,6 +4,7 @@ import com.sarapis.orservice.entity.core.Organization; import java.util.List; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -12,6 +13,7 @@ @Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class OrganizationDTO { private String id; private String name; @@ -25,4 +27,22 @@ public class OrganizationDTO { private String logo; private String uri; private Organization parentOrganization; + + public Organization toEntity() { + return Organization.builder() + .id(this.id) + .name(this.name) + .alternateName(this.alternateName) + .description(this.description) + .email(this.email) + .website(this.website) + .additionalWebsites(this.additionalWebsites) + .yearIncorporated(this.yearIncorporated) + .legalStatus(this.legalStatus) + .logo(this.logo) + .uri(this.uri) + .parentOrganization(this.parentOrganization) + .build(); + } + } diff --git a/src/main/java/com/sarapis/orservice/entity/core/Organization.java b/src/main/java/com/sarapis/orservice/entity/core/Organization.java index cb23587..32181e8 100644 --- a/src/main/java/com/sarapis/orservice/entity/core/Organization.java +++ b/src/main/java/com/sarapis/orservice/entity/core/Organization.java @@ -1,5 +1,6 @@ package com.sarapis.orservice.entity.core; +import com.sarapis.orservice.dto.OrganizationDTO; import com.sarapis.orservice.entity.Url; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -10,6 +11,7 @@ import jakarta.persistence.Table; import java.util.List; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -21,6 +23,7 @@ @Setter @AllArgsConstructor @NoArgsConstructor +@Builder public class Organization { @Id @GeneratedValue @@ -52,4 +55,21 @@ public class Organization { @OneToOne private Organization parentOrganization; + + public OrganizationDTO toDTO() { + return OrganizationDTO.builder() + .id(id) + .name(name) + .alternateName(alternateName) + .description(description) + .email(email) + .website(website) + .additionalWebsites(additionalWebsites) + .yearIncorporated(yearIncorporated) + .legalStatus(legalStatus) + .logo(logo) + .uri(uri) + .parentOrganization(parentOrganization) + .build(); + } } diff --git a/src/main/java/com/sarapis/orservice/service/OrganizationServiceImpl.java b/src/main/java/com/sarapis/orservice/service/OrganizationServiceImpl.java index e227172..19f15f9 100644 --- a/src/main/java/com/sarapis/orservice/service/OrganizationServiceImpl.java +++ b/src/main/java/com/sarapis/orservice/service/OrganizationServiceImpl.java @@ -13,40 +13,6 @@ public class OrganizationServiceImpl implements OrganizationService { private final OrganizationRepository organizationRepository; - private OrganizationDTO mapToDTO(Organization organization) { - return new OrganizationDTO( - organization.getId(), - organization.getName(), - organization.getAlternateName(), - organization.getDescription(), - organization.getEmail(), - organization.getWebsite(), - organization.getAdditionalWebsites(), - organization.getYearIncorporated(), - organization.getLegalStatus(), - organization.getLogo(), - organization.getUri(), - organization.getParentOrganization() - ); - } - - private Organization mapToEntity(OrganizationDTO organizationDTO) { - return new Organization( - organizationDTO.getId(), - organizationDTO.getName(), - organizationDTO.getAlternateName(), - organizationDTO.getDescription(), - organizationDTO.getEmail(), - organizationDTO.getWebsite(), - organizationDTO.getAdditionalWebsites(), - organizationDTO.getYearIncorporated(), - organizationDTO.getLegalStatus(), - organizationDTO.getLogo(), - organizationDTO.getUri(), - organizationDTO.getParentOrganization() - ); - } - @Autowired public OrganizationServiceImpl(OrganizationRepository organizationRepository) { this.organizationRepository = organizationRepository; @@ -55,7 +21,7 @@ public OrganizationServiceImpl(OrganizationRepository organizationRepository) { @Override public List getAllOrganizations() { return organizationRepository.findAll().stream() - .map(this::mapToDTO) + .map(Organization::toDTO) .collect(Collectors.toList()); } @@ -63,14 +29,14 @@ public List getAllOrganizations() { public OrganizationDTO getOrganizationById(String id) { Organization organization = organizationRepository.findById(Long.parseLong(id)) .orElseThrow(() -> new RuntimeException("Organization not found")); - return mapToDTO(organization); + return organization.toDTO(); } @Override public OrganizationDTO createOrganization(OrganizationDTO organizationDTO) { - Organization organization = mapToEntity(organizationDTO); + Organization organization = organizationDTO.toEntity(); Organization savedOrganization = organizationRepository.save(organization); - return mapToDTO(savedOrganization); + return savedOrganization.toDTO(); } @Override @@ -83,7 +49,7 @@ public OrganizationDTO updateOrganization(String id, OrganizationDTO organizatio existingOrganization.setEmail(organizationDTO.getEmail()); existingOrganization.setWebsite(organizationDTO.getWebsite()); Organization updatedOrganization = organizationRepository.save(existingOrganization); - return mapToDTO(updatedOrganization); + return updatedOrganization.toDTO(); } @Override From fb9e6106eb2b7cb8a4b3a5fe0366c7210b348fba Mon Sep 17 00:00:00 2001 From: ZhangTerrence Date: Thu, 21 Nov 2024 13:49:40 -0500 Subject: [PATCH 08/28] fixed merge error --- .../orservice/entity/core/Organization.java | 68 +++++++++++++++---- 1 file changed, 54 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/sarapis/orservice/entity/core/Organization.java b/src/main/java/com/sarapis/orservice/entity/core/Organization.java index 32181e8..be9c0b8 100644 --- a/src/main/java/com/sarapis/orservice/entity/core/Organization.java +++ b/src/main/java/com/sarapis/orservice/entity/core/Organization.java @@ -1,22 +1,13 @@ package com.sarapis.orservice.entity.core; import com.sarapis.orservice.dto.OrganizationDTO; -import com.sarapis.orservice.entity.Url; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.OneToMany; -import jakarta.persistence.OneToOne; -import jakarta.persistence.Table; -import java.util.List; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import com.sarapis.orservice.entity.*; +import jakarta.persistence.*; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.List; + @Entity @Table(name = "organization") @Getter @@ -30,32 +21,81 @@ public class Organization { @UuidGenerator private String id; + @Column(name = "name") private String name; @Column(name = "alternate_name") private String alternateName; + @Column(name = "description") private String description; + @Column(name = "email") private String email; + @Column(name = "website") private String website; @OneToMany + @JoinColumn(name = "organization_id") private List additionalWebsites; + // Deprecated + @Column(name = "tax_status") + private String taxStatus; + + // Deprecated + @Column(name = "tax_id") + private String taxId; + @Column(name = "year_incorporated") private int yearIncorporated; + @Column(name = "legal_status") private String legalStatus; + @Column(name = "logo") private String logo; + @Column(name = "uri") private String uri; @OneToOne + @JoinColumn(name = "parent_organization_id") private Organization parentOrganization; + @OneToMany + @JoinColumn(name = "organization_id") + private List funding; + + @OneToMany + @JoinColumn(name = "organization_id") + private List contacts; + + @OneToMany + @JoinColumn(name = "organization_id") + private List phones; + + @OneToMany + @JoinColumn(name = "organization_id") + private List locations; + + @OneToMany + @JoinColumn(name = "organization_id") + private List programs; + + @OneToMany + @JoinColumn(name = "organization_id") + private List organizationIdentifiers; + + @OneToMany + @JoinColumn(name = "link_id") + private List attributes; + + @OneToMany + @JoinColumn(name = "resource_id") + private List metadata; + public OrganizationDTO toDTO() { return OrganizationDTO.builder() .id(id) From e08283b3f130adcee785362b114c3786c900e5a5 Mon Sep 17 00:00:00 2001 From: ZhangTerrence Date: Thu, 21 Nov 2024 13:51:43 -0500 Subject: [PATCH 09/28] added deprecated tags --- src/main/java/com/sarapis/orservice/entity/core/Service.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/sarapis/orservice/entity/core/Service.java b/src/main/java/com/sarapis/orservice/entity/core/Service.java index 5c0be89..3bf0526 100644 --- a/src/main/java/com/sarapis/orservice/entity/core/Service.java +++ b/src/main/java/com/sarapis/orservice/entity/core/Service.java @@ -55,9 +55,11 @@ public class Service { @Column(name = "fees_description") private String feesDescription; + // Deprecated @Column(name = "wait_time") private String waitTime; + // Deprecated @Column(name = "fees") private String fees; @@ -79,6 +81,7 @@ public class Service { @Column(name = "assurer_email") private String assurerEmail; + // Deprecated @Column(name = "licenses") private String licenses; From 65e8f3df2335148232d3cab73cbd7b0513c4ca09 Mon Sep 17 00:00:00 2001 From: Butter - ThinkWin Date: Thu, 21 Nov 2024 14:22:16 -0500 Subject: [PATCH 10/28] Implemented Repository, DTO, and Service for Address --- .../com/sarapis/orservice/dto/AddressDTO.java | 26 +++++ .../repository/AddressRepository.java | 9 ++ .../orservice/service/AddressService.java | 17 ++++ .../orservice/service/AddressServiceImpl.java | 98 +++++++++++++++++++ 4 files changed, 150 insertions(+) create mode 100644 src/main/java/com/sarapis/orservice/dto/AddressDTO.java create mode 100644 src/main/java/com/sarapis/orservice/repository/AddressRepository.java create mode 100644 src/main/java/com/sarapis/orservice/service/AddressService.java create mode 100644 src/main/java/com/sarapis/orservice/service/AddressServiceImpl.java diff --git a/src/main/java/com/sarapis/orservice/dto/AddressDTO.java b/src/main/java/com/sarapis/orservice/dto/AddressDTO.java new file mode 100644 index 0000000..698936c --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/AddressDTO.java @@ -0,0 +1,26 @@ +package com.sarapis.orservice.dto; + +import com.sarapis.orservice.entity.AddressType; +import com.sarapis.orservice.entity.core.Location; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +public class AddressDTO { + private String id; + private Location location; + private String attention; + private String address_1; + private String address_2; + private String city; + private String region; + private String stateProvince; + private String postalCode; + private String country; + private AddressType addressType; +} diff --git a/src/main/java/com/sarapis/orservice/repository/AddressRepository.java b/src/main/java/com/sarapis/orservice/repository/AddressRepository.java new file mode 100644 index 0000000..b19c2e8 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/repository/AddressRepository.java @@ -0,0 +1,9 @@ +package com.sarapis.orservice.repository; + +import com.sarapis.orservice.entity.Address; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface AddressRepository extends JpaRepository { +} diff --git a/src/main/java/com/sarapis/orservice/service/AddressService.java b/src/main/java/com/sarapis/orservice/service/AddressService.java new file mode 100644 index 0000000..c05f2d9 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/service/AddressService.java @@ -0,0 +1,17 @@ +package com.sarapis.orservice.service; + +import com.sarapis.orservice.dto.AddressDTO; + +import java.util.List; + +public interface AddressService { + List getAllAddresses(); + + AddressDTO getAddressById(String id); + + AddressDTO createAddress(AddressDTO addressDTO); + + AddressDTO updateAddress(String id, AddressDTO addressDTO); + + void deleteAddress(String id); +} diff --git a/src/main/java/com/sarapis/orservice/service/AddressServiceImpl.java b/src/main/java/com/sarapis/orservice/service/AddressServiceImpl.java new file mode 100644 index 0000000..f339088 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/service/AddressServiceImpl.java @@ -0,0 +1,98 @@ +package com.sarapis.orservice.service; + +import com.sarapis.orservice.dto.AddressDTO; +import com.sarapis.orservice.entity.Address; +import com.sarapis.orservice.repository.AddressRepository; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.stream.Collectors; + +@Service +public class AddressServiceImpl implements AddressService { + private final AddressRepository addressRepository; + + private AddressDTO mapToDTO(Address address) { + return new AddressDTO( + address.getId(), + address.getLocation(), + address.getAttention(), + address.getAddress_1(), + address.getAddress_2(), + address.getCity(), + address.getRegion(), + address.getStateProvince(), + address.getPostalCode(), + address.getCountry(), + address.getAddressType() + ); + } + + private Address mapToEntity(AddressDTO addressDTO) { + return new Address( + addressDTO.getId(), + addressDTO.getLocation(), + addressDTO.getAttention(), + addressDTO.getAddress_1(), + addressDTO.getAddress_2(), + addressDTO.getCity(), + addressDTO.getRegion(), + addressDTO.getStateProvince(), + addressDTO.getPostalCode(), + addressDTO.getCountry(), + addressDTO.getAddressType() + ); + } + + public AddressServiceImpl(AddressRepository addressRepository) { + this.addressRepository = addressRepository; + } + + @Override + public List getAllAddresses() { + return this.addressRepository.findAll().stream() + .map(this::mapToDTO) + .collect(Collectors.toList()); + } + + @Override + public AddressDTO getAddressById(String id) { + Address address = this.addressRepository.findById(Long.parseLong(id)) + .orElseThrow(() -> new RuntimeException("Address not found")); + return this.mapToDTO(address); + } + + @Override + public AddressDTO createAddress(AddressDTO addressDTO) { + Address address = this.mapToEntity(addressDTO); + Address savedAddress = this.addressRepository.save(address); + return this.mapToDTO(savedAddress); + } + + @Override + public AddressDTO updateAddress(String id, AddressDTO addressDTO) { + Address oldAddress = this.addressRepository.findById(Long.parseLong(id)) + .orElseThrow(() -> new RuntimeException("Address not found")); + + oldAddress.setLocation(addressDTO.getLocation()); + oldAddress.setAttention(addressDTO.getAttention()); + oldAddress.setAddress_1(addressDTO.getAddress_1()); + oldAddress.setAddress_2(addressDTO.getAddress_2()); + oldAddress.setCity(addressDTO.getCity()); + oldAddress.setRegion(addressDTO.getRegion()); + oldAddress.setStateProvince(addressDTO.getStateProvince()); + oldAddress.setPostalCode(addressDTO.getPostalCode()); + oldAddress.setCountry(addressDTO.getCountry()); + oldAddress.setAddressType(addressDTO.getAddressType()); + + Address updatedAddress = this.addressRepository.save(oldAddress); + return this.mapToDTO(updatedAddress); + } + + @Override + public void deleteAddress(String id) { + Address target = this.addressRepository.findById(Long.parseLong(id)) + .orElseThrow(() -> new RuntimeException("Address not found")); + this.addressRepository.delete(target); + } +} From ef45845e88b470468ee73e483c05522ad68392a3 Mon Sep 17 00:00:00 2001 From: Butter - ThinkWin Date: Thu, 21 Nov 2024 14:23:25 -0500 Subject: [PATCH 11/28] Removed setId call on updateAttribute() --- .../com/sarapis/orservice/service/AttributeServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/sarapis/orservice/service/AttributeServiceImpl.java b/src/main/java/com/sarapis/orservice/service/AttributeServiceImpl.java index 22627ad..7d57a76 100644 --- a/src/main/java/com/sarapis/orservice/service/AttributeServiceImpl.java +++ b/src/main/java/com/sarapis/orservice/service/AttributeServiceImpl.java @@ -71,7 +71,7 @@ public AttributeDTO createAttribute(AttributeDTO attributeDTO) { public AttributeDTO updateAttribute(String id, AttributeDTO attributeDTO) { Attribute oldAttr = this.attributeRepository.findById(Long.parseLong(id)) .orElseThrow(() -> new RuntimeException("Attribute not found")); - oldAttr.setId(attributeDTO.getId()); + oldAttr.setLinkId(attributeDTO.getLinkId()); oldAttr.setLinkType(attributeDTO.getLinkType()); oldAttr.setLinkEntity(attributeDTO.getLinkEntity()); From 2131a9c0333b53ab572ea49880d2f9662e44d16b Mon Sep 17 00:00:00 2001 From: ZhangTerrence Date: Thu, 21 Nov 2024 16:00:05 -0500 Subject: [PATCH 12/28] added nonnullable --- .../sarapis/orservice/entity/Accessibility.java | 1 + .../com/sarapis/orservice/entity/Address.java | 13 +++++++------ .../com/sarapis/orservice/entity/Attribute.java | 1 + .../com/sarapis/orservice/entity/Contact.java | 1 + .../com/sarapis/orservice/entity/CostOption.java | 1 + .../com/sarapis/orservice/entity/Funding.java | 1 + .../com/sarapis/orservice/entity/Language.java | 1 + .../orservice/entity/MetaTableDescription.java | 1 + .../com/sarapis/orservice/entity/Metadata.java | 15 ++++++++------- .../orservice/entity/OrganizationIdentifier.java | 5 +++-- .../java/com/sarapis/orservice/entity/Phone.java | 3 ++- .../com/sarapis/orservice/entity/Program.java | 5 +++-- .../orservice/entity/RequiredDocument.java | 1 + .../com/sarapis/orservice/entity/Schedule.java | 1 + .../com/sarapis/orservice/entity/ServiceArea.java | 1 + .../sarapis/orservice/entity/ServiceCapacity.java | 7 ++++--- .../com/sarapis/orservice/entity/Taxonomy.java | 5 +++-- .../sarapis/orservice/entity/TaxonomyTerm.java | 5 +++-- .../java/com/sarapis/orservice/entity/Unit.java | 3 ++- .../java/com/sarapis/orservice/entity/Url.java | 3 ++- .../sarapis/orservice/entity/core/Location.java | 3 ++- .../orservice/entity/core/Organization.java | 5 +++-- .../sarapis/orservice/entity/core/Service.java | 5 +++-- .../orservice/entity/core/ServiceAtLocation.java | 1 + 24 files changed, 56 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/sarapis/orservice/entity/Accessibility.java b/src/main/java/com/sarapis/orservice/entity/Accessibility.java index d571310..2022036 100644 --- a/src/main/java/com/sarapis/orservice/entity/Accessibility.java +++ b/src/main/java/com/sarapis/orservice/entity/Accessibility.java @@ -20,6 +20,7 @@ public class Accessibility { @Id @GeneratedValue @UuidGenerator + @Column(name = "id", nullable = false) private String id; @ManyToOne diff --git a/src/main/java/com/sarapis/orservice/entity/Address.java b/src/main/java/com/sarapis/orservice/entity/Address.java index 3966873..465ce3f 100644 --- a/src/main/java/com/sarapis/orservice/entity/Address.java +++ b/src/main/java/com/sarapis/orservice/entity/Address.java @@ -20,6 +20,7 @@ public class Address { @Id @GeneratedValue @UuidGenerator + @Column(name = "id", nullable = false) private String id; @ManyToOne @@ -29,29 +30,29 @@ public class Address { @Column(name = "attention") private String attention; - @Column(name = "address_1") + @Column(name = "address_1", nullable = false) private String address_1; @Column(name = "address_2") private String address_2; - @Column(name = "city") + @Column(name = "city", nullable = false) private String city; @Column(name = "region") private String region; - @Column(name = "state_province") + @Column(name = "state_province", nullable = false) private String stateProvince; - @Column(name = "postal_code") + @Column(name = "postal_code", nullable = false) private String postalCode; - @Column(name = "country") + @Column(name = "country", nullable = false) private String country; @Enumerated(EnumType.STRING) - @Column(name = "address_type") + @Column(name = "address_type", nullable = false) private AddressType addressType; @OneToMany diff --git a/src/main/java/com/sarapis/orservice/entity/Attribute.java b/src/main/java/com/sarapis/orservice/entity/Attribute.java index 9503c3f..1a01e26 100644 --- a/src/main/java/com/sarapis/orservice/entity/Attribute.java +++ b/src/main/java/com/sarapis/orservice/entity/Attribute.java @@ -19,6 +19,7 @@ public class Attribute { @Id @GeneratedValue @UuidGenerator + @Column(name = "id", nullable = false) private String id; // FK Property diff --git a/src/main/java/com/sarapis/orservice/entity/Contact.java b/src/main/java/com/sarapis/orservice/entity/Contact.java index 77e2fb5..066fc55 100644 --- a/src/main/java/com/sarapis/orservice/entity/Contact.java +++ b/src/main/java/com/sarapis/orservice/entity/Contact.java @@ -23,6 +23,7 @@ public class Contact { @Id @GeneratedValue @UuidGenerator + @Column(name = "id", nullable = false) private String id; @ManyToOne diff --git a/src/main/java/com/sarapis/orservice/entity/CostOption.java b/src/main/java/com/sarapis/orservice/entity/CostOption.java index 21c0513..0129d5b 100644 --- a/src/main/java/com/sarapis/orservice/entity/CostOption.java +++ b/src/main/java/com/sarapis/orservice/entity/CostOption.java @@ -21,6 +21,7 @@ public class CostOption { @Id @GeneratedValue @UuidGenerator + @Column(name = "id", nullable = false) private String id; @OneToOne diff --git a/src/main/java/com/sarapis/orservice/entity/Funding.java b/src/main/java/com/sarapis/orservice/entity/Funding.java index 3ebe7e2..fa37bdd 100644 --- a/src/main/java/com/sarapis/orservice/entity/Funding.java +++ b/src/main/java/com/sarapis/orservice/entity/Funding.java @@ -21,6 +21,7 @@ public class Funding { @Id @GeneratedValue @UuidGenerator + @Column(name = "id", nullable = false) private String id; @ManyToOne diff --git a/src/main/java/com/sarapis/orservice/entity/Language.java b/src/main/java/com/sarapis/orservice/entity/Language.java index ccae04f..2d73e20 100644 --- a/src/main/java/com/sarapis/orservice/entity/Language.java +++ b/src/main/java/com/sarapis/orservice/entity/Language.java @@ -21,6 +21,7 @@ public class Language { @Id @GeneratedValue @UuidGenerator + @Column(name = "id", nullable = false) private String id; @ManyToOne diff --git a/src/main/java/com/sarapis/orservice/entity/MetaTableDescription.java b/src/main/java/com/sarapis/orservice/entity/MetaTableDescription.java index d9cf328..c02130b 100644 --- a/src/main/java/com/sarapis/orservice/entity/MetaTableDescription.java +++ b/src/main/java/com/sarapis/orservice/entity/MetaTableDescription.java @@ -19,6 +19,7 @@ public class MetaTableDescription { @Id @GeneratedValue @UuidGenerator + @Column(name = "id", nullable = false) private String id; @Column(name = "name") diff --git a/src/main/java/com/sarapis/orservice/entity/Metadata.java b/src/main/java/com/sarapis/orservice/entity/Metadata.java index 6b5593e..748f689 100644 --- a/src/main/java/com/sarapis/orservice/entity/Metadata.java +++ b/src/main/java/com/sarapis/orservice/entity/Metadata.java @@ -19,31 +19,32 @@ public class Metadata { @Id @GeneratedValue @UuidGenerator + @Column(name = "id", nullable = false) private String id; // FK Property - @Column(name = "resource_id", nullable = false, unique = true) + @Column(name = "resource_id") private String resourceId; @Enumerated(EnumType.STRING) @Column(name = "resource_type") private ResourceType resourceType; - @Column(name = "last_action_date") + @Column(name = "last_action_date", nullable = false) private LocalDate lastActionDate; - @Column(name = "last_action_type") + @Column(name = "last_action_type", nullable = false) private String lastActionType; - @Column(name = "field_name") + @Column(name = "field_name", nullable = false) private String fieldName; - @Column(name = "previous_value") + @Column(name = "previous_value", nullable = false) private String previousValue; - @Column(name = "replacement_value") + @Column(name = "replacement_value", nullable = false) private String replacementValue; - @Column(name = "updated_by") + @Column(name = "updated_by", nullable = false) private String updatedBy; } diff --git a/src/main/java/com/sarapis/orservice/entity/OrganizationIdentifier.java b/src/main/java/com/sarapis/orservice/entity/OrganizationIdentifier.java index 0ded841..4f8a8aa 100644 --- a/src/main/java/com/sarapis/orservice/entity/OrganizationIdentifier.java +++ b/src/main/java/com/sarapis/orservice/entity/OrganizationIdentifier.java @@ -20,6 +20,7 @@ public class OrganizationIdentifier { @Id @GeneratedValue @UuidGenerator + @Column(name = "id", nullable = false) private String id; @ManyToOne @@ -29,10 +30,10 @@ public class OrganizationIdentifier { @Column(name = "identifier_scheme") private String identifierScheme; - @Column(name = "identifier_type") + @Column(name = "identifier_type", nullable = false) private String identifierType; - @Column(name = "identifier") + @Column(name = "identifier", nullable = false) private String identifier; @OneToMany diff --git a/src/main/java/com/sarapis/orservice/entity/Phone.java b/src/main/java/com/sarapis/orservice/entity/Phone.java index a8dd020..48fc17a 100644 --- a/src/main/java/com/sarapis/orservice/entity/Phone.java +++ b/src/main/java/com/sarapis/orservice/entity/Phone.java @@ -22,6 +22,7 @@ public class Phone { @Id @GeneratedValue @UuidGenerator + @Column(name = "id", nullable = false) private String id; @ManyToOne @@ -40,7 +41,7 @@ public class Phone { @JoinColumn(name = "service_at_location_id") private ServiceAtLocation serviceAtLocation; - @Column(name = "number") + @Column(name = "number", nullable = false) private String number; @Column(name = "extension") diff --git a/src/main/java/com/sarapis/orservice/entity/Program.java b/src/main/java/com/sarapis/orservice/entity/Program.java index a3c6733..696b504 100644 --- a/src/main/java/com/sarapis/orservice/entity/Program.java +++ b/src/main/java/com/sarapis/orservice/entity/Program.java @@ -20,19 +20,20 @@ public class Program { @Id @GeneratedValue @UuidGenerator + @Column(name = "id", nullable = false) private String id; @ManyToOne @JoinColumn(name = "organization_id") private Organization organization; - @Column(name = "name") + @Column(name = "name", nullable = false) private String name; @Column(name = "alternate_name") private String alternateName; - @Column(name = "description") + @Column(name = "description", nullable = false) private String description; @OneToMany diff --git a/src/main/java/com/sarapis/orservice/entity/RequiredDocument.java b/src/main/java/com/sarapis/orservice/entity/RequiredDocument.java index 6aa621c..cf32e17 100644 --- a/src/main/java/com/sarapis/orservice/entity/RequiredDocument.java +++ b/src/main/java/com/sarapis/orservice/entity/RequiredDocument.java @@ -20,6 +20,7 @@ public class RequiredDocument { @Id @GeneratedValue @UuidGenerator + @Column(name = "id", nullable = false) private String id; @ManyToOne diff --git a/src/main/java/com/sarapis/orservice/entity/Schedule.java b/src/main/java/com/sarapis/orservice/entity/Schedule.java index 8df64f3..9a033c4 100644 --- a/src/main/java/com/sarapis/orservice/entity/Schedule.java +++ b/src/main/java/com/sarapis/orservice/entity/Schedule.java @@ -24,6 +24,7 @@ public class Schedule { @Id @GeneratedValue @UuidGenerator + @Column(name = "id", nullable = false) private String id; @ManyToOne diff --git a/src/main/java/com/sarapis/orservice/entity/ServiceArea.java b/src/main/java/com/sarapis/orservice/entity/ServiceArea.java index 808e9cb..c2a1ad9 100644 --- a/src/main/java/com/sarapis/orservice/entity/ServiceArea.java +++ b/src/main/java/com/sarapis/orservice/entity/ServiceArea.java @@ -21,6 +21,7 @@ public class ServiceArea { @Id @GeneratedValue @UuidGenerator + @Column(name = "id", nullable = false) private String id; @ManyToOne diff --git a/src/main/java/com/sarapis/orservice/entity/ServiceCapacity.java b/src/main/java/com/sarapis/orservice/entity/ServiceCapacity.java index bf68a74..3154dab 100644 --- a/src/main/java/com/sarapis/orservice/entity/ServiceCapacity.java +++ b/src/main/java/com/sarapis/orservice/entity/ServiceCapacity.java @@ -21,6 +21,7 @@ public class ServiceCapacity { @Id @GeneratedValue @UuidGenerator + @Column(name = "id", nullable = false) private String id; @ManyToOne @@ -28,10 +29,10 @@ public class ServiceCapacity { private Service service; @OneToOne - @JoinColumn(name = "unit_id") + @JoinColumn(name = "unit_id", nullable = false) private Unit unit; - @Column(name = "available") + @Column(name = "available", nullable = false) private int available; @Column(name = "maximum") @@ -40,7 +41,7 @@ public class ServiceCapacity { @Column(name = "description") private String description; - @Column(name = "updated") + @Column(name = "updated", nullable = false) private LocalDate updated; @OneToMany diff --git a/src/main/java/com/sarapis/orservice/entity/Taxonomy.java b/src/main/java/com/sarapis/orservice/entity/Taxonomy.java index 6129802..beab69a 100644 --- a/src/main/java/com/sarapis/orservice/entity/Taxonomy.java +++ b/src/main/java/com/sarapis/orservice/entity/Taxonomy.java @@ -19,12 +19,13 @@ public class Taxonomy { @Id @GeneratedValue @UuidGenerator + @Column(name = "id", nullable = false) private String id; - @Column(name = "name") + @Column(name = "name", nullable = false) private String name; - @Column(name = "description") + @Column(name = "description", nullable = false) private String description; @Column(name = "uri") diff --git a/src/main/java/com/sarapis/orservice/entity/TaxonomyTerm.java b/src/main/java/com/sarapis/orservice/entity/TaxonomyTerm.java index c6453f5..14628e6 100644 --- a/src/main/java/com/sarapis/orservice/entity/TaxonomyTerm.java +++ b/src/main/java/com/sarapis/orservice/entity/TaxonomyTerm.java @@ -19,15 +19,16 @@ public class TaxonomyTerm { @Id @GeneratedValue @UuidGenerator + @Column(name = "id", nullable = false) private String id; @Column(name = "code") private String code; - @Column(name = "name") + @Column(name = "name", nullable = false) private String name; - @Column(name = "description") + @Column(name = "description", nullable = false) private String description; @OneToOne diff --git a/src/main/java/com/sarapis/orservice/entity/Unit.java b/src/main/java/com/sarapis/orservice/entity/Unit.java index a491a7b..f8590d3 100644 --- a/src/main/java/com/sarapis/orservice/entity/Unit.java +++ b/src/main/java/com/sarapis/orservice/entity/Unit.java @@ -19,9 +19,10 @@ public class Unit { @Id @GeneratedValue @UuidGenerator + @Column(name = "id", nullable = false) private String id; - @Column(name = "name") + @Column(name = "name", nullable = false) private String name; @Column(name = "scheme") diff --git a/src/main/java/com/sarapis/orservice/entity/Url.java b/src/main/java/com/sarapis/orservice/entity/Url.java index 7ff5aac..a0b2113 100644 --- a/src/main/java/com/sarapis/orservice/entity/Url.java +++ b/src/main/java/com/sarapis/orservice/entity/Url.java @@ -21,12 +21,13 @@ public class Url { @Id @GeneratedValue @UuidGenerator + @Column(name = "id", nullable = false) private String id; @Column(name = "label") private String label; - @Column(name = "url") + @Column(name = "url", nullable = false) private String url; @ManyToOne diff --git a/src/main/java/com/sarapis/orservice/entity/core/Location.java b/src/main/java/com/sarapis/orservice/entity/core/Location.java index d6e6856..42b00ac 100644 --- a/src/main/java/com/sarapis/orservice/entity/core/Location.java +++ b/src/main/java/com/sarapis/orservice/entity/core/Location.java @@ -20,10 +20,11 @@ public class Location { @Id @GeneratedValue @UuidGenerator + @Column(name = "id", nullable = false) private String id; @Enumerated(EnumType.STRING) - @Column(name = "location_type") + @Column(name = "location_type", nullable = false) private LocationType locationType; @Column(name = "url") diff --git a/src/main/java/com/sarapis/orservice/entity/core/Organization.java b/src/main/java/com/sarapis/orservice/entity/core/Organization.java index be9c0b8..2b938a9 100644 --- a/src/main/java/com/sarapis/orservice/entity/core/Organization.java +++ b/src/main/java/com/sarapis/orservice/entity/core/Organization.java @@ -19,15 +19,16 @@ public class Organization { @Id @GeneratedValue @UuidGenerator + @Column(name = "id", nullable = false) private String id; - @Column(name = "name") + @Column(name = "name", nullable = false) private String name; @Column(name = "alternate_name") private String alternateName; - @Column(name = "description") + @Column(name = "description", nullable = false) private String description; @Column(name = "email") diff --git a/src/main/java/com/sarapis/orservice/entity/core/Service.java b/src/main/java/com/sarapis/orservice/entity/core/Service.java index 3bf0526..71c9b86 100644 --- a/src/main/java/com/sarapis/orservice/entity/core/Service.java +++ b/src/main/java/com/sarapis/orservice/entity/core/Service.java @@ -21,9 +21,10 @@ public class Service { @Id @GeneratedValue @UuidGenerator + @Column(name = "id", nullable = false) private String id; - @Column(name = "name") + @Column(name = "name", nullable = false) private String name; @Column(name = "alternate_name") @@ -43,7 +44,7 @@ public class Service { private String email; @Enumerated(EnumType.STRING) - @Column(name = "status") + @Column(name = "status", nullable = false) private Status status; @Column(name = "interpretation_services") diff --git a/src/main/java/com/sarapis/orservice/entity/core/ServiceAtLocation.java b/src/main/java/com/sarapis/orservice/entity/core/ServiceAtLocation.java index fe73309..6c7f018 100644 --- a/src/main/java/com/sarapis/orservice/entity/core/ServiceAtLocation.java +++ b/src/main/java/com/sarapis/orservice/entity/core/ServiceAtLocation.java @@ -20,6 +20,7 @@ public class ServiceAtLocation { @Id @GeneratedValue @UuidGenerator + @Column(name = "id", nullable = false) private String id; @ManyToOne From db72650e6e6ffe0de33186ffc5ab6839e4e512fe Mon Sep 17 00:00:00 2001 From: ZhangTerrence Date: Fri, 22 Nov 2024 11:51:46 -0500 Subject: [PATCH 13/28] removed unnecessary bidirectional relations --- .../orservice/entity/Accessibility.java | 46 ++--- .../com/sarapis/orservice/entity/Address.java | 72 +++---- .../sarapis/orservice/entity/Attribute.java | 49 ++--- .../com/sarapis/orservice/entity/Contact.java | 71 +++---- .../sarapis/orservice/entity/CostOption.java | 58 +++--- .../com/sarapis/orservice/entity/Funding.java | 49 ++--- .../sarapis/orservice/entity/Language.java | 55 ++--- .../entity/MetaTableDescription.java | 41 ++-- .../sarapis/orservice/entity/Metadata.java | 50 ++--- .../entity/OrganizationIdentifier.java | 46 ++--- .../com/sarapis/orservice/entity/Phone.java | 70 +++---- .../com/sarapis/orservice/entity/Program.java | 46 ++--- .../orservice/entity/RequiredDocument.java | 42 ++-- .../sarapis/orservice/entity/Schedule.java | 124 +++++------ .../sarapis/orservice/entity/ServiceArea.java | 61 +++--- .../orservice/entity/ServiceCapacity.java | 18 +- .../sarapis/orservice/entity/Taxonomy.java | 39 ++-- .../orservice/entity/TaxonomyTerm.java | 59 +++--- .../com/sarapis/orservice/entity/Unit.java | 13 +- .../com/sarapis/orservice/entity/Url.java | 43 ++-- .../orservice/entity/core/Location.java | 111 +++++----- .../orservice/entity/core/Organization.java | 195 +++++++++--------- .../orservice/entity/core/Service.java | 195 +++++++++--------- .../entity/core/ServiceAtLocation.java | 77 ++++--- 24 files changed, 732 insertions(+), 898 deletions(-) diff --git a/src/main/java/com/sarapis/orservice/entity/Accessibility.java b/src/main/java/com/sarapis/orservice/entity/Accessibility.java index 2022036..9fe3b75 100644 --- a/src/main/java/com/sarapis/orservice/entity/Accessibility.java +++ b/src/main/java/com/sarapis/orservice/entity/Accessibility.java @@ -1,13 +1,10 @@ package com.sarapis.orservice.entity; -import com.sarapis.orservice.entity.core.Location; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; import java.util.List; @Entity @@ -16,31 +13,28 @@ @Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class Accessibility { - @Id - @GeneratedValue - @UuidGenerator - @Column(name = "id", nullable = false) - private String id; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; - @ManyToOne - @JoinColumn(name = "location_id") - private Location location; + @Column(name = "description") + private String description; - @Column(name = "description") - private String description; + @Column(name = "details") + private String details; - @Column(name = "details") - private String details; + @Column(name = "url") + private String url; - @Column(name = "url") - private String url; + @OneToMany + @JoinColumn(name = "link_id") + private List attributes = new ArrayList<>(); - @OneToMany - @JoinColumn(name = "link_id") - private List attributes; - - @OneToMany - @JoinColumn(name = "resource_id") - private List metadata; + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "resource_id") + private List metadata = new ArrayList<>(); } diff --git a/src/main/java/com/sarapis/orservice/entity/Address.java b/src/main/java/com/sarapis/orservice/entity/Address.java index 465ce3f..ff8865d 100644 --- a/src/main/java/com/sarapis/orservice/entity/Address.java +++ b/src/main/java/com/sarapis/orservice/entity/Address.java @@ -1,13 +1,10 @@ package com.sarapis.orservice.entity; -import com.sarapis.orservice.entity.core.Location; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; import java.util.List; @Entity @@ -16,50 +13,47 @@ @Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class Address { - @Id - @GeneratedValue - @UuidGenerator - @Column(name = "id", nullable = false) - private String id; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; - @ManyToOne - @JoinColumn(name = "location_id") - private Location location; + @Column(name = "attention") + private String attention; - @Column(name = "attention") - private String attention; + @Column(name = "address_1", nullable = false) + private String address_1; - @Column(name = "address_1", nullable = false) - private String address_1; + @Column(name = "address_2") + private String address_2; - @Column(name = "address_2") - private String address_2; + @Column(name = "city", nullable = false) + private String city; - @Column(name = "city", nullable = false) - private String city; + @Column(name = "region") + private String region; - @Column(name = "region") - private String region; + @Column(name = "state_province", nullable = false) + private String stateProvince; - @Column(name = "state_province", nullable = false) - private String stateProvince; + @Column(name = "postal_code", nullable = false) + private String postalCode; - @Column(name = "postal_code", nullable = false) - private String postalCode; + @Column(name = "country", nullable = false) + private String country; - @Column(name = "country", nullable = false) - private String country; + @Enumerated(EnumType.STRING) + @Column(name = "address_type", nullable = false) + private AddressType addressType; - @Enumerated(EnumType.STRING) - @Column(name = "address_type", nullable = false) - private AddressType addressType; + @OneToMany + @JoinColumn(name = "link_id") + private List attributes = new ArrayList<>(); - @OneToMany - @JoinColumn(name = "link_id") - private List attributes; - - @OneToMany - @JoinColumn(name = "resource_id") - private List metadata; + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "resource_id") + private List metadata = new ArrayList<>(); } diff --git a/src/main/java/com/sarapis/orservice/entity/Attribute.java b/src/main/java/com/sarapis/orservice/entity/Attribute.java index 1a01e26..a3d14f5 100644 --- a/src/main/java/com/sarapis/orservice/entity/Attribute.java +++ b/src/main/java/com/sarapis/orservice/entity/Attribute.java @@ -1,12 +1,10 @@ package com.sarapis.orservice.entity; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; import java.util.List; @Entity @@ -15,34 +13,31 @@ @Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class Attribute { - @Id - @GeneratedValue - @UuidGenerator - @Column(name = "id", nullable = false) - private String id; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; - // FK Property - @Column(name = "link_id", nullable = false, unique = true) - private String linkId; + @Column(name = "link_type") + private String linkType; - @Column(name = "link_type") - private String linkType; + @Column(name = "link_entity") + private String linkEntity; - @Column(name = "link_entity") - private String linkEntity; + @Column(name = "value") + private String value; - @Column(name = "value") - private String value; + @OneToOne + @JoinColumn(name = "taxonomy_term_id") + private TaxonomyTerm taxonomyTerm; - @OneToOne - @JoinColumn(name = "taxonomy_term_id") - private TaxonomyTerm taxonomyTerm; + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "resource_id") + private List metadata = new ArrayList<>(); - @OneToMany - @JoinColumn(name = "resource_id") - private List metadata; - - @Column(name = "label") - private String label; + @Column(name = "label") + private String label; } diff --git a/src/main/java/com/sarapis/orservice/entity/Contact.java b/src/main/java/com/sarapis/orservice/entity/Contact.java index 066fc55..dbe7aa0 100644 --- a/src/main/java/com/sarapis/orservice/entity/Contact.java +++ b/src/main/java/com/sarapis/orservice/entity/Contact.java @@ -1,16 +1,10 @@ package com.sarapis.orservice.entity; -import com.sarapis.orservice.entity.core.Location; -import com.sarapis.orservice.entity.core.Organization; -import com.sarapis.orservice.entity.core.Service; -import com.sarapis.orservice.entity.core.ServiceAtLocation; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; import java.util.List; @Entity @@ -19,50 +13,35 @@ @Getter @NoArgsConstructor @AllArgsConstructor +@Builder public class Contact { - @Id - @GeneratedValue - @UuidGenerator - @Column(name = "id", nullable = false) - private String id; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; - @ManyToOne - @JoinColumn(name = "organization_id") - private Organization organization; + @Column(name = "name") + private String name; - @ManyToOne - @JoinColumn(name = "service_id") - private Service service; + @Column(name = "title") + private String title; - @ManyToOne - @JoinColumn(name = "service_at_location_id") - private ServiceAtLocation serviceAtLocation; + @Column(name = "department") + private String department; - @ManyToOne - @JoinColumn(name = "location_id") - private Location location; + @Column(name = "email") + private String email; - @Column(name = "name") - private String name; + @OneToMany + @JoinColumn(name = "contact_id") + private List phones = new ArrayList<>(); - @Column(name = "title") - private String title; + @OneToMany + @JoinColumn(name = "link_id") + private List attributes = new ArrayList<>(); - @Column(name = "department") - private String department; - - @Column(name = "email") - private String email; - - @OneToMany - @JoinColumn(name = "contact_id") - private List phones; - - @OneToMany - @JoinColumn(name = "link_id") - private List attributes; - - @OneToMany - @JoinColumn(name = "resource_id") - private List metadata; + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "resource_id") + private List metadata = new ArrayList<>(); } diff --git a/src/main/java/com/sarapis/orservice/entity/CostOption.java b/src/main/java/com/sarapis/orservice/entity/CostOption.java index 0129d5b..dd00eda 100644 --- a/src/main/java/com/sarapis/orservice/entity/CostOption.java +++ b/src/main/java/com/sarapis/orservice/entity/CostOption.java @@ -1,14 +1,11 @@ package com.sarapis.orservice.entity; -import com.sarapis.orservice.entity.core.Service; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; import org.hibernate.annotations.UuidGenerator; import java.time.LocalDate; +import java.util.ArrayList; import java.util.List; @Entity @@ -17,40 +14,37 @@ @Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class CostOption { - @Id - @GeneratedValue - @UuidGenerator - @Column(name = "id", nullable = false) - private String id; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; - @OneToOne - @JoinColumn(name = "service_id") - private Service service; + @Column(name = "valid_from") + private LocalDate validFrom; - @Column(name = "valid_from") - private LocalDate validFrom; + @Column(name = "valid_to") + private LocalDate validTo; - @Column(name = "valid_to") - private LocalDate validTo; + @Column(name = "option") + private String option; - @Column(name = "option") - private String option; + @Column(name = "currency") + private String currency; - @Column(name = "currency") - private String currency; + @Column(name = "amount") + private int amount; - @Column(name = "amount") - private int amount; + @Column(name = "amount_description") + private String amountDescription; - @Column(name = "amount_description") - private String amountDescription; + @OneToMany + @JoinColumn(name = "link_id") + private List attributes = new ArrayList<>(); - @OneToMany - @JoinColumn(name = "link_id") - private List attributes; - - @OneToMany - @JoinColumn(name = "resource_id") - private List metadata; + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "resource_id") + private List metadata = new ArrayList<>(); } diff --git a/src/main/java/com/sarapis/orservice/entity/Funding.java b/src/main/java/com/sarapis/orservice/entity/Funding.java index fa37bdd..f4c70ff 100644 --- a/src/main/java/com/sarapis/orservice/entity/Funding.java +++ b/src/main/java/com/sarapis/orservice/entity/Funding.java @@ -1,14 +1,10 @@ package com.sarapis.orservice.entity; -import com.sarapis.orservice.entity.core.Organization; -import com.sarapis.orservice.entity.core.Service; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; import java.util.List; @Entity @@ -17,29 +13,22 @@ @Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class Funding { - @Id - @GeneratedValue - @UuidGenerator - @Column(name = "id", nullable = false) - private String id; - - @ManyToOne - @JoinColumn(name = "organization_id") - private Organization organization; - - @ManyToOne - @JoinColumn(name = "service_id") - private Service service; - - @Column(name = "source") - private String source; - - @OneToMany - @JoinColumn(name = "link_id") - private List attributes; - - @OneToMany - @JoinColumn(name = "resource_id") - private List metadata; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; + + @Column(name = "source") + private String source; + + @OneToMany + @JoinColumn(name = "link_id") + private List attributes = new ArrayList<>(); + + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "resource_id") + private List metadata = new ArrayList<>(); } diff --git a/src/main/java/com/sarapis/orservice/entity/Language.java b/src/main/java/com/sarapis/orservice/entity/Language.java index 2d73e20..523813b 100644 --- a/src/main/java/com/sarapis/orservice/entity/Language.java +++ b/src/main/java/com/sarapis/orservice/entity/Language.java @@ -1,14 +1,10 @@ package com.sarapis.orservice.entity; -import com.sarapis.orservice.entity.core.Location; -import com.sarapis.orservice.entity.core.Service; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; import java.util.List; @Entity @@ -17,39 +13,28 @@ @Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class Language { - @Id - @GeneratedValue - @UuidGenerator - @Column(name = "id", nullable = false) - private String id; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; - @ManyToOne - @JoinColumn(name = "service_id") - private Service service; + @Column(name = "name") + private String name; - @ManyToOne - @JoinColumn(name = "location_id") - private Location location; + @Column(name = "code") + private String code; - @ManyToOne - @JoinColumn(name = "phone_id") - private Phone phone; + @Column(name = "note") + private String note; - @Column(name = "name") - private String name; + @OneToMany + @JoinColumn(name = "link_id") + private List attributes = new ArrayList<>(); - @Column(name = "code") - private String code; - - @Column(name = "note") - private String note; - - @OneToMany - @JoinColumn(name = "link_id") - private List attributes; - - @OneToMany - @JoinColumn(name = "resource_id") - private List metadata; + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "resource_id") + private List metadata = new ArrayList<>(); } diff --git a/src/main/java/com/sarapis/orservice/entity/MetaTableDescription.java b/src/main/java/com/sarapis/orservice/entity/MetaTableDescription.java index c02130b..79f7882 100644 --- a/src/main/java/com/sarapis/orservice/entity/MetaTableDescription.java +++ b/src/main/java/com/sarapis/orservice/entity/MetaTableDescription.java @@ -1,12 +1,10 @@ package com.sarapis.orservice.entity; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; import java.util.List; @Entity @@ -15,27 +13,28 @@ @Getter @NoArgsConstructor @AllArgsConstructor +@Builder public class MetaTableDescription { - @Id - @GeneratedValue - @UuidGenerator - @Column(name = "id", nullable = false) - private String id; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; - @Column(name = "name") - private String name; + @Column(name = "name") + private String name; - @Column(name = "language") - private String language; + @Column(name = "language") + private String language; - @Column(name = "character_set") - private String characterSet; + @Column(name = "character_set") + private String characterSet; - @OneToMany - @JoinColumn(name = "link_id") - private List attributes; + @OneToMany + @JoinColumn(name = "link_id") + private List attributes = new ArrayList<>(); - @OneToMany - @JoinColumn(name = "resource_id") - private List metadata; + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "resource_id") + private List metadata = new ArrayList<>(); } diff --git a/src/main/java/com/sarapis/orservice/entity/Metadata.java b/src/main/java/com/sarapis/orservice/entity/Metadata.java index 748f689..12b94c4 100644 --- a/src/main/java/com/sarapis/orservice/entity/Metadata.java +++ b/src/main/java/com/sarapis/orservice/entity/Metadata.java @@ -1,10 +1,7 @@ package com.sarapis.orservice.entity; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; import org.hibernate.annotations.UuidGenerator; import java.time.LocalDate; @@ -15,36 +12,33 @@ @Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class Metadata { - @Id - @GeneratedValue - @UuidGenerator - @Column(name = "id", nullable = false) - private String id; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; - // FK Property - @Column(name = "resource_id") - private String resourceId; + @Enumerated(EnumType.STRING) + @Column(name = "resource_type") + private ResourceType resourceType; - @Enumerated(EnumType.STRING) - @Column(name = "resource_type") - private ResourceType resourceType; + @Column(name = "last_action_date", nullable = false) + private LocalDate lastActionDate; - @Column(name = "last_action_date", nullable = false) - private LocalDate lastActionDate; + @Column(name = "last_action_type", nullable = false) + private String lastActionType; - @Column(name = "last_action_type", nullable = false) - private String lastActionType; + @Column(name = "field_name", nullable = false) + private String fieldName; - @Column(name = "field_name", nullable = false) - private String fieldName; + @Column(name = "previous_value", nullable = false) + private String previousValue; - @Column(name = "previous_value", nullable = false) - private String previousValue; + @Column(name = "replacement_value", nullable = false) + private String replacementValue; - @Column(name = "replacement_value", nullable = false) - private String replacementValue; - - @Column(name = "updated_by", nullable = false) - private String updatedBy; + @Column(name = "updated_by", nullable = false) + private String updatedBy; } diff --git a/src/main/java/com/sarapis/orservice/entity/OrganizationIdentifier.java b/src/main/java/com/sarapis/orservice/entity/OrganizationIdentifier.java index 4f8a8aa..caabf1c 100644 --- a/src/main/java/com/sarapis/orservice/entity/OrganizationIdentifier.java +++ b/src/main/java/com/sarapis/orservice/entity/OrganizationIdentifier.java @@ -1,13 +1,10 @@ package com.sarapis.orservice.entity; -import com.sarapis.orservice.entity.core.Organization; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; import java.util.List; @Entity @@ -16,31 +13,28 @@ @Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class OrganizationIdentifier { - @Id - @GeneratedValue - @UuidGenerator - @Column(name = "id", nullable = false) - private String id; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; - @ManyToOne - @JoinColumn(name = "organization_id") - private Organization organization; + @Column(name = "identifier_scheme") + private String identifierScheme; - @Column(name = "identifier_scheme") - private String identifierScheme; + @Column(name = "identifier_type", nullable = false) + private String identifierType; - @Column(name = "identifier_type", nullable = false) - private String identifierType; + @Column(name = "identifier", nullable = false) + private String identifier; - @Column(name = "identifier", nullable = false) - private String identifier; + @OneToMany + @JoinColumn(name = "link_id") + private List attributes = new ArrayList<>(); - @OneToMany - @JoinColumn(name = "link_id") - private List attributes; - - @OneToMany - @JoinColumn(name = "resource_id") - private List metadata; + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "resource_id") + private List metadata = new ArrayList<>(); } diff --git a/src/main/java/com/sarapis/orservice/entity/Phone.java b/src/main/java/com/sarapis/orservice/entity/Phone.java index 48fc17a..7df4bc6 100644 --- a/src/main/java/com/sarapis/orservice/entity/Phone.java +++ b/src/main/java/com/sarapis/orservice/entity/Phone.java @@ -1,15 +1,10 @@ package com.sarapis.orservice.entity; -import com.sarapis.orservice.entity.core.Location; -import com.sarapis.orservice.entity.core.Service; -import com.sarapis.orservice.entity.core.ServiceAtLocation; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; import java.util.List; @Entity @@ -18,50 +13,35 @@ @Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class Phone { - @Id - @GeneratedValue - @UuidGenerator - @Column(name = "id", nullable = false) - private String id; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; - @ManyToOne - @JoinColumn(name = "location_id") - private Location location; + @Column(name = "number", nullable = false) + private String number; - @ManyToOne - @JoinColumn(name = "service_id") - private Service service; + @Column(name = "extension") + private String extension; - @ManyToOne - @JoinColumn(name = "contact_id") - private Contact contact; + @Column(name = "type") + private String type; - @ManyToOne - @JoinColumn(name = "service_at_location_id") - private ServiceAtLocation serviceAtLocation; + @Column(name = "description") + private String description; - @Column(name = "number", nullable = false) - private String number; + @OneToMany + @JoinColumn(name = "phone_id") + private List languages = new ArrayList<>(); - @Column(name = "extension") - private String extension; + @OneToMany + @JoinColumn(name = "link_id") + private List attributes = new ArrayList<>(); - @Column(name = "type") - private String type; - - @Column(name = "description") - private String description; - - @OneToMany - @JoinColumn(name = "phone_id") - private List languages; - - @OneToMany - @JoinColumn(name = "link_id") - private List attributes; - - @OneToMany - @JoinColumn(name = "resource_id") - private List metadata; + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "resource_id") + private List metadata = new ArrayList<>(); } diff --git a/src/main/java/com/sarapis/orservice/entity/Program.java b/src/main/java/com/sarapis/orservice/entity/Program.java index 696b504..0ebc9da 100644 --- a/src/main/java/com/sarapis/orservice/entity/Program.java +++ b/src/main/java/com/sarapis/orservice/entity/Program.java @@ -1,13 +1,10 @@ package com.sarapis.orservice.entity; -import com.sarapis.orservice.entity.core.Organization; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; import java.util.List; @Entity @@ -16,31 +13,28 @@ @Setter @AllArgsConstructor @NoArgsConstructor +@Builder public class Program { - @Id - @GeneratedValue - @UuidGenerator - @Column(name = "id", nullable = false) - private String id; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; - @ManyToOne - @JoinColumn(name = "organization_id") - private Organization organization; + @Column(name = "name", nullable = false) + private String name; - @Column(name = "name", nullable = false) - private String name; + @Column(name = "alternate_name") + private String alternateName; - @Column(name = "alternate_name") - private String alternateName; + @Column(name = "description", nullable = false) + private String description; - @Column(name = "description", nullable = false) - private String description; + @OneToMany + @JoinColumn(name = "link_id") + private List attributes = new ArrayList<>(); - @OneToMany - @JoinColumn(name = "link_id") - private List attributes; - - @OneToMany - @JoinColumn(name = "resource_id") - private List metadata; + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "resource_id") + private List metadata = new ArrayList<>(); } diff --git a/src/main/java/com/sarapis/orservice/entity/RequiredDocument.java b/src/main/java/com/sarapis/orservice/entity/RequiredDocument.java index cf32e17..40421d4 100644 --- a/src/main/java/com/sarapis/orservice/entity/RequiredDocument.java +++ b/src/main/java/com/sarapis/orservice/entity/RequiredDocument.java @@ -1,13 +1,10 @@ package com.sarapis.orservice.entity; -import com.sarapis.orservice.entity.core.Service; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; import java.util.List; @Entity @@ -16,28 +13,25 @@ @Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class RequiredDocument { - @Id - @GeneratedValue - @UuidGenerator - @Column(name = "id", nullable = false) - private String id; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; - @ManyToOne - @JoinColumn(name = "service_id") - private Service service; + @Column(name = "document") + private String document; - @Column(name = "document") - private String document; + @Column(name = "uri") + private String uri; - @Column(name = "uri") - private String uri; + @OneToMany + @JoinColumn(name = "link_id") + private List attributes = new ArrayList<>(); - @OneToMany - @JoinColumn(name = "link_id") - private List attributes; - - @OneToMany - @JoinColumn(name = "resource_id") - private List metadata; + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "resource_id") + private List metadata = new ArrayList<>(); } diff --git a/src/main/java/com/sarapis/orservice/entity/Schedule.java b/src/main/java/com/sarapis/orservice/entity/Schedule.java index 9a033c4..3a9430a 100644 --- a/src/main/java/com/sarapis/orservice/entity/Schedule.java +++ b/src/main/java/com/sarapis/orservice/entity/Schedule.java @@ -1,17 +1,12 @@ package com.sarapis.orservice.entity; -import com.sarapis.orservice.entity.core.Location; -import com.sarapis.orservice.entity.core.Service; -import com.sarapis.orservice.entity.core.ServiceAtLocation; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; import org.hibernate.annotations.UuidGenerator; import java.sql.Date; import java.sql.Time; +import java.util.ArrayList; import java.util.List; @Entity @@ -20,89 +15,78 @@ @Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class Schedule { - @Id - @GeneratedValue - @UuidGenerator - @Column(name = "id", nullable = false) - private String id; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; - @ManyToOne - @JoinColumn(name = "service_id") - private Service service; + @Column(name = "valid_from") + private Date validFrom; - @ManyToOne - @JoinColumn(name = "location_id") - private Location location; + @Column(name = "valid_to") + private Date validTo; - @ManyToOne - @JoinColumn(name = "service_at_location_id") - private ServiceAtLocation serviceAtLocation; + @Column(name = "dtstart") + private Date dtStart; - @Column(name = "valid_from") - private Date validFrom; + @Column(name = "timezone") + private int timezone; - @Column(name = "valid_to") - private Date validTo; + @Column(name = "until") + private Date until; - @Column(name = "dtstart") - private Date dtStart; + @Column(name = "count") + private int count; - @Column(name = "timezone") - private int timezone; + @Enumerated(EnumType.STRING) + @Column(name = "wkst") + private WkSt wkst; - @Column(name = "until") - private Date until; + @Enumerated(EnumType.STRING) + @Column(name = "freq") + private Freq freq; - @Column(name = "count") - private int count; + @Column(name = "interval") + private int interval; - @Enumerated(EnumType.STRING) - @Column(name = "wkst") - private WkSt wkst; + @Column(name = "byday") + private String byday; - @Enumerated(EnumType.STRING) - @Column(name = "freq") - private Freq freq; + @Column(name = "byweekno") + private String byweekno; - @Column(name = "interval") - private int interval; + @Column(name = "bymonthday") + private String bymonthday; - @Column(name = "byday") - private String byday; + @Column(name = "byyearday") + private String byyearday; - @Column(name = "byweekno") - private String byweekno; + @Column(name = "description") + private String description; - @Column(name = "bymonthday") - private String bymonthday; + @Column(name = "opens_at") + private Time opensAt; - @Column(name = "byyearday") - private String byyearday; + @Column(name = "closes_at") + private Time closesAt; - @Column(name = "description") - private String description; + @Column(name = "schedule_link") + private String scheduleLink; - @Column(name = "opens_at") - private Time opensAt; + @Column(name = "attending_type") + private String attendingType; - @Column(name = "closes_at") - private Time closesAt; + @Column(name = "notes") + private String notes; - @Column(name = "schedule_link") - private String scheduleLink; + @OneToMany + @JoinColumn(name = "link_id") + private List attributes = new ArrayList<>(); - @Column(name = "attending_type") - private String attendingType; - - @Column(name = "notes") - private String notes; - - @OneToMany - @JoinColumn(name = "link_id") - private List attributes; - - @OneToMany - @JoinColumn(name = "resource_id") - private List metadata; + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "resource_id") + private List metadata = new ArrayList<>(); } diff --git a/src/main/java/com/sarapis/orservice/entity/ServiceArea.java b/src/main/java/com/sarapis/orservice/entity/ServiceArea.java index c2a1ad9..ad0b3e9 100644 --- a/src/main/java/com/sarapis/orservice/entity/ServiceArea.java +++ b/src/main/java/com/sarapis/orservice/entity/ServiceArea.java @@ -1,14 +1,10 @@ package com.sarapis.orservice.entity; -import com.sarapis.orservice.entity.core.Service; -import com.sarapis.orservice.entity.core.ServiceAtLocation; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; import java.util.List; @Entity @@ -17,42 +13,35 @@ @Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class ServiceArea { - @Id - @GeneratedValue - @UuidGenerator - @Column(name = "id", nullable = false) - private String id; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; - @ManyToOne - @JoinColumn(name = "service_id") - private Service service; + @Column(name = "name") + private String name; - @ManyToOne - @JoinColumn(name = "service_at_location_id") - private ServiceAtLocation serviceAtLocation; + @Column(name = "description") + private String description; - @Column(name = "name") - private String name; + @Column(name = "extent") + private String extent; - @Column(name = "description") - private String description; + @Enumerated(EnumType.STRING) + @Column(name = "extent_type") + private ExtentType extentType; - @Column(name = "extent") - private String extent; + @Column(name = "uri") + private String uri; - @Enumerated(EnumType.STRING) - @Column(name = "extent_type") - private ExtentType extentType; + @OneToMany + @JoinColumn(name = "link_id") + private List attributes = new ArrayList<>(); - @Column(name = "uri") - private String uri; - - @OneToMany - @JoinColumn(name = "link_id") - private List attributes; - - @OneToMany - @JoinColumn(name = "resource_id") - private List metadata; + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "resource_id") + private List metadata = new ArrayList<>(); } diff --git a/src/main/java/com/sarapis/orservice/entity/ServiceCapacity.java b/src/main/java/com/sarapis/orservice/entity/ServiceCapacity.java index 3154dab..f350cd7 100644 --- a/src/main/java/com/sarapis/orservice/entity/ServiceCapacity.java +++ b/src/main/java/com/sarapis/orservice/entity/ServiceCapacity.java @@ -1,14 +1,11 @@ package com.sarapis.orservice.entity; -import com.sarapis.orservice.entity.core.Service; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; import org.hibernate.annotations.UuidGenerator; import java.time.LocalDate; +import java.util.ArrayList; import java.util.List; @Entity @@ -17,6 +14,7 @@ @Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class ServiceCapacity { @Id @GeneratedValue @@ -24,10 +22,6 @@ public class ServiceCapacity { @Column(name = "id", nullable = false) private String id; - @ManyToOne - @JoinColumn(name = "service_id") - private Service service; - @OneToOne @JoinColumn(name = "unit_id", nullable = false) private Unit unit; @@ -46,9 +40,9 @@ public class ServiceCapacity { @OneToMany @JoinColumn(name = "link_id") - private List attributes; + private List attributes = new ArrayList<>(); - @OneToMany + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "resource_id") - private List metadata; + private List metadata = new ArrayList<>(); } diff --git a/src/main/java/com/sarapis/orservice/entity/Taxonomy.java b/src/main/java/com/sarapis/orservice/entity/Taxonomy.java index beab69a..0cf8076 100644 --- a/src/main/java/com/sarapis/orservice/entity/Taxonomy.java +++ b/src/main/java/com/sarapis/orservice/entity/Taxonomy.java @@ -1,12 +1,10 @@ package com.sarapis.orservice.entity; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; import java.util.List; @Entity @@ -15,26 +13,27 @@ @Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class Taxonomy { - @Id - @GeneratedValue - @UuidGenerator - @Column(name = "id", nullable = false) - private String id; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; - @Column(name = "name", nullable = false) - private String name; + @Column(name = "name", nullable = false) + private String name; - @Column(name = "description", nullable = false) - private String description; + @Column(name = "description", nullable = false) + private String description; - @Column(name = "uri") - private String uri; + @Column(name = "uri") + private String uri; - @Column(name = "version") - private String version; + @Column(name = "version") + private String version; - @OneToMany - @JoinColumn(name = "resource_id") - private List metadata; + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "resource_id") + private List metadata = new ArrayList<>(); } diff --git a/src/main/java/com/sarapis/orservice/entity/TaxonomyTerm.java b/src/main/java/com/sarapis/orservice/entity/TaxonomyTerm.java index 14628e6..5c96871 100644 --- a/src/main/java/com/sarapis/orservice/entity/TaxonomyTerm.java +++ b/src/main/java/com/sarapis/orservice/entity/TaxonomyTerm.java @@ -1,12 +1,10 @@ package com.sarapis.orservice.entity; import jakarta.persistence.*; -import lombok.Getter; -import lombok.Setter; -import lombok.NoArgsConstructor; -import lombok.AllArgsConstructor; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; import java.util.List; @Entity @@ -15,40 +13,41 @@ @Getter @NoArgsConstructor @AllArgsConstructor +@Builder public class TaxonomyTerm { - @Id - @GeneratedValue - @UuidGenerator - @Column(name = "id", nullable = false) - private String id; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; - @Column(name = "code") - private String code; + @Column(name = "code") + private String code; - @Column(name = "name", nullable = false) - private String name; + @Column(name = "name", nullable = false) + private String name; - @Column(name = "description", nullable = false) - private String description; + @Column(name = "description", nullable = false) + private String description; - @OneToOne - @JoinColumn(name = "parent_id") - private TaxonomyTerm parent; + @OneToOne + @JoinColumn(name = "parent_id") + private TaxonomyTerm parent; - @Column(name = "taxonomy") - private String taxonomyName; + @Column(name = "taxonomy") + private String taxonomyName; - @ManyToOne - @JoinColumn(name = "taxonomy_id") - private Taxonomy taxonomy; + @ManyToOne + @JoinColumn(name = "taxonomy_id") + private Taxonomy taxonomy; - @Column(name = "language") - private String language; + @Column(name = "language") + private String language; - @Column(name = "term_uri") - private String termUri; + @Column(name = "term_uri") + private String termUri; - @OneToMany - @JoinColumn(name = "resource_id") - private List metadata; + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "resource_id") + private List metadata = new ArrayList<>(); } diff --git a/src/main/java/com/sarapis/orservice/entity/Unit.java b/src/main/java/com/sarapis/orservice/entity/Unit.java index f8590d3..dcbad59 100644 --- a/src/main/java/com/sarapis/orservice/entity/Unit.java +++ b/src/main/java/com/sarapis/orservice/entity/Unit.java @@ -1,12 +1,10 @@ package com.sarapis.orservice.entity; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; import java.util.List; @Entity @@ -15,6 +13,7 @@ @Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class Unit { @Id @GeneratedValue @@ -36,9 +35,9 @@ public class Unit { @OneToMany @JoinColumn(name = "link_id") - private List attributes; + private List attributes = new ArrayList<>(); - @OneToMany + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "resource_id") - private List metadata; + private List metadata = new ArrayList<>(); } diff --git a/src/main/java/com/sarapis/orservice/entity/Url.java b/src/main/java/com/sarapis/orservice/entity/Url.java index a0b2113..5d42283 100644 --- a/src/main/java/com/sarapis/orservice/entity/Url.java +++ b/src/main/java/com/sarapis/orservice/entity/Url.java @@ -1,14 +1,10 @@ package com.sarapis.orservice.entity; -import com.sarapis.orservice.entity.core.Organization; -import com.sarapis.orservice.entity.core.Service; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; import java.util.List; @Entity @@ -17,28 +13,25 @@ @Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class Url { - @Id - @GeneratedValue - @UuidGenerator - @Column(name = "id", nullable = false) - private String id; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; - @Column(name = "label") - private String label; + @Column(name = "label") + private String label; - @Column(name = "url", nullable = false) - private String url; + @Column(name = "url", nullable = false) + private String url; - @ManyToOne - @JoinColumn(name = "organization_id") - private Organization organization; + @OneToMany + @JoinColumn(name = "link_id") + private List attributes = new ArrayList<>(); - @ManyToOne - @JoinColumn(name = "service_id") - private Service service; - - @OneToMany - @JoinColumn(name = "resource_id") - private List metadata; + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "resource_id") + private List metadata = new ArrayList<>(); } diff --git a/src/main/java/com/sarapis/orservice/entity/core/Location.java b/src/main/java/com/sarapis/orservice/entity/core/Location.java index 42b00ac..f940211 100644 --- a/src/main/java/com/sarapis/orservice/entity/core/Location.java +++ b/src/main/java/com/sarapis/orservice/entity/core/Location.java @@ -2,12 +2,10 @@ import com.sarapis.orservice.entity.*; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; import java.util.List; @Entity @@ -16,77 +14,74 @@ @Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class Location { - @Id - @GeneratedValue - @UuidGenerator - @Column(name = "id", nullable = false) - private String id; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; - @Enumerated(EnumType.STRING) - @Column(name = "location_type", nullable = false) - private LocationType locationType; + @Enumerated(EnumType.STRING) + @Column(name = "location_type", nullable = false) + private LocationType locationType; - @Column(name = "url") - private String url; + @Column(name = "url") + private String url; - @ManyToOne - @JoinColumn(name = "organization_id") - private Organization organization; + @Column(name = "name") + private String name; - @Column(name = "name") - private String name; + @Column(name = "alternate_name") + private String alternateName; - @Column(name = "alternate_name") - private String alternateName; + @Column(name = "description") + private String description; - @Column(name = "description") - private String description; + @Column(name = "transportation") + private String transportation; - @Column(name = "transportation") - private String transportation; + @Column(name = "latitude") + private int latitude; - @Column(name = "latitude") - private int latitude; + @Column(name = "longitude") + private int longitude; - @Column(name = "longitude") - private int longitude; + @Column(name = "external_identifier") + private String externalIdentifier; - @Column(name = "external_identifier") - private String externalIdentifier; + @Column(name = "external_identifier_type") + private String externalIdentifierType; - @Column(name = "external_identifier_type") - private String externalIdentifierType; + @OneToMany + @JoinColumn(name = "location_id") + private List languages = new ArrayList<>(); - @OneToMany - @JoinColumn(name = "location_id") - private List languages; + @OneToMany + @JoinColumn(name = "location_id") + private List
addresses = new ArrayList<>(); - @OneToMany - @JoinColumn(name = "location_id") - private List
addresses; + @OneToMany + @JoinColumn(name = "location_id") + private List contacts = new ArrayList<>(); - @OneToMany - @JoinColumn(name = "location_id") - private List contacts; + @OneToMany + @JoinColumn(name = "location_id") + private List accessibility = new ArrayList<>(); - @OneToMany - @JoinColumn(name = "location_id") - private List accessibility; + @OneToMany + @JoinColumn(name = "location_id") + private List phones = new ArrayList<>(); - @OneToMany - @JoinColumn(name = "location_id") - private List phones; + @OneToMany + @JoinColumn(name = "location_id") + private List schedules = new ArrayList<>(); - @OneToMany - @JoinColumn(name = "location_id") - private List schedules; + @OneToMany + @JoinColumn(name = "link_id") + private List attributes = new ArrayList<>(); - @OneToMany - @JoinColumn(name = "link_id") - private List attributes; - - @OneToMany - @JoinColumn(name = "resource_id") - private List metadata; + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "resource_id") + private List metadata = new ArrayList<>(); } diff --git a/src/main/java/com/sarapis/orservice/entity/core/Organization.java b/src/main/java/com/sarapis/orservice/entity/core/Organization.java index 2b938a9..bf5b8e4 100644 --- a/src/main/java/com/sarapis/orservice/entity/core/Organization.java +++ b/src/main/java/com/sarapis/orservice/entity/core/Organization.java @@ -6,6 +6,7 @@ import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; import java.util.List; @Entity @@ -16,101 +17,101 @@ @NoArgsConstructor @Builder public class Organization { - @Id - @GeneratedValue - @UuidGenerator - @Column(name = "id", nullable = false) - private String id; - - @Column(name = "name", nullable = false) - private String name; - - @Column(name = "alternate_name") - private String alternateName; - - @Column(name = "description", nullable = false) - private String description; - - @Column(name = "email") - private String email; - - @Column(name = "website") - private String website; - - @OneToMany - @JoinColumn(name = "organization_id") - private List additionalWebsites; - - // Deprecated - @Column(name = "tax_status") - private String taxStatus; - - // Deprecated - @Column(name = "tax_id") - private String taxId; - - @Column(name = "year_incorporated") - private int yearIncorporated; - - @Column(name = "legal_status") - private String legalStatus; - - @Column(name = "logo") - private String logo; - - @Column(name = "uri") - private String uri; - - @OneToOne - @JoinColumn(name = "parent_organization_id") - private Organization parentOrganization; - - @OneToMany - @JoinColumn(name = "organization_id") - private List funding; - - @OneToMany - @JoinColumn(name = "organization_id") - private List contacts; - - @OneToMany - @JoinColumn(name = "organization_id") - private List phones; - - @OneToMany - @JoinColumn(name = "organization_id") - private List locations; - - @OneToMany - @JoinColumn(name = "organization_id") - private List programs; - - @OneToMany - @JoinColumn(name = "organization_id") - private List organizationIdentifiers; - - @OneToMany - @JoinColumn(name = "link_id") - private List attributes; - - @OneToMany - @JoinColumn(name = "resource_id") - private List metadata; - - public OrganizationDTO toDTO() { - return OrganizationDTO.builder() - .id(id) - .name(name) - .alternateName(alternateName) - .description(description) - .email(email) - .website(website) - .additionalWebsites(additionalWebsites) - .yearIncorporated(yearIncorporated) - .legalStatus(legalStatus) - .logo(logo) - .uri(uri) - .parentOrganization(parentOrganization) - .build(); - } + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; + + @Column(name = "name", nullable = false) + private String name; + + @Column(name = "alternate_name") + private String alternateName; + + @Column(name = "description", nullable = false) + private String description; + + @Column(name = "email") + private String email; + + @Column(name = "website") + private String website; + + @OneToMany + @JoinColumn(name = "organization_id") + private List additionalWebsites = new ArrayList<>(); + + // Deprecated + @Column(name = "tax_status") + private String taxStatus; + + // Deprecated + @Column(name = "tax_id") + private String taxId; + + @Column(name = "year_incorporated") + private int yearIncorporated; + + @Column(name = "legal_status") + private String legalStatus; + + @Column(name = "logo") + private String logo; + + @Column(name = "uri") + private String uri; + + @OneToOne + @JoinColumn(name = "parent_organization_id") + private Organization parentOrganization; + + @OneToMany + @JoinColumn(name = "organization_id") + private List funding = new ArrayList<>(); + + @OneToMany + @JoinColumn(name = "organization_id") + private List contacts = new ArrayList<>(); + + @OneToMany + @JoinColumn(name = "organization_id") + private List phones = new ArrayList<>(); + + @OneToMany + @JoinColumn(name = "organization_id") + private List locations = new ArrayList<>(); + + @OneToMany + @JoinColumn(name = "organization_id") + private List programs = new ArrayList<>(); + + @OneToMany + @JoinColumn(name = "organization_id") + private List organizationIdentifiers = new ArrayList<>(); + + @OneToMany + @JoinColumn(name = "link_id") + private List attributes = new ArrayList<>(); + + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "resource_id") + private List metadata = new ArrayList<>(); + + public OrganizationDTO toDTO() { + return OrganizationDTO.builder() + .id(id) + .name(name) + .alternateName(alternateName) + .description(description) + .email(email) + .website(website) + .additionalWebsites(additionalWebsites) + .yearIncorporated(yearIncorporated) + .legalStatus(legalStatus) + .logo(logo) + .uri(uri) + .parentOrganization(parentOrganization) + .build(); + } } diff --git a/src/main/java/com/sarapis/orservice/entity/core/Service.java b/src/main/java/com/sarapis/orservice/entity/core/Service.java index 71c9b86..7f4d5d2 100644 --- a/src/main/java/com/sarapis/orservice/entity/core/Service.java +++ b/src/main/java/com/sarapis/orservice/entity/core/Service.java @@ -2,13 +2,11 @@ import com.sarapis.orservice.entity.*; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; import org.hibernate.annotations.UuidGenerator; import java.time.LocalDate; +import java.util.ArrayList; import java.util.List; @Entity @@ -17,134 +15,135 @@ @Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class Service { - @Id - @GeneratedValue - @UuidGenerator - @Column(name = "id", nullable = false) - private String id; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; - @Column(name = "name", nullable = false) - private String name; + @Column(name = "name", nullable = false) + private String name; - @Column(name = "alternate_name") - private String alternateName; + @Column(name = "alternate_name") + private String alternateName; - @Column(name = "description") - private String description; + @Column(name = "description") + private String description; - @Column(name = "url") - private String url; + @Column(name = "url") + private String url; - @OneToMany - @JoinColumn(name = "service_id") - private List additionUrls; + @OneToMany + @JoinColumn(name = "service_id") + private List additionalUrls = new ArrayList<>(); - @Column(name = "email") - private String email; + @Column(name = "email") + private String email; - @Enumerated(EnumType.STRING) - @Column(name = "status", nullable = false) - private Status status; + @Enumerated(EnumType.STRING) + @Column(name = "status", nullable = false) + private Status status; - @Column(name = "interpretation_services") - private String interpretationServices; + @Column(name = "interpretation_services") + private String interpretationServices; - @Column(name = "application_process") - private String applicationProcess; + @Column(name = "application_process") + private String applicationProcess; - @Column(name = "fees_description") - private String feesDescription; + @Column(name = "fees_description") + private String feesDescription; - // Deprecated - @Column(name = "wait_time") - private String waitTime; + // Deprecated + @Column(name = "wait_time") + private String waitTime; - // Deprecated - @Column(name = "fees") - private String fees; + // Deprecated + @Column(name = "fees") + private String fees; - @Column(name = "accreditations") - private String accreditations; + @Column(name = "accreditations") + private String accreditations; - @Column(name = "eligibility_description") - private String eligibilityDescription; + @Column(name = "eligibility_description") + private String eligibilityDescription; - @Column(name = "minimum_age") - private int minimumAge; + @Column(name = "minimum_age") + private int minimumAge; - @Column(name = "maximum_age") - private int maximumAge; + @Column(name = "maximum_age") + private int maximumAge; - @Column(name = "assured_date") - private LocalDate assuredDate; + @Column(name = "assured_date") + private LocalDate assuredDate; - @Column(name = "assurer_email") - private String assurerEmail; + @Column(name = "assurer_email") + private String assurerEmail; - // Deprecated - @Column(name = "licenses") - private String licenses; + // Deprecated + @Column(name = "licenses") + private String licenses; - @Column(name = "alert") - private String alert; + @Column(name = "alert") + private String alert; - @Column(name = "last_modified") - private LocalDate lastModified; + @Column(name = "last_modified") + private LocalDate lastModified; - @OneToMany - @JoinColumn(name = "service_id") - private List phones; + @OneToMany + @JoinColumn(name = "service_id") + private List phones = new ArrayList<>(); - @OneToMany - @JoinColumn(name = "service_id") - private List schedules; + @OneToMany + @JoinColumn(name = "service_id") + private List schedules = new ArrayList<>(); - @OneToMany - @JoinColumn(name = "service_id") - private List serviceAreas; + @OneToMany + @JoinColumn(name = "service_id") + private List serviceAreas = new ArrayList<>(); - @OneToMany - @JoinColumn(name = "service_id") - private List serviceAtLocations; + @OneToMany + @JoinColumn(name = "service_id") + private List serviceAtLocations = new ArrayList<>(); - @OneToMany - @JoinColumn(name = "service_id") - private List languages; + @OneToMany + @JoinColumn(name = "service_id") + private List languages = new ArrayList<>(); - @OneToOne - @JoinColumn(name = "organization_id") - private Organization organization; + @ManyToOne + @JoinColumn(name = "organization_id") + private Organization organization; - @OneToMany - @JoinColumn(name = "service_id") - private List funding; + @OneToMany + @JoinColumn(name = "service_id") + private List funding = new ArrayList<>(); - @OneToMany - @JoinColumn(name = "service_id") - private List costOptions; + @OneToMany + @JoinColumn(name = "service_id") + private List costOptions = new ArrayList<>(); - @OneToOne - @JoinColumn(name = "program_id") - private Program program; + @ManyToOne + @JoinColumn(name = "program_id") + private Program program; - @OneToMany - @JoinColumn(name = "service_id") - private List requiredDocuments; + @OneToMany + @JoinColumn(name = "service_id") + private List requiredDocuments = new ArrayList<>(); - @OneToMany - @JoinColumn(name = "service_id") - private List contacts; + @OneToMany + @JoinColumn(name = "service_id") + private List contacts = new ArrayList<>(); - @OneToMany - @JoinColumn(name = "service_id") - private List capacities; + @OneToMany + @JoinColumn(name = "service_id") + private List capacities = new ArrayList<>(); - @OneToMany - @JoinColumn(name = "link_id") - private List attributes; + @OneToMany + @JoinColumn(name = "link_id") + private List attributes = new ArrayList<>(); - @OneToMany - @JoinColumn(name = "resource_id") - private List metadata; + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "resource_id") + private List metadata = new ArrayList<>(); } diff --git a/src/main/java/com/sarapis/orservice/entity/core/ServiceAtLocation.java b/src/main/java/com/sarapis/orservice/entity/core/ServiceAtLocation.java index 6c7f018..2c18934 100644 --- a/src/main/java/com/sarapis/orservice/entity/core/ServiceAtLocation.java +++ b/src/main/java/com/sarapis/orservice/entity/core/ServiceAtLocation.java @@ -8,6 +8,7 @@ import lombok.Setter; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; import java.util.List; @Entity @@ -17,44 +18,40 @@ @NoArgsConstructor @AllArgsConstructor public class ServiceAtLocation { - @Id - @GeneratedValue - @UuidGenerator - @Column(name = "id", nullable = false) - private String id; - - @ManyToOne - @JoinColumn(name = "service_id") - private Service service; - - @Column(name = "description") - private String description; - - @OneToMany - @JoinColumn(name = "service_at_location_id") - private List serviceAreas; - - @OneToMany - @JoinColumn(name = "service_at_location_id") - private List contacts; - - @OneToMany - @JoinColumn(name = "service_at_location_id") - private List phones; - - @OneToMany - @JoinColumn(name = "service_at_location_id") - private List schedules; - - @OneToOne - @JoinColumn(name = "location_id") - private Location location; - - @OneToMany - @JoinColumn(name = "link_id") - private List attributes; - - @OneToMany - @JoinColumn(name = "resource_id") - private List metadata; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; + + @Column(name = "description") + private String description; + + @OneToMany + @JoinColumn(name = "service_at_location_id") + private List serviceAreas = new ArrayList<>(); + + @OneToMany + @JoinColumn(name = "service_at_location_id") + private List contacts = new ArrayList<>(); + + @OneToMany + @JoinColumn(name = "service_at_location_id") + private List phones = new ArrayList<>(); + + @OneToMany + @JoinColumn(name = "service_at_location_id") + private List schedules = new ArrayList<>(); + + @OneToOne + @JoinColumn(name = "location_id") + private Location location; + + @OneToMany + @JoinColumn(name = "link_id") + private List attributes = new ArrayList<>(); + + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "resource_id") + private List metadata = new ArrayList<>(); } From 58ad1fbff1d5c7384aadaf449f84bcff61adaae8 Mon Sep 17 00:00:00 2001 From: ZhangTerrence Date: Fri, 22 Nov 2024 18:53:38 -0500 Subject: [PATCH 14/28] implemented dtos for all entities --- .../orservice/dto/AccessibilityDTO.java | 32 +++++++ .../com/sarapis/orservice/dto/AddressDTO.java | 45 +++++++++ .../sarapis/orservice/dto/AttributeDTO.java | 32 +++++++ .../com/sarapis/orservice/dto/ContactDTO.java | 36 +++++++ .../sarapis/orservice/dto/CostOptionDTO.java | 39 ++++++++ .../com/sarapis/orservice/dto/FundingDTO.java | 28 ++++++ .../sarapis/orservice/dto/LanguageDTO.java | 32 +++++++ .../sarapis/orservice/dto/LocationDTO.java | 59 ++++++++++++ .../dto/MetaTableDescriptionDTO.java | 32 +++++++ .../sarapis/orservice/dto/MetadataDTO.java | 36 +++++++ .../orservice/dto/OrganizationDTO.java | 86 ++++++++++------- .../dto/OrganizationIdentifierDTO.java | 32 +++++++ .../sarapis/orservice/dto/PaginationDTO.java | 55 ++++++----- .../com/sarapis/orservice/dto/PhoneDTO.java | 36 +++++++ .../com/sarapis/orservice/dto/ProgramDTO.java | 32 +++++++ .../orservice/dto/RequiredDocumentDTO.java | 30 ++++++ .../com/sarapis/orservice/dto/RootDTO.java | 6 +- .../sarapis/orservice/dto/ScheduleDTO.java | 68 ++++++++++++++ .../sarapis/orservice/dto/ServiceAreaDTO.java | 37 ++++++++ .../orservice/dto/ServiceAtLocationDTO.java | 39 ++++++-- .../orservice/dto/ServiceCapacityDTO.java | 37 ++++++++ .../com/sarapis/orservice/dto/ServiceDTO.java | 94 ++++++++++++++----- .../sarapis/orservice/dto/TaxonomyDTO.java | 26 +++-- .../orservice/dto/TaxonomyTermDTO.java | 37 ++++++-- .../com/sarapis/orservice/dto/UnitDTO.java | 34 +++++++ .../com/sarapis/orservice/dto/UrlDTO.java | 30 ++++++ .../orservice/entity/Accessibility.java | 12 +++ .../com/sarapis/orservice/entity/Address.java | 18 ++++ .../sarapis/orservice/entity/Attribute.java | 14 ++- .../com/sarapis/orservice/entity/Contact.java | 14 +++ .../sarapis/orservice/entity/CostOption.java | 15 +++ .../com/sarapis/orservice/entity/Funding.java | 10 ++ .../sarapis/orservice/entity/Language.java | 12 +++ .../entity/MetaTableDescription.java | 12 +++ .../sarapis/orservice/entity/Metadata.java | 14 +++ .../entity/OrganizationIdentifier.java | 12 +++ .../com/sarapis/orservice/entity/Phone.java | 14 +++ .../com/sarapis/orservice/entity/Program.java | 12 +++ .../orservice/entity/RequiredDocument.java | 11 +++ .../sarapis/orservice/entity/Schedule.java | 44 +++++++-- .../sarapis/orservice/entity/ServiceArea.java | 14 +++ .../orservice/entity/ServiceCapacity.java | 16 +++- .../sarapis/orservice/entity/Taxonomy.java | 12 +++ .../orservice/entity/TaxonomyTerm.java | 22 ++++- .../com/sarapis/orservice/entity/Unit.java | 13 +++ .../com/sarapis/orservice/entity/Url.java | 11 +++ .../orservice/entity/core/Location.java | 25 +++++ .../orservice/entity/core/Organization.java | 36 ++++--- .../orservice/entity/core/Service.java | 49 +++++++++- .../entity/core/ServiceAtLocation.java | 23 ++++- 50 files changed, 1334 insertions(+), 151 deletions(-) create mode 100644 src/main/java/com/sarapis/orservice/dto/AccessibilityDTO.java create mode 100644 src/main/java/com/sarapis/orservice/dto/AddressDTO.java create mode 100644 src/main/java/com/sarapis/orservice/dto/AttributeDTO.java create mode 100644 src/main/java/com/sarapis/orservice/dto/ContactDTO.java create mode 100644 src/main/java/com/sarapis/orservice/dto/CostOptionDTO.java create mode 100644 src/main/java/com/sarapis/orservice/dto/FundingDTO.java create mode 100644 src/main/java/com/sarapis/orservice/dto/LanguageDTO.java create mode 100644 src/main/java/com/sarapis/orservice/dto/LocationDTO.java create mode 100644 src/main/java/com/sarapis/orservice/dto/MetaTableDescriptionDTO.java create mode 100644 src/main/java/com/sarapis/orservice/dto/MetadataDTO.java create mode 100644 src/main/java/com/sarapis/orservice/dto/OrganizationIdentifierDTO.java create mode 100644 src/main/java/com/sarapis/orservice/dto/PhoneDTO.java create mode 100644 src/main/java/com/sarapis/orservice/dto/ProgramDTO.java create mode 100644 src/main/java/com/sarapis/orservice/dto/RequiredDocumentDTO.java create mode 100644 src/main/java/com/sarapis/orservice/dto/ScheduleDTO.java create mode 100644 src/main/java/com/sarapis/orservice/dto/ServiceAreaDTO.java create mode 100644 src/main/java/com/sarapis/orservice/dto/ServiceCapacityDTO.java create mode 100644 src/main/java/com/sarapis/orservice/dto/UnitDTO.java create mode 100644 src/main/java/com/sarapis/orservice/dto/UrlDTO.java diff --git a/src/main/java/com/sarapis/orservice/dto/AccessibilityDTO.java b/src/main/java/com/sarapis/orservice/dto/AccessibilityDTO.java new file mode 100644 index 0000000..50596e3 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/AccessibilityDTO.java @@ -0,0 +1,32 @@ +package com.sarapis.orservice.dto; + +import com.sarapis.orservice.entity.Accessibility; +import lombok.*; + +import java.util.ArrayList; +import java.util.List; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class AccessibilityDTO { + private String id; + private String description; + private String details; + private String url; + private List attributes = new ArrayList<>(); + private List metadata = new ArrayList<>(); + + public Accessibility toEntity() { + return Accessibility.builder() + .id(this.id) + .description(this.description) + .details(this.details) + .url(this.url) + .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) + .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) + .build(); + } +} diff --git a/src/main/java/com/sarapis/orservice/dto/AddressDTO.java b/src/main/java/com/sarapis/orservice/dto/AddressDTO.java new file mode 100644 index 0000000..300a9da --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/AddressDTO.java @@ -0,0 +1,45 @@ +package com.sarapis.orservice.dto; + +import com.sarapis.orservice.entity.Address; +import com.sarapis.orservice.entity.AddressType; +import lombok.*; + +import java.util.ArrayList; +import java.util.List; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class AddressDTO { + private String id; + private String attention; + private String address_1; + private String address_2; + private String city; + private String region; + private String stateProvince; + private String postalCode; + private String country; + private AddressType addressType; + private List attributes = new ArrayList<>(); + private List metadata = new ArrayList<>(); + + public Address toEntity() { + return Address.builder() + .id(this.id) + .attention(this.attention) + .address_1(this.address_1) + .address_2(this.address_2) + .city(this.city) + .region(this.region) + .stateProvince(this.stateProvince) + .postalCode(this.postalCode) + .country(this.country) + .addressType(this.addressType) + .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) + .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) + .build(); + } +} diff --git a/src/main/java/com/sarapis/orservice/dto/AttributeDTO.java b/src/main/java/com/sarapis/orservice/dto/AttributeDTO.java new file mode 100644 index 0000000..6b7dee6 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/AttributeDTO.java @@ -0,0 +1,32 @@ +package com.sarapis.orservice.dto; + +import com.sarapis.orservice.entity.Attribute; +import lombok.*; + +import java.util.ArrayList; +import java.util.List; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class AttributeDTO { + private String id; + private String linkEntity; + private String value; + private TaxonomyTermDTO taxonomyTerm = null; + private List metadata = new ArrayList<>(); + private String label; + + public Attribute toEntity() { + return Attribute.builder() + .id(this.id) + .linkEntity(this.linkEntity) + .value(this.value) + .taxonomyTerm(this.taxonomyTerm != null ? this.taxonomyTerm.toEntity() : null) + .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) + .label(this.label) + .build(); + } +} diff --git a/src/main/java/com/sarapis/orservice/dto/ContactDTO.java b/src/main/java/com/sarapis/orservice/dto/ContactDTO.java new file mode 100644 index 0000000..46ae09e --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/ContactDTO.java @@ -0,0 +1,36 @@ +package com.sarapis.orservice.dto; + +import com.sarapis.orservice.entity.Contact; +import lombok.*; + +import java.util.ArrayList; +import java.util.List; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class ContactDTO { + private String id; + private String name; + private String title; + private String department; + private String email; + private List phones = new ArrayList<>(); + private List attributes = new ArrayList<>(); + private List metadata = new ArrayList<>(); + + public Contact toEntity() { + return Contact.builder() + .id(this.id) + .name(this.name) + .title(this.title) + .department(this.department) + .email(this.email) + .phones(this.phones.stream().map(PhoneDTO::toEntity).toList()) + .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) + .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) + .build(); + } +} diff --git a/src/main/java/com/sarapis/orservice/dto/CostOptionDTO.java b/src/main/java/com/sarapis/orservice/dto/CostOptionDTO.java new file mode 100644 index 0000000..877eeb7 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/CostOptionDTO.java @@ -0,0 +1,39 @@ +package com.sarapis.orservice.dto; + +import com.sarapis.orservice.entity.CostOption; +import lombok.*; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class CostOptionDTO { + private String id; + private LocalDate validFrom; + private LocalDate validTo; + private String option; + private String currency; + private int amount; + private String amountDescription; + private List attributes = new ArrayList<>(); + private List metadata = new ArrayList<>(); + + public CostOption toEntity() { + return CostOption.builder() + .id(this.id) + .validFrom(this.validFrom) + .validTo(this.validTo) + .option(this.option) + .currency(this.currency) + .amount(this.amount) + .amountDescription(this.amountDescription) + .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) + .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) + .build(); + } +} diff --git a/src/main/java/com/sarapis/orservice/dto/FundingDTO.java b/src/main/java/com/sarapis/orservice/dto/FundingDTO.java new file mode 100644 index 0000000..a565538 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/FundingDTO.java @@ -0,0 +1,28 @@ +package com.sarapis.orservice.dto; + +import com.sarapis.orservice.entity.Funding; +import lombok.*; + +import java.util.ArrayList; +import java.util.List; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class FundingDTO { + private String id; + private String source; + private List attributes = new ArrayList<>(); + private List metadata = new ArrayList<>(); + + public Funding toEntity() { + return Funding.builder() + .id(this.id) + .source(this.source) + .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) + .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) + .build(); + } +} diff --git a/src/main/java/com/sarapis/orservice/dto/LanguageDTO.java b/src/main/java/com/sarapis/orservice/dto/LanguageDTO.java new file mode 100644 index 0000000..3fe98e2 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/LanguageDTO.java @@ -0,0 +1,32 @@ +package com.sarapis.orservice.dto; + +import com.sarapis.orservice.entity.Language; +import lombok.*; + +import java.util.ArrayList; +import java.util.List; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class LanguageDTO { + private String id; + private String name; + private String code; + private String note; + private List attributes = new ArrayList<>(); + private List metadata = new ArrayList<>(); + + public Language toEntity() { + return Language.builder() + .id(this.id) + .name(this.name) + .code(this.code) + .note(this.note) + .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) + .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) + .build(); + } +} diff --git a/src/main/java/com/sarapis/orservice/dto/LocationDTO.java b/src/main/java/com/sarapis/orservice/dto/LocationDTO.java new file mode 100644 index 0000000..13b2c7a --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/LocationDTO.java @@ -0,0 +1,59 @@ +package com.sarapis.orservice.dto; + +import com.sarapis.orservice.entity.core.Location; +import com.sarapis.orservice.entity.core.LocationType; +import lombok.*; + +import java.util.ArrayList; +import java.util.List; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class LocationDTO { + private String id; + private LocationType locationType; + private String url; + private String name; + private String alternateName; + private String description; + private String transportation; + private int latitude; + private int longitude; + private String externalIdentifier; + private String externalIdentifierType; + private List languages = new ArrayList<>(); + private List addresses = new ArrayList<>(); + private List contacts = new ArrayList<>(); + private List accessibility = new ArrayList<>(); + private List phones = new ArrayList<>(); + private List schedules = new ArrayList<>(); + private List attributes = new ArrayList<>(); + private List metadata = new ArrayList<>(); + + public Location toEntity() { + return Location.builder() + .id(this.id) + .locationType(this.locationType) + .url(this.url) + .name(this.name) + .alternateName(this.alternateName) + .description(this.description) + .transportation(this.transportation) + .latitude(this.latitude) + .longitude(this.longitude) + .externalIdentifier(this.externalIdentifier) + .externalIdentifierType(this.externalIdentifierType) + .languages(this.languages.stream().map(LanguageDTO::toEntity).toList()) + .addresses(this.addresses.stream().map(AddressDTO::toEntity).toList()) + .contacts(this.contacts.stream().map(ContactDTO::toEntity).toList()) + .accessibility(this.accessibility.stream().map(AccessibilityDTO::toEntity).toList()) + .phones(this.phones.stream().map(PhoneDTO::toEntity).toList()) + .schedules(this.schedules.stream().map(ScheduleDTO::toEntity).toList()) + .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) + .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) + .build(); + } +} diff --git a/src/main/java/com/sarapis/orservice/dto/MetaTableDescriptionDTO.java b/src/main/java/com/sarapis/orservice/dto/MetaTableDescriptionDTO.java new file mode 100644 index 0000000..cce4358 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/MetaTableDescriptionDTO.java @@ -0,0 +1,32 @@ +package com.sarapis.orservice.dto; + +import com.sarapis.orservice.entity.MetaTableDescription; +import lombok.*; + +import java.util.ArrayList; +import java.util.List; + +@Setter +@Getter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class MetaTableDescriptionDTO { + private String id; + private String name; + private String language; + private String characterSet; + private List attributes = new ArrayList<>(); + private List metadata = new ArrayList<>(); + + public MetaTableDescription toEntity() { + return MetaTableDescription.builder() + .id(this.id) + .name(this.name) + .language(this.language) + .characterSet(this.characterSet) + .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) + .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) + .build(); + } +} diff --git a/src/main/java/com/sarapis/orservice/dto/MetadataDTO.java b/src/main/java/com/sarapis/orservice/dto/MetadataDTO.java new file mode 100644 index 0000000..c757637 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/MetadataDTO.java @@ -0,0 +1,36 @@ +package com.sarapis.orservice.dto; + +import com.sarapis.orservice.entity.Metadata; +import com.sarapis.orservice.entity.ResourceType; +import lombok.*; + +import java.time.LocalDate; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class MetadataDTO { + private String id; + private ResourceType resourceType; + private LocalDate lastActionDate; + private String lastActionType; + private String fieldName; + private String previousValue; + private String replacementValue; + private String updatedBy; + + public Metadata toEntity() { + return Metadata.builder() + .id(this.id) + .resourceType(this.resourceType) + .lastActionDate(this.lastActionDate) + .lastActionType(this.lastActionType) + .fieldName(this.fieldName) + .previousValue(this.previousValue) + .replacementValue(this.replacementValue) + .updatedBy(this.updatedBy) + .build(); + } +} diff --git a/src/main/java/com/sarapis/orservice/dto/OrganizationDTO.java b/src/main/java/com/sarapis/orservice/dto/OrganizationDTO.java index 1f346f9..b3cf4aa 100644 --- a/src/main/java/com/sarapis/orservice/dto/OrganizationDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/OrganizationDTO.java @@ -1,13 +1,10 @@ package com.sarapis.orservice.dto; -import com.sarapis.orservice.entity.Url; import com.sarapis.orservice.entity.core.Organization; +import lombok.*; + +import java.util.ArrayList; import java.util.List; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; @Getter @Setter @@ -15,34 +12,53 @@ @AllArgsConstructor @Builder public class OrganizationDTO { - private String id; - private String name; - private String alternateName; - private String description; - private String email; - private String website; - private List additionalWebsites; - private int yearIncorporated; - private String legalStatus; - private String logo; - private String uri; - private Organization parentOrganization; - - public Organization toEntity() { - return Organization.builder() - .id(this.id) - .name(this.name) - .alternateName(this.alternateName) - .description(this.description) - .email(this.email) - .website(this.website) - .additionalWebsites(this.additionalWebsites) - .yearIncorporated(this.yearIncorporated) - .legalStatus(this.legalStatus) - .logo(this.logo) - .uri(this.uri) - .parentOrganization(this.parentOrganization) - .build(); - } + private String id; + private String name; + private String alternateName; + private String description; + private String email; + private String website; + private List additionalWebsites = new ArrayList<>(); + private String taxStatus; + private String taxId; + private int yearIncorporated; + private String legalStatus; + private String logo; + private String uri; + private OrganizationDTO parentOrganization = null; + private List funding = new ArrayList<>(); + private List contacts = new ArrayList<>(); + private List phones = new ArrayList<>(); + private List locations = new ArrayList<>(); + private List programs = new ArrayList<>(); + private List organizationIdentifiers = new ArrayList<>(); + private List attributes = new ArrayList<>(); + private List metadata = new ArrayList<>(); + public Organization toEntity() { + return Organization.builder() + .id(this.id) + .name(this.name) + .alternateName(this.alternateName) + .description(this.description) + .email(this.email) + .website(this.website) + .additionalWebsites(this.additionalWebsites.stream().map(UrlDTO::toEntity).toList()) + .taxStatus(this.taxStatus) + .taxId(this.taxId) + .yearIncorporated(this.yearIncorporated) + .legalStatus(this.legalStatus) + .logo(this.logo) + .uri(this.uri) + .parentOrganization(this.parentOrganization != null ? this.parentOrganization.toEntity() : null) + .funding(this.funding.stream().map(FundingDTO::toEntity).toList()) + .contacts(this.contacts.stream().map(ContactDTO::toEntity).toList()) + .phones(this.phones.stream().map(PhoneDTO::toEntity).toList()) + .locations(this.locations.stream().map(LocationDTO::toEntity).toList()) + .programs(this.programs.stream().map(ProgramDTO::toEntity).toList()) + .organizationIdentifiers(this.organizationIdentifiers.stream().map(OrganizationIdentifierDTO::toEntity).toList()) + .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) + .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) + .build(); + } } diff --git a/src/main/java/com/sarapis/orservice/dto/OrganizationIdentifierDTO.java b/src/main/java/com/sarapis/orservice/dto/OrganizationIdentifierDTO.java new file mode 100644 index 0000000..feeab9c --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/OrganizationIdentifierDTO.java @@ -0,0 +1,32 @@ +package com.sarapis.orservice.dto; + +import com.sarapis.orservice.entity.OrganizationIdentifier; +import lombok.*; + +import java.util.ArrayList; +import java.util.List; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class OrganizationIdentifierDTO { + private String id; + private String identifierScheme; + private String identifierType; + private String identifier; + private List attributes = new ArrayList<>(); + private List metadata = new ArrayList<>(); + + public OrganizationIdentifier toEntity() { + return OrganizationIdentifier.builder() + .id(this.id) + .identifierScheme(this.identifierScheme) + .identifierType(this.identifierType) + .identifier(this.identifier) + .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) + .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) + .build(); + } +} diff --git a/src/main/java/com/sarapis/orservice/dto/PaginationDTO.java b/src/main/java/com/sarapis/orservice/dto/PaginationDTO.java index 0de0156..35d2e56 100644 --- a/src/main/java/com/sarapis/orservice/dto/PaginationDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/PaginationDTO.java @@ -1,37 +1,40 @@ package com.sarapis.orservice.dto; import java.util.List; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; + +import lombok.*; @Getter @Setter @AllArgsConstructor @NoArgsConstructor public class PaginationDTO { - private int totalItems; - private int totalPages; - private int pageNumber; - private int size; - private boolean firstPage; - private boolean lastPage; - private boolean empty; - private List contents; + private int totalItems; + private int totalPages; + private int pageNumber; + private int size; + private boolean firstPage; + private boolean lastPage; + private boolean empty; + private List contents; - public static PaginationDTO of(int totalItems, - int totalPages, int pageNumber, int size, - boolean firstPage, boolean lastPage, boolean empty, List contents) { - PaginationDTO paginationDTO = new PaginationDTO<>(); - paginationDTO.setTotalItems(totalItems); - paginationDTO.setTotalPages(totalPages); - paginationDTO.setPageNumber(pageNumber); - paginationDTO.setSize(size); - paginationDTO.setFirstPage(firstPage); - paginationDTO.setLastPage(lastPage); - paginationDTO.setEmpty(empty); - paginationDTO.setContents(contents); - return paginationDTO; - } + public static PaginationDTO of(int totalItems, + int totalPages, + int pageNumber, + int size, + boolean firstPage, + boolean lastPage, + boolean empty, + List contents) { + PaginationDTO paginationDTO = new PaginationDTO<>(); + paginationDTO.setTotalItems(totalItems); + paginationDTO.setTotalPages(totalPages); + paginationDTO.setPageNumber(pageNumber); + paginationDTO.setSize(size); + paginationDTO.setFirstPage(firstPage); + paginationDTO.setLastPage(lastPage); + paginationDTO.setEmpty(empty); + paginationDTO.setContents(contents); + return paginationDTO; + } } diff --git a/src/main/java/com/sarapis/orservice/dto/PhoneDTO.java b/src/main/java/com/sarapis/orservice/dto/PhoneDTO.java new file mode 100644 index 0000000..ee339e3 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/PhoneDTO.java @@ -0,0 +1,36 @@ +package com.sarapis.orservice.dto; + +import com.sarapis.orservice.entity.Phone; +import lombok.*; + +import java.util.ArrayList; +import java.util.List; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class PhoneDTO { + private String id; + private String number; + private String extension; + private String type; + private String description; + private List languages = new ArrayList<>(); + private List attributes = new ArrayList<>(); + private List metadata = new ArrayList<>(); + + public Phone toEntity() { + return Phone.builder() + .id(this.id) + .number(this.number) + .extension(this.extension) + .type(this.type) + .description(this.description) + .languages(this.languages.stream().map(LanguageDTO::toEntity).toList()) + .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) + .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) + .build(); + } +} diff --git a/src/main/java/com/sarapis/orservice/dto/ProgramDTO.java b/src/main/java/com/sarapis/orservice/dto/ProgramDTO.java new file mode 100644 index 0000000..4ede1eb --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/ProgramDTO.java @@ -0,0 +1,32 @@ +package com.sarapis.orservice.dto; + +import com.sarapis.orservice.entity.Program; +import lombok.*; + +import java.util.ArrayList; +import java.util.List; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class ProgramDTO { + private String id; + private String name; + private String alternateName; + private String description; + private List attributes = new ArrayList<>(); + private List metadata = new ArrayList<>(); + + public Program toEntity() { + return Program.builder() + .id(this.id) + .name(this.name) + .alternateName(this.alternateName) + .description(this.description) + .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) + .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) + .build(); + } +} diff --git a/src/main/java/com/sarapis/orservice/dto/RequiredDocumentDTO.java b/src/main/java/com/sarapis/orservice/dto/RequiredDocumentDTO.java new file mode 100644 index 0000000..aa43480 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/RequiredDocumentDTO.java @@ -0,0 +1,30 @@ +package com.sarapis.orservice.dto; + +import com.sarapis.orservice.entity.RequiredDocument; +import lombok.*; + +import java.util.ArrayList; +import java.util.List; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class RequiredDocumentDTO { + private String id; + private String document; + private String uri; + private List attributes = new ArrayList<>(); + private List metadata = new ArrayList<>(); + + public RequiredDocument toEntity() { + return RequiredDocument.builder() + .id(this.id) + .document(this.document) + .uri(this.uri) + .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) + .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) + .build(); + } +} diff --git a/src/main/java/com/sarapis/orservice/dto/RootDTO.java b/src/main/java/com/sarapis/orservice/dto/RootDTO.java index 32ed88f..faa573c 100644 --- a/src/main/java/com/sarapis/orservice/dto/RootDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/RootDTO.java @@ -1,10 +1,6 @@ package com.sarapis.orservice.dto; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; @Getter @Setter diff --git a/src/main/java/com/sarapis/orservice/dto/ScheduleDTO.java b/src/main/java/com/sarapis/orservice/dto/ScheduleDTO.java new file mode 100644 index 0000000..5105680 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/ScheduleDTO.java @@ -0,0 +1,68 @@ +package com.sarapis.orservice.dto; + +import com.sarapis.orservice.entity.Freq; +import com.sarapis.orservice.entity.Schedule; +import com.sarapis.orservice.entity.WkSt; +import lombok.*; + +import java.time.LocalDate; +import java.time.LocalTime; +import java.util.ArrayList; +import java.util.List; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class ScheduleDTO { + private String id; + private LocalDate validFrom; + private LocalDate validTo; + private LocalDate dtStart; + private int timezone; + private LocalDate until; + private int count; + private WkSt wkst; + private Freq freq; + private int interval; + private String byday; + private String byweekno; + private String bymonthday; + private String byyearday; + private String description; + private LocalTime opensAt; + private LocalTime closesAt; + private String scheduleLink; + private String attendingType; + private String notes; + private List attributes = new ArrayList<>(); + private List metadata = new ArrayList<>(); + + public Schedule toEntity() { + return Schedule.builder() + .id(this.id) + .validFrom(this.validFrom) + .validTo(this.validTo) + .dtStart(this.dtStart) + .timezone(this.timezone) + .until(this.until) + .count(this.count) + .wkst(this.wkst) + .freq(this.freq) + .interval(this.interval) + .byday(this.byday) + .byweekno(this.byweekno) + .bymonthday(this.bymonthday) + .byyearday(this.byyearday) + .description(this.description) + .opensAt(this.opensAt) + .closesAt(this.closesAt) + .scheduleLink(this.scheduleLink) + .attendingType(this.attendingType) + .notes(this.notes) + .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) + .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) + .build(); + } +} diff --git a/src/main/java/com/sarapis/orservice/dto/ServiceAreaDTO.java b/src/main/java/com/sarapis/orservice/dto/ServiceAreaDTO.java new file mode 100644 index 0000000..6d7cc1f --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/ServiceAreaDTO.java @@ -0,0 +1,37 @@ +package com.sarapis.orservice.dto; + +import com.sarapis.orservice.entity.ExtentType; +import com.sarapis.orservice.entity.ServiceArea; +import lombok.*; + +import java.util.ArrayList; +import java.util.List; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class ServiceAreaDTO { + private String id; + private String name; + private String description; + private String extent; + private ExtentType extentType; + private String uri; + private List attributes = new ArrayList<>(); + private List metadata = new ArrayList<>(); + + public ServiceArea toEntity() { + return ServiceArea.builder() + .id(this.id) + .name(this.name) + .description(this.description) + .extent(this.extent) + .extentType(this.extentType) + .uri(this.uri) + .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) + .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) + .build(); + } +} diff --git a/src/main/java/com/sarapis/orservice/dto/ServiceAtLocationDTO.java b/src/main/java/com/sarapis/orservice/dto/ServiceAtLocationDTO.java index e4727a7..df0a5c5 100644 --- a/src/main/java/com/sarapis/orservice/dto/ServiceAtLocationDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/ServiceAtLocationDTO.java @@ -1,19 +1,38 @@ package com.sarapis.orservice.dto; -import com.sarapis.orservice.entity.core.Location; -import com.sarapis.orservice.entity.core.Service; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import com.sarapis.orservice.entity.core.ServiceAtLocation; +import lombok.*; + +import java.util.ArrayList; +import java.util.List; -@NoArgsConstructor -@AllArgsConstructor @Getter @Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder public class ServiceAtLocationDTO { private String id; - private ServiceDTO service; - private Location location; private String description; + private List serviceAreas = new ArrayList<>(); + private List contacts = new ArrayList<>(); + private List phones = new ArrayList<>(); + private List schedules = new ArrayList<>(); + private LocationDTO location = null; + private List attributes = new ArrayList<>(); + private List metadata = new ArrayList<>(); + + public ServiceAtLocation toEntity() { + return ServiceAtLocation.builder() + .id(this.id) + .description(this.description) + .serviceAreas(this.serviceAreas.stream().map(ServiceAreaDTO::toEntity).toList()) + .contacts(this.contacts.stream().map(ContactDTO::toEntity).toList()) + .phones(this.phones.stream().map(PhoneDTO::toEntity).toList()) + .schedules(this.schedules.stream().map(ScheduleDTO::toEntity).toList()) + .location(this.location != null ? this.location.toEntity() : null) + .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) + .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) + .build(); + } } diff --git a/src/main/java/com/sarapis/orservice/dto/ServiceCapacityDTO.java b/src/main/java/com/sarapis/orservice/dto/ServiceCapacityDTO.java new file mode 100644 index 0000000..2a0dd5e --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/ServiceCapacityDTO.java @@ -0,0 +1,37 @@ +package com.sarapis.orservice.dto; + +import com.sarapis.orservice.entity.ServiceCapacity; +import lombok.*; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class ServiceCapacityDTO { + private String id; + private UnitDTO unit = null; + private int available; + private int maximum; + private String description; + private LocalDate updated; + private List attributes = new ArrayList<>(); + private List metadata = new ArrayList<>(); + + public ServiceCapacity toEntity() { + return ServiceCapacity.builder() + .id(this.id) + .unit(this.unit != null ? this.unit.toEntity() : null) + .available(this.available) + .maximum(this.maximum) + .description(this.description) + .updated(this.updated) + .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) + .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) + .build(); + } +} diff --git a/src/main/java/com/sarapis/orservice/dto/ServiceDTO.java b/src/main/java/com/sarapis/orservice/dto/ServiceDTO.java index 3d36874..b5e7e41 100644 --- a/src/main/java/com/sarapis/orservice/dto/ServiceDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/ServiceDTO.java @@ -1,27 +1,28 @@ package com.sarapis.orservice.dto; -import com.sarapis.orservice.entity.*; -import com.sarapis.orservice.entity.core.Organization; -import com.sarapis.orservice.entity.core.ServiceAtLocation; +import com.sarapis.orservice.entity.Attribute; +import com.sarapis.orservice.entity.Metadata; +import com.sarapis.orservice.entity.core.Service; import com.sarapis.orservice.entity.core.Status; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; +@Getter +@Setter @NoArgsConstructor @AllArgsConstructor -@Setter -@Getter +@Builder public class ServiceDTO { private String id; private String name; private String alternateName; private String description; private String url; - private List additionalUrls; + private List additionalUrls = new ArrayList<>(); private String email; private Status status; private String interpretationServices; @@ -33,23 +34,64 @@ public class ServiceDTO { private String eligibilityDescription; private int minimumAge; private int maximumAge; - private String assuredDate; + private LocalDate assuredDate; private String assurerEmail; private String licenses; private String alert; - private String lastModified; - private List phones; - private List schedules; - private List serviceAreas; - private List serviceAtLocations; - private List languages; - private Organization organization; - private List funding; - private List costOptions; - private Program program; - private List requiredDocuments; - private List contacts; - private List capacities; - private List attributes; - private List metadata; + private LocalDateTime lastModified; + private List phones = new ArrayList<>(); + private List schedules = new ArrayList<>(); + private List serviceAreas = new ArrayList<>(); + private List serviceAtLocations = new ArrayList<>(); + private List languages = new ArrayList<>(); + private OrganizationDTO organization = null; + private List funding = new ArrayList<>(); + private List costOptions = new ArrayList<>(); + private ProgramDTO program = null; + private List requiredDocuments = new ArrayList<>(); + private List contacts = new ArrayList<>(); + private List capacities = new ArrayList<>(); + private List attributes = new ArrayList<>(); + private List metadata = new ArrayList<>(); + + public Service toEntity() { + return Service.builder() + .id(this.id) + .name(this.name) + .alternateName(this.alternateName) + .description(this.description) + .url(this.url) + .additionalUrls(this.additionalUrls.stream().map(UrlDTO::toEntity).toList()) + .email(this.email) + .status(this.status) + .interpretationServices(this.interpretationServices) + .applicationProcess(this.applicationProcess) + .feesDescription(this.feesDescription) + .waitTime(this.waitTime) + .fees(this.fees) + .accreditations(this.accreditations) + .eligibilityDescription(this.eligibilityDescription) + .minimumAge(this.minimumAge) + .maximumAge(this.maximumAge) + .assuredDate(this.assuredDate) + .assurerEmail(this.assurerEmail) + .licenses(this.licenses) + .alert(this.alert) + .lastModified(this.lastModified) + .phones(this.phones.stream().map(PhoneDTO::toEntity).toList()) + .schedules(this.schedules.stream().map(ScheduleDTO::toEntity).toList()) + .serviceAreas(this.serviceAreas.stream().map(ServiceAreaDTO::toEntity).toList()) + .serviceAtLocations(this.serviceAtLocations.stream().map(ServiceAtLocationDTO::toEntity).toList()) + .languages(this.languages.stream().map(LanguageDTO::toEntity).toList()) + .organization(this.organization != null ? organization.toEntity() : null) + .funding(this.funding.stream().map(FundingDTO::toEntity).toList()) + .costOptions(this.costOptions.stream().map(CostOptionDTO::toEntity).toList()) + .program(this.program != null ? program.toEntity() : null) + .requiredDocuments(this.requiredDocuments.stream().map(RequiredDocumentDTO::toEntity).toList()) + .contacts(this.contacts.stream().map(ContactDTO::toEntity).toList()) + .capacities(this.capacities.stream().map(ServiceCapacityDTO::toEntity).toList()) + .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) + .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) + .build(); + } } diff --git a/src/main/java/com/sarapis/orservice/dto/TaxonomyDTO.java b/src/main/java/com/sarapis/orservice/dto/TaxonomyDTO.java index 3d6ed6b..06ddbfb 100644 --- a/src/main/java/com/sarapis/orservice/dto/TaxonomyDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/TaxonomyDTO.java @@ -1,18 +1,32 @@ package com.sarapis.orservice.dto; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import com.sarapis.orservice.entity.Taxonomy; +import lombok.*; +import java.util.ArrayList; +import java.util.List; + +@Getter +@Setter @NoArgsConstructor @AllArgsConstructor -@Setter -@Getter +@Builder public class TaxonomyDTO { private String id; private String name; private String description; private String uri; private String version; + private List metadata = new ArrayList<>(); + + public Taxonomy toEntity() { + return Taxonomy.builder() + .id(this.id) + .name(this.name) + .description(this.description) + .uri(this.uri) + .version(this.version) + .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) + .build(); + } } diff --git a/src/main/java/com/sarapis/orservice/dto/TaxonomyTermDTO.java b/src/main/java/com/sarapis/orservice/dto/TaxonomyTermDTO.java index e4eb97d..d733f0b 100644 --- a/src/main/java/com/sarapis/orservice/dto/TaxonomyTermDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/TaxonomyTermDTO.java @@ -1,21 +1,40 @@ package com.sarapis.orservice.dto; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import com.sarapis.orservice.entity.TaxonomyTerm; +import lombok.*; +import java.util.ArrayList; +import java.util.List; + +@Getter +@Setter @NoArgsConstructor @AllArgsConstructor -@Setter -@Getter +@Builder public class TaxonomyTermDTO { private String id; private String code; private String name; - private TaxonomyTermDTO parent; - private String taxonomyName; - private TaxonomyDTO taxonomy; + private String description; + private TaxonomyTermDTO parent = null; + private String taxonomy; + private TaxonomyDTO taxonomyDetail = null; private String language; private String termUri; + private List metadata = new ArrayList<>(); + + public TaxonomyTerm toEntity() { + return TaxonomyTerm.builder() + .id(this.id) + .code(this.code) + .name(this.name) + .description(this.description) + .parent(this.parent != null ? this.parent.toEntity() : null) + .taxonomy(this.taxonomy) + .taxonomyDetail(this.taxonomyDetail != null ? this.taxonomyDetail.toEntity() : null) + .language(this.language) + .termUri(this.termUri) + .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) + .build(); + } } diff --git a/src/main/java/com/sarapis/orservice/dto/UnitDTO.java b/src/main/java/com/sarapis/orservice/dto/UnitDTO.java new file mode 100644 index 0000000..a8bf6ab --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/UnitDTO.java @@ -0,0 +1,34 @@ +package com.sarapis.orservice.dto; + +import com.sarapis.orservice.entity.Unit; +import lombok.*; + +import java.util.ArrayList; +import java.util.List; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class UnitDTO { + private String id; + private String name; + private String scheme; + private String identifier; + private String uri; + private List attributes = new ArrayList<>(); + private List metadata = new ArrayList<>(); + + public Unit toEntity() { + return Unit.builder() + .id(this.id) + .name(this.name) + .scheme(this.scheme) + .identifier(this.identifier) + .uri(this.uri) + .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) + .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) + .build(); + } +} diff --git a/src/main/java/com/sarapis/orservice/dto/UrlDTO.java b/src/main/java/com/sarapis/orservice/dto/UrlDTO.java new file mode 100644 index 0000000..ef25789 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/UrlDTO.java @@ -0,0 +1,30 @@ +package com.sarapis.orservice.dto; + +import com.sarapis.orservice.entity.Url; +import lombok.*; + +import java.util.ArrayList; +import java.util.List; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class UrlDTO { + private String id; + private String label; + private String url; + private List attributes = new ArrayList<>(); + private List metadata = new ArrayList<>(); + + public Url toEntity() { + return Url.builder() + .id(this.id) + .label(this.label) + .url(this.url) + .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) + .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) + .build(); + } +} diff --git a/src/main/java/com/sarapis/orservice/entity/Accessibility.java b/src/main/java/com/sarapis/orservice/entity/Accessibility.java index 9fe3b75..8b73eea 100644 --- a/src/main/java/com/sarapis/orservice/entity/Accessibility.java +++ b/src/main/java/com/sarapis/orservice/entity/Accessibility.java @@ -1,5 +1,6 @@ package com.sarapis.orservice.entity; +import com.sarapis.orservice.dto.AccessibilityDTO; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.UuidGenerator; @@ -37,4 +38,15 @@ public class Accessibility { @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "resource_id") private List metadata = new ArrayList<>(); + + public AccessibilityDTO toDTO() { + return AccessibilityDTO.builder() + .id(this.id) + .description(this.description) + .details(this.details) + .url(this.url) + .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) + .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .build(); + } } diff --git a/src/main/java/com/sarapis/orservice/entity/Address.java b/src/main/java/com/sarapis/orservice/entity/Address.java index ff8865d..ae40ec6 100644 --- a/src/main/java/com/sarapis/orservice/entity/Address.java +++ b/src/main/java/com/sarapis/orservice/entity/Address.java @@ -1,5 +1,6 @@ package com.sarapis.orservice.entity; +import com.sarapis.orservice.dto.AddressDTO; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.UuidGenerator; @@ -56,4 +57,21 @@ public class Address { @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "resource_id") private List metadata = new ArrayList<>(); + + public AddressDTO toDTO() { + return AddressDTO.builder() + .id(this.id) + .attention(this.attention) + .address_1(this.address_1) + .address_2(this.address_2) + .city(this.city) + .region(this.region) + .stateProvince(this.stateProvince) + .postalCode(this.postalCode) + .country(this.country) + .addressType(this.addressType) + .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) + .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .build(); + } } diff --git a/src/main/java/com/sarapis/orservice/entity/Attribute.java b/src/main/java/com/sarapis/orservice/entity/Attribute.java index a3d14f5..6c156d5 100644 --- a/src/main/java/com/sarapis/orservice/entity/Attribute.java +++ b/src/main/java/com/sarapis/orservice/entity/Attribute.java @@ -1,5 +1,6 @@ package com.sarapis.orservice.entity; +import com.sarapis.orservice.dto.AttributeDTO; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.UuidGenerator; @@ -32,7 +33,7 @@ public class Attribute { @OneToOne @JoinColumn(name = "taxonomy_term_id") - private TaxonomyTerm taxonomyTerm; + private TaxonomyTerm taxonomyTerm = null; @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "resource_id") @@ -40,4 +41,15 @@ public class Attribute { @Column(name = "label") private String label; + + public AttributeDTO toDTO() { + return AttributeDTO.builder() + .id(this.id) + .linkEntity(this.linkEntity) + .value(this.value) + .taxonomyTerm(this.taxonomyTerm != null ? this.taxonomyTerm.toDTO() : null) + .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .label(this.label) + .build(); + } } diff --git a/src/main/java/com/sarapis/orservice/entity/Contact.java b/src/main/java/com/sarapis/orservice/entity/Contact.java index dbe7aa0..6ea8840 100644 --- a/src/main/java/com/sarapis/orservice/entity/Contact.java +++ b/src/main/java/com/sarapis/orservice/entity/Contact.java @@ -1,5 +1,6 @@ package com.sarapis.orservice.entity; +import com.sarapis.orservice.dto.ContactDTO; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.UuidGenerator; @@ -44,4 +45,17 @@ public class Contact { @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "resource_id") private List metadata = new ArrayList<>(); + + public ContactDTO toDTO() { + return ContactDTO.builder() + .id(this.id) + .name(this.name) + .title(this.title) + .department(this.department) + .email(this.email) + .phones(this.phones.stream().map(Phone::toDTO).toList()) + .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) + .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .build(); + } } diff --git a/src/main/java/com/sarapis/orservice/entity/CostOption.java b/src/main/java/com/sarapis/orservice/entity/CostOption.java index dd00eda..78fd7b6 100644 --- a/src/main/java/com/sarapis/orservice/entity/CostOption.java +++ b/src/main/java/com/sarapis/orservice/entity/CostOption.java @@ -1,5 +1,6 @@ package com.sarapis.orservice.entity; +import com.sarapis.orservice.dto.CostOptionDTO; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.UuidGenerator; @@ -47,4 +48,18 @@ public class CostOption { @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "resource_id") private List metadata = new ArrayList<>(); + + public CostOptionDTO toDTO() { + return CostOptionDTO.builder() + .id(this.id) + .validFrom(this.validFrom) + .validTo(this.validTo) + .option(this.option) + .currency(this.currency) + .amount(this.amount) + .amountDescription(this.amountDescription) + .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) + .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .build(); + } } diff --git a/src/main/java/com/sarapis/orservice/entity/Funding.java b/src/main/java/com/sarapis/orservice/entity/Funding.java index f4c70ff..10873b4 100644 --- a/src/main/java/com/sarapis/orservice/entity/Funding.java +++ b/src/main/java/com/sarapis/orservice/entity/Funding.java @@ -1,5 +1,6 @@ package com.sarapis.orservice.entity; +import com.sarapis.orservice.dto.FundingDTO; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.UuidGenerator; @@ -31,4 +32,13 @@ public class Funding { @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "resource_id") private List metadata = new ArrayList<>(); + + public FundingDTO toDTO() { + return FundingDTO.builder() + .id(this.id) + .source(this.source) + .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) + .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .build(); + } } diff --git a/src/main/java/com/sarapis/orservice/entity/Language.java b/src/main/java/com/sarapis/orservice/entity/Language.java index 523813b..b09da3f 100644 --- a/src/main/java/com/sarapis/orservice/entity/Language.java +++ b/src/main/java/com/sarapis/orservice/entity/Language.java @@ -1,5 +1,6 @@ package com.sarapis.orservice.entity; +import com.sarapis.orservice.dto.LanguageDTO; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.UuidGenerator; @@ -37,4 +38,15 @@ public class Language { @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "resource_id") private List metadata = new ArrayList<>(); + + public LanguageDTO toDTO() { + return LanguageDTO.builder() + .id(this.id) + .name(this.name) + .code(this.code) + .note(this.note) + .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) + .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .build(); + } } diff --git a/src/main/java/com/sarapis/orservice/entity/MetaTableDescription.java b/src/main/java/com/sarapis/orservice/entity/MetaTableDescription.java index 79f7882..bbe9f36 100644 --- a/src/main/java/com/sarapis/orservice/entity/MetaTableDescription.java +++ b/src/main/java/com/sarapis/orservice/entity/MetaTableDescription.java @@ -1,5 +1,6 @@ package com.sarapis.orservice.entity; +import com.sarapis.orservice.dto.MetaTableDescriptionDTO; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.UuidGenerator; @@ -37,4 +38,15 @@ public class MetaTableDescription { @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "resource_id") private List metadata = new ArrayList<>(); + + public MetaTableDescriptionDTO toDTO() { + return MetaTableDescriptionDTO.builder() + .id(this.id) + .name(this.name) + .language(this.language) + .characterSet(this.characterSet) + .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) + .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .build(); + } } diff --git a/src/main/java/com/sarapis/orservice/entity/Metadata.java b/src/main/java/com/sarapis/orservice/entity/Metadata.java index 12b94c4..d6b9ab9 100644 --- a/src/main/java/com/sarapis/orservice/entity/Metadata.java +++ b/src/main/java/com/sarapis/orservice/entity/Metadata.java @@ -1,5 +1,6 @@ package com.sarapis.orservice.entity; +import com.sarapis.orservice.dto.MetadataDTO; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.UuidGenerator; @@ -41,4 +42,17 @@ public class Metadata { @Column(name = "updated_by", nullable = false) private String updatedBy; + + public MetadataDTO toDTO() { + return MetadataDTO.builder() + .id(this.id) + .resourceType(this.resourceType) + .lastActionDate(this.lastActionDate) + .lastActionType(this.lastActionType) + .fieldName(this.fieldName) + .previousValue(this.previousValue) + .replacementValue(this.replacementValue) + .updatedBy(this.updatedBy) + .build(); + } } diff --git a/src/main/java/com/sarapis/orservice/entity/OrganizationIdentifier.java b/src/main/java/com/sarapis/orservice/entity/OrganizationIdentifier.java index caabf1c..4125351 100644 --- a/src/main/java/com/sarapis/orservice/entity/OrganizationIdentifier.java +++ b/src/main/java/com/sarapis/orservice/entity/OrganizationIdentifier.java @@ -1,5 +1,6 @@ package com.sarapis.orservice.entity; +import com.sarapis.orservice.dto.OrganizationIdentifierDTO; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.UuidGenerator; @@ -37,4 +38,15 @@ public class OrganizationIdentifier { @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "resource_id") private List metadata = new ArrayList<>(); + + public OrganizationIdentifierDTO toDTO() { + return OrganizationIdentifierDTO.builder() + .id(this.id) + .identifierScheme(this.identifierScheme) + .identifierType(this.identifierType) + .identifier(this.identifier) + .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) + .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .build(); + } } diff --git a/src/main/java/com/sarapis/orservice/entity/Phone.java b/src/main/java/com/sarapis/orservice/entity/Phone.java index 7df4bc6..fc5aa60 100644 --- a/src/main/java/com/sarapis/orservice/entity/Phone.java +++ b/src/main/java/com/sarapis/orservice/entity/Phone.java @@ -1,5 +1,6 @@ package com.sarapis.orservice.entity; +import com.sarapis.orservice.dto.PhoneDTO; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.UuidGenerator; @@ -44,4 +45,17 @@ public class Phone { @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "resource_id") private List metadata = new ArrayList<>(); + + public PhoneDTO toDTO() { + return PhoneDTO.builder() + .id(this.id) + .number(this.number) + .extension(this.extension) + .type(this.type) + .description(this.description) + .languages(this.languages.stream().map(Language::toDTO).toList()) + .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) + .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .build(); + } } diff --git a/src/main/java/com/sarapis/orservice/entity/Program.java b/src/main/java/com/sarapis/orservice/entity/Program.java index 0ebc9da..9ae363a 100644 --- a/src/main/java/com/sarapis/orservice/entity/Program.java +++ b/src/main/java/com/sarapis/orservice/entity/Program.java @@ -1,5 +1,6 @@ package com.sarapis.orservice.entity; +import com.sarapis.orservice.dto.ProgramDTO; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.UuidGenerator; @@ -37,4 +38,15 @@ public class Program { @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "resource_id") private List metadata = new ArrayList<>(); + + public ProgramDTO toDTO() { + return ProgramDTO.builder() + .id(this.id) + .name(this.name) + .alternateName(this.alternateName) + .description(this.description) + .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) + .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .build(); + } } diff --git a/src/main/java/com/sarapis/orservice/entity/RequiredDocument.java b/src/main/java/com/sarapis/orservice/entity/RequiredDocument.java index 40421d4..0d3936f 100644 --- a/src/main/java/com/sarapis/orservice/entity/RequiredDocument.java +++ b/src/main/java/com/sarapis/orservice/entity/RequiredDocument.java @@ -1,5 +1,6 @@ package com.sarapis.orservice.entity; +import com.sarapis.orservice.dto.RequiredDocumentDTO; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.UuidGenerator; @@ -34,4 +35,14 @@ public class RequiredDocument { @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "resource_id") private List metadata = new ArrayList<>(); + + public RequiredDocumentDTO toDTO() { + return RequiredDocumentDTO.builder() + .id(this.id) + .document(this.document) + .uri(this.uri) + .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) + .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .build(); + } } diff --git a/src/main/java/com/sarapis/orservice/entity/Schedule.java b/src/main/java/com/sarapis/orservice/entity/Schedule.java index 3a9430a..22ce882 100644 --- a/src/main/java/com/sarapis/orservice/entity/Schedule.java +++ b/src/main/java/com/sarapis/orservice/entity/Schedule.java @@ -1,11 +1,12 @@ package com.sarapis.orservice.entity; +import com.sarapis.orservice.dto.ScheduleDTO; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.UuidGenerator; -import java.sql.Date; -import java.sql.Time; +import java.time.LocalDate; +import java.time.LocalTime; import java.util.ArrayList; import java.util.List; @@ -24,19 +25,19 @@ public class Schedule { private String id; @Column(name = "valid_from") - private Date validFrom; + private LocalDate validFrom; @Column(name = "valid_to") - private Date validTo; + private LocalDate validTo; @Column(name = "dtstart") - private Date dtStart; + private LocalDate dtStart; @Column(name = "timezone") private int timezone; @Column(name = "until") - private Date until; + private LocalDate until; @Column(name = "count") private int count; @@ -68,10 +69,10 @@ public class Schedule { private String description; @Column(name = "opens_at") - private Time opensAt; + private LocalTime opensAt; @Column(name = "closes_at") - private Time closesAt; + private LocalTime closesAt; @Column(name = "schedule_link") private String scheduleLink; @@ -89,4 +90,31 @@ public class Schedule { @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "resource_id") private List metadata = new ArrayList<>(); + + public ScheduleDTO toDTO() { + return ScheduleDTO.builder() + .id(this.id) + .validFrom(this.validFrom) + .validTo(this.validTo) + .dtStart(this.dtStart) + .timezone(this.timezone) + .until(this.until) + .count(this.count) + .wkst(this.wkst) + .freq(this.freq) + .interval(this.interval) + .byday(this.byday) + .byweekno(this.byweekno) + .bymonthday(this.bymonthday) + .byyearday(this.byyearday) + .description(this.description) + .opensAt(this.opensAt) + .closesAt(this.closesAt) + .scheduleLink(this.scheduleLink) + .attendingType(this.attendingType) + .notes(this.notes) + .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) + .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .build(); + } } diff --git a/src/main/java/com/sarapis/orservice/entity/ServiceArea.java b/src/main/java/com/sarapis/orservice/entity/ServiceArea.java index ad0b3e9..53ccb75 100644 --- a/src/main/java/com/sarapis/orservice/entity/ServiceArea.java +++ b/src/main/java/com/sarapis/orservice/entity/ServiceArea.java @@ -1,5 +1,6 @@ package com.sarapis.orservice.entity; +import com.sarapis.orservice.dto.ServiceAreaDTO; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.UuidGenerator; @@ -44,4 +45,17 @@ public class ServiceArea { @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "resource_id") private List metadata = new ArrayList<>(); + + public ServiceAreaDTO toDTO() { + return ServiceAreaDTO.builder() + .id(this.id) + .name(this.name) + .description(this.description) + .extent(this.extent) + .extentType(this.extentType) + .uri(this.uri) + .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) + .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .build(); + } } diff --git a/src/main/java/com/sarapis/orservice/entity/ServiceCapacity.java b/src/main/java/com/sarapis/orservice/entity/ServiceCapacity.java index f350cd7..7bef604 100644 --- a/src/main/java/com/sarapis/orservice/entity/ServiceCapacity.java +++ b/src/main/java/com/sarapis/orservice/entity/ServiceCapacity.java @@ -1,5 +1,6 @@ package com.sarapis.orservice.entity; +import com.sarapis.orservice.dto.ServiceCapacityDTO; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.UuidGenerator; @@ -24,7 +25,7 @@ public class ServiceCapacity { @OneToOne @JoinColumn(name = "unit_id", nullable = false) - private Unit unit; + private Unit unit = null; @Column(name = "available", nullable = false) private int available; @@ -45,4 +46,17 @@ public class ServiceCapacity { @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "resource_id") private List metadata = new ArrayList<>(); + + public ServiceCapacityDTO toDTO() { + return ServiceCapacityDTO.builder() + .id(this.id) + .unit(this.unit != null ? this.unit.toDTO() : null) + .available(this.available) + .maximum(this.maximum) + .description(this.description) + .updated(this.updated) + .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) + .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .build(); + } } diff --git a/src/main/java/com/sarapis/orservice/entity/Taxonomy.java b/src/main/java/com/sarapis/orservice/entity/Taxonomy.java index 0cf8076..f8ca6bb 100644 --- a/src/main/java/com/sarapis/orservice/entity/Taxonomy.java +++ b/src/main/java/com/sarapis/orservice/entity/Taxonomy.java @@ -1,5 +1,6 @@ package com.sarapis.orservice.entity; +import com.sarapis.orservice.dto.TaxonomyDTO; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.UuidGenerator; @@ -36,4 +37,15 @@ public class Taxonomy { @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "resource_id") private List metadata = new ArrayList<>(); + + public TaxonomyDTO toDTO() { + return TaxonomyDTO.builder() + .id(this.id) + .name(this.name) + .description(this.description) + .uri(this.uri) + .version(this.version) + .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .build(); + } } diff --git a/src/main/java/com/sarapis/orservice/entity/TaxonomyTerm.java b/src/main/java/com/sarapis/orservice/entity/TaxonomyTerm.java index 5c96871..cca4772 100644 --- a/src/main/java/com/sarapis/orservice/entity/TaxonomyTerm.java +++ b/src/main/java/com/sarapis/orservice/entity/TaxonomyTerm.java @@ -1,5 +1,6 @@ package com.sarapis.orservice.entity; +import com.sarapis.orservice.dto.TaxonomyTermDTO; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.UuidGenerator; @@ -32,14 +33,14 @@ public class TaxonomyTerm { @OneToOne @JoinColumn(name = "parent_id") - private TaxonomyTerm parent; + private TaxonomyTerm parent = null; @Column(name = "taxonomy") - private String taxonomyName; + private String taxonomy; @ManyToOne @JoinColumn(name = "taxonomy_id") - private Taxonomy taxonomy; + private Taxonomy taxonomyDetail = null; @Column(name = "language") private String language; @@ -50,4 +51,19 @@ public class TaxonomyTerm { @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "resource_id") private List metadata = new ArrayList<>(); + + public TaxonomyTermDTO toDTO() { + return TaxonomyTermDTO.builder() + .id(this.id) + .code(this.code) + .name(this.name) + .description(this.description) + .parent(this.parent != null ? this.parent.toDTO() : null) + .taxonomy(this.taxonomy) + .taxonomyDetail(this.taxonomyDetail != null ? this.taxonomyDetail.toDTO() : null) + .language(this.language) + .termUri(this.termUri) + .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .build(); + } } diff --git a/src/main/java/com/sarapis/orservice/entity/Unit.java b/src/main/java/com/sarapis/orservice/entity/Unit.java index dcbad59..3cb3b6d 100644 --- a/src/main/java/com/sarapis/orservice/entity/Unit.java +++ b/src/main/java/com/sarapis/orservice/entity/Unit.java @@ -1,5 +1,6 @@ package com.sarapis.orservice.entity; +import com.sarapis.orservice.dto.UnitDTO; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.UuidGenerator; @@ -40,4 +41,16 @@ public class Unit { @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "resource_id") private List metadata = new ArrayList<>(); + + public UnitDTO toDTO() { + return UnitDTO.builder() + .id(this.id) + .name(this.name) + .scheme(this.scheme) + .identifier(this.identifier) + .uri(this.uri) + .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) + .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .build(); + } } diff --git a/src/main/java/com/sarapis/orservice/entity/Url.java b/src/main/java/com/sarapis/orservice/entity/Url.java index 5d42283..2b942bb 100644 --- a/src/main/java/com/sarapis/orservice/entity/Url.java +++ b/src/main/java/com/sarapis/orservice/entity/Url.java @@ -1,5 +1,6 @@ package com.sarapis.orservice.entity; +import com.sarapis.orservice.dto.UrlDTO; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.UuidGenerator; @@ -34,4 +35,14 @@ public class Url { @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "resource_id") private List metadata = new ArrayList<>(); + + public UrlDTO toDTO() { + return UrlDTO.builder() + .id(this.id) + .label(this.label) + .url(this.url) + .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) + .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .build(); + } } diff --git a/src/main/java/com/sarapis/orservice/entity/core/Location.java b/src/main/java/com/sarapis/orservice/entity/core/Location.java index f940211..a496efc 100644 --- a/src/main/java/com/sarapis/orservice/entity/core/Location.java +++ b/src/main/java/com/sarapis/orservice/entity/core/Location.java @@ -1,5 +1,6 @@ package com.sarapis.orservice.entity.core; +import com.sarapis.orservice.dto.LocationDTO; import com.sarapis.orservice.entity.*; import jakarta.persistence.*; import lombok.*; @@ -84,4 +85,28 @@ public class Location { @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "resource_id") private List metadata = new ArrayList<>(); + + public LocationDTO toDTO() { + return LocationDTO.builder() + .id(this.id) + .locationType(this.locationType) + .url(this.url) + .name(this.name) + .alternateName(this.alternateName) + .description(this.description) + .transportation(this.transportation) + .latitude(this.latitude) + .longitude(this.longitude) + .externalIdentifier(this.externalIdentifier) + .externalIdentifierType(this.externalIdentifierType) + .languages(this.languages.stream().map(Language::toDTO).toList()) + .addresses(this.addresses.stream().map(Address::toDTO).toList()) + .contacts(this.contacts.stream().map(Contact::toDTO).toList()) + .accessibility(this.accessibility.stream().map(Accessibility::toDTO).toList()) + .phones(this.phones.stream().map(Phone::toDTO).toList()) + .schedules(this.schedules.stream().map(Schedule::toDTO).toList()) + .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) + .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .build(); + } } diff --git a/src/main/java/com/sarapis/orservice/entity/core/Organization.java b/src/main/java/com/sarapis/orservice/entity/core/Organization.java index bf5b8e4..cb60aef 100644 --- a/src/main/java/com/sarapis/orservice/entity/core/Organization.java +++ b/src/main/java/com/sarapis/orservice/entity/core/Organization.java @@ -64,7 +64,7 @@ public class Organization { @OneToOne @JoinColumn(name = "parent_organization_id") - private Organization parentOrganization; + private Organization parentOrganization = null; @OneToMany @JoinColumn(name = "organization_id") @@ -100,18 +100,28 @@ public class Organization { public OrganizationDTO toDTO() { return OrganizationDTO.builder() - .id(id) - .name(name) - .alternateName(alternateName) - .description(description) - .email(email) - .website(website) - .additionalWebsites(additionalWebsites) - .yearIncorporated(yearIncorporated) - .legalStatus(legalStatus) - .logo(logo) - .uri(uri) - .parentOrganization(parentOrganization) + .id(this.id) + .name(this.name) + .alternateName(this.alternateName) + .description(this.description) + .email(this.email) + .website(this.website) + .additionalWebsites(this.additionalWebsites.stream().map(Url::toDTO).toList()) + .taxStatus(this.taxStatus) + .taxId(this.taxId) + .yearIncorporated(this.yearIncorporated) + .legalStatus(this.legalStatus) + .logo(this.logo) + .uri(this.uri) + .parentOrganization(this.parentOrganization != null ? this.parentOrganization.toDTO() : null) + .funding(this.funding.stream().map(Funding::toDTO).toList()) + .contacts(this.contacts.stream().map(Contact::toDTO).toList()) + .phones(this.phones.stream().map(Phone::toDTO).toList()) + .locations(this.locations.stream().map(Location::toDTO).toList()) + .programs(this.programs.stream().map(Program::toDTO).toList()) + .organizationIdentifiers(this.organizationIdentifiers.stream().map(OrganizationIdentifier::toDTO).toList()) + .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) + .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/entity/core/Service.java b/src/main/java/com/sarapis/orservice/entity/core/Service.java index 7f4d5d2..c2a5846 100644 --- a/src/main/java/com/sarapis/orservice/entity/core/Service.java +++ b/src/main/java/com/sarapis/orservice/entity/core/Service.java @@ -1,11 +1,13 @@ package com.sarapis.orservice.entity.core; +import com.sarapis.orservice.dto.ServiceDTO; import com.sarapis.orservice.entity.*; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.UuidGenerator; import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -89,7 +91,7 @@ public class Service { private String alert; @Column(name = "last_modified") - private LocalDate lastModified; + private LocalDateTime lastModified; @OneToMany @JoinColumn(name = "service_id") @@ -113,7 +115,7 @@ public class Service { @ManyToOne @JoinColumn(name = "organization_id") - private Organization organization; + private Organization organization = null; @OneToMany @JoinColumn(name = "service_id") @@ -125,7 +127,7 @@ public class Service { @ManyToOne @JoinColumn(name = "program_id") - private Program program; + private Program program = null; @OneToMany @JoinColumn(name = "service_id") @@ -146,4 +148,45 @@ public class Service { @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "resource_id") private List metadata = new ArrayList<>(); + + public ServiceDTO toDTO() { + return ServiceDTO.builder() + .id(this.id) + .name(this.name) + .alternateName(this.alternateName) + .description(this.description) + .url(this.url) + .additionalUrls(this.additionalUrls.stream().map(Url::toDTO).toList()) + .email(this.email) + .status(this.status) + .interpretationServices(this.interpretationServices) + .applicationProcess(this.applicationProcess) + .feesDescription(this.feesDescription) + .waitTime(this.waitTime) + .fees(this.fees) + .accreditations(this.accreditations) + .eligibilityDescription(this.eligibilityDescription) + .minimumAge(this.minimumAge) + .maximumAge(this.maximumAge) + .assuredDate(this.assuredDate) + .assurerEmail(this.assurerEmail) + .licenses(this.licenses) + .alert(this.alert) + .lastModified(this.lastModified) + .phones(this.phones.stream().map(Phone::toDTO).toList()) + .schedules(this.schedules.stream().map(Schedule::toDTO).toList()) + .serviceAreas(this.serviceAreas.stream().map(ServiceArea::toDTO).toList()) + .serviceAtLocations(this.serviceAtLocations.stream().map(ServiceAtLocation::toDTO).toList()) + .languages(this.languages.stream().map(Language::toDTO).toList()) + .organization(this.organization != null ? organization.toDTO() : null) + .funding(this.funding.stream().map(Funding::toDTO).toList()) + .costOptions(this.costOptions.stream().map(CostOption::toDTO).toList()) + .program(this.program != null ? program.toDTO() : null) + .requiredDocuments(this.requiredDocuments.stream().map(RequiredDocument::toDTO).toList()) + .contacts(this.contacts.stream().map(Contact::toDTO).toList()) + .capacities(this.capacities.stream().map(ServiceCapacity::toDTO).toList()) + .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) + .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .build(); + } } diff --git a/src/main/java/com/sarapis/orservice/entity/core/ServiceAtLocation.java b/src/main/java/com/sarapis/orservice/entity/core/ServiceAtLocation.java index 2c18934..df09011 100644 --- a/src/main/java/com/sarapis/orservice/entity/core/ServiceAtLocation.java +++ b/src/main/java/com/sarapis/orservice/entity/core/ServiceAtLocation.java @@ -1,11 +1,9 @@ package com.sarapis.orservice.entity.core; +import com.sarapis.orservice.dto.ServiceAtLocationDTO; import com.sarapis.orservice.entity.*; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; import org.hibernate.annotations.UuidGenerator; import java.util.ArrayList; @@ -17,6 +15,7 @@ @Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class ServiceAtLocation { @Id @GeneratedValue @@ -45,7 +44,7 @@ public class ServiceAtLocation { @OneToOne @JoinColumn(name = "location_id") - private Location location; + private Location location = null; @OneToMany @JoinColumn(name = "link_id") @@ -54,4 +53,18 @@ public class ServiceAtLocation { @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "resource_id") private List metadata = new ArrayList<>(); + + public ServiceAtLocationDTO toDTO() { + return ServiceAtLocationDTO.builder() + .id(this.id) + .description(this.description) + .serviceAreas(this.serviceAreas.stream().map(ServiceArea::toDTO).toList()) + .contacts(this.contacts.stream().map(Contact::toDTO).toList()) + .phones(this.phones.stream().map(Phone::toDTO).toList()) + .schedules(this.schedules.stream().map(Schedule::toDTO).toList()) + .location(this.location != null ? this.location.toDTO() : null) + .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) + .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .build(); + } } From cdb57023b6c2761f6cb82b44f0a80c11c4393c11 Mon Sep 17 00:00:00 2001 From: Butter - ThinkWin Date: Sat, 23 Nov 2024 11:33:42 -0500 Subject: [PATCH 15/28] Update address service impl --- .../orservice/service/AddressServiceImpl.java | 43 +++---------------- 1 file changed, 5 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/sarapis/orservice/service/AddressServiceImpl.java b/src/main/java/com/sarapis/orservice/service/AddressServiceImpl.java index f339088..a77ac91 100644 --- a/src/main/java/com/sarapis/orservice/service/AddressServiceImpl.java +++ b/src/main/java/com/sarapis/orservice/service/AddressServiceImpl.java @@ -12,38 +12,6 @@ public class AddressServiceImpl implements AddressService { private final AddressRepository addressRepository; - private AddressDTO mapToDTO(Address address) { - return new AddressDTO( - address.getId(), - address.getLocation(), - address.getAttention(), - address.getAddress_1(), - address.getAddress_2(), - address.getCity(), - address.getRegion(), - address.getStateProvince(), - address.getPostalCode(), - address.getCountry(), - address.getAddressType() - ); - } - - private Address mapToEntity(AddressDTO addressDTO) { - return new Address( - addressDTO.getId(), - addressDTO.getLocation(), - addressDTO.getAttention(), - addressDTO.getAddress_1(), - addressDTO.getAddress_2(), - addressDTO.getCity(), - addressDTO.getRegion(), - addressDTO.getStateProvince(), - addressDTO.getPostalCode(), - addressDTO.getCountry(), - addressDTO.getAddressType() - ); - } - public AddressServiceImpl(AddressRepository addressRepository) { this.addressRepository = addressRepository; } @@ -51,7 +19,7 @@ public AddressServiceImpl(AddressRepository addressRepository) { @Override public List getAllAddresses() { return this.addressRepository.findAll().stream() - .map(this::mapToDTO) + .map(Address::toDTO) .collect(Collectors.toList()); } @@ -59,14 +27,14 @@ public List getAllAddresses() { public AddressDTO getAddressById(String id) { Address address = this.addressRepository.findById(Long.parseLong(id)) .orElseThrow(() -> new RuntimeException("Address not found")); - return this.mapToDTO(address); + return address.toDTO(); } @Override public AddressDTO createAddress(AddressDTO addressDTO) { - Address address = this.mapToEntity(addressDTO); + Address address = addressDTO.toEntity(); Address savedAddress = this.addressRepository.save(address); - return this.mapToDTO(savedAddress); + return savedAddress.toDTO(); } @Override @@ -74,7 +42,6 @@ public AddressDTO updateAddress(String id, AddressDTO addressDTO) { Address oldAddress = this.addressRepository.findById(Long.parseLong(id)) .orElseThrow(() -> new RuntimeException("Address not found")); - oldAddress.setLocation(addressDTO.getLocation()); oldAddress.setAttention(addressDTO.getAttention()); oldAddress.setAddress_1(addressDTO.getAddress_1()); oldAddress.setAddress_2(addressDTO.getAddress_2()); @@ -86,7 +53,7 @@ public AddressDTO updateAddress(String id, AddressDTO addressDTO) { oldAddress.setAddressType(addressDTO.getAddressType()); Address updatedAddress = this.addressRepository.save(oldAddress); - return this.mapToDTO(updatedAddress); + return updatedAddress.toDTO(); } @Override From ff9da0f7a9cc69bd8b3893fa8f93b136dddcbe5e Mon Sep 17 00:00:00 2001 From: Butter - ThinkWin Date: Sat, 23 Nov 2024 11:47:24 -0500 Subject: [PATCH 16/28] Created Address Controller --- .../controller/AddressController.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/main/java/com/sarapis/orservice/controller/AddressController.java diff --git a/src/main/java/com/sarapis/orservice/controller/AddressController.java b/src/main/java/com/sarapis/orservice/controller/AddressController.java new file mode 100644 index 0000000..39bdf81 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/controller/AddressController.java @@ -0,0 +1,50 @@ +package com.sarapis.orservice.controller; + +import com.sarapis.orservice.dto.AddressDTO; +import com.sarapis.orservice.service.AddressService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/api/address") +public class AddressController { + public final AddressService addressService; + + @Autowired + public AddressController(AddressService addressService) { + this.addressService = addressService; + } + + @GetMapping + public ResponseEntity> getAllAddresses() { + List addressDTOs = this.addressService.getAllAddresses(); + return ResponseEntity.ok(addressDTOs); + } + + @GetMapping("/{id}") + public ResponseEntity getAddressById(@PathVariable String id) { + AddressDTO queried = this.addressService.getAddressById(id); + return ResponseEntity.ok(queried); + } + + @PostMapping + public ResponseEntity createAddress(@RequestBody AddressDTO addressDTO) { + AddressDTO createdAddress = this.addressService.createAddress(addressDTO); + return ResponseEntity.ok(createdAddress); + } + + @PutMapping("/{id}") + public ResponseEntity updateAddress(@PathVariable String id, @RequestBody AddressDTO addressDTO) { + AddressDTO updateAddress = this.addressService.updateAddress(id, addressDTO); + return ResponseEntity.ok(updateAddress); + } + + @DeleteMapping("/{id}") + public ResponseEntity deleteAddress(@PathVariable String id) { + this.addressService.deleteAddress(id); + return ResponseEntity.noContent().build(); + } +} From 8e5663a7eba4948a1c6c5064659b8041a184a2c8 Mon Sep 17 00:00:00 2001 From: Butter - ThinkWin Date: Sat, 23 Nov 2024 12:00:19 -0500 Subject: [PATCH 17/28] Updated Attribute Service Impl --- .../service/AttributeServiceImpl.java | 48 +++++-------------- 1 file changed, 13 insertions(+), 35 deletions(-) diff --git a/src/main/java/com/sarapis/orservice/service/AttributeServiceImpl.java b/src/main/java/com/sarapis/orservice/service/AttributeServiceImpl.java index 7d57a76..d41817e 100644 --- a/src/main/java/com/sarapis/orservice/service/AttributeServiceImpl.java +++ b/src/main/java/com/sarapis/orservice/service/AttributeServiceImpl.java @@ -1,6 +1,7 @@ package com.sarapis.orservice.service; import com.sarapis.orservice.dto.AttributeDTO; +import com.sarapis.orservice.dto.MetadataDTO; import com.sarapis.orservice.entity.Attribute; import com.sarapis.orservice.repository.AttributeRepository; import org.springframework.beans.factory.annotation.Autowired; @@ -14,32 +15,6 @@ public class AttributeServiceImpl implements AttributeService { private final AttributeRepository attributeRepository; - private AttributeDTO mapToDTO(Attribute attribute) { - return new AttributeDTO( - attribute.getId(), - attribute.getLinkId(), - attribute.getLinkType(), - attribute.getLinkEntity(), - attribute.getValue(), - attribute.getTaxonomyTerm(), - attribute.getMetadata(), - attribute.getLabel() - ); - } - - private Attribute mapToEntity(AttributeDTO attributeDTO) { - return new Attribute( - attributeDTO.getId(), - attributeDTO.getLinkId(), - attributeDTO.getLinkType(), - attributeDTO.getLinkEntity(), - attributeDTO.getValue(), - attributeDTO.getTaxonomyTerm(), - attributeDTO.getMetadata(), - attributeDTO.getLabel() - ); - } - @Autowired public AttributeServiceImpl(AttributeRepository attributeRepository) { this.attributeRepository = attributeRepository; @@ -49,7 +24,7 @@ public AttributeServiceImpl(AttributeRepository attributeRepository) { public List getAllAttributes() { return this.attributeRepository.findAll() .stream() - .map(this::mapToDTO) + .map(Attribute::toDTO) .collect(Collectors.toList()); } @@ -57,14 +32,14 @@ public List getAllAttributes() { public AttributeDTO getAttributeById(String id) { Attribute attr = this.attributeRepository.findById(Long.parseLong(id)) .orElseThrow(() -> new RuntimeException("Attribute not found")); - return this.mapToDTO(attr); + return attr.toDTO(); } @Override public AttributeDTO createAttribute(AttributeDTO attributeDTO) { - Attribute attr = this.mapToEntity(attributeDTO); + Attribute attr = attributeDTO.toEntity(); Attribute savedAttr = this.attributeRepository.save(attr); - return this.mapToDTO(savedAttr); + return savedAttr.toDTO(); } @Override @@ -72,16 +47,19 @@ public AttributeDTO updateAttribute(String id, AttributeDTO attributeDTO) { Attribute oldAttr = this.attributeRepository.findById(Long.parseLong(id)) .orElseThrow(() -> new RuntimeException("Attribute not found")); - oldAttr.setLinkId(attributeDTO.getLinkId()); - oldAttr.setLinkType(attributeDTO.getLinkType()); + //oldAttr.setLinkType(attributeDTO.getLinkType()); oldAttr.setLinkEntity(attributeDTO.getLinkEntity()); oldAttr.setValue(attributeDTO.getValue()); - oldAttr.setTaxonomyTerm(attributeDTO.getTaxonomyTerm()); - oldAttr.setMetadata(attributeDTO.getMetadata()); + oldAttr.setTaxonomyTerm(attributeDTO.getTaxonomyTerm().toEntity()); + + oldAttr.setMetadata(attributeDTO.getMetadata().stream() + .map(MetadataDTO::toEntity) + .collect(Collectors.toList()) + ); oldAttr.setLabel(attributeDTO.getLabel()); Attribute upAttr = this.attributeRepository.save(oldAttr); - return mapToDTO(upAttr); + return upAttr.toDTO(); } @Override From 12e015ee199af96dfe4c7a2b0d7c9ae0f6d07868 Mon Sep 17 00:00:00 2001 From: Butter - ThinkWin Date: Sat, 23 Nov 2024 12:11:00 -0500 Subject: [PATCH 18/28] Created Attribute Controller --- .../controller/AttributeController.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/main/java/com/sarapis/orservice/controller/AttributeController.java diff --git a/src/main/java/com/sarapis/orservice/controller/AttributeController.java b/src/main/java/com/sarapis/orservice/controller/AttributeController.java new file mode 100644 index 0000000..ee27502 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/controller/AttributeController.java @@ -0,0 +1,50 @@ +package com.sarapis.orservice.controller; + +import com.sarapis.orservice.dto.AttributeDTO; +import com.sarapis.orservice.service.AttributeService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/api/attribute") +public class AttributeController { + private final AttributeService attributeService; + + @Autowired + public AttributeController(AttributeService attributeService) { + this.attributeService = attributeService; + } + + @GetMapping + public ResponseEntity> getAllAttributes() { + List attributeDTOs = this.attributeService.getAllAttributes(); + return ResponseEntity.ok(attributeDTOs); + } + + @GetMapping("/{id}") + public ResponseEntity getAttributeById(@PathVariable String id) { + AttributeDTO queried = this.attributeService.getAttributeById(id); + return ResponseEntity.ok(queried); + } + + @PostMapping + public ResponseEntity createAttribute(@RequestBody AttributeDTO attributeDTO) { + AttributeDTO createdAttribute = this.attributeService.createAttribute(attributeDTO); + return ResponseEntity.ok(createdAttribute); + } + + @PutMapping("/{id}") + public ResponseEntity updateAttribute(@PathVariable String id, @RequestBody AttributeDTO attributeDTO) { + AttributeDTO updatedAttribute = this.attributeService.updateAttribute(id, attributeDTO); + return ResponseEntity.ok(updatedAttribute); + } + + @DeleteMapping("/{id}") + public ResponseEntity deleteAttribute(@PathVariable String id) { + this.attributeService.deleteAttribute(id); + return ResponseEntity.noContent().build(); + } +} From e1227df33a06f3eefb4a2d03e78cecc04ded616c Mon Sep 17 00:00:00 2001 From: ZhangTerrence Date: Sat, 23 Nov 2024 12:53:26 -0500 Subject: [PATCH 19/28] added hidden nonnull relations --- .../orservice/dto/AccessibilityDTO.java | 2 - .../com/sarapis/orservice/dto/AddressDTO.java | 2 - .../sarapis/orservice/dto/AttributeDTO.java | 13 +++--- .../com/sarapis/orservice/dto/ContactDTO.java | 2 - .../sarapis/orservice/dto/CostOptionDTO.java | 2 - .../com/sarapis/orservice/dto/FundingDTO.java | 2 - .../sarapis/orservice/dto/LanguageDTO.java | 2 - .../sarapis/orservice/dto/LocationDTO.java | 2 - .../dto/MetaTableDescriptionDTO.java | 2 - .../sarapis/orservice/dto/MetadataDTO.java | 3 +- .../orservice/dto/OrganizationDTO.java | 2 - .../dto/OrganizationIdentifierDTO.java | 2 - .../com/sarapis/orservice/dto/PhoneDTO.java | 2 - .../com/sarapis/orservice/dto/ProgramDTO.java | 2 - .../orservice/dto/RequiredDocumentDTO.java | 2 - .../sarapis/orservice/dto/ScheduleDTO.java | 2 - .../sarapis/orservice/dto/ServiceAreaDTO.java | 2 - .../orservice/dto/ServiceAtLocationDTO.java | 6 +-- .../orservice/dto/ServiceCapacityDTO.java | 2 - .../com/sarapis/orservice/dto/ServiceDTO.java | 8 ++-- .../sarapis/orservice/dto/TaxonomyDTO.java | 1 - .../orservice/dto/TaxonomyTermDTO.java | 1 - .../com/sarapis/orservice/dto/UnitDTO.java | 2 - .../com/sarapis/orservice/dto/UrlDTO.java | 2 - .../orservice/entity/Accessibility.java | 13 +----- .../com/sarapis/orservice/entity/Address.java | 13 +----- .../sarapis/orservice/entity/Attribute.java | 21 ++++----- .../com/sarapis/orservice/entity/Contact.java | 14 ++---- .../sarapis/orservice/entity/CostOption.java | 13 +----- .../com/sarapis/orservice/entity/Funding.java | 13 +----- .../sarapis/orservice/entity/Language.java | 13 +----- .../sarapis/orservice/entity/LinkEntity.java | 24 ++++++++++ .../entity/MetaTableDescription.java | 13 +----- .../sarapis/orservice/entity/Metadata.java | 5 +- .../entity/OrganizationIdentifier.java | 13 +----- .../com/sarapis/orservice/entity/Phone.java | 14 ++---- .../com/sarapis/orservice/entity/Program.java | 13 +----- .../orservice/entity/RequiredDocument.java | 13 +----- .../orservice/entity/ResourceType.java | 22 ++++++++- .../sarapis/orservice/entity/Schedule.java | 13 +----- .../sarapis/orservice/entity/ServiceArea.java | 13 +----- .../orservice/entity/ServiceCapacity.java | 15 ++---- .../sarapis/orservice/entity/Taxonomy.java | 7 +-- .../orservice/entity/TaxonomyTerm.java | 7 +-- .../com/sarapis/orservice/entity/Unit.java | 13 +----- .../com/sarapis/orservice/entity/Url.java | 13 +----- .../orservice/entity/core/Location.java | 24 ++++------ .../orservice/entity/core/Organization.java | 30 +++++------- .../orservice/entity/core/Service.java | 46 ++++++++----------- .../entity/core/ServiceAtLocation.java | 31 ++++++------- 50 files changed, 161 insertions(+), 336 deletions(-) create mode 100644 src/main/java/com/sarapis/orservice/entity/LinkEntity.java diff --git a/src/main/java/com/sarapis/orservice/dto/AccessibilityDTO.java b/src/main/java/com/sarapis/orservice/dto/AccessibilityDTO.java index 50596e3..d42bdb2 100644 --- a/src/main/java/com/sarapis/orservice/dto/AccessibilityDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/AccessibilityDTO.java @@ -25,8 +25,6 @@ public Accessibility toEntity() { .description(this.description) .details(this.details) .url(this.url) - .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) - .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/dto/AddressDTO.java b/src/main/java/com/sarapis/orservice/dto/AddressDTO.java index 300a9da..9924e62 100644 --- a/src/main/java/com/sarapis/orservice/dto/AddressDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/AddressDTO.java @@ -38,8 +38,6 @@ public Address toEntity() { .postalCode(this.postalCode) .country(this.country) .addressType(this.addressType) - .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) - .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/dto/AttributeDTO.java b/src/main/java/com/sarapis/orservice/dto/AttributeDTO.java index 6b7dee6..e29d4ba 100644 --- a/src/main/java/com/sarapis/orservice/dto/AttributeDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/AttributeDTO.java @@ -1,6 +1,7 @@ package com.sarapis.orservice.dto; import com.sarapis.orservice.entity.Attribute; +import com.sarapis.orservice.entity.LinkEntity; import lombok.*; import java.util.ArrayList; @@ -13,19 +14,19 @@ @Builder public class AttributeDTO { private String id; - private String linkEntity; + private LinkEntity linkEntity; private String value; - private TaxonomyTermDTO taxonomyTerm = null; - private List metadata = new ArrayList<>(); + private TaxonomyTermDTO taxonomyTerm; private String label; + private List metadata = new ArrayList<>(); - public Attribute toEntity() { + public Attribute toEntity(String linkId) { return Attribute.builder() .id(this.id) + .linkId(linkId) .linkEntity(this.linkEntity) .value(this.value) - .taxonomyTerm(this.taxonomyTerm != null ? this.taxonomyTerm.toEntity() : null) - .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) + .taxonomyTerm(this.taxonomyTerm.toEntity()) .label(this.label) .build(); } diff --git a/src/main/java/com/sarapis/orservice/dto/ContactDTO.java b/src/main/java/com/sarapis/orservice/dto/ContactDTO.java index 46ae09e..fd8a2d7 100644 --- a/src/main/java/com/sarapis/orservice/dto/ContactDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/ContactDTO.java @@ -29,8 +29,6 @@ public Contact toEntity() { .department(this.department) .email(this.email) .phones(this.phones.stream().map(PhoneDTO::toEntity).toList()) - .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) - .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/dto/CostOptionDTO.java b/src/main/java/com/sarapis/orservice/dto/CostOptionDTO.java index 877eeb7..c1c34aa 100644 --- a/src/main/java/com/sarapis/orservice/dto/CostOptionDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/CostOptionDTO.java @@ -32,8 +32,6 @@ public CostOption toEntity() { .currency(this.currency) .amount(this.amount) .amountDescription(this.amountDescription) - .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) - .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/dto/FundingDTO.java b/src/main/java/com/sarapis/orservice/dto/FundingDTO.java index a565538..7b825e9 100644 --- a/src/main/java/com/sarapis/orservice/dto/FundingDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/FundingDTO.java @@ -21,8 +21,6 @@ public Funding toEntity() { return Funding.builder() .id(this.id) .source(this.source) - .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) - .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/dto/LanguageDTO.java b/src/main/java/com/sarapis/orservice/dto/LanguageDTO.java index 3fe98e2..875e08e 100644 --- a/src/main/java/com/sarapis/orservice/dto/LanguageDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/LanguageDTO.java @@ -25,8 +25,6 @@ public Language toEntity() { .name(this.name) .code(this.code) .note(this.note) - .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) - .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/dto/LocationDTO.java b/src/main/java/com/sarapis/orservice/dto/LocationDTO.java index 13b2c7a..45c9efa 100644 --- a/src/main/java/com/sarapis/orservice/dto/LocationDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/LocationDTO.java @@ -52,8 +52,6 @@ public Location toEntity() { .accessibility(this.accessibility.stream().map(AccessibilityDTO::toEntity).toList()) .phones(this.phones.stream().map(PhoneDTO::toEntity).toList()) .schedules(this.schedules.stream().map(ScheduleDTO::toEntity).toList()) - .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) - .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/dto/MetaTableDescriptionDTO.java b/src/main/java/com/sarapis/orservice/dto/MetaTableDescriptionDTO.java index cce4358..4930826 100644 --- a/src/main/java/com/sarapis/orservice/dto/MetaTableDescriptionDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/MetaTableDescriptionDTO.java @@ -25,8 +25,6 @@ public MetaTableDescription toEntity() { .name(this.name) .language(this.language) .characterSet(this.characterSet) - .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) - .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/dto/MetadataDTO.java b/src/main/java/com/sarapis/orservice/dto/MetadataDTO.java index c757637..96fcc9a 100644 --- a/src/main/java/com/sarapis/orservice/dto/MetadataDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/MetadataDTO.java @@ -21,9 +21,10 @@ public class MetadataDTO { private String replacementValue; private String updatedBy; - public Metadata toEntity() { + public Metadata toEntity(String resourceId) { return Metadata.builder() .id(this.id) + .resourceId(resourceId) .resourceType(this.resourceType) .lastActionDate(this.lastActionDate) .lastActionType(this.lastActionType) diff --git a/src/main/java/com/sarapis/orservice/dto/OrganizationDTO.java b/src/main/java/com/sarapis/orservice/dto/OrganizationDTO.java index b3cf4aa..c7aed5f 100644 --- a/src/main/java/com/sarapis/orservice/dto/OrganizationDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/OrganizationDTO.java @@ -57,8 +57,6 @@ public Organization toEntity() { .locations(this.locations.stream().map(LocationDTO::toEntity).toList()) .programs(this.programs.stream().map(ProgramDTO::toEntity).toList()) .organizationIdentifiers(this.organizationIdentifiers.stream().map(OrganizationIdentifierDTO::toEntity).toList()) - .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) - .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/dto/OrganizationIdentifierDTO.java b/src/main/java/com/sarapis/orservice/dto/OrganizationIdentifierDTO.java index feeab9c..1ac16d6 100644 --- a/src/main/java/com/sarapis/orservice/dto/OrganizationIdentifierDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/OrganizationIdentifierDTO.java @@ -25,8 +25,6 @@ public OrganizationIdentifier toEntity() { .identifierScheme(this.identifierScheme) .identifierType(this.identifierType) .identifier(this.identifier) - .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) - .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/dto/PhoneDTO.java b/src/main/java/com/sarapis/orservice/dto/PhoneDTO.java index ee339e3..49081d1 100644 --- a/src/main/java/com/sarapis/orservice/dto/PhoneDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/PhoneDTO.java @@ -29,8 +29,6 @@ public Phone toEntity() { .type(this.type) .description(this.description) .languages(this.languages.stream().map(LanguageDTO::toEntity).toList()) - .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) - .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/dto/ProgramDTO.java b/src/main/java/com/sarapis/orservice/dto/ProgramDTO.java index 4ede1eb..b6d18f6 100644 --- a/src/main/java/com/sarapis/orservice/dto/ProgramDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/ProgramDTO.java @@ -25,8 +25,6 @@ public Program toEntity() { .name(this.name) .alternateName(this.alternateName) .description(this.description) - .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) - .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/dto/RequiredDocumentDTO.java b/src/main/java/com/sarapis/orservice/dto/RequiredDocumentDTO.java index aa43480..55c8024 100644 --- a/src/main/java/com/sarapis/orservice/dto/RequiredDocumentDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/RequiredDocumentDTO.java @@ -23,8 +23,6 @@ public RequiredDocument toEntity() { .id(this.id) .document(this.document) .uri(this.uri) - .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) - .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/dto/ScheduleDTO.java b/src/main/java/com/sarapis/orservice/dto/ScheduleDTO.java index 5105680..8d40dc8 100644 --- a/src/main/java/com/sarapis/orservice/dto/ScheduleDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/ScheduleDTO.java @@ -61,8 +61,6 @@ public Schedule toEntity() { .scheduleLink(this.scheduleLink) .attendingType(this.attendingType) .notes(this.notes) - .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) - .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/dto/ServiceAreaDTO.java b/src/main/java/com/sarapis/orservice/dto/ServiceAreaDTO.java index 6d7cc1f..430db6f 100644 --- a/src/main/java/com/sarapis/orservice/dto/ServiceAreaDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/ServiceAreaDTO.java @@ -30,8 +30,6 @@ public ServiceArea toEntity() { .extent(this.extent) .extentType(this.extentType) .uri(this.uri) - .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) - .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/dto/ServiceAtLocationDTO.java b/src/main/java/com/sarapis/orservice/dto/ServiceAtLocationDTO.java index df0a5c5..9bbfc3d 100644 --- a/src/main/java/com/sarapis/orservice/dto/ServiceAtLocationDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/ServiceAtLocationDTO.java @@ -18,7 +18,7 @@ public class ServiceAtLocationDTO { private List contacts = new ArrayList<>(); private List phones = new ArrayList<>(); private List schedules = new ArrayList<>(); - private LocationDTO location = null; + private LocationDTO location; private List attributes = new ArrayList<>(); private List metadata = new ArrayList<>(); @@ -30,9 +30,7 @@ public ServiceAtLocation toEntity() { .contacts(this.contacts.stream().map(ContactDTO::toEntity).toList()) .phones(this.phones.stream().map(PhoneDTO::toEntity).toList()) .schedules(this.schedules.stream().map(ScheduleDTO::toEntity).toList()) - .location(this.location != null ? this.location.toEntity() : null) - .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) - .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) + .location(this.location.toEntity()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/dto/ServiceCapacityDTO.java b/src/main/java/com/sarapis/orservice/dto/ServiceCapacityDTO.java index 2a0dd5e..1531284 100644 --- a/src/main/java/com/sarapis/orservice/dto/ServiceCapacityDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/ServiceCapacityDTO.java @@ -30,8 +30,6 @@ public ServiceCapacity toEntity() { .maximum(this.maximum) .description(this.description) .updated(this.updated) - .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) - .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/dto/ServiceDTO.java b/src/main/java/com/sarapis/orservice/dto/ServiceDTO.java index b5e7e41..297b6a9 100644 --- a/src/main/java/com/sarapis/orservice/dto/ServiceDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/ServiceDTO.java @@ -44,7 +44,7 @@ public class ServiceDTO { private List serviceAreas = new ArrayList<>(); private List serviceAtLocations = new ArrayList<>(); private List languages = new ArrayList<>(); - private OrganizationDTO organization = null; + private OrganizationDTO organization; private List funding = new ArrayList<>(); private List costOptions = new ArrayList<>(); private ProgramDTO program = null; @@ -83,15 +83,13 @@ public Service toEntity() { .serviceAreas(this.serviceAreas.stream().map(ServiceAreaDTO::toEntity).toList()) .serviceAtLocations(this.serviceAtLocations.stream().map(ServiceAtLocationDTO::toEntity).toList()) .languages(this.languages.stream().map(LanguageDTO::toEntity).toList()) - .organization(this.organization != null ? organization.toEntity() : null) + .organization(this.organization.toEntity()) .funding(this.funding.stream().map(FundingDTO::toEntity).toList()) .costOptions(this.costOptions.stream().map(CostOptionDTO::toEntity).toList()) - .program(this.program != null ? program.toEntity() : null) + .program(this.program != null ? this.program.toEntity() : null) .requiredDocuments(this.requiredDocuments.stream().map(RequiredDocumentDTO::toEntity).toList()) .contacts(this.contacts.stream().map(ContactDTO::toEntity).toList()) .capacities(this.capacities.stream().map(ServiceCapacityDTO::toEntity).toList()) - .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) - .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/dto/TaxonomyDTO.java b/src/main/java/com/sarapis/orservice/dto/TaxonomyDTO.java index 06ddbfb..e7edb8b 100644 --- a/src/main/java/com/sarapis/orservice/dto/TaxonomyDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/TaxonomyDTO.java @@ -26,7 +26,6 @@ public Taxonomy toEntity() { .description(this.description) .uri(this.uri) .version(this.version) - .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/dto/TaxonomyTermDTO.java b/src/main/java/com/sarapis/orservice/dto/TaxonomyTermDTO.java index d733f0b..5e1358c 100644 --- a/src/main/java/com/sarapis/orservice/dto/TaxonomyTermDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/TaxonomyTermDTO.java @@ -34,7 +34,6 @@ public TaxonomyTerm toEntity() { .taxonomyDetail(this.taxonomyDetail != null ? this.taxonomyDetail.toEntity() : null) .language(this.language) .termUri(this.termUri) - .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/dto/UnitDTO.java b/src/main/java/com/sarapis/orservice/dto/UnitDTO.java index a8bf6ab..4bfea69 100644 --- a/src/main/java/com/sarapis/orservice/dto/UnitDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/UnitDTO.java @@ -27,8 +27,6 @@ public Unit toEntity() { .scheme(this.scheme) .identifier(this.identifier) .uri(this.uri) - .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) - .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/dto/UrlDTO.java b/src/main/java/com/sarapis/orservice/dto/UrlDTO.java index ef25789..6c87584 100644 --- a/src/main/java/com/sarapis/orservice/dto/UrlDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/UrlDTO.java @@ -23,8 +23,6 @@ public Url toEntity() { .id(this.id) .label(this.label) .url(this.url) - .attributes(this.attributes.stream().map(AttributeDTO::toEntity).toList()) - .metadata(this.metadata.stream().map(MetadataDTO::toEntity).toList()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/entity/Accessibility.java b/src/main/java/com/sarapis/orservice/entity/Accessibility.java index 8b73eea..7bfc983 100644 --- a/src/main/java/com/sarapis/orservice/entity/Accessibility.java +++ b/src/main/java/com/sarapis/orservice/entity/Accessibility.java @@ -6,7 +6,6 @@ import org.hibernate.annotations.UuidGenerator; import java.util.ArrayList; -import java.util.List; @Entity @Table(name = "accessibility") @@ -31,22 +30,14 @@ public class Accessibility { @Column(name = "url") private String url; - @OneToMany - @JoinColumn(name = "link_id") - private List attributes = new ArrayList<>(); - - @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "resource_id") - private List metadata = new ArrayList<>(); - public AccessibilityDTO toDTO() { return AccessibilityDTO.builder() .id(this.id) .description(this.description) .details(this.details) .url(this.url) - .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) - .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .attributes(new ArrayList<>()) + .metadata(new ArrayList<>()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/entity/Address.java b/src/main/java/com/sarapis/orservice/entity/Address.java index ae40ec6..5ae08e8 100644 --- a/src/main/java/com/sarapis/orservice/entity/Address.java +++ b/src/main/java/com/sarapis/orservice/entity/Address.java @@ -6,7 +6,6 @@ import org.hibernate.annotations.UuidGenerator; import java.util.ArrayList; -import java.util.List; @Entity @Table(name = "address") @@ -50,14 +49,6 @@ public class Address { @Column(name = "address_type", nullable = false) private AddressType addressType; - @OneToMany - @JoinColumn(name = "link_id") - private List attributes = new ArrayList<>(); - - @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "resource_id") - private List metadata = new ArrayList<>(); - public AddressDTO toDTO() { return AddressDTO.builder() .id(this.id) @@ -70,8 +61,8 @@ public AddressDTO toDTO() { .postalCode(this.postalCode) .country(this.country) .addressType(this.addressType) - .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) - .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .attributes(new ArrayList<>()) + .metadata(new ArrayList<>()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/entity/Attribute.java b/src/main/java/com/sarapis/orservice/entity/Attribute.java index 6c156d5..be840a5 100644 --- a/src/main/java/com/sarapis/orservice/entity/Attribute.java +++ b/src/main/java/com/sarapis/orservice/entity/Attribute.java @@ -6,7 +6,6 @@ import org.hibernate.annotations.UuidGenerator; import java.util.ArrayList; -import java.util.List; @Entity @Table(name = "attribute") @@ -22,22 +21,22 @@ public class Attribute { @Column(name = "id", nullable = false) private String id; + @Column(name = "link_id", nullable = false) + private String linkId; + @Column(name = "link_type") private String linkType; - @Column(name = "link_entity") - private String linkEntity; + @Enumerated(EnumType.STRING) + @Column(name = "link_entity", nullable = false) + private LinkEntity linkEntity; @Column(name = "value") private String value; - @OneToOne - @JoinColumn(name = "taxonomy_term_id") - private TaxonomyTerm taxonomyTerm = null; - - @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "resource_id") - private List metadata = new ArrayList<>(); + @OneToOne(orphanRemoval = true, optional = false) + @JoinColumn(name = "taxonomy_term_id", nullable = false) + private TaxonomyTerm taxonomyTerm; @Column(name = "label") private String label; @@ -48,7 +47,7 @@ public AttributeDTO toDTO() { .linkEntity(this.linkEntity) .value(this.value) .taxonomyTerm(this.taxonomyTerm != null ? this.taxonomyTerm.toDTO() : null) - .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .metadata(new ArrayList<>()) .label(this.label) .build(); } diff --git a/src/main/java/com/sarapis/orservice/entity/Contact.java b/src/main/java/com/sarapis/orservice/entity/Contact.java index 6ea8840..008f7af 100644 --- a/src/main/java/com/sarapis/orservice/entity/Contact.java +++ b/src/main/java/com/sarapis/orservice/entity/Contact.java @@ -34,18 +34,10 @@ public class Contact { @Column(name = "email") private String email; - @OneToMany + @OneToMany(cascade = CascadeType.PERSIST) @JoinColumn(name = "contact_id") private List phones = new ArrayList<>(); - @OneToMany - @JoinColumn(name = "link_id") - private List attributes = new ArrayList<>(); - - @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "resource_id") - private List metadata = new ArrayList<>(); - public ContactDTO toDTO() { return ContactDTO.builder() .id(this.id) @@ -54,8 +46,8 @@ public ContactDTO toDTO() { .department(this.department) .email(this.email) .phones(this.phones.stream().map(Phone::toDTO).toList()) - .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) - .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .attributes(new ArrayList<>()) + .metadata(new ArrayList<>()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/entity/CostOption.java b/src/main/java/com/sarapis/orservice/entity/CostOption.java index 78fd7b6..268aa60 100644 --- a/src/main/java/com/sarapis/orservice/entity/CostOption.java +++ b/src/main/java/com/sarapis/orservice/entity/CostOption.java @@ -7,7 +7,6 @@ import java.time.LocalDate; import java.util.ArrayList; -import java.util.List; @Entity @Table(name = "cost_option") @@ -41,14 +40,6 @@ public class CostOption { @Column(name = "amount_description") private String amountDescription; - @OneToMany - @JoinColumn(name = "link_id") - private List attributes = new ArrayList<>(); - - @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "resource_id") - private List metadata = new ArrayList<>(); - public CostOptionDTO toDTO() { return CostOptionDTO.builder() .id(this.id) @@ -58,8 +49,8 @@ public CostOptionDTO toDTO() { .currency(this.currency) .amount(this.amount) .amountDescription(this.amountDescription) - .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) - .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .attributes(new ArrayList<>()) + .metadata(new ArrayList<>()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/entity/Funding.java b/src/main/java/com/sarapis/orservice/entity/Funding.java index 10873b4..4446b2e 100644 --- a/src/main/java/com/sarapis/orservice/entity/Funding.java +++ b/src/main/java/com/sarapis/orservice/entity/Funding.java @@ -6,7 +6,6 @@ import org.hibernate.annotations.UuidGenerator; import java.util.ArrayList; -import java.util.List; @Entity @Table(name = "funding") @@ -25,20 +24,12 @@ public class Funding { @Column(name = "source") private String source; - @OneToMany - @JoinColumn(name = "link_id") - private List attributes = new ArrayList<>(); - - @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "resource_id") - private List metadata = new ArrayList<>(); - public FundingDTO toDTO() { return FundingDTO.builder() .id(this.id) .source(this.source) - .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) - .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .attributes(new ArrayList<>()) + .metadata(new ArrayList<>()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/entity/Language.java b/src/main/java/com/sarapis/orservice/entity/Language.java index b09da3f..efec762 100644 --- a/src/main/java/com/sarapis/orservice/entity/Language.java +++ b/src/main/java/com/sarapis/orservice/entity/Language.java @@ -6,7 +6,6 @@ import org.hibernate.annotations.UuidGenerator; import java.util.ArrayList; -import java.util.List; @Entity @Table(name = "language") @@ -31,22 +30,14 @@ public class Language { @Column(name = "note") private String note; - @OneToMany - @JoinColumn(name = "link_id") - private List attributes = new ArrayList<>(); - - @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "resource_id") - private List metadata = new ArrayList<>(); - public LanguageDTO toDTO() { return LanguageDTO.builder() .id(this.id) .name(this.name) .code(this.code) .note(this.note) - .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) - .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .attributes(new ArrayList<>()) + .metadata(new ArrayList<>()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/entity/LinkEntity.java b/src/main/java/com/sarapis/orservice/entity/LinkEntity.java new file mode 100644 index 0000000..c2e5387 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/entity/LinkEntity.java @@ -0,0 +1,24 @@ +package com.sarapis.orservice.entity; + +public enum LinkEntity { + organization, + service, + location, + service_at_location, + address, + phone, + schedule, + service_area, + language, + funding, + accessibility, + cost_option, + program, + required_document, + contact, + organization_identifier, + unit, + service_capacity, + url, + meta_table_description +} diff --git a/src/main/java/com/sarapis/orservice/entity/MetaTableDescription.java b/src/main/java/com/sarapis/orservice/entity/MetaTableDescription.java index bbe9f36..0ac64cf 100644 --- a/src/main/java/com/sarapis/orservice/entity/MetaTableDescription.java +++ b/src/main/java/com/sarapis/orservice/entity/MetaTableDescription.java @@ -6,7 +6,6 @@ import org.hibernate.annotations.UuidGenerator; import java.util.ArrayList; -import java.util.List; @Entity @Table(name = "meta_table_description") @@ -31,22 +30,14 @@ public class MetaTableDescription { @Column(name = "character_set") private String characterSet; - @OneToMany - @JoinColumn(name = "link_id") - private List attributes = new ArrayList<>(); - - @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "resource_id") - private List metadata = new ArrayList<>(); - public MetaTableDescriptionDTO toDTO() { return MetaTableDescriptionDTO.builder() .id(this.id) .name(this.name) .language(this.language) .characterSet(this.characterSet) - .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) - .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .attributes(new ArrayList<>()) + .metadata(new ArrayList<>()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/entity/Metadata.java b/src/main/java/com/sarapis/orservice/entity/Metadata.java index d6b9ab9..8052e38 100644 --- a/src/main/java/com/sarapis/orservice/entity/Metadata.java +++ b/src/main/java/com/sarapis/orservice/entity/Metadata.java @@ -21,8 +21,11 @@ public class Metadata { @Column(name = "id", nullable = false) private String id; + @Column(name = "resource_id", nullable = false) + private String resourceId; + @Enumerated(EnumType.STRING) - @Column(name = "resource_type") + @Column(name = "resource_type", nullable = false) private ResourceType resourceType; @Column(name = "last_action_date", nullable = false) diff --git a/src/main/java/com/sarapis/orservice/entity/OrganizationIdentifier.java b/src/main/java/com/sarapis/orservice/entity/OrganizationIdentifier.java index 4125351..dce94fa 100644 --- a/src/main/java/com/sarapis/orservice/entity/OrganizationIdentifier.java +++ b/src/main/java/com/sarapis/orservice/entity/OrganizationIdentifier.java @@ -6,7 +6,6 @@ import org.hibernate.annotations.UuidGenerator; import java.util.ArrayList; -import java.util.List; @Entity @Table(name = "organization_identifier") @@ -31,22 +30,14 @@ public class OrganizationIdentifier { @Column(name = "identifier", nullable = false) private String identifier; - @OneToMany - @JoinColumn(name = "link_id") - private List attributes = new ArrayList<>(); - - @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "resource_id") - private List metadata = new ArrayList<>(); - public OrganizationIdentifierDTO toDTO() { return OrganizationIdentifierDTO.builder() .id(this.id) .identifierScheme(this.identifierScheme) .identifierType(this.identifierType) .identifier(this.identifier) - .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) - .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .attributes(new ArrayList<>()) + .metadata(new ArrayList<>()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/entity/Phone.java b/src/main/java/com/sarapis/orservice/entity/Phone.java index fc5aa60..5969a51 100644 --- a/src/main/java/com/sarapis/orservice/entity/Phone.java +++ b/src/main/java/com/sarapis/orservice/entity/Phone.java @@ -34,18 +34,10 @@ public class Phone { @Column(name = "description") private String description; - @OneToMany + @OneToMany(cascade = CascadeType.PERSIST) @JoinColumn(name = "phone_id") private List languages = new ArrayList<>(); - @OneToMany - @JoinColumn(name = "link_id") - private List attributes = new ArrayList<>(); - - @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "resource_id") - private List metadata = new ArrayList<>(); - public PhoneDTO toDTO() { return PhoneDTO.builder() .id(this.id) @@ -54,8 +46,8 @@ public PhoneDTO toDTO() { .type(this.type) .description(this.description) .languages(this.languages.stream().map(Language::toDTO).toList()) - .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) - .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .attributes(new ArrayList<>()) + .metadata(new ArrayList<>()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/entity/Program.java b/src/main/java/com/sarapis/orservice/entity/Program.java index 9ae363a..57c11bd 100644 --- a/src/main/java/com/sarapis/orservice/entity/Program.java +++ b/src/main/java/com/sarapis/orservice/entity/Program.java @@ -6,7 +6,6 @@ import org.hibernate.annotations.UuidGenerator; import java.util.ArrayList; -import java.util.List; @Entity @Table(name = "program") @@ -31,22 +30,14 @@ public class Program { @Column(name = "description", nullable = false) private String description; - @OneToMany - @JoinColumn(name = "link_id") - private List attributes = new ArrayList<>(); - - @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "resource_id") - private List metadata = new ArrayList<>(); - public ProgramDTO toDTO() { return ProgramDTO.builder() .id(this.id) .name(this.name) .alternateName(this.alternateName) .description(this.description) - .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) - .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .attributes(new ArrayList<>()) + .metadata(new ArrayList<>()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/entity/RequiredDocument.java b/src/main/java/com/sarapis/orservice/entity/RequiredDocument.java index 0d3936f..1e8ae53 100644 --- a/src/main/java/com/sarapis/orservice/entity/RequiredDocument.java +++ b/src/main/java/com/sarapis/orservice/entity/RequiredDocument.java @@ -6,7 +6,6 @@ import org.hibernate.annotations.UuidGenerator; import java.util.ArrayList; -import java.util.List; @Entity @Table(name = "required_document") @@ -28,21 +27,13 @@ public class RequiredDocument { @Column(name = "uri") private String uri; - @OneToMany - @JoinColumn(name = "link_id") - private List attributes = new ArrayList<>(); - - @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "resource_id") - private List metadata = new ArrayList<>(); - public RequiredDocumentDTO toDTO() { return RequiredDocumentDTO.builder() .id(this.id) .document(this.document) .uri(this.uri) - .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) - .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .attributes(new ArrayList<>()) + .metadata(new ArrayList<>()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/entity/ResourceType.java b/src/main/java/com/sarapis/orservice/entity/ResourceType.java index 0b626b5..7bfb5ea 100644 --- a/src/main/java/com/sarapis/orservice/entity/ResourceType.java +++ b/src/main/java/com/sarapis/orservice/entity/ResourceType.java @@ -1,9 +1,27 @@ package com.sarapis.orservice.entity; public enum ResourceType { + organization, service, - program, location, + service_at_location, address, - contact + phone, + schedule, + service_area, + language, + funding, + accessibility, + cost_option, + program, + required_document, + contact, + organization_identifier, + unit, + service_capacity, + attribute, + url, + meta_table_description, + taxonomy, + taxonomy_term } diff --git a/src/main/java/com/sarapis/orservice/entity/Schedule.java b/src/main/java/com/sarapis/orservice/entity/Schedule.java index 22ce882..899c945 100644 --- a/src/main/java/com/sarapis/orservice/entity/Schedule.java +++ b/src/main/java/com/sarapis/orservice/entity/Schedule.java @@ -8,7 +8,6 @@ import java.time.LocalDate; import java.time.LocalTime; import java.util.ArrayList; -import java.util.List; @Entity @Table(name = "schedule") @@ -83,14 +82,6 @@ public class Schedule { @Column(name = "notes") private String notes; - @OneToMany - @JoinColumn(name = "link_id") - private List attributes = new ArrayList<>(); - - @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "resource_id") - private List metadata = new ArrayList<>(); - public ScheduleDTO toDTO() { return ScheduleDTO.builder() .id(this.id) @@ -113,8 +104,8 @@ public ScheduleDTO toDTO() { .scheduleLink(this.scheduleLink) .attendingType(this.attendingType) .notes(this.notes) - .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) - .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .attributes(new ArrayList<>()) + .metadata(new ArrayList<>()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/entity/ServiceArea.java b/src/main/java/com/sarapis/orservice/entity/ServiceArea.java index 53ccb75..e1dccab 100644 --- a/src/main/java/com/sarapis/orservice/entity/ServiceArea.java +++ b/src/main/java/com/sarapis/orservice/entity/ServiceArea.java @@ -6,7 +6,6 @@ import org.hibernate.annotations.UuidGenerator; import java.util.ArrayList; -import java.util.List; @Entity @Table(name = "service_area") @@ -38,14 +37,6 @@ public class ServiceArea { @Column(name = "uri") private String uri; - @OneToMany - @JoinColumn(name = "link_id") - private List attributes = new ArrayList<>(); - - @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "resource_id") - private List metadata = new ArrayList<>(); - public ServiceAreaDTO toDTO() { return ServiceAreaDTO.builder() .id(this.id) @@ -54,8 +45,8 @@ public ServiceAreaDTO toDTO() { .extent(this.extent) .extentType(this.extentType) .uri(this.uri) - .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) - .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .attributes(new ArrayList<>()) + .metadata(new ArrayList<>()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/entity/ServiceCapacity.java b/src/main/java/com/sarapis/orservice/entity/ServiceCapacity.java index 7bef604..c14a420 100644 --- a/src/main/java/com/sarapis/orservice/entity/ServiceCapacity.java +++ b/src/main/java/com/sarapis/orservice/entity/ServiceCapacity.java @@ -7,7 +7,6 @@ import java.time.LocalDate; import java.util.ArrayList; -import java.util.List; @Entity @Table(name = "service_capacity") @@ -24,7 +23,7 @@ public class ServiceCapacity { private String id; @OneToOne - @JoinColumn(name = "unit_id", nullable = false) + @JoinColumn(name = "unit_id") private Unit unit = null; @Column(name = "available", nullable = false) @@ -39,14 +38,6 @@ public class ServiceCapacity { @Column(name = "updated", nullable = false) private LocalDate updated; - @OneToMany - @JoinColumn(name = "link_id") - private List attributes = new ArrayList<>(); - - @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "resource_id") - private List metadata = new ArrayList<>(); - public ServiceCapacityDTO toDTO() { return ServiceCapacityDTO.builder() .id(this.id) @@ -55,8 +46,8 @@ public ServiceCapacityDTO toDTO() { .maximum(this.maximum) .description(this.description) .updated(this.updated) - .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) - .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .attributes(new ArrayList<>()) + .metadata(new ArrayList<>()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/entity/Taxonomy.java b/src/main/java/com/sarapis/orservice/entity/Taxonomy.java index f8ca6bb..ef33790 100644 --- a/src/main/java/com/sarapis/orservice/entity/Taxonomy.java +++ b/src/main/java/com/sarapis/orservice/entity/Taxonomy.java @@ -6,7 +6,6 @@ import org.hibernate.annotations.UuidGenerator; import java.util.ArrayList; -import java.util.List; @Entity @Table(name = "taxonomy") @@ -34,10 +33,6 @@ public class Taxonomy { @Column(name = "version") private String version; - @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "resource_id") - private List metadata = new ArrayList<>(); - public TaxonomyDTO toDTO() { return TaxonomyDTO.builder() .id(this.id) @@ -45,7 +40,7 @@ public TaxonomyDTO toDTO() { .description(this.description) .uri(this.uri) .version(this.version) - .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .metadata(new ArrayList<>()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/entity/TaxonomyTerm.java b/src/main/java/com/sarapis/orservice/entity/TaxonomyTerm.java index cca4772..59bf611 100644 --- a/src/main/java/com/sarapis/orservice/entity/TaxonomyTerm.java +++ b/src/main/java/com/sarapis/orservice/entity/TaxonomyTerm.java @@ -6,7 +6,6 @@ import org.hibernate.annotations.UuidGenerator; import java.util.ArrayList; -import java.util.List; @Entity @Table(name = "taxonomy_term") @@ -48,10 +47,6 @@ public class TaxonomyTerm { @Column(name = "term_uri") private String termUri; - @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "resource_id") - private List metadata = new ArrayList<>(); - public TaxonomyTermDTO toDTO() { return TaxonomyTermDTO.builder() .id(this.id) @@ -63,7 +58,7 @@ public TaxonomyTermDTO toDTO() { .taxonomyDetail(this.taxonomyDetail != null ? this.taxonomyDetail.toDTO() : null) .language(this.language) .termUri(this.termUri) - .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .metadata(new ArrayList<>()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/entity/Unit.java b/src/main/java/com/sarapis/orservice/entity/Unit.java index 3cb3b6d..0508205 100644 --- a/src/main/java/com/sarapis/orservice/entity/Unit.java +++ b/src/main/java/com/sarapis/orservice/entity/Unit.java @@ -6,7 +6,6 @@ import org.hibernate.annotations.UuidGenerator; import java.util.ArrayList; -import java.util.List; @Entity @Table(name = "unit") @@ -34,14 +33,6 @@ public class Unit { @Column(name = "uri") private String uri; - @OneToMany - @JoinColumn(name = "link_id") - private List attributes = new ArrayList<>(); - - @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "resource_id") - private List metadata = new ArrayList<>(); - public UnitDTO toDTO() { return UnitDTO.builder() .id(this.id) @@ -49,8 +40,8 @@ public UnitDTO toDTO() { .scheme(this.scheme) .identifier(this.identifier) .uri(this.uri) - .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) - .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .attributes(new ArrayList<>()) + .metadata(new ArrayList<>()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/entity/Url.java b/src/main/java/com/sarapis/orservice/entity/Url.java index 2b942bb..7917cb0 100644 --- a/src/main/java/com/sarapis/orservice/entity/Url.java +++ b/src/main/java/com/sarapis/orservice/entity/Url.java @@ -6,7 +6,6 @@ import org.hibernate.annotations.UuidGenerator; import java.util.ArrayList; -import java.util.List; @Entity @Table(name = "url") @@ -28,21 +27,13 @@ public class Url { @Column(name = "url", nullable = false) private String url; - @OneToMany - @JoinColumn(name = "link_id") - private List attributes = new ArrayList<>(); - - @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "resource_id") - private List metadata = new ArrayList<>(); - public UrlDTO toDTO() { return UrlDTO.builder() .id(this.id) .label(this.label) .url(this.url) - .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) - .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .attributes(new ArrayList<>()) + .metadata(new ArrayList<>()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/entity/core/Location.java b/src/main/java/com/sarapis/orservice/entity/core/Location.java index a496efc..27c8ae4 100644 --- a/src/main/java/com/sarapis/orservice/entity/core/Location.java +++ b/src/main/java/com/sarapis/orservice/entity/core/Location.java @@ -54,38 +54,30 @@ public class Location { @Column(name = "external_identifier_type") private String externalIdentifierType; - @OneToMany + @OneToMany(cascade = CascadeType.PERSIST) @JoinColumn(name = "location_id") private List languages = new ArrayList<>(); - @OneToMany + @OneToMany(cascade = CascadeType.PERSIST) @JoinColumn(name = "location_id") private List
addresses = new ArrayList<>(); - @OneToMany + @OneToMany(cascade = CascadeType.PERSIST) @JoinColumn(name = "location_id") private List contacts = new ArrayList<>(); - @OneToMany + @OneToMany(cascade = CascadeType.PERSIST) @JoinColumn(name = "location_id") private List accessibility = new ArrayList<>(); - @OneToMany + @OneToMany(cascade = CascadeType.PERSIST) @JoinColumn(name = "location_id") private List phones = new ArrayList<>(); - @OneToMany + @OneToMany(cascade = CascadeType.PERSIST) @JoinColumn(name = "location_id") private List schedules = new ArrayList<>(); - @OneToMany - @JoinColumn(name = "link_id") - private List attributes = new ArrayList<>(); - - @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "resource_id") - private List metadata = new ArrayList<>(); - public LocationDTO toDTO() { return LocationDTO.builder() .id(this.id) @@ -105,8 +97,8 @@ public LocationDTO toDTO() { .accessibility(this.accessibility.stream().map(Accessibility::toDTO).toList()) .phones(this.phones.stream().map(Phone::toDTO).toList()) .schedules(this.schedules.stream().map(Schedule::toDTO).toList()) - .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) - .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .attributes(new ArrayList<>()) + .metadata(new ArrayList<>()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/entity/core/Organization.java b/src/main/java/com/sarapis/orservice/entity/core/Organization.java index cb60aef..e304c87 100644 --- a/src/main/java/com/sarapis/orservice/entity/core/Organization.java +++ b/src/main/java/com/sarapis/orservice/entity/core/Organization.java @@ -38,7 +38,7 @@ public class Organization { @Column(name = "website") private String website; - @OneToMany + @OneToMany(cascade = CascadeType.PERSIST) @JoinColumn(name = "organization_id") private List additionalWebsites = new ArrayList<>(); @@ -66,37 +66,29 @@ public class Organization { @JoinColumn(name = "parent_organization_id") private Organization parentOrganization = null; - @OneToMany + @OneToMany(cascade = CascadeType.PERSIST) @JoinColumn(name = "organization_id") private List funding = new ArrayList<>(); - @OneToMany + @OneToMany(cascade = CascadeType.PERSIST) @JoinColumn(name = "organization_id") private List contacts = new ArrayList<>(); - @OneToMany + @OneToMany(cascade = CascadeType.PERSIST) @JoinColumn(name = "organization_id") private List phones = new ArrayList<>(); - @OneToMany + @OneToMany(cascade = CascadeType.PERSIST) @JoinColumn(name = "organization_id") private List locations = new ArrayList<>(); - @OneToMany - @JoinColumn(name = "organization_id") + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "organization_id", nullable = false) private List programs = new ArrayList<>(); - @OneToMany - @JoinColumn(name = "organization_id") - private List organizationIdentifiers = new ArrayList<>(); - - @OneToMany - @JoinColumn(name = "link_id") - private List attributes = new ArrayList<>(); - @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "resource_id") - private List metadata = new ArrayList<>(); + @JoinColumn(name = "organization_id", nullable = false) + private List organizationIdentifiers = new ArrayList<>(); public OrganizationDTO toDTO() { return OrganizationDTO.builder() @@ -120,8 +112,8 @@ public OrganizationDTO toDTO() { .locations(this.locations.stream().map(Location::toDTO).toList()) .programs(this.programs.stream().map(Program::toDTO).toList()) .organizationIdentifiers(this.organizationIdentifiers.stream().map(OrganizationIdentifier::toDTO).toList()) - .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) - .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .attributes(new ArrayList<>()) + .metadata(new ArrayList<>()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/entity/core/Service.java b/src/main/java/com/sarapis/orservice/entity/core/Service.java index c2a5846..5443895 100644 --- a/src/main/java/com/sarapis/orservice/entity/core/Service.java +++ b/src/main/java/com/sarapis/orservice/entity/core/Service.java @@ -4,6 +4,7 @@ import com.sarapis.orservice.entity.*; import jakarta.persistence.*; import lombok.*; +import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.UuidGenerator; import java.time.LocalDate; @@ -37,7 +38,7 @@ public class Service { @Column(name = "url") private String url; - @OneToMany + @OneToMany(cascade = CascadeType.PERSIST) @JoinColumn(name = "service_id") private List additionalUrls = new ArrayList<>(); @@ -93,62 +94,55 @@ public class Service { @Column(name = "last_modified") private LocalDateTime lastModified; - @OneToMany + @OneToMany(cascade = CascadeType.PERSIST) @JoinColumn(name = "service_id") private List phones = new ArrayList<>(); - @OneToMany + @OneToMany(cascade = CascadeType.PERSIST) @JoinColumn(name = "service_id") private List schedules = new ArrayList<>(); - @OneToMany + @OneToMany(cascade = CascadeType.PERSIST) @JoinColumn(name = "service_id") private List serviceAreas = new ArrayList<>(); - @OneToMany - @JoinColumn(name = "service_id") + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "service_id", nullable = false) private List serviceAtLocations = new ArrayList<>(); - @OneToMany + @OneToMany(cascade = CascadeType.PERSIST) @JoinColumn(name = "service_id") private List languages = new ArrayList<>(); - @ManyToOne - @JoinColumn(name = "organization_id") - private Organization organization = null; + // On Organization delete, all related Services should be deleted. + @ManyToOne(optional = false) + @JoinColumn(name = "organization_id", nullable = false) + private Organization organization; - @OneToMany + @OneToMany(cascade = CascadeType.PERSIST) @JoinColumn(name = "service_id") private List funding = new ArrayList<>(); - @OneToMany - @JoinColumn(name = "service_id") + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "service_id", nullable = false) private List costOptions = new ArrayList<>(); @ManyToOne @JoinColumn(name = "program_id") private Program program = null; - @OneToMany + @OneToMany(cascade = CascadeType.PERSIST) @JoinColumn(name = "service_id") private List requiredDocuments = new ArrayList<>(); - @OneToMany + @OneToMany(cascade = CascadeType.PERSIST) @JoinColumn(name = "service_id") private List contacts = new ArrayList<>(); - @OneToMany + @OneToMany(cascade = CascadeType.PERSIST) @JoinColumn(name = "service_id") private List capacities = new ArrayList<>(); - @OneToMany - @JoinColumn(name = "link_id") - private List attributes = new ArrayList<>(); - - @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "resource_id") - private List metadata = new ArrayList<>(); - public ServiceDTO toDTO() { return ServiceDTO.builder() .id(this.id) @@ -185,8 +179,8 @@ public ServiceDTO toDTO() { .requiredDocuments(this.requiredDocuments.stream().map(RequiredDocument::toDTO).toList()) .contacts(this.contacts.stream().map(Contact::toDTO).toList()) .capacities(this.capacities.stream().map(ServiceCapacity::toDTO).toList()) - .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) - .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .attributes(new ArrayList<>()) + .metadata(new ArrayList<>()) .build(); } } diff --git a/src/main/java/com/sarapis/orservice/entity/core/ServiceAtLocation.java b/src/main/java/com/sarapis/orservice/entity/core/ServiceAtLocation.java index df09011..847758a 100644 --- a/src/main/java/com/sarapis/orservice/entity/core/ServiceAtLocation.java +++ b/src/main/java/com/sarapis/orservice/entity/core/ServiceAtLocation.java @@ -1,7 +1,10 @@ package com.sarapis.orservice.entity.core; import com.sarapis.orservice.dto.ServiceAtLocationDTO; -import com.sarapis.orservice.entity.*; +import com.sarapis.orservice.entity.Contact; +import com.sarapis.orservice.entity.Phone; +import com.sarapis.orservice.entity.Schedule; +import com.sarapis.orservice.entity.ServiceArea; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.UuidGenerator; @@ -26,33 +29,25 @@ public class ServiceAtLocation { @Column(name = "description") private String description; - @OneToMany + @OneToMany(cascade = CascadeType.PERSIST) @JoinColumn(name = "service_at_location_id") private List serviceAreas = new ArrayList<>(); - @OneToMany + @OneToMany(cascade = CascadeType.PERSIST) @JoinColumn(name = "service_at_location_id") private List contacts = new ArrayList<>(); - @OneToMany + @OneToMany(cascade = CascadeType.PERSIST) @JoinColumn(name = "service_at_location_id") private List phones = new ArrayList<>(); - @OneToMany + @OneToMany(cascade = CascadeType.PERSIST) @JoinColumn(name = "service_at_location_id") private List schedules = new ArrayList<>(); - @OneToOne - @JoinColumn(name = "location_id") - private Location location = null; - - @OneToMany - @JoinColumn(name = "link_id") - private List attributes = new ArrayList<>(); - - @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "resource_id") - private List metadata = new ArrayList<>(); + @OneToOne(orphanRemoval = true, optional = false) + @JoinColumn(name = "location_id", nullable = false) + private Location location; public ServiceAtLocationDTO toDTO() { return ServiceAtLocationDTO.builder() @@ -63,8 +58,8 @@ public ServiceAtLocationDTO toDTO() { .phones(this.phones.stream().map(Phone::toDTO).toList()) .schedules(this.schedules.stream().map(Schedule::toDTO).toList()) .location(this.location != null ? this.location.toDTO() : null) - .attributes(this.attributes.stream().map(Attribute::toDTO).toList()) - .metadata(this.metadata.stream().map(Metadata::toDTO).toList()) + .attributes(new ArrayList<>()) + .metadata(new ArrayList<>()) .build(); } } From e9df8f93b9e8b3d72b27ae472a155261e96e17e6 Mon Sep 17 00:00:00 2001 From: ZhangTerrence Date: Sat, 23 Nov 2024 15:37:33 -0500 Subject: [PATCH 20/28] implemented basic CRUD for organizations --- .../controller/OrganizationController.java | 100 ++++++------ .../sarapis/orservice/dto/AttributeDTO.java | 1 + .../sarapis/orservice/dto/MetadataDTO.java | 1 + .../sarapis/orservice/entity/Attribute.java | 1 + .../sarapis/orservice/entity/Metadata.java | 1 + .../repository/AttributeRepository.java | 9 ++ .../repository/MetadataRepository.java | 9 ++ .../repository/OrganizationRepository.java | 2 +- .../service/OrganizationServiceImpl.java | 147 ++++++++++++------ 9 files changed, 167 insertions(+), 104 deletions(-) create mode 100644 src/main/java/com/sarapis/orservice/repository/AttributeRepository.java create mode 100644 src/main/java/com/sarapis/orservice/repository/MetadataRepository.java diff --git a/src/main/java/com/sarapis/orservice/controller/OrganizationController.java b/src/main/java/com/sarapis/orservice/controller/OrganizationController.java index 0ade99e..1ffa999 100644 --- a/src/main/java/com/sarapis/orservice/controller/OrganizationController.java +++ b/src/main/java/com/sarapis/orservice/controller/OrganizationController.java @@ -3,71 +3,63 @@ import com.sarapis.orservice.dto.OrganizationDTO; import com.sarapis.orservice.dto.PaginationDTO; import com.sarapis.orservice.service.OrganizationService; -import java.util.List; -import java.util.UUID; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.UUID; @RestController @RequestMapping("/api/organizations") public class OrganizationController { + private final OrganizationService organizationService; - private final OrganizationService organizationService; - - @Autowired - public OrganizationController(OrganizationService organizationService) { - this.organizationService = organizationService; - } - - @GetMapping - public ResponseEntity> getAllOrganizations() { - List organizations = organizationService.getAllOrganizations(); - PaginationDTO paginationDTO = PaginationDTO.of( - organizations.size(), - 1, - 1, - organizations.size(), - true, - false, - false, - organizations - ); - return ResponseEntity.ok(paginationDTO); - } + @Autowired + public OrganizationController(OrganizationService organizationService) { + this.organizationService = organizationService; + } - @GetMapping("/{id}") - public ResponseEntity getOrganizationById(@PathVariable String id) { - OrganizationDTO organization = organizationService.getOrganizationById(id); - return ResponseEntity.ok(organization); - } + @GetMapping + public ResponseEntity> getAllOrganizations() { + List organizations = organizationService.getAllOrganizations(); + PaginationDTO paginationDTO = PaginationDTO.of( + organizations.size(), + 1, + 1, + organizations.size(), + true, + false, + false, + organizations + ); + return ResponseEntity.ok(paginationDTO); + } - @PostMapping - public ResponseEntity createOrganization(@RequestBody OrganizationDTO organizationDTO) { - if (organizationDTO.getId() == null) { - organizationDTO.setId(UUID.randomUUID().toString()); + @GetMapping("/{id}") + public ResponseEntity getOrganizationById(@PathVariable String id) { + OrganizationDTO organization = organizationService.getOrganizationById(id); + return ResponseEntity.ok(organization); } - OrganizationDTO createdOrganization = organizationService.createOrganization(organizationDTO); - return ResponseEntity.ok(createdOrganization); - } - @PutMapping("/{id}") - public ResponseEntity updateOrganization(@PathVariable String id, @RequestBody OrganizationDTO organizationDTO) { - OrganizationDTO updatedOrganization = organizationService.updateOrganization(id, organizationDTO); - return ResponseEntity.ok(updatedOrganization); - } + @PostMapping + public ResponseEntity createOrganization(@RequestBody OrganizationDTO organizationDTO) { + if (organizationDTO.getId() == null) { + organizationDTO.setId(UUID.randomUUID().toString()); + } + OrganizationDTO createdOrganization = organizationService.createOrganization(organizationDTO); + return ResponseEntity.ok(createdOrganization); + } - @DeleteMapping("/{id}") - public ResponseEntity deleteOrganization(@PathVariable String id) { - organizationService.deleteOrganization(id); - return ResponseEntity.noContent().build(); - } + @PutMapping("/{id}") + public ResponseEntity updateOrganization(@PathVariable String id, @RequestBody OrganizationDTO organizationDTO) { + OrganizationDTO updatedOrganization = organizationService.updateOrganization(id, organizationDTO); + return ResponseEntity.ok(updatedOrganization); + } + @DeleteMapping("/{id}") + public ResponseEntity deleteOrganization(@PathVariable String id) { + organizationService.deleteOrganization(id); + return ResponseEntity.noContent().build(); + } } diff --git a/src/main/java/com/sarapis/orservice/dto/AttributeDTO.java b/src/main/java/com/sarapis/orservice/dto/AttributeDTO.java index e29d4ba..c8e477a 100644 --- a/src/main/java/com/sarapis/orservice/dto/AttributeDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/AttributeDTO.java @@ -14,6 +14,7 @@ @Builder public class AttributeDTO { private String id; + private String linkId; private LinkEntity linkEntity; private String value; private TaxonomyTermDTO taxonomyTerm; diff --git a/src/main/java/com/sarapis/orservice/dto/MetadataDTO.java b/src/main/java/com/sarapis/orservice/dto/MetadataDTO.java index 96fcc9a..e1d17d9 100644 --- a/src/main/java/com/sarapis/orservice/dto/MetadataDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/MetadataDTO.java @@ -13,6 +13,7 @@ @Builder public class MetadataDTO { private String id; + private String resourceId; private ResourceType resourceType; private LocalDate lastActionDate; private String lastActionType; diff --git a/src/main/java/com/sarapis/orservice/entity/Attribute.java b/src/main/java/com/sarapis/orservice/entity/Attribute.java index be840a5..0c2b365 100644 --- a/src/main/java/com/sarapis/orservice/entity/Attribute.java +++ b/src/main/java/com/sarapis/orservice/entity/Attribute.java @@ -44,6 +44,7 @@ public class Attribute { public AttributeDTO toDTO() { return AttributeDTO.builder() .id(this.id) + .linkId(this.linkId) .linkEntity(this.linkEntity) .value(this.value) .taxonomyTerm(this.taxonomyTerm != null ? this.taxonomyTerm.toDTO() : null) diff --git a/src/main/java/com/sarapis/orservice/entity/Metadata.java b/src/main/java/com/sarapis/orservice/entity/Metadata.java index 8052e38..732774d 100644 --- a/src/main/java/com/sarapis/orservice/entity/Metadata.java +++ b/src/main/java/com/sarapis/orservice/entity/Metadata.java @@ -49,6 +49,7 @@ public class Metadata { public MetadataDTO toDTO() { return MetadataDTO.builder() .id(this.id) + .resourceId(this.resourceId) .resourceType(this.resourceType) .lastActionDate(this.lastActionDate) .lastActionType(this.lastActionType) diff --git a/src/main/java/com/sarapis/orservice/repository/AttributeRepository.java b/src/main/java/com/sarapis/orservice/repository/AttributeRepository.java new file mode 100644 index 0000000..ab1dc93 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/repository/AttributeRepository.java @@ -0,0 +1,9 @@ +package com.sarapis.orservice.repository; + +import com.sarapis.orservice.entity.Attribute; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface AttributeRepository extends JpaRepository { +} diff --git a/src/main/java/com/sarapis/orservice/repository/MetadataRepository.java b/src/main/java/com/sarapis/orservice/repository/MetadataRepository.java new file mode 100644 index 0000000..ea36188 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/repository/MetadataRepository.java @@ -0,0 +1,9 @@ +package com.sarapis.orservice.repository; + +import com.sarapis.orservice.entity.Metadata; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface MetadataRepository extends JpaRepository { +} diff --git a/src/main/java/com/sarapis/orservice/repository/OrganizationRepository.java b/src/main/java/com/sarapis/orservice/repository/OrganizationRepository.java index 1210f0a..7131346 100644 --- a/src/main/java/com/sarapis/orservice/repository/OrganizationRepository.java +++ b/src/main/java/com/sarapis/orservice/repository/OrganizationRepository.java @@ -5,5 +5,5 @@ import org.springframework.stereotype.Repository; @Repository -public interface OrganizationRepository extends JpaRepository { +public interface OrganizationRepository extends JpaRepository { } diff --git a/src/main/java/com/sarapis/orservice/service/OrganizationServiceImpl.java b/src/main/java/com/sarapis/orservice/service/OrganizationServiceImpl.java index 19f15f9..90ead21 100644 --- a/src/main/java/com/sarapis/orservice/service/OrganizationServiceImpl.java +++ b/src/main/java/com/sarapis/orservice/service/OrganizationServiceImpl.java @@ -1,61 +1,110 @@ package com.sarapis.orservice.service; +import com.sarapis.orservice.dto.AttributeDTO; +import com.sarapis.orservice.dto.MetadataDTO; import com.sarapis.orservice.dto.OrganizationDTO; +import com.sarapis.orservice.entity.Attribute; +import com.sarapis.orservice.entity.Metadata; import com.sarapis.orservice.entity.core.Organization; +import com.sarapis.orservice.repository.AttributeRepository; +import com.sarapis.orservice.repository.MetadataRepository; import com.sarapis.orservice.repository.OrganizationRepository; -import java.util.List; -import java.util.stream.Collectors; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.List; +import java.util.Objects; + @Service public class OrganizationServiceImpl implements OrganizationService { + private final OrganizationRepository organizationRepository; + private final AttributeRepository attributeRepository; + private final MetadataRepository metadataRepository; + + @Autowired + public OrganizationServiceImpl(OrganizationRepository organizationRepository, AttributeRepository attributeRepository, MetadataRepository metadataRepository) { + this.organizationRepository = organizationRepository; + this.attributeRepository = attributeRepository; + this.metadataRepository = metadataRepository; + } + + @Override + public List getAllOrganizations() { + List organizationDTOs = organizationRepository.findAll().stream().map(Organization::toDTO).toList(); + + organizationDTOs.forEach(this::getRelatedData); + + return organizationDTOs; + } + + @Override + public OrganizationDTO getOrganizationById(String id) { + Organization organization = organizationRepository.findById(id).orElseThrow(() -> new RuntimeException("Organization not found.")); + OrganizationDTO organizationDTO = organization.toDTO(); + + getRelatedData(organizationDTO); + return organizationDTO; + } + + @Override + public OrganizationDTO createOrganization(OrganizationDTO organizationDTO) { + Organization organization = organizationRepository.save(organizationDTO.toEntity()); + + for (AttributeDTO attributeDTO : organizationDTO.getAttributes()) { + attributeRepository.save(attributeDTO.toEntity(organization.getId())); + } + + for (MetadataDTO metadataDTO : organizationDTO.getMetadata()) { + metadataRepository.save(metadataDTO.toEntity(organization.getId())); + } + + OrganizationDTO savedOrganizationDTO = organizationRepository.save(organization).toDTO(); + getRelatedData(savedOrganizationDTO); + return savedOrganizationDTO; + } + + @Override + public OrganizationDTO updateOrganization(String id, OrganizationDTO organizationDTO) { + Organization existingOrganization = organizationRepository.findById(id).orElseThrow(() -> new RuntimeException("Organization not found.")); + existingOrganization.setName(organizationDTO.getName()); + existingOrganization.setAlternateName(organizationDTO.getAlternateName()); + existingOrganization.setDescription(organizationDTO.getDescription()); + existingOrganization.setEmail(organizationDTO.getEmail()); + existingOrganization.setWebsite(organizationDTO.getWebsite()); + existingOrganization.setTaxStatus(organizationDTO.getTaxStatus()); + existingOrganization.setTaxId(organizationDTO.getTaxId()); + existingOrganization.setYearIncorporated(organizationDTO.getYearIncorporated()); + existingOrganization.setLegalStatus(organizationDTO.getLegalStatus()); + existingOrganization.setLogo(organizationDTO.getLogo()); + existingOrganization.setUri(organizationDTO.getUri()); + existingOrganization.setParentOrganization(organizationDTO.getParentOrganization().toEntity()); + Organization updatedOrganization = organizationRepository.save(existingOrganization); + return updatedOrganization.toDTO(); + } + + @Override + public void deleteOrganization(String id) { + Organization organization = organizationRepository.findById(id).orElseThrow(() -> new RuntimeException("Organization not found.")); + + List attributes = attributeRepository.findAll(); + List relatedAttributes = attributes.stream().filter((e) -> Objects.equals(e.getLinkId(), organization.getId())).toList(); + attributeRepository.deleteAll(relatedAttributes); + + List metadatas = metadataRepository.findAll(); + List relatedMetadatas = metadatas.stream().filter((e) -> Objects.equals(e.getResourceId(), organization.getId())).toList(); + metadataRepository.deleteAll(relatedMetadatas); + + organizationRepository.delete(organization); + } + + private void getRelatedData(OrganizationDTO organizationDTO) { + List attributes = attributeRepository.findAll(); + List relatedAttributeDTOs = attributes.stream().filter((e) -> Objects.equals(e.getLinkId(), organizationDTO.getId())).map(Attribute::toDTO).toList(); + + List metadatas = metadataRepository.findAll(); + List relatedMetadataDTOs = metadatas.stream().filter((e) -> Objects.equals(e.getResourceId(), organizationDTO.getId())).map(Metadata::toDTO).toList(); - private final OrganizationRepository organizationRepository; - - @Autowired - public OrganizationServiceImpl(OrganizationRepository organizationRepository) { - this.organizationRepository = organizationRepository; - } - - @Override - public List getAllOrganizations() { - return organizationRepository.findAll().stream() - .map(Organization::toDTO) - .collect(Collectors.toList()); - } - - @Override - public OrganizationDTO getOrganizationById(String id) { - Organization organization = organizationRepository.findById(Long.parseLong(id)) - .orElseThrow(() -> new RuntimeException("Organization not found")); - return organization.toDTO(); - } - - @Override - public OrganizationDTO createOrganization(OrganizationDTO organizationDTO) { - Organization organization = organizationDTO.toEntity(); - Organization savedOrganization = organizationRepository.save(organization); - return savedOrganization.toDTO(); - } - - @Override - public OrganizationDTO updateOrganization(String id, OrganizationDTO organizationDTO) { - Organization existingOrganization = organizationRepository.findById(Long.parseLong(id)) - .orElseThrow(() -> new RuntimeException("Could not find organization")); - existingOrganization.setName(organizationDTO.getName()); - existingOrganization.setAlternateName(organizationDTO.getAlternateName()); - existingOrganization.setDescription(organizationDTO.getDescription()); - existingOrganization.setEmail(organizationDTO.getEmail()); - existingOrganization.setWebsite(organizationDTO.getWebsite()); - Organization updatedOrganization = organizationRepository.save(existingOrganization); - return updatedOrganization.toDTO(); - } - - @Override - public void deleteOrganization(String id) { - Organization organization = organizationRepository.findById(Long.parseLong(id)) - .orElseThrow(() -> new RuntimeException("Could not find organization")); - organizationRepository.delete(organization); - } + organizationDTO.getAttributes().addAll(relatedAttributeDTOs); + organizationDTO.getMetadata().addAll(relatedMetadataDTOs); + } } From 0aa5db82a2264b836aab090d59708b885eb329f9 Mon Sep 17 00:00:00 2001 From: maxgreen01 <69012713+maxgreen01@users.noreply.github.com> Date: Sun, 24 Nov 2024 12:12:48 -0500 Subject: [PATCH 21/28] Added Repository, Service, and Controller for Accessibility. --- .../controller/AccessibilityController.java | 54 ++++++++++++++++ .../repository/AccessibilityRepository.java | 9 +++ .../service/AccessibilityService.java | 17 +++++ .../service/AccessibilityServiceImpl.java | 63 +++++++++++++++++++ 4 files changed, 143 insertions(+) create mode 100644 src/main/java/com/sarapis/orservice/controller/AccessibilityController.java create mode 100644 src/main/java/com/sarapis/orservice/repository/AccessibilityRepository.java create mode 100644 src/main/java/com/sarapis/orservice/service/AccessibilityService.java create mode 100644 src/main/java/com/sarapis/orservice/service/AccessibilityServiceImpl.java diff --git a/src/main/java/com/sarapis/orservice/controller/AccessibilityController.java b/src/main/java/com/sarapis/orservice/controller/AccessibilityController.java new file mode 100644 index 0000000..f7a52e3 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/controller/AccessibilityController.java @@ -0,0 +1,54 @@ +package com.sarapis.orservice.controller; + +import com.sarapis.orservice.dto.AccessibilityDTO; +import com.sarapis.orservice.service.AccessibilityService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.UUID; + +@RestController +@RequestMapping("/api/accessibility") +public class AccessibilityController { + private final AccessibilityService accessibilityService; + + @Autowired + public AccessibilityController(AccessibilityService accessibilityService) { + this.accessibilityService = accessibilityService; + } + + @GetMapping + public ResponseEntity> getAllAccessibilities() { + List accessibilityDTOs = this.accessibilityService.getAllAccessibilities(); + return ResponseEntity.ok(accessibilityDTOs); + } + + @GetMapping("/{id}") + public ResponseEntity getAccessibilityById(@PathVariable String id) { + AccessibilityDTO accessibility = this.accessibilityService.getAccessibilityById(id); + return ResponseEntity.ok(accessibility); + } + + @PostMapping + public ResponseEntity createAccessibility(@RequestBody AccessibilityDTO accessibilityDTO) { + if (accessibilityDTO.getId() == null) { + accessibilityDTO.setId(UUID.randomUUID().toString()); + } + AccessibilityDTO createdAccessibility = this.accessibilityService.createAccessibility(accessibilityDTO); + return ResponseEntity.ok(createdAccessibility); + } + + @PutMapping("/{id}") + public ResponseEntity updateAccessibility(@PathVariable String id, @RequestBody AccessibilityDTO accessibilityDTO) { + AccessibilityDTO updatedAccessibility = this.accessibilityService.updateAccessibility(id, accessibilityDTO); + return ResponseEntity.ok(updatedAccessibility); + } + + @DeleteMapping("/{id}") + public ResponseEntity deleteAccessibility(@PathVariable String id) { + this.accessibilityService.deleteAccessibility(id); + return ResponseEntity.noContent().build(); + } +} \ No newline at end of file diff --git a/src/main/java/com/sarapis/orservice/repository/AccessibilityRepository.java b/src/main/java/com/sarapis/orservice/repository/AccessibilityRepository.java new file mode 100644 index 0000000..eafa172 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/repository/AccessibilityRepository.java @@ -0,0 +1,9 @@ +package com.sarapis.orservice.repository; + +import com.sarapis.orservice.entity.Accessibility; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface AccessibilityRepository extends JpaRepository { +} diff --git a/src/main/java/com/sarapis/orservice/service/AccessibilityService.java b/src/main/java/com/sarapis/orservice/service/AccessibilityService.java new file mode 100644 index 0000000..97badc5 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/service/AccessibilityService.java @@ -0,0 +1,17 @@ +package com.sarapis.orservice.service; + +import com.sarapis.orservice.dto.AccessibilityDTO; + +import java.util.List; + +public interface AccessibilityService { + List getAllAccessibilities(); + + AccessibilityDTO getAccessibilityById(String id); + + AccessibilityDTO createAccessibility(AccessibilityDTO accessibilityDTO); + + AccessibilityDTO updateAccessibility(String id, AccessibilityDTO accessibilityDTO); + + void deleteAccessibility(String id); +} \ No newline at end of file diff --git a/src/main/java/com/sarapis/orservice/service/AccessibilityServiceImpl.java b/src/main/java/com/sarapis/orservice/service/AccessibilityServiceImpl.java new file mode 100644 index 0000000..fee856f --- /dev/null +++ b/src/main/java/com/sarapis/orservice/service/AccessibilityServiceImpl.java @@ -0,0 +1,63 @@ +package com.sarapis.orservice.service; + +import com.sarapis.orservice.dto.AccessibilityDTO; +import com.sarapis.orservice.entity.Accessibility; +import com.sarapis.orservice.repository.AccessibilityRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.stream.Collectors; + +@Service +public class AccessibilityServiceImpl implements AccessibilityService { + + private final AccessibilityRepository accessibilityRepository; + + @Autowired + public AccessibilityServiceImpl(AccessibilityRepository accessibilityRepository) { + this.accessibilityRepository = accessibilityRepository; + } + + @Override + public List getAllAccessibilities() { + return this.accessibilityRepository.findAll() + .stream() + .map(Accessibility::toDTO) + .collect(Collectors.toList()); + } + + @Override + public AccessibilityDTO getAccessibilityById(String id) { + Accessibility accessibility = this.accessibilityRepository.findById(id) + .orElseThrow(() -> new RuntimeException("Accessibility not found")); + return accessibility.toDTO(); + } + + @Override + public AccessibilityDTO createAccessibility(AccessibilityDTO accessibilityDTO) { + Accessibility accessibility = accessibilityDTO.toEntity(); + Accessibility savedAccessibility = this.accessibilityRepository.save(accessibility); + return savedAccessibility.toDTO(); + } + + @Override + public AccessibilityDTO updateAccessibility(String id, AccessibilityDTO accessibilityDTO) { + Accessibility oldAccessibility = this.accessibilityRepository.findById(id) + .orElseThrow(() -> new RuntimeException("Accessibility not found")); + + oldAccessibility.setDescription(accessibilityDTO.getDescription()); + oldAccessibility.setDetails(accessibilityDTO.getDetails()); + oldAccessibility.setUrl(accessibilityDTO.getUrl()); + + Accessibility updatedAccessibility = this.accessibilityRepository.save(oldAccessibility); + return updatedAccessibility.toDTO(); + } + + @Override + public void deleteAccessibility(String id) { + Accessibility target = this.accessibilityRepository.findById(id) + .orElseThrow(() -> new RuntimeException("Accessibility not found")); + this.accessibilityRepository.delete(target); + } +} \ No newline at end of file From 6265a618908e4e88513b066764c57dafef8509ee Mon Sep 17 00:00:00 2001 From: maxgreen01 <69012713+maxgreen01@users.noreply.github.com> Date: Mon, 25 Nov 2024 20:07:31 -0500 Subject: [PATCH 22/28] update Attribute & Metadata saves/deletes based on new system --- .../service/AccessibilityServiceImpl.java | 52 +++++++++++++------ 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/sarapis/orservice/service/AccessibilityServiceImpl.java b/src/main/java/com/sarapis/orservice/service/AccessibilityServiceImpl.java index fee856f..dbd8c6e 100644 --- a/src/main/java/com/sarapis/orservice/service/AccessibilityServiceImpl.java +++ b/src/main/java/com/sarapis/orservice/service/AccessibilityServiceImpl.java @@ -1,63 +1,85 @@ package com.sarapis.orservice.service; +import com.sarapis.orservice.dto.AttributeDTO; +import com.sarapis.orservice.dto.MetadataDTO; import com.sarapis.orservice.dto.AccessibilityDTO; +import com.sarapis.orservice.entity.Attribute; +import com.sarapis.orservice.entity.Metadata; import com.sarapis.orservice.entity.Accessibility; +import com.sarapis.orservice.repository.AttributeRepository; +import com.sarapis.orservice.repository.MetadataRepository; import com.sarapis.orservice.repository.AccessibilityRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; -import java.util.stream.Collectors; +import java.util.Objects; @Service public class AccessibilityServiceImpl implements AccessibilityService { private final AccessibilityRepository accessibilityRepository; + private final AttributeRepository attributeRepository; + private final MetadataRepository metadataRepository; @Autowired - public AccessibilityServiceImpl(AccessibilityRepository accessibilityRepository) { + public AccessibilityServiceImpl(AccessibilityRepository accessibilityRepository, AttributeRepository attributeRepository, MetadataRepository metadataRepository) { this.accessibilityRepository = accessibilityRepository; + this.attributeRepository = attributeRepository; + this.metadataRepository = metadataRepository; } @Override public List getAllAccessibilities() { - return this.accessibilityRepository.findAll() - .stream() - .map(Accessibility::toDTO) - .collect(Collectors.toList()); + return accessibilityRepository.findAll().stream().map(Accessibility::toDTO).toList(); } @Override public AccessibilityDTO getAccessibilityById(String id) { - Accessibility accessibility = this.accessibilityRepository.findById(id) - .orElseThrow(() -> new RuntimeException("Accessibility not found")); + Accessibility accessibility = accessibilityRepository.findById(id).orElseThrow(() -> new RuntimeException("Accessibility not found")); return accessibility.toDTO(); } @Override public AccessibilityDTO createAccessibility(AccessibilityDTO accessibilityDTO) { Accessibility accessibility = accessibilityDTO.toEntity(); - Accessibility savedAccessibility = this.accessibilityRepository.save(accessibility); + + for (AttributeDTO attributeDTO : accessibilityDTO.getAttributes()) { + attributeRepository.save(attributeDTO.toEntity(accessibility.getId())); + } + + for (MetadataDTO metadataDTO : accessibilityDTO.getMetadata()) { + metadataRepository.save(metadataDTO.toEntity(accessibility.getId())); + } + + Accessibility savedAccessibility = accessibilityRepository.save(accessibility); return savedAccessibility.toDTO(); } @Override public AccessibilityDTO updateAccessibility(String id, AccessibilityDTO accessibilityDTO) { - Accessibility oldAccessibility = this.accessibilityRepository.findById(id) - .orElseThrow(() -> new RuntimeException("Accessibility not found")); + Accessibility oldAccessibility = accessibilityRepository.findById(id).orElseThrow(() -> new RuntimeException("Accessibility not found")); oldAccessibility.setDescription(accessibilityDTO.getDescription()); oldAccessibility.setDetails(accessibilityDTO.getDetails()); oldAccessibility.setUrl(accessibilityDTO.getUrl()); - Accessibility updatedAccessibility = this.accessibilityRepository.save(oldAccessibility); + Accessibility updatedAccessibility = accessibilityRepository.save(oldAccessibility); return updatedAccessibility.toDTO(); } @Override public void deleteAccessibility(String id) { - Accessibility target = this.accessibilityRepository.findById(id) - .orElseThrow(() -> new RuntimeException("Accessibility not found")); - this.accessibilityRepository.delete(target); + Accessibility accessibility = accessibilityRepository.findById(id).orElseThrow(() -> new RuntimeException("Accessibility not found")); + + List attributes = attributeRepository.findAll(); + List relatedAttributes = attributes.stream().filter((e) -> Objects.equals(e.getLinkId(), accessibility.getId())).toList(); + attributeRepository.deleteAll(relatedAttributes); + + List metadatas = metadataRepository.findAll(); + List relatedMetadatas = metadatas.stream().filter((e) -> Objects.equals(e.getResourceId(), accessibility.getId())).toList(); + metadataRepository.deleteAll(relatedMetadatas); + + accessibilityRepository.delete(accessibility); } } \ No newline at end of file From 2ca2e3dfbfe6ba84ec70a998100abf9ceca79188 Mon Sep 17 00:00:00 2001 From: ZhangTerrence Date: Thu, 28 Nov 2024 16:15:49 -0500 Subject: [PATCH 23/28] resolved merge conflicts --- .../controller/AccessibilityController.java | 2 +- .../controller/AddressController.java | 2 +- .../controller/AttributeController.java | 2 +- .../sarapis/orservice/dto/AttributeDTO.java | 2 + .../sarapis/orservice/entity/Attribute.java | 2 +- .../repository/AddressRepository.java | 2 +- .../repository/AttributeRepository.java | 2 +- .../service/AccessibilityServiceImpl.java | 58 +++++++++----- .../orservice/service/AddressServiceImpl.java | 74 +++++++++++++---- .../service/AttributeServiceImpl.java | 80 ++++++++++++------- .../service/OrganizationServiceImpl.java | 64 ++++++++------- 11 files changed, 188 insertions(+), 102 deletions(-) diff --git a/src/main/java/com/sarapis/orservice/controller/AccessibilityController.java b/src/main/java/com/sarapis/orservice/controller/AccessibilityController.java index f7a52e3..29cbcdd 100644 --- a/src/main/java/com/sarapis/orservice/controller/AccessibilityController.java +++ b/src/main/java/com/sarapis/orservice/controller/AccessibilityController.java @@ -10,7 +10,7 @@ import java.util.UUID; @RestController -@RequestMapping("/api/accessibility") +@RequestMapping("/api/accessibilities") public class AccessibilityController { private final AccessibilityService accessibilityService; diff --git a/src/main/java/com/sarapis/orservice/controller/AddressController.java b/src/main/java/com/sarapis/orservice/controller/AddressController.java index 39bdf81..f0e60d6 100644 --- a/src/main/java/com/sarapis/orservice/controller/AddressController.java +++ b/src/main/java/com/sarapis/orservice/controller/AddressController.java @@ -9,7 +9,7 @@ import java.util.List; @RestController -@RequestMapping("/api/address") +@RequestMapping("/api/addresses") public class AddressController { public final AddressService addressService; diff --git a/src/main/java/com/sarapis/orservice/controller/AttributeController.java b/src/main/java/com/sarapis/orservice/controller/AttributeController.java index ee27502..5f5f7f5 100644 --- a/src/main/java/com/sarapis/orservice/controller/AttributeController.java +++ b/src/main/java/com/sarapis/orservice/controller/AttributeController.java @@ -9,7 +9,7 @@ import java.util.List; @RestController -@RequestMapping("/api/attribute") +@RequestMapping("/api/attributes") public class AttributeController { private final AttributeService attributeService; diff --git a/src/main/java/com/sarapis/orservice/dto/AttributeDTO.java b/src/main/java/com/sarapis/orservice/dto/AttributeDTO.java index c8e477a..6deae5c 100644 --- a/src/main/java/com/sarapis/orservice/dto/AttributeDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/AttributeDTO.java @@ -15,6 +15,7 @@ public class AttributeDTO { private String id; private String linkId; + private String linkType; private LinkEntity linkEntity; private String value; private TaxonomyTermDTO taxonomyTerm; @@ -25,6 +26,7 @@ public Attribute toEntity(String linkId) { return Attribute.builder() .id(this.id) .linkId(linkId) + .linkType(this.linkType) .linkEntity(this.linkEntity) .value(this.value) .taxonomyTerm(this.taxonomyTerm.toEntity()) diff --git a/src/main/java/com/sarapis/orservice/entity/Attribute.java b/src/main/java/com/sarapis/orservice/entity/Attribute.java index 0c2b365..53adbed 100644 --- a/src/main/java/com/sarapis/orservice/entity/Attribute.java +++ b/src/main/java/com/sarapis/orservice/entity/Attribute.java @@ -34,7 +34,7 @@ public class Attribute { @Column(name = "value") private String value; - @OneToOne(orphanRemoval = true, optional = false) + @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, optional = false) @JoinColumn(name = "taxonomy_term_id", nullable = false) private TaxonomyTerm taxonomyTerm; diff --git a/src/main/java/com/sarapis/orservice/repository/AddressRepository.java b/src/main/java/com/sarapis/orservice/repository/AddressRepository.java index b19c2e8..8dbbed1 100644 --- a/src/main/java/com/sarapis/orservice/repository/AddressRepository.java +++ b/src/main/java/com/sarapis/orservice/repository/AddressRepository.java @@ -5,5 +5,5 @@ import org.springframework.stereotype.Repository; @Repository -public interface AddressRepository extends JpaRepository { +public interface AddressRepository extends JpaRepository { } diff --git a/src/main/java/com/sarapis/orservice/repository/AttributeRepository.java b/src/main/java/com/sarapis/orservice/repository/AttributeRepository.java index 88b026d..ab1dc93 100644 --- a/src/main/java/com/sarapis/orservice/repository/AttributeRepository.java +++ b/src/main/java/com/sarapis/orservice/repository/AttributeRepository.java @@ -5,5 +5,5 @@ import org.springframework.stereotype.Repository; @Repository -public interface AttributeRepository extends JpaRepository { +public interface AttributeRepository extends JpaRepository { } diff --git a/src/main/java/com/sarapis/orservice/service/AccessibilityServiceImpl.java b/src/main/java/com/sarapis/orservice/service/AccessibilityServiceImpl.java index dbd8c6e..d4761fe 100644 --- a/src/main/java/com/sarapis/orservice/service/AccessibilityServiceImpl.java +++ b/src/main/java/com/sarapis/orservice/service/AccessibilityServiceImpl.java @@ -1,14 +1,14 @@ package com.sarapis.orservice.service; +import com.sarapis.orservice.dto.AccessibilityDTO; import com.sarapis.orservice.dto.AttributeDTO; import com.sarapis.orservice.dto.MetadataDTO; -import com.sarapis.orservice.dto.AccessibilityDTO; +import com.sarapis.orservice.entity.Accessibility; import com.sarapis.orservice.entity.Attribute; import com.sarapis.orservice.entity.Metadata; -import com.sarapis.orservice.entity.Accessibility; +import com.sarapis.orservice.repository.AccessibilityRepository; import com.sarapis.orservice.repository.AttributeRepository; import com.sarapis.orservice.repository.MetadataRepository; -import com.sarapis.orservice.repository.AccessibilityRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -17,7 +17,6 @@ @Service public class AccessibilityServiceImpl implements AccessibilityService { - private final AccessibilityRepository accessibilityRepository; private final AttributeRepository attributeRepository; private final MetadataRepository metadataRepository; @@ -31,55 +30,74 @@ public AccessibilityServiceImpl(AccessibilityRepository accessibilityRepository, @Override public List getAllAccessibilities() { - return accessibilityRepository.findAll().stream().map(Accessibility::toDTO).toList(); + List accessibilityDTOs = this.accessibilityRepository.findAll().stream().map(Accessibility::toDTO).toList(); + accessibilityDTOs.forEach(this::getRelatedData); + return accessibilityDTOs; } @Override public AccessibilityDTO getAccessibilityById(String id) { - Accessibility accessibility = accessibilityRepository.findById(id).orElseThrow(() -> new RuntimeException("Accessibility not found")); - return accessibility.toDTO(); + Accessibility accessibility = this.accessibilityRepository.findById(id) + .orElseThrow(() -> new RuntimeException("Accessibility not found.")); + AccessibilityDTO accessibilityDTO = accessibility.toDTO(); + getRelatedData(accessibilityDTO); + return accessibilityDTO; } @Override public AccessibilityDTO createAccessibility(AccessibilityDTO accessibilityDTO) { - Accessibility accessibility = accessibilityDTO.toEntity(); + Accessibility accessibility = this.accessibilityRepository.save(accessibilityDTO.toEntity()); for (AttributeDTO attributeDTO : accessibilityDTO.getAttributes()) { - attributeRepository.save(attributeDTO.toEntity(accessibility.getId())); + this.attributeRepository.save(attributeDTO.toEntity(accessibility.getId())); } for (MetadataDTO metadataDTO : accessibilityDTO.getMetadata()) { - metadataRepository.save(metadataDTO.toEntity(accessibility.getId())); + this.metadataRepository.save(metadataDTO.toEntity(accessibility.getId())); } - Accessibility savedAccessibility = accessibilityRepository.save(accessibility); - return savedAccessibility.toDTO(); + AccessibilityDTO savedAccessibilityDTO = this.accessibilityRepository.save(accessibility).toDTO(); + getRelatedData(savedAccessibilityDTO); + return savedAccessibilityDTO; } @Override public AccessibilityDTO updateAccessibility(String id, AccessibilityDTO accessibilityDTO) { - Accessibility oldAccessibility = accessibilityRepository.findById(id).orElseThrow(() -> new RuntimeException("Accessibility not found")); + Accessibility oldAccessibility = this.accessibilityRepository.findById(id) + .orElseThrow(() -> new RuntimeException("Accessibility not found.")); oldAccessibility.setDescription(accessibilityDTO.getDescription()); oldAccessibility.setDetails(accessibilityDTO.getDetails()); oldAccessibility.setUrl(accessibilityDTO.getUrl()); - Accessibility updatedAccessibility = accessibilityRepository.save(oldAccessibility); + Accessibility updatedAccessibility = this.accessibilityRepository.save(oldAccessibility); return updatedAccessibility.toDTO(); } @Override public void deleteAccessibility(String id) { - Accessibility accessibility = accessibilityRepository.findById(id).orElseThrow(() -> new RuntimeException("Accessibility not found")); + Accessibility accessibility = this.accessibilityRepository.findById(id) + .orElseThrow(() -> new RuntimeException("Accessibility not found.")); - List attributes = attributeRepository.findAll(); + List attributes = this.attributeRepository.findAll(); List relatedAttributes = attributes.stream().filter((e) -> Objects.equals(e.getLinkId(), accessibility.getId())).toList(); - attributeRepository.deleteAll(relatedAttributes); + this.attributeRepository.deleteAll(relatedAttributes); - List metadatas = metadataRepository.findAll(); + List metadatas = this.metadataRepository.findAll(); List relatedMetadatas = metadatas.stream().filter((e) -> Objects.equals(e.getResourceId(), accessibility.getId())).toList(); - metadataRepository.deleteAll(relatedMetadatas); + this.metadataRepository.deleteAll(relatedMetadatas); + + this.accessibilityRepository.delete(accessibility); + } + + private void getRelatedData(AccessibilityDTO accessibilityDTO) { + List attributes = this.attributeRepository.findAll(); + List relatedAttributeDTOs = attributes.stream().filter((e) -> Objects.equals(e.getLinkId(), accessibilityDTO.getId())).map(Attribute::toDTO).toList(); + + List metadatas = this.metadataRepository.findAll(); + List relatedMetadataDTOs = metadatas.stream().filter((e) -> Objects.equals(e.getResourceId(), accessibilityDTO.getId())).map(Metadata::toDTO).toList(); - accessibilityRepository.delete(accessibility); + accessibilityDTO.getAttributes().addAll(relatedAttributeDTOs); + accessibilityDTO.getMetadata().addAll(relatedMetadataDTOs); } } \ No newline at end of file diff --git a/src/main/java/com/sarapis/orservice/service/AddressServiceImpl.java b/src/main/java/com/sarapis/orservice/service/AddressServiceImpl.java index a77ac91..e79301d 100644 --- a/src/main/java/com/sarapis/orservice/service/AddressServiceImpl.java +++ b/src/main/java/com/sarapis/orservice/service/AddressServiceImpl.java @@ -1,46 +1,68 @@ package com.sarapis.orservice.service; import com.sarapis.orservice.dto.AddressDTO; +import com.sarapis.orservice.dto.AttributeDTO; +import com.sarapis.orservice.dto.MetadataDTO; import com.sarapis.orservice.entity.Address; +import com.sarapis.orservice.entity.Attribute; +import com.sarapis.orservice.entity.Metadata; import com.sarapis.orservice.repository.AddressRepository; +import com.sarapis.orservice.repository.AttributeRepository; +import com.sarapis.orservice.repository.MetadataRepository; import org.springframework.stereotype.Service; import java.util.List; -import java.util.stream.Collectors; +import java.util.Objects; @Service public class AddressServiceImpl implements AddressService { private final AddressRepository addressRepository; + private final AttributeRepository attributeRepository; + private final MetadataRepository metadataRepository; - public AddressServiceImpl(AddressRepository addressRepository) { + public AddressServiceImpl(AddressRepository addressRepository, AttributeRepository attributeRepository, MetadataRepository metadataRepository) { this.addressRepository = addressRepository; + this.attributeRepository = attributeRepository; + this.metadataRepository = metadataRepository; } @Override public List getAllAddresses() { - return this.addressRepository.findAll().stream() - .map(Address::toDTO) - .collect(Collectors.toList()); + List addressDTOs = this.addressRepository.findAll().stream().map(Address::toDTO).toList(); + addressDTOs.forEach(this::getRelatedData); + return addressDTOs; } @Override public AddressDTO getAddressById(String id) { - Address address = this.addressRepository.findById(Long.parseLong(id)) - .orElseThrow(() -> new RuntimeException("Address not found")); - return address.toDTO(); + Address address = this.addressRepository.findById(id) + .orElseThrow(() -> new RuntimeException("Address not found.")); + AddressDTO addressDTO = address.toDTO(); + getRelatedData(addressDTO); + return addressDTO; } @Override public AddressDTO createAddress(AddressDTO addressDTO) { - Address address = addressDTO.toEntity(); - Address savedAddress = this.addressRepository.save(address); - return savedAddress.toDTO(); + Address address = this.addressRepository.save(addressDTO.toEntity()); + + for (AttributeDTO attributeDTO : addressDTO.getAttributes()) { + this.attributeRepository.save(attributeDTO.toEntity(address.getId())); + } + + for (MetadataDTO metadataDTO : addressDTO.getMetadata()) { + this.metadataRepository.save(metadataDTO.toEntity(address.getId())); + } + + AddressDTO savedAddressDTO = this.addressRepository.save(address).toDTO(); + getRelatedData(savedAddressDTO); + return savedAddressDTO; } @Override public AddressDTO updateAddress(String id, AddressDTO addressDTO) { - Address oldAddress = this.addressRepository.findById(Long.parseLong(id)) - .orElseThrow(() -> new RuntimeException("Address not found")); + Address oldAddress = this.addressRepository.findById(id) + .orElseThrow(() -> new RuntimeException("Address not found.")); oldAddress.setAttention(addressDTO.getAttention()); oldAddress.setAddress_1(addressDTO.getAddress_1()); @@ -58,8 +80,28 @@ public AddressDTO updateAddress(String id, AddressDTO addressDTO) { @Override public void deleteAddress(String id) { - Address target = this.addressRepository.findById(Long.parseLong(id)) - .orElseThrow(() -> new RuntimeException("Address not found")); - this.addressRepository.delete(target); + Address address = this.addressRepository.findById(id) + .orElseThrow(() -> new RuntimeException("Address not found.")); + + List attributes = this.attributeRepository.findAll(); + List relatedAttributes = attributes.stream().filter((e) -> Objects.equals(e.getLinkId(), address.getId())).toList(); + this.attributeRepository.deleteAll(relatedAttributes); + + List metadatas = this.metadataRepository.findAll(); + List relatedMetadatas = metadatas.stream().filter((e) -> Objects.equals(e.getResourceId(), address.getId())).toList(); + this.metadataRepository.deleteAll(relatedMetadatas); + + this.addressRepository.delete(address); + } + + private void getRelatedData(AddressDTO addressDTO) { + List attributes = this.attributeRepository.findAll(); + List relatedAttributeDTOs = attributes.stream().filter((e) -> Objects.equals(e.getLinkId(), addressDTO.getId())).map(Attribute::toDTO).toList(); + + List metadatas = this.metadataRepository.findAll(); + List relatedMetadataDTOs = metadatas.stream().filter((e) -> Objects.equals(e.getResourceId(), addressDTO.getId())).map(Metadata::toDTO).toList(); + + addressDTO.getAttributes().addAll(relatedAttributeDTOs); + addressDTO.getMetadata().addAll(relatedMetadataDTOs); } } diff --git a/src/main/java/com/sarapis/orservice/service/AttributeServiceImpl.java b/src/main/java/com/sarapis/orservice/service/AttributeServiceImpl.java index d41817e..2fd17c6 100644 --- a/src/main/java/com/sarapis/orservice/service/AttributeServiceImpl.java +++ b/src/main/java/com/sarapis/orservice/service/AttributeServiceImpl.java @@ -3,69 +3,91 @@ import com.sarapis.orservice.dto.AttributeDTO; import com.sarapis.orservice.dto.MetadataDTO; import com.sarapis.orservice.entity.Attribute; +import com.sarapis.orservice.entity.Metadata; import com.sarapis.orservice.repository.AttributeRepository; +import com.sarapis.orservice.repository.MetadataRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; -import java.util.stream.Collectors; +import java.util.Objects; @Service public class AttributeServiceImpl implements AttributeService { - private final AttributeRepository attributeRepository; + private final MetadataRepository metadataRepository; @Autowired - public AttributeServiceImpl(AttributeRepository attributeRepository) { + public AttributeServiceImpl(AttributeRepository attributeRepository, MetadataRepository metadataRepository) { this.attributeRepository = attributeRepository; + this.metadataRepository = metadataRepository; } @Override public List getAllAttributes() { - return this.attributeRepository.findAll() + List attributeDTOs = this.attributeRepository.findAll() .stream() .map(Attribute::toDTO) - .collect(Collectors.toList()); + .toList(); + attributeDTOs.forEach(this::getRelatedData); + + return attributeDTOs; } @Override public AttributeDTO getAttributeById(String id) { - Attribute attr = this.attributeRepository.findById(Long.parseLong(id)) - .orElseThrow(() -> new RuntimeException("Attribute not found")); - return attr.toDTO(); + Attribute attribute = this.attributeRepository.findById(id) + .orElseThrow(() -> new RuntimeException("Attribute not found.")); + AttributeDTO attributeDTO = attribute.toDTO(); + this.getRelatedData(attributeDTO); + return attributeDTO; } @Override public AttributeDTO createAttribute(AttributeDTO attributeDTO) { - Attribute attr = attributeDTO.toEntity(); - Attribute savedAttr = this.attributeRepository.save(attr); + Attribute attribute = this.attributeRepository.save(attributeDTO.toEntity(attributeDTO.getLinkId())); + + for (MetadataDTO metadataDTO : attributeDTO.getMetadata()) { + this.metadataRepository.save(metadataDTO.toEntity(attribute.getId())); + } + + Attribute savedAttr = this.attributeRepository.save(attribute); + getRelatedData(attributeDTO); return savedAttr.toDTO(); } @Override public AttributeDTO updateAttribute(String id, AttributeDTO attributeDTO) { - Attribute oldAttr = this.attributeRepository.findById(Long.parseLong(id)) - .orElseThrow(() -> new RuntimeException("Attribute not found")); - - //oldAttr.setLinkType(attributeDTO.getLinkType()); - oldAttr.setLinkEntity(attributeDTO.getLinkEntity()); - oldAttr.setValue(attributeDTO.getValue()); - oldAttr.setTaxonomyTerm(attributeDTO.getTaxonomyTerm().toEntity()); - - oldAttr.setMetadata(attributeDTO.getMetadata().stream() - .map(MetadataDTO::toEntity) - .collect(Collectors.toList()) - ); - oldAttr.setLabel(attributeDTO.getLabel()); - - Attribute upAttr = this.attributeRepository.save(oldAttr); - return upAttr.toDTO(); + Attribute oldAttribute = this.attributeRepository.findById(id) + .orElseThrow(() -> new RuntimeException("Attribute not found.")); + + oldAttribute.setLinkId(attributeDTO.getLinkId()); + oldAttribute.setLinkType(attributeDTO.getLinkType()); + oldAttribute.setLinkEntity(attributeDTO.getLinkEntity()); + oldAttribute.setValue(attributeDTO.getValue()); + oldAttribute.setTaxonomyTerm(attributeDTO.getTaxonomyTerm().toEntity()); + oldAttribute.setLabel(attributeDTO.getLabel()); + + Attribute updatedAttribute = this.attributeRepository.save(oldAttribute); + return updatedAttribute.toDTO(); } @Override public void deleteAttribute(String id) { - Attribute target = this.attributeRepository.findById(Long.parseLong(id)) - .orElseThrow(() -> new RuntimeException("Attribute not found")); - this.attributeRepository.delete(target); + Attribute attribute = this.attributeRepository.findById(id) + .orElseThrow(() -> new RuntimeException("Attribute not found.")); + + List metadatas = metadataRepository.findAll(); + List relatedMetadatas = metadatas.stream().filter((e) -> Objects.equals(e.getResourceId(), attribute.getId())).toList(); + this.metadataRepository.deleteAll(relatedMetadatas); + + this.attributeRepository.delete(attribute); + } + + private void getRelatedData(AttributeDTO attributeDTO) { + List metadatas = this.metadataRepository.findAll(); + List relatedMetadataDTOs = metadatas.stream().filter((e) -> Objects.equals(e.getResourceId(), attributeDTO.getId())).map(Metadata::toDTO).toList(); + + attributeDTO.getMetadata().addAll(relatedMetadataDTOs); } } diff --git a/src/main/java/com/sarapis/orservice/service/OrganizationServiceImpl.java b/src/main/java/com/sarapis/orservice/service/OrganizationServiceImpl.java index 90ead21..0c52c0d 100644 --- a/src/main/java/com/sarapis/orservice/service/OrganizationServiceImpl.java +++ b/src/main/java/com/sarapis/orservice/service/OrganizationServiceImpl.java @@ -30,78 +30,80 @@ public OrganizationServiceImpl(OrganizationRepository organizationRepository, At @Override public List getAllOrganizations() { - List organizationDTOs = organizationRepository.findAll().stream().map(Organization::toDTO).toList(); - + List organizationDTOs = this.organizationRepository.findAll().stream().map(Organization::toDTO).toList(); organizationDTOs.forEach(this::getRelatedData); - return organizationDTOs; } @Override public OrganizationDTO getOrganizationById(String id) { - Organization organization = organizationRepository.findById(id).orElseThrow(() -> new RuntimeException("Organization not found.")); + Organization organization = this.organizationRepository.findById(id) + .orElseThrow(() -> new RuntimeException("Organization not found.")); OrganizationDTO organizationDTO = organization.toDTO(); - getRelatedData(organizationDTO); return organizationDTO; } @Override public OrganizationDTO createOrganization(OrganizationDTO organizationDTO) { - Organization organization = organizationRepository.save(organizationDTO.toEntity()); + Organization organization = this.organizationRepository.save(organizationDTO.toEntity()); for (AttributeDTO attributeDTO : organizationDTO.getAttributes()) { - attributeRepository.save(attributeDTO.toEntity(organization.getId())); + this.attributeRepository.save(attributeDTO.toEntity(organization.getId())); } for (MetadataDTO metadataDTO : organizationDTO.getMetadata()) { - metadataRepository.save(metadataDTO.toEntity(organization.getId())); + this.metadataRepository.save(metadataDTO.toEntity(organization.getId())); } - OrganizationDTO savedOrganizationDTO = organizationRepository.save(organization).toDTO(); + OrganizationDTO savedOrganizationDTO = this.organizationRepository.save(organization).toDTO(); getRelatedData(savedOrganizationDTO); return savedOrganizationDTO; } @Override public OrganizationDTO updateOrganization(String id, OrganizationDTO organizationDTO) { - Organization existingOrganization = organizationRepository.findById(id).orElseThrow(() -> new RuntimeException("Organization not found.")); - existingOrganization.setName(organizationDTO.getName()); - existingOrganization.setAlternateName(organizationDTO.getAlternateName()); - existingOrganization.setDescription(organizationDTO.getDescription()); - existingOrganization.setEmail(organizationDTO.getEmail()); - existingOrganization.setWebsite(organizationDTO.getWebsite()); - existingOrganization.setTaxStatus(organizationDTO.getTaxStatus()); - existingOrganization.setTaxId(organizationDTO.getTaxId()); - existingOrganization.setYearIncorporated(organizationDTO.getYearIncorporated()); - existingOrganization.setLegalStatus(organizationDTO.getLegalStatus()); - existingOrganization.setLogo(organizationDTO.getLogo()); - existingOrganization.setUri(organizationDTO.getUri()); - existingOrganization.setParentOrganization(organizationDTO.getParentOrganization().toEntity()); - Organization updatedOrganization = organizationRepository.save(existingOrganization); + Organization organization = this.organizationRepository.findById(id) + .orElseThrow(() -> new RuntimeException("Organization not found.")); + + organization.setName(organizationDTO.getName()); + organization.setAlternateName(organizationDTO.getAlternateName()); + organization.setDescription(organizationDTO.getDescription()); + organization.setEmail(organizationDTO.getEmail()); + organization.setWebsite(organizationDTO.getWebsite()); + organization.setTaxStatus(organizationDTO.getTaxStatus()); + organization.setTaxId(organizationDTO.getTaxId()); + organization.setYearIncorporated(organizationDTO.getYearIncorporated()); + organization.setLegalStatus(organizationDTO.getLegalStatus()); + organization.setLogo(organizationDTO.getLogo()); + organization.setUri(organizationDTO.getUri()); + organization.setParentOrganization(organizationDTO.getParentOrganization().toEntity()); + + Organization updatedOrganization = this.organizationRepository.save(organization); return updatedOrganization.toDTO(); } @Override public void deleteOrganization(String id) { - Organization organization = organizationRepository.findById(id).orElseThrow(() -> new RuntimeException("Organization not found.")); + Organization organization = this.organizationRepository.findById(id) + .orElseThrow(() -> new RuntimeException("Organization not found.")); - List attributes = attributeRepository.findAll(); + List attributes = this.attributeRepository.findAll(); List relatedAttributes = attributes.stream().filter((e) -> Objects.equals(e.getLinkId(), organization.getId())).toList(); - attributeRepository.deleteAll(relatedAttributes); + this.attributeRepository.deleteAll(relatedAttributes); - List metadatas = metadataRepository.findAll(); + List metadatas = this.metadataRepository.findAll(); List relatedMetadatas = metadatas.stream().filter((e) -> Objects.equals(e.getResourceId(), organization.getId())).toList(); - metadataRepository.deleteAll(relatedMetadatas); + this.metadataRepository.deleteAll(relatedMetadatas); - organizationRepository.delete(organization); + this.organizationRepository.delete(organization); } private void getRelatedData(OrganizationDTO organizationDTO) { - List attributes = attributeRepository.findAll(); + List attributes = this.attributeRepository.findAll(); List relatedAttributeDTOs = attributes.stream().filter((e) -> Objects.equals(e.getLinkId(), organizationDTO.getId())).map(Attribute::toDTO).toList(); - List metadatas = metadataRepository.findAll(); + List metadatas = this.metadataRepository.findAll(); List relatedMetadataDTOs = metadatas.stream().filter((e) -> Objects.equals(e.getResourceId(), organizationDTO.getId())).map(Metadata::toDTO).toList(); organizationDTO.getAttributes().addAll(relatedAttributeDTOs); From db7dd5e510a2953b02d8c0aa94574b230100e11c Mon Sep 17 00:00:00 2001 From: ZhangTerrence Date: Tue, 3 Dec 2024 12:59:34 -0500 Subject: [PATCH 24/28] implemented custom repo queries --- .../repository/AccessibilityRepository.java | 22 ++++++++++++ .../repository/AddressRepository.java | 22 ++++++++++++ .../repository/AttributeRepository.java | 13 +++++++ .../repository/OrganizationRepository.java | 22 ++++++++++++ .../ServiceAtLocationRepository.java | 2 +- .../repository/ServiceRepository.java | 2 +- .../repository/TaxonomyRepository.java | 2 +- .../repository/TaxonomyTermRepository.java | 2 +- .../service/AccessibilityServiceImpl.java | 33 ++++++------------ .../orservice/service/AddressServiceImpl.java | 33 ++++++------------ .../service/AttributeServiceImpl.java | 30 ++++------------ .../service/OrganizationServiceImpl.java | 34 ++++++------------- 12 files changed, 120 insertions(+), 97 deletions(-) diff --git a/src/main/java/com/sarapis/orservice/repository/AccessibilityRepository.java b/src/main/java/com/sarapis/orservice/repository/AccessibilityRepository.java index eafa172..108357a 100644 --- a/src/main/java/com/sarapis/orservice/repository/AccessibilityRepository.java +++ b/src/main/java/com/sarapis/orservice/repository/AccessibilityRepository.java @@ -1,9 +1,31 @@ package com.sarapis.orservice.repository; import com.sarapis.orservice.entity.Accessibility; +import com.sarapis.orservice.entity.Attribute; +import com.sarapis.orservice.entity.Metadata; +import jakarta.transaction.Transactional; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface AccessibilityRepository extends JpaRepository { + @Query("SELECT new Attribute(id, linkId, linkType, linkEntity, value, taxonomyTerm, label) FROM Attribute WHERE linkId = ?1") + List getAttributes(String organizationId); + + @Query("SELECT new Metadata(id, resourceId, resourceType, lastActionDate, lastActionType, fieldName, previousValue, replacementValue, updatedBy) FROM Metadata WHERE resourceId = ?1") + List getMetadata(String organizationId); + + @Modifying + @Transactional + @Query("DELETE FROM Attribute WHERE linkId = ?1") + void deleteAttributes(String organizationId); + + @Modifying + @Transactional + @Query("DELETE FROM Metadata WHERE resourceId = ?1") + void deleteMetadata(String organizationId); } diff --git a/src/main/java/com/sarapis/orservice/repository/AddressRepository.java b/src/main/java/com/sarapis/orservice/repository/AddressRepository.java index 8dbbed1..e538c5f 100644 --- a/src/main/java/com/sarapis/orservice/repository/AddressRepository.java +++ b/src/main/java/com/sarapis/orservice/repository/AddressRepository.java @@ -1,9 +1,31 @@ package com.sarapis.orservice.repository; import com.sarapis.orservice.entity.Address; +import com.sarapis.orservice.entity.Attribute; +import com.sarapis.orservice.entity.Metadata; +import jakarta.transaction.Transactional; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface AddressRepository extends JpaRepository { + @Query("SELECT new Attribute(id, linkId, linkType, linkEntity, value, taxonomyTerm, label) FROM Attribute WHERE linkId = ?1") + List getAttributes(String organizationId); + + @Query("SELECT new Metadata(id, resourceId, resourceType, lastActionDate, lastActionType, fieldName, previousValue, replacementValue, updatedBy) FROM Metadata WHERE resourceId = ?1") + List getMetadata(String organizationId); + + @Modifying + @Transactional + @Query("DELETE FROM Attribute WHERE linkId = ?1") + void deleteAttributes(String organizationId); + + @Modifying + @Transactional + @Query("DELETE FROM Metadata WHERE resourceId = ?1") + void deleteMetadata(String organizationId); } diff --git a/src/main/java/com/sarapis/orservice/repository/AttributeRepository.java b/src/main/java/com/sarapis/orservice/repository/AttributeRepository.java index ab1dc93..4517c26 100644 --- a/src/main/java/com/sarapis/orservice/repository/AttributeRepository.java +++ b/src/main/java/com/sarapis/orservice/repository/AttributeRepository.java @@ -1,9 +1,22 @@ package com.sarapis.orservice.repository; import com.sarapis.orservice.entity.Attribute; +import com.sarapis.orservice.entity.Metadata; +import jakarta.transaction.Transactional; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface AttributeRepository extends JpaRepository { + @Query("SELECT new Metadata(id, resourceId, resourceType, lastActionDate, lastActionType, fieldName, previousValue, replacementValue, updatedBy) FROM Metadata WHERE resourceId = ?1") + List getMetadata(String organizationId); + + @Modifying + @Transactional + @Query("DELETE FROM Metadata WHERE resourceId = ?1") + void deleteMetadata(String organizationId); } diff --git a/src/main/java/com/sarapis/orservice/repository/OrganizationRepository.java b/src/main/java/com/sarapis/orservice/repository/OrganizationRepository.java index 7131346..dff0628 100644 --- a/src/main/java/com/sarapis/orservice/repository/OrganizationRepository.java +++ b/src/main/java/com/sarapis/orservice/repository/OrganizationRepository.java @@ -1,9 +1,31 @@ package com.sarapis.orservice.repository; +import com.sarapis.orservice.entity.Attribute; +import com.sarapis.orservice.entity.Metadata; import com.sarapis.orservice.entity.core.Organization; +import jakarta.transaction.Transactional; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface OrganizationRepository extends JpaRepository { + @Query("SELECT new Attribute(id, linkId, linkType, linkEntity, value, taxonomyTerm, label) FROM Attribute WHERE linkId = ?1") + List getAttributes(String organizationId); + + @Query("SELECT new Metadata(id, resourceId, resourceType, lastActionDate, lastActionType, fieldName, previousValue, replacementValue, updatedBy) FROM Metadata WHERE resourceId = ?1") + List getMetadata(String organizationId); + + @Modifying + @Transactional + @Query("DELETE FROM Attribute WHERE linkId = ?1") + void deleteAttributes(String organizationId); + + @Modifying + @Transactional + @Query("DELETE FROM Metadata WHERE resourceId = ?1") + void deleteMetadata(String organizationId); } diff --git a/src/main/java/com/sarapis/orservice/repository/ServiceAtLocationRepository.java b/src/main/java/com/sarapis/orservice/repository/ServiceAtLocationRepository.java index 4eee34f..f9e9f1b 100644 --- a/src/main/java/com/sarapis/orservice/repository/ServiceAtLocationRepository.java +++ b/src/main/java/com/sarapis/orservice/repository/ServiceAtLocationRepository.java @@ -5,5 +5,5 @@ import org.springframework.stereotype.Repository; @Repository -public interface ServiceAtLocationRepository extends JpaRepository { +public interface ServiceAtLocationRepository extends JpaRepository { } diff --git a/src/main/java/com/sarapis/orservice/repository/ServiceRepository.java b/src/main/java/com/sarapis/orservice/repository/ServiceRepository.java index f426418..01dce0f 100644 --- a/src/main/java/com/sarapis/orservice/repository/ServiceRepository.java +++ b/src/main/java/com/sarapis/orservice/repository/ServiceRepository.java @@ -5,5 +5,5 @@ import org.springframework.stereotype.Repository; @Repository -public interface ServiceRepository extends JpaRepository { +public interface ServiceRepository extends JpaRepository { } diff --git a/src/main/java/com/sarapis/orservice/repository/TaxonomyRepository.java b/src/main/java/com/sarapis/orservice/repository/TaxonomyRepository.java index c0df50a..a2ef859 100644 --- a/src/main/java/com/sarapis/orservice/repository/TaxonomyRepository.java +++ b/src/main/java/com/sarapis/orservice/repository/TaxonomyRepository.java @@ -5,5 +5,5 @@ import org.springframework.stereotype.Repository; @Repository -public interface TaxonomyRepository extends JpaRepository { +public interface TaxonomyRepository extends JpaRepository { } diff --git a/src/main/java/com/sarapis/orservice/repository/TaxonomyTermRepository.java b/src/main/java/com/sarapis/orservice/repository/TaxonomyTermRepository.java index 3983128..d5bc9dd 100644 --- a/src/main/java/com/sarapis/orservice/repository/TaxonomyTermRepository.java +++ b/src/main/java/com/sarapis/orservice/repository/TaxonomyTermRepository.java @@ -5,5 +5,5 @@ import org.springframework.stereotype.Repository; @Repository -public interface TaxonomyTermRepository extends JpaRepository { +public interface TaxonomyTermRepository extends JpaRepository { } diff --git a/src/main/java/com/sarapis/orservice/service/AccessibilityServiceImpl.java b/src/main/java/com/sarapis/orservice/service/AccessibilityServiceImpl.java index d4761fe..7d11df9 100644 --- a/src/main/java/com/sarapis/orservice/service/AccessibilityServiceImpl.java +++ b/src/main/java/com/sarapis/orservice/service/AccessibilityServiceImpl.java @@ -31,7 +31,10 @@ public AccessibilityServiceImpl(AccessibilityRepository accessibilityRepository, @Override public List getAllAccessibilities() { List accessibilityDTOs = this.accessibilityRepository.findAll().stream().map(Accessibility::toDTO).toList(); - accessibilityDTOs.forEach(this::getRelatedData); + accessibilityDTOs.forEach(accessibilityDTO -> { + accessibilityDTO.getAttributes().addAll(this.accessibilityRepository.getAttributes(accessibilityDTO.getId()).stream().map(Attribute::toDTO).toList()); + accessibilityDTO.getMetadata().addAll(this.accessibilityRepository.getMetadata(accessibilityDTO.getId()).stream().map(Metadata::toDTO).toList()); + }); return accessibilityDTOs; } @@ -40,7 +43,8 @@ public AccessibilityDTO getAccessibilityById(String id) { Accessibility accessibility = this.accessibilityRepository.findById(id) .orElseThrow(() -> new RuntimeException("Accessibility not found.")); AccessibilityDTO accessibilityDTO = accessibility.toDTO(); - getRelatedData(accessibilityDTO); + accessibilityDTO.getAttributes().addAll(this.accessibilityRepository.getAttributes(accessibilityDTO.getId()).stream().map(Attribute::toDTO).toList()); + accessibilityDTO.getMetadata().addAll(this.accessibilityRepository.getMetadata(accessibilityDTO.getId()).stream().map(Metadata::toDTO).toList()); return accessibilityDTO; } @@ -57,7 +61,8 @@ public AccessibilityDTO createAccessibility(AccessibilityDTO accessibilityDTO) { } AccessibilityDTO savedAccessibilityDTO = this.accessibilityRepository.save(accessibility).toDTO(); - getRelatedData(savedAccessibilityDTO); + savedAccessibilityDTO.getAttributes().addAll(this.accessibilityRepository.getAttributes(savedAccessibilityDTO.getId()).stream().map(Attribute::toDTO).toList()); + savedAccessibilityDTO.getMetadata().addAll(this.accessibilityRepository.getMetadata(savedAccessibilityDTO.getId()).stream().map(Metadata::toDTO).toList()); return savedAccessibilityDTO; } @@ -78,26 +83,8 @@ public AccessibilityDTO updateAccessibility(String id, AccessibilityDTO accessib public void deleteAccessibility(String id) { Accessibility accessibility = this.accessibilityRepository.findById(id) .orElseThrow(() -> new RuntimeException("Accessibility not found.")); - - List attributes = this.attributeRepository.findAll(); - List relatedAttributes = attributes.stream().filter((e) -> Objects.equals(e.getLinkId(), accessibility.getId())).toList(); - this.attributeRepository.deleteAll(relatedAttributes); - - List metadatas = this.metadataRepository.findAll(); - List relatedMetadatas = metadatas.stream().filter((e) -> Objects.equals(e.getResourceId(), accessibility.getId())).toList(); - this.metadataRepository.deleteAll(relatedMetadatas); - + this.accessibilityRepository.deleteAttributes(accessibility.getId()); + this.accessibilityRepository.deleteMetadata(accessibility.getId()); this.accessibilityRepository.delete(accessibility); } - - private void getRelatedData(AccessibilityDTO accessibilityDTO) { - List attributes = this.attributeRepository.findAll(); - List relatedAttributeDTOs = attributes.stream().filter((e) -> Objects.equals(e.getLinkId(), accessibilityDTO.getId())).map(Attribute::toDTO).toList(); - - List metadatas = this.metadataRepository.findAll(); - List relatedMetadataDTOs = metadatas.stream().filter((e) -> Objects.equals(e.getResourceId(), accessibilityDTO.getId())).map(Metadata::toDTO).toList(); - - accessibilityDTO.getAttributes().addAll(relatedAttributeDTOs); - accessibilityDTO.getMetadata().addAll(relatedMetadataDTOs); - } } \ No newline at end of file diff --git a/src/main/java/com/sarapis/orservice/service/AddressServiceImpl.java b/src/main/java/com/sarapis/orservice/service/AddressServiceImpl.java index e79301d..aa73980 100644 --- a/src/main/java/com/sarapis/orservice/service/AddressServiceImpl.java +++ b/src/main/java/com/sarapis/orservice/service/AddressServiceImpl.java @@ -12,7 +12,6 @@ import org.springframework.stereotype.Service; import java.util.List; -import java.util.Objects; @Service public class AddressServiceImpl implements AddressService { @@ -29,7 +28,10 @@ public AddressServiceImpl(AddressRepository addressRepository, AttributeReposito @Override public List getAllAddresses() { List addressDTOs = this.addressRepository.findAll().stream().map(Address::toDTO).toList(); - addressDTOs.forEach(this::getRelatedData); + addressDTOs.forEach(addressDTO -> { + addressDTO.getAttributes().addAll(this.addressRepository.getAttributes(addressDTO.getId()).stream().map(Attribute::toDTO).toList()); + addressDTO.getMetadata().addAll(this.addressRepository.getMetadata(addressDTO.getId()).stream().map(Metadata::toDTO).toList()); + }); return addressDTOs; } @@ -38,7 +40,8 @@ public AddressDTO getAddressById(String id) { Address address = this.addressRepository.findById(id) .orElseThrow(() -> new RuntimeException("Address not found.")); AddressDTO addressDTO = address.toDTO(); - getRelatedData(addressDTO); + addressDTO.getAttributes().addAll(this.addressRepository.getAttributes(addressDTO.getId()).stream().map(Attribute::toDTO).toList()); + addressDTO.getMetadata().addAll(this.addressRepository.getMetadata(addressDTO.getId()).stream().map(Metadata::toDTO).toList()); return addressDTO; } @@ -55,7 +58,8 @@ public AddressDTO createAddress(AddressDTO addressDTO) { } AddressDTO savedAddressDTO = this.addressRepository.save(address).toDTO(); - getRelatedData(savedAddressDTO); + savedAddressDTO.getAttributes().addAll(this.addressRepository.getAttributes(savedAddressDTO.getId()).stream().map(Attribute::toDTO).toList()); + savedAddressDTO.getMetadata().addAll(this.addressRepository.getMetadata(savedAddressDTO.getId()).stream().map(Metadata::toDTO).toList()); return savedAddressDTO; } @@ -83,25 +87,8 @@ public void deleteAddress(String id) { Address address = this.addressRepository.findById(id) .orElseThrow(() -> new RuntimeException("Address not found.")); - List attributes = this.attributeRepository.findAll(); - List relatedAttributes = attributes.stream().filter((e) -> Objects.equals(e.getLinkId(), address.getId())).toList(); - this.attributeRepository.deleteAll(relatedAttributes); - - List metadatas = this.metadataRepository.findAll(); - List relatedMetadatas = metadatas.stream().filter((e) -> Objects.equals(e.getResourceId(), address.getId())).toList(); - this.metadataRepository.deleteAll(relatedMetadatas); - + this.addressRepository.deleteAttributes(address.getId()); + this.addressRepository.deleteMetadata(address.getId()); this.addressRepository.delete(address); } - - private void getRelatedData(AddressDTO addressDTO) { - List attributes = this.attributeRepository.findAll(); - List relatedAttributeDTOs = attributes.stream().filter((e) -> Objects.equals(e.getLinkId(), addressDTO.getId())).map(Attribute::toDTO).toList(); - - List metadatas = this.metadataRepository.findAll(); - List relatedMetadataDTOs = metadatas.stream().filter((e) -> Objects.equals(e.getResourceId(), addressDTO.getId())).map(Metadata::toDTO).toList(); - - addressDTO.getAttributes().addAll(relatedAttributeDTOs); - addressDTO.getMetadata().addAll(relatedMetadataDTOs); - } } diff --git a/src/main/java/com/sarapis/orservice/service/AttributeServiceImpl.java b/src/main/java/com/sarapis/orservice/service/AttributeServiceImpl.java index 2fd17c6..9831f03 100644 --- a/src/main/java/com/sarapis/orservice/service/AttributeServiceImpl.java +++ b/src/main/java/com/sarapis/orservice/service/AttributeServiceImpl.java @@ -10,7 +10,6 @@ import org.springframework.stereotype.Service; import java.util.List; -import java.util.Objects; @Service public class AttributeServiceImpl implements AttributeService { @@ -25,12 +24,8 @@ public AttributeServiceImpl(AttributeRepository attributeRepository, MetadataRep @Override public List getAllAttributes() { - List attributeDTOs = this.attributeRepository.findAll() - .stream() - .map(Attribute::toDTO) - .toList(); - attributeDTOs.forEach(this::getRelatedData); - + List attributeDTOs = this.attributeRepository.findAll().stream().map(Attribute::toDTO).toList(); + attributeDTOs.forEach(attributeDTO -> attributeDTO.getMetadata().addAll(this.attributeRepository.getMetadata(attributeDTO.getId()).stream().map(Metadata::toDTO).toList())); return attributeDTOs; } @@ -39,7 +34,7 @@ public AttributeDTO getAttributeById(String id) { Attribute attribute = this.attributeRepository.findById(id) .orElseThrow(() -> new RuntimeException("Attribute not found.")); AttributeDTO attributeDTO = attribute.toDTO(); - this.getRelatedData(attributeDTO); + attributeDTO.getMetadata().addAll(this.attributeRepository.getMetadata(attributeDTO.getId()).stream().map(Metadata::toDTO).toList()); return attributeDTO; } @@ -51,9 +46,9 @@ public AttributeDTO createAttribute(AttributeDTO attributeDTO) { this.metadataRepository.save(metadataDTO.toEntity(attribute.getId())); } - Attribute savedAttr = this.attributeRepository.save(attribute); - getRelatedData(attributeDTO); - return savedAttr.toDTO(); + AttributeDTO savedAttributedDTO = this.attributeRepository.save(attribute).toDTO(); + savedAttributedDTO.getMetadata().addAll(this.attributeRepository.getMetadata(savedAttributedDTO.getId()).stream().map(Metadata::toDTO).toList()); + return savedAttributedDTO; } @Override @@ -76,18 +71,7 @@ public AttributeDTO updateAttribute(String id, AttributeDTO attributeDTO) { public void deleteAttribute(String id) { Attribute attribute = this.attributeRepository.findById(id) .orElseThrow(() -> new RuntimeException("Attribute not found.")); - - List metadatas = metadataRepository.findAll(); - List relatedMetadatas = metadatas.stream().filter((e) -> Objects.equals(e.getResourceId(), attribute.getId())).toList(); - this.metadataRepository.deleteAll(relatedMetadatas); - + this.attributeRepository.deleteMetadata(attribute.getId()); this.attributeRepository.delete(attribute); } - - private void getRelatedData(AttributeDTO attributeDTO) { - List metadatas = this.metadataRepository.findAll(); - List relatedMetadataDTOs = metadatas.stream().filter((e) -> Objects.equals(e.getResourceId(), attributeDTO.getId())).map(Metadata::toDTO).toList(); - - attributeDTO.getMetadata().addAll(relatedMetadataDTOs); - } } diff --git a/src/main/java/com/sarapis/orservice/service/OrganizationServiceImpl.java b/src/main/java/com/sarapis/orservice/service/OrganizationServiceImpl.java index 0c52c0d..2cd07fd 100644 --- a/src/main/java/com/sarapis/orservice/service/OrganizationServiceImpl.java +++ b/src/main/java/com/sarapis/orservice/service/OrganizationServiceImpl.java @@ -13,7 +13,6 @@ import org.springframework.stereotype.Service; import java.util.List; -import java.util.Objects; @Service public class OrganizationServiceImpl implements OrganizationService { @@ -31,7 +30,10 @@ public OrganizationServiceImpl(OrganizationRepository organizationRepository, At @Override public List getAllOrganizations() { List organizationDTOs = this.organizationRepository.findAll().stream().map(Organization::toDTO).toList(); - organizationDTOs.forEach(this::getRelatedData); + organizationDTOs.forEach(organizationDTO -> { + organizationDTO.getAttributes().addAll(this.organizationRepository.getAttributes(organizationDTO.getId()).stream().map(Attribute::toDTO).toList()); + organizationDTO.getMetadata().addAll(this.organizationRepository.getMetadata(organizationDTO.getId()).stream().map(Metadata::toDTO).toList()); + }); return organizationDTOs; } @@ -40,7 +42,8 @@ public OrganizationDTO getOrganizationById(String id) { Organization organization = this.organizationRepository.findById(id) .orElseThrow(() -> new RuntimeException("Organization not found.")); OrganizationDTO organizationDTO = organization.toDTO(); - getRelatedData(organizationDTO); + organizationDTO.getAttributes().addAll(this.organizationRepository.getAttributes(organizationDTO.getId()).stream().map(Attribute::toDTO).toList()); + organizationDTO.getMetadata().addAll(this.organizationRepository.getMetadata(organizationDTO.getId()).stream().map(Metadata::toDTO).toList()); return organizationDTO; } @@ -57,7 +60,8 @@ public OrganizationDTO createOrganization(OrganizationDTO organizationDTO) { } OrganizationDTO savedOrganizationDTO = this.organizationRepository.save(organization).toDTO(); - getRelatedData(savedOrganizationDTO); + savedOrganizationDTO.getAttributes().addAll(this.organizationRepository.getAttributes(savedOrganizationDTO.getId()).stream().map(Attribute::toDTO).toList()); + savedOrganizationDTO.getMetadata().addAll(this.organizationRepository.getMetadata(savedOrganizationDTO.getId()).stream().map(Metadata::toDTO).toList()); return savedOrganizationDTO; } @@ -87,26 +91,8 @@ public OrganizationDTO updateOrganization(String id, OrganizationDTO organizatio public void deleteOrganization(String id) { Organization organization = this.organizationRepository.findById(id) .orElseThrow(() -> new RuntimeException("Organization not found.")); - - List attributes = this.attributeRepository.findAll(); - List relatedAttributes = attributes.stream().filter((e) -> Objects.equals(e.getLinkId(), organization.getId())).toList(); - this.attributeRepository.deleteAll(relatedAttributes); - - List metadatas = this.metadataRepository.findAll(); - List relatedMetadatas = metadatas.stream().filter((e) -> Objects.equals(e.getResourceId(), organization.getId())).toList(); - this.metadataRepository.deleteAll(relatedMetadatas); - + this.organizationRepository.deleteAttributes(organization.getId()); + this.organizationRepository.deleteMetadata(organization.getId()); this.organizationRepository.delete(organization); } - - private void getRelatedData(OrganizationDTO organizationDTO) { - List attributes = this.attributeRepository.findAll(); - List relatedAttributeDTOs = attributes.stream().filter((e) -> Objects.equals(e.getLinkId(), organizationDTO.getId())).map(Attribute::toDTO).toList(); - - List metadatas = this.metadataRepository.findAll(); - List relatedMetadataDTOs = metadatas.stream().filter((e) -> Objects.equals(e.getResourceId(), organizationDTO.getId())).map(Metadata::toDTO).toList(); - - organizationDTO.getAttributes().addAll(relatedAttributeDTOs); - organizationDTO.getMetadata().addAll(relatedMetadataDTOs); - } } From 1d1bd6e46bf819ad0fde6d2871b3a02c25a0cd64 Mon Sep 17 00:00:00 2001 From: ZhangTerrence Date: Tue, 3 Dec 2024 13:07:44 -0500 Subject: [PATCH 25/28] refactored redundant logic --- .../service/AccessibilityServiceImpl.java | 19 ++++++++++--------- .../orservice/service/AddressServiceImpl.java | 16 ++++++++-------- .../service/AttributeServiceImpl.java | 10 +++++++--- .../service/OrganizationServiceImpl.java | 16 ++++++++-------- 4 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/sarapis/orservice/service/AccessibilityServiceImpl.java b/src/main/java/com/sarapis/orservice/service/AccessibilityServiceImpl.java index 7d11df9..b386eb9 100644 --- a/src/main/java/com/sarapis/orservice/service/AccessibilityServiceImpl.java +++ b/src/main/java/com/sarapis/orservice/service/AccessibilityServiceImpl.java @@ -13,7 +13,6 @@ import org.springframework.stereotype.Service; import java.util.List; -import java.util.Objects; @Service public class AccessibilityServiceImpl implements AccessibilityService { @@ -31,20 +30,18 @@ public AccessibilityServiceImpl(AccessibilityRepository accessibilityRepository, @Override public List getAllAccessibilities() { List accessibilityDTOs = this.accessibilityRepository.findAll().stream().map(Accessibility::toDTO).toList(); - accessibilityDTOs.forEach(accessibilityDTO -> { - accessibilityDTO.getAttributes().addAll(this.accessibilityRepository.getAttributes(accessibilityDTO.getId()).stream().map(Attribute::toDTO).toList()); - accessibilityDTO.getMetadata().addAll(this.accessibilityRepository.getMetadata(accessibilityDTO.getId()).stream().map(Metadata::toDTO).toList()); - }); + accessibilityDTOs.forEach(this::addRelatedData); return accessibilityDTOs; } + + @Override public AccessibilityDTO getAccessibilityById(String id) { Accessibility accessibility = this.accessibilityRepository.findById(id) .orElseThrow(() -> new RuntimeException("Accessibility not found.")); AccessibilityDTO accessibilityDTO = accessibility.toDTO(); - accessibilityDTO.getAttributes().addAll(this.accessibilityRepository.getAttributes(accessibilityDTO.getId()).stream().map(Attribute::toDTO).toList()); - accessibilityDTO.getMetadata().addAll(this.accessibilityRepository.getMetadata(accessibilityDTO.getId()).stream().map(Metadata::toDTO).toList()); + this.addRelatedData(accessibilityDTO); return accessibilityDTO; } @@ -61,8 +58,7 @@ public AccessibilityDTO createAccessibility(AccessibilityDTO accessibilityDTO) { } AccessibilityDTO savedAccessibilityDTO = this.accessibilityRepository.save(accessibility).toDTO(); - savedAccessibilityDTO.getAttributes().addAll(this.accessibilityRepository.getAttributes(savedAccessibilityDTO.getId()).stream().map(Attribute::toDTO).toList()); - savedAccessibilityDTO.getMetadata().addAll(this.accessibilityRepository.getMetadata(savedAccessibilityDTO.getId()).stream().map(Metadata::toDTO).toList()); + this.addRelatedData(savedAccessibilityDTO); return savedAccessibilityDTO; } @@ -87,4 +83,9 @@ public void deleteAccessibility(String id) { this.accessibilityRepository.deleteMetadata(accessibility.getId()); this.accessibilityRepository.delete(accessibility); } + + private void addRelatedData(AccessibilityDTO accessibilityDTO) { + accessibilityDTO.getAttributes().addAll(this.accessibilityRepository.getAttributes(accessibilityDTO.getId()).stream().map(Attribute::toDTO).toList()); + accessibilityDTO.getMetadata().addAll(this.accessibilityRepository.getMetadata(accessibilityDTO.getId()).stream().map(Metadata::toDTO).toList()); + } } \ No newline at end of file diff --git a/src/main/java/com/sarapis/orservice/service/AddressServiceImpl.java b/src/main/java/com/sarapis/orservice/service/AddressServiceImpl.java index aa73980..91546ea 100644 --- a/src/main/java/com/sarapis/orservice/service/AddressServiceImpl.java +++ b/src/main/java/com/sarapis/orservice/service/AddressServiceImpl.java @@ -28,10 +28,7 @@ public AddressServiceImpl(AddressRepository addressRepository, AttributeReposito @Override public List getAllAddresses() { List addressDTOs = this.addressRepository.findAll().stream().map(Address::toDTO).toList(); - addressDTOs.forEach(addressDTO -> { - addressDTO.getAttributes().addAll(this.addressRepository.getAttributes(addressDTO.getId()).stream().map(Attribute::toDTO).toList()); - addressDTO.getMetadata().addAll(this.addressRepository.getMetadata(addressDTO.getId()).stream().map(Metadata::toDTO).toList()); - }); + addressDTOs.forEach(this::addRelatedData); return addressDTOs; } @@ -40,8 +37,7 @@ public AddressDTO getAddressById(String id) { Address address = this.addressRepository.findById(id) .orElseThrow(() -> new RuntimeException("Address not found.")); AddressDTO addressDTO = address.toDTO(); - addressDTO.getAttributes().addAll(this.addressRepository.getAttributes(addressDTO.getId()).stream().map(Attribute::toDTO).toList()); - addressDTO.getMetadata().addAll(this.addressRepository.getMetadata(addressDTO.getId()).stream().map(Metadata::toDTO).toList()); + this.addRelatedData(addressDTO); return addressDTO; } @@ -58,8 +54,7 @@ public AddressDTO createAddress(AddressDTO addressDTO) { } AddressDTO savedAddressDTO = this.addressRepository.save(address).toDTO(); - savedAddressDTO.getAttributes().addAll(this.addressRepository.getAttributes(savedAddressDTO.getId()).stream().map(Attribute::toDTO).toList()); - savedAddressDTO.getMetadata().addAll(this.addressRepository.getMetadata(savedAddressDTO.getId()).stream().map(Metadata::toDTO).toList()); + this.addRelatedData(savedAddressDTO); return savedAddressDTO; } @@ -91,4 +86,9 @@ public void deleteAddress(String id) { this.addressRepository.deleteMetadata(address.getId()); this.addressRepository.delete(address); } + + private void addRelatedData(AddressDTO addressDTO) { + addressDTO.getAttributes().addAll(this.addressRepository.getAttributes(addressDTO.getId()).stream().map(Attribute::toDTO).toList()); + addressDTO.getMetadata().addAll(this.addressRepository.getMetadata(addressDTO.getId()).stream().map(Metadata::toDTO).toList()); + } } diff --git a/src/main/java/com/sarapis/orservice/service/AttributeServiceImpl.java b/src/main/java/com/sarapis/orservice/service/AttributeServiceImpl.java index 9831f03..1062151 100644 --- a/src/main/java/com/sarapis/orservice/service/AttributeServiceImpl.java +++ b/src/main/java/com/sarapis/orservice/service/AttributeServiceImpl.java @@ -25,7 +25,7 @@ public AttributeServiceImpl(AttributeRepository attributeRepository, MetadataRep @Override public List getAllAttributes() { List attributeDTOs = this.attributeRepository.findAll().stream().map(Attribute::toDTO).toList(); - attributeDTOs.forEach(attributeDTO -> attributeDTO.getMetadata().addAll(this.attributeRepository.getMetadata(attributeDTO.getId()).stream().map(Metadata::toDTO).toList())); + attributeDTOs.forEach(this::addRelatedData); return attributeDTOs; } @@ -34,7 +34,7 @@ public AttributeDTO getAttributeById(String id) { Attribute attribute = this.attributeRepository.findById(id) .orElseThrow(() -> new RuntimeException("Attribute not found.")); AttributeDTO attributeDTO = attribute.toDTO(); - attributeDTO.getMetadata().addAll(this.attributeRepository.getMetadata(attributeDTO.getId()).stream().map(Metadata::toDTO).toList()); + this.addRelatedData(attributeDTO); return attributeDTO; } @@ -47,7 +47,7 @@ public AttributeDTO createAttribute(AttributeDTO attributeDTO) { } AttributeDTO savedAttributedDTO = this.attributeRepository.save(attribute).toDTO(); - savedAttributedDTO.getMetadata().addAll(this.attributeRepository.getMetadata(savedAttributedDTO.getId()).stream().map(Metadata::toDTO).toList()); + this.addRelatedData(savedAttributedDTO); return savedAttributedDTO; } @@ -74,4 +74,8 @@ public void deleteAttribute(String id) { this.attributeRepository.deleteMetadata(attribute.getId()); this.attributeRepository.delete(attribute); } + + private void addRelatedData(AttributeDTO attributeDTO) { + attributeDTO.getMetadata().addAll(this.attributeRepository.getMetadata(attributeDTO.getId()).stream().map(Metadata::toDTO).toList()); + } } diff --git a/src/main/java/com/sarapis/orservice/service/OrganizationServiceImpl.java b/src/main/java/com/sarapis/orservice/service/OrganizationServiceImpl.java index 2cd07fd..a3eb522 100644 --- a/src/main/java/com/sarapis/orservice/service/OrganizationServiceImpl.java +++ b/src/main/java/com/sarapis/orservice/service/OrganizationServiceImpl.java @@ -30,10 +30,7 @@ public OrganizationServiceImpl(OrganizationRepository organizationRepository, At @Override public List getAllOrganizations() { List organizationDTOs = this.organizationRepository.findAll().stream().map(Organization::toDTO).toList(); - organizationDTOs.forEach(organizationDTO -> { - organizationDTO.getAttributes().addAll(this.organizationRepository.getAttributes(organizationDTO.getId()).stream().map(Attribute::toDTO).toList()); - organizationDTO.getMetadata().addAll(this.organizationRepository.getMetadata(organizationDTO.getId()).stream().map(Metadata::toDTO).toList()); - }); + organizationDTOs.forEach(this::addRelatedData); return organizationDTOs; } @@ -42,8 +39,7 @@ public OrganizationDTO getOrganizationById(String id) { Organization organization = this.organizationRepository.findById(id) .orElseThrow(() -> new RuntimeException("Organization not found.")); OrganizationDTO organizationDTO = organization.toDTO(); - organizationDTO.getAttributes().addAll(this.organizationRepository.getAttributes(organizationDTO.getId()).stream().map(Attribute::toDTO).toList()); - organizationDTO.getMetadata().addAll(this.organizationRepository.getMetadata(organizationDTO.getId()).stream().map(Metadata::toDTO).toList()); + this.addRelatedData(organizationDTO); return organizationDTO; } @@ -60,8 +56,7 @@ public OrganizationDTO createOrganization(OrganizationDTO organizationDTO) { } OrganizationDTO savedOrganizationDTO = this.organizationRepository.save(organization).toDTO(); - savedOrganizationDTO.getAttributes().addAll(this.organizationRepository.getAttributes(savedOrganizationDTO.getId()).stream().map(Attribute::toDTO).toList()); - savedOrganizationDTO.getMetadata().addAll(this.organizationRepository.getMetadata(savedOrganizationDTO.getId()).stream().map(Metadata::toDTO).toList()); + this.addRelatedData(savedOrganizationDTO); return savedOrganizationDTO; } @@ -95,4 +90,9 @@ public void deleteOrganization(String id) { this.organizationRepository.deleteMetadata(organization.getId()); this.organizationRepository.delete(organization); } + + private void addRelatedData(OrganizationDTO organizationDTO) { + organizationDTO.getAttributes().addAll(this.organizationRepository.getAttributes(organizationDTO.getId()).stream().map(Attribute::toDTO).toList()); + organizationDTO.getMetadata().addAll(this.organizationRepository.getMetadata(organizationDTO.getId()).stream().map(Metadata::toDTO).toList()); + } } From d11b6af7b2e79165ab33ee8964c2b68d1a32799d Mon Sep 17 00:00:00 2001 From: miguel-merlin Date: Wed, 4 Dec 2024 15:37:05 -0500 Subject: [PATCH 26/28] feat: Added import and export controller --- .../controller/ExportController.java | 10 +++++++ .../controller/ImportController.java | 28 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/main/java/com/sarapis/orservice/controller/ExportController.java create mode 100644 src/main/java/com/sarapis/orservice/controller/ImportController.java diff --git a/src/main/java/com/sarapis/orservice/controller/ExportController.java b/src/main/java/com/sarapis/orservice/controller/ExportController.java new file mode 100644 index 0000000..2f44f7c --- /dev/null +++ b/src/main/java/com/sarapis/orservice/controller/ExportController.java @@ -0,0 +1,10 @@ +package com.sarapis.orservice.controller; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api/export") +public class ExportController { + +} diff --git a/src/main/java/com/sarapis/orservice/controller/ImportController.java b/src/main/java/com/sarapis/orservice/controller/ImportController.java new file mode 100644 index 0000000..194e8a8 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/controller/ImportController.java @@ -0,0 +1,28 @@ +package com.sarapis.orservice.controller; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api/import") +public class ImportController { + @GetMapping("/csv") + public void exportCSV() { + } + + @PostMapping("/csv") + public void importCSV() { + } + + @GetMapping("/pdf") + public void exportPDF() { + + } + + @PostMapping("/pdf") + public void importPDF() { + + } +} From 38f05708e431a7b51fcfd77e8a4067b824db3347 Mon Sep 17 00:00:00 2001 From: miguel-merlin Date: Wed, 4 Dec 2024 16:09:41 -0500 Subject: [PATCH 27/28] feat: added export controller --- pom.xml | 5 ++++ .../controller/ExportController.java | 20 ++++++++++++++ .../orservice/entity/core/Organization.java | 27 +++++++++++++++++++ .../service/OrganizationService.java | 4 +++ .../service/OrganizationServiceImpl.java | 7 +++++ 5 files changed, 63 insertions(+) diff --git a/pom.xml b/pom.xml index 5a9375d..68ce85a 100644 --- a/pom.xml +++ b/pom.xml @@ -75,6 +75,11 @@ postgresql 42.2.6 + + org.apache.commons + commons-csv + 1.8 + diff --git a/src/main/java/com/sarapis/orservice/controller/ExportController.java b/src/main/java/com/sarapis/orservice/controller/ExportController.java index 2f44f7c..dccf830 100644 --- a/src/main/java/com/sarapis/orservice/controller/ExportController.java +++ b/src/main/java/com/sarapis/orservice/controller/ExportController.java @@ -1,10 +1,30 @@ package com.sarapis.orservice.controller; +import com.sarapis.orservice.service.OrganizationService; +import java.io.ByteArrayInputStream; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.InputStreamResource; +import org.springframework.core.io.Resource; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/api/export") public class ExportController { + private final OrganizationService organizationService; + + @Autowired + public ExportController(OrganizationService organizationService) { + this.organizationService = organizationService; + } + + @RequestMapping("/csv") + public ResponseEntity exportCSV() { + String filename = "organizations.csv"; + InputStreamResource organizationCSV = new InputStreamResource(organizationService.loadCSV()); + return ResponseEntity.ok() + .body(organizationCSV); + } } diff --git a/src/main/java/com/sarapis/orservice/entity/core/Organization.java b/src/main/java/com/sarapis/orservice/entity/core/Organization.java index e304c87..cfd532b 100644 --- a/src/main/java/com/sarapis/orservice/entity/core/Organization.java +++ b/src/main/java/com/sarapis/orservice/entity/core/Organization.java @@ -3,7 +3,15 @@ import com.sarapis.orservice.dto.OrganizationDTO; import com.sarapis.orservice.entity.*; import jakarta.persistence.*; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; import lombok.*; +import org.apache.commons.csv.CSVFormat; +import org.apache.commons.csv.CSVPrinter; +import org.apache.commons.csv.QuoteMode; import org.hibernate.annotations.UuidGenerator; import java.util.ArrayList; @@ -116,4 +124,23 @@ public OrganizationDTO toDTO() { .metadata(new ArrayList<>()) .build(); } + + public static ByteArrayInputStream toCSV(List organizations) { + final CSVFormat format = CSVFormat.DEFAULT.withQuoteMode(QuoteMode.MINIMAL); + try (ByteArrayOutputStream out = new ByteArrayOutputStream(); + CSVPrinter csvPrinter = new CSVPrinter(new PrintWriter(out), format);) { + for (Organization organization : organizations) { + List data = Arrays.asList( + String.valueOf(organization.getId()), + organization.getName(), + organization.getDescription() + ); + csvPrinter.printRecord(data); + } + csvPrinter.flush(); + return new ByteArrayInputStream(out.toByteArray()); + } catch (IOException e) { + throw new RuntimeException("fail to import data to CSV file: " + e.getMessage()); + } + } } diff --git a/src/main/java/com/sarapis/orservice/service/OrganizationService.java b/src/main/java/com/sarapis/orservice/service/OrganizationService.java index 95c1947..36e6879 100644 --- a/src/main/java/com/sarapis/orservice/service/OrganizationService.java +++ b/src/main/java/com/sarapis/orservice/service/OrganizationService.java @@ -1,6 +1,8 @@ package com.sarapis.orservice.service; import com.sarapis.orservice.dto.OrganizationDTO; +import com.sarapis.orservice.entity.core.Organization; +import java.io.ByteArrayInputStream; import java.util.List; public interface OrganizationService { @@ -14,4 +16,6 @@ public interface OrganizationService { void deleteOrganization(String id); + ByteArrayInputStream loadCSV(); + } diff --git a/src/main/java/com/sarapis/orservice/service/OrganizationServiceImpl.java b/src/main/java/com/sarapis/orservice/service/OrganizationServiceImpl.java index a3eb522..26fa1dc 100644 --- a/src/main/java/com/sarapis/orservice/service/OrganizationServiceImpl.java +++ b/src/main/java/com/sarapis/orservice/service/OrganizationServiceImpl.java @@ -9,6 +9,7 @@ import com.sarapis.orservice.repository.AttributeRepository; import com.sarapis.orservice.repository.MetadataRepository; import com.sarapis.orservice.repository.OrganizationRepository; +import java.io.ByteArrayInputStream; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -91,6 +92,12 @@ public void deleteOrganization(String id) { this.organizationRepository.delete(organization); } + @Override + public ByteArrayInputStream loadCSV() { + List organizations = organizationRepository.findAll(); + return Organization.toCSV(organizations); + } + private void addRelatedData(OrganizationDTO organizationDTO) { organizationDTO.getAttributes().addAll(this.organizationRepository.getAttributes(organizationDTO.getId()).stream().map(Attribute::toDTO).toList()); organizationDTO.getMetadata().addAll(this.organizationRepository.getMetadata(organizationDTO.getId()).stream().map(Metadata::toDTO).toList()); From e0bb8c19890e5b18f813a824db25beb1072ed603 Mon Sep 17 00:00:00 2001 From: miguel-merlin Date: Wed, 4 Dec 2024 16:23:13 -0500 Subject: [PATCH 28/28] feat: Added export service --- .../orservice/service/ExportService.java | 11 ++++ .../orservice/service/ExportServiceImpl.java | 51 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 src/main/java/com/sarapis/orservice/service/ExportService.java create mode 100644 src/main/java/com/sarapis/orservice/service/ExportServiceImpl.java diff --git a/src/main/java/com/sarapis/orservice/service/ExportService.java b/src/main/java/com/sarapis/orservice/service/ExportService.java new file mode 100644 index 0000000..9bcee6f --- /dev/null +++ b/src/main/java/com/sarapis/orservice/service/ExportService.java @@ -0,0 +1,11 @@ +package com.sarapis.orservice.service; + +import java.io.IOException; +import java.util.Map; +import org.springframework.core.io.InputStreamResource; + +public interface ExportService { + InputStreamResource createCsvZip() throws IOException; + + InputStreamResource createPdfZip() throws IOException; +} diff --git a/src/main/java/com/sarapis/orservice/service/ExportServiceImpl.java b/src/main/java/com/sarapis/orservice/service/ExportServiceImpl.java new file mode 100644 index 0000000..9695c9f --- /dev/null +++ b/src/main/java/com/sarapis/orservice/service/ExportServiceImpl.java @@ -0,0 +1,51 @@ +package com.sarapis.orservice.service; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; +import org.springframework.core.io.InputStreamResource; + +public class ExportServiceImpl implements ExportService { + private static void addToZip( + ZipOutputStream zipOut, + String fileName, + InputStreamResource resource) throws IOException { + + ZipEntry zipEntry = new ZipEntry(fileName); + zipOut.putNextEntry(zipEntry); + + try (InputStream inputStream = resource.getInputStream()) { + byte[] bytes = new byte[1024]; + int length; + while ((length = inputStream.read(bytes)) >= 0) { + zipOut.write(bytes, 0, length); + } + } + zipOut.closeEntry(); + } + + private Map getCSVsFromTables() { + return null; + } + + @Override + public InputStreamResource createCsvZip() throws IOException { + Map files = getCSVsFromTables(); + ByteArrayOutputStream zipStream = new ByteArrayOutputStream(); + try (ZipOutputStream zipOut = new ZipOutputStream(zipStream)) { + for (Map.Entry entry : files.entrySet()) { + addToZip(zipOut, entry.getKey(), entry.getValue()); + } + } + return new InputStreamResource(new ByteArrayInputStream(zipStream.toByteArray())); + } + + @Override + public InputStreamResource createPdfZip() throws IOException { + return null; + } +}