Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: P4ADEV-1764 api category taxonomy #14

Merged
merged 21 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0e3a953
updated entity
oleksiybozhykntt Dec 19, 2024
165654b
updated entity
oleksiybozhykntt Dec 20, 2024
aeff788
updated code
oleksiybozhykntt Jan 13, 2025
27cadab
Merge branch 'develop' of https://github.com/pagopa/p4pa-organization…
oleksiybozhykntt Jan 13, 2025
e86f939
updated code
oleksiybozhykntt Jan 13, 2025
e39f2d5
updated code
oleksiybozhykntt Jan 13, 2025
b7f1f51
updated code
oleksiybozhykntt Jan 13, 2025
6deec7c
updated code
oleksiybozhykntt Jan 14, 2025
fff0a88
Update src/main/java/it/gov/pagopa/pu/organization/repository/Taxonom…
oleksiybozhykntt Jan 14, 2025
e5f1ac7
Update src/main/java/it/gov/pagopa/pu/organization/model/DistinctColl…
oleksiybozhykntt Jan 14, 2025
68f5082
Update src/main/java/it/gov/pagopa/pu/organization/model/DistinctColl…
oleksiybozhykntt Jan 14, 2025
92607d1
Update src/main/java/it/gov/pagopa/pu/organization/model/DistinctMacr…
oleksiybozhykntt Jan 14, 2025
7e9f0a0
Update src/main/java/it/gov/pagopa/pu/organization/model/DistinctOrga…
oleksiybozhykntt Jan 14, 2025
c5c5252
Update src/main/java/it/gov/pagopa/pu/organization/model/DistinctServ…
oleksiybozhykntt Jan 14, 2025
06d4a12
Update src/main/java/it/gov/pagopa/pu/organization/model/DistinctTaxo…
oleksiybozhykntt Jan 14, 2025
ab8c91c
updated code
oleksiybozhykntt Jan 14, 2025
4368864
Update src/main/java/it/gov/pagopa/pu/organization/model/taxonomy/Tax…
oleksiybozhykntt Jan 14, 2025
b5bc8ff
updated code
oleksiybozhykntt Jan 14, 2025
b3701e6
updated code
oleksiybozhykntt Jan 14, 2025
73cc7b1
updated code
oleksiybozhykntt Jan 14, 2025
c5695ee
updated code
oleksiybozhykntt Jan 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
603 changes: 603 additions & 0 deletions openapi/generated.openapi.json

Large diffs are not rendered by default.

antonioT90 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package it.gov.pagopa.pu.organization.controller;

import it.gov.pagopa.pu.organization.model.DistinctOrganizationTypeDTO;
import it.gov.pagopa.pu.organization.service.TaxonomyService;
import java.util.List;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TaxonomyController {

TaxonomyService taxonomyService;

public TaxonomyController(TaxonomyService taxonomyService){
this.taxonomyService = taxonomyService;
}

@GetMapping("/taxonomy/custom/getDistinctOrganizationType")
antonioT90 marked this conversation as resolved.
Show resolved Hide resolved
public ResponseEntity<List<DistinctOrganizationTypeDTO>> getDistinctOrgType(Sort sort){
return new ResponseEntity<>(taxonomyService.getDistinctOrganizationType(sort),
HttpStatusCode.valueOf(200));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package it.gov.pagopa.pu.organization.dto;

public interface DistinctCollectionReasonDTO {
String getOrganizationType();
String getOrganizationTypeDescription();
String getMacroAreaCode();
String getMacroAreaName();
String getServiceTypeCode();
String getServiceType();
String getServiceTypeDescription();
String getCollectionReason();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package it.gov.pagopa.pu.organization.dto;

public interface DistinctMacroAreaDTO {
String getOrganizationType();
String getOrganizationTypeDescription();
String getMacroAreaCode();
String getMacroAreaName();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package it.gov.pagopa.pu.organization.dto;

public interface DistinctServiceTypeDTO {
String getOrganizationType();
String getOrganizationTypeDescription();
String getMacroAreaCode();
String getMacroAreaName();
String getServiceTypeCode();
String getServiceType();
String getServiceTypeDescription();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package it.gov.pagopa.pu.organization.dto;

public interface DistinctTaxonomyCodeDTO {
String getOrganizationType();
String getOrganizationTypeDescription();
String getMacroAreaCode();
String getMacroAreaName();
String getServiceTypeCode();
String getServiceType();
String getServiceTypeDescription();
String getCollectionReason();
String getTaxonomyCode();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package it.gov.pagopa.pu.organization.model;

public interface DistinctOrganizationTypeDTO {
antonioT90 marked this conversation as resolved.
Show resolved Hide resolved
String getOrganizationType();
String getOrganizationTypeDescription();

}
43 changes: 43 additions & 0 deletions src/main/java/it/gov/pagopa/pu/organization/model/Taxonomy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package it.gov.pagopa.pu.organization.model;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.SequenceGenerator;
import jakarta.persistence.Table;
import java.io.Serializable;
import java.sql.Timestamp;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "taxonomy")
@AllArgsConstructor
@NoArgsConstructor
@Data
public class Taxonomy implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "taxonomy_generator")
@SequenceGenerator(name = "taxonomy_generator", sequenceName = "taxonomy_seq", allocationSize = 1)
private Long taxonomyId;
private Long version;
private String organizationType;
private String organizationTypeDescription;
private String macroAreaCode;
private String macroAreaName;
private String macroAreaDescription;
private String serviceTypeCode;
private String serviceType;
private String serviceTypeDescription;
private String collectionReason;
private Timestamp startDateValidity;
private Timestamp endDateOfValidity;
private String taxonomyCode;
private Timestamp creationDate;
private Timestamp lastModifiedDate;
private Long versionMyPay;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package it.gov.pagopa.pu.organization.repository;

import it.gov.pagopa.pu.organization.model.DistinctOrganizationTypeDTO;
import it.gov.pagopa.pu.organization.model.Taxonomy;
import java.util.List;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.data.rest.core.annotation.RestResource;

@RepositoryRestResource(collectionResourceRel = "taxonomy", path = "taxonomy")
oleksiybozhykntt marked this conversation as resolved.
Show resolved Hide resolved
public interface TaxonomyRepository extends JpaRepository<Taxonomy, Long> {

//@Query("select distinct t.organizationType as organizationType, t.organizationTypeDescription as organizationTypeDescription from Taxonomy t")
@RestResource(exported = false)
@Query(value = "select distinct t.organizationType as organizationType, t.organizationTypeDescription as organizationTypeDescription from Taxonomy t")
List<DistinctOrganizationTypeDTO> findDistinctOrganizationTypes(Sort sort);

List<Taxonomy> findDistinctMacroAreaCodeByOrganizationType(String organizationType);

List<Taxonomy> findDistinctServiceTypeCodeByOrganizationTypeAndMacroAreaCode(String organizationType,String macroAreaCode);

List<Taxonomy> findDistinctCollectionReasonByOrganizationTypeAndMacroAreaCodeAndServiceTypeCode(String organizationType,String macroAreaCode,String serviceTypeCode);

List<Taxonomy> findDistinctTaxonomyCodeByOrganizationTypeAndMacroAreaCodeAndServiceTypeCodeAndCollectionReason(String organizationType,String macroAreaName,String serviceType,String collectionReason);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package it.gov.pagopa.pu.organization.service;

import it.gov.pagopa.pu.organization.model.DistinctOrganizationTypeDTO;
import java.util.List;
import org.springframework.data.domain.Sort;

public interface TaxonomyService {
List<DistinctOrganizationTypeDTO> getDistinctOrganizationType(Sort sort);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package it.gov.pagopa.pu.organization.service;

import it.gov.pagopa.pu.organization.model.DistinctOrganizationTypeDTO;
import it.gov.pagopa.pu.organization.repository.TaxonomyRepository;
import java.util.List;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

@Service
public class TaxonomyServiceImpl implements TaxonomyService{
private TaxonomyRepository taxonomyRepository;
public TaxonomyServiceImpl(TaxonomyRepository taxonomyRepository){
this.taxonomyRepository = taxonomyRepository;
}

public List<DistinctOrganizationTypeDTO> getDistinctOrganizationType(Sort sort){
return taxonomyRepository.findDistinctOrganizationTypes(sort);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package it.gov.pagopa.pu.organization.controller;

import it.gov.pagopa.pu.organization.model.DistinctOrganizationTypeDTO;
import it.gov.pagopa.pu.organization.service.TaxonomyService;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.http.ResponseEntity;
import org.springframework.test.web.servlet.MockMvc;

@ExtendWith(MockitoExtension.class)
class TaxonomyControllerTest {

@Autowired
private MockMvc mockMvc;

@Mock
private TaxonomyService taxonomyServiceMock;

@InjectMocks
private TaxonomyController taxonomyController;

@Test
void getDistinctOrgType() {
List<DistinctOrganizationTypeDTO> orgTypes = new ArrayList<>();
orgTypes.add(new DistinctOrganizationTypeDTO() {
@Override
public String getOrganizationType() {
return "test";
}

@Override
public String getOrganizationTypeDescription() {
return "test";
}
});

Mockito.when(taxonomyServiceMock.getDistinctOrganizationType(Sort.by(Sort.Order.asc("organizationType")))).thenReturn(orgTypes);

ResponseEntity<List<DistinctOrganizationTypeDTO>> orgTypesResult = taxonomyController.getDistinctOrgType(Sort.by(Sort.Order.asc("organizationType")));

Assertions.assertEquals(200,orgTypesResult.getStatusCode().value());
Assertions.assertEquals(orgTypes,orgTypesResult.getBody());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package it.gov.pagopa.pu.organization.exception;

import it.gov.pagopa.pu.organization.controller.BrokerController;
import it.gov.pagopa.pu.organization.controller.TaxonomyController;
import it.gov.pagopa.pu.organization.service.broker.BrokerService;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
Expand All @@ -22,6 +23,9 @@ class ControllerExceptionHandlerTest {
@MockitoBean
private BrokerService brokerServiceMock;

@MockitoBean
private TaxonomyController taxonomyController;

@Autowired
private MockMvc mockMvc;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package it.gov.pagopa.pu.organization.service;

import static org.junit.jupiter.api.Assertions.*;

import it.gov.pagopa.pu.organization.model.DistinctOrganizationTypeDTO;
import it.gov.pagopa.pu.organization.repository.TaxonomyRepository;
import java.util.Arrays;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.data.domain.Sort;

@ExtendWith(MockitoExtension.class)
class TaxonomyServiceTest {
@Mock
private TaxonomyRepository taxonomyRepository;

@InjectMocks
private TaxonomyServiceImpl taxonomyService;

@Test
void testGetDistinctOrganizationType() {
// Arrange
Sort sort = Sort.by("name");
DistinctOrganizationTypeDTO dto1 = new DistinctOrganizationTypeDTO() {
@Override
public String getOrganizationType () {
return null;
}

@Override
public String getOrganizationTypeDescription () {
return null;
}
};
DistinctOrganizationTypeDTO dto2 = new DistinctOrganizationTypeDTO() {
@Override
public String getOrganizationType () {
return null;
}

@Override
public String getOrganizationTypeDescription () {
return null;
}
};
List<DistinctOrganizationTypeDTO> expectedList = Arrays.asList(dto1, dto2);
Mockito.when(taxonomyRepository.findDistinctOrganizationTypes(sort)).thenReturn(expectedList);

// Act
List<DistinctOrganizationTypeDTO> result = taxonomyService.getDistinctOrganizationType(sort);

// Assert
assertEquals(expectedList, result);
Mockito.verify(taxonomyRepository, Mockito.times(1)).findDistinctOrganizationTypes(sort);
}
}
Loading