Question: how to implement a concept of 'draft' entities?

Hi,

I’m looking for a generic approach to working with draft (or concept) entities. Such entities would be visible only within a certain context, e.g. a ‘draft table’ or alike. In the remainder of the system, such entities should not be shown.

So far I’m considering to using a concept field (to indicate whether an entity is a concept entity or not) and applying a constraint to keep concept entities from showing up within the system.

On the entity (preferably using an interface etc.):

    @Column(name = "CONCEPT")
    private Boolean concept = false; // This is the default

    public Boolean getConcept() {
        return concept != null && concept;
    }

    public void setConcept(Boolean concept) {
        this.concept = concept;
    }

With a constraint on the root group:

   {E}.concept = true

This would be very convenient both in terms of the effort and reliability except that it doesn’t allow to have a screen / location that does show these entities in a ‘draft table’ as they are filtered out at all times. There is no way to bypass a constraint (for the same user / session) at some locations, is there?

Another option would be to - again - use a concept field and adapt each and every query on them to exclude the concept entities except for the ‘draft table’. This is a lot of work and may lead to errors in future developments.

Do you have any suggestions on how to approach something like this?

Any help appreciated.

Regards,
-b

Hi,
I don’t have any experience about defining constraints on the root group, but exposed solution has interested me in reading more about it because I’m ignorant of the matter.
I suppose that you have taken a look to the developer’s manual but I found this information that could be for your interest, especially the section about “Checking constraints in application code”.
contraints

I found this functionality very powerful.

Regards,

Hi,

We have been using constraints heavily as they are very powerful indeed. Checking in code just helps to know whether a constraint is applied/applicable but doesn’t help bypassing it.

However, we did find the authentication service helpful in this case. There is a call to execute some code as a system user (thus avoiding the constraints). Still figuring out if this holds a solution and whether it is the best way forward.

Regards,
-b

This proved to be the solution we were looking for. By performing a query through the authentication asSystemUser() function we are able to get all concept entities on required locations while the remainder of the system does not show them at all due to the global constraint we apply.

Maybe this helps others as well.

Regards,
-b

1 Like