use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.
the class EmxMetaDataParser method parseEntitiesSheet.
/**
* Load all entities (optional)
*
* @param entitiesRepo the Repository for the entities
* @param intermediateResults {@link IntermediateParseResults} containing the attributes already parsed
*/
private void parseEntitiesSheet(Repository<Entity> entitiesRepo, IntermediateParseResults intermediateResults) {
if (entitiesRepo != null) {
for (Attribute attr : entitiesRepo.getEntityType().getAtomicAttributes()) {
if (!EMX_ENTITIES_ALLOWED_ATTRS.contains(attr.getName().toLowerCase()) && !(isI18n(attr.getName()) && (attr.getName().startsWith(EMX_ENTITIES_DESCRIPTION) || attr.getName().startsWith(EMX_ENTITIES_LABEL)))) {
throw new IllegalArgumentException("Unsupported entity metadata: entities." + attr.getName());
}
}
int i = 1;
for (Entity entity : entitiesRepo) {
i++;
String emxEntityName = entity.getString(EMX_ENTITIES_NAME);
String emxEntityPackage = entity.getString(EMX_ENTITIES_PACKAGE);
String emxEntityLabel = entity.getString(EMX_ENTITIES_LABEL);
String emxEntityDescription = entity.getString(EMX_ENTITIES_DESCRIPTION);
String emxEntityAbstract = entity.getString(EMX_ENTITIES_ABSTRACT);
String emxEntityExtends = entity.getString(EMX_ENTITIES_EXTENDS);
String emxEntityBackend = entity.getString(EMX_ENTITIES_BACKEND);
String emxEntityTags = entity.getString(EMX_ENTITIES_TAGS);
// required
if (emxEntityName == null) {
throw new IllegalArgumentException("entity.name is missing on line " + i);
}
String entityTypeId;
if (emxEntityPackage != null) {
entityTypeId = emxEntityPackage + PACKAGE_SEPARATOR + emxEntityName;
} else {
entityTypeId = emxEntityName;
}
EntityType entityType = intermediateResults.getEntityType(entityTypeId);
if (entityType == null) {
entityType = intermediateResults.addEntityType(entityTypeId);
}
if (dataService != null) {
if (emxEntityBackend != null) {
if (dataService.getMeta().getBackend(emxEntityBackend) == null) {
throw new MolgenisDataException("Unknown backend '" + emxEntityBackend + '\'');
}
} else {
emxEntityBackend = dataService.getMeta().getDefaultBackend().getName();
}
entityType.setBackend(emxEntityBackend);
}
if (emxEntityPackage != null) {
Package p = intermediateResults.getPackage(emxEntityPackage);
if (p == null) {
throw new MolgenisDataException("Unknown package: '" + emxEntityPackage + "' for entity '" + emxEntityName + "'. Please specify the package on the " + EMX_PACKAGES + " sheet and use the fully qualified package and entity names.");
}
entityType.setPackage(p);
}
if (emxEntityLabel == null) {
emxEntityLabel = emxEntityName;
}
entityType.setLabel(emxEntityLabel);
entityType.setDescription(emxEntityDescription);
for (String attributeName : entity.getAttributeNames()) {
if (isI18n(attributeName)) {
if (attributeName.startsWith(EMX_ENTITIES_DESCRIPTION)) {
String description = entity.getString(attributeName);
if (description != null) {
String languageCode = getLanguageCode(attributeName);
entityType.setDescription(languageCode, description);
}
} else if (attributeName.startsWith(EMX_ENTITIES_LABEL)) {
String label = entity.getString(attributeName);
if (label != null) {
String languageCode = getLanguageCode(attributeName);
entityType.setLabel(languageCode, label);
}
}
}
}
if (emxEntityAbstract != null) {
entityType.setAbstract(parseBoolean(emxEntityAbstract, i, EMX_ENTITIES_ABSTRACT));
}
if (emxEntityExtends != null) {
EntityType extendsEntityType = null;
if (intermediateResults.knowsEntity(emxEntityExtends)) {
extendsEntityType = intermediateResults.getEntityType(emxEntityExtends);
} else {
if (dataService != null) {
extendsEntityType = dataService.getMeta().getEntityType(emxEntityExtends);
}
}
if (extendsEntityType == null) {
throw new MolgenisDataException("Missing super entity " + emxEntityExtends + " for entity " + emxEntityName + " on line " + i);
}
entityType.setExtends(extendsEntityType);
}
List<String> tagIdentifiers = toList(emxEntityTags);
if (tagIdentifiers != null && !tagIdentifiers.isEmpty()) {
entityType.setTags(toTags(intermediateResults, tagIdentifiers));
}
}
}
}
use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.
the class EmxMetaDataParser method putEntitiesInDefaultPackage.
/**
* Put the entities that are not in a package in the selected package
*/
private List<EntityType> putEntitiesInDefaultPackage(IntermediateParseResults intermediateResults, String defaultPackageId) {
Package p = getPackage(intermediateResults, defaultPackageId);
if (p == null && dataService != null) {
throw new IllegalArgumentException(format("Unknown package [%s]", defaultPackageId));
}
List<EntityType> entities = newArrayList();
for (EntityType entityType : intermediateResults.getEntities()) {
if (entityType.getPackage() == null) {
entityType.setPackage(p);
}
entities.add(entityType);
}
return entities;
}
use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.
the class SystemEntityTypePersisterTest method removeNonExistingSystemEntities.
@Test
public void removeNonExistingSystemEntities() throws Exception {
Package systemPackage = mock(Package.class);
when(systemPackage.getId()).thenReturn(PACKAGE_SYSTEM);
EntityType refRemovedMeta = when(mock(EntityType.class).getId()).thenReturn("refRemoved").getMock();
when(refRemovedMeta.getPackage()).thenReturn(systemPackage);
when(refRemovedMeta.toString()).thenReturn("refRemoved");
when(refRemovedMeta.getAtomicAttributes()).thenReturn(emptyList());
EntityType removedMeta = when(mock(EntityType.class).getId()).thenReturn("removed").getMock();
when(removedMeta.getPackage()).thenReturn(systemPackage);
when(removedMeta.toString()).thenReturn("removed");
Attribute refAttr = when(mock(Attribute.class).getRefEntity()).thenReturn(refRemovedMeta).getMock();
when(removedMeta.getAtomicAttributes()).thenReturn(singletonList(refAttr));
EntityType refEntityType = when(mock(EntityType.class).getId()).thenReturn("refEntity").getMock();
when(refEntityType.getPackage()).thenReturn(systemPackage);
when(refEntityType.toString()).thenReturn("refEntity");
when(refEntityType.getAtomicAttributes()).thenReturn(emptyList());
EntityType entityType = when(mock(EntityType.class).getId()).thenReturn("entity").getMock();
when(entityType.getPackage()).thenReturn(systemPackage);
when(entityType.toString()).thenReturn("entity");
when(entityType.getAtomicAttributes()).thenReturn(emptyList());
when(systemEntityTypeRegistry.hasSystemEntityType("removed")).thenReturn(false);
when(systemEntityTypeRegistry.hasSystemEntityType("refRemoved")).thenReturn(false);
when(systemEntityTypeRegistry.hasSystemEntityType("entity")).thenReturn(true);
when(systemEntityTypeRegistry.hasSystemEntityType("refEntity")).thenReturn(true);
when(dataService.findAll(ENTITY_TYPE_META_DATA, EntityType.class)).thenReturn(Stream.of(refEntityType, entityType, refRemovedMeta, removedMeta));
systemEntityTypePersister.removeNonExistingSystemEntityTypes();
verify(metaDataService).deleteEntityType(newArrayList(refRemovedMeta, removedMeta));
}
use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.
the class PackageRepositoryValidationDecoratorTest method testDeleteInvalid.
@Test(expectedExceptions = MolgenisValidationException.class)
public void testDeleteInvalid() throws Exception {
Package package_ = mock(Package.class);
doThrow(mock(MolgenisValidationException.class)).when(packageValidator).validate(package_);
packageRepositoryValidationDecorator.delete(package_);
}
use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.
the class PackageRepositoryValidationDecoratorTest method testAddInvalid.
@Test(expectedExceptions = MolgenisValidationException.class)
public void testAddInvalid() throws Exception {
Package package_ = mock(Package.class);
doThrow(mock(MolgenisValidationException.class)).when(packageValidator).validate(package_);
packageRepositoryValidationDecorator.add(package_);
}
Aggregations