Skip to content

Commit 344ec8f

Browse files
[SELC-5924] feat: Fixed contract template and version into ProductsMapper
1 parent 9938520 commit 344ec8f

File tree

8 files changed

+190
-184
lines changed

8 files changed

+190
-184
lines changed

src/main/java/it/pagopa/selfcare/external_api/mapper/ProductsMapper.java

+46-44
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,60 @@
22

33
import it.pagopa.selfcare.external_api.model.product.ProductResource;
44
import it.pagopa.selfcare.onboarding.common.PartyRole;
5-
import it.pagopa.selfcare.product.entity.ContractTemplate;
65
import it.pagopa.selfcare.product.entity.Product;
76
import it.pagopa.selfcare.product.entity.ProductRoleInfo;
8-
import org.mapstruct.Mapper;
9-
import org.mapstruct.Mapping;
10-
import org.mapstruct.Named;
11-
127
import java.util.EnumMap;
138
import java.util.Map;
14-
import java.util.Objects;
159
import java.util.Optional;
10+
import org.mapstruct.Mapper;
11+
import org.mapstruct.Mapping;
12+
import org.mapstruct.Named;
1613

1714
@Mapper(componentModel = "spring")
1815
public interface ProductsMapper {
1916

20-
@Mapping(target = "roleMappings", expression = "java(toRoleMappings(model.getRoleMappings(institutionType)))")
21-
@Mapping(target = "contractTemplatePath", expression = "java(toContractTemplatePath(model,institutionType))")
22-
@Mapping(target = "contractTemplateVersion", expression = "java(toContractTemplateVersion(model,institutionType))")
23-
ProductResource toResource(Product model, String institutionType);
24-
25-
@Named("toRoleMappings")
26-
default EnumMap<PartyRole, ProductRoleInfo> toRoleMappings(Map<PartyRole, ProductRoleInfo> roleMappings){
27-
EnumMap<PartyRole, ProductRoleInfo> result;
28-
if(roleMappings != null){
29-
result = new EnumMap<>(PartyRole.class);
30-
31-
roleMappings.forEach((key, value) -> {
32-
ProductRoleInfo productRoleInfo = new ProductRoleInfo();
33-
productRoleInfo.setRoles(roleMappings.get(key).getRoles());
34-
productRoleInfo.setMultiroleAllowed(roleMappings.get(key).isMultiroleAllowed());
35-
result.put(key, productRoleInfo);
36-
});
37-
}
38-
else{
39-
result = null;
40-
}
41-
return result;
42-
}
43-
44-
@Named("toContractTemplatePath")
45-
default String toContractTemplatePath(Product model, String institutionType){
46-
if(Objects.isNull(institutionType)) return null;
47-
return Optional.ofNullable(model.getInstitutionContractTemplate(institutionType))
48-
.map(ContractTemplate::getContractTemplatePath)
49-
.orElse(null);
50-
}
51-
52-
@Named("toContractTemplateVersion")
53-
default String toContractTemplateVersion(Product model, String institutionType){
54-
if(Objects.isNull(institutionType)) return null;
55-
return Optional.ofNullable(model.getInstitutionContractTemplate(institutionType))
56-
.map(ContractTemplate::getContractTemplateVersion)
57-
.orElse(null);
17+
@Mapping(
18+
target = "roleMappings",
19+
expression = "java(toRoleMappings(model.getRoleMappings(institutionType)))")
20+
@Mapping(
21+
target = "contractTemplatePath",
22+
expression = "java(toContractTemplatePath(model,institutionType))")
23+
@Mapping(
24+
target = "contractTemplateVersion",
25+
expression = "java(toContractTemplateVersion(model,institutionType))")
26+
ProductResource toResource(Product model, String institutionType);
27+
28+
@Named("toRoleMappings")
29+
default EnumMap<PartyRole, ProductRoleInfo> toRoleMappings(
30+
Map<PartyRole, ProductRoleInfo> roleMappings) {
31+
EnumMap<PartyRole, ProductRoleInfo> result;
32+
if (roleMappings != null) {
33+
result = new EnumMap<>(PartyRole.class);
34+
35+
roleMappings.forEach(
36+
(key, value) -> {
37+
ProductRoleInfo productRoleInfo = new ProductRoleInfo();
38+
productRoleInfo.setRoles(roleMappings.get(key).getRoles());
39+
productRoleInfo.setMultiroleAllowed(roleMappings.get(key).isMultiroleAllowed());
40+
result.put(key, productRoleInfo);
41+
});
42+
} else {
43+
result = null;
5844
}
45+
return result;
46+
}
47+
48+
@Named("toContractTemplatePath")
49+
default String toContractTemplatePath(Product model, String institutionType) {
50+
return Optional.ofNullable(
51+
model.getInstitutionContractTemplate(institutionType).getContractTemplatePath())
52+
.orElse(null);
53+
}
54+
55+
@Named("toContractTemplateVersion")
56+
default String toContractTemplateVersion(Product model, String institutionType) {
57+
return Optional.ofNullable(
58+
model.getInstitutionContractTemplate(institutionType).getContractTemplateVersion())
59+
.orElse(null);
60+
}
5961
}

src/main/java/it/pagopa/selfcare/external_api/model/product/ProductResource.java

+44-45
Original file line numberDiff line numberDiff line change
@@ -2,68 +2,67 @@
22

33
import io.swagger.annotations.ApiModelProperty;
44
import it.pagopa.selfcare.onboarding.common.PartyRole;
5-
import lombok.Data;
6-
7-
import javax.validation.constraints.NotBlank;
8-
import javax.validation.constraints.NotEmpty;
95
import java.time.Instant;
106
import java.util.EnumMap;
7+
import javax.validation.constraints.NotBlank;
8+
import javax.validation.constraints.NotEmpty;
9+
import lombok.Data;
1110

1211
@Data
1312
public class ProductResource {
14-
@ApiModelProperty(value = "${swagger.external_api.products.model.id}", required = true)
15-
@NotBlank
16-
private String id;
17-
18-
@ApiModelProperty(value = "${swagger.external_api.products.model.title}", required = true)
19-
@NotBlank
20-
private String title;
21-
22-
@ApiModelProperty(value = "${swagger.external_api.products.model.contractTemplatePath}", required = true)
23-
@NotBlank
24-
private String contractTemplatePath;
13+
@ApiModelProperty(value = "${swagger.external_api.products.model.id}", required = true)
14+
@NotBlank
15+
private String id;
2516

26-
@ApiModelProperty(value = "${swagger.external_api.products.model.contractTemplateUpdatedAt}")
27-
private Instant contractTemplateUpdatedAt;
17+
@ApiModelProperty(value = "${swagger.external_api.products.model.title}", required = true)
18+
@NotBlank
19+
private String title;
2820

29-
@ApiModelProperty(value = "${swagger.external_api.products.model.contractTemplateVersion}", required = true)
30-
@NotBlank
31-
private String contractTemplateVersion;
21+
@ApiModelProperty(
22+
value = "${swagger.external_api.products.model.contractTemplatePath}",
23+
required = true)
24+
@NotBlank
25+
private String contractTemplatePath;
3226

33-
@ApiModelProperty(value = "${swagger.external_api.products.model.createdAt}")
34-
private Instant createdAt;
27+
@ApiModelProperty(
28+
value = "${swagger.external_api.products.model.contractTemplateVersion}",
29+
required = true)
30+
@NotBlank
31+
private String contractTemplateVersion;
3532

36-
@ApiModelProperty(value = "${swagger.external_api.products.model.description}", required = true)
37-
@NotBlank
38-
private String description;
33+
@ApiModelProperty(value = "${swagger.external_api.products.model.createdAt}")
34+
private Instant createdAt;
3935

40-
@ApiModelProperty("${swagger.external_api.products.model.urlPublic}")
41-
private String urlPublic;
36+
@ApiModelProperty(value = "${swagger.external_api.products.model.description}", required = true)
37+
@NotBlank
38+
private String description;
4239

43-
@ApiModelProperty(value = "${swagger.external_api.products.model.urlBO}", required = true)
44-
@NotBlank
45-
private String urlBO;
40+
@ApiModelProperty("${swagger.external_api.products.model.urlPublic}")
41+
private String urlPublic;
4642

47-
@ApiModelProperty(value = "${swagger.external_api.products.model.depictImageUrl}")
48-
private String depictImageUrl;
43+
@ApiModelProperty(value = "${swagger.external_api.products.model.urlBO}", required = true)
44+
@NotBlank
45+
private String urlBO;
4946

50-
@ApiModelProperty(value = "${swagger.external_api.products.model.identityTokenAudience}")
51-
private String identityTokenAudience;
47+
@ApiModelProperty(value = "${swagger.external_api.products.model.depictImageUrl}")
48+
private String depictImageUrl;
5249

53-
@ApiModelProperty(value = "${swagger.external_api.products.model.logo}")
54-
private String logo;
50+
@ApiModelProperty(value = "${swagger.external_api.products.model.identityTokenAudience}")
51+
private String identityTokenAudience;
5552

56-
@ApiModelProperty(value = "${swagger.external_api.products.model.logoBgColor}")
57-
private String logoBgColor;
53+
@ApiModelProperty(value = "${swagger.external_api.products.model.logo}")
54+
private String logo;
5855

59-
@ApiModelProperty(value = "${swagger.external_api.products.model.parentId}")
60-
private String parentId;
56+
@ApiModelProperty(value = "${swagger.external_api.products.model.logoBgColor}")
57+
private String logoBgColor;
6158

62-
@ApiModelProperty(value = "${swagger.external_api.products.model.roleMappings}", required = true)
63-
@NotEmpty
64-
private EnumMap<PartyRole, it.pagopa.selfcare.product.entity.ProductRoleInfo> roleMappings;
59+
@ApiModelProperty(value = "${swagger.external_api.products.model.parentId}")
60+
private String parentId;
6561

66-
@ApiModelProperty(value = "${swagger.external_api.products.model.roleManagementURL}")
67-
private String roleManagementURL;
62+
@ApiModelProperty(value = "${swagger.external_api.products.model.roleMappings}", required = true)
63+
@NotEmpty
64+
private EnumMap<PartyRole, it.pagopa.selfcare.product.entity.ProductRoleInfo> roleMappings;
6865

66+
@ApiModelProperty(value = "${swagger.external_api.products.model.roleManagementURL}")
67+
private String roleManagementURL;
6968
}

src/main/resources/swagger/api-docs.json

-5
Original file line numberDiff line numberDiff line change
@@ -2248,11 +2248,6 @@
22482248
"type" : "string",
22492249
"description" : "The path of contract"
22502250
},
2251-
"contractTemplateUpdatedAt" : {
2252-
"type" : "string",
2253-
"description" : "Date the contract was postponed",
2254-
"format" : "date-time"
2255-
},
22562251
"contractTemplateVersion" : {
22572252
"type" : "string",
22582253
"description" : "Version of the contract"

src/test/java/it/pagopa/selfcare/external_api/controller/InstitutionControllerV2Test.java

+6
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ void getInstitutionUserProductsWith2Elements() throws Exception {
211211
byte[] productStream = Files.readAllBytes(inputResource.getFile().toPath());
212212
List<ProductResource> products = objectMapper.readValue(productStream, new TypeReference<>() {});
213213

214+
products.forEach(
215+
productResource -> {
216+
productResource.setContractTemplatePath("contractTemplatePath");
217+
productResource.setContractTemplateVersion("1.0.0");
218+
});
219+
214220
ClassPathResource outputResource = new ClassPathResource("expectations/ProductResources.json");
215221
String expectedResource = StringUtils.deleteWhitespace(new String(Files.readAllBytes(outputResource.getFile().toPath())));
216222

0 commit comments

Comments
 (0)