diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/experiment/CreateExperimentExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/experiment/CreateExperimentExecutor.java index b95e45aededf4b8346f89da7f93c7aeebb4048cd..d46166f53dbd11e14c2d4a3956f9ae989e0284a2 100644 --- a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/experiment/CreateExperimentExecutor.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/experiment/CreateExperimentExecutor.java @@ -28,6 +28,7 @@ import ch.ethz.sis.openbis.generic.server.api.v3.executor.entity.IGetEntityTypeB import ch.ethz.sis.openbis.generic.server.api.v3.executor.project.IGetProjectByIdExecutor; import ch.ethz.sis.openbis.generic.server.api.v3.executor.property.IUpdateEntityPropertyExecutor; import ch.ethz.sis.openbis.generic.server.api.v3.executor.tag.IAddTagToEntityExecutor; +import ch.ethz.sis.openbis.generic.server.api.v3.helper.experiment.ExperimentContextDescription; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.experiment.ExperimentCreation; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.entitytype.IEntityTypeId; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.experiment.ExperimentPermId; @@ -88,14 +89,14 @@ public class CreateExperimentExecutor implements ICreateExperimentExecutor { List<ExperimentPermId> result = new LinkedList<ExperimentPermId>(); - for (ExperimentCreation experimentCreation : creations) + for (ExperimentCreation creation : creations) { - context.pushContextDescription("register experiment " + experimentCreation.getCode()); + context.pushContextDescription(ExperimentContextDescription.creating(creation)); - ExperimentPE experiment = createExperimentPE(context, experimentCreation); + ExperimentPE experiment = createExperimentPE(context, creation); daoFactory.getExperimentDAO().createOrUpdateExperiment(experiment, context.getSession().tryGetPerson()); - createAttachmentExecutor.create(context, experiment, experimentCreation.getAttachments()); - addTagToEntityExecutor.add(context, experiment, experimentCreation.getTagIds()); + createAttachmentExecutor.create(context, experiment, creation.getAttachments()); + addTagToEntityExecutor.add(context, experiment, creation.getTagIds()); result.add(new ExperimentPermId(experiment.getPermId())); context.popContextDescription(); diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/experiment/UpdateExperimentExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/experiment/UpdateExperimentExecutor.java index fb9c075a0221f37f010d07f923b3c195fca805e0..127f213a88e1821b6c00dcd057b7b418795c28cf 100644 --- a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/experiment/UpdateExperimentExecutor.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/experiment/UpdateExperimentExecutor.java @@ -32,6 +32,7 @@ import org.springframework.stereotype.Component; import ch.ethz.sis.openbis.generic.server.api.v3.executor.IOperationContext; import ch.ethz.sis.openbis.generic.server.api.v3.executor.property.IUpdateEntityPropertyExecutor; import ch.ethz.sis.openbis.generic.server.api.v3.executor.tag.IUpdateTagForEntityExecutor; +import ch.ethz.sis.openbis.generic.server.api.v3.helper.experiment.ExperimentContextDescription; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.experiment.ExperimentUpdate; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.experiment.IExperimentId; import ch.ethz.sis.openbis.generic.shared.api.v3.exceptions.ObjectNotFoundException; @@ -112,6 +113,8 @@ public class UpdateExperimentExecutor implements IUpdateExperimentExecutor for (IExperimentId experimentId : experimentIds) { + context.pushContextDescription(ExperimentContextDescription.updating(experimentId)); + ExperimentPE experiment = experimentMap.get(experimentId); if (experiment == null) { @@ -121,6 +124,8 @@ public class UpdateExperimentExecutor implements IUpdateExperimentExecutor { throw new UnauthorizedObjectAccessException(experimentId); } + + context.popContextDescription(); } Map<ExperimentUpdate, ExperimentPE> result = new HashMap<ExperimentUpdate, ExperimentPE>(); @@ -134,7 +139,7 @@ public class UpdateExperimentExecutor implements IUpdateExperimentExecutor private void updateExperiment(IOperationContext context, ExperimentUpdate update, ExperimentPE experiment) { - context.pushContextDescription("update experiment " + update.getExperimentId()); + context.pushContextDescription(ExperimentContextDescription.updating(update.getExperimentId())); updateExperimentProjectExecutor.update(context, experiment, update.getProjectId()); updateEntityPropertyExecutor.update(context, experiment, experiment.getEntityType(), update.getProperties()); diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/experiment/ExperimentContextDescription.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/experiment/ExperimentContextDescription.java new file mode 100644 index 0000000000000000000000000000000000000000..e696a73f1059bd829abdccb142387fc1bd69599a --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/experiment/ExperimentContextDescription.java @@ -0,0 +1,38 @@ +/* + * Copyright 2014 ETH Zuerich, Scientific IT Services + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.ethz.sis.openbis.generic.server.api.v3.helper.experiment; + +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.experiment.ExperimentCreation; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.experiment.IExperimentId; + +/** + * @author pkupczyk + */ +public class ExperimentContextDescription +{ + + public static String creating(ExperimentCreation creation) + { + return "Creating experiment: " + creation.getCode() + " in project: " + creation.getProjectId(); + } + + public static String updating(IExperimentId experimentId) + { + return "Updating experiment: " + experimentId; + } + +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sample/SampleContextDescription.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sample/SampleContextDescription.java new file mode 100644 index 0000000000000000000000000000000000000000..6a4dfb98a9c187d6bfab10814c69a24c54f782a5 --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sample/SampleContextDescription.java @@ -0,0 +1,38 @@ +/* + * Copyright 2014 ETH Zuerich, Scientific IT Services + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.ethz.sis.openbis.generic.server.api.v3.helper.sample; + +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.sample.SampleCreation; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.sample.ISampleId; + +/** + * @author pkupczyk + */ +public class SampleContextDescription +{ + + public static String creating(SampleCreation creation) + { + return "Creating sample: " + creation.getCode() + " in space: " + creation.getSpaceId() + " in experiment: " + creation.getExperimentId(); + } + + public static String updating(ISampleId sampleId) + { + return "Updating sample: " + sampleId; + } + +} diff --git a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/AbstractTest.java b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/AbstractTest.java index 56bc7f476020f3ac7197a592149579a2cf0f14f8..92ca9ff9e2f86e81014ca44f73c4486001aa76a4 100644 --- a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/AbstractTest.java +++ b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/AbstractTest.java @@ -38,6 +38,7 @@ import ch.ethz.sis.openbis.generic.shared.api.v3.exceptions.ObjectNotFoundExcept import ch.ethz.sis.openbis.generic.shared.api.v3.exceptions.UnauthorizedObjectAccessException; import ch.systemsx.cisd.common.action.IDelegatedAction; import ch.systemsx.cisd.common.logging.BufferedAppender; +import ch.systemsx.cisd.common.test.AssertionUtil; import ch.systemsx.cisd.openbis.systemtest.SystemTestCase; /** @@ -363,6 +364,11 @@ public class AbstractTest extends SystemTestCase } protected void assertUnauthorizedObjectAccessException(IDelegatedAction action, IObjectId expectedObjectId) + { + assertUnauthorizedObjectAccessException(action, expectedObjectId, null); + } + + protected void assertUnauthorizedObjectAccessException(IDelegatedAction action, IObjectId expectedObjectId, String expectedContextDescription) { try { @@ -373,10 +379,19 @@ public class AbstractTest extends SystemTestCase assertNotNull(e.getCause()); assertEquals(e.getCause().getClass(), UnauthorizedObjectAccessException.class); assertEquals(((UnauthorizedObjectAccessException) e.getCause()).getObjectId(), expectedObjectId); + if (expectedContextDescription != null) + { + AssertionUtil.assertContains("(Context: [" + expectedContextDescription + "])", e.getMessage()); + } } } protected void assertObjectNotFoundException(IDelegatedAction action, IObjectId expectedObjectId) + { + assertObjectNotFoundException(action, expectedObjectId, null); + } + + protected void assertObjectNotFoundException(IDelegatedAction action, IObjectId expectedObjectId, String expectedContextDescription) { try { @@ -387,6 +402,10 @@ public class AbstractTest extends SystemTestCase assertNotNull(e.getCause()); assertEquals(e.getCause().getClass(), ObjectNotFoundException.class); assertEquals(((ObjectNotFoundException) e.getCause()).getObjectId(), expectedObjectId); + if (expectedContextDescription != null) + { + AssertionUtil.assertContains("(Context: [" + expectedContextDescription + "])", e.getMessage()); + } } } diff --git a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/CreateExperimentTest.java b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/CreateExperimentTest.java index c1c556d8f25aa82cb76dd75dbca0219e7dbe150c..8daa862e5e48a73fb3b12af143cf5b3d5d373554 100644 --- a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/CreateExperimentTest.java +++ b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/CreateExperimentTest.java @@ -28,6 +28,7 @@ import junit.framework.Assert; import org.testng.annotations.Test; +import ch.ethz.sis.openbis.generic.server.api.v3.helper.experiment.ExperimentContextDescription; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.attachment.Attachment; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.attachment.AttachmentCreation; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.experiment.Experiment; @@ -67,7 +68,7 @@ public class CreateExperimentTest extends AbstractExperimentTest { v3api.createExperiments(sessionToken, Arrays.asList(experiment)); } - }, projectId); + }, projectId, ExperimentContextDescription.creating(experiment)); } @Test @@ -88,7 +89,7 @@ public class CreateExperimentTest extends AbstractExperimentTest { v3api.createExperiments(sessionToken, Arrays.asList(experiment)); } - }, projectId); + }, projectId, ExperimentContextDescription.creating(experiment)); } @Test diff --git a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/UpdateExperimentTest.java b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/UpdateExperimentTest.java index 4d82484f8d909813ffab471395b4a58ac9612ac9..877f46f2e7e11b507e8add8df3fec43010e49f19 100644 --- a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/UpdateExperimentTest.java +++ b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/UpdateExperimentTest.java @@ -23,6 +23,7 @@ import java.util.List; import org.testng.annotations.Test; +import ch.ethz.sis.openbis.generic.server.api.v3.helper.experiment.ExperimentContextDescription; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.experiment.Experiment; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.experiment.ExperimentCreation; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.experiment.ExperimentUpdate; @@ -86,7 +87,7 @@ public class UpdateExperimentTest extends AbstractExperimentTest { v3api.updateExperiments(sessionToken, Arrays.asList(update)); } - }, experimentId); + }, experimentId, ExperimentContextDescription.updating(experimentId)); } @Test @@ -105,7 +106,7 @@ public class UpdateExperimentTest extends AbstractExperimentTest { v3api.updateExperiments(sessionToken, Arrays.asList(update)); } - }, experimentId); + }, experimentId, ExperimentContextDescription.updating(experimentId)); } @Test @@ -113,9 +114,10 @@ public class UpdateExperimentTest extends AbstractExperimentTest { final String sessionToken = v3api.login(TEST_SPACE_USER, PASSWORD); + final IExperimentId experimentId = new ExperimentPermId("200902091255058-1037"); final IProjectId projectId = new ProjectIdentifier("/CISD/NEMO"); final ExperimentUpdate update = new ExperimentUpdate(); - update.setExperimentId(new ExperimentPermId("200902091255058-1037")); + update.setExperimentId(experimentId); update.setProjectId(projectId); assertUnauthorizedObjectAccessException(new IDelegatedAction() @@ -125,7 +127,7 @@ public class UpdateExperimentTest extends AbstractExperimentTest { v3api.updateExperiments(sessionToken, Arrays.asList(update)); } - }, projectId); + }, projectId, ExperimentContextDescription.updating(experimentId)); } @Test @@ -133,9 +135,10 @@ public class UpdateExperimentTest extends AbstractExperimentTest { final String sessionToken = v3api.login(TEST_SPACE_USER, PASSWORD); + final IExperimentId experimentId = new ExperimentPermId("200902091255058-1037"); final IProjectId projectId = new ProjectIdentifier("IDONTEXIST"); final ExperimentUpdate update = new ExperimentUpdate(); - update.setExperimentId(new ExperimentPermId("200902091255058-1037")); + update.setExperimentId(experimentId); update.setProjectId(projectId); assertObjectNotFoundException(new IDelegatedAction() @@ -145,7 +148,7 @@ public class UpdateExperimentTest extends AbstractExperimentTest { v3api.updateExperiments(sessionToken, Arrays.asList(update)); } - }, projectId); + }, projectId, ExperimentContextDescription.updating(experimentId)); } @Test diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/exceptions/ObjectNotFoundException.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/exceptions/ObjectNotFoundException.java index 966dd8d3c53ac4cbfe034dd3201eb3f7b3ab835b..c9903a645c2b1a2c9b9689b150f19812f58b0346 100644 --- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/exceptions/ObjectNotFoundException.java +++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/exceptions/ObjectNotFoundException.java @@ -31,7 +31,7 @@ public class ObjectNotFoundException extends UserFailureException public ObjectNotFoundException(IObjectId id) { - super("Object with id [" + id + "] has not been found."); + super("Object with " + id.getClass().getSimpleName() + " = [" + id + "] has not been found."); this.objectId = id; } diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/exceptions/UnauthorizedObjectAccessException.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/exceptions/UnauthorizedObjectAccessException.java index 415184838d81cb75b576db5ca1105346eff10bd5..4bbf3d9952faf87e811d3cdf2424cc76bc9bbcca 100644 --- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/exceptions/UnauthorizedObjectAccessException.java +++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/exceptions/UnauthorizedObjectAccessException.java @@ -31,7 +31,7 @@ public class UnauthorizedObjectAccessException extends UserFailureException public UnauthorizedObjectAccessException(IObjectId id) { - super("Object with id [" + id + "] cannot be accessed."); + super("Access denied to object with " + id.getClass().getSimpleName() + " = [" + id + "]."); this.objectId = id; }