From c756e2a554381e50157e8a28cf0811c8c14b2104 Mon Sep 17 00:00:00 2001 From: Alexander Avershin <55056382+asavershin@users.noreply.github.com> Date: Thu, 3 Oct 2024 18:12:33 +0300 Subject: [PATCH] 53 Fix incorrect blank lines (#54) * 53 Fix incorrect blank lines * 53 Fix sql requests --- .../java/agroscience/fields/Application.java | 1 + .../fields/configuration/Config.java | 1 + .../fields/configuration/MeteoProperties.java | 2 ++ .../fields/controllers/AdminController.java | 2 +- .../controllers/CropRotationsController.java | 2 +- .../fields/controllers/CropsController.java | 2 ++ .../fields/controllers/FieldController.java | 1 + .../fields/controllers/SoilController.java | 2 ++ .../agroscience/fields/dao/entities/Crop.java | 1 + .../fields/dao/entities/Field.java | 1 + .../agroscience/fields/dao/entities/Soil.java | 2 ++ .../fields/dao/models/FandCRandC.java | 2 ++ .../fields/dao/models/FandCRandCImpl.java | 2 ++ .../dao/models/FieldAndCurrentCrop.java | 2 ++ .../dao/models/FieldAndCurrentCropImpl.java | 2 ++ .../fields/dao/models/FieldCRsSoil.java | 2 ++ .../fields/dao/models/FieldCRsSoilImpl.java | 2 ++ .../repositories/CropRotationRepository.java | 16 ++++++--------- .../dao/repositories/CropsRepository.java | 2 ++ .../dao/repositories/FieldRepository.java | 20 ++++++++----------- .../fields/dao/repositories/JbdcDao.java | 4 ++-- .../dao/repositories/SoilRepository.java | 2 ++ .../agroscience/fields/dto/ResponseMeteo.java | 2 ++ .../java/agroscience/fields/dto/TimeDTO.java | 2 ++ .../fields/dto/crop/RequestCrop.java | 2 ++ .../fields/dto/crop/RequestGetCrops.java | 2 ++ .../fields/dto/crop/ResponseCrop.java | 2 ++ .../dto/croprotation/RequestCropRotation.java | 1 + .../dto/croprotation/ResponseCRForF.java | 2 ++ .../dto/croprotation/ResponseCRWithField.java | 2 ++ .../dto/croprotation/ResponseFieldName.java | 2 ++ .../ResponseListCropRotationsForField.java | 2 ++ .../fields/dto/field/CoordinatesDTO.java | 2 ++ .../dto/field/CoordinatesWithFieldId.java | 2 ++ .../agroscience/fields/dto/field/GeomDTO.java | 2 ++ .../fields/dto/field/RequestField.java | 1 + .../dto/field/ResponseFieldPreview.java | 2 ++ .../fields/dto/field/ResponseFieldWithCR.java | 2 ++ .../fields/dto/field/ResponseFullField.java | 2 ++ .../fields/dto/soil/RequestSoil.java | 2 ++ .../dto/soil/RequestSoilWithouFieldId.java | 2 ++ .../fields/dto/soil/ResponseSoil.java | 2 ++ .../fields/dto/soil/ResponseSoilForF.java | 2 ++ .../fields/exceptions/AuthException.java | 2 ++ .../fields/exceptions/DateException.java | 2 ++ .../fields/exceptions/DuplicateException.java | 1 + .../fields/exceptions/ExceptionBody.java | 2 ++ .../fields/exceptions/HandleErrorService.java | 2 ++ .../exceptions/WrongCoordinatesException.java | 2 ++ .../constraints/LocalDateFormat.java | 2 ++ .../validators/LocalDateFormatValidator.java | 2 ++ .../LocalDateValidatorForFieldType.java | 2 ++ .../fields/mappers/CropMapper.java | 2 ++ .../fields/mappers/CropRotationMapper.java | 1 + .../fields/mappers/FieldMapper.java | 2 ++ .../fields/security/AuthoriseService.java | 2 ++ .../agroscience/fields/security/Role.java | 2 ++ .../fields/services/AdminService.java | 2 ++ .../fields/services/CropRotationsService.java | 8 +++++--- .../fields/services/CropsService.java | 2 ++ .../fields/services/FieldService.java | 5 ++++- .../fields/services/SoilService.java | 2 ++ .../fields/utilities/LocalDateConverting.java | 2 ++ .../agroscience/fields/AdminServiceTest.java | 2 ++ .../fields/CropRotationsServiceTest.java | 2 ++ .../agroscience/fields/FieldServiceTest.java | 1 + .../fields/PostgreTestContainerConfig.java | 4 ++++ .../agroscience/fields/SoilServiceTest.java | 1 + 68 files changed, 140 insertions(+), 30 deletions(-) diff --git a/src/main/java/agroscience/fields/Application.java b/src/main/java/agroscience/fields/Application.java index eb51f74..a1f1b41 100644 --- a/src/main/java/agroscience/fields/Application.java +++ b/src/main/java/agroscience/fields/Application.java @@ -5,6 +5,7 @@ @SpringBootApplication public class Application { + public static void main(String[] args) { SpringApplication.run(Application.class, args); } diff --git a/src/main/java/agroscience/fields/configuration/Config.java b/src/main/java/agroscience/fields/configuration/Config.java index c82ca02..c169079 100644 --- a/src/main/java/agroscience/fields/configuration/Config.java +++ b/src/main/java/agroscience/fields/configuration/Config.java @@ -6,6 +6,7 @@ @Configuration public class Config { + @Bean public RestTemplate restTemplate() { return new RestTemplate(); diff --git a/src/main/java/agroscience/fields/configuration/MeteoProperties.java b/src/main/java/agroscience/fields/configuration/MeteoProperties.java index ecb2ef3..4bd4758 100644 --- a/src/main/java/agroscience/fields/configuration/MeteoProperties.java +++ b/src/main/java/agroscience/fields/configuration/MeteoProperties.java @@ -8,6 +8,8 @@ @Data @ConfigurationProperties(prefix = "meteo") public class MeteoProperties { + private String host; private String port; + } diff --git a/src/main/java/agroscience/fields/controllers/AdminController.java b/src/main/java/agroscience/fields/controllers/AdminController.java index 571897c..d034645 100644 --- a/src/main/java/agroscience/fields/controllers/AdminController.java +++ b/src/main/java/agroscience/fields/controllers/AdminController.java @@ -26,9 +26,9 @@ @RequiredArgsConstructor @RequestMapping(path = "api/v1/admin") public class AdminController { + private final AdminService cropsService; private final CropMapper cropMapper; - private final AuthoriseService auth; @PostMapping @Operation(description = "Создание культуры") diff --git a/src/main/java/agroscience/fields/controllers/CropRotationsController.java b/src/main/java/agroscience/fields/controllers/CropRotationsController.java index a59f6a1..b231308 100644 --- a/src/main/java/agroscience/fields/controllers/CropRotationsController.java +++ b/src/main/java/agroscience/fields/controllers/CropRotationsController.java @@ -32,6 +32,7 @@ @RequiredArgsConstructor @RequestMapping(path = "api/v1/fields/crop-rotations") public class CropRotationsController { + private final CropRotationsService crService; private final CropRotationMapper crMapper; private final AuthoriseService auth; @@ -121,5 +122,4 @@ public ResponseEntity deleteCR(@Valid @Min(1) Long id, HttpServletRequest return ResponseEntity.noContent().build(); } - } diff --git a/src/main/java/agroscience/fields/controllers/CropsController.java b/src/main/java/agroscience/fields/controllers/CropsController.java index a4db39d..7e5c479 100644 --- a/src/main/java/agroscience/fields/controllers/CropsController.java +++ b/src/main/java/agroscience/fields/controllers/CropsController.java @@ -18,6 +18,7 @@ @RequiredArgsConstructor @RequestMapping(path = "api/v1/fields") public class CropsController { + private final CropsService cropsService; private final CropMapper cropMapper; private final AuthoriseService auth; @@ -29,4 +30,5 @@ public List getCrops(RequestGetCrops request, HttpServletRequest h return cropsService.getCrop(request.getName(), request.getPage(), request.getSize()) .stream().map(cropMapper::cropToResponseCrop).toList(); } + } diff --git a/src/main/java/agroscience/fields/controllers/FieldController.java b/src/main/java/agroscience/fields/controllers/FieldController.java index b5d880a..6ffd42e 100644 --- a/src/main/java/agroscience/fields/controllers/FieldController.java +++ b/src/main/java/agroscience/fields/controllers/FieldController.java @@ -144,4 +144,5 @@ public List getFieldsPreview(@Valid Page page, HttpServlet public List getAllCoordinates() { return fieldService.getAllCoordinates(); } + } \ No newline at end of file diff --git a/src/main/java/agroscience/fields/controllers/SoilController.java b/src/main/java/agroscience/fields/controllers/SoilController.java index 40bdb9f..2333056 100644 --- a/src/main/java/agroscience/fields/controllers/SoilController.java +++ b/src/main/java/agroscience/fields/controllers/SoilController.java @@ -28,6 +28,7 @@ @RequiredArgsConstructor @RequestMapping(path = "api/v1/fields/soil") public class SoilController { + private final SoilService soilService; private final SoilMapper soilMapper; private final AuthoriseService auth; @@ -77,4 +78,5 @@ public ResponseEntity deleteSoil(@Valid @Min(1) Long soilId, HttpServletRe soilService.deleteSoilById(soilId, auth.doFilter(request, new Role.Builder().worker().organization().build())); return ResponseEntity.noContent().build(); } + } diff --git a/src/main/java/agroscience/fields/dao/entities/Crop.java b/src/main/java/agroscience/fields/dao/entities/Crop.java index 0922ec6..08755e9 100644 --- a/src/main/java/agroscience/fields/dao/entities/Crop.java +++ b/src/main/java/agroscience/fields/dao/entities/Crop.java @@ -41,4 +41,5 @@ public class Crop { @ToString.Exclude @EqualsAndHashCode.Exclude private List cropRotations = new ArrayList<>(); + } diff --git a/src/main/java/agroscience/fields/dao/entities/Field.java b/src/main/java/agroscience/fields/dao/entities/Field.java index a13f7d5..61b24c8 100644 --- a/src/main/java/agroscience/fields/dao/entities/Field.java +++ b/src/main/java/agroscience/fields/dao/entities/Field.java @@ -74,4 +74,5 @@ public class Field { @ToString.Exclude @EqualsAndHashCode.Exclude private List soils = new ArrayList<>(); + } diff --git a/src/main/java/agroscience/fields/dao/entities/Soil.java b/src/main/java/agroscience/fields/dao/entities/Soil.java index 306f974..de84670 100644 --- a/src/main/java/agroscience/fields/dao/entities/Soil.java +++ b/src/main/java/agroscience/fields/dao/entities/Soil.java @@ -26,6 +26,7 @@ @AllArgsConstructor @Builder public class Soil { + @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "soil_soil_id_seq") @SequenceGenerator(name = "soil_soil_id_seq", sequenceName = "soil_soil_id_seq", allocationSize = 1) @@ -82,4 +83,5 @@ public class Soil { @Column(name = "soil_zn") private String soilZn; + } diff --git a/src/main/java/agroscience/fields/dao/models/FandCRandC.java b/src/main/java/agroscience/fields/dao/models/FandCRandC.java index b7adcaa..0dd91d9 100644 --- a/src/main/java/agroscience/fields/dao/models/FandCRandC.java +++ b/src/main/java/agroscience/fields/dao/models/FandCRandC.java @@ -5,9 +5,11 @@ import agroscience.fields.dao.entities.Field; public interface FandCRandC { + Field getField(); CropRotation getCropRotation(); Crop getCrop(); + } diff --git a/src/main/java/agroscience/fields/dao/models/FandCRandCImpl.java b/src/main/java/agroscience/fields/dao/models/FandCRandCImpl.java index 4504564..9ed204e 100644 --- a/src/main/java/agroscience/fields/dao/models/FandCRandCImpl.java +++ b/src/main/java/agroscience/fields/dao/models/FandCRandCImpl.java @@ -9,7 +9,9 @@ @Data @AllArgsConstructor public class FandCRandCImpl implements FandCRandC { + private final Field field; private final CropRotation cropRotation; private final Crop crop; + } diff --git a/src/main/java/agroscience/fields/dao/models/FieldAndCurrentCrop.java b/src/main/java/agroscience/fields/dao/models/FieldAndCurrentCrop.java index cabbb67..bc9639c 100644 --- a/src/main/java/agroscience/fields/dao/models/FieldAndCurrentCrop.java +++ b/src/main/java/agroscience/fields/dao/models/FieldAndCurrentCrop.java @@ -5,7 +5,9 @@ public interface FieldAndCurrentCrop { + Field getField(); CropRotation getCropRotation(); + } diff --git a/src/main/java/agroscience/fields/dao/models/FieldAndCurrentCropImpl.java b/src/main/java/agroscience/fields/dao/models/FieldAndCurrentCropImpl.java index 3b04afa..d082179 100644 --- a/src/main/java/agroscience/fields/dao/models/FieldAndCurrentCropImpl.java +++ b/src/main/java/agroscience/fields/dao/models/FieldAndCurrentCropImpl.java @@ -8,6 +8,8 @@ @Data @AllArgsConstructor public class FieldAndCurrentCropImpl implements FieldAndCurrentCrop { + private final Field field; private final CropRotation cropRotation; + } diff --git a/src/main/java/agroscience/fields/dao/models/FieldCRsSoil.java b/src/main/java/agroscience/fields/dao/models/FieldCRsSoil.java index 86ccc9d..1db6789 100644 --- a/src/main/java/agroscience/fields/dao/models/FieldCRsSoil.java +++ b/src/main/java/agroscience/fields/dao/models/FieldCRsSoil.java @@ -6,6 +6,7 @@ import agroscience.fields.dao.entities.Soil; public interface FieldCRsSoil { + Field getField(); CropRotation getCropRotation(); @@ -13,4 +14,5 @@ public interface FieldCRsSoil { Soil getSoil(); Crop getCrop(); + } diff --git a/src/main/java/agroscience/fields/dao/models/FieldCRsSoilImpl.java b/src/main/java/agroscience/fields/dao/models/FieldCRsSoilImpl.java index e3bb39f..bab9845 100644 --- a/src/main/java/agroscience/fields/dao/models/FieldCRsSoilImpl.java +++ b/src/main/java/agroscience/fields/dao/models/FieldCRsSoilImpl.java @@ -11,8 +11,10 @@ @Data @AllArgsConstructor public class FieldCRsSoilImpl implements FieldCRsSoil { + private final Field field; private final CropRotation cropRotation; private final Soil soil; private final Crop crop; + } diff --git a/src/main/java/agroscience/fields/dao/repositories/CropRotationRepository.java b/src/main/java/agroscience/fields/dao/repositories/CropRotationRepository.java index 0625116..8a934a5 100644 --- a/src/main/java/agroscience/fields/dao/repositories/CropRotationRepository.java +++ b/src/main/java/agroscience/fields/dao/repositories/CropRotationRepository.java @@ -20,30 +20,26 @@ public interface CropRotationRepository extends JpaRepository findAllByOrgId(Long orgId, Pageable pageable); + } diff --git a/src/main/java/agroscience/fields/dao/repositories/CropsRepository.java b/src/main/java/agroscience/fields/dao/repositories/CropsRepository.java index 171f7ec..543cdcd 100644 --- a/src/main/java/agroscience/fields/dao/repositories/CropsRepository.java +++ b/src/main/java/agroscience/fields/dao/repositories/CropsRepository.java @@ -6,9 +6,11 @@ import org.springframework.data.jpa.repository.JpaRepository; public interface CropsRepository extends JpaRepository { + Crop findCropByCropId(Long cropId); boolean existsByCropName(String name); List findAllByCropNameIgnoreCaseStartingWith(String cropName, PageRequest of); + } diff --git a/src/main/java/agroscience/fields/dao/repositories/FieldRepository.java b/src/main/java/agroscience/fields/dao/repositories/FieldRepository.java index 7551cd1..17129bf 100644 --- a/src/main/java/agroscience/fields/dao/repositories/FieldRepository.java +++ b/src/main/java/agroscience/fields/dao/repositories/FieldRepository.java @@ -10,8 +10,8 @@ import org.springframework.data.repository.query.Param; public interface FieldRepository extends JpaRepository { - @Query( - """ + + @Query(""" SELECT f as field, cr as cropRotation FROM Field f LEFT JOIN FETCH f.cropRotations cr @@ -20,12 +20,10 @@ public interface FieldRepository extends JpaRepository { WHERE cr2.field = f) OR cr.cropRotationStartDate IS NULL) AND f.fieldOrganizationId = :orgId - """ - ) + """) Slice fieldsWithLatestCrops(@Param("orgId") Long orgId, Pageable pageable); - @Query( - """ + @Query(""" SELECT f as field, cr as cropRotation FROM Field f LEFT JOIN FETCH f.cropRotations cr @@ -34,12 +32,10 @@ public interface FieldRepository extends JpaRepository { WHERE cr2.field = f) OR cr.cropRotationStartDate IS NULL) AND f.fieldId = :fieldId - """ - ) + """) FieldAndCurrentCrop fieldWithLatestCrop(@Param("fieldId") Long fieldId); - @Query( - """ + @Query(""" SELECT f as field, cr as cropRotation, s as soil, c as crop FROM Field f LEFT JOIN FETCH f.cropRotations cr @@ -48,9 +44,9 @@ public interface FieldRepository extends JpaRepository { WHERE f.fieldId = :fieldId ORDER BY cr.cropRotationStartDate DESC, s.soilSampleDate DESC LIMIT 1 - """ - ) + """) FieldCRsSoil getFullField(@Param("fieldId") Long fieldId); boolean existsByFieldName(String name); + } diff --git a/src/main/java/agroscience/fields/dao/repositories/JbdcDao.java b/src/main/java/agroscience/fields/dao/repositories/JbdcDao.java index dfdbb2f..3326874 100644 --- a/src/main/java/agroscience/fields/dao/repositories/JbdcDao.java +++ b/src/main/java/agroscience/fields/dao/repositories/JbdcDao.java @@ -10,13 +10,11 @@ @RequiredArgsConstructor public class JbdcDao { - private final JdbcTemplate jdbcTemplate; private static final String GET_ORG_ID_BY_FIELD_ID = """ SELECT f.field_organization_id as orgId FROM field f WHERE f.field_id = ? """; - private static final String GET_ALL_COORDINATES = """ SELECT field_id, @@ -24,6 +22,7 @@ public class JbdcDao { ST_Y(ST_Centroid(field_geom)) as latitude FROM field """; + private final JdbcTemplate jdbcTemplate; public List getAllCoordinates() { @@ -42,4 +41,5 @@ public Long getOrgIdByFieldId(Long fieldId) { fieldId ); } + } diff --git a/src/main/java/agroscience/fields/dao/repositories/SoilRepository.java b/src/main/java/agroscience/fields/dao/repositories/SoilRepository.java index c0137ad..af7f254 100644 --- a/src/main/java/agroscience/fields/dao/repositories/SoilRepository.java +++ b/src/main/java/agroscience/fields/dao/repositories/SoilRepository.java @@ -5,5 +5,7 @@ import org.springframework.data.jpa.repository.JpaRepository; public interface SoilRepository extends JpaRepository { + boolean existsBySoilSampleDate(LocalDate date); + } diff --git a/src/main/java/agroscience/fields/dto/ResponseMeteo.java b/src/main/java/agroscience/fields/dto/ResponseMeteo.java index e952e54..6e8b2de 100644 --- a/src/main/java/agroscience/fields/dto/ResponseMeteo.java +++ b/src/main/java/agroscience/fields/dto/ResponseMeteo.java @@ -11,9 +11,11 @@ @Builder @NoArgsConstructor public class ResponseMeteo { + private LocalDate day; private Long fieldId; private Double temperature; private Double humidity; private Double pressure; + } diff --git a/src/main/java/agroscience/fields/dto/TimeDTO.java b/src/main/java/agroscience/fields/dto/TimeDTO.java index 2bda909..0d0bae4 100644 --- a/src/main/java/agroscience/fields/dto/TimeDTO.java +++ b/src/main/java/agroscience/fields/dto/TimeDTO.java @@ -1,7 +1,9 @@ package agroscience.fields.dto; public interface TimeDTO { + String start(); String end(); + } diff --git a/src/main/java/agroscience/fields/dto/crop/RequestCrop.java b/src/main/java/agroscience/fields/dto/crop/RequestCrop.java index c324798..fce6295 100644 --- a/src/main/java/agroscience/fields/dto/crop/RequestCrop.java +++ b/src/main/java/agroscience/fields/dto/crop/RequestCrop.java @@ -7,8 +7,10 @@ @Data public class RequestCrop { + @NotBlank @Size(max = 50) @JsonAlias("name") private String cropName; + } diff --git a/src/main/java/agroscience/fields/dto/crop/RequestGetCrops.java b/src/main/java/agroscience/fields/dto/crop/RequestGetCrops.java index 98985f3..6f44d8b 100644 --- a/src/main/java/agroscience/fields/dto/crop/RequestGetCrops.java +++ b/src/main/java/agroscience/fields/dto/crop/RequestGetCrops.java @@ -9,7 +9,9 @@ @Getter @Setter public class RequestGetCrops extends Page { + @Size(max = 50) @JsonProperty("name") private String name; + } diff --git a/src/main/java/agroscience/fields/dto/crop/ResponseCrop.java b/src/main/java/agroscience/fields/dto/crop/ResponseCrop.java index 8982568..8b82249 100644 --- a/src/main/java/agroscience/fields/dto/crop/ResponseCrop.java +++ b/src/main/java/agroscience/fields/dto/crop/ResponseCrop.java @@ -7,8 +7,10 @@ @Data @AllArgsConstructor public class ResponseCrop { + @JsonProperty("id") private Long cropId; @JsonProperty("name") private String cropName; + } diff --git a/src/main/java/agroscience/fields/dto/croprotation/RequestCropRotation.java b/src/main/java/agroscience/fields/dto/croprotation/RequestCropRotation.java index 5624047..93d0e21 100644 --- a/src/main/java/agroscience/fields/dto/croprotation/RequestCropRotation.java +++ b/src/main/java/agroscience/fields/dto/croprotation/RequestCropRotation.java @@ -43,4 +43,5 @@ public String start() { public String end() { return cropRotationEndDate; } + } diff --git a/src/main/java/agroscience/fields/dto/croprotation/ResponseCRForF.java b/src/main/java/agroscience/fields/dto/croprotation/ResponseCRForF.java index bbe7d84..45a9b88 100644 --- a/src/main/java/agroscience/fields/dto/croprotation/ResponseCRForF.java +++ b/src/main/java/agroscience/fields/dto/croprotation/ResponseCRForF.java @@ -6,6 +6,7 @@ @Data public class ResponseCRForF { + @JsonProperty("id") private Long cropRotationId; private ResponseCrop crop; @@ -15,4 +16,5 @@ public class ResponseCRForF { private String cropRotationStartDate; @JsonProperty("endDate") private String cropRotationEndDate; + } diff --git a/src/main/java/agroscience/fields/dto/croprotation/ResponseCRWithField.java b/src/main/java/agroscience/fields/dto/croprotation/ResponseCRWithField.java index c2d8311..12290b6 100644 --- a/src/main/java/agroscience/fields/dto/croprotation/ResponseCRWithField.java +++ b/src/main/java/agroscience/fields/dto/croprotation/ResponseCRWithField.java @@ -6,6 +6,7 @@ @Data public class ResponseCRWithField { + @JsonProperty("id") private Long cropRotationId; private ResponseCrop crop; @@ -16,4 +17,5 @@ public class ResponseCRWithField { @JsonProperty("endDate") private String cropRotationEndDate; private ResponseFieldName field; + } diff --git a/src/main/java/agroscience/fields/dto/croprotation/ResponseFieldName.java b/src/main/java/agroscience/fields/dto/croprotation/ResponseFieldName.java index 6b9be8f..06bc4c5 100644 --- a/src/main/java/agroscience/fields/dto/croprotation/ResponseFieldName.java +++ b/src/main/java/agroscience/fields/dto/croprotation/ResponseFieldName.java @@ -6,8 +6,10 @@ @Data public class ResponseFieldName { + @JsonProperty("id") private Long fieldId; @JsonAlias("name") private String fieldName; + } diff --git a/src/main/java/agroscience/fields/dto/croprotation/ResponseListCropRotationsForField.java b/src/main/java/agroscience/fields/dto/croprotation/ResponseListCropRotationsForField.java index 01ed9a1..0f5f0e5 100644 --- a/src/main/java/agroscience/fields/dto/croprotation/ResponseListCropRotationsForField.java +++ b/src/main/java/agroscience/fields/dto/croprotation/ResponseListCropRotationsForField.java @@ -5,6 +5,8 @@ @Data public class ResponseListCropRotationsForField { + List cropRotations; private Long fieldId; + } diff --git a/src/main/java/agroscience/fields/dto/field/CoordinatesDTO.java b/src/main/java/agroscience/fields/dto/field/CoordinatesDTO.java index bc3fd8b..168e1e5 100644 --- a/src/main/java/agroscience/fields/dto/field/CoordinatesDTO.java +++ b/src/main/java/agroscience/fields/dto/field/CoordinatesDTO.java @@ -9,8 +9,10 @@ @AllArgsConstructor @NoArgsConstructor public class CoordinatesDTO { + @NotNull(message = "Must be filled") private Double longitude; @NotNull(message = "Must be filled") private Double latitude; + } diff --git a/src/main/java/agroscience/fields/dto/field/CoordinatesWithFieldId.java b/src/main/java/agroscience/fields/dto/field/CoordinatesWithFieldId.java index 0c81c8d..9c551ba 100644 --- a/src/main/java/agroscience/fields/dto/field/CoordinatesWithFieldId.java +++ b/src/main/java/agroscience/fields/dto/field/CoordinatesWithFieldId.java @@ -7,6 +7,7 @@ @EqualsAndHashCode(callSuper = true) @Data public class CoordinatesWithFieldId extends CoordinatesDTO { + @JsonProperty("id") private final Long fieldId; @@ -14,4 +15,5 @@ public CoordinatesWithFieldId(Long fieldId, Double longitude, Double latitude) { super(longitude, latitude); this.fieldId = fieldId; } + } diff --git a/src/main/java/agroscience/fields/dto/field/GeomDTO.java b/src/main/java/agroscience/fields/dto/field/GeomDTO.java index 7a12b0a..db3b864 100644 --- a/src/main/java/agroscience/fields/dto/field/GeomDTO.java +++ b/src/main/java/agroscience/fields/dto/field/GeomDTO.java @@ -10,9 +10,11 @@ @Data @AllArgsConstructor public class GeomDTO { + @NotBlank(message = "Must be filled") private String type; @Size(min = 3) @Valid private List coordinates; + } diff --git a/src/main/java/agroscience/fields/dto/field/RequestField.java b/src/main/java/agroscience/fields/dto/field/RequestField.java index c3768c2..88854ff 100644 --- a/src/main/java/agroscience/fields/dto/field/RequestField.java +++ b/src/main/java/agroscience/fields/dto/field/RequestField.java @@ -61,4 +61,5 @@ public String start() { public String end() { return fieldActivityEnd; } + } diff --git a/src/main/java/agroscience/fields/dto/field/ResponseFieldPreview.java b/src/main/java/agroscience/fields/dto/field/ResponseFieldPreview.java index b224af5..dc0cca4 100644 --- a/src/main/java/agroscience/fields/dto/field/ResponseFieldPreview.java +++ b/src/main/java/agroscience/fields/dto/field/ResponseFieldPreview.java @@ -7,6 +7,7 @@ @Data public class ResponseFieldPreview { + @JsonProperty("id") private Long fieldId; @JsonProperty("organizationId") @@ -27,4 +28,5 @@ public class ResponseFieldPreview { @JsonProperty("activityEnd") private String fieldActivityEnd; private ResponseCrop crop; + } diff --git a/src/main/java/agroscience/fields/dto/field/ResponseFieldWithCR.java b/src/main/java/agroscience/fields/dto/field/ResponseFieldWithCR.java index d1d2f2a..4f122c9 100644 --- a/src/main/java/agroscience/fields/dto/field/ResponseFieldWithCR.java +++ b/src/main/java/agroscience/fields/dto/field/ResponseFieldWithCR.java @@ -7,6 +7,7 @@ @Data public class ResponseFieldWithCR { + @JsonProperty("id") private Long fieldId; @JsonProperty("organizationId") @@ -27,4 +28,5 @@ public class ResponseFieldWithCR { @JsonProperty("activityEnd") private String fieldActivityEnd; private ResponseCRForF cropRotation; + } diff --git a/src/main/java/agroscience/fields/dto/field/ResponseFullField.java b/src/main/java/agroscience/fields/dto/field/ResponseFullField.java index 26384a0..332c0d5 100644 --- a/src/main/java/agroscience/fields/dto/field/ResponseFullField.java +++ b/src/main/java/agroscience/fields/dto/field/ResponseFullField.java @@ -10,6 +10,7 @@ @Data public class ResponseFullField { + @JsonProperty("id") private Long fieldId; @JsonProperty("organizationId") @@ -32,4 +33,5 @@ public class ResponseFullField { private ResponseCRForF cropRotation; private ResponseSoilForF soil; private List meteoList; + } diff --git a/src/main/java/agroscience/fields/dto/soil/RequestSoil.java b/src/main/java/agroscience/fields/dto/soil/RequestSoil.java index 4b9d0fc..7b1fb6a 100644 --- a/src/main/java/agroscience/fields/dto/soil/RequestSoil.java +++ b/src/main/java/agroscience/fields/dto/soil/RequestSoil.java @@ -9,6 +9,7 @@ @Data public class RequestSoil { + @NotNull private Long fieldId; @@ -74,4 +75,5 @@ public class RequestSoil { @Size(max = 10, message = "Maximum 10 characters") @JsonAlias("zn") private String soilZn; + } diff --git a/src/main/java/agroscience/fields/dto/soil/RequestSoilWithouFieldId.java b/src/main/java/agroscience/fields/dto/soil/RequestSoilWithouFieldId.java index 9f6e961..b00f4eb 100644 --- a/src/main/java/agroscience/fields/dto/soil/RequestSoilWithouFieldId.java +++ b/src/main/java/agroscience/fields/dto/soil/RequestSoilWithouFieldId.java @@ -8,6 +8,7 @@ @Data public class RequestSoilWithouFieldId { + @Size(max = 10, message = "Maximum 10 characters") @JsonAlias("ph") private String soilPh; @@ -70,4 +71,5 @@ public class RequestSoilWithouFieldId { @Size(max = 10, message = "Maximum 10 characters") @JsonAlias("zn") private String soilZn; + } diff --git a/src/main/java/agroscience/fields/dto/soil/ResponseSoil.java b/src/main/java/agroscience/fields/dto/soil/ResponseSoil.java index 35a0295..4962de3 100644 --- a/src/main/java/agroscience/fields/dto/soil/ResponseSoil.java +++ b/src/main/java/agroscience/fields/dto/soil/ResponseSoil.java @@ -5,6 +5,7 @@ @Data public class ResponseSoil { + @JsonProperty("id") private Long soilId; @@ -39,4 +40,5 @@ public class ResponseSoil { private String soilMn; @JsonProperty("zn") private String soilZn; + } diff --git a/src/main/java/agroscience/fields/dto/soil/ResponseSoilForF.java b/src/main/java/agroscience/fields/dto/soil/ResponseSoilForF.java index 563afda..677d345 100644 --- a/src/main/java/agroscience/fields/dto/soil/ResponseSoilForF.java +++ b/src/main/java/agroscience/fields/dto/soil/ResponseSoilForF.java @@ -5,6 +5,7 @@ @Data public class ResponseSoilForF { + @JsonProperty("id") private Long soilId; @JsonProperty("ph") @@ -37,4 +38,5 @@ public class ResponseSoilForF { private String soilMn; @JsonProperty("zn") private String soilZn; + } diff --git a/src/main/java/agroscience/fields/exceptions/AuthException.java b/src/main/java/agroscience/fields/exceptions/AuthException.java index 39a0b0c..a2d2c01 100644 --- a/src/main/java/agroscience/fields/exceptions/AuthException.java +++ b/src/main/java/agroscience/fields/exceptions/AuthException.java @@ -6,9 +6,11 @@ @Getter @Setter public class AuthException extends RuntimeException { + private final String message; public AuthException(String message) { this.message = message; } + } diff --git a/src/main/java/agroscience/fields/exceptions/DateException.java b/src/main/java/agroscience/fields/exceptions/DateException.java index 042361a..e7f1254 100644 --- a/src/main/java/agroscience/fields/exceptions/DateException.java +++ b/src/main/java/agroscience/fields/exceptions/DateException.java @@ -9,5 +9,7 @@ @EqualsAndHashCode(callSuper = true) @Data public class DateException extends IllegalArgumentException { + private final List> fieldErrors = new ArrayList<>(); + } diff --git a/src/main/java/agroscience/fields/exceptions/DuplicateException.java b/src/main/java/agroscience/fields/exceptions/DuplicateException.java index 479dd31..0387558 100644 --- a/src/main/java/agroscience/fields/exceptions/DuplicateException.java +++ b/src/main/java/agroscience/fields/exceptions/DuplicateException.java @@ -7,6 +7,7 @@ @Setter @Getter public class DuplicateException extends RuntimeException { + private String fieldName; public DuplicateException(String message, String fieldName) { diff --git a/src/main/java/agroscience/fields/exceptions/ExceptionBody.java b/src/main/java/agroscience/fields/exceptions/ExceptionBody.java index 70fd46b..f12e134 100644 --- a/src/main/java/agroscience/fields/exceptions/ExceptionBody.java +++ b/src/main/java/agroscience/fields/exceptions/ExceptionBody.java @@ -7,10 +7,12 @@ @Data @AllArgsConstructor public class ExceptionBody { + private String message; private Map errors; public ExceptionBody(final String message) { this.message = message; } + } diff --git a/src/main/java/agroscience/fields/exceptions/HandleErrorService.java b/src/main/java/agroscience/fields/exceptions/HandleErrorService.java index d6537f3..e98042f 100644 --- a/src/main/java/agroscience/fields/exceptions/HandleErrorService.java +++ b/src/main/java/agroscience/fields/exceptions/HandleErrorService.java @@ -14,6 +14,7 @@ @RestControllerAdvice public class HandleErrorService { + @ExceptionHandler(MethodArgumentNotValidException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) public ExceptionBody handleValidationException(MethodArgumentNotValidException ex) { @@ -77,4 +78,5 @@ public ExceptionBody handleWrongCoordinatesException(WrongCoordinatesException e exceptionBody.setErrors(errorMap); return exceptionBody; } + } diff --git a/src/main/java/agroscience/fields/exceptions/WrongCoordinatesException.java b/src/main/java/agroscience/fields/exceptions/WrongCoordinatesException.java index 567f589..7e76e9b 100644 --- a/src/main/java/agroscience/fields/exceptions/WrongCoordinatesException.java +++ b/src/main/java/agroscience/fields/exceptions/WrongCoordinatesException.java @@ -1,7 +1,9 @@ package agroscience.fields.exceptions; public class WrongCoordinatesException extends RuntimeException { + public WrongCoordinatesException(String message) { super(message); } + } diff --git a/src/main/java/agroscience/fields/exceptions/validation/constraints/LocalDateFormat.java b/src/main/java/agroscience/fields/exceptions/validation/constraints/LocalDateFormat.java index 07316ad..c0415bd 100644 --- a/src/main/java/agroscience/fields/exceptions/validation/constraints/LocalDateFormat.java +++ b/src/main/java/agroscience/fields/exceptions/validation/constraints/LocalDateFormat.java @@ -13,9 +13,11 @@ @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = {LocalDateFormatValidator.class, LocalDateValidatorForFieldType.class}) public @interface LocalDateFormat { + String message() default "Дата введена неверно"; Class[] groups() default {}; Class[] payload() default {}; + } diff --git a/src/main/java/agroscience/fields/exceptions/validation/validators/LocalDateFormatValidator.java b/src/main/java/agroscience/fields/exceptions/validation/validators/LocalDateFormatValidator.java index 66c0c36..c9b0950 100644 --- a/src/main/java/agroscience/fields/exceptions/validation/validators/LocalDateFormatValidator.java +++ b/src/main/java/agroscience/fields/exceptions/validation/validators/LocalDateFormatValidator.java @@ -10,6 +10,7 @@ import org.springframework.data.util.Pair; public class LocalDateFormatValidator implements ConstraintValidator { + @Override public boolean isValid(TimeDTO request, ConstraintValidatorContext context) { @@ -40,4 +41,5 @@ public boolean isValid(TimeDTO request, ConstraintValidatorContext context) { return true; } + } diff --git a/src/main/java/agroscience/fields/exceptions/validation/validators/LocalDateValidatorForFieldType.java b/src/main/java/agroscience/fields/exceptions/validation/validators/LocalDateValidatorForFieldType.java index dada66f..4db346d 100644 --- a/src/main/java/agroscience/fields/exceptions/validation/validators/LocalDateValidatorForFieldType.java +++ b/src/main/java/agroscience/fields/exceptions/validation/validators/LocalDateValidatorForFieldType.java @@ -7,6 +7,7 @@ import java.time.LocalDate; public class LocalDateValidatorForFieldType implements ConstraintValidator { + @Override public boolean isValid(String date, ConstraintValidatorContext constraintValidatorContext) { LocalDate localDate = null; @@ -18,4 +19,5 @@ public boolean isValid(String date, ConstraintValidatorContext constraintValidat } return true; } + } diff --git a/src/main/java/agroscience/fields/mappers/CropMapper.java b/src/main/java/agroscience/fields/mappers/CropMapper.java index 50c0168..4bbd955 100644 --- a/src/main/java/agroscience/fields/mappers/CropMapper.java +++ b/src/main/java/agroscience/fields/mappers/CropMapper.java @@ -7,7 +7,9 @@ @Mapper(componentModel = "spring") public interface CropMapper { + Crop requestCropToCrop(RequestCrop requestCrop); ResponseCrop cropToResponseCrop(Crop crop); + } diff --git a/src/main/java/agroscience/fields/mappers/CropRotationMapper.java b/src/main/java/agroscience/fields/mappers/CropRotationMapper.java index 90aaa13..2cf2d2a 100644 --- a/src/main/java/agroscience/fields/mappers/CropRotationMapper.java +++ b/src/main/java/agroscience/fields/mappers/CropRotationMapper.java @@ -57,4 +57,5 @@ default LocalDate localDateToString(String date) throws ParseException { @Mapping(target = "field", ignore = true) @Mapping(target = "crop", ignore = true) void newCRToCR(@MappingTarget CropRotation cropRotation, CropRotation newCropRotation); + } diff --git a/src/main/java/agroscience/fields/mappers/FieldMapper.java b/src/main/java/agroscience/fields/mappers/FieldMapper.java index 994668d..48af299 100644 --- a/src/main/java/agroscience/fields/mappers/FieldMapper.java +++ b/src/main/java/agroscience/fields/mappers/FieldMapper.java @@ -24,6 +24,7 @@ @Mapper(componentModel = "spring", uses = {FieldMapper.class, CropRotationMapper.class, CropMapper.class, SoilMapper.class}) public interface FieldMapper { + @Mapping(target = "fieldActivityStart", source = "request.fieldActivityStart", qualifiedByName = "stringToLocalDate") @Mapping(target = "fieldActivityEnd", source = "request.fieldActivityEnd", qualifiedByName = "stringToLocalDate") @Mapping(target = "fieldGeom", source = "request.fieldGeom", qualifiedByName = "geom") @@ -105,4 +106,5 @@ default Geometry requestGeomToGeom(GeomDTO request) { throw new WrongCoordinatesException("Points of polygon do not form a closed linestring"); } } + } diff --git a/src/main/java/agroscience/fields/security/AuthoriseService.java b/src/main/java/agroscience/fields/security/AuthoriseService.java index 6eb3355..477347f 100644 --- a/src/main/java/agroscience/fields/security/AuthoriseService.java +++ b/src/main/java/agroscience/fields/security/AuthoriseService.java @@ -10,6 +10,7 @@ @Component @RequiredArgsConstructor public class AuthoriseService { + private final JwtFilter filter; /** @@ -42,4 +43,5 @@ public Long doFilter(HttpServletRequest request, List roles) { } return orgId; } + } diff --git a/src/main/java/agroscience/fields/security/Role.java b/src/main/java/agroscience/fields/security/Role.java index bf9ba3c..d2e8187 100644 --- a/src/main/java/agroscience/fields/security/Role.java +++ b/src/main/java/agroscience/fields/security/Role.java @@ -13,6 +13,7 @@ public enum Role { private final String vale; public static class Builder { + List roles; public Builder() { @@ -37,5 +38,6 @@ public Builder admin() { public List build() { return roles; } + } } diff --git a/src/main/java/agroscience/fields/services/AdminService.java b/src/main/java/agroscience/fields/services/AdminService.java index 3bf11a6..74c3493 100644 --- a/src/main/java/agroscience/fields/services/AdminService.java +++ b/src/main/java/agroscience/fields/services/AdminService.java @@ -12,6 +12,7 @@ @Service @RequiredArgsConstructor public class AdminService { + private final CropsRepository cropsRepository; private boolean validateName(String name) { @@ -55,4 +56,5 @@ public Crop getCrop(Long cropId) { return cropsRepository.findById(cropId) .orElseThrow(() -> new EntityNotFoundException("Field with id " + cropId + " not found")); } + } diff --git a/src/main/java/agroscience/fields/services/CropRotationsService.java b/src/main/java/agroscience/fields/services/CropRotationsService.java index 2b8f869..5913a35 100644 --- a/src/main/java/agroscience/fields/services/CropRotationsService.java +++ b/src/main/java/agroscience/fields/services/CropRotationsService.java @@ -24,6 +24,7 @@ @RequiredArgsConstructor @Slf4j public class CropRotationsService { + private final CropRotationRepository crRepository; private final CropsRepository cropsRepository; private final CropRotationMapper crMapper; @@ -101,9 +102,9 @@ public ResponseCRWithField updateCR(Long orgId, Long id, CropRotation newCropRot crMapper.newCRToCR(cropRotation, newCropRotation); cropRotation.setCrop(newCrop); return crMapper.responseCRWithField( - new FandCRandCImpl(cropRotation.getField(), - crRepository.save(cropRotation), - newCrop) + new FandCRandCImpl(cropRotation.getField(), + crRepository.save(cropRotation), + newCrop) ); } @@ -127,4 +128,5 @@ public void deleteCR(Long id, Long orgId) { crRepository.delete(cropRotation); } + } diff --git a/src/main/java/agroscience/fields/services/CropsService.java b/src/main/java/agroscience/fields/services/CropsService.java index 5deccb5..410c617 100644 --- a/src/main/java/agroscience/fields/services/CropsService.java +++ b/src/main/java/agroscience/fields/services/CropsService.java @@ -11,6 +11,7 @@ @Service @RequiredArgsConstructor public class CropsService { + private final CropsRepository cropsRepository; public List getCrop(String name, int page, int size) { @@ -18,4 +19,5 @@ public List getCrop(String name, int page, int size) { name, PageRequest.of(page, size, Sort.by(Sort.Direction.ASC, "cropName")) ); } + } \ No newline at end of file diff --git a/src/main/java/agroscience/fields/services/FieldService.java b/src/main/java/agroscience/fields/services/FieldService.java index b50bafc..960580d 100644 --- a/src/main/java/agroscience/fields/services/FieldService.java +++ b/src/main/java/agroscience/fields/services/FieldService.java @@ -30,6 +30,7 @@ @Service @RequiredArgsConstructor public class FieldService { + private final FieldRepository fieldRepository; private final FieldMapper fieldMapper; private final JbdcDao jbdcFieldDao; @@ -58,7 +59,8 @@ public ResponseFullField getFullField(Long id, Long orgId) { "http://" + meteoProperties.getHost() + ":" + meteoProperties.getPort() + "/api/v1/meteo/" + id, HttpMethod.GET, null, - new ParameterizedTypeReference<>() {} + new ParameterizedTypeReference<>() { + } ); if (response.getStatusCode().is2xxSuccessful()) { @@ -140,4 +142,5 @@ public List getFieldsForPreview(Long orgId, Pageable pageab public List getAllCoordinates() { return jbdcFieldDao.getAllCoordinates(); } + } diff --git a/src/main/java/agroscience/fields/services/SoilService.java b/src/main/java/agroscience/fields/services/SoilService.java index ae5ef5c..2b71ef3 100644 --- a/src/main/java/agroscience/fields/services/SoilService.java +++ b/src/main/java/agroscience/fields/services/SoilService.java @@ -14,6 +14,7 @@ @Service @RequiredArgsConstructor public class SoilService { + private final SoilRepository soilRepository; private final FieldRepository fieldRepository; private final SoilMapper soilMapper; @@ -58,4 +59,5 @@ public Soil updateSoil(Long orgId, Long soilId, Soil newSoil) { soilMapper.newSoilToSoil(soil, newSoil); return soilRepository.save(soil); } + } diff --git a/src/main/java/agroscience/fields/utilities/LocalDateConverting.java b/src/main/java/agroscience/fields/utilities/LocalDateConverting.java index e3fb11c..0be1412 100644 --- a/src/main/java/agroscience/fields/utilities/LocalDateConverting.java +++ b/src/main/java/agroscience/fields/utilities/LocalDateConverting.java @@ -7,6 +7,7 @@ import java.time.format.DateTimeFormatter; public class LocalDateConverting { + static String stringFormat = "dd-MM-yyyy"; public static LocalDate stringToLocalDate(String date) throws ParseException { @@ -21,4 +22,5 @@ public static LocalDate stringToLocalDate(String date) throws ParseException { public static String localDateToString(LocalDate localDate) { return localDate.format(DateTimeFormatter.ofPattern(stringFormat)); } + } diff --git a/src/test/java/agroscience/fields/AdminServiceTest.java b/src/test/java/agroscience/fields/AdminServiceTest.java index 2db5d9a..4eab511 100644 --- a/src/test/java/agroscience/fields/AdminServiceTest.java +++ b/src/test/java/agroscience/fields/AdminServiceTest.java @@ -27,6 +27,7 @@ public class AdminServiceTest extends AbstractTest { + @Autowired private FieldRepository fieldRepository; @Autowired @@ -98,4 +99,5 @@ public void deleteCropTest() { assertFalse(CRRepository.existsById(CRId)); } + } diff --git a/src/test/java/agroscience/fields/CropRotationsServiceTest.java b/src/test/java/agroscience/fields/CropRotationsServiceTest.java index 7542c8a..a4ddc8c 100644 --- a/src/test/java/agroscience/fields/CropRotationsServiceTest.java +++ b/src/test/java/agroscience/fields/CropRotationsServiceTest.java @@ -29,6 +29,7 @@ public class CropRotationsServiceTest extends AbstractTest { + @Autowired private FieldRepository fieldRepository; @Autowired @@ -128,4 +129,5 @@ public void updateCRTest() { assertEquals(CRWithField.getCropRotationId(), CRId); assertNotEquals(cropId, CRWithField.getCrop().getCropId()); } + } diff --git a/src/test/java/agroscience/fields/FieldServiceTest.java b/src/test/java/agroscience/fields/FieldServiceTest.java index 93cc12b..89ffd6d 100644 --- a/src/test/java/agroscience/fields/FieldServiceTest.java +++ b/src/test/java/agroscience/fields/FieldServiceTest.java @@ -41,6 +41,7 @@ public class FieldServiceTest extends AbstractTest { + @Autowired private FieldService fieldService; @Autowired diff --git a/src/test/java/agroscience/fields/PostgreTestContainerConfig.java b/src/test/java/agroscience/fields/PostgreTestContainerConfig.java index 9c91607..7ba5b7f 100644 --- a/src/test/java/agroscience/fields/PostgreTestContainerConfig.java +++ b/src/test/java/agroscience/fields/PostgreTestContainerConfig.java @@ -12,6 +12,7 @@ @Slf4j public class PostgreTestContainerConfig { + private static volatile PostgreSQLContainer postgreSQLContainer = null; private static PostgreSQLContainer getPostgreSQLContainer() { @@ -32,6 +33,7 @@ private static PostgreSQLContainer getPostgreSQLContainer() { @Component("PostgresInitializer") public static class Initializer implements ApplicationContextInitializer { + @Override public void initialize(ConfigurableApplicationContext configurableApplicationContext) { var postgreSQLContainer = getPostgreSQLContainer(); @@ -41,5 +43,7 @@ public void initialize(ConfigurableApplicationContext configurableApplicationCon "POSTGRESQL_PASSWORD: " + postgreSQLContainer.getPassword() ).applyTo(configurableApplicationContext.getEnvironment()); } + } + } diff --git a/src/test/java/agroscience/fields/SoilServiceTest.java b/src/test/java/agroscience/fields/SoilServiceTest.java index e85a9ad..4f90aa1 100644 --- a/src/test/java/agroscience/fields/SoilServiceTest.java +++ b/src/test/java/agroscience/fields/SoilServiceTest.java @@ -29,6 +29,7 @@ public class SoilServiceTest extends AbstractTest { + @Autowired private FieldRepository fieldRepository; @Autowired