Search in sources :

Example 91 with EntityType

use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.

the class EntityIdentityUtilsTest method testToIdType.

@Test(dataProvider = "testToIdTypeProvider")
public void testToIdType(AttributeType attributeType, Class<?> expectedIdType) {
    EntityType entityType = mock(EntityType.class);
    Attribute idAttribute = when(mock(Attribute.class).getDataType()).thenReturn(attributeType).getMock();
    when(entityType.getIdAttribute()).thenReturn(idAttribute);
    assertEquals(EntityIdentityUtils.toIdType(entityType), expectedIdType);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Attribute(org.molgenis.data.meta.model.Attribute) Test(org.testng.annotations.Test)

Example 92 with EntityType

use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.

the class RestService method convertMref.

private List<?> convertMref(Attribute attr, Object paramValue) {
    List<?> value;
    if (paramValue != null) {
        List<?> mrefParamValues;
        if (paramValue instanceof String) {
            mrefParamValues = asList(StringUtils.split((String) paramValue, ','));
        } else if (paramValue instanceof List<?>) {
            mrefParamValues = (List<?>) paramValue;
        } else {
            throw new MolgenisDataException(format("Attribute [%s] value is of type [%s] instead of [%s] or [%s]", attr.getName(), paramValue.getClass().getSimpleName(), String.class.getSimpleName(), List.class.getSimpleName()));
        }
        EntityType mrefEntity = attr.getRefEntity();
        Attribute mrefEntityIdAttr = mrefEntity.getIdAttribute();
        value = mrefParamValues.stream().map(mrefParamValue -> toEntityValue(mrefEntityIdAttr, mrefParamValue, null)).map(mrefIdValue -> entityManager.getReference(mrefEntity, mrefIdValue)).collect(toList());
    } else {
        value = emptyList();
    }
    return value;
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) IdGenerator(org.molgenis.data.populate.IdGenerator) ONE_TO_MANY(org.molgenis.data.meta.AttributeType.ONE_TO_MANY) StringUtils(org.apache.commons.lang3.StringUtils) Attribute(org.molgenis.data.meta.model.Attribute) FileStore(org.molgenis.data.file.FileStore) FileDownloadController(org.molgenis.core.ui.file.FileDownloadController) FileMetaFactory(org.molgenis.data.file.model.FileMetaFactory) Service(org.springframework.stereotype.Service) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Collectors.toSet(java.util.stream.Collectors.toSet) POPULATE(org.molgenis.data.EntityManager.CreationMode.POPULATE) AttributeType(org.molgenis.data.meta.AttributeType) ServletUriComponentsBuilder(org.springframework.web.servlet.support.ServletUriComponentsBuilder) Collections.emptyList(java.util.Collections.emptyList) Set(java.util.Set) IOException(java.io.IOException) Instant(java.time.Instant) MolgenisDateFormat(org.molgenis.data.util.MolgenisDateFormat) EntityType(org.molgenis.data.meta.model.EntityType) FILENAME(org.molgenis.data.file.model.FileMetaMetaData.FILENAME) String.format(java.lang.String.format) UnexpectedEnumException(org.molgenis.util.UnexpectedEnumException) FileMeta(org.molgenis.data.file.model.FileMeta) FILE_META(org.molgenis.data.file.model.FileMetaMetaData.FILE_META) DateTimeParseException(java.time.format.DateTimeParseException) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) StreamSupport.stream(java.util.stream.StreamSupport.stream) LocalDate(java.time.LocalDate) DataService(org.molgenis.data.DataService) MultipartFile(org.springframework.web.multipart.MultipartFile) MolgenisDataException(org.molgenis.data.MolgenisDataException) EntityManager(org.molgenis.data.EntityManager) Entity(org.molgenis.data.Entity) UriComponents(org.springframework.web.util.UriComponents) MolgenisDataException(org.molgenis.data.MolgenisDataException) Attribute(org.molgenis.data.meta.model.Attribute) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList)

Example 93 with EntityType

use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.

the class RepositorySecurityDecorator method findOneById.

@Override
public Entity findOneById(Object id, Fetch fetch) {
    EntityType entityType = delegate().getEntityType();
    validatePermission(entityType, EntityTypePermission.READ);
    return delegate().findOneById(id, fetch);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType)

Example 94 with EntityType

use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.

the class RepositorySecurityDecorator method update.

@Override
public void update(Entity entity) {
    EntityType entityType = delegate().getEntityType();
    validatePermission(entityType, EntityTypePermission.WRITE);
    delegate().update(entity);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType)

Example 95 with EntityType

use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.

the class RepositorySecurityDecorator method forEachBatched.

@Override
public void forEachBatched(Fetch fetch, Consumer<List<Entity>> consumer, int batchSize) {
    EntityType entityType = delegate().getEntityType();
    validatePermission(entityType, EntityTypePermission.READ);
    delegate().forEachBatched(fetch, consumer, batchSize);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType)

Aggregations

EntityType (org.molgenis.data.meta.model.EntityType)581 Test (org.testng.annotations.Test)367 Attribute (org.molgenis.data.meta.model.Attribute)315 Entity (org.molgenis.data.Entity)98 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)71 DynamicEntity (org.molgenis.data.support.DynamicEntity)61 Stream (java.util.stream.Stream)44 EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)43 WithMockUser (org.springframework.security.test.context.support.WithMockUser)40 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)36 QueryImpl (org.molgenis.data.support.QueryImpl)33 Package (org.molgenis.data.meta.model.Package)32 Objects.requireNonNull (java.util.Objects.requireNonNull)22 Collectors.toList (java.util.stream.Collectors.toList)22 BeforeMethod (org.testng.annotations.BeforeMethod)20 AttributeType (org.molgenis.data.meta.AttributeType)19 List (java.util.List)17 String.format (java.lang.String.format)16 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)16 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)15