[MAGNOLIA-6679] User and UserManager do not support multivalued properties Created: 19/Apr/16  Updated: 14/Jun/16  Resolved: 14/Jun/16

Status: Closed
Project: Magnolia
Component/s: core, security
Affects Version/s: 5.4.5
Fix Version/s: None

Type: Improvement Priority: Major
Reporter: Teresa Miyar Assignee: Federico Grilli
Resolution: Not an issue Votes: 0
Labels: architecture, support
Remaining Estimate: 0d
Time Spent: 0.5d
Original Estimate: Not Specified

Attachments: XML File config.modules.security-app.dialogs.user.form.tabs.user.fields.companies-2.xml    
Issue Links:
dependency
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Date of First Response:
Sprint: Basel 48
Story Points: 5

 Description   

When using a info.magnolia.ui.form.field.definition.LinkFieldDefinition with Multivaluetransformer, the data is saved correctly but an exception is thrown when retrieving it

(see the [ in the uuid
Caused by: java.lang.IllegalArgumentException: [d14950fc-7fc2-4631-92f1-b6f60a1fe40a
	at org.apache.jackrabbit.core.id.NodeId.<init>(NodeId.java:129)
	at org.apache.jackrabbit.core.id.NodeId.valueOf(NodeId.java:52)
	at org.apache.jackrabbit.core.SessionImpl.getNodeByIdentifier(SessionImpl.java:1098)
	... 123 more

OUTCOME
---------------

After some debugging it seems that the issue is not due to the transformer, rather to the lack in our UserManager of a method to save a property as multivalued and User to support such properties.
Regarding the original issue (where the cause was initially thought to be a bug in Multivaluetransformer), a LinkedList object with property values is simply turned into its String representation at PropertyUtil.createValue(Object, ValueFactory) at line #331. This looks like a JCR multivalued property [foo, bar] but it's not (it's a string), hence the failure when retrieving the value.

Whilst it is easy to workaround the limitation of not having a User API allowing to save a multivalued property, an error occurs once one tries to edit/update a User with such a property.

ERROR info.magnolia.cms.security.MgnlUserManager        : Could not retrieve user with name: tina
javax.jcr.ValueFormatException: property /admin/tina/companies is a multi-valued property, so it's values can only be retrieved as an array
	at org.apache.jackrabbit.core.PropertyImpl.internalGetValue(PropertyImpl.java:483)
	at org.apache.jackrabbit.core.PropertyImpl.getValue(PropertyImpl.java:510)
	at org.apache.jackrabbit.core.PropertyImpl.getString(PropertyImpl.java:520)
	at info.magnolia.cms.security.MgnlUserManager.newUserInstance(MgnlUserManager.java:576)

this is eventually due to User (in our case implemented by MgnlUser) not supporting multivalued properties.

PROPOSAL
----------------
Besides having User setProperty(User user, String propertyName, String propertyValue), we'd need UserManager should have a User setProperty(User user, String propertyName, String[] multivalued) as well.
User should have a String[] getMultivaluedProperty(String propertyName) method or similar. Implementations of User should be able to store and return both simple String and String[] (multivalued) props.



 Comments   
Comment by Federico Grilli [ 14/Jun/16 ]

In the arch meeting has been decided not to proceed with the proposed solution because we do not actually intend to support multivalued properties in the users workspace. We will instead look at an alternative solution involving the profiles workspace as place fitter to hold non security-related user properties https://wiki.magnolia-cms.com/display/DEV/Preferences+and+User+profile
A customer wanting to have multivalued user properties anyway can nonetheless resort to a custom SaveUserDialoAction as outlined at MGNLUI-3860

Generated at Mon Feb 12 04:16:48 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.