Remove obsolete packaging and property-related code.
Eliminates unused controllers, services, DTOs, and models for packaging and property types from the codebase. Streamlines the repository by renaming and refactoring existing classes to improve module organization.
This commit is contained in:
parent
2c0707717e
commit
7eb5667d32
46 changed files with 955 additions and 866 deletions
|
|
@ -15,16 +15,16 @@ import java.util.List;
|
|||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/countries")
|
||||
public class CountryPropertyController {
|
||||
public class CountryController {
|
||||
|
||||
private final CountryService countryService;
|
||||
|
||||
/**
|
||||
* Constructs a new instance of {@link CountryPropertyController} with the given {@link CountryService}.
|
||||
* Constructs a new instance of {@link CountryController} with the given {@link CountryService}.
|
||||
*
|
||||
* @param countryService the service responsible for interacting with country data
|
||||
*/
|
||||
public CountryPropertyController(CountryService countryService) {
|
||||
public CountryController(CountryService countryService) {
|
||||
this.countryService = countryService;
|
||||
}
|
||||
|
||||
|
|
@ -52,7 +52,6 @@ public class CountryPropertyController {
|
|||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves a complete list of countries with optional filtering.
|
||||
*
|
||||
|
|
@ -80,7 +79,7 @@ public class CountryPropertyController {
|
|||
* @return a {@link ResponseEntity} containing a {@link CountryDetailDTO} with the country's details
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<CountryDetailDTO> getCountryDetails(@PathVariable Integer id) {
|
||||
return ResponseEntity.ok(countryService.getCountry(id));
|
||||
public ResponseEntity<CountryDetailDTO> getCountryDetails(@PathVariable Integer id, @RequestParam(name = "property_set", defaultValue = "0", required = false) Integer propertySetId) {
|
||||
return ResponseEntity.ok(countryService.getCountry(id, propertySetId).orElseThrow());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
package de.avatic.lcc.controller.configuration;
|
||||
|
||||
import de.avatic.lcc.dto.configuration.packaging.view.PackagingViewDTO;
|
||||
import de.avatic.lcc.dto.configuration.packaging.update.PackagingUpdateDTO;
|
||||
import de.avatic.lcc.repositories.packaging.PackagingRepository;
|
||||
import de.avatic.lcc.repositories.pagination.SearchQueryResult;
|
||||
import de.avatic.lcc.service.configuration.PackagingService;
|
||||
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/packaging")
|
||||
public class PackagingController {
|
||||
|
||||
private final PackagingService packagingService;
|
||||
|
||||
@Autowired
|
||||
public PackagingController(PackagingService packagingService) {
|
||||
this.packagingService = packagingService;
|
||||
}
|
||||
|
||||
@GetMapping("/")
|
||||
public ResponseEntity<List<PackagingViewDTO>> listPackaging(
|
||||
@RequestParam(defaultValue = "20") int limit,
|
||||
@RequestParam(defaultValue = "0") int page,
|
||||
@RequestParam(required = false) Integer materialId,
|
||||
@RequestParam(required = false) Integer supplierId) {
|
||||
|
||||
SearchQueryResult<PackagingViewDTO> listEntries = packagingService.listPackaging(materialId, supplierId, page, limit);
|
||||
|
||||
return ResponseEntity.ok()
|
||||
.header("X-Total-Count", String.valueOf(listEntries.getTotalElements()))
|
||||
.header("X-Page-Count", String.valueOf(listEntries.getTotalPages()))
|
||||
.header("X-Current-Page", String.valueOf(page))
|
||||
.body(listEntries.toList());
|
||||
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<PackagingViewDTO> getPackagingDetails(@PathVariable Integer id) {
|
||||
return ResponseEntity.ok(packagingService.getPackaging(id));
|
||||
}
|
||||
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<Void> updatePackaging(@PathVariable Integer id, @RequestBody PackagingUpdateDTO packaging) {
|
||||
packagingService.updatePackaging(id, packaging);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Integer> deletePackagingDetails(@PathVariable Integer id) {
|
||||
return ResponseEntity.ok(packagingService.deletePackaging(id));
|
||||
}
|
||||
|
||||
@PostMapping("/")
|
||||
public ResponseEntity<Integer> addPackaging(@RequestBody PackagingUpdateDTO packaging) {
|
||||
return ResponseEntity.ok(packagingService.createPackaging(packaging));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
package de.avatic.lcc.controller.configuration;
|
||||
|
||||
import de.avatic.lcc.dto.configuration.properties.post.PropertiesPostDTO;
|
||||
import de.avatic.lcc.service.configuration.PropertiesService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/properties")
|
||||
public class PropertiesController {
|
||||
|
||||
private final PropertiesService propertiesService;
|
||||
|
||||
public PropertiesController(PropertiesService propertiesService) {
|
||||
this.propertiesService = propertiesService;
|
||||
}
|
||||
|
||||
@PostMapping("/{type}/{id}")
|
||||
public void setProperties(@PathVariable String type, @PathVariable Integer id, @RequestBody List<PropertiesPostDTO> properties) {
|
||||
propertiesService.setProperties(type, properties);
|
||||
}
|
||||
|
||||
@PostMapping("/{type}/{id}/{external_mapping}")
|
||||
public void setProperties(@PathVariable(name = "type") String type, @PathVariable(name= "external_mapping") String externalMappingId, @RequestBody PropertiesPostDTO property) {
|
||||
propertiesService.setProperties(type, List.of(property));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
package de.avatic.lcc.controller.configuration;
|
||||
|
||||
import de.avatic.lcc.dto.configuration.properties.PropertySetDTO;
|
||||
import de.avatic.lcc.dto.generic.PropertyDTO;
|
||||
import de.avatic.lcc.model.country.IsoCode;
|
||||
import de.avatic.lcc.model.properties.PropertySet;
|
||||
import de.avatic.lcc.service.configuration.CountryService;
|
||||
import de.avatic.lcc.service.configuration.PropertiesService;
|
||||
import de.avatic.lcc.service.configuration.StagedChangesService;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* REST controller for managing application properties.
|
||||
* Provides endpoints for listing, modifying, and approving staged properties.
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/properties")
|
||||
public class PropertyController {
|
||||
|
||||
private final PropertiesService propertiesService;
|
||||
private final StagedChangesService stagedChangesService;
|
||||
private final CountryService countryService;
|
||||
|
||||
/**
|
||||
* Constructs a new PropertyController with the provided services.
|
||||
*
|
||||
* @param propertiesService Service for managing properties.
|
||||
* @param stagedChangesService Service for managing staged changes.
|
||||
*/
|
||||
public PropertyController(PropertiesService propertiesService, StagedChangesService stagedChangesService, CountryService countryService) {
|
||||
this.propertiesService = propertiesService;
|
||||
this.stagedChangesService = stagedChangesService;
|
||||
this.countryService = countryService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the list of all application properties.
|
||||
*
|
||||
* @return ResponseEntity containing the list of PropertyDTO objects.
|
||||
*/
|
||||
@GetMapping("/")
|
||||
public ResponseEntity<List<PropertyDTO>> listProperties(@RequestParam(name = "property_set", defaultValue = "0", required = false) Integer propertySetId) {
|
||||
return ResponseEntity.ok(propertiesService.listProperties(propertySetId));
|
||||
}
|
||||
|
||||
@GetMapping("/periods")
|
||||
public ResponseEntity<List<PropertySetDTO>> listPeriods() {
|
||||
return ResponseEntity.ok(propertiesService.listPropertySets());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a country-specific property by ISO code and external mapping ID.
|
||||
*
|
||||
* @param isoCode The ISO code of the country.
|
||||
* @param mappingId The external mapping ID for the property.
|
||||
* @param value The value to set for the property.
|
||||
* @return ResponseEntity indicating the operation status.
|
||||
*/
|
||||
@PutMapping("/country/{iso}/{external_mapping_id}")
|
||||
public ResponseEntity<Void> setCountryProperty(@PathVariable("iso") IsoCode isoCode, @PathVariable(name = "external_mapping_id") String mappingId, @RequestBody String value) {
|
||||
countryService.setProperties(isoCode, mappingId, value);
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a system-wide property by external mapping ID.
|
||||
*
|
||||
* @param externalMappingId The external mapping ID for the property.
|
||||
* @param value The value to set for the property.
|
||||
* @return ResponseEntity indicating the operation status.
|
||||
*/
|
||||
@PutMapping("/system/{external_mapping_id}")
|
||||
public ResponseEntity<Void> setProperties(@PathVariable(name = "external_mapping_id") String externalMappingId, @RequestBody String value) {
|
||||
propertiesService.setProperties(externalMappingId, value);
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if there are any staged changes for properties.
|
||||
*
|
||||
* @return ResponseEntity containing true if drafts are present, false otherwise.
|
||||
*/
|
||||
@GetMapping("/staged_changes")
|
||||
public ResponseEntity<Boolean> checkPropertiesDrafts() {
|
||||
return ResponseEntity.ok(stagedChangesService.hasPropertiesDraft());
|
||||
}
|
||||
|
||||
/**
|
||||
* Approves all staged changes for properties.
|
||||
*
|
||||
* @return ResponseEntity indicating the operation status.
|
||||
*/
|
||||
@PutMapping("/staged_changes")
|
||||
public ResponseEntity<Void> approvePropertiesDrafts() {
|
||||
stagedChangesService.approvePropertiesDrafts();
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package de.avatic.lcc.dto.configuration.countries.view;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import de.avatic.lcc.dto.generic.PropertyDTO;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
|
|
@ -16,7 +17,7 @@ public class CountryDetailDTO {
|
|||
@JsonProperty("region_code")
|
||||
private String regionCode;
|
||||
|
||||
private Collection<CountryViewPropertyDTO> properties;
|
||||
private Collection<PropertyDTO> properties;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
|
|
@ -50,11 +51,11 @@ public class CountryDetailDTO {
|
|||
this.regionCode = regionCode;
|
||||
}
|
||||
|
||||
public Collection<CountryViewPropertyDTO> getProperties() {
|
||||
public Collection<PropertyDTO> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public void setProperties(Collection<CountryViewPropertyDTO> properties) {
|
||||
public void setProperties(Collection<PropertyDTO> properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,48 @@
|
|||
package de.avatic.lcc.dto.configuration.properties;
|
||||
|
||||
import de.avatic.lcc.model.properties.PropertySetState;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class PropertySetDTO {
|
||||
|
||||
private Integer id;
|
||||
|
||||
private LocalDateTime startDate;
|
||||
|
||||
private LocalDateTime endDate;
|
||||
|
||||
private PropertySetState state;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public LocalDateTime getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public void setStartDate(LocalDateTime startDate) {
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
||||
public LocalDateTime getEndDate() {
|
||||
return endDate;
|
||||
}
|
||||
|
||||
public void setEndDate(LocalDateTime endDate) {
|
||||
this.endDate = endDate;
|
||||
}
|
||||
|
||||
public PropertySetState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(PropertySetState state) {
|
||||
this.state = state;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
package de.avatic.lcc.dto.configuration.properties.post;
|
||||
|
||||
public class PropertiesPostDTO {
|
||||
|
||||
String externalMappingId;
|
||||
String value;
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
package de.avatic.lcc.dto.configuration.countries.view;
|
||||
package de.avatic.lcc.dto.generic;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class CountryViewPropertyDTO {
|
||||
public class PropertyDTO {
|
||||
|
||||
private String name;
|
||||
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package de.avatic.lcc.model.packaging;
|
||||
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.jdbc.core.mapping.AggregateReference;
|
||||
import org.springframework.data.relational.core.mapping.Table;
|
||||
|
||||
public class PackagingProperty {
|
||||
|
||||
private Integer id;
|
||||
|
||||
private String propertyValue;
|
||||
|
||||
private Integer packagingId;
|
||||
|
||||
private PackagingPropertyType packagingPropertyType;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getPropertyValue() {
|
||||
return propertyValue;
|
||||
}
|
||||
|
||||
public void setPropertyValue(String propertyValue) {
|
||||
this.propertyValue = propertyValue;
|
||||
}
|
||||
|
||||
public Integer getPackagingId() {
|
||||
return packagingId;
|
||||
}
|
||||
|
||||
public void setPackagingId(Integer packagingId) {
|
||||
this.packagingId = packagingId;
|
||||
}
|
||||
|
||||
public PackagingPropertyType getPackagingPropertyType() {
|
||||
return packagingPropertyType;
|
||||
}
|
||||
|
||||
public void setPackagingPropertyType(PackagingPropertyType packagingPropertyType) {
|
||||
this.packagingPropertyType = packagingPropertyType;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,103 +0,0 @@
|
|||
package de.avatic.lcc.model.packaging;
|
||||
|
||||
|
||||
import de.avatic.lcc.model.properties.PropertyDataType;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.relational.core.mapping.Table;
|
||||
|
||||
|
||||
/**
|
||||
* Represents the type of a property used in packaging.
|
||||
* This includes details such as its name, data type, validation rules, and whether the property is required.
|
||||
*/
|
||||
public class PackagingPropertyType {
|
||||
|
||||
|
||||
/**
|
||||
* Unique identifier for the packaging property type.
|
||||
*/
|
||||
private Integer id;
|
||||
|
||||
@NotNull
|
||||
@Size(max = 255)
|
||||
/**
|
||||
* Name of the property type.
|
||||
* Must not be null and must not exceed 255 characters.
|
||||
*/
|
||||
private String name;
|
||||
|
||||
@Size(max = 16)
|
||||
/**
|
||||
* The data type of the property, defining the kind of value it holds.
|
||||
* Must not exceed 16 characters.
|
||||
*/
|
||||
private PropertyDataType dataType;
|
||||
|
||||
@Size(max = 64)
|
||||
/**
|
||||
* Optional validation rule specifying restrictions or patterns for this property type.
|
||||
* Must not exceed 64 characters.
|
||||
*/
|
||||
private String validationRule;
|
||||
|
||||
@NotNull
|
||||
/**
|
||||
* Indicates whether the property is mandatory (true) or optional (false).
|
||||
* Must not be null.
|
||||
*/
|
||||
private Boolean isRequired;
|
||||
|
||||
@Size(max = 16)
|
||||
private String externalMappingId;
|
||||
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public PropertyDataType getDataType() {
|
||||
return dataType;
|
||||
}
|
||||
|
||||
public void setDataType(PropertyDataType dataType) {
|
||||
this.dataType = dataType;
|
||||
}
|
||||
|
||||
public String getValidationRule() {
|
||||
return validationRule;
|
||||
}
|
||||
|
||||
public void setValidationRule(String validationRule) {
|
||||
this.validationRule = validationRule;
|
||||
}
|
||||
|
||||
public Boolean getRequired() {
|
||||
return isRequired;
|
||||
}
|
||||
|
||||
public void setRequired(Boolean required) {
|
||||
isRequired = required;
|
||||
}
|
||||
|
||||
public String getExternalMappingId() {
|
||||
return externalMappingId;
|
||||
}
|
||||
|
||||
public void setExternalMappingId(String externalMappingId) {
|
||||
this.externalMappingId = externalMappingId;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,24 +1,25 @@
|
|||
package de.avatic.lcc.model.properties;
|
||||
|
||||
|
||||
import jakarta.validation.constraints.Size;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.jdbc.core.mapping.AggregateReference;
|
||||
import org.springframework.data.relational.core.mapping.Column;
|
||||
import org.springframework.data.relational.core.mapping.Table;
|
||||
|
||||
|
||||
public class CountryProperty {
|
||||
|
||||
private Integer id;
|
||||
|
||||
private String value;
|
||||
|
||||
private CountryPropertyType type;
|
||||
private PropertyType type;
|
||||
|
||||
private Integer countryId;
|
||||
|
||||
private PropertySet propertySet;
|
||||
private Integer propertySetId;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
|
|
@ -28,11 +29,11 @@ public class CountryProperty {
|
|||
this.value = value;
|
||||
}
|
||||
|
||||
public CountryPropertyType getType() {
|
||||
public PropertyType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(CountryPropertyType type) {
|
||||
public void setType(PropertyType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
|
@ -44,11 +45,11 @@ public class CountryProperty {
|
|||
this.countryId = countryId;
|
||||
}
|
||||
|
||||
public PropertySet getPropertySet() {
|
||||
return propertySet;
|
||||
public Integer getPropertySetId() {
|
||||
return propertySetId;
|
||||
}
|
||||
|
||||
public void setPropertySet(PropertySet propertySet) {
|
||||
this.propertySet = propertySet;
|
||||
public void setPropertySetId(Integer propertySetId) {
|
||||
this.propertySetId = propertySetId;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,76 +0,0 @@
|
|||
package de.avatic.lcc.model.properties;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.relational.core.mapping.Table;
|
||||
|
||||
|
||||
|
||||
public class CountryPropertyType {
|
||||
|
||||
private Integer id;
|
||||
|
||||
@NotNull
|
||||
@Size(max = 255)
|
||||
private String name;
|
||||
|
||||
@Size(max = 16)
|
||||
private String externalMappingId;
|
||||
|
||||
@NotNull
|
||||
private PropertyDataType dataType;
|
||||
|
||||
@Size(max = 64)
|
||||
private String validationRule;
|
||||
|
||||
private Boolean isRequired;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getExternalMappingId() {
|
||||
return externalMappingId;
|
||||
}
|
||||
|
||||
public void setExternalMappingId(String externalMappingId) {
|
||||
this.externalMappingId = externalMappingId;
|
||||
}
|
||||
|
||||
public PropertyDataType getDataType() {
|
||||
return dataType;
|
||||
}
|
||||
|
||||
public void setDataType(PropertyDataType dataType) {
|
||||
this.dataType = dataType;
|
||||
}
|
||||
|
||||
public String getValidationRule() {
|
||||
return validationRule;
|
||||
}
|
||||
|
||||
public void setValidationRule(String validationRule) {
|
||||
this.validationRule = validationRule;
|
||||
}
|
||||
|
||||
public Boolean getRequired() {
|
||||
return isRequired;
|
||||
}
|
||||
|
||||
public void setRequired(Boolean required) {
|
||||
isRequired = required;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
package de.avatic.lcc.model.properties;
|
||||
|
||||
|
||||
public class PackagingProperty {
|
||||
|
||||
private Integer id;
|
||||
|
||||
private String value;
|
||||
|
||||
private Integer packagingId;
|
||||
|
||||
private PropertyType type;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Integer getPackagingId() {
|
||||
return packagingId;
|
||||
}
|
||||
|
||||
public void setPackagingId(Integer packagingId) {
|
||||
this.packagingId = packagingId;
|
||||
}
|
||||
|
||||
public PropertyType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(PropertyType type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
|
|
@ -9,10 +9,8 @@ import java.time.OffsetDateTime;
|
|||
import java.util.Set;
|
||||
|
||||
|
||||
@Table(name = "property_set")
|
||||
public class PropertySet {
|
||||
|
||||
@Id
|
||||
private Integer id;
|
||||
|
||||
private LocalDateTime startDate;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,73 @@
|
|||
package de.avatic.lcc.model.properties;
|
||||
|
||||
public enum PropertyType {
|
||||
COUNTRY, SYSTEM, PACKAGING
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
|
||||
public class PropertyType {
|
||||
|
||||
private Integer id;
|
||||
|
||||
@NotNull
|
||||
@Size(max = 255)
|
||||
private String name;
|
||||
|
||||
@Size(max = 16)
|
||||
private String externalMappingId;
|
||||
|
||||
@NotNull
|
||||
private PropertyDataType dataType;
|
||||
|
||||
@Size(max = 64)
|
||||
private String validationRule;
|
||||
|
||||
private Boolean isRequired;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getExternalMappingId() {
|
||||
return externalMappingId;
|
||||
}
|
||||
|
||||
public void setExternalMappingId(String externalMappingId) {
|
||||
this.externalMappingId = externalMappingId;
|
||||
}
|
||||
|
||||
public PropertyDataType getDataType() {
|
||||
return dataType;
|
||||
}
|
||||
|
||||
public void setDataType(PropertyDataType dataType) {
|
||||
this.dataType = dataType;
|
||||
}
|
||||
|
||||
public String getValidationRule() {
|
||||
return validationRule;
|
||||
}
|
||||
|
||||
public void setValidationRule(String validationRule) {
|
||||
this.validationRule = validationRule;
|
||||
}
|
||||
|
||||
public Boolean getRequired() {
|
||||
return isRequired;
|
||||
}
|
||||
|
||||
public void setRequired(Boolean required) {
|
||||
isRequired = required;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +1,15 @@
|
|||
package de.avatic.lcc.model.properties;
|
||||
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.jdbc.core.mapping.AggregateReference;
|
||||
import org.springframework.data.relational.core.mapping.Column;
|
||||
import org.springframework.data.relational.core.mapping.Table;
|
||||
|
||||
@Table(name = "system_property")
|
||||
public class SystemProperty {
|
||||
|
||||
@Id
|
||||
private Integer id;
|
||||
|
||||
@Size(max = 500)
|
||||
private String propertyValue;
|
||||
private String value;
|
||||
|
||||
@NotNull
|
||||
@Column("system_property_type_id")
|
||||
private AggregateReference<SystemPropertyType,Integer> type;
|
||||
private PropertyType type;
|
||||
|
||||
private Integer propertySetId;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
|
|
@ -29,19 +19,27 @@ public class SystemProperty {
|
|||
this.id = id;
|
||||
}
|
||||
|
||||
public String getPropertyValue() {
|
||||
return propertyValue;
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setPropertyValue(String propertyValue) {
|
||||
this.propertyValue = propertyValue;
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public AggregateReference<SystemPropertyType, Integer> getType() {
|
||||
public PropertyType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(AggregateReference<SystemPropertyType, Integer> type) {
|
||||
public void setType(PropertyType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Integer getPropertySetId() {
|
||||
return propertySetId;
|
||||
}
|
||||
|
||||
public void setPropertySetId(Integer propertySetId) {
|
||||
this.propertySetId = propertySetId;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,68 +0,0 @@
|
|||
package de.avatic.lcc.model.properties;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.relational.core.mapping.Table;
|
||||
|
||||
|
||||
@Table("system_property_type")
|
||||
public class SystemPropertyType {
|
||||
|
||||
@Id
|
||||
private Integer id;
|
||||
|
||||
@NotNull
|
||||
@Size(max = 255)
|
||||
private String name;
|
||||
|
||||
@Size(max = 16)
|
||||
private String externalMappingId;
|
||||
|
||||
@NotNull
|
||||
private PropertyDataType dataType;
|
||||
|
||||
@Size(max = 64)
|
||||
private String validationRule;
|
||||
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getExternalMappingId() {
|
||||
return externalMappingId;
|
||||
}
|
||||
|
||||
public void setExternalMappingId(String externalMappingId) {
|
||||
this.externalMappingId = externalMappingId;
|
||||
}
|
||||
|
||||
public PropertyDataType getDataType() {
|
||||
return dataType;
|
||||
}
|
||||
|
||||
public void setDataType(PropertyDataType dataType) {
|
||||
this.dataType = dataType;
|
||||
}
|
||||
|
||||
public String getValidationRule() {
|
||||
return validationRule;
|
||||
}
|
||||
|
||||
public void setValidationRule(String validationRule) {
|
||||
this.validationRule = validationRule;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,33 @@
|
|||
package de.avatic.lcc.model.users;
|
||||
|
||||
public class Group {
|
||||
|
||||
private Integer id;
|
||||
private String name;
|
||||
private String description;
|
||||
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,78 @@
|
|||
package de.avatic.lcc.model.users;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class User {
|
||||
|
||||
private Integer id;
|
||||
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
|
||||
private String email;
|
||||
|
||||
@NotNull
|
||||
private String workdayId;
|
||||
|
||||
private Boolean isActive;
|
||||
|
||||
private List<@NotNull Group> groups;
|
||||
|
||||
public List<Group> getGroups() {
|
||||
return groups;
|
||||
}
|
||||
|
||||
public void setGroups(List<Group> groups) {
|
||||
this.groups = groups;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getWorkdayId() {
|
||||
return workdayId;
|
||||
}
|
||||
|
||||
public void setWorkdayId(String workdayId) {
|
||||
this.workdayId = workdayId;
|
||||
}
|
||||
|
||||
public Boolean getActive() {
|
||||
return isActive;
|
||||
}
|
||||
|
||||
public void setActive(Boolean active) {
|
||||
isActive = active;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -122,6 +122,8 @@ public class MaterialRepository {
|
|||
@Transactional
|
||||
public Optional<Integer> create(Material material) {
|
||||
|
||||
//todo if there is a deprecated, reuse this
|
||||
|
||||
KeyHolder keyHolder = new GeneratedKeyHolder();
|
||||
|
||||
jdbcTemplate.update(connection -> {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,92 @@
|
|||
package de.avatic.lcc.repositories.country;
|
||||
|
||||
import de.avatic.lcc.dto.generic.PropertyDTO;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public class CountryPropertyRepository {
|
||||
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
public CountryPropertyRepository(JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void setProperty(Integer setId, Integer countryId, String mappingId, String value) {
|
||||
Integer typeId = getTypeIdByMappingId(mappingId);
|
||||
|
||||
String query = """
|
||||
INSERT INTO country_property (property_value, country_id, country_property_type_id, property_set_id) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE property_value = ?
|
||||
""";
|
||||
|
||||
jdbcTemplate.update(query, value, countryId, typeId, setId, value);
|
||||
}
|
||||
|
||||
|
||||
private Integer getTypeIdByMappingId(String mappingId) {
|
||||
String query = "SELECT id FROM country_property_type WHERE external_mapping_id = ?";
|
||||
return jdbcTemplate.queryForObject(query, Integer.class, mappingId);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<PropertyDTO> listPropertiesByCountryId(Integer id) {
|
||||
|
||||
String query = """
|
||||
SELECT type.name as name, type.data_type as dataType, type.external_mapping_id as externalMappingId, type.validation_rule as validationRule,
|
||||
draft.property_value as draftValue, valid.property_value as validValue
|
||||
FROM country_property_type AS type
|
||||
LEFT JOIN country_property AS draft ON draft.country_property_type_id = type.id
|
||||
LEFT JOIN country_property AS valid ON valid.country_property_type_id = type.id
|
||||
LEFT JOIN property_set AS draftSet ON draftSet.id = draft.property_set_id
|
||||
LEFT JOIN property_set AS validSet ON validSet.id = valid.property_set_id
|
||||
WHERE draftSet.state = 'DRAFT' AND validSet.state = 'VALID' AND draft.country_id = ? AND valid.country_id = ?
|
||||
""";
|
||||
|
||||
return jdbcTemplate.query(query, (rs, rowNum) -> {
|
||||
var dto = new PropertyDTO();
|
||||
|
||||
dto.setName(rs.getString("name"));
|
||||
dto.setDraftValue(rs.getString("draftValue"));
|
||||
dto.setCurrentValue(rs.getString("validValue"));
|
||||
dto.setValidationRule(rs.getString("validationRule"));
|
||||
dto.setExternalMappingId(rs.getString("externalMappingId"));
|
||||
dto.setRequired(true);
|
||||
dto.setDataType(rs.getString("dataType"));
|
||||
|
||||
return dto;
|
||||
}, id, id);
|
||||
}
|
||||
|
||||
public Collection<PropertyDTO> listPropertiesByCountryIdAndPropertySetId(Integer id, Integer propertySetId) {
|
||||
|
||||
String query = """
|
||||
SELECT type.name as name, type.data_type as dataType, type.external_mapping_id as externalMappingId, type.validation_rule as validationRule,
|
||||
property.property_value as draftValue, property.property_value as validValue
|
||||
FROM country_property_type AS type
|
||||
LEFT JOIN country_property AS property ON property.country_property_type_id = type.id
|
||||
LEFT JOIN property_set AS propertySet ON propertySet.id = property.property_set_id
|
||||
WHERE propertySet.state = 'EXPIRED' AND property.country_id = ? AND propertySet.id = ?
|
||||
""";
|
||||
|
||||
return jdbcTemplate.query(query, (rs, rowNum) -> {
|
||||
var dto = new PropertyDTO();
|
||||
|
||||
dto.setName(rs.getString("name"));
|
||||
dto.setDraftValue(rs.getString("draftValue"));
|
||||
dto.setCurrentValue(rs.getString("validValue"));
|
||||
dto.setValidationRule(rs.getString("validationRule"));
|
||||
dto.setExternalMappingId(rs.getString("externalMappingId"));
|
||||
dto.setRequired(true);
|
||||
dto.setDataType(rs.getString("dataType"));
|
||||
|
||||
return dto;
|
||||
}, id, propertySetId);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package de.avatic.lcc.repositories;
|
||||
package de.avatic.lcc.repositories.country;
|
||||
|
||||
import de.avatic.lcc.model.country.Country;
|
||||
import de.avatic.lcc.model.country.IsoCode;
|
||||
|
|
@ -25,7 +25,7 @@ public class CountryRepository {
|
|||
}
|
||||
|
||||
@Transactional
|
||||
public Optional<Country> getById(Integer countryId) {
|
||||
public Optional<Country> getById(Integer id) {
|
||||
|
||||
String query = """
|
||||
SELECT country.id AS id, country.iso_code AS iso_code, country.region_code AS region_code, country.is_deprecated AS is_deprecated
|
||||
|
|
@ -33,18 +33,20 @@ public class CountryRepository {
|
|||
WHERE country.id = ?
|
||||
""";
|
||||
|
||||
var country = jdbcTemplate.queryForObject(query, (rs, rowNum) -> {
|
||||
var data = new Country();
|
||||
return Optional.ofNullable(jdbcTemplate.queryForObject(query, new CountryMapper(), id));
|
||||
|
||||
data.setId(rs.getInt("id"));
|
||||
data.setIsoCode(IsoCode.valueOf(rs.getString("iso_code")));
|
||||
data.setRegionCode(RegionCode.valueOf(rs.getString("region_code")));
|
||||
data.setDeprecated(rs.getBoolean("is_deprecated"));
|
||||
}
|
||||
|
||||
return data;
|
||||
});
|
||||
@Transactional
|
||||
public Optional<Country> getByIsoCode(IsoCode isoCode) {
|
||||
|
||||
return Optional.ofNullable(country);
|
||||
String query = """
|
||||
SELECT country.id AS id, country.iso_code AS iso_code, country.region_code AS region_code, country.is_deprecated AS is_deprecated
|
||||
FROM country
|
||||
WHERE country.iso_code = ?
|
||||
""";
|
||||
|
||||
return Optional.ofNullable(jdbcTemplate.queryForObject(query, new CountryMapper(), isoCode.name()));
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -113,6 +115,7 @@ public class CountryRepository {
|
|||
}
|
||||
|
||||
|
||||
|
||||
private static class CountryMapper implements RowMapper<Country> {
|
||||
@Override
|
||||
public Country mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
|
|
@ -1,9 +1,8 @@
|
|||
package de.avatic.lcc.repositories.properties;
|
||||
package de.avatic.lcc.repositories.packaging;
|
||||
|
||||
import de.avatic.lcc.model.packaging.PackagingProperty;
|
||||
import de.avatic.lcc.model.packaging.PackagingPropertyType;
|
||||
import de.avatic.lcc.model.properties.CountryPropertyType;
|
||||
import de.avatic.lcc.model.properties.PackagingProperty;
|
||||
import de.avatic.lcc.model.properties.PropertyDataType;
|
||||
import de.avatic.lcc.model.properties.PropertyType;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
|
|
@ -29,7 +28,7 @@ public class PackagingPropertiesRepository {
|
|||
return jdbcTemplate.query(query, (rs, rowNum) -> {
|
||||
|
||||
PackagingProperty property = new PackagingProperty();
|
||||
PackagingPropertyType type = new PackagingPropertyType();
|
||||
PropertyType type = new PropertyType();
|
||||
|
||||
type.setId(rs.getInt("type_id"));
|
||||
type.setName(rs.getString("type_name"));
|
||||
|
|
@ -38,10 +37,10 @@ public class PackagingPropertiesRepository {
|
|||
type.setExternalMappingId(rs.getString("type_external_mapping_id"));
|
||||
type.setValidationRule(rs.getString("type_validation_rule"));
|
||||
|
||||
property.setPackagingPropertyType(type);
|
||||
property.setType(type);
|
||||
property.setId(rs.getInt("id"));
|
||||
property.setPackagingId(rs.getInt("packaging_id"));
|
||||
property.setPropertyValue(rs.getString("value"));
|
||||
property.setValue(rs.getString("value"));
|
||||
|
||||
return property;
|
||||
}, id);
|
||||
|
|
@ -50,13 +49,13 @@ public class PackagingPropertiesRepository {
|
|||
|
||||
|
||||
|
||||
public List<PackagingPropertyType> listTypes() {
|
||||
public List<PropertyType> listTypes() {
|
||||
String query = """
|
||||
SELECT * FROM packaging_property_type
|
||||
""";
|
||||
|
||||
return jdbcTemplate.query(query, (rs, rowNum) -> {
|
||||
PackagingPropertyType type = new PackagingPropertyType();
|
||||
PropertyType type = new PropertyType();
|
||||
|
||||
type.setId(rs.getInt("id"));
|
||||
type.setName(rs.getString("name"));
|
||||
|
|
@ -1,8 +1,12 @@
|
|||
package de.avatic.lcc.repositories.pagination;
|
||||
|
||||
import jakarta.validation.constraints.Min;
|
||||
|
||||
public class SearchQueryPagination {
|
||||
|
||||
@Min(1)
|
||||
private final Integer page;
|
||||
|
||||
private final Integer size;
|
||||
|
||||
public SearchQueryPagination(Integer page, Integer size) {
|
||||
|
|
@ -15,7 +19,7 @@ public class SearchQueryPagination {
|
|||
}
|
||||
|
||||
public Integer getOffset() {
|
||||
return page * size;
|
||||
return (page - 1) * size;
|
||||
}
|
||||
|
||||
public Integer getPage() { return page; }
|
||||
|
|
|
|||
|
|
@ -1,94 +0,0 @@
|
|||
package de.avatic.lcc.repositories.properties;
|
||||
|
||||
import de.avatic.lcc.model.properties.*;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class CountryPropertiesRepository {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
public CountryPropertiesRepository(JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Transactional
|
||||
public List<CountryProperty> listByCountryId(Integer id) {
|
||||
|
||||
String query = """
|
||||
SELECT p.id as id, p.country_id as country_id, p.property_value as value,
|
||||
ps.id as property_set_id, ps.start_date as property_set_start_date, ps.end_date as property_set_end_date, ps.state as property_set_state,
|
||||
type.id as type_id, type.name as type_name, type.data_type as type_data_type, type.is_required as type_is_required, type.external_mapping_id as type_external_mapping_id, type.validation_rule as type_validation_rule
|
||||
FROM country_property p
|
||||
LEFT JOIN country_property_type type on p.country_property_type_id = type.id
|
||||
LEFT JOIN property_set ps on p.property_set_id = ps.id
|
||||
WHERE p.country_id = ? AND ps.state = 'VALID' OR ps.state = 'DRAFT'""";
|
||||
|
||||
return jdbcTemplate.query(query, (rs, rowNum) -> {
|
||||
CountryProperty entity = new CountryProperty();
|
||||
CountryPropertyType type = new CountryPropertyType();
|
||||
PropertySet propertySet = new PropertySet();
|
||||
|
||||
propertySet.setId(rs.getInt("property_set_id"));
|
||||
propertySet.setStartDate(rs.getTimestamp("property_set_start_date").toLocalDateTime());
|
||||
propertySet.setEndDate(rs.getTimestamp("property_set_end_date").toLocalDateTime());
|
||||
propertySet.setState(PropertySetState.valueOf(rs.getString("property_set_state")));
|
||||
|
||||
type.setId(rs.getInt("type_id"));
|
||||
type.setName(rs.getString("type_name"));
|
||||
type.setDataType(PropertyDataType.valueOf(rs.getString("type_data_type")));
|
||||
type.setRequired(rs.getBoolean("type_is_required"));
|
||||
type.setExternalMappingId(rs.getString("type_external_mapping_id"));
|
||||
type.setValidationRule(rs.getString("type_validation_rule"));
|
||||
|
||||
entity.setCountryId(id);
|
||||
entity.setType(type);
|
||||
entity.setPropertySet(propertySet);
|
||||
entity.setValue(rs.getString("value"));
|
||||
|
||||
return entity;
|
||||
}, id);
|
||||
}
|
||||
|
||||
public void update(CountryProperty entity) {
|
||||
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<CountryPropertyType> listTypes() {
|
||||
String query = """
|
||||
SELECT * FROM country_property_type
|
||||
""";
|
||||
|
||||
return jdbcTemplate.query(query, (rs, rowNum) -> {
|
||||
CountryPropertyType type = new CountryPropertyType();
|
||||
|
||||
type.setId(rs.getInt("id"));
|
||||
type.setName(rs.getString("name"));
|
||||
type.setDataType(PropertyDataType.valueOf(rs.getString("data_type")));
|
||||
type.setRequired(rs.getBoolean("is_required"));
|
||||
type.setExternalMappingId(rs.getString("external_mapping_id"));
|
||||
type.setValidationRule(rs.getString("validation_rule"));
|
||||
|
||||
return type;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void update(Integer countryId, Integer typeId, Integer propertySetId, String value) {
|
||||
|
||||
String query = """
|
||||
INSERT INTO country_property (property_value, property_set_id, country_property_type_id, country_id) VALUES (?, ?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE property_value = ?""";
|
||||
|
||||
jdbcTemplate.update(query, value, propertySetId, typeId, countryId, value);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
package de.avatic.lcc.repositories.properties;
|
||||
|
||||
import de.avatic.lcc.dto.generic.PropertyDTO;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Repository
|
||||
public class PropertyRepository {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
public PropertyRepository(JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void setProperty(Integer setId, String mappingId, String value) {
|
||||
var typeId = getTypeIdByMappingId(mappingId);
|
||||
|
||||
String query = """
|
||||
INSERT INTO system_property (property_set_id, system_property_type_id, property_value) VALUES (?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE property_value = ?""";
|
||||
|
||||
jdbcTemplate.update(query, setId, typeId, value, value);
|
||||
}
|
||||
|
||||
private Integer getTypeIdByMappingId(String mappingId) {
|
||||
String query = "SELECT id FROM system_property_type WHERE external_mapping_id = ?";
|
||||
return jdbcTemplate.queryForObject(query, Integer.class, mappingId);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<PropertyDTO> listProperties() {
|
||||
|
||||
String query = """
|
||||
SELECT type.name as name, type.data_type as dataType, type.external_mapping_id as externalMappingId, type.validation_rule as validationRule,
|
||||
draft.property_value as draftValue, valid.property_value as validValue
|
||||
FROM system_property_type AS type
|
||||
LEFT JOIN system_property AS draft ON draft.system_property_type_id = type.id
|
||||
LEFT JOIN system_property AS valid ON valid.system_property_type_id = type.id
|
||||
LEFT JOIN property_set AS draftSet ON draftSet.id = draft.property_set_id
|
||||
LEFT JOIN property_set AS validSet ON validSet.id = valid.property_set_id
|
||||
WHERE draftSet.state = 'DRAFT' AND validSet.state = 'VALID'
|
||||
""";
|
||||
|
||||
return jdbcTemplate.query(query, (rs, rowNum) -> {
|
||||
var dto = new PropertyDTO();
|
||||
|
||||
dto.setName(rs.getString("name"));
|
||||
dto.setDraftValue(rs.getString("draftValue"));
|
||||
dto.setCurrentValue(rs.getString("validValue"));
|
||||
dto.setValidationRule(rs.getString("validationRule"));
|
||||
dto.setExternalMappingId(rs.getString("externalMappingId"));
|
||||
dto.setRequired(true);
|
||||
dto.setDataType(rs.getString("dataType"));
|
||||
|
||||
return dto;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public List<PropertyDTO> listPropertiesBySetId(Integer propertySetId) {
|
||||
|
||||
String query = """
|
||||
SELECT type.name as name, type.data_type as dataType, type.external_mapping_id as externalMappingId, type.validation_rule as validationRule,
|
||||
property.property_value as draftValue, property.property_value as validValue
|
||||
FROM system_property_type AS type
|
||||
LEFT JOIN system_property AS property ON property.system_property_type_id = type.id
|
||||
LEFT JOIN property_set AS propertySet ON propertySet.id = property.property_set_id
|
||||
WHERE propertySet.state = 'EXPIRED' AND propertySet.id = ?
|
||||
""";
|
||||
|
||||
return jdbcTemplate.query(query, (rs, rowNum) -> {
|
||||
var dto = new PropertyDTO();
|
||||
|
||||
dto.setName(rs.getString("name"));
|
||||
dto.setDraftValue(rs.getString("draftValue"));
|
||||
dto.setCurrentValue(rs.getString("validValue"));
|
||||
dto.setValidationRule(rs.getString("validationRule"));
|
||||
dto.setExternalMappingId(rs.getString("externalMappingId"));
|
||||
dto.setRequired(true);
|
||||
dto.setDataType(rs.getString("dataType"));
|
||||
|
||||
return dto;
|
||||
}, propertySetId);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
package de.avatic.lcc.repositories.properties;
|
||||
|
||||
|
||||
import de.avatic.lcc.model.properties.PropertySet;
|
||||
import de.avatic.lcc.model.properties.PropertySetState;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public class PropertySetRepository {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
public PropertySetRepository(JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<PropertySet> listPropertySets() {
|
||||
String query = "SELECT id, start_date, end_date, state FROM property_set";
|
||||
|
||||
return jdbcTemplate.query(query, new PropertySetMapper());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Integer getDraftSetId() {
|
||||
return getDraftSet().getId();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public PropertySet getDraftSet() {
|
||||
createSet();
|
||||
return jdbcTemplate.queryForObject("SELECT id, start_date, end_date, state FROM property_set WHERE state = ?", new PropertySetMapper(), PropertySetState.DRAFT.name());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public boolean hasDraftSet() {
|
||||
Integer count = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM property_set WHERE state = ?", Integer.class, PropertySetState.DRAFT.name());
|
||||
return !(count == null || count == 0);
|
||||
}
|
||||
|
||||
|
||||
private void createSet() {
|
||||
jdbcTemplate.update("INSERT INTO property_set (state) SELECT ? WHERE NOT EXISTS (SELECT 1 FROM property_set WHERE state = ?)", PropertySetState.DRAFT.name(), PropertySetState.DRAFT.name());
|
||||
}
|
||||
|
||||
public PropertySet getValidSet() {
|
||||
return jdbcTemplate.queryForObject("SELECT id, start_date, end_date, state FROM property_set WHERE state = ?", new PropertySetMapper(), PropertySetState.VALID.name());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void applyDraft() {
|
||||
final Timestamp currentTimestamp = new Timestamp(System.currentTimeMillis());
|
||||
|
||||
if(hasDraftSet())
|
||||
{
|
||||
jdbcTemplate.update("UPDATE property_set SET state = ?, end_date = ? WHERE state = ? ", PropertySetState.EXPIRED.name(), currentTimestamp, PropertySetState.VALID.name());
|
||||
jdbcTemplate.update("UPDATE property_set SET state = ?, start_date = ? WHERE id = ? AND state = ? ", PropertySetState.VALID.name(), currentTimestamp, PropertySetState.DRAFT.name());
|
||||
//TODO: fill all missing values in draft set!
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void invalidateById(Integer id) {
|
||||
jdbcTemplate.update("UPDATE property_set SET state = ? WHERE id = ? AND state = ? ", PropertySetState.INVALID.name(), id, PropertySetState.EXPIRED.name());
|
||||
}
|
||||
|
||||
private static class PropertySetMapper implements RowMapper<PropertySet> {
|
||||
|
||||
@Override
|
||||
public PropertySet mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
PropertySet propertySet = new PropertySet();
|
||||
|
||||
propertySet.setId(rs.getInt("id"));
|
||||
propertySet.setStartDate(rs.getTimestamp("start_date").toLocalDateTime());
|
||||
propertySet.setEndDate(rs.getTimestamp("end_date").toLocalDateTime());
|
||||
|
||||
return propertySet;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
package de.avatic.lcc.repositories.properties;
|
||||
|
||||
import de.avatic.lcc.model.properties.*;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.support.GeneratedKeyHolder;
|
||||
import org.springframework.jdbc.support.KeyHolder;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.Statement;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
@Repository
|
||||
public class SystemPropertiesRepository {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
public SystemPropertiesRepository(JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public PropertySet getDraftSet() {
|
||||
createSet();
|
||||
|
||||
String query = "SELECT id, start_date, end_date, state FROM property_set WHERE state = ?";
|
||||
|
||||
return jdbcTemplate.queryForObject(query, (rs, rowNum) -> {
|
||||
PropertySet propertySet = new PropertySet();
|
||||
|
||||
propertySet.setId(rs.getInt("id"));
|
||||
propertySet.setStartDate(rs.getTimestamp("start_date").toLocalDateTime());
|
||||
propertySet.setEndDate(rs.getTimestamp("end_date").toLocalDateTime());
|
||||
|
||||
return propertySet;
|
||||
|
||||
}, PropertySetState.DRAFT.name());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public boolean hasDraftSet() {
|
||||
Integer count = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM property_set WHERE state = ?", Integer.class, PropertySetState.DRAFT.name());
|
||||
return !(count == null || count == 0);
|
||||
}
|
||||
|
||||
|
||||
private void createSet() {
|
||||
String query = "INSERT INTO property_set (state) SELECT ? WHERE NOT EXISTS (SELECT 1 FROM property_set WHERE state = ?)";
|
||||
jdbcTemplate.update(query, PropertySetState.DRAFT.name(), PropertySetState.DRAFT.name());
|
||||
}
|
||||
|
||||
private List<SystemPropertyType> getSystemPropertyTypes() {
|
||||
return jdbcTemplate.query("SELECT * FROM system_property_type", (rs, rowNum) -> {
|
||||
SystemPropertyType systemPropertyType = new SystemPropertyType();
|
||||
|
||||
systemPropertyType.setId(rs.getInt("id"));
|
||||
systemPropertyType.setName(rs.getString("name"));
|
||||
systemPropertyType.setDataType(PropertyDataType.valueOf(rs.getString("data_type")));
|
||||
systemPropertyType.setExternalMappingId(rs.getString("external_mapping_id"));
|
||||
systemPropertyType.setValidationRule(rs.getString("validation_rule"));
|
||||
|
||||
return systemPropertyType;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,60 +1,75 @@
|
|||
package de.avatic.lcc.service.configuration;
|
||||
|
||||
import de.avatic.lcc.dto.configuration.countries.view.CountryDetailDTO;
|
||||
import de.avatic.lcc.dto.configuration.countries.update.CountryUpdateDTO;
|
||||
import de.avatic.lcc.dto.generic.CountryDTO;
|
||||
import de.avatic.lcc.model.properties.CountryProperty;
|
||||
import de.avatic.lcc.model.properties.CountryPropertyType;
|
||||
import de.avatic.lcc.model.properties.PropertySet;
|
||||
import de.avatic.lcc.repositories.properties.CountryPropertiesRepository;
|
||||
import de.avatic.lcc.repositories.CountryRepository;
|
||||
import de.avatic.lcc.model.country.Country;
|
||||
import de.avatic.lcc.model.country.IsoCode;
|
||||
import de.avatic.lcc.repositories.country.CountryPropertyRepository;
|
||||
import de.avatic.lcc.repositories.country.CountryRepository;
|
||||
import de.avatic.lcc.repositories.pagination.SearchQueryPagination;
|
||||
import de.avatic.lcc.repositories.pagination.SearchQueryResult;
|
||||
import de.avatic.lcc.repositories.properties.SystemPropertiesRepository;
|
||||
import de.avatic.lcc.service.transformer.country.CountryTransformerService;
|
||||
import de.avatic.lcc.service.transformer.generic.CountryDTOTransformer;
|
||||
import de.avatic.lcc.repositories.properties.PropertySetRepository;
|
||||
import de.avatic.lcc.service.transformer.generic.CountryTransformer;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class CountryService {
|
||||
|
||||
private final CountryRepository countryRepository;
|
||||
private final CountryTransformerService countryTransformerService;
|
||||
private final CountryPropertiesRepository countryPropertiesRepository;
|
||||
private final SystemPropertiesRepository systemPropertiesRepository;
|
||||
private final CountryDTOTransformer countryDTOTransformer;
|
||||
private final CountryTransformer countryTransformer;
|
||||
private final CountryPropertyRepository countryPropertyRepository;
|
||||
private final PropertySetRepository propertySetRepository;
|
||||
|
||||
public CountryService(CountryRepository countryRepository, CountryTransformerService countryTransformerService, CountryPropertiesRepository countryPropertiesRepository, SystemPropertiesRepository systemPropertiesRepository, CountryDTOTransformer countryDTOTransformer) {
|
||||
public CountryService(CountryRepository countryRepository, CountryTransformer countryTransformer, CountryPropertyRepository countryPropertyRepository, PropertySetRepository propertySetRepository) {
|
||||
this.countryRepository = countryRepository;
|
||||
this.countryTransformerService = countryTransformerService;
|
||||
this.countryPropertiesRepository = countryPropertiesRepository;
|
||||
this.systemPropertiesRepository = systemPropertiesRepository;
|
||||
this.countryDTOTransformer = countryDTOTransformer;
|
||||
this.countryTransformer = countryTransformer;
|
||||
this.countryPropertyRepository = countryPropertyRepository;
|
||||
this.propertySetRepository = propertySetRepository;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void setProperties(IsoCode isoCode, String mappingId, String value) {
|
||||
//todo validate property value!
|
||||
var country = countryRepository.getByIsoCode(isoCode);
|
||||
countryPropertyRepository.setProperty(propertySetRepository.getDraftSetId(), country.orElseThrow().getId(), mappingId, value);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public SearchQueryResult<CountryDTO> listCountries(String filter, int page, int limit) {
|
||||
return SearchQueryResult.map(countryRepository.listCountries(filter, true, new SearchQueryPagination(page, limit)), countryDTOTransformer::toCountryDTO);
|
||||
return SearchQueryResult.map(countryRepository.listCountries(filter, true, new SearchQueryPagination(page, limit)), countryTransformer::toCountryDTO);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public CountryDetailDTO getCountry(Integer id) {
|
||||
List<CountryProperty> properties = countryPropertiesRepository.listByCountryId(id);
|
||||
return countryTransformerService.convertToCountryGetDTO(countryRepository.getById(id), properties).orElseThrow();
|
||||
public SearchQueryResult<CountryDTO> listCountries(String filter) {
|
||||
return SearchQueryResult.map(countryRepository.listCountries(filter, true), countryTransformer::toCountryDTO);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void updateCountry(Integer id, CountryUpdateDTO dto) {
|
||||
List<CountryPropertyType> types = countryPropertiesRepository.listTypes();
|
||||
PropertySet set = systemPropertiesRepository.getDraftSet();
|
||||
public Optional<CountryDetailDTO> getCountry(Integer id, Integer propertySetId) {
|
||||
var country = countryRepository.getById(id);
|
||||
if (country.isEmpty()) return Optional.empty();
|
||||
|
||||
for(CountryPropertyType type : types) {
|
||||
var value = dto.getProperties().get(type.getExternalMappingId());
|
||||
if(value != null) {
|
||||
countryPropertiesRepository.update(id, type.getId(), set.getId(), value);
|
||||
}
|
||||
CountryDetailDTO dto = new CountryDetailDTO();
|
||||
Country entity = country.get();
|
||||
|
||||
dto.setIsoCode(entity.getIsoCode().getCode());
|
||||
dto.setRegionCode(entity.getRegionCode().getCode());
|
||||
dto.setName(entity.getIsoCode().getFullName());
|
||||
dto.setId(entity.getId());
|
||||
|
||||
if(0 == propertySetId) {
|
||||
dto.setProperties(countryPropertyRepository.listPropertiesByCountryId(entity.getId()));
|
||||
} else {
|
||||
dto.setProperties(countryPropertyRepository.listPropertiesByCountryIdAndPropertySetId(entity.getId(), propertySetId));
|
||||
}
|
||||
|
||||
|
||||
|
||||
return Optional.of(dto);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,15 @@
|
|||
package de.avatic.lcc.service.configuration;
|
||||
|
||||
import de.avatic.lcc.dto.configuration.material.view.MaterialViewDTO;
|
||||
import de.avatic.lcc.dto.configuration.material.update.MaterialUpdateDTO;
|
||||
import de.avatic.lcc.model.materials.Material;
|
||||
import de.avatic.lcc.dto.configuration.material.view.MaterialViewDTO;
|
||||
import de.avatic.lcc.dto.generic.MaterialDTO;
|
||||
import de.avatic.lcc.repositories.CountryRepository;
|
||||
import de.avatic.lcc.model.materials.Material;
|
||||
import de.avatic.lcc.repositories.MaterialRepository;
|
||||
import de.avatic.lcc.repositories.NodeRepository;
|
||||
import de.avatic.lcc.repositories.packaging.PackagingDimensionRepository;
|
||||
import de.avatic.lcc.repositories.packaging.PackagingRepository;
|
||||
import de.avatic.lcc.repositories.pagination.SearchQueryPagination;
|
||||
import de.avatic.lcc.repositories.pagination.SearchQueryResult;
|
||||
import de.avatic.lcc.service.transformer.generic.MaterialTransformer;
|
||||
import de.avatic.lcc.service.transformer.material.MaterialUpdateDTOTransformer;
|
||||
import de.avatic.lcc.service.transformer.material.MaterialViewDTOTransformer;
|
||||
import de.avatic.lcc.service.transformer.generic.DimensionDTOTransformer;
|
||||
import de.avatic.lcc.service.transformer.generic.MaterialDTOTransformer;
|
||||
import de.avatic.lcc.service.transformer.generic.NodeDTOTransformer;
|
||||
import de.avatic.lcc.util.exception.clienterror.MaterialNotFoundException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
|
@ -23,32 +17,20 @@ import org.springframework.stereotype.Service;
|
|||
public class MaterialService {
|
||||
|
||||
private final MaterialUpdateDTOTransformer materialUpdateDTOTransformer;
|
||||
private final PackagingRepository packagingRepository;
|
||||
private final CountryRepository countryRepository;
|
||||
private final NodeRepository nodeRepository;
|
||||
private final PackagingDimensionRepository packagingDimensionRepository;
|
||||
private final MaterialRepository materialRepository;
|
||||
private final MaterialDTOTransformer materialDTOTransformer;
|
||||
private final DimensionDTOTransformer dimensionDTOTransformer;
|
||||
private final NodeDTOTransformer nodeDTOTransformer;
|
||||
private final MaterialTransformer materialTransformer;
|
||||
private final MaterialViewDTOTransformer materialViewDTOTransformer;
|
||||
|
||||
public MaterialService(MaterialRepository materialRepository, MaterialUpdateDTOTransformer materialUpdateDTOTransformer, PackagingRepository packagingRepository, CountryRepository countryRepository, NodeRepository nodeRepository, PackagingDimensionRepository packagingDimensionRepository, MaterialDTOTransformer materialDTOTransformer, DimensionDTOTransformer dimensionDTOTransformer, NodeDTOTransformer nodeDTOTransformer, MaterialViewDTOTransformer materialViewDTOTransformer) {
|
||||
public MaterialService(MaterialRepository materialRepository, MaterialUpdateDTOTransformer materialUpdateDTOTransformer, MaterialTransformer materialTransformer, MaterialViewDTOTransformer materialViewDTOTransformer) {
|
||||
this.materialRepository = materialRepository;
|
||||
this.materialUpdateDTOTransformer = materialUpdateDTOTransformer;
|
||||
this.packagingRepository = packagingRepository;
|
||||
this.countryRepository = countryRepository;
|
||||
this.nodeRepository = nodeRepository;
|
||||
this.packagingDimensionRepository = packagingDimensionRepository;
|
||||
this.materialDTOTransformer = materialDTOTransformer;
|
||||
this.dimensionDTOTransformer = dimensionDTOTransformer;
|
||||
this.nodeDTOTransformer = nodeDTOTransformer;
|
||||
this.materialTransformer = materialTransformer;
|
||||
this.materialViewDTOTransformer = materialViewDTOTransformer;
|
||||
}
|
||||
|
||||
public SearchQueryResult<MaterialDTO> listMaterial(String filter, int page, int limit) {
|
||||
SearchQueryResult<Material> queryResult = materialRepository.listMaterials(filter, true, new SearchQueryPagination(page, limit));
|
||||
return SearchQueryResult.map(queryResult, materialDTOTransformer::toMaterialDTO);
|
||||
return SearchQueryResult.map(queryResult, materialTransformer::toMaterialDTO);
|
||||
}
|
||||
|
||||
public MaterialViewDTO getMaterial(Integer id) {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import de.avatic.lcc.repositories.pagination.SearchQueryPagination;
|
|||
import de.avatic.lcc.repositories.pagination.SearchQueryResult;
|
||||
import de.avatic.lcc.service.transformer.nodes.NodeUpdateDTOTransformer;
|
||||
import de.avatic.lcc.service.transformer.nodes.NodeViewDTOTransformer;
|
||||
import de.avatic.lcc.service.transformer.generic.NodeDTOTransformer;
|
||||
import de.avatic.lcc.service.transformer.generic.NodeTransformer;
|
||||
import de.avatic.lcc.util.exception.clienterror.NodeNotFoundException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
|
@ -16,19 +16,19 @@ import org.springframework.stereotype.Service;
|
|||
public class NodeService {
|
||||
|
||||
private final NodeRepository nodeRepository;
|
||||
private final NodeDTOTransformer nodeDTOTransformer;
|
||||
private final NodeTransformer nodeTransformer;
|
||||
private final NodeViewDTOTransformer nodeViewDTOTransformer;
|
||||
private final NodeUpdateDTOTransformer nodeUpdateDTOTransformer;
|
||||
|
||||
public NodeService(NodeRepository nodeRepository, NodeDTOTransformer nodeDTOTransformer, NodeViewDTOTransformer nodeViewDTOTransformer, NodeUpdateDTOTransformer nodeUpdateDTOTransformer) {
|
||||
public NodeService(NodeRepository nodeRepository, NodeTransformer nodeTransformer, NodeViewDTOTransformer nodeViewDTOTransformer, NodeUpdateDTOTransformer nodeUpdateDTOTransformer) {
|
||||
this.nodeRepository = nodeRepository;
|
||||
this.nodeDTOTransformer = nodeDTOTransformer;
|
||||
this.nodeTransformer = nodeTransformer;
|
||||
this.nodeViewDTOTransformer = nodeViewDTOTransformer;
|
||||
this.nodeUpdateDTOTransformer = nodeUpdateDTOTransformer;
|
||||
}
|
||||
|
||||
public SearchQueryResult<NodeDTO> listNodes(String filter, int page, int limit) {
|
||||
return SearchQueryResult.map(nodeRepository.listNodes(filter, true, new SearchQueryPagination(page, limit)), nodeDTOTransformer::toNodeDTO);
|
||||
return SearchQueryResult.map(nodeRepository.listNodes(filter, true, new SearchQueryPagination(page, limit)), nodeTransformer::toNodeDTO);
|
||||
}
|
||||
|
||||
public SearchQueryResult<NodeDetailDTO> listNodesView(String filter, int page, int limit) {
|
||||
|
|
|
|||
|
|
@ -7,20 +7,20 @@ import de.avatic.lcc.model.materials.Material;
|
|||
import de.avatic.lcc.model.nodes.Node;
|
||||
import de.avatic.lcc.model.packaging.Packaging;
|
||||
import de.avatic.lcc.model.packaging.PackagingDimension;
|
||||
import de.avatic.lcc.model.packaging.PackagingProperty;
|
||||
import de.avatic.lcc.model.packaging.PackagingPropertyType;
|
||||
import de.avatic.lcc.repositories.CountryRepository;
|
||||
import de.avatic.lcc.model.properties.PackagingProperty;
|
||||
import de.avatic.lcc.model.properties.PropertyType;
|
||||
import de.avatic.lcc.repositories.country.CountryRepository;
|
||||
import de.avatic.lcc.repositories.MaterialRepository;
|
||||
import de.avatic.lcc.repositories.NodeRepository;
|
||||
import de.avatic.lcc.repositories.packaging.PackagingDimensionRepository;
|
||||
import de.avatic.lcc.repositories.packaging.PackagingRepository;
|
||||
import de.avatic.lcc.repositories.pagination.SearchQueryPagination;
|
||||
import de.avatic.lcc.repositories.pagination.SearchQueryResult;
|
||||
import de.avatic.lcc.repositories.properties.PackagingPropertiesRepository;
|
||||
import de.avatic.lcc.repositories.packaging.PackagingPropertiesRepository;
|
||||
import de.avatic.lcc.service.transformer.packaging.PackagingTransformerService;
|
||||
import de.avatic.lcc.service.transformer.generic.DimensionDTOTransformer;
|
||||
import de.avatic.lcc.service.transformer.generic.MaterialDTOTransformer;
|
||||
import de.avatic.lcc.service.transformer.generic.NodeDTOTransformer;
|
||||
import de.avatic.lcc.service.transformer.generic.DimensionTransformer;
|
||||
import de.avatic.lcc.service.transformer.generic.MaterialTransformer;
|
||||
import de.avatic.lcc.service.transformer.generic.NodeTransformer;
|
||||
import de.avatic.lcc.util.Check;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
|
@ -37,11 +37,11 @@ public class PackagingService {
|
|||
private final CountryRepository countryRepository;
|
||||
private final PackagingTransformerService packagingTransformerService;
|
||||
private final PackagingPropertiesRepository packagingPropertiesRepository;
|
||||
private final MaterialDTOTransformer materialDTOTransformer;
|
||||
private final NodeDTOTransformer nodeDTOTransformer;
|
||||
private final DimensionDTOTransformer dimensionDTOTransformer;
|
||||
private final MaterialTransformer materialTransformer;
|
||||
private final NodeTransformer nodeTransformer;
|
||||
private final DimensionTransformer dimensionTransformer;
|
||||
|
||||
public PackagingService(PackagingRepository packagingRepository, PackagingDimensionRepository packagingDimensionRepository, NodeRepository nodeRepository, MaterialRepository materialRepository, CountryRepository countryRepository, PackagingTransformerService packagingTransformerService, PackagingPropertiesRepository packagingPropertiesRepository, MaterialDTOTransformer materialDTOTransformer, NodeDTOTransformer nodeDTOTransformer, DimensionDTOTransformer dimensionDTOTransformer) {
|
||||
public PackagingService(PackagingRepository packagingRepository, PackagingDimensionRepository packagingDimensionRepository, NodeRepository nodeRepository, MaterialRepository materialRepository, CountryRepository countryRepository, PackagingTransformerService packagingTransformerService, PackagingPropertiesRepository packagingPropertiesRepository, MaterialTransformer materialTransformer, NodeTransformer nodeTransformer, DimensionTransformer dimensionTransformer) {
|
||||
this.packagingRepository = packagingRepository;
|
||||
this.packagingDimensionRepository = packagingDimensionRepository;
|
||||
this.nodeRepository = nodeRepository;
|
||||
|
|
@ -49,9 +49,9 @@ public class PackagingService {
|
|||
this.countryRepository = countryRepository;
|
||||
this.packagingTransformerService = packagingTransformerService;
|
||||
this.packagingPropertiesRepository = packagingPropertiesRepository;
|
||||
this.materialDTOTransformer = materialDTOTransformer;
|
||||
this.nodeDTOTransformer = nodeDTOTransformer;
|
||||
this.dimensionDTOTransformer = dimensionDTOTransformer;
|
||||
this.materialTransformer = materialTransformer;
|
||||
this.nodeTransformer = nodeTransformer;
|
||||
this.dimensionTransformer = dimensionTransformer;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
|
|
@ -63,10 +63,10 @@ public class PackagingService {
|
|||
PackagingViewDTO dtoEntry = new PackagingViewDTO();
|
||||
Optional<Node> node = nodeRepository.getById(packaging.getSupplierId());
|
||||
Optional<Material> material = materialRepository.getById(packaging.getMaterialId());
|
||||
dtoEntry.setHu(dimensionDTOTransformer.toDimensionDTO(packagingDimensionRepository.getById(packaging.getHuId()).orElseThrow()));
|
||||
dtoEntry.setShu(dimensionDTOTransformer.toDimensionDTO(packagingDimensionRepository.getById(packaging.getShuId()).orElseThrow()));
|
||||
dtoEntry.setSupplier(nodeDTOTransformer.toNodeDTO(node.orElseThrow()));
|
||||
dtoEntry.setMaterial(materialDTOTransformer.toMaterialDTO(material.orElseThrow()));
|
||||
dtoEntry.setHu(dimensionTransformer.toDimensionDTO(packagingDimensionRepository.getById(packaging.getHuId()).orElseThrow()));
|
||||
dtoEntry.setShu(dimensionTransformer.toDimensionDTO(packagingDimensionRepository.getById(packaging.getShuId()).orElseThrow()));
|
||||
dtoEntry.setSupplier(nodeTransformer.toNodeDTO(node.orElseThrow()));
|
||||
dtoEntry.setMaterial(materialTransformer.toMaterialDTO(material.orElseThrow()));
|
||||
return dtoEntry;
|
||||
}
|
||||
|
||||
|
|
@ -96,13 +96,13 @@ public class PackagingService {
|
|||
Check.equals(dto.getHu().getId(), entity.get().getHuId());
|
||||
Check.equals(dto.getId(), id);
|
||||
|
||||
packagingDimensionRepository.update(dimensionDTOTransformer.toDimensionEntity(dto.getHu()));
|
||||
packagingDimensionRepository.update(dimensionDTOTransformer.toDimensionEntity(dto.getShu()));
|
||||
packagingDimensionRepository.update(dimensionTransformer.toDimensionEntity(dto.getHu()));
|
||||
packagingDimensionRepository.update(dimensionTransformer.toDimensionEntity(dto.getShu()));
|
||||
|
||||
List<PackagingPropertyType> types = packagingPropertiesRepository.listTypes();
|
||||
List<PropertyType> types = packagingPropertiesRepository.listTypes();
|
||||
|
||||
|
||||
for(PackagingPropertyType type : types) {
|
||||
for(PropertyType type : types) {
|
||||
var value = dto.getProperties().get(type.getExternalMappingId());
|
||||
if(value != null) {
|
||||
packagingPropertiesRepository.update(id, type.getId(), value);
|
||||
|
|
@ -119,8 +119,8 @@ public class PackagingService {
|
|||
@Transactional
|
||||
public Integer createPackaging(PackagingUpdateDTO dto) {
|
||||
|
||||
Optional<Integer> huId = packagingDimensionRepository.insert(dimensionDTOTransformer.toDimensionEntity(dto.getHu()));
|
||||
Optional<Integer> shuId = packagingDimensionRepository.insert(dimensionDTOTransformer.toDimensionEntity(dto.getShu()));
|
||||
Optional<Integer> huId = packagingDimensionRepository.insert(dimensionTransformer.toDimensionEntity(dto.getHu()));
|
||||
Optional<Integer> shuId = packagingDimensionRepository.insert(dimensionTransformer.toDimensionEntity(dto.getShu()));
|
||||
|
||||
Packaging entity = packagingTransformerService.convertFromPackagingPostDTO(dto);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,26 +1,52 @@
|
|||
package de.avatic.lcc.service.configuration;
|
||||
|
||||
import de.avatic.lcc.dto.configuration.properties.post.PropertiesPostDTO;
|
||||
import de.avatic.lcc.model.properties.PropertyType;
|
||||
import de.avatic.lcc.dto.configuration.properties.PropertySetDTO;
|
||||
import de.avatic.lcc.dto.generic.PropertyDTO;
|
||||
import de.avatic.lcc.model.properties.PropertySet;
|
||||
import de.avatic.lcc.repositories.properties.PropertyRepository;
|
||||
import de.avatic.lcc.repositories.properties.PropertySetRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class PropertiesService {
|
||||
|
||||
public void setProperties(String type, List<PropertiesPostDTO> property) {
|
||||
PropertyType propertyType = PropertyType.valueOf(type);
|
||||
private final PropertyRepository propertyRepository;
|
||||
private final PropertySetRepository propertySetRepository;
|
||||
|
||||
switch (propertyType) {
|
||||
case SYSTEM:
|
||||
|
||||
break;
|
||||
case COUNTRY:
|
||||
break;
|
||||
case PACKAGING:
|
||||
break;
|
||||
public PropertiesService(PropertyRepository propertyRepository, PropertySetRepository propertySetRepository) {
|
||||
this.propertyRepository = propertyRepository;
|
||||
this.propertySetRepository = propertySetRepository;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void setProperties(String mappingId, String value) {
|
||||
|
||||
//todo validate if property value is set correctly!
|
||||
|
||||
propertyRepository.setProperty(propertySetRepository.getDraftSetId(), mappingId, value);
|
||||
}
|
||||
|
||||
public List<PropertyDTO> listProperties(Integer propertySetId) {
|
||||
if(propertySetId == 0)
|
||||
return propertyRepository.listProperties();
|
||||
|
||||
return propertyRepository.listPropertiesBySetId(propertySetId);
|
||||
}
|
||||
|
||||
public List<PropertySetDTO> listPropertySets() {
|
||||
return propertySetRepository.listPropertySets().stream().map(propertySet -> {
|
||||
PropertySetDTO dto = new PropertySetDTO();
|
||||
|
||||
dto.setId(propertySet.getId());
|
||||
dto.setEndDate(propertySet.getEndDate());
|
||||
dto.setStartDate(propertySet.getStartDate());
|
||||
dto.setState(propertySet.getState());
|
||||
|
||||
return dto;
|
||||
}).toList();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,19 @@
|
|||
package de.avatic.lcc.service.configuration;
|
||||
|
||||
import de.avatic.lcc.repositories.properties.PropertyRepository;
|
||||
import de.avatic.lcc.repositories.properties.PropertySetRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class StagedChangesService {
|
||||
private final PropertySetRepository propertySetRepository;
|
||||
private final PropertyRepository propertyRepository;
|
||||
|
||||
public StagedChangesService(PropertySetRepository propertySetRepository, PropertyRepository propertyRepository) {
|
||||
this.propertySetRepository = propertySetRepository;
|
||||
this.propertyRepository = propertyRepository;
|
||||
}
|
||||
|
||||
public Boolean hasRateDrafts() {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -11,4 +21,15 @@ public class StagedChangesService {
|
|||
public void approveRateDrafts() {
|
||||
|
||||
}
|
||||
|
||||
public Boolean hasPropertiesDraft() {
|
||||
propertyRepository.listPropertiesBySetId(propertySetRepository.getDraftSetId());
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void approvePropertiesDrafts() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
package de.avatic.lcc.service.transformer;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class PropertiesTransformerService {
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
package de.avatic.lcc.service.transformer.country;
|
||||
|
||||
|
||||
import de.avatic.lcc.dto.configuration.countries.view.CountryDetailDTO;
|
||||
import de.avatic.lcc.dto.generic.PropertyDTO;
|
||||
import de.avatic.lcc.model.country.Country;
|
||||
import de.avatic.lcc.model.properties.CountryProperty;
|
||||
import de.avatic.lcc.model.properties.PropertySetState;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class CountryDetailTransformer {
|
||||
|
||||
public Optional<CountryDetailDTO> toCountryDetailDTO(Optional<Country> country, List<CountryProperty> properties) {
|
||||
|
||||
if (country.isEmpty()) return Optional.empty();
|
||||
|
||||
CountryDetailDTO dto = new CountryDetailDTO();
|
||||
Country entity = country.get();
|
||||
|
||||
dto.setIsoCode(entity.getIsoCode().getCode());
|
||||
dto.setRegionCode(entity.getRegionCode().getCode());
|
||||
dto.setName(entity.getIsoCode().getFullName());
|
||||
dto.setId(entity.getId());
|
||||
|
||||
dto.setProperties(properties.stream().filter(p -> p.getPropertySet().getState().equals(PropertySetState.VALID)).map(p -> {
|
||||
PropertyDTO dtoEntry = new PropertyDTO();
|
||||
|
||||
Optional<CountryProperty> draft = properties.stream().filter(d -> d.getPropertySet().getState().equals(PropertySetState.DRAFT) && d.getType().getExternalMappingId().equals(p.getType().getExternalMappingId())).findFirst();
|
||||
|
||||
dtoEntry.setCurrentValue(p.getValue());
|
||||
draft.ifPresent(countryProperty -> dtoEntry.setDraftValue(countryProperty.getValue()));
|
||||
dtoEntry.setRequired(p.getType().getRequired());
|
||||
dtoEntry.setName(p.getType().getName());
|
||||
dtoEntry.setExternalMappingId(p.getType().getExternalMappingId());
|
||||
dtoEntry.setDataType(p.getType().getDataType().name());
|
||||
dtoEntry.setValidationRule(p.getType().getValidationRule());
|
||||
|
||||
return dtoEntry;
|
||||
}).toList());
|
||||
|
||||
return Optional.of(dto);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@ import de.avatic.lcc.model.packaging.PackagingDimension;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class DimensionDTOTransformer {
|
||||
public class DimensionTransformer {
|
||||
|
||||
public DimensionDTO toDimensionDTO(PackagingDimension entity) {
|
||||
DimensionDTO dto = new DimensionDTO();
|
||||
|
|
@ -5,7 +5,7 @@ import de.avatic.lcc.model.nodes.Node;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class LocationDTOTransformer {
|
||||
public class LocationTransformer {
|
||||
public LocationDTO toLocationDTO(Node entity) {
|
||||
return new LocationDTO(entity.getGeoLat().doubleValue(), entity.getGeoLng().doubleValue());
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@ import de.avatic.lcc.model.materials.Material;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class MaterialDTOTransformer {
|
||||
public class MaterialTransformer {
|
||||
|
||||
public MaterialDTO toMaterialDTO(Material entity) {
|
||||
|
||||
|
|
@ -3,22 +3,22 @@ package de.avatic.lcc.service.transformer.generic;
|
|||
import de.avatic.lcc.dto.generic.NodeDTO;
|
||||
import de.avatic.lcc.dto.generic.NodeTypeDTO;
|
||||
import de.avatic.lcc.model.nodes.Node;
|
||||
import de.avatic.lcc.repositories.CountryRepository;
|
||||
import de.avatic.lcc.repositories.country.CountryRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Service
|
||||
public class NodeDTOTransformer {
|
||||
public class NodeTransformer {
|
||||
|
||||
private final CountryDTOTransformer countryTransformerService;
|
||||
private final CountryTransformer countryTransformerService;
|
||||
private final CountryRepository countryRepository;
|
||||
private final LocationDTOTransformer locationDTOTransformer;
|
||||
private final LocationTransformer locationTransformer;
|
||||
|
||||
public NodeDTOTransformer(CountryDTOTransformer countryTransformerService, CountryRepository countryRepository, LocationDTOTransformer locationDTOTransformer) {
|
||||
public NodeTransformer(CountryTransformer countryTransformerService, CountryRepository countryRepository, LocationTransformer locationTransformer) {
|
||||
this.countryTransformerService = countryTransformerService;
|
||||
this.countryRepository = countryRepository;
|
||||
this.locationDTOTransformer = locationDTOTransformer;
|
||||
this.locationTransformer = locationTransformer;
|
||||
}
|
||||
|
||||
public NodeDTO toNodeDTO(Node entity) {
|
||||
|
|
@ -35,7 +35,7 @@ public class NodeDTOTransformer {
|
|||
dto.setCountry(countryTransformerService.toCountryDTO(countryRepository.getById(entity.getCountryId())).orElseThrow());
|
||||
dto.setTypes(types);
|
||||
dto.setDeprecated(entity.getDeprecated());
|
||||
dto.setLocation(locationDTOTransformer.toLocationDTO(entity));
|
||||
dto.setLocation(locationTransformer.toLocationDTO(entity));
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
|
@ -6,8 +6,8 @@ import de.avatic.lcc.model.packaging.Packaging;
|
|||
import de.avatic.lcc.model.packaging.PackagingDimension;
|
||||
import de.avatic.lcc.repositories.NodeRepository;
|
||||
import de.avatic.lcc.repositories.packaging.PackagingDimensionRepository;
|
||||
import de.avatic.lcc.service.transformer.generic.DimensionDTOTransformer;
|
||||
import de.avatic.lcc.service.transformer.generic.NodeDTOTransformer;
|
||||
import de.avatic.lcc.service.transformer.generic.DimensionTransformer;
|
||||
import de.avatic.lcc.service.transformer.generic.NodeTransformer;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Optional;
|
||||
|
|
@ -17,14 +17,14 @@ public class MaterialViewPackagingDTOTransformer {
|
|||
|
||||
private final NodeRepository nodeRepository;
|
||||
private final PackagingDimensionRepository packagingDimensionRepository;
|
||||
private final DimensionDTOTransformer dimensionDTOTransformer;
|
||||
private final NodeDTOTransformer nodeDTOTransformer;
|
||||
private final DimensionTransformer dimensionTransformer;
|
||||
private final NodeTransformer nodeTransformer;
|
||||
|
||||
public MaterialViewPackagingDTOTransformer(NodeRepository nodeRepository, PackagingDimensionRepository packagingDimensionRepository, DimensionDTOTransformer dimensionDTOTransformer, NodeDTOTransformer nodeDTOTransformer) {
|
||||
public MaterialViewPackagingDTOTransformer(NodeRepository nodeRepository, PackagingDimensionRepository packagingDimensionRepository, DimensionTransformer dimensionTransformer, NodeTransformer nodeTransformer) {
|
||||
this.nodeRepository = nodeRepository;
|
||||
this.packagingDimensionRepository = packagingDimensionRepository;
|
||||
this.dimensionDTOTransformer = dimensionDTOTransformer;
|
||||
this.nodeDTOTransformer = nodeDTOTransformer;
|
||||
this.dimensionTransformer = dimensionTransformer;
|
||||
this.nodeTransformer = nodeTransformer;
|
||||
}
|
||||
|
||||
public MaterialViewPackagingDTO toMaterialViewPackagingDTO(Packaging entity) {
|
||||
|
|
@ -35,9 +35,9 @@ public class MaterialViewPackagingDTOTransformer {
|
|||
MaterialViewPackagingDTO dto = new MaterialViewPackagingDTO();
|
||||
dto.setId(entity.getId());
|
||||
dto.setDeprecated(entity.getDeprecated());
|
||||
dto.setHu(dimensionDTOTransformer.toDimensionDTO(hu.orElseThrow()));
|
||||
dto.setShu(dimensionDTOTransformer.toDimensionDTO(shu.orElseThrow()));
|
||||
dto.setSupplier(nodeDTOTransformer.toNodeDTO(supplier.orElseThrow()));
|
||||
dto.setHu(dimensionTransformer.toDimensionDTO(hu.orElseThrow()));
|
||||
dto.setShu(dimensionTransformer.toDimensionDTO(shu.orElseThrow()));
|
||||
dto.setSupplier(nodeTransformer.toNodeDTO(supplier.orElseThrow()));
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@ import de.avatic.lcc.dto.generic.NodeDTO;
|
|||
import de.avatic.lcc.dto.generic.NodeTypeDTO;
|
||||
import de.avatic.lcc.dto.configuration.nodes.view.NodeDetailDTO;
|
||||
import de.avatic.lcc.model.nodes.Node;
|
||||
import de.avatic.lcc.repositories.CountryRepository;
|
||||
import de.avatic.lcc.repositories.country.CountryRepository;
|
||||
import de.avatic.lcc.repositories.NodeRepository;
|
||||
import de.avatic.lcc.service.transformer.generic.CountryDTOTransformer;
|
||||
import de.avatic.lcc.service.transformer.generic.LocationDTOTransformer;
|
||||
import de.avatic.lcc.service.transformer.generic.NodeDTOTransformer;
|
||||
import de.avatic.lcc.service.transformer.generic.CountryTransformer;
|
||||
import de.avatic.lcc.service.transformer.generic.LocationTransformer;
|
||||
import de.avatic.lcc.service.transformer.generic.NodeTransformer;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -18,17 +18,17 @@ import java.util.Map;
|
|||
@Service
|
||||
public class NodeViewDTOTransformer {
|
||||
|
||||
private final CountryDTOTransformer countryDTOTransformer;
|
||||
private final CountryTransformer countryTransformer;
|
||||
private final CountryRepository countryRepository;
|
||||
private final LocationDTOTransformer locationDTOTransformer;
|
||||
private final NodeDTOTransformer nodeDTOTransformer;
|
||||
private final LocationTransformer locationTransformer;
|
||||
private final NodeTransformer nodeTransformer;
|
||||
private final NodeRepository nodeRepository;
|
||||
|
||||
public NodeViewDTOTransformer(CountryDTOTransformer countryDTOTransformer, CountryRepository countryRepository, LocationDTOTransformer locationDTOTransformer, NodeDTOTransformer nodeDTOTransformer, NodeRepository nodeRepository) {
|
||||
this.countryDTOTransformer = countryDTOTransformer;
|
||||
public NodeViewDTOTransformer(CountryTransformer countryTransformer, CountryRepository countryRepository, LocationTransformer locationTransformer, NodeTransformer nodeTransformer, NodeRepository nodeRepository) {
|
||||
this.countryTransformer = countryTransformer;
|
||||
this.countryRepository = countryRepository;
|
||||
this.locationDTOTransformer = locationDTOTransformer;
|
||||
this.nodeDTOTransformer = nodeDTOTransformer;
|
||||
this.locationTransformer = locationTransformer;
|
||||
this.nodeTransformer = nodeTransformer;
|
||||
this.nodeRepository = nodeRepository;
|
||||
}
|
||||
|
||||
|
|
@ -38,17 +38,17 @@ public class NodeViewDTOTransformer {
|
|||
Map<Integer, NodeDTO> predecessors = new HashMap<>();
|
||||
|
||||
for (Integer seq : node.getNodePredecessors().keySet())
|
||||
predecessors.put(seq, nodeDTOTransformer.toNodeDTO(nodeRepository.getById(node.getNodePredecessors().get(seq)).orElseThrow()));
|
||||
predecessors.put(seq, nodeTransformer.toNodeDTO(nodeRepository.getById(node.getNodePredecessors().get(seq)).orElseThrow()));
|
||||
|
||||
dto.setId(node.getId());
|
||||
dto.setDeprecated(node.getDeprecated());
|
||||
dto.setCountry(countryDTOTransformer.toCountryDTO(countryRepository.getById(node.getCountryId()).orElseThrow()));
|
||||
dto.setCountry(countryTransformer.toCountryDTO(countryRepository.getById(node.getCountryId()).orElseThrow()));
|
||||
dto.setName(node.getName());
|
||||
dto.setAddress(node.getAddress());
|
||||
dto.setLocation(locationDTOTransformer.toLocationDTO(node));
|
||||
dto.setLocation(locationTransformer.toLocationDTO(node));
|
||||
dto.setTypes(toNodeTypeArrayList(node));
|
||||
dto.setPredecessors(predecessors);
|
||||
dto.setOutboundCountries(node.getOutboundCountries().stream().map(id -> countryDTOTransformer.toCountryDTO(countryRepository.getById(id).orElseThrow())).toList());
|
||||
dto.setOutboundCountries(node.getOutboundCountries().stream().map(id -> countryTransformer.toCountryDTO(countryRepository.getById(id).orElseThrow())).toList());
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,10 +7,10 @@ import de.avatic.lcc.model.materials.Material;
|
|||
import de.avatic.lcc.model.nodes.Node;
|
||||
import de.avatic.lcc.model.packaging.Packaging;
|
||||
import de.avatic.lcc.model.packaging.PackagingDimension;
|
||||
import de.avatic.lcc.model.packaging.PackagingProperty;
|
||||
import de.avatic.lcc.service.transformer.generic.DimensionDTOTransformer;
|
||||
import de.avatic.lcc.service.transformer.generic.MaterialDTOTransformer;
|
||||
import de.avatic.lcc.service.transformer.generic.NodeDTOTransformer;
|
||||
import de.avatic.lcc.model.properties.PackagingProperty;
|
||||
import de.avatic.lcc.service.transformer.generic.DimensionTransformer;
|
||||
import de.avatic.lcc.service.transformer.generic.MaterialTransformer;
|
||||
import de.avatic.lcc.service.transformer.generic.NodeTransformer;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -21,15 +21,15 @@ public class PackagingTransformerService {
|
|||
|
||||
//TODO refactor to new format
|
||||
|
||||
private final MaterialDTOTransformer materialDTOTransformer;
|
||||
private final DimensionDTOTransformer dimensionDTOTransformer;
|
||||
private final NodeDTOTransformer nodeDTOTransformer;
|
||||
private final MaterialTransformer materialTransformer;
|
||||
private final DimensionTransformer dimensionTransformer;
|
||||
private final NodeTransformer nodeTransformer;
|
||||
private final PackagingViewPropertyDTOTransformer packagingViewPropertyDTOTransformer;
|
||||
|
||||
public PackagingTransformerService(MaterialDTOTransformer materialDTOTransformer, DimensionDTOTransformer dimensionDTOTransformer, NodeDTOTransformer nodeDTOTransformer, PackagingViewPropertyDTOTransformer packagingViewPropertyDTOTransformer) {
|
||||
this.materialDTOTransformer = materialDTOTransformer;
|
||||
this.dimensionDTOTransformer = dimensionDTOTransformer;
|
||||
this.nodeDTOTransformer = nodeDTOTransformer;
|
||||
public PackagingTransformerService(MaterialTransformer materialTransformer, DimensionTransformer dimensionTransformer, NodeTransformer nodeTransformer, PackagingViewPropertyDTOTransformer packagingViewPropertyDTOTransformer) {
|
||||
this.materialTransformer = materialTransformer;
|
||||
this.dimensionTransformer = dimensionTransformer;
|
||||
this.nodeTransformer = nodeTransformer;
|
||||
this.packagingViewPropertyDTOTransformer = packagingViewPropertyDTOTransformer;
|
||||
}
|
||||
|
||||
|
|
@ -41,10 +41,10 @@ public class PackagingTransformerService {
|
|||
var dto = new PackagingViewDTO();
|
||||
|
||||
dto.setId(data.getId());
|
||||
dto.setMaterial(materialDTOTransformer.toMaterialDTO(material.orElseThrow()));
|
||||
dto.setSupplier(nodeDTOTransformer.toNodeDTO(supplier.orElseThrow()));
|
||||
dto.setHu(dimensionDTOTransformer.toDimensionDTO(hu.orElseThrow()));
|
||||
dto.setShu(dimensionDTOTransformer.toDimensionDTO(shu.orElseThrow()));
|
||||
dto.setMaterial(materialTransformer.toMaterialDTO(material.orElseThrow()));
|
||||
dto.setSupplier(nodeTransformer.toNodeDTO(supplier.orElseThrow()));
|
||||
dto.setHu(dimensionTransformer.toDimensionDTO(hu.orElseThrow()));
|
||||
dto.setShu(dimensionTransformer.toDimensionDTO(shu.orElseThrow()));
|
||||
dto.setDeprecated(data.getDeprecated());
|
||||
dto.setProperties(properties.stream().map(packagingViewPropertyDTOTransformer::toPackagingViewPropertyDTO).toList());
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package de.avatic.lcc.service.transformer.packaging;
|
||||
|
||||
import de.avatic.lcc.dto.configuration.packaging.view.PackagingViewPropertyDTO;
|
||||
import de.avatic.lcc.model.packaging.PackagingProperty;
|
||||
import de.avatic.lcc.model.properties.PackagingProperty;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
|
|
@ -10,12 +10,12 @@ public class PackagingViewPropertyDTOTransformer {
|
|||
public PackagingViewPropertyDTO toPackagingViewPropertyDTO(PackagingProperty property) {
|
||||
PackagingViewPropertyDTO dto = new PackagingViewPropertyDTO();
|
||||
|
||||
dto.setCurrentValue(property.getPropertyValue());
|
||||
dto.setDataType(property.getPackagingPropertyType().getDataType().name());
|
||||
dto.setRequired(property.getPackagingPropertyType().getRequired());
|
||||
dto.setName(property.getPackagingPropertyType().getName());
|
||||
dto.setExternalMappingId(property.getPackagingPropertyType().getExternalMappingId());
|
||||
dto.setValidationRule(property.getPackagingPropertyType().getValidationRule());
|
||||
dto.setCurrentValue(property.getValue());
|
||||
dto.setDataType(property.getType().getDataType().name());
|
||||
dto.setRequired(property.getType().getRequired());
|
||||
dto.setName(property.getType().getName());
|
||||
dto.setExternalMappingId(property.getType().getExternalMappingId());
|
||||
dto.setValidationRule(property.getType().getValidationRule());
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +0,0 @@
|
|||
package de.avatic.lcc.service.transformer.users;
|
||||
|
||||
import de.avatic.lcc.dto.users.UserDTO;
|
||||
import de.avatic.lcc.model.users.User;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class UserDTOTransformer {
|
||||
|
||||
public UserDTO toUserDTO(User entity) {
|
||||
UserDTO dto = new UserDTO();
|
||||
|
||||
// todo implement
|
||||
|
||||
return dto;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
package de.avatic.lcc.service.transformer.users;
|
||||
|
||||
import de.avatic.lcc.dto.users.UserDTO;
|
||||
import de.avatic.lcc.model.users.Group;
|
||||
import de.avatic.lcc.model.users.User;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class UserTransformer {
|
||||
|
||||
public UserDTO toUserDTO(User entity) {
|
||||
UserDTO dto = new UserDTO();
|
||||
|
||||
dto.setActive(entity.getActive());
|
||||
dto.setEmail(entity.getEmail());
|
||||
dto.setFirstName(entity.getFirstName());
|
||||
dto.setLastName(entity.getLastName());
|
||||
dto.setWorkdayId(entity.getWorkdayId());
|
||||
dto.setGroups(entity.getGroups().stream().map(Group::getName).toList());
|
||||
|
||||
return dto;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public User fromUserDTO(UserDTO dto) {
|
||||
User entity = new User();
|
||||
|
||||
entity.setActive(dto.isActive());
|
||||
entity.setEmail(dto.getEmail());
|
||||
entity.setFirstName(dto.getFirstName());
|
||||
entity.setLastName(dto.getLastName());
|
||||
entity.setWorkdayId(dto.getWorkdayId());
|
||||
entity.setGroups(dto.getGroups().stream().map(this::fromGroupDTO).toList());
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
private Group fromGroupDTO(String name) {
|
||||
var group = new Group();
|
||||
group.setName(name);
|
||||
return group;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue