use of org.molgenis.data.UnknownPackageException in project molgenis by molgenis.
the class EmxMetadataParser method putEntitiesInDefaultPackage.
/**
* Put the entities that are not in a package in the selected package
*/
List<EntityType> putEntitiesInDefaultPackage(IntermediateParseResults intermediateResults, String defaultPackageId) {
Package p = getPackage(intermediateResults, defaultPackageId);
if (p == null) {
throw new UnknownPackageException(defaultPackageId);
}
List<EntityType> entities = newArrayList();
for (EntityType entityType : intermediateResults.getEntityTypes()) {
if (entityType.getPackage() == null) {
entityType.setId(defaultPackageId + PACKAGE_SEPARATOR + entityType.getId());
entityType.setPackage(p);
}
entities.add(entityType);
}
return entities;
}
use of org.molgenis.data.UnknownPackageException in project molgenis by molgenis.
the class EmxMetadataParser method setPackage.
private void setPackage(IntermediateParseResults intermediateResults, int rowIndex, String emxEntityPackage, EntityType entityType) {
Package p = intermediateResults.getPackage(emxEntityPackage);
if (p == null) {
throw new EmxImportException(new UnknownPackageException(emxEntityPackage), EMX_ENTITIES, rowIndex);
}
entityType.setPackage(p);
}
use of org.molgenis.data.UnknownPackageException in project molgenis by molgenis.
the class EntityTypeRequestMapperImpl method updateEntityType.
@SuppressWarnings({ "java:S1192" })
private // ATTRIBUTES constant in this class is not related to the one in this switch
void updateEntityType(EntityType entityType, Entry<String, Object> entry) {
switch(entry.getKey()) {
case "package":
String packageId = String.valueOf(entry.getValue());
Package pack = metaDataService.getPackage(packageId).orElseThrow(() -> new UnknownPackageException(packageId));
entityType.setPackage(pack);
break;
case "id":
case "abstract":
throw new ReadOnlyFieldException(entry.getKey(), "entityType");
case "extends":
String extendsValue = String.valueOf(entry.getValue());
EntityType parent = metaDataService.getEntityType(extendsValue).orElseThrow(() -> new UnknownEntityTypeException(extendsValue));
entityType.setExtends(parent);
break;
case "label":
I18nValue label = I18nValueMapper.toI18nValue(entry.getValue());
processI18nLabel(label, entityType);
break;
case "description":
I18nValue description = I18nValueMapper.toI18nValue(entry.getValue());
processI18nDescription(description, entityType);
break;
case "attributes":
if (entry.getValue() != null) {
Iterable<Attribute> attributes = mapAttributes(entityType, entry);
entityType.setOwnAllAttributes(attributes);
} else {
throw new EmptyAttributesException();
}
break;
case "tags":
case "backend":
throw new UnsupportedFieldException(entry.getKey());
default:
throw new InvalidKeyException("entityType", entry.getKey());
}
}
use of org.molgenis.data.UnknownPackageException in project molgenis by molgenis.
the class EntityTypeRequestMapperImpl method toEntityType.
@Override
public EntityType toEntityType(CreateEntityTypeRequest entityTypeRequest) {
EntityType entityType = entityTypeFactory.create();
String entityTypeId = entityTypeRequest.getId();
if (entityTypeId != null) {
entityType.setId(entityTypeId);
}
String packageId = entityTypeRequest.getPackage();
Package pack = null;
if (packageId != null) {
pack = metaDataService.getPackage(packageId).orElseThrow(() -> new UnknownPackageException(entityTypeRequest.getPackage()));
}
entityType.setPackage(pack);
String extendsEntityTypeId = entityTypeRequest.getExtends();
if (extendsEntityTypeId != null) {
EntityType extendsEntityType = metaDataService.getEntityType(extendsEntityTypeId).orElseThrow(() -> new UnknownEntityTypeException(extendsEntityTypeId));
entityType.setExtends(extendsEntityType);
}
processI18nLabel(entityTypeRequest.getLabel(), entityType);
processI18nDescription(entityTypeRequest.getDescription(), entityType);
List<Attribute> ownAttributes = attributeRequestMapper.toAttributes(entityTypeRequest.getAttributes(), entityTypeRequest, entityType);
entityType.setOwnAllAttributes(ownAttributes);
Boolean abstractEntityType = entityTypeRequest.getAbstract();
if (abstractEntityType != null) {
entityType.setAbstract(abstractEntityType);
}
entityType.setBackend(metaDataService.getDefaultBackend().getName());
processSelfReferencingAttributes(entityType, ownAttributes);
return entityType;
}
Aggregations