ContextMapper / context-mapper-dsl

ContextMapper DSL: A Domain-specific Language for Context Mapping & Service Decomposition
https://contextmapper.org/
Apache License 2.0
215 stars 28 forks source link

Unable to specify attribute type of entity as Map #318

Closed sunilk-m closed 2 years ago

sunilk-m commented 2 years ago

I am modeling an entity which has an attribute of type Map<String, String>. I see examples of other collection types here (https://contextmapper.org/docs/tactic-ddd/) . The Map keyword is not recognised the way List or Set is recognized in the editor. I see a MAP_COLLECTION_TYPE in the TacticDDDLanguage.xtext. I have declared it as shown below.

Map<String, String> phones

stefan-ka commented 2 years ago

Hi @sunilk-m

Thanks for reporting your issue!

Yes, it looks like Sculptor only supports maps as return or parameter types but not in attributes.

An example where it works: (return type)

Service AddressService {
    Map<String, @Address> createAddressMap();
}

However, I honestly don't see yet why I would need maps in a domain model. Can you explain your use case a bit more detailed? I actually don't understand what you model with Map<String, String> phones... What is the key and the value in this case? Personally I would also question why Strings are used here. Shouldn't a phone number be a value object?

Thanks and best regards, Stefan

sunilk-m commented 2 years ago

We have to display a collection of phone numbers as part of "Contact Us". In one instance of the entity it might be Phone1, Phone 2 etc and the corresponding number. In some other case it might be Mobile, Toll free etc. So the key is the name like Phone 1, Phone 2, Mobile etc and value is actual phone number.

stefan-ka commented 2 years ago

Okay @sunilk-m, but why don't you model that as follows (just an example, of course) instead of using a map of primitives?

Entity Person {
    String firstName
    String lastName

    - List<Phone> phones
}

ValueObject Phone {
    - PhoneType typ
    String number
}

enum PhoneType {
    PHONE1, PHONE2, MOBILE
}
sunilk-m commented 2 years ago

PhoneType can't be an enum. I probably didn't convey the intent in the above example. The keys are dynamic and not fixed. So the PhoneType will have to be a String in your model.
Thanks for your responses. I think this change will support my need.