{"action":"created","issue":{"url":"https://api.github.com/repos/eurotech/kapua/issues/181","repository_url":"https://api.github.com/repos/eurotech/kapua","labels_url":"https://api.github.com/repos/eurotech/kapua/issues/181/labels{/name}","comments_url":"https://api.github.com/repos/eurotech/kapua/issues/181/comments","events_url":"https://api.github.com/repos/eurotech/kapua/issues/181/events","html_url":"https://github.com/eurotech/kapua/issues/181","id":178100984,"number":181,"title":"KapuaEntity objects' scopeId is not deserialized","user":{"login":"Lorthirk","id":8140139,"avatar_url":"https://avatars.githubusercontent.com/u/8140139?v=3","gravatar_id":"","url":"https://api.github.com/users/Lorthirk","html_url":"https://github.com/Lorthirk","followers_url":"https://api.github.com/users/Lorthirk/followers","following_url":"https://api.github.com/users/Lorthirk/following{/other_user}","gists_url":"https://api.github.com/users/Lorthirk/gists{/gist_id}","starred_url":"https://api.github.com/users/Lorthirk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Lorthirk/subscriptions","organizations_url":"https://api.github.com/users/Lorthirk/orgs","repos_url":"https://api.github.com/users/Lorthirk/repos","events_url":"https://api.github.com/users/Lorthirk/events{/privacy}","received_events_url":"https://api.github.com/users/Lorthirk/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/eurotech/kapua/labels/bug","name":"bug","color":"ee0701"}],"state":"open","locked":false,"assignee":{"login":"Lorthirk","id":8140139,"avatar_url":"https://avatars.githubusercontent.com/u/8140139?v=3","gravatar_id":"","url":"https://api.github.com/users/Lorthirk","html_url":"https://github.com/Lorthirk","followers_url":"https://api.github.com/users/Lorthirk/followers","following_url":"https://api.github.com/users/Lorthirk/following{/other_user}","gists_url":"https://api.github.com/users/Lorthirk/gists{/gist_id}","starred_url":"https://api.github.com/users/Lorthirk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Lorthirk/subscriptions","organizations_url":"https://api.github.com/users/Lorthirk/orgs","repos_url":"https://api.github.com/users/Lorthirk/repos","events_url":"https://api.github.com/users/Lorthirk/events{/privacy}","received_events_url":"https://api.github.com/users/Lorthirk/received_events","type":"User","site_admin":false},"assignees":[{"login":"Lorthirk","id":8140139,"avatar_url":"https://avatars.githubusercontent.com/u/8140139?v=3","gravatar_id":"","url":"https://api.github.com/users/Lorthirk","html_url":"https://github.com/Lorthirk","followers_url":"https://api.github.com/users/Lorthirk/followers","following_url":"https://api.github.com/users/Lorthirk/following{/other_user}","gists_url":"https://api.github.com/users/Lorthirk/gists{/gist_id}","starred_url":"https://api.github.com/users/Lorthirk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Lorthirk/subscriptions","organizations_url":"https://api.github.com/users/Lorthirk/orgs","repos_url":"https://api.github.com/users/Lorthirk/repos","events_url":"https://api.github.com/users/Lorthirk/events{/privacy}","received_events_url":"https://api.github.com/users/Lorthirk/received_events","type":"User","site_admin":false}],"milestone":null,"comments":2,"created_at":"2016-09-20T15:54:08Z","updated_at":"2016-09-21T18:32:37Z","closed_at":null,"body":"This happens because of `KapuaEntity` not requiring a public setter for scopeId"},"comment":{"url":"https://api.github.com/repos/eurotech/kapua/issues/comments/248701695","html_url":"https://github.com/eurotech/kapua/issues/181#issuecomment-248701695","issue_url":"https://api.github.com/repos/eurotech/kapua/issues/181","id":248701695,"user":{"login":"stefanomorson","id":11518067,"avatar_url":"https://avatars.githubusercontent.com/u/11518067?v=3","gravatar_id":"","url":"https://api.github.com/users/stefanomorson","html_url":"https://github.com/stefanomorson","followers_url":"https://api.github.com/users/stefanomorson/followers","following_url":"https://api.github.com/users/stefanomorson/following{/other_user}","gists_url":"https://api.github.com/users/stefanomorson/gists{/gist_id}","starred_url":"https://api.github.com/users/stefanomorson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stefanomorson/subscriptions","organizations_url":"https://api.github.com/users/stefanomorson/orgs","repos_url":"https://api.github.com/users/stefanomorson/repos","events_url":"https://api.github.com/users/stefanomorson/events{/privacy}","received_events_url":"https://api.github.com/users/stefanomorson/received_events","type":"User","site_admin":false},"created_at":"2016-09-21T18:32:37Z","updated_at":"2016-09-21T18:32:37Z","body":"@Lorthirk , @Coduz : I was looking at the viable solutions, possibly without breaking the contracts that we have. Actually the issue (unmarshalling don't set the scopeId property) affects the createdOn/createdBy and modifiedOn/modifiedBy as well. The problem shows with the update operations invoked by the rest API.\r\n\r\nI think we were right at the beginning when we thought to make this properties \"read only\" (scopeId is not read-only just for the creators). \r\n\r\nMy idea is to manage this stuff on the implementation side and specifically in ServiceDAO:\r\n\r\n```\r\n    public static <E extends KapuaEntity> E update(EntityManager em, Class<E> clazz, E entity)\r\n    {\r\n        //\r\n        // Checking existence\r\n        E entityToUpdate = em.find(clazz, entity.getId());\r\n\r\n        ...\r\n    }\r\n```\r\n\r\nActually, in my understanding, ServiceDAO was created not to give a super generic DAO that works with every implementation of KapuaEntity but more as an helper class that puts together some common code for reusability. In all the DAOs that use ServiceDAO we already cast entities to implementations, for example in AccountDAO (and others) we do the following:\r\n\r\n```\r\n    public static Account update(EntityManager em, Account account)\r\n        throws KapuaException\r\n    {\r\n        //\r\n        // Update account\r\n        AccountImpl accountImpl = (AccountImpl) account;\r\n\r\n        return ServiceDAO.update(em, AccountImpl.class, accountImpl);\r\n    }\r\n ```\r\n\r\nSo my proposal is the following, change a bit the ServiceDAO implementation in:\r\n\r\n```\r\n    public static <E extends KapuaEntity> E update(EntityManager em, Class<E> clazz, E entity)\r\n    {\r\n        //\r\n        // Checking existence\r\n        AbstractKapuaEntity entityToUpdate = (AbstractKapuaEntity)em.find(clazz, entity.getId());\r\n        entity.setScopeId(entityToUpdate.getScopeId());\r\n        entity.setCreatedBy(entityToUpdate.getCreatedBy());\r\n        entity.setCreatedOn(entityToUpdate.getCreatedOn());\r\n        if (entity implements AbstractKapuaUpdatableEntity) {\r\n                AbstractKapuaUpdatableEntity updatableEntity = (AbstractKapuaUpdatableEntity)entity;\r\n                AbstractKapuaUpdatableEntity updEntityToUpdate = (AbstractKapuaUpdatableEntity)entityToUpdate;\r\n                entityToUpdate.setModifiedOn(updEntityToUpdate.getModifiedOn());\r\n                entityToUpdate.setModifiedBy(updEntityToUpdate.getModifiedBy());\r\n        }\r\n        //\r\n        // Deleting if not null\r\n        if (entityToUpdate != null) {\r\n            em.merge(entity);\r\n            em.flush();\r\n            em.refresh(entityToUpdate);\r\n        }\r\n\r\n        return entityToUpdate;\r\n    }\r\n```\r\n\r\n"}}
{"actor":{"display_login":"stefanomorson"}}