From 450b4f564d30f1d6dbc6167c0c46e7c031368532 Mon Sep 17 00:00:00 2001 From: felmer <felmer> Date: Thu, 30 Nov 2017 10:38:18 +0000 Subject: [PATCH] SSDM-5721: bug fixed caused by introduction of Me SVN: 38991 --- .../UpdateAuthorizationGroupExecutor.java | 9 +++------ .../v3/executor/person/MapPersonByIdExecutor.java | 2 +- .../asapi/v3/helper/person/ListPersonByMe.java | 14 +++++++++++++- .../public/resources/api/v3/as/dto/person/id/Me.js | 3 ++- .../asapi/v3/dto/common/id/ObjectPermId.java | 5 +++++ 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/authorizationgroup/UpdateAuthorizationGroupExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/authorizationgroup/UpdateAuthorizationGroupExecutor.java index 5bd928a999e..0749bda7088 100644 --- a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/authorizationgroup/UpdateAuthorizationGroupExecutor.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/authorizationgroup/UpdateAuthorizationGroupExecutor.java @@ -90,10 +90,10 @@ public class UpdateAuthorizationGroupExecutor for (Map.Entry<AuthorizationGroupUpdate, AuthorizationGroupPE> entry : batch.getObjects().entrySet()) { AuthorizationGroupUpdate update = entry.getKey(); - AuthorizationGroupPE tag = entry.getValue(); + AuthorizationGroupPE group = entry.getValue(); if (update.getDescription() != null && update.getDescription().isModified()) { - tag.setDescription(update.getDescription().getValue()); + group.setDescription(update.getDescription().getValue()); } } } @@ -119,10 +119,7 @@ public class UpdateAuthorizationGroupExecutor @Override protected void save(IOperationContext context, List<AuthorizationGroupPE> entities, boolean clearCache) { - for (AuthorizationGroupPE group : entities) - { - daoFactory.getAuthorizationGroupDAO().persist(group); - } + // Entities updated by Hibernate at the end of the transaction } @Override diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/person/MapPersonByIdExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/person/MapPersonByIdExecutor.java index 0fd8068ceae..cf455356399 100644 --- a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/person/MapPersonByIdExecutor.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/person/MapPersonByIdExecutor.java @@ -53,7 +53,7 @@ public class MapPersonByIdExecutor extends AbstractMapObjectByIdExecutor<IPerson protected void addListers(IOperationContext context, List<IListObjectById<? extends IPersonId, PersonPE>> listers) { listers.add(new ListPersonByPermId(personDAO)); - listers.add(new ListPersonByMe()); + listers.add(new ListPersonByMe(personDAO)); } @Autowired diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/helper/person/ListPersonByMe.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/helper/person/ListPersonByMe.java index cf0c8a55e03..db8f4c69359 100644 --- a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/helper/person/ListPersonByMe.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/helper/person/ListPersonByMe.java @@ -23,6 +23,8 @@ import ch.ethz.sis.openbis.generic.asapi.v3.dto.person.id.Me; import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.IOperationContext; import ch.ethz.sis.openbis.generic.server.asapi.v3.helper.common.AbstractListObjectById; import ch.systemsx.cisd.common.exceptions.UserFailureException; +import ch.systemsx.cisd.openbis.generic.server.dataaccess.IPersonDAO; +import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE; /** @@ -33,6 +35,13 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE; public class ListPersonByMe extends AbstractListObjectById<Me, PersonPE> { + private IPersonDAO personDAO; + + public ListPersonByMe(IPersonDAO personDAO) + { + this.personDAO = personDAO; + } + @Override public Me createId(PersonPE entity) { @@ -47,7 +56,10 @@ public class ListPersonByMe extends AbstractListObjectById<Me, PersonPE> { throw new UserFailureException("Can not resolve 'Me' because there is no session user."); } - return Collections.nCopies(ids.size(), person); + // The session user has to be loaded from the database because it isn't in the Hibernate session. + // This is important for example when adding the session user to an authorization group. + PersonPE reloadedPerson = personDAO.getByTechId(TechId.create(person)); + return Collections.nCopies(ids.size(), reloadedPerson); } @Override diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/person/id/Me.js b/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/person/id/Me.js index 1e80686cbab..0a622c85398 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/person/id/Me.js +++ b/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/person/id/Me.js @@ -1,7 +1,8 @@ define([ "stjs", "as/dto/common/id/ObjectPermId", "as/dto/person/id/IPersonId" ], function(stjs, ObjectPermId, IPersonId) { var Me = function() { + ObjectPermId.call(this, null); }; - stjs.extend(PersonPermId, ObjectPermId, [ ObjectPermId, IPersonId ], function(constructor, prototype) { + stjs.extend(Me, ObjectPermId, [ ObjectPermId, IPersonId ], function(constructor, prototype) { prototype['@type'] = 'as.dto.person.id.Me'; constructor.serialVersionUID = 1; }, {}); diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/common/id/ObjectPermId.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/common/id/ObjectPermId.java index 1bfe424b224..128c1f9780e 100644 --- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/common/id/ObjectPermId.java +++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/common/id/ObjectPermId.java @@ -16,6 +16,9 @@ package ch.ethz.sis.openbis.generic.asapi.v3.dto.common.id; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; + import ch.systemsx.cisd.base.annotation.JsonObject; /** @@ -31,6 +34,7 @@ public abstract class ObjectPermId implements IObjectId private static final long serialVersionUID = 1L; + @JsonProperty private String permId; public ObjectPermId(String permId) @@ -51,6 +55,7 @@ public abstract class ObjectPermId implements IObjectId { } + @JsonIgnore private void setPermId(String permId) { if (permId == null) -- GitLab