diff --git a/pom.xml b/pom.xml index 1f90d96..0084ffc 100644 --- a/pom.xml +++ b/pom.xml @@ -38,7 +38,6 @@ org.springframework.boot spring-boot-starter-web - org.projectlombok lombok @@ -80,7 +79,11 @@ org.springframework.boot spring-boot-starter-actuator - + + org.apache.commons + commons-csv + 1.8 + 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/controller/AccessibilityController.java b/src/main/java/com/sarapis/orservice/controller/AccessibilityController.java new file mode 100644 index 0000000..29cbcdd --- /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/accessibilities") +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/controller/AddressController.java b/src/main/java/com/sarapis/orservice/controller/AddressController.java new file mode 100644 index 0000000..f0e60d6 --- /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/addresses") +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(); + } +} 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..5f5f7f5 --- /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/attributes") +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(); + } +} 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..dccf830 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/controller/ExportController.java @@ -0,0 +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/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() { + + } +} 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/AccessibilityDTO.java b/src/main/java/com/sarapis/orservice/dto/AccessibilityDTO.java new file mode 100644 index 0000000..d42bdb2 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/AccessibilityDTO.java @@ -0,0 +1,30 @@ +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) + .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..9924e62 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/AddressDTO.java @@ -0,0 +1,43 @@ +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) + .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..6deae5c --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/AttributeDTO.java @@ -0,0 +1,36 @@ +package com.sarapis.orservice.dto; + +import com.sarapis.orservice.entity.Attribute; +import com.sarapis.orservice.entity.LinkEntity; +import lombok.*; + +import java.util.ArrayList; +import java.util.List; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class AttributeDTO { + private String id; + private String linkId; + private String linkType; + private LinkEntity linkEntity; + private String value; + private TaxonomyTermDTO taxonomyTerm; + private String label; + private List metadata = new ArrayList<>(); + + 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()) + .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..fd8a2d7 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/ContactDTO.java @@ -0,0 +1,34 @@ +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()) + .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..c1c34aa --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/CostOptionDTO.java @@ -0,0 +1,37 @@ +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) + .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..7b825e9 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/FundingDTO.java @@ -0,0 +1,26 @@ +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) + .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..875e08e --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/LanguageDTO.java @@ -0,0 +1,30 @@ +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) + .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..45c9efa --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/LocationDTO.java @@ -0,0 +1,57 @@ +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()) + .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..4930826 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/MetaTableDescriptionDTO.java @@ -0,0 +1,30 @@ +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) + .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..e1d17d9 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/MetadataDTO.java @@ -0,0 +1,38 @@ +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 String resourceId; + private ResourceType resourceType; + private LocalDate lastActionDate; + private String lastActionType; + private String fieldName; + private String previousValue; + private String replacementValue; + private String updatedBy; + + public Metadata toEntity(String resourceId) { + return Metadata.builder() + .id(this.id) + .resourceId(resourceId) + .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 ce947d7..c7aed5f 100644 --- a/src/main/java/com/sarapis/orservice/dto/OrganizationDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/OrganizationDTO.java @@ -1,28 +1,62 @@ 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.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; @Getter @Setter @NoArgsConstructor @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; + 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()) + .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..1ac16d6 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/OrganizationIdentifierDTO.java @@ -0,0 +1,30 @@ +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) + .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..49081d1 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/PhoneDTO.java @@ -0,0 +1,34 @@ +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()) + .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..b6d18f6 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/ProgramDTO.java @@ -0,0 +1,30 @@ +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) + .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..55c8024 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/RequiredDocumentDTO.java @@ -0,0 +1,28 @@ +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) + .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..8d40dc8 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/ScheduleDTO.java @@ -0,0 +1,66 @@ +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) + .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..430db6f --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/ServiceAreaDTO.java @@ -0,0 +1,35 @@ +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) + .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..9bbfc3d 100644 --- a/src/main/java/com/sarapis/orservice/dto/ServiceAtLocationDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/ServiceAtLocationDTO.java @@ -1,19 +1,36 @@ 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; + 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.toEntity()) + .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..1531284 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/ServiceCapacityDTO.java @@ -0,0 +1,35 @@ +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) + .build(); + } +} diff --git a/src/main/java/com/sarapis/orservice/dto/ServiceDTO.java b/src/main/java/com/sarapis/orservice/dto/ServiceDTO.java index 610bc0a..297b6a9 100644 --- a/src/main/java/com/sarapis/orservice/dto/ServiceDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/ServiceDTO.java @@ -1,24 +1,28 @@ package com.sarapis.orservice.dto; -import com.sarapis.orservice.entity.Program; -import com.sarapis.orservice.entity.core.Organization; +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 OrganizationDTO organization; - private Program program; private String name; private String alternateName; + private String description; private String url; + private List additionalUrls = new ArrayList<>(); private String email; private Status status; private String interpretationServices; @@ -30,9 +34,62 @@ 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 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; + 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.toEntity()) + .funding(this.funding.stream().map(FundingDTO::toEntity).toList()) + .costOptions(this.costOptions.stream().map(CostOptionDTO::toEntity).toList()) + .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()) + .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..e7edb8b 100644 --- a/src/main/java/com/sarapis/orservice/dto/TaxonomyDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/TaxonomyDTO.java @@ -1,18 +1,31 @@ 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) + .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..5e1358c 100644 --- a/src/main/java/com/sarapis/orservice/dto/TaxonomyTermDTO.java +++ b/src/main/java/com/sarapis/orservice/dto/TaxonomyTermDTO.java @@ -1,21 +1,39 @@ 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) + .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..4bfea69 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/UnitDTO.java @@ -0,0 +1,32 @@ +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) + .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..6c87584 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/dto/UrlDTO.java @@ -0,0 +1,28 @@ +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) + .build(); + } +} diff --git a/src/main/java/com/sarapis/orservice/entity/Accessibility.java b/src/main/java/com/sarapis/orservice/entity/Accessibility.java index 822e469..7bfc983 100644 --- a/src/main/java/com/sarapis/orservice/entity/Accessibility.java +++ b/src/main/java/com/sarapis/orservice/entity/Accessibility.java @@ -1,35 +1,43 @@ 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 lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import org.hibernate.annotations.GenericGenerator; +import com.sarapis.orservice.dto.AccessibilityDTO; +import jakarta.persistence.*; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; + @Entity @Table(name = "accessibility") @Getter @Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class Accessibility { - @Id - @GeneratedValue - @UuidGenerator - private String id; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; + + @Column(name = "description") + private String description; + + @Column(name = "details") + private String details; - @ManyToOne - private Location location; + @Column(name = "url") + private String url; - private String description; - private String details; - private String url; + public AccessibilityDTO toDTO() { + return AccessibilityDTO.builder() + .id(this.id) + .description(this.description) + .details(this.details) + .url(this.url) + .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 8c8b334..5ae08e8 100644 --- a/src/main/java/com/sarapis/orservice/entity/Address.java +++ b/src/main/java/com/sarapis/orservice/entity/Address.java @@ -1,44 +1,68 @@ 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 lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import com.sarapis.orservice.dto.AddressDTO; +import jakarta.persistence.*; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; + @Entity @Table(name = "address") @Getter @Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class Address { - @Id - @GeneratedValue - @UuidGenerator - private String id; - - @OneToOne - 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; - - @Enumerated(EnumType.STRING) - private AddressType addressType; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; + + @Column(name = "attention") + private String attention; + + @Column(name = "address_1", nullable = false) + private String address_1; + + @Column(name = "address_2") + private String address_2; + + @Column(name = "city", nullable = false) + private String city; + + @Column(name = "region") + private String region; + + @Column(name = "state_province", nullable = false) + private String stateProvince; + + @Column(name = "postal_code", nullable = false) + private String postalCode; + + @Column(name = "country", nullable = false) + private String country; + + @Enumerated(EnumType.STRING) + @Column(name = "address_type", nullable = false) + private AddressType addressType; + + 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(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 36da1b7..53adbed 100644 --- a/src/main/java/com/sarapis/orservice/entity/Attribute.java +++ b/src/main/java/com/sarapis/orservice/entity/Attribute.java @@ -1,25 +1,55 @@ 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 lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import com.sarapis.orservice.dto.AttributeDTO; +import jakarta.persistence.*; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; + @Entity @Table(name = "attribute") @Getter @Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class Attribute { - @Id - @GeneratedValue - @UuidGenerator - private String id; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; + + @Column(name = "link_id", nullable = false) + private String linkId; + + @Column(name = "link_type") + private String linkType; + + @Enumerated(EnumType.STRING) + @Column(name = "link_entity", nullable = false) + private LinkEntity linkEntity; + + @Column(name = "value") + private String value; + + @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, optional = false) + @JoinColumn(name = "taxonomy_term_id", nullable = false) + private TaxonomyTerm taxonomyTerm; + + @Column(name = "label") + private String label; + + 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) + .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 8052bf7..008f7af 100644 --- a/src/main/java/com/sarapis/orservice/entity/Contact.java +++ b/src/main/java/com/sarapis/orservice/entity/Contact.java @@ -1,47 +1,53 @@ 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.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.Table; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import com.sarapis.orservice.dto.ContactDTO; +import jakarta.persistence.*; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; +import java.util.List; + @Entity @Table(name = "contact") @Setter @Getter @NoArgsConstructor @AllArgsConstructor +@Builder public class Contact { - @Id - @GeneratedValue - @UuidGenerator - private String id; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; + + @Column(name = "name") + private String name; - @ManyToOne - private Organization organization; + @Column(name = "title") + private String title; - @ManyToOne - private Service service; + @Column(name = "department") + private String department; - @ManyToOne - private ServiceAtLocation serviceAtLocation; + @Column(name = "email") + private String email; - @ManyToOne - private Location location; + @OneToMany(cascade = CascadeType.PERSIST) + @JoinColumn(name = "contact_id") + private List phones = new ArrayList<>(); - private String name; - private String title; - private String department; - private String email; + 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(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 1224ecf..268aa60 100644 --- a/src/main/java/com/sarapis/orservice/entity/CostOption.java +++ b/src/main/java/com/sarapis/orservice/entity/CostOption.java @@ -1,45 +1,56 @@ 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 lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import com.sarapis.orservice.dto.CostOptionDTO; +import jakarta.persistence.*; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.time.LocalDate; +import java.util.ArrayList; + @Entity @Table(name = "cost_option") -@Setter @Getter +@Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class CostOption { - @Id - @GeneratedValue - @UuidGenerator - private String id; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; + + @Column(name = "valid_from") + private LocalDate validFrom; + + @Column(name = "valid_to") + private LocalDate validTo; - @OneToOne - private Service service; + @Column(name = "option") + private String option; - @Column(name = "valid_from") - private LocalDate validFrom; + @Column(name = "currency") + private String currency; - @Column(name = "valid_to") - private LocalDate validTo; + @Column(name = "amount") + private int amount; - private String option; - private String currency; - private int amount; + @Column(name = "amount_description") + private String amountDescription; - @Column(name = "amount_description") - private String amountDescription; + 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(new ArrayList<>()) + .metadata(new ArrayList<>()) + .build(); + } } 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..4446b2e 100644 --- a/src/main/java/com/sarapis/orservice/entity/Funding.java +++ b/src/main/java/com/sarapis/orservice/entity/Funding.java @@ -1,38 +1,35 @@ package com.sarapis.orservice.entity; -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 lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import com.sarapis.orservice.dto.FundingDTO; +import jakarta.persistence.*; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; + @Entity @Table(name = "funding") -@Setter @Getter +@Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class Funding { - @Id - @GeneratedValue - @UuidGenerator - private String id; - - @ManyToOne - private Organization organization; - - @ManyToOne - private Service service; - - private String source; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; + @Column(name = "source") + private String source; + public FundingDTO toDTO() { + return FundingDTO.builder() + .id(this.id) + .source(this.source) + .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 72d1032..efec762 100644 --- a/src/main/java/com/sarapis/orservice/entity/Language.java +++ b/src/main/java/com/sarapis/orservice/entity/Language.java @@ -1,41 +1,43 @@ package com.sarapis.orservice.entity; -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 lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import com.sarapis.orservice.dto.LanguageDTO; +import jakarta.persistence.*; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; + @Entity @Table(name = "language") @Getter @Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class Language { - @Id - @GeneratedValue - @UuidGenerator - private String id; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; - @ManyToOne - private Service service; + @Column(name = "name") + private String name; - @ManyToOne - private Location location; + @Column(name = "code") + private String code; - @ManyToOne - private Phone phone; + @Column(name = "note") + private String note; - private String name; - private String code; - private String note; + public LanguageDTO toDTO() { + return LanguageDTO.builder() + .id(this.id) + .name(this.name) + .code(this.code) + .note(this.note) + .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 ae7a1e5..0ac64cf 100644 --- a/src/main/java/com/sarapis/orservice/entity/MetaTableDescription.java +++ b/src/main/java/com/sarapis/orservice/entity/MetaTableDescription.java @@ -1,31 +1,43 @@ 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 lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import com.sarapis.orservice.dto.MetaTableDescriptionDTO; +import jakarta.persistence.*; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; + @Entity @Table(name = "meta_table_description") @Setter @Getter @NoArgsConstructor @AllArgsConstructor +@Builder public class MetaTableDescription { - @Id - @GeneratedValue - @UuidGenerator - private String id; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; + + @Column(name = "name") + private String name; + + @Column(name = "language") + private String language; + + @Column(name = "character_set") + private String characterSet; - private String name; - private String language; - @Column(name = "character_set") - private String characterSet; + public MetaTableDescriptionDTO toDTO() { + return MetaTableDescriptionDTO.builder() + .id(this.id) + .name(this.name) + .language(this.language) + .characterSet(this.characterSet) + .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 47b7b92..732774d 100644 --- a/src/main/java/com/sarapis/orservice/entity/Metadata.java +++ b/src/main/java/com/sarapis/orservice/entity/Metadata.java @@ -1,50 +1,62 @@ 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 lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import com.sarapis.orservice.dto.MetadataDTO; +import jakarta.persistence.*; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.time.LocalDate; + @Entity @Table(name = "metadata") @Getter @Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class Metadata { - @Id - @GeneratedValue - @UuidGenerator - private String id; - - @Column(name = "resource_id", nullable = false, unique = true) - private String resourceId; - - @Enumerated(EnumType.STRING) - private ResourceType resourceType; - - @Column(name = "last_action_date") - private LocalDate lastActionDate; - - @Column(name = "last_action_type") - private String lastActionType; - - private String fieldName; - - private String previousValue; - - private String replacementValue; - - private String updatedBy; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; + + @Column(name = "resource_id", nullable = false) + private String resourceId; + + @Enumerated(EnumType.STRING) + @Column(name = "resource_type", nullable = false) + private ResourceType resourceType; + + @Column(name = "last_action_date", nullable = false) + private LocalDate lastActionDate; + + @Column(name = "last_action_type", nullable = false) + private String lastActionType; + + @Column(name = "field_name", nullable = false) + private String fieldName; + + @Column(name = "previous_value", nullable = false) + private String previousValue; + + @Column(name = "replacement_value", nullable = false) + private String replacementValue; + + @Column(name = "updated_by", nullable = false) + private String updatedBy; + + public MetadataDTO toDTO() { + return MetadataDTO.builder() + .id(this.id) + .resourceId(this.resourceId) + .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 0835995..dce94fa 100644 --- a/src/main/java/com/sarapis/orservice/entity/OrganizationIdentifier.java +++ b/src/main/java/com/sarapis/orservice/entity/OrganizationIdentifier.java @@ -1,38 +1,43 @@ 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 lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import com.sarapis.orservice.dto.OrganizationIdentifierDTO; +import jakarta.persistence.*; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; + @Entity @Table(name = "organization_identifier") -@Setter @Getter +@Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class OrganizationIdentifier { - @Id - @GeneratedValue - @UuidGenerator - private String id; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; + + @Column(name = "identifier_scheme") + private String identifierScheme; - @OneToOne - private Organization organization; + @Column(name = "identifier_type", nullable = false) + private String identifierType; - @Column(name = "identifier_scheme") - private String identifierScheme; + @Column(name = "identifier", nullable = false) + private String identifier; - @Column(name = "identifier_type") - private String identifierType; + public OrganizationIdentifierDTO toDTO() { + return OrganizationIdentifierDTO.builder() + .id(this.id) + .identifierScheme(this.identifierScheme) + .identifierType(this.identifierType) + .identifier(this.identifier) + .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 1410eae..5969a51 100644 --- a/src/main/java/com/sarapis/orservice/entity/Phone.java +++ b/src/main/java/com/sarapis/orservice/entity/Phone.java @@ -1,46 +1,53 @@ 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.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.Table; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import com.sarapis.orservice.dto.PhoneDTO; +import jakarta.persistence.*; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; +import java.util.List; + @Entity @Table(name = "phone") @Getter @Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class Phone { - @Id - @GeneratedValue - @UuidGenerator - private String id; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; + + @Column(name = "number", nullable = false) + private String number; - @ManyToOne - private Location location; + @Column(name = "extension") + private String extension; - @ManyToOne - private Service service; + @Column(name = "type") + private String type; - @ManyToOne - private Contact contact; + @Column(name = "description") + private String description; - @ManyToOne - private ServiceAtLocation serviceAtLocation; + @OneToMany(cascade = CascadeType.PERSIST) + @JoinColumn(name = "phone_id") + private List languages = new ArrayList<>(); - private String number; - private String extension; - private String type; - private String description; + 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(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 131e631..57c11bd 100644 --- a/src/main/java/com/sarapis/orservice/entity/Program.java +++ b/src/main/java/com/sarapis/orservice/entity/Program.java @@ -1,37 +1,43 @@ 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 lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import com.sarapis.orservice.dto.ProgramDTO; +import jakarta.persistence.*; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; + @Entity -@Table +@Table(name = "program") @Getter @Setter @AllArgsConstructor @NoArgsConstructor +@Builder public class Program { - @Id - @GeneratedValue - @UuidGenerator - private String id; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; - @ManyToOne - private Organization organization; + @Column(name = "name", nullable = false) + private String name; - 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; - private String description; + public ProgramDTO toDTO() { + return ProgramDTO.builder() + .id(this.id) + .name(this.name) + .alternateName(this.alternateName) + .description(this.description) + .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 2f23de7..1e8ae53 100644 --- a/src/main/java/com/sarapis/orservice/entity/RequiredDocument.java +++ b/src/main/java/com/sarapis/orservice/entity/RequiredDocument.java @@ -1,32 +1,39 @@ 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 lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import com.sarapis.orservice.dto.RequiredDocumentDTO; +import jakarta.persistence.*; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; + @Entity @Table(name = "required_document") @Getter @Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class RequiredDocument { - @Id - @GeneratedValue - @UuidGenerator - private String id; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; + + @Column(name = "document") + private String document; + + @Column(name = "uri") + private String uri; - @ManyToOne - private Service service; - private String document; - private String uri; + public RequiredDocumentDTO toDTO() { + return RequiredDocumentDTO.builder() + .id(this.id) + .document(this.document) + .uri(this.uri) + .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 598b32d..899c945 100644 --- a/src/main/java/com/sarapis/orservice/entity/Schedule.java +++ b/src/main/java/com/sarapis/orservice/entity/Schedule.java @@ -1,74 +1,111 @@ package com.sarapis.orservice.entity; -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 lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import com.sarapis.orservice.dto.ScheduleDTO; +import jakarta.persistence.*; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.time.LocalDate; +import java.time.LocalTime; +import java.util.ArrayList; + @Entity @Table(name = "schedule") @Getter @Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class Schedule { - @Id - @GeneratedValue - @UuidGenerator - private String id; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; + + @Column(name = "valid_from") + private LocalDate validFrom; + + @Column(name = "valid_to") + private LocalDate validTo; + + @Column(name = "dtstart") + private LocalDate dtStart; + + @Column(name = "timezone") + private int timezone; + + @Column(name = "until") + private LocalDate 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; - @ManyToOne - private Service service; + @Column(name = "interval") + private int interval; - @ManyToOne - private ServiceAtLocation serviceAtLocation; + @Column(name = "byday") + private String byday; - @Column(name = "valid_from") - private Date validFrom; + @Column(name = "byweekno") + private String byweekno; - @Column(name = "valid_to") - private Date validTo; + @Column(name = "bymonthday") + private String bymonthday; - @Column(name = "dtstart") - private Date dtStart; + @Column(name = "byyearday") + private String byyearday; - private int TimeZone; - private Date until; - private int count; + @Column(name = "description") + private String description; - @Enumerated(EnumType.STRING) - private WkSt wkst; + @Column(name = "opens_at") + private LocalTime opensAt; - @Enumerated(EnumType.STRING) - private Freq freq; + @Column(name = "closes_at") + private LocalTime closesAt; - private int interval; - private String byday; - private String byweekno; - private String bymonthday; - private String byyearday; - 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; - private String scheduleLink; - private String attendingType; - private String notes; + 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(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 2f8afbe..e1dccab 100644 --- a/src/main/java/com/sarapis/orservice/entity/ServiceArea.java +++ b/src/main/java/com/sarapis/orservice/entity/ServiceArea.java @@ -1,36 +1,52 @@ 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 lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import com.sarapis.orservice.dto.ServiceAreaDTO; +import jakarta.persistence.*; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; + @Entity @Table(name = "service_area") @Getter @Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class ServiceArea { - @Id - @GeneratedValue - @UuidGenerator - private String id; - - @ManyToOne - private Service service; - - private String name; - private String description; - private String extent; - private String extentType; - private String uri; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; + + @Column(name = "name") + private String name; + + @Column(name = "description") + private String description; + + @Column(name = "extent") + private String extent; + + @Enumerated(EnumType.STRING) + @Column(name = "extent_type") + private ExtentType extentType; + + @Column(name = "uri") + private String uri; + + 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(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 new file mode 100644 index 0000000..c14a420 --- /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.dto.ServiceCapacityDTO; +import jakarta.persistence.*; +import lombok.*; +import org.hibernate.annotations.UuidGenerator; + +import java.time.LocalDate; +import java.util.ArrayList; + +@Entity +@Table(name = "service_capacity") +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class ServiceCapacity { + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; + + @OneToOne + @JoinColumn(name = "unit_id") + private Unit unit = null; + + @Column(name = "available", nullable = false) + private int available; + + @Column(name = "maximum") + private int maximum; + + @Column(name = "description") + private String description; + + @Column(name = "updated", nullable = false) + private LocalDate updated; + + 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(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 6827cbd..ef33790 100644 --- a/src/main/java/com/sarapis/orservice/entity/Taxonomy.java +++ b/src/main/java/com/sarapis/orservice/entity/Taxonomy.java @@ -1,33 +1,46 @@ 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 lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import com.sarapis.orservice.dto.TaxonomyDTO; +import jakarta.persistence.*; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; + @Entity @Table(name = "taxonomy") -@Setter @Getter +@Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class Taxonomy { - @Id - @GeneratedValue - @UuidGenerator - private String id; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; + + @Column(name = "name", nullable = false) + private String name; - private String name; + @Column(name = "description", nullable = false) + private String description; - private String description; + @Column(name = "uri") + private String uri; - private String uri; + @Column(name = "version") + private String version; - private String version; + public TaxonomyDTO toDTO() { + return TaxonomyDTO.builder() + .id(this.id) + .name(this.name) + .description(this.description) + .uri(this.uri) + .version(this.version) + .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 d9bca73..59bf611 100644 --- a/src/main/java/com/sarapis/orservice/entity/TaxonomyTerm.java +++ b/src/main/java/com/sarapis/orservice/entity/TaxonomyTerm.java @@ -1,46 +1,64 @@ 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 lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import com.sarapis.orservice.dto.TaxonomyTermDTO; +import jakarta.persistence.*; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; + @Entity @Table(name = "taxonomy_term") @Setter @Getter @NoArgsConstructor @AllArgsConstructor +@Builder public class TaxonomyTerm { - @Id - @GeneratedValue - @UuidGenerator - private String id; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; + + @Column(name = "code") + private String code; + + @Column(name = "name", nullable = false) + private String name; + + @Column(name = "description", nullable = false) + private String description; - private String code; - private String name; - private String description; + @OneToOne + @JoinColumn(name = "parent_id") + private TaxonomyTerm parent = null; - @OneToOne - private TaxonomyTerm parent; + @Column(name = "taxonomy") + private String taxonomy; - @Column(name = "taxonomy") - private String taxonomyName; + @ManyToOne + @JoinColumn(name = "taxonomy_id") + private Taxonomy taxonomyDetail = null; - @ManyToOne - private Taxonomy taxonomy; - private String language; + @Column(name = "language") + private String language; - @Column(name = "term_uri") - private String termUri; + @Column(name = "term_uri") + private String termUri; + 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(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 new file mode 100644 index 0000000..0508205 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/entity/Unit.java @@ -0,0 +1,47 @@ +package com.sarapis.orservice.entity; + +import com.sarapis.orservice.dto.UnitDTO; +import jakarta.persistence.*; +import lombok.*; +import org.hibernate.annotations.UuidGenerator; + +import java.util.ArrayList; + +@Entity +@Table(name = "unit") +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class Unit { + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; + + @Column(name = "name", nullable = false) + private String name; + + @Column(name = "scheme") + private String scheme; + + @Column(name = "identifier") + private String identifier; + + @Column(name = "uri") + private String uri; + + public UnitDTO toDTO() { + return UnitDTO.builder() + .id(this.id) + .name(this.name) + .scheme(this.scheme) + .identifier(this.identifier) + .uri(this.uri) + .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 0f2f95a..7917cb0 100644 --- a/src/main/java/com/sarapis/orservice/entity/Url.java +++ b/src/main/java/com/sarapis/orservice/entity/Url.java @@ -1,37 +1,39 @@ package com.sarapis.orservice.entity; -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 lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import com.sarapis.orservice.dto.UrlDTO; +import jakarta.persistence.*; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; + @Entity @Table(name = "url") @Getter @Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class Url { - @Id - @GeneratedValue - @UuidGenerator - private String id; - private String label; - private String url; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; - @ManyToOne - private Organization organization; + @Column(name = "label") + private String label; - @ManyToOne - private Service service; + @Column(name = "url", nullable = false) + private String url; + public UrlDTO toDTO() { + return UrlDTO.builder() + .id(this.id) + .label(this.label) + .url(this.url) + .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 ad2db94..27c8ae4 100644 --- a/src/main/java/com/sarapis/orservice/entity/core/Location.java +++ b/src/main/java/com/sarapis/orservice/entity/core/Location.java @@ -1,60 +1,104 @@ 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 lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import com.sarapis.orservice.dto.LocationDTO; +import com.sarapis.orservice.entity.*; +import jakarta.persistence.*; +import lombok.*; import org.hibernate.annotations.UuidGenerator; +import java.util.ArrayList; +import java.util.List; + @Entity @Table(name = "location") @Getter @Setter -@AllArgsConstructor @NoArgsConstructor +@AllArgsConstructor +@Builder public class Location { - @Id - @GeneratedValue - @UuidGenerator - 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; + + @Column(name = "url") + private String url; + + @Column(name = "name") + private String name; + + @Column(name = "alternate_name") + private String alternateName; + + @Column(name = "description") + private String description; - @Column(name = "location_type") - @Enumerated(EnumType.STRING) - private LocationType locationType; + @Column(name = "transportation") + private String transportation; - @Column(name = "url") - private String Url; + @Column(name = "latitude") + private int latitude; - @ManyToOne - private Organization organization; + @Column(name = "longitude") + private int longitude; - private String name; + @Column(name = "external_identifier") + private String externalIdentifier; - @Column(name = "alternate_name") - private String alternateName; + @Column(name = "external_identifier_type") + private String externalIdentifierType; - private String description; + @OneToMany(cascade = CascadeType.PERSIST) + @JoinColumn(name = "location_id") + private List languages = new ArrayList<>(); - private String transportation; + @OneToMany(cascade = CascadeType.PERSIST) + @JoinColumn(name = "location_id") + private List
addresses = new ArrayList<>(); - private int latitude; + @OneToMany(cascade = CascadeType.PERSIST) + @JoinColumn(name = "location_id") + private List contacts = new ArrayList<>(); - private int longitude; + @OneToMany(cascade = CascadeType.PERSIST) + @JoinColumn(name = "location_id") + private List accessibility = new ArrayList<>(); - @Column(name = "external_identifier") - private String externalIdentifier; + @OneToMany(cascade = CascadeType.PERSIST) + @JoinColumn(name = "location_id") + private List phones = new ArrayList<>(); - @Column(name = "external_identifier_type") - private String externalIdentifierType; + @OneToMany(cascade = CascadeType.PERSIST) + @JoinColumn(name = "location_id") + private List schedules = 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(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 cb23587..cfd532b 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,146 @@ 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 lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +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; +import java.util.List; + @Entity @Table(name = "organization") @Getter @Setter @AllArgsConstructor @NoArgsConstructor +@Builder public class Organization { - @Id - @GeneratedValue - @UuidGenerator - private String id; + @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(cascade = CascadeType.PERSIST) + @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; - private String name; + @Column(name = "logo") + private String logo; - @Column(name = "alternate_name") - private String alternateName; + @Column(name = "uri") + private String uri; - private String description; + @OneToOne + @JoinColumn(name = "parent_organization_id") + private Organization parentOrganization = null; - private String email; + @OneToMany(cascade = CascadeType.PERSIST) + @JoinColumn(name = "organization_id") + private List funding = new ArrayList<>(); - private String website; + @OneToMany(cascade = CascadeType.PERSIST) + @JoinColumn(name = "organization_id") + private List contacts = new ArrayList<>(); - @OneToMany - private List additionalWebsites; + @OneToMany(cascade = CascadeType.PERSIST) + @JoinColumn(name = "organization_id") + private List phones = new ArrayList<>(); - @Column(name = "year_incorporated") - private int yearIncorporated; + @OneToMany(cascade = CascadeType.PERSIST) + @JoinColumn(name = "organization_id") + private List locations = new ArrayList<>(); - private String legalStatus; + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "organization_id", nullable = false) + private List programs = new ArrayList<>(); - private String logo; + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "organization_id", nullable = false) + private List organizationIdentifiers = new ArrayList<>(); - private String uri; + public OrganizationDTO toDTO() { + return OrganizationDTO.builder() + .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(new ArrayList<>()) + .metadata(new ArrayList<>()) + .build(); + } - @OneToOne - private Organization parentOrganization; + 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/entity/core/Service.java b/src/main/java/com/sarapis/orservice/entity/core/Service.java index 75a3153..5443895 100644 --- a/src/main/java/com/sarapis/orservice/entity/core/Service.java +++ b/src/main/java/com/sarapis/orservice/entity/core/Service.java @@ -1,91 +1,186 @@ 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 lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import com.sarapis.orservice.dto.ServiceDTO; +import com.sarapis.orservice.entity.*; +import jakarta.persistence.*; +import lombok.*; +import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.UuidGenerator; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + @Entity @Table(name = "service") @Getter @Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class Service { - @Id - @GeneratedValue - @UuidGenerator - private String id; - - @ManyToOne - private Organization organization; - - @ManyToOne - private Program program; - - private String name; - - @Column(name = "alternate_name") - private String alternateName; - - private String description; - - private String Url; - - private String email; - - @Enumerated(EnumType.STRING) - private Status status; - - @Column(name = "interpretation_services") - private String interpretationServices; - - @Column(name = "application_process") - private String applicationProcess; - - @Column(name = "fees_description") - private String feesDescription; - - @Column(name = "wait_time") - private String waitTime; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; - private String fees; + @Column(name = "name", nullable = false) + private String name; - private String accreditations; + @Column(name = "alternate_name") + private String alternateName; - @Column(name = "eligibility_description") - private String eligibilityDescription; + @Column(name = "description") + private String description; - @Column(name = "minimum_age") - private int minimumAge; + @Column(name = "url") + private String url; - @Column(name = "maximum_age") - private int maximumAge; + @OneToMany(cascade = CascadeType.PERSIST) + @JoinColumn(name = "service_id") + private List additionalUrls = new ArrayList<>(); - @Column(name = "assured_date") - private LocalDate assuredDate; + @Column(name = "email") + private String email; - @Column(name = "assurer_email") - private String assurerEmail; + @Enumerated(EnumType.STRING) + @Column(name = "status", nullable = false) + private Status status; - private String licenses; + @Column(name = "interpretation_services") + private String interpretationServices; - private String alert; + @Column(name = "application_process") + private String applicationProcess; - @Column(name = "last_modified") - private LocalDate lastModified; + @Column(name = "fees_description") + private String feesDescription; + // Deprecated + @Column(name = "wait_time") + private String waitTime; + + // Deprecated + @Column(name = "fees") + private String fees; + + @Column(name = "accreditations") + private String accreditations; + + @Column(name = "eligibility_description") + private String eligibilityDescription; + + @Column(name = "minimum_age") + private int minimumAge; + + @Column(name = "maximum_age") + private int maximumAge; + + @Column(name = "assured_date") + private LocalDate assuredDate; + + @Column(name = "assurer_email") + private String assurerEmail; + + // Deprecated + @Column(name = "licenses") + private String licenses; + + @Column(name = "alert") + private String alert; + + @Column(name = "last_modified") + private LocalDateTime lastModified; + + @OneToMany(cascade = CascadeType.PERSIST) + @JoinColumn(name = "service_id") + private List phones = new ArrayList<>(); + + @OneToMany(cascade = CascadeType.PERSIST) + @JoinColumn(name = "service_id") + private List schedules = new ArrayList<>(); + + @OneToMany(cascade = CascadeType.PERSIST) + @JoinColumn(name = "service_id") + private List serviceAreas = new ArrayList<>(); + + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "service_id", nullable = false) + private List serviceAtLocations = new ArrayList<>(); + + @OneToMany(cascade = CascadeType.PERSIST) + @JoinColumn(name = "service_id") + private List languages = new ArrayList<>(); + + // On Organization delete, all related Services should be deleted. + @ManyToOne(optional = false) + @JoinColumn(name = "organization_id", nullable = false) + private Organization organization; + + @OneToMany(cascade = CascadeType.PERSIST) + @JoinColumn(name = "service_id") + private List funding = new ArrayList<>(); + + @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(cascade = CascadeType.PERSIST) + @JoinColumn(name = "service_id") + private List requiredDocuments = new ArrayList<>(); + + @OneToMany(cascade = CascadeType.PERSIST) + @JoinColumn(name = "service_id") + private List contacts = new ArrayList<>(); + + @OneToMany(cascade = CascadeType.PERSIST) + @JoinColumn(name = "service_id") + private List capacities = 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(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 a3c91d3..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,34 +1,65 @@ 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 lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import com.sarapis.orservice.dto.ServiceAtLocationDTO; +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; +import java.util.ArrayList; +import java.util.List; + @Entity @Table(name = "service_at_location") -@Setter @Getter +@Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class ServiceAtLocation { - @Id - @GeneratedValue - @UuidGenerator - private String id; + @Id + @GeneratedValue + @UuidGenerator + @Column(name = "id", nullable = false) + private String id; + + @Column(name = "description") + private String description; + + @OneToMany(cascade = CascadeType.PERSIST) + @JoinColumn(name = "service_at_location_id") + private List serviceAreas = new ArrayList<>(); + + @OneToMany(cascade = CascadeType.PERSIST) + @JoinColumn(name = "service_at_location_id") + private List contacts = new ArrayList<>(); + + @OneToMany(cascade = CascadeType.PERSIST) + @JoinColumn(name = "service_at_location_id") + private List phones = new ArrayList<>(); - @ManyToOne - private Service service; + @OneToMany(cascade = CascadeType.PERSIST) + @JoinColumn(name = "service_at_location_id") + private List schedules = new ArrayList<>(); - @ManyToOne - private Location location; + @OneToOne(orphanRemoval = true, optional = false) + @JoinColumn(name = "location_id", nullable = false) + private Location location; - private String description; + 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(new ArrayList<>()) + .metadata(new ArrayList<>()) + .build(); + } } 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..108357a --- /dev/null +++ b/src/main/java/com/sarapis/orservice/repository/AccessibilityRepository.java @@ -0,0 +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 new file mode 100644 index 0000000..e538c5f --- /dev/null +++ b/src/main/java/com/sarapis/orservice/repository/AddressRepository.java @@ -0,0 +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 new file mode 100644 index 0000000..4517c26 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/repository/AttributeRepository.java @@ -0,0 +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/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..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 { +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/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..b386eb9 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/service/AccessibilityServiceImpl.java @@ -0,0 +1,91 @@ +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.entity.Accessibility; +import com.sarapis.orservice.entity.Attribute; +import com.sarapis.orservice.entity.Metadata; +import com.sarapis.orservice.repository.AccessibilityRepository; +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; + +@Service +public class AccessibilityServiceImpl implements AccessibilityService { + private final AccessibilityRepository accessibilityRepository; + private final AttributeRepository attributeRepository; + private final MetadataRepository metadataRepository; + + @Autowired + public AccessibilityServiceImpl(AccessibilityRepository accessibilityRepository, AttributeRepository attributeRepository, MetadataRepository metadataRepository) { + this.accessibilityRepository = accessibilityRepository; + this.attributeRepository = attributeRepository; + this.metadataRepository = metadataRepository; + } + + @Override + public List getAllAccessibilities() { + List accessibilityDTOs = this.accessibilityRepository.findAll().stream().map(Accessibility::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(); + this.addRelatedData(accessibilityDTO); + return accessibilityDTO; + } + + @Override + public AccessibilityDTO createAccessibility(AccessibilityDTO accessibilityDTO) { + Accessibility accessibility = this.accessibilityRepository.save(accessibilityDTO.toEntity()); + + for (AttributeDTO attributeDTO : accessibilityDTO.getAttributes()) { + this.attributeRepository.save(attributeDTO.toEntity(accessibility.getId())); + } + + for (MetadataDTO metadataDTO : accessibilityDTO.getMetadata()) { + this.metadataRepository.save(metadataDTO.toEntity(accessibility.getId())); + } + + AccessibilityDTO savedAccessibilityDTO = this.accessibilityRepository.save(accessibility).toDTO(); + this.addRelatedData(savedAccessibilityDTO); + return savedAccessibilityDTO; + } + + @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 accessibility = this.accessibilityRepository.findById(id) + .orElseThrow(() -> new RuntimeException("Accessibility not found.")); + this.accessibilityRepository.deleteAttributes(accessibility.getId()); + 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/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..91546ea --- /dev/null +++ b/src/main/java/com/sarapis/orservice/service/AddressServiceImpl.java @@ -0,0 +1,94 @@ +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; + +@Service +public class AddressServiceImpl implements AddressService { + private final AddressRepository addressRepository; + private final AttributeRepository attributeRepository; + private final MetadataRepository metadataRepository; + + public AddressServiceImpl(AddressRepository addressRepository, AttributeRepository attributeRepository, MetadataRepository metadataRepository) { + this.addressRepository = addressRepository; + this.attributeRepository = attributeRepository; + this.metadataRepository = metadataRepository; + } + + @Override + public List getAllAddresses() { + List addressDTOs = this.addressRepository.findAll().stream().map(Address::toDTO).toList(); + addressDTOs.forEach(this::addRelatedData); + return addressDTOs; + } + + @Override + public AddressDTO getAddressById(String id) { + Address address = this.addressRepository.findById(id) + .orElseThrow(() -> new RuntimeException("Address not found.")); + AddressDTO addressDTO = address.toDTO(); + this.addRelatedData(addressDTO); + return addressDTO; + } + + @Override + public AddressDTO createAddress(AddressDTO addressDTO) { + 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(); + this.addRelatedData(savedAddressDTO); + return savedAddressDTO; + } + + @Override + public AddressDTO updateAddress(String id, AddressDTO addressDTO) { + Address oldAddress = this.addressRepository.findById(id) + .orElseThrow(() -> new RuntimeException("Address not found.")); + + 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 updatedAddress.toDTO(); + } + + @Override + public void deleteAddress(String id) { + Address address = this.addressRepository.findById(id) + .orElseThrow(() -> new RuntimeException("Address not found.")); + + this.addressRepository.deleteAttributes(address.getId()); + 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/AttributeService.java b/src/main/java/com/sarapis/orservice/service/AttributeService.java new file mode 100644 index 0000000..56cfedb --- /dev/null +++ b/src/main/java/com/sarapis/orservice/service/AttributeService.java @@ -0,0 +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 new file mode 100644 index 0000000..1062151 --- /dev/null +++ b/src/main/java/com/sarapis/orservice/service/AttributeServiceImpl.java @@ -0,0 +1,81 @@ +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.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; + +@Service +public class AttributeServiceImpl implements AttributeService { + private final AttributeRepository attributeRepository; + private final MetadataRepository metadataRepository; + + @Autowired + public AttributeServiceImpl(AttributeRepository attributeRepository, MetadataRepository metadataRepository) { + this.attributeRepository = attributeRepository; + this.metadataRepository = metadataRepository; + } + + @Override + public List getAllAttributes() { + List attributeDTOs = this.attributeRepository.findAll().stream().map(Attribute::toDTO).toList(); + attributeDTOs.forEach(this::addRelatedData); + return attributeDTOs; + } + + @Override + public AttributeDTO getAttributeById(String id) { + Attribute attribute = this.attributeRepository.findById(id) + .orElseThrow(() -> new RuntimeException("Attribute not found.")); + AttributeDTO attributeDTO = attribute.toDTO(); + this.addRelatedData(attributeDTO); + return attributeDTO; + } + + @Override + public AttributeDTO createAttribute(AttributeDTO attributeDTO) { + Attribute attribute = this.attributeRepository.save(attributeDTO.toEntity(attributeDTO.getLinkId())); + + for (MetadataDTO metadataDTO : attributeDTO.getMetadata()) { + this.metadataRepository.save(metadataDTO.toEntity(attribute.getId())); + } + + AttributeDTO savedAttributedDTO = this.attributeRepository.save(attribute).toDTO(); + this.addRelatedData(savedAttributedDTO); + return savedAttributedDTO; + } + + @Override + public AttributeDTO updateAttribute(String id, AttributeDTO attributeDTO) { + 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 attribute = this.attributeRepository.findById(id) + .orElseThrow(() -> new RuntimeException("Attribute not found.")); + 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/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; + } +} 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 e227172..26fa1dc 100644 --- a/src/main/java/com/sarapis/orservice/service/OrganizationServiceImpl.java +++ b/src/main/java/com/sarapis/orservice/service/OrganizationServiceImpl.java @@ -1,95 +1,105 @@ 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 java.io.ByteArrayInputStream; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.List; + @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 = this.organizationRepository.findAll().stream().map(Organization::toDTO).toList(); + organizationDTOs.forEach(this::addRelatedData); + return organizationDTOs; + } + + @Override + public OrganizationDTO getOrganizationById(String id) { + Organization organization = this.organizationRepository.findById(id) + .orElseThrow(() -> new RuntimeException("Organization not found.")); + OrganizationDTO organizationDTO = organization.toDTO(); + this.addRelatedData(organizationDTO); + return organizationDTO; + } + + @Override + public OrganizationDTO createOrganization(OrganizationDTO organizationDTO) { + Organization organization = this.organizationRepository.save(organizationDTO.toEntity()); + + for (AttributeDTO attributeDTO : organizationDTO.getAttributes()) { + this.attributeRepository.save(attributeDTO.toEntity(organization.getId())); + } + + for (MetadataDTO metadataDTO : organizationDTO.getMetadata()) { + this.metadataRepository.save(metadataDTO.toEntity(organization.getId())); + } + + OrganizationDTO savedOrganizationDTO = this.organizationRepository.save(organization).toDTO(); + this.addRelatedData(savedOrganizationDTO); + return savedOrganizationDTO; + } + + @Override + public OrganizationDTO updateOrganization(String id, OrganizationDTO organizationDTO) { + 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 = this.organizationRepository.findById(id) + .orElseThrow(() -> new RuntimeException("Organization not found.")); + this.organizationRepository.deleteAttributes(organization.getId()); + this.organizationRepository.deleteMetadata(organization.getId()); + this.organizationRepository.delete(organization); + } + + @Override + public ByteArrayInputStream loadCSV() { + List organizations = organizationRepository.findAll(); + return Organization.toCSV(organizations); + } - 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; - } - - @Override - public List getAllOrganizations() { - return organizationRepository.findAll().stream() - .map(this::mapToDTO) - .collect(Collectors.toList()); - } - - @Override - public OrganizationDTO getOrganizationById(String id) { - Organization organization = organizationRepository.findById(Long.parseLong(id)) - .orElseThrow(() -> new RuntimeException("Organization not found")); - return mapToDTO(organization); - } - - @Override - public OrganizationDTO createOrganization(OrganizationDTO organizationDTO) { - Organization organization = mapToEntity(organizationDTO); - Organization savedOrganization = organizationRepository.save(organization); - return mapToDTO(savedOrganization); - } - - @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 mapToDTO(updatedOrganization); - } - - @Override - public void deleteOrganization(String id) { - Organization organization = organizationRepository.findById(Long.parseLong(id)) - .orElseThrow(() -> new RuntimeException("Could not find organization")); - 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()); + } }