'Finding nested duplicates in OCL

I am facing a challenge when trying to check for duplicates in OCL.

Here is a simplification of the class diagram:

                                       +-----------+
                                       |ChapterName|
                                       +-----------+
                                           ^ 0..* chapterNames
                                           |
                                           ^
                                           V
                 +-------+    books 0..* +----+
                 |Catalog|<>------------>|Book|
                 +-------+               +----+
      catalogs 0..* ^                       ^ 0..* books
                    |                       | 
                  +----+  customers 0..* +--------+
                  |Shop|<>-------------->|Customer|
                  +----+                 +--------+

The attributes for each class are declared as follows:

  • ChapterName
    • Name
  • Catalog
    • Category

Problem: What I want to check is if a customer has any books with duplicate chapter names, that also belong to a specific category in catalog.

I haven't managed to wrap my head around the logic. What I have so far is:

context Shop
self.customers.books->select(cubks | cubks =
  self.catalogs.books->select(cabks | cabks = cubks)->first())

...Which should find the books from the catalog which a customer has.

Question: How can I add further constraints to solve the problem above?

Also. I am using Eclipse, EMF, and the OCL console from within Eclipse.

ocl


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source