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;
}
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));
}
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);
}
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);
}
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;
}
Aggregations