Skip to content

Commit

Permalink
feat(#1): added globally unique locale specific attributes support
Browse files Browse the repository at this point in the history
  • Loading branch information
tpz committed Dec 7, 2023
1 parent 64e8bd9 commit 5539e08
Show file tree
Hide file tree
Showing 45 changed files with 548 additions and 236 deletions.
55 changes: 54 additions & 1 deletion EvitaDB.Client/Converters/Models/EvitaEnumConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using EvitaDB.Client.Models.Data;
using EvitaDB.Client.Models.Data.Mutations;
using EvitaDB.Client.Models.Schemas;
using EvitaDB.Client.Models.Schemas.Dtos;
using EvitaDB.Client.Queries.Filter;
using EvitaDB.Client.Queries.Order;
using EvitaDB.Client.Queries.Requires;
Expand Down Expand Up @@ -473,4 +474,56 @@ public static GrpcOperation ToGrpcOperation(Operation operation)
_ => throw new ArgumentOutOfRangeException(nameof(operation), operation, null)
};
}
}

public static AttributeUniquenessType ToAttributeUniquenessType(
GrpcAttributeUniquenessType grpcAttributeUniquenessType)
{
return grpcAttributeUniquenessType switch
{
GrpcAttributeUniquenessType.NotUnique => AttributeUniquenessType.NotUnique,
GrpcAttributeUniquenessType.UniqueWithinCollection => AttributeUniquenessType.UniqueWithinCollection,
GrpcAttributeUniquenessType.UniqueWithinCollectionLocale =>
AttributeUniquenessType.UniqueWithinCollectionLocale,
_ => throw new EvitaInternalError("Unrecognized remote attribute uniqueness type: " +
grpcAttributeUniquenessType)
};
}

public static GrpcAttributeUniquenessType ToGrpcAttributeUniquenessType(
AttributeUniquenessType attributeUniquenessType)
{
return attributeUniquenessType switch
{
AttributeUniquenessType.NotUnique => GrpcAttributeUniquenessType.NotUnique,
AttributeUniquenessType.UniqueWithinCollection => GrpcAttributeUniquenessType.UniqueWithinCollection,
AttributeUniquenessType.UniqueWithinCollectionLocale =>
GrpcAttributeUniquenessType.UniqueWithinCollectionLocale,
_ => throw new EvitaInternalError("Unrecognized attribute uniqueness type: " + attributeUniquenessType)
};
}

public static GlobalAttributeUniquenessType ToGlobalAttributeUniquenessType(
GrpcGlobalAttributeUniquenessType grpcGlobalAttributeUniquenessType)
{
return grpcGlobalAttributeUniquenessType switch
{
GrpcGlobalAttributeUniquenessType.NotGloballyUnique => GlobalAttributeUniquenessType.NotUnique,
GrpcGlobalAttributeUniquenessType.UniqueWithinCatalog => GlobalAttributeUniquenessType.UniqueWithinCatalog,
GrpcGlobalAttributeUniquenessType.UniqueWithinCatalogLocale => GlobalAttributeUniquenessType.UniqueWithinCatalogLocale,
_ => throw new EvitaInternalError("Unrecognized remote global attribute uniqueness type: " +
grpcGlobalAttributeUniquenessType)
};
}

public static GrpcGlobalAttributeUniquenessType ToGrpcGlobalAttributeUniquenessType(
GlobalAttributeUniquenessType globalAttributeUniquenessType)
{
return globalAttributeUniquenessType switch
{
GlobalAttributeUniquenessType.NotUnique => GrpcGlobalAttributeUniquenessType.NotGloballyUnique,
GlobalAttributeUniquenessType.UniqueWithinCatalog => GrpcGlobalAttributeUniquenessType.UniqueWithinCatalog,
GlobalAttributeUniquenessType.UniqueWithinCatalogLocale => GrpcGlobalAttributeUniquenessType.UniqueWithinCatalogLocale,
_ => throw new EvitaInternalError("Unrecognized global attribute uniqueness type: " + globalAttributeUniquenessType)
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ private static GrpcGlobalAttributeSchema ToGrpcGlobalAttributeSchema(
return new GrpcGlobalAttributeSchema
{
Name = attributeSchema.Name,
Unique = attributeSchema.Unique,
UniqueGlobally = attributeSchema.UniqueGlobally,
Unique = EvitaEnumConverter.ToGrpcAttributeUniquenessType(attributeSchema.UniquenessType),
UniqueGlobally = EvitaEnumConverter.ToGrpcGlobalAttributeUniquenessType(attributeSchema.GlobalUniquenessType),
Filterable = attributeSchema.Filterable,
Sortable = attributeSchema.Sortable,
Localized = attributeSchema.Localized,
Expand All @@ -79,8 +79,8 @@ private static IGlobalAttributeSchema ToGlobalAttributeSchema(
attributeSchema.Name,
attributeSchema.Description,
attributeSchema.DeprecationNotice,
attributeSchema.Unique,
attributeSchema.UniqueGlobally,
EvitaEnumConverter.ToAttributeUniquenessType(attributeSchema.Unique),
EvitaEnumConverter.ToGlobalAttributeUniquenessType(attributeSchema.UniqueGlobally),
attributeSchema.Filterable,
attributeSchema.Sortable,
attributeSchema.Localized,
Expand All @@ -93,4 +93,4 @@ attributeSchema.DefaultValue is not null
attributeSchema.IndexedDecimalPlaces
);
}
}
}
64 changes: 37 additions & 27 deletions EvitaDB.Client/Converters/Models/Schema/EntitySchemaConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ public static GrpcEntitySchema Convert(IEntitySchema entitySchema)
WithHierarchy = entitySchema.WithHierarchy,
WithPrice = entitySchema.WithPrice,
IndexedPricePlaces = entitySchema.IndexedPricePlaces,
Locales = {entitySchema.Locales.Select(EvitaDataTypesConverter.ToGrpcLocale)},
Currencies = {entitySchema.Currencies.Select(EvitaDataTypesConverter.ToGrpcCurrency)},
Attributes = {ToGrpcAttributeSchemas(entitySchema.Attributes)},
AssociatedData = {ToGrpcAssociatedDataSchemas(entitySchema.AssociatedData)},
References = {ToGrpcReferenceSchemas(entitySchema.References)},
EvolutionMode = {entitySchema.EvolutionModes.Select(EvitaEnumConverter.ToGrpcEvolutionMode)},
Locales = { entitySchema.Locales.Select(EvitaDataTypesConverter.ToGrpcLocale) },
Currencies = { entitySchema.Currencies.Select(EvitaDataTypesConverter.ToGrpcCurrency) },
Attributes = { ToGrpcAttributeSchemas(entitySchema.Attributes) },
AssociatedData = { ToGrpcAssociatedDataSchemas(entitySchema.AssociatedData) },
References = { ToGrpcReferenceSchemas(entitySchema.References) },
EvolutionMode = { entitySchema.EvolutionModes.Select(EvitaEnumConverter.ToGrpcEvolutionMode) },
SortableAttributeCompounds =
{ToGrpcSortableAttributeCompoundSchemas(entitySchema.GetSortableAttributeCompounds())},
{
ToGrpcSortableAttributeCompoundSchemas(entitySchema.GetSortableAttributeCompounds())
},
Version = entitySchema.Version,
};
}
Expand Down Expand Up @@ -74,8 +76,8 @@ private static T ToAttributeSchema<T>(GrpcAttributeSchema attributeSchema) where
NamingConventionHelper.Generate(attributeSchema.Name),
string.IsNullOrEmpty(attributeSchema.Description) ? null : attributeSchema.Description,
string.IsNullOrEmpty(attributeSchema.DeprecationNotice) ? null : attributeSchema.DeprecationNotice,
attributeSchema.Unique,
attributeSchema.UniqueGlobally,
EvitaEnumConverter.ToAttributeUniquenessType(attributeSchema.Unique),
EvitaEnumConverter.ToGlobalAttributeUniquenessType(attributeSchema.UniqueGlobally),
attributeSchema.Filterable,
attributeSchema.Sortable,
attributeSchema.Localized,
Expand All @@ -88,7 +90,9 @@ attributeSchema.DefaultValue is null
attributeSchema.IndexedDecimalPlaces
) as T)!;
}
throw new EvitaInvalidUsageException("Expected global attribute, but `" + attributeSchema.SchemaType + "` was provided!");

throw new EvitaInvalidUsageException("Expected global attribute, but `" + attributeSchema.SchemaType +
"` was provided!");
}

if (attributeSchema.SchemaType == GrpcAttributeSchemaType.Entity)
Expand All @@ -100,7 +104,7 @@ attributeSchema.DefaultValue is null
NamingConventionHelper.Generate(attributeSchema.Name),
string.IsNullOrEmpty(attributeSchema.Description) ? null : attributeSchema.Description,
string.IsNullOrEmpty(attributeSchema.DeprecationNotice) ? null : attributeSchema.DeprecationNotice,
attributeSchema.Unique,
EvitaEnumConverter.ToAttributeUniquenessType(attributeSchema.Unique),
attributeSchema.Filterable,
attributeSchema.Sortable,
attributeSchema.Localized,
Expand All @@ -113,15 +117,17 @@ attributeSchema.DefaultValue is null
attributeSchema.IndexedDecimalPlaces
) as T)!;
}
throw new EvitaInvalidUsageException("Expected entity attribute, but `" + attributeSchema.SchemaType + "` was provided!");

throw new EvitaInvalidUsageException("Expected entity attribute, but `" + attributeSchema.SchemaType +
"` was provided!");
}

return (AttributeSchema.InternalBuild(
attributeSchema.Name,
NamingConventionHelper.Generate(attributeSchema.Name),
string.IsNullOrEmpty(attributeSchema.Description) ? null : attributeSchema.Description,
string.IsNullOrEmpty(attributeSchema.DeprecationNotice) ? null : attributeSchema.DeprecationNotice,
attributeSchema.Unique,
EvitaEnumConverter.ToAttributeUniquenessType(attributeSchema.Unique),
attributeSchema.Filterable,
attributeSchema.Sortable,
attributeSchema.Localized,
Expand Down Expand Up @@ -200,7 +206,7 @@ private static GrpcSortableAttributeCompoundSchema ToGrpcSortableAttributeCompou
return new GrpcSortableAttributeCompoundSchema
{
Name = attributeSchema.Name,
AttributeElements = {ToGrpcAttributeElement(attributeSchema.AttributeElements)},
AttributeElements = { ToGrpcAttributeElement(attributeSchema.AttributeElements) },
Description = attributeSchema.Description,
DeprecationNotice = attributeSchema.DeprecationNotice
};
Expand Down Expand Up @@ -259,8 +265,7 @@ private static GrpcAttributeSchema ToGrpcAttributeSchema(IAttributeSchema attrib
GrpcAttributeSchema grpcAttributeSchema = new GrpcAttributeSchema
{
Name = attributeSchema.Name,
Unique = attributeSchema.Unique,
UniqueGlobally = isGlobal && ((IGlobalAttributeSchema) attributeSchema).UniqueGlobally,
Unique = EvitaEnumConverter.ToGrpcAttributeUniquenessType(attributeSchema.UniquenessType),
Filterable = attributeSchema.Filterable,
Sortable = attributeSchema.Sortable,
Localized = attributeSchema.Localized,
Expand All @@ -273,16 +278,19 @@ private static GrpcAttributeSchema ToGrpcAttributeSchema(IAttributeSchema attrib
Description = attributeSchema.Description,
DeprecationNotice = attributeSchema.DeprecationNotice
};

if (isEntity) {
IEntityAttributeSchema globalAttributeSchema = (IEntityAttributeSchema) attributeSchema;

if (isEntity)
{
IEntityAttributeSchema globalAttributeSchema = (IEntityAttributeSchema)attributeSchema;
grpcAttributeSchema.Representative = globalAttributeSchema.Representative;
}

if (isGlobal) {
IGlobalAttributeSchema globalAttributeSchema = (IGlobalAttributeSchema) attributeSchema;
grpcAttributeSchema.Representative= globalAttributeSchema.Representative;
grpcAttributeSchema.UniqueGlobally= globalAttributeSchema.UniqueGlobally;
if (isGlobal)
{
IGlobalAttributeSchema globalAttributeSchema = (IGlobalAttributeSchema)attributeSchema;
grpcAttributeSchema.Representative = globalAttributeSchema.Representative;
grpcAttributeSchema.UniqueGlobally =
EvitaEnumConverter.ToGrpcGlobalAttributeUniquenessType(globalAttributeSchema.GlobalUniquenessType);
}

return grpcAttributeSchema;
Expand Down Expand Up @@ -338,11 +346,13 @@ private static GrpcReferenceSchema ToGrpcReferenceSchema(IReferenceSchema refere
GroupTypeRelatesToEntity = referenceSchema.ReferencedGroupTypeManaged,
Indexed = referenceSchema.IsIndexed,
Faceted = referenceSchema.IsFaceted,
Attributes = {ToGrpcAttributeSchemas(referenceSchema.GetAttributes())},
Attributes = { ToGrpcAttributeSchemas(referenceSchema.GetAttributes()) },
SortableAttributeCompounds =
{ToGrpcSortableAttributeCompoundSchemas(referenceSchema.GetSortableAttributeCompounds())},
{
ToGrpcSortableAttributeCompoundSchemas(referenceSchema.GetSortableAttributeCompounds())
},
Description = referenceSchema.Description,
DeprecationNotice = referenceSchema.DeprecationNotice
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public GrpcCreateAttributeSchemaMutation Convert(CreateAttributeSchemaMutation m
return new GrpcCreateAttributeSchemaMutation
{
Name = mutation.Name,
Unique = mutation.Unique,
Unique = EvitaEnumConverter.ToGrpcAttributeUniquenessType(mutation.Unique),
Filterable = mutation.Filterable,
Sortable = mutation.Sortable,
Localized = mutation.Localized,
Expand All @@ -30,7 +30,7 @@ public CreateAttributeSchemaMutation Convert(GrpcCreateAttributeSchemaMutation m
mutation.Name,
mutation.Description,
mutation.DeprecationNotice,
mutation.Unique,
EvitaEnumConverter.ToAttributeUniquenessType(mutation.Unique),
mutation.Filterable,
mutation.Sortable,
mutation.Localized,
Expand All @@ -41,4 +41,4 @@ public CreateAttributeSchemaMutation Convert(GrpcCreateAttributeSchemaMutation m
mutation.IndexedDecimalPlaces
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public GrpcCreateGlobalAttributeSchemaMutation Convert(CreateGlobalAttributeSche
Name = mutation.Name,
Description = mutation.Description,
DeprecationNotice = mutation.DeprecationNotice,
Unique = mutation.Unique,
UniqueGlobally = mutation.UniqueGlobally,
Unique = EvitaEnumConverter.ToGrpcAttributeUniquenessType(mutation.Unique),
UniqueGlobally = EvitaEnumConverter.ToGrpcGlobalAttributeUniquenessType(mutation.UniqueGlobally),
Filterable = mutation.Filterable,
Sortable = mutation.Sortable,
Localized = mutation.Localized,
Expand All @@ -31,9 +31,11 @@ public GrpcCreateGlobalAttributeSchemaMutation Convert(CreateGlobalAttributeSche
public CreateGlobalAttributeSchemaMutation Convert(GrpcCreateGlobalAttributeSchemaMutation mutation)
{
return new CreateGlobalAttributeSchemaMutation(mutation.Name, mutation.Description, mutation.DeprecationNotice,
mutation.Unique, mutation.UniqueGlobally, mutation.Filterable, mutation.Sortable, mutation.Localized,
EvitaEnumConverter.ToAttributeUniquenessType(mutation.Unique),
EvitaEnumConverter.ToGlobalAttributeUniquenessType(mutation.UniqueGlobally), mutation.Filterable,
mutation.Sortable, mutation.Localized,
mutation.Nullable, mutation.Representative, EvitaDataTypesConverter.ToEvitaDataType(mutation.Type),
mutation.DefaultValue is not null ? EvitaDataTypesConverter.ToEvitaValue(mutation.DefaultValue) : null,
mutation.IndexedDecimalPlaces);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ public GrpcSetAttributeSchemaGloballyUniqueMutation Convert(SetAttributeSchemaGl
return new GrpcSetAttributeSchemaGloballyUniqueMutation
{
Name = mutation.Name,
UniqueGlobally = mutation.UniqueGlobally
UniqueGlobally = EvitaEnumConverter.ToGrpcGlobalAttributeUniquenessType(mutation.UniqueGlobally)
};
}

public SetAttributeSchemaGloballyUniqueMutation Convert(GrpcSetAttributeSchemaGloballyUniqueMutation mutation)
{
return new SetAttributeSchemaGloballyUniqueMutation(mutation.Name, mutation.UniqueGlobally);
return new SetAttributeSchemaGloballyUniqueMutation(mutation.Name,
EvitaEnumConverter.ToGlobalAttributeUniquenessType(mutation.UniqueGlobally));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ public GrpcSetAttributeSchemaUniqueMutation Convert(SetAttributeSchemaUniqueMuta
return new GrpcSetAttributeSchemaUniqueMutation
{
Name = mutation.Name,
Unique = mutation.Unique
Unique = EvitaEnumConverter.ToGrpcAttributeUniquenessType(mutation.Unique)
};
}

public SetAttributeSchemaUniqueMutation Convert(GrpcSetAttributeSchemaUniqueMutation mutation)
{
return new SetAttributeSchemaUniqueMutation(mutation.Name, mutation.Unique);
return new SetAttributeSchemaUniqueMutation(mutation.Name, EvitaEnumConverter.ToAttributeUniquenessType(mutation.Unique));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public GrpcLocalCatalogSchemaMutation Convert(ILocalCatalogSchemaMutation mutati
grpcLocalCatalogSchemaMutation.RemoveEntitySchemaMutation = new RemoveEntitySchemaMutationConverter().Convert(removeEntitySchemaMutation);
break;
default:
throw new EvitaInternalError("This should never happen!");;
throw new EvitaInternalError("This should never happen!");
}
return grpcLocalCatalogSchemaMutation;
}
Expand Down Expand Up @@ -122,4 +122,4 @@ public ILocalCatalogSchemaMutation Convert(GrpcLocalCatalogSchemaMutation mutati
_ => throw new EvitaInternalError("This should never happen!")
};
}
}
}
Loading

0 comments on commit 5539e08

Please sign in to comment.