mikolajmitura / crud-wizard

0 stars 1 forks source link

Mapper between Service and DataStorage #1

Closed mikolajmitura closed 1 year ago

mikolajmitura commented 3 years ago

types:

places where mapper can be:

additional fields for metadata for mappers:

languages for mappers:

example:

person = personData // default maping dto/map map/dto 
person.uuid = uuid // mapping of some fields
address = personData.address // default maping dto/map map/dto 
personType = @springBeanName.methodName($headers[‘person-type’]) // maping to value by spring bean named  “springBeanName” via method named “methodName”
otherPerson= @mapperName(personData) // mapping by other named mapper "mapperName"
otherPerson.nestedField= @mapperName(otherPersonData.otherField) // mapping by other named mapper "mapperName" (mapper with type CWML or groovy script with name “mapperName”)
=person // to root of object put value from whole node named "person"
=otherPersonField // to root of object put value from whole node named "otherPersonField", duplication of field names should inform about exception... field duplication can be overriden below, when is overriden then exception should not be thrown
somefield= // put whole value from source to to field named  "somefield"
somfield=$headers['some-key']
list=#innerMethodWithCreateWholeList // TODO this should be checked that it will be used this method or get results from that method and iterate througth that and put to target list
otherList.*=#innerMethodForMapEachElement // TODO this should be checked...
someField=java(headers.get("x-somecookie") + "sometext")//Maybe on future will be opportunity for usage other languages.

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:

mikolajmitura commented 3 years 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.

mikolajmitura commented 2 years ago

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

https://stackoverflow.com/questions/2946338/how-do-i-programmatically-compile-and-instantiate-a-java-class

mikolajmitura commented 2 years ago

Add mapper type upon that will be done validation. Existing_java_mapper, generated_mapper, By_groovy_code, by_java_code