@Test public void test_should_use_value_from_first_matching_rule_to_set_computed_field() { final List<AttributeEntry> attributeEntries = Arrays.asList( new AttributeEntry("gender", "male"), new AttributeEntry("age", "30") ); final ServiceRequest serviceRequest = createServiceRequest(attributeEntries); final SevaRequest contractSevaRequest = mock(SevaRequest.class); final AttributeDefinition genderAttributeDefinition = AttributeDefinition.builder() .code("gender") .dataType(AttributeDataType.SINGLE_VALUE_LIST) .actions(Collections.emptyList()) .build(); final AttributeDefinition ageAttributeDefinition = AttributeDefinition.builder() .code("age") .dataType(AttributeDataType.INTEGER) .actions(Collections.emptyList()) .build(); final ComputeRuleDefinition ruleDefinition1 = ComputeRuleDefinition.builder() .rule("true") .value("50") .build(); final ComputeRuleDefinition ruleDefinition2 = ComputeRuleDefinition.builder() .rule("true") .value("60") .build(); final List<ComputeRuleDefinition> computeRules = Arrays.asList( ruleDefinition1, ruleDefinition2 ); final AttributeActionsDefinition attributeActionsDefinition = new AttributeActionsDefinition(ServiceStatus.COMPLAINT_REGISTERED); final AttributeDefinition applicationFeeAttributeDefinition = AttributeDefinition.builder() .code("applicationFee") .dataType(AttributeDataType.DOUBLE) .readOnly(true) .computeRules(computeRules) .actions(Collections.singletonList(attributeActionsDefinition)) .build(); final List<AttributeDefinition> attributeDefinitions = Arrays.asList( genderAttributeDefinition, ageAttributeDefinition, applicationFeeAttributeDefinition ); final ServiceDefinition serviceDefinition = ServiceDefinition.builder() .attributes(attributeDefinitions) .build(); final org.egov.pgrrest.common.contract.web.ServiceRequest mockServiceRequest = mock(org.egov.pgrrest.common.contract.web.ServiceRequest.class); final List<org.egov.pgr.common.contract.AttributeEntry> contractAttributeEntries = new ArrayList<>(); contractAttributeEntries.add(new org.egov.pgr.common.contract.AttributeEntry("gender", "male")); contractAttributeEntries.add(new org.egov.pgr.common.contract.AttributeEntry("age", "30")); when(contractSevaRequest.getAttributeValues()).thenReturn(contractAttributeEntries); final ServiceDefinitionSearchCriteria searchCriteria = new ServiceDefinitionSearchCriteria("serviceCode", "tenantId"); when(serviceDefinitionService.find(searchCriteria)) .thenReturn(serviceDefinition); customFieldService.enrich(serviceRequest, contractSevaRequest, ServiceStatus.COMPLAINT_REGISTERED); assertEquals(3, contractAttributeEntries.size()); assertEquals("50", contractAttributeEntries.get(2).getName()); assertEquals("applicationFee", contractAttributeEntries.get(2).getKey()); }
public void enrich(ServiceRequest serviceRequest, SevaRequest contractSevaRequest, ServiceStatus action) { final List<org.egov.pgr.common.contract.AttributeEntry> attribValues = contractSevaRequest.getAttributeValues(); final ServiceDefinition serviceDefinition = getServiceDefinition(serviceRequest); validateKnownServiceDefinition(serviceRequest, serviceDefinition); if (serviceDefinition.isAttributesAbsent()) { return; } validateAttributeValues(serviceRequest, serviceDefinition, action); if (serviceDefinition.isComputedFieldsAbsent(action)) { return; } computeFields(serviceRequest, attribValues, serviceDefinition, action); }
ServiceRequestCustomFieldService { public void enrich(ServiceRequest serviceRequest, SevaRequest contractSevaRequest, ServiceStatus action) { final List<org.egov.pgr.common.contract.AttributeEntry> attribValues = contractSevaRequest.getAttributeValues(); final ServiceDefinition serviceDefinition = getServiceDefinition(serviceRequest); validateKnownServiceDefinition(serviceRequest, serviceDefinition); if (serviceDefinition.isAttributesAbsent()) { return; } validateAttributeValues(serviceRequest, serviceDefinition, action); if (serviceDefinition.isComputedFieldsAbsent(action)) { return; } computeFields(serviceRequest, attribValues, serviceDefinition, action); } }
ServiceRequestCustomFieldService { public void enrich(ServiceRequest serviceRequest, SevaRequest contractSevaRequest, ServiceStatus action) { final List<org.egov.pgr.common.contract.AttributeEntry> attribValues = contractSevaRequest.getAttributeValues(); final ServiceDefinition serviceDefinition = getServiceDefinition(serviceRequest); validateKnownServiceDefinition(serviceRequest, serviceDefinition); if (serviceDefinition.isAttributesAbsent()) { return; } validateAttributeValues(serviceRequest, serviceDefinition, action); if (serviceDefinition.isComputedFieldsAbsent(action)) { return; } computeFields(serviceRequest, attribValues, serviceDefinition, action); } ServiceRequestCustomFieldService(ServiceDefinitionService serviceDefinitionService,
                                            List<AttributeValueValidator> attributeValueValidators,
                                            JSScriptEngineFactory scriptEngineFactory); }
ServiceRequestCustomFieldService { public void enrich(ServiceRequest serviceRequest, SevaRequest contractSevaRequest, ServiceStatus action) { final List<org.egov.pgr.common.contract.AttributeEntry> attribValues = contractSevaRequest.getAttributeValues(); final ServiceDefinition serviceDefinition = getServiceDefinition(serviceRequest); validateKnownServiceDefinition(serviceRequest, serviceDefinition); if (serviceDefinition.isAttributesAbsent()) { return; } validateAttributeValues(serviceRequest, serviceDefinition, action); if (serviceDefinition.isComputedFieldsAbsent(action)) { return; } computeFields(serviceRequest, attribValues, serviceDefinition, action); } ServiceRequestCustomFieldService(ServiceDefinitionService serviceDefinitionService,
                                            List<AttributeValueValidator> attributeValueValidators,
                                            JSScriptEngineFactory scriptEngineFactory); void enrich(ServiceRequest serviceRequest, SevaRequest contractSevaRequest, ServiceStatus action); }
ServiceRequestCustomFieldService { public void enrich(ServiceRequest serviceRequest, SevaRequest contractSevaRequest, ServiceStatus action) { final List<org.egov.pgr.common.contract.AttributeEntry> attribValues = contractSevaRequest.getAttributeValues(); final ServiceDefinition serviceDefinition = getServiceDefinition(serviceRequest); validateKnownServiceDefinition(serviceRequest, serviceDefinition); if (serviceDefinition.isAttributesAbsent()) { return; } validateAttributeValues(serviceRequest, serviceDefinition, action); if (serviceDefinition.isComputedFieldsAbsent(action)) { return; } computeFields(serviceRequest, attribValues, serviceDefinition, action); } ServiceRequestCustomFieldService(ServiceDefinitionService serviceDefinitionService,
                                            List<AttributeValueValidator> attributeValueValidators,
                                            JSScriptEngineFactory scriptEngineFactory); void enrich(ServiceRequest serviceRequest, SevaRequest contractSevaRequest, ServiceStatus action);  }