Search in sources :

Example 46 with EntityType

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

the class OneClickImportJob method getEntityType.

@Transactional
public List<EntityType> getEntityType(Progress progress, String filename) throws UnknownFileTypeException, IOException, InvalidFormatException, EmptySheetException {
    File file = fileStore.getFile(filename);
    String fileExtension = findExtensionFromPossibilities(filename, newHashSet("csv", "xlsx", "zip", "xls"));
    progress.status("Preparing import");
    List<DataCollection> dataCollections = newArrayList();
    if (fileExtension == null) {
        throw new UnknownFileTypeException(String.format("File [%s] does not have a valid extension, supported: [csv, xlsx, zip, xls]", filename));
    } else if (fileExtension.equals("xls") || fileExtension.equals("xlsx")) {
        List<Sheet> sheets = excelService.buildExcelSheetsFromFile(file);
        dataCollections.addAll(oneClickImporterService.buildDataCollectionsFromExcel(sheets));
    } else if (fileExtension.equals("csv")) {
        List<String[]> lines = csvService.buildLinesFromFile(file);
        dataCollections.add(oneClickImporterService.buildDataCollectionFromCsv(oneClickImporterNamingService.createValidIdFromFileName(filename), lines));
    } else if (fileExtension.equals("zip")) {
        List<File> filesInZip = unzip(file);
        for (File fileInZip : filesInZip) {
            String fileInZipExtension = findExtensionFromPossibilities(fileInZip.getName(), newHashSet("csv"));
            if (fileInZipExtension != null) {
                List<String[]> lines = csvService.buildLinesFromFile(fileInZip);
                dataCollections.add(oneClickImporterService.buildDataCollectionFromCsv(oneClickImporterNamingService.createValidIdFromFileName(fileInZip.getName()), lines));
            } else {
                throw new UnknownFileTypeException("Zip file contains files which are not of type CSV");
            }
        }
    }
    List<EntityType> entityTypes = newArrayList();
    String packageName = oneClickImporterNamingService.createValidIdFromFileName(filename);
    dataCollections.forEach(dataCollection -> {
        progress.status("Importing [" + dataCollection.getName() + "] into package [" + packageName + "]");
        entityTypes.add(entityService.createEntityType(dataCollection, packageName));
    });
    return entityTypes;
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) DataCollection(org.molgenis.oneclickimporter.model.DataCollection) UnknownFileTypeException(org.molgenis.oneclickimporter.exceptions.UnknownFileTypeException) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) File(java.io.File) Transactional(org.springframework.transaction.annotation.Transactional)

Example 47 with EntityType

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

the class MetadataManagerServiceImpl method upsertEntityType.

@Override
public void upsertEntityType(EditorEntityType editorEntityType) {
    EntityType entityType = entityTypeMapper.toEntityType(editorEntityType);
    metadataService.upsertEntityTypes(newArrayList(entityType));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType)

Example 48 with EntityType

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

the class EntityTypeParentMapperTest method testToEntityTypeReference.

@Test
public void testToEntityTypeReference() {
    String id = "id";
    String label = "label";
    @SuppressWarnings("unchecked") List<EditorAttributeIdentifier> attributes = mock(List.class);
    EditorEntityTypeParent parent = mock(EditorEntityTypeParent.class);
    EditorEntityTypeParent editorEntityTypeParent = EditorEntityTypeParent.create(id, label, attributes, parent);
    EntityType entityType = entityTypeParentMapper.toEntityTypeReference(editorEntityTypeParent);
    assertEquals(entityType.getIdValue(), id);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EditorAttributeIdentifier(org.molgenis.metadata.manager.model.EditorAttributeIdentifier) EditorEntityTypeParent(org.molgenis.metadata.manager.model.EditorEntityTypeParent) Test(org.testng.annotations.Test)

Example 49 with EntityType

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

the class PermissionManagerController method toEntityTypePermissions.

private Permissions toEntityTypePermissions(List<EntityType> entityTypes, Map<ObjectIdentity, Acl> aclMap, Sid sid) {
    Permissions permissions = new Permissions();
    // set permissions: entity ids
    Map<String, String> entityTypeMap = entityTypes.stream().collect(toMap(EntityType::getId, EntityType::getId, (u, v) -> {
        throw new IllegalStateException(format("Duplicate key %s", u));
    }, LinkedHashMap::new));
    permissions.setEntityIds(entityTypeMap);
    return toEntityTypePermissions(aclMap, sid, permissions);
}
Also used : PluginController(org.molgenis.web.PluginController) java.util(java.util) EntityTypeMetadata(org.molgenis.data.meta.model.EntityTypeMetadata) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) WebRequest(org.springframework.web.context.request.WebRequest) LoggerFactory(org.slf4j.LoggerFactory) PackageMetadata(org.molgenis.data.meta.model.PackageMetadata) Controller(org.springframework.stereotype.Controller) Collections.singletonList(java.util.Collections.singletonList) Valid(javax.validation.Valid) User(org.molgenis.data.security.auth.User) Model(org.springframework.ui.Model) Lists(com.google.common.collect.Lists) ANONYMOUS_USERNAME(org.molgenis.security.core.utils.SecurityUtils.ANONYMOUS_USERNAME) Collectors.toMap(java.util.stream.Collectors.toMap) USER(org.molgenis.data.security.auth.UserMetaData.USER) PluginPermission(org.molgenis.data.plugin.model.PluginPermission) Objects.requireNonNull(java.util.Objects.requireNonNull) PluginIdentity(org.molgenis.data.plugin.model.PluginIdentity) SystemEntityTypeRegistry(org.molgenis.data.meta.system.SystemEntityTypeRegistry) org.springframework.security.acls.model(org.springframework.security.acls.model) Comparator.comparing(java.util.Comparator.comparing) URI(org.molgenis.core.ui.admin.permission.PermissionManagerController.URI) SidUtils(org.molgenis.security.acl.SidUtils) Logger(org.slf4j.Logger) USERNAME(org.molgenis.data.security.auth.UserMetaData.USERNAME) org.molgenis.data.security(org.molgenis.data.security) SidUtils.createAnonymousSid(org.molgenis.security.acl.SidUtils.createAnonymousSid) EntityType(org.molgenis.data.meta.model.EntityType) Collectors(java.util.stream.Collectors) MutableAclClassService(org.molgenis.security.acl.MutableAclClassService) String.format(java.lang.String.format) GrantedAuthoritySid(org.springframework.security.acls.domain.GrantedAuthoritySid) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) HttpStatus(org.springframework.http.HttpStatus) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) GROUP(org.molgenis.data.security.auth.GroupMetaData.GROUP) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) DataService(org.molgenis.data.DataService) Package(org.molgenis.data.meta.model.Package) Group(org.molgenis.data.security.auth.Group) PLUGIN(org.molgenis.data.plugin.model.PluginMetadata.PLUGIN) Permissions(org.molgenis.security.permission.Permissions) Plugin(org.molgenis.data.plugin.model.Plugin) Transactional(org.springframework.transaction.annotation.Transactional) Permissions(org.molgenis.security.permission.Permissions)

Example 50 with EntityType

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

the class MolgenisRSQLVisitor method getAttribute.

private Attribute getAttribute(ComparisonNode node) {
    String attrName = node.getSelector();
    String[] attrTokens = attrName.split("\\.");
    Attribute attr = entityType.getAttribute(attrTokens[0]);
    if (attr == null) {
        throw new UnknownAttributeException(entityType, attrName);
    }
    EntityType entityTypeAtDepth;
    for (int i = 1; i < attrTokens.length; ++i) {
        entityTypeAtDepth = attr.getRefEntity();
        attr = entityTypeAtDepth.getAttribute(attrTokens[i]);
        if (attr == null) {
            throw new UnknownAttributeException(entityTypeAtDepth, attrName);
        }
    }
    return attr;
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Attribute(org.molgenis.data.meta.model.Attribute) UnknownAttributeException(org.molgenis.data.UnknownAttributeException)

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