Skip to content

Commit

Permalink
fix: Add string trim on fields contianing evaluable data
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-deri committed Feb 15, 2024
1 parent e1627be commit 6cdf2cd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
package it.gov.pagopa.mocker.config.mapper;

import it.gov.pagopa.mocker.config.entity.*;
import it.gov.pagopa.mocker.config.util.Utility;
import it.gov.pagopa.mocker.config.model.mockresource.MockCondition;
import it.gov.pagopa.mocker.config.model.mockresource.MockResource;
import it.gov.pagopa.mocker.config.model.mockresource.MockResponse;
import it.gov.pagopa.mocker.config.model.mockresource.MockRule;
import it.gov.pagopa.mocker.config.util.Utility;
import org.modelmapper.Converter;
import org.modelmapper.spi.MappingContext;

import java.util.*;
import java.util.stream.Collectors;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;

public class ConvertMockResourceToMockResourceEntity implements Converter<MockResource, MockResourceEntity> {

@Override
public MockResourceEntity convert(MappingContext<MockResource, MockResourceEntity> mappingContext) {
MockResource mockResource = mappingContext.getSource();

String subsystem = mockResource.getSubsystem().trim();
String resourceUrl = mockResource.getResourceURL().trim();
String soapAction = mockResource.getSoapAction().trim();
MockResourceEntity mockResourceEntity = MockResourceEntity.builder()
.id(Utility.generateResourceId(mockResource.getHttpMethod(), mockResource.getSubsystem(), mockResource.getResourceURL(), mockResource.getSoapAction()))
.id(Utility.generateResourceId(mockResource.getHttpMethod(), subsystem, resourceUrl, soapAction))
.name(mockResource.getName())
.subsystemUrl(mockResource.getSubsystem())
.resourceUrl(mockResource.getResourceURL())
.action(mockResource.getSoapAction())
.subsystemUrl(subsystem)
.resourceUrl(resourceUrl)
.action(soapAction)
.httpMethod(mockResource.getHttpMethod())
.isActive(mockResource.getIsActive())
.tags(new HashSet<>(mockResource.getTags()))
.tags(new HashSet<>(mockResource.getTags().stream().map(String::trim).filter(value -> !value.isBlank()).toList()))
.build();

List<MockRuleEntity> ruleEntities = new LinkedList<>();
Expand All @@ -51,7 +56,7 @@ private MockRuleEntity buildMockRule(MockRule mockRule, MockResponseEntity mockR
.order(mockRule.getOrder())
.isActive(mockRule.getIsActive())
.response(mockResponseEntity)
.tags(new HashSet<>(mockRule.getTags()))
.tags(new HashSet<>(mockRule.getTags().stream().map(String::trim).filter(value -> !value.isBlank()).toList()))
.build();
}

Expand All @@ -65,7 +70,7 @@ private List<MockConditionEntity> buildMockConditions(MockRule mockRule, MockRul
.order(mockCondition.getOrder())
.fieldPosition(mockCondition.getFieldPosition())
.analyzedContentType(mockCondition.getAnalyzedContentType())
.fieldName(mockCondition.getFieldName())
.fieldName(mockCondition.getFieldName().trim())
.conditionType(mockCondition.getConditionType())
.conditionValue(mockCondition.getConditionValue())
.build()
Expand All @@ -83,13 +88,13 @@ private MockResponseEntity buildMockResponse(MockResponse mockResponse) {
.headers(mockResponse.getHeaders()
.stream()
.map(header -> ResponseHeaderEntity.builder()
.header(header.getName())
.header(header.getName().trim())
.value(header.getValue())
.build()
)
.collect(Collectors.toList())
.toList()
)
.parameters(new HashSet<>(mockResponse.getParameters()))
.parameters(new HashSet<>(mockResponse.getParameters().stream().map(String::trim).filter(value -> !value.isBlank()).toList()))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import org.modelmapper.Converter;
import org.modelmapper.spi.MappingContext;

import java.util.*;
import java.util.stream.Collectors;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;

public class ConvertMockRuleToMockRuleEntity implements Converter<MockRule, MockRuleEntity> {

Expand All @@ -35,7 +37,7 @@ private MockRuleEntity buildMockRule(MockRule mockRule, MockResponseEntity mockR
.order(mockRule.getOrder())
.isActive(mockRule.getIsActive())
.response(mockResponseEntity)
.tags(new HashSet<>(mockRule.getTags()))
.tags(new HashSet<>(mockRule.getTags().stream().map(String::trim).filter(value -> !value.isBlank()).toList()))
.build();
}

Expand All @@ -49,7 +51,7 @@ private List<MockConditionEntity> buildMockConditions(MockRule mockRule, MockRul
.order(mockCondition.getOrder())
.fieldPosition(mockCondition.getFieldPosition())
.analyzedContentType(mockCondition.getAnalyzedContentType())
.fieldName(mockCondition.getFieldName())
.fieldName(mockCondition.getFieldName().trim())
.conditionType(mockCondition.getConditionType())
.conditionValue(mockCondition.getConditionValue())
.build()
Expand All @@ -67,13 +69,13 @@ private MockResponseEntity buildMockResponse(MockResponse mockResponse) {
.headers(mockResponse.getHeaders()
.stream()
.map(header -> ResponseHeaderEntity.builder()
.header(header.getName())
.header(header.getName().trim())
.value(header.getValue())
.build()
)
.collect(Collectors.toList())
.toList()
)
.parameters(new HashSet<>(mockResponse.getParameters()))
.parameters(new HashSet<>(mockResponse.getParameters().stream().map(String::trim).filter(value -> !value.isBlank()).toList()))
.build();
}
}

0 comments on commit 6cdf2cd

Please sign in to comment.