Skip to content
Snippets Groups Projects
Commit 067412d2 authored by pkupczyk's avatar pkupczyk
Browse files

SSDM-2706 : V3 AS API - create data sets (only metadata) - add registrator id + unauthorized tests

SVN: 34968
parent 8fbdb91c
No related branches found
No related tags found
No related merge requests found
......@@ -85,6 +85,9 @@ public class CreateDataSetExecutor extends AbstractCreateEntityExecutor<DataSetC
@Autowired
private ISetDataSetRelatedDataSetsExecutor setDataSetRelatedDataSetsExecutor;
@Autowired
private ISetDataSetRegistratorExecutor setDataSetRegistratorExecutor;
@Autowired
private IUpdateEntityPropertyExecutor updateEntityPropertyExecutor;
......@@ -153,7 +156,6 @@ public class CreateDataSetExecutor extends AbstractCreateEntityExecutor<DataSetC
dataSet.setCode(creation.getCode());
dataSet.setDataSetType(type);
dataSet.setDerived(false == creation.isMeasured());
dataSet.setRegistrator(context.getSession().tryGetPerson());
RelationshipUtils.updateModificationDateAndModifier(dataSet, context.getSession().tryGetPerson());
dataSets.add(dataSet);
......@@ -171,7 +173,7 @@ public class CreateDataSetExecutor extends AbstractCreateEntityExecutor<DataSetC
@Override
protected void checkAccess(IOperationContext context, DataPE entity)
{
if (false == new DataSetPEByExperimentOrSampleIdentifierValidator().doValidation(context.getSession().tryGetPerson(), entity))
if (false == new DataSetPEByExperimentOrSampleIdentifierValidator().doValidation(entity.getRegistrator(), entity))
{
throw new UnauthorizedObjectAccessException(new DataSetPermId(entity.getPermId()));
}
......@@ -191,6 +193,7 @@ public class CreateDataSetExecutor extends AbstractCreateEntityExecutor<DataSetC
setDataSetDataStoreExecutor.set(context, entitiesMap);
setDataSetExperimentExecutor.set(context, entitiesMap);
setDataSetSampleExecutor.set(context, entitiesMap);
setDataSetRegistratorExecutor.set(context, entitiesMap);
Map<IEntityPropertiesHolder, Map<String, String>> propertyMap = new HashMap<IEntityPropertiesHolder, Map<String, String>>();
for (Map.Entry<DataSetCreation, DataPE> entry : entitiesMap.entrySet())
......
/*
* Copyright 2015 ETH Zuerich, CISD
*
* 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.executor.dataset;
import java.util.Map;
import ch.ethz.sis.openbis.generic.server.api.v3.executor.IOperationContext;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.dataset.DataSetCreation;
import ch.systemsx.cisd.openbis.generic.shared.dto.DataPE;
/**
* @author pkupczyk
*/
public interface ISetDataSetRegistratorExecutor
{
void set(IOperationContext context, Map<DataSetCreation, DataPE> entitiesMap);
}
/*
* Copyright 2015 ETH Zuerich, CISD
*
* 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.executor.dataset;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
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.entity.AbstractSetEntityToOneRelationExecutor;
import ch.ethz.sis.openbis.generic.server.api.v3.executor.person.IMapPersonByIdExecutor;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.dataset.DataSetCreation;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.person.IPersonId;
import ch.systemsx.cisd.openbis.generic.shared.dto.DataPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE;
/**
* @author pkupczyk
*/
@Component
public class SetDataSetRegistratorExecutor extends AbstractSetEntityToOneRelationExecutor<DataSetCreation, DataPE, IPersonId, PersonPE> implements
ISetDataSetRegistratorExecutor
{
@Autowired
private IMapPersonByIdExecutor mapPersonByIdExecutor;
@Override
protected IPersonId getRelatedId(DataSetCreation creation)
{
return creation.getRegistratorId();
}
@Override
protected Map<IPersonId, PersonPE> map(IOperationContext context, List<IPersonId> relatedIds)
{
return mapPersonByIdExecutor.map(context, relatedIds);
}
@Override
protected void check(IOperationContext context, DataPE entity, IPersonId relatedId, PersonPE related)
{
}
@Override
protected void set(IOperationContext context, DataPE entity, PersonPE related)
{
if (related == null)
{
entity.setRegistrator(context.getSession().tryGetPerson());
} else
{
entity.setRegistrator(related);
}
}
}
......@@ -60,6 +60,7 @@ public abstract class AbstractSetEntityToOneRelationExecutor<ENTITY_CREATION, EN
if (relatedId == null)
{
check(context, entity, null, null);
set(context, entity, null);
} else
{
RELATED_PE related = relatedMap.get(relatedId);
......
......@@ -43,7 +43,10 @@ import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.entitytype.EntityTypePer
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.ExperimentIdentifier;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.experiment.ExperimentPermId;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.experiment.IExperimentId;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.person.PersonPermId;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.project.ProjectIdentifier;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.sample.ISampleId;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.sample.SampleIdentifier;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.sample.SamplePermId;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.space.SpacePermId;
......@@ -400,6 +403,27 @@ public class CreateDataSetTest extends AbstractDataSetTest
}, experimentIds.get(0));
}
@Test
public void testCreateWithExperimentUnauthorized()
{
final String sessionToken = v3api.login(TEST_USER, PASSWORD);
final IExperimentId experimentId = new ExperimentIdentifier("/CISD/NEMO/EXP1");
final DataSetCreation creation = dataSetCreation();
creation.setExperimentId(experimentId);
creation.setSampleId(null);
creation.setRegistratorId(new PersonPermId(TEST_SPACE_USER));
assertUnauthorizedObjectAccessException(new IDelegatedAction()
{
@Override
public void execute()
{
v3api.createDataSets(sessionToken, Arrays.asList(creation));
}
}, new DataSetPermId(creation.getCode()));
}
@Test
public void testCreateWithSampleInTrash()
{
......@@ -424,6 +448,27 @@ public class CreateDataSetTest extends AbstractDataSetTest
}, sampleIds.get(0));
}
@Test
public void testCreateWithSampleUnauthorized()
{
final String sessionToken = v3api.login(TEST_USER, PASSWORD);
final ISampleId sampleId = new SampleIdentifier("/CISD/CP-TEST-1");
final DataSetCreation creation = dataSetCreation();
creation.setExperimentId(null);
creation.setSampleId(sampleId);
creation.setRegistratorId(new PersonPermId(TEST_SPACE_USER));
assertUnauthorizedObjectAccessException(new IDelegatedAction()
{
@Override
public void execute()
{
v3api.createDataSets(sessionToken, Arrays.asList(creation));
}
}, new DataSetPermId(creation.getCode()));
}
@Test
public void testCreateWithSampleShared()
{
......@@ -554,9 +599,4 @@ public class CreateDataSetTest extends AbstractDataSetTest
return creation;
}
public static void main(String[] args)
{
System.out.println("REQUIRES_EXPERIMENT".matches("(?!REQUIRES\\_EXPERIMENT).*"));
}
}
......@@ -27,6 +27,7 @@ import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.dataset.IDataSetId;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.datastore.IDataStoreId;
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.IExperimentId;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.person.IPersonId;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.sample.ISampleId;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.tag.ITagId;
import ch.systemsx.cisd.base.annotation.JsonObject;
......@@ -67,6 +68,8 @@ public class DataSetCreation implements Serializable, ICreationIdHolder
private List<? extends IDataSetId> childIds;
private IPersonId registratorId;
private CreationId creationId;
public IEntityTypeId getTypeId()
......@@ -210,6 +213,16 @@ public class DataSetCreation implements Serializable, ICreationIdHolder
return properties;
}
public IPersonId getRegistratorId()
{
return registratorId;
}
public void setRegistratorId(IPersonId registratorId)
{
this.registratorId = registratorId;
}
@Override
public CreationId getCreationId()
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment