Before a new property can be saved, a property key needs to be generated from the property name. The best place to do this is in the entity class itself. Accordingly, we add a new method, generatePropertyKey(), to the booksomeplace.entity.property.Property class, as shown here. If for some reason the property name is less than four characters long, we append an underscore (_) character.
We also remove any spaces and make the first four letters uppercase. Finally, a random four-digit number is appended:
def generatePropertyKey(self) :
import random
first4 = self['propName']
first4 = first4.replace(' ', '')
first4 = first4[0:4]
first4 = first4.ljust(4, '_')
self['propertyKey'] = first4.upper() + \
str(random.randint(1000, 9999))
return self['propertyKey']
Next, we will update the property domain service.