Skip to content

Commit

Permalink
[SELC-5924] feat: Fixed contract template and version into ProductsMa…
Browse files Browse the repository at this point in the history
…pper
  • Loading branch information
giampieroferrara authored Nov 6, 2024
1 parent 9938520 commit 344ec8f
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 184 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,60 @@

import it.pagopa.selfcare.external_api.model.product.ProductResource;
import it.pagopa.selfcare.onboarding.common.PartyRole;
import it.pagopa.selfcare.product.entity.ContractTemplate;
import it.pagopa.selfcare.product.entity.Product;
import it.pagopa.selfcare.product.entity.ProductRoleInfo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;

import java.util.EnumMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;

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

@Mapping(target = "roleMappings", expression = "java(toRoleMappings(model.getRoleMappings(institutionType)))")
@Mapping(target = "contractTemplatePath", expression = "java(toContractTemplatePath(model,institutionType))")
@Mapping(target = "contractTemplateVersion", expression = "java(toContractTemplateVersion(model,institutionType))")
ProductResource toResource(Product model, String institutionType);

@Named("toRoleMappings")
default EnumMap<PartyRole, ProductRoleInfo> toRoleMappings(Map<PartyRole, ProductRoleInfo> roleMappings){
EnumMap<PartyRole, ProductRoleInfo> result;
if(roleMappings != null){
result = new EnumMap<>(PartyRole.class);

roleMappings.forEach((key, value) -> {
ProductRoleInfo productRoleInfo = new ProductRoleInfo();
productRoleInfo.setRoles(roleMappings.get(key).getRoles());
productRoleInfo.setMultiroleAllowed(roleMappings.get(key).isMultiroleAllowed());
result.put(key, productRoleInfo);
});
}
else{
result = null;
}
return result;
}

@Named("toContractTemplatePath")
default String toContractTemplatePath(Product model, String institutionType){
if(Objects.isNull(institutionType)) return null;
return Optional.ofNullable(model.getInstitutionContractTemplate(institutionType))
.map(ContractTemplate::getContractTemplatePath)
.orElse(null);
}

@Named("toContractTemplateVersion")
default String toContractTemplateVersion(Product model, String institutionType){
if(Objects.isNull(institutionType)) return null;
return Optional.ofNullable(model.getInstitutionContractTemplate(institutionType))
.map(ContractTemplate::getContractTemplateVersion)
.orElse(null);
@Mapping(
target = "roleMappings",
expression = "java(toRoleMappings(model.getRoleMappings(institutionType)))")
@Mapping(
target = "contractTemplatePath",
expression = "java(toContractTemplatePath(model,institutionType))")
@Mapping(
target = "contractTemplateVersion",
expression = "java(toContractTemplateVersion(model,institutionType))")
ProductResource toResource(Product model, String institutionType);

@Named("toRoleMappings")
default EnumMap<PartyRole, ProductRoleInfo> toRoleMappings(
Map<PartyRole, ProductRoleInfo> roleMappings) {
EnumMap<PartyRole, ProductRoleInfo> result;
if (roleMappings != null) {
result = new EnumMap<>(PartyRole.class);

roleMappings.forEach(
(key, value) -> {
ProductRoleInfo productRoleInfo = new ProductRoleInfo();
productRoleInfo.setRoles(roleMappings.get(key).getRoles());
productRoleInfo.setMultiroleAllowed(roleMappings.get(key).isMultiroleAllowed());
result.put(key, productRoleInfo);
});
} else {
result = null;
}
return result;
}

@Named("toContractTemplatePath")
default String toContractTemplatePath(Product model, String institutionType) {
return Optional.ofNullable(
model.getInstitutionContractTemplate(institutionType).getContractTemplatePath())
.orElse(null);
}

@Named("toContractTemplateVersion")
default String toContractTemplateVersion(Product model, String institutionType) {
return Optional.ofNullable(
model.getInstitutionContractTemplate(institutionType).getContractTemplateVersion())
.orElse(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,67 @@

import io.swagger.annotations.ApiModelProperty;
import it.pagopa.selfcare.onboarding.common.PartyRole;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import java.time.Instant;
import java.util.EnumMap;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import lombok.Data;

@Data
public class ProductResource {
@ApiModelProperty(value = "${swagger.external_api.products.model.id}", required = true)
@NotBlank
private String id;

@ApiModelProperty(value = "${swagger.external_api.products.model.title}", required = true)
@NotBlank
private String title;

@ApiModelProperty(value = "${swagger.external_api.products.model.contractTemplatePath}", required = true)
@NotBlank
private String contractTemplatePath;
@ApiModelProperty(value = "${swagger.external_api.products.model.id}", required = true)
@NotBlank
private String id;

@ApiModelProperty(value = "${swagger.external_api.products.model.contractTemplateUpdatedAt}")
private Instant contractTemplateUpdatedAt;
@ApiModelProperty(value = "${swagger.external_api.products.model.title}", required = true)
@NotBlank
private String title;

@ApiModelProperty(value = "${swagger.external_api.products.model.contractTemplateVersion}", required = true)
@NotBlank
private String contractTemplateVersion;
@ApiModelProperty(
value = "${swagger.external_api.products.model.contractTemplatePath}",
required = true)
@NotBlank
private String contractTemplatePath;

@ApiModelProperty(value = "${swagger.external_api.products.model.createdAt}")
private Instant createdAt;
@ApiModelProperty(
value = "${swagger.external_api.products.model.contractTemplateVersion}",
required = true)
@NotBlank
private String contractTemplateVersion;

@ApiModelProperty(value = "${swagger.external_api.products.model.description}", required = true)
@NotBlank
private String description;
@ApiModelProperty(value = "${swagger.external_api.products.model.createdAt}")
private Instant createdAt;

@ApiModelProperty("${swagger.external_api.products.model.urlPublic}")
private String urlPublic;
@ApiModelProperty(value = "${swagger.external_api.products.model.description}", required = true)
@NotBlank
private String description;

@ApiModelProperty(value = "${swagger.external_api.products.model.urlBO}", required = true)
@NotBlank
private String urlBO;
@ApiModelProperty("${swagger.external_api.products.model.urlPublic}")
private String urlPublic;

@ApiModelProperty(value = "${swagger.external_api.products.model.depictImageUrl}")
private String depictImageUrl;
@ApiModelProperty(value = "${swagger.external_api.products.model.urlBO}", required = true)
@NotBlank
private String urlBO;

@ApiModelProperty(value = "${swagger.external_api.products.model.identityTokenAudience}")
private String identityTokenAudience;
@ApiModelProperty(value = "${swagger.external_api.products.model.depictImageUrl}")
private String depictImageUrl;

@ApiModelProperty(value = "${swagger.external_api.products.model.logo}")
private String logo;
@ApiModelProperty(value = "${swagger.external_api.products.model.identityTokenAudience}")
private String identityTokenAudience;

@ApiModelProperty(value = "${swagger.external_api.products.model.logoBgColor}")
private String logoBgColor;
@ApiModelProperty(value = "${swagger.external_api.products.model.logo}")
private String logo;

@ApiModelProperty(value = "${swagger.external_api.products.model.parentId}")
private String parentId;
@ApiModelProperty(value = "${swagger.external_api.products.model.logoBgColor}")
private String logoBgColor;

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

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

@ApiModelProperty(value = "${swagger.external_api.products.model.roleManagementURL}")
private String roleManagementURL;
}
5 changes: 0 additions & 5 deletions src/main/resources/swagger/api-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2248,11 +2248,6 @@
"type" : "string",
"description" : "The path of contract"
},
"contractTemplateUpdatedAt" : {
"type" : "string",
"description" : "Date the contract was postponed",
"format" : "date-time"
},
"contractTemplateVersion" : {
"type" : "string",
"description" : "Version of the contract"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ void getInstitutionUserProductsWith2Elements() throws Exception {
byte[] productStream = Files.readAllBytes(inputResource.getFile().toPath());
List<ProductResource> products = objectMapper.readValue(productStream, new TypeReference<>() {});

products.forEach(
productResource -> {
productResource.setContractTemplatePath("contractTemplatePath");
productResource.setContractTemplateVersion("1.0.0");
});

ClassPathResource outputResource = new ClassPathResource("expectations/ProductResources.json");
String expectedResource = StringUtils.deleteWhitespace(new String(Files.readAllBytes(outputResource.getFile().toPath())));

Expand Down
Loading

0 comments on commit 344ec8f

Please sign in to comment.