Closed mikolajmitura closed 1 year ago
Mapper should not work in runtime mapper code always should create code on groovy. Run groovy grom java https://docs.groovy-lang.org/latest/html/documentation/guide-integrating.html Do when some models wl be changed then mappers should be updated somehow. Only those which arę based on CWML, because other parts will be run normaly without checking compilatiom opportunity, maybe groovy have some flag for enable type checking.
Or generate code in java and in runtime load that generated classes. During save mappers via Rest should be validated
https://stackoverflow.com/questions/1010919/adding-files-to-java-classpath-at-runtime
Add mapper type upon that will be done validation. Existing_java_mapper, generated_mapper, By_groovy_code, by_java_code
types:
places where mapper can be:
additional fields for metadata for mappers:
languages for mappers:
example:
for mapping list will be used one of inner method when exists otherwise will be generated inner method for mapping each element with that method.
all available variables (should be used with prefix "$") rootSourceObject = soure object which will be mapped to other object (usefull in nested expressions). '$rootSourceObject' is equals to '$sourceObject' in main mapper method. In inner method $rootSourceObject means SourceObject from main mapper. sourceObject= soure object which will be mapped to other object (usefull in nested expressions). '$sourceObject' is equals to '' (when this is inner mapper method) headers = http headers from rest pathVariables = path params from URL requestParams - http get params mappingContext - other values from other datastorages
above fields and source will come from class GenericMapperArgument:
class GenericMapperArgument { Object sourceObject; Map headers; Map pathVariables; Map requestParams; Map mappingContext; }
mapping fields from GenericMapperArgument in CWML GenericMapperArgument.source.fieldName in CWML is "fieldName" GenericMapperArgument.header['cookie'] is "$header['cookie']" etc at left side is always field value or root in target object.
should be default mappers for concrete metamodels, so if some mapper not exists then try read everything per fields and ignore those which not exists in target and which cannot be mapped. So will be automapping for 4 mapper types. Mappers should use spring converter or Jackson converts types if certain mapper is not provided or default for those not exists.
java in mapper could use method argument like in generic service.
so to choose mapper metamodel during create/edit endpoint: