added validate method to config
This commit is contained in:
		
							parent
							
								
									90d34b5bd0
								
							
						
					
					
						commit
						6db073ba53
					
				@ -213,8 +213,7 @@ public class CalculatedFieldController extends BaseController {
 | 
			
		||||
            @RequestBody JsonNode inputParams) {
 | 
			
		||||
        String expression = inputParams.get("expression").asText();
 | 
			
		||||
        Map<String, TbelCfArg> arguments = Objects.requireNonNullElse(
 | 
			
		||||
                JacksonUtil.convertValue(inputParams.get("arguments"), new TypeReference<>() {
 | 
			
		||||
                }),
 | 
			
		||||
                JacksonUtil.convertValue(inputParams.get("arguments"), new TypeReference<>() {}),
 | 
			
		||||
                Collections.emptyMap()
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
@ -289,8 +288,7 @@ public class CalculatedFieldController extends BaseController {
 | 
			
		||||
                        return;
 | 
			
		||||
                    }
 | 
			
		||||
                    case CUSTOMER, ASSET, DEVICE -> checkEntityId(referencedEntityId, Operation.READ);
 | 
			
		||||
                    default ->
 | 
			
		||||
                            throw new IllegalArgumentException("Calculated fields do not support '" + entityType + "' for referenced entities.");
 | 
			
		||||
                    default -> throw new IllegalArgumentException("Calculated fields do not support '" + entityType + "' for referenced entities.");
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -14,8 +14,6 @@ public interface ArgumentsBasedCalculatedFieldConfiguration extends CalculatedFi
 | 
			
		||||
 | 
			
		||||
    Output getOutput();
 | 
			
		||||
 | 
			
		||||
    void validate();
 | 
			
		||||
 | 
			
		||||
    @JsonIgnore
 | 
			
		||||
    default boolean isScheduledUpdateEnabled() {
 | 
			
		||||
        return false;
 | 
			
		||||
 | 
			
		||||
@ -60,6 +60,9 @@ public abstract class BaseCalculatedFieldConfiguration implements ArgumentsBased
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void validate() {
 | 
			
		||||
        if (arguments.containsKey("ctx")) {
 | 
			
		||||
            throw new IllegalArgumentException("Argument name 'ctx' is reserved and cannot be used.");
 | 
			
		||||
        }
 | 
			
		||||
        if (arguments.values().stream().anyMatch(Argument::hasDynamicSource)) {
 | 
			
		||||
            throw new IllegalArgumentException("Calculated field with type: '" + getType() + "' doesn't support dynamic source configuration!");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -44,6 +44,8 @@ public interface CalculatedFieldConfiguration {
 | 
			
		||||
    @JsonIgnore
 | 
			
		||||
    CalculatedFieldType getType();
 | 
			
		||||
 | 
			
		||||
    void validate();
 | 
			
		||||
 | 
			
		||||
    @JsonIgnore
 | 
			
		||||
    default List<EntityId> getReferencedEntities() {
 | 
			
		||||
        return Collections.emptyList();
 | 
			
		||||
 | 
			
		||||
@ -82,16 +82,11 @@ public class CalculatedFieldDataValidator extends DataValidator<CalculatedField>
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void validateCalculatedFieldConfiguration(CalculatedField calculatedField) {
 | 
			
		||||
        if (calculatedField.getConfiguration() instanceof ArgumentsBasedCalculatedFieldConfiguration configuration) {
 | 
			
		||||
            if (configuration.getArguments().containsKey("ctx")) {
 | 
			
		||||
                throw new DataValidationException("Argument name 'ctx' is reserved and cannot be used.");
 | 
			
		||||
            }
 | 
			
		||||
        try {
 | 
			
		||||
                configuration.validate();
 | 
			
		||||
            calculatedField.getConfiguration().validate();
 | 
			
		||||
        } catch (IllegalArgumentException e) {
 | 
			
		||||
            throw new DataValidationException(e.getMessage(), e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user