Skip to content

Commit

Permalink
fix(repository): renormalize
Browse files Browse the repository at this point in the history
  • Loading branch information
bkapustik committed Sep 1, 2024
1 parent 8f1dc3c commit 90133e3
Show file tree
Hide file tree
Showing 27 changed files with 2,305 additions and 2,305 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/xperience-administration-search-index-edit-form.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
136 changes: 68 additions & 68 deletions src/Kentico.Xperience.Lucene.Admin/LuceneConfigurationModel.cs
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
using System.ComponentModel.DataAnnotations;

using Kentico.Xperience.Admin.Base.FormAnnotations;
using Kentico.Xperience.Admin.Base.Forms;
using Kentico.Xperience.Lucene.Admin.Providers;
using Kentico.Xperience.Lucene.Core.Indexing;

namespace Kentico.Xperience.Lucene.Admin;

public class LuceneConfigurationModel
{
public int Id { get; set; }

[TextInputComponent(
Label = "Index Name",
ExplanationText = "Changing this value on an existing index without changing application code will cause the search experience to stop working.",
Order = 1)]
[Required]
[MinLength(1)]
public string IndexName { get; set; } = "";

[GeneralSelectorComponent(dataProviderType: typeof(LanguageOptionsProvider), Label = "Indexed Languages", Order = 2)]
public IEnumerable<string> LanguageNames { get; set; } = Enumerable.Empty<string>();

[DropDownComponent(Label = "Channel Name", DataProviderType = typeof(ChannelOptionsProvider), Order = 3)]
public string ChannelName { get; set; } = "";

[DropDownComponent(Label = "Indexing Strategy", DataProviderType = typeof(IndexingStrategyOptionsProvider), Order = 4)]
public string StrategyName { get; set; } = "";

[DropDownComponent(Label = "Lucene Analyzer", DataProviderType = typeof(AnalyzerOptionsProvider), Order = 5)]
public string AnalyzerName { get; set; } = "";

[TextInputComponent(Label = "Rebuild Hook")]
public string RebuildHook { get; set; } = "";

[LuceneIndexConfigurationComponent(Label = "Included Paths")]
public IEnumerable<LuceneIndexIncludedPath> Paths { get; set; } = Enumerable.Empty<LuceneIndexIncludedPath>();

public LuceneConfigurationModel() { }

public LuceneConfigurationModel(
LuceneIndexModel luceneModel
)
{
Id = luceneModel.Id;
IndexName = luceneModel.IndexName;
LanguageNames = luceneModel.LanguageNames;
ChannelName = luceneModel.ChannelName;
StrategyName = luceneModel.StrategyName;
AnalyzerName = luceneModel.AnalyzerName;
RebuildHook = luceneModel.RebuildHook;
Paths = luceneModel.Paths;
}

public LuceneIndexModel ToLuceneModel() =>
new()
{
Id = Id,
IndexName = IndexName,
LanguageNames = LanguageNames,
ChannelName = ChannelName,
AnalyzerName = AnalyzerName,
StrategyName = StrategyName,
RebuildHook = RebuildHook,
Paths = Paths
};
}
using System.ComponentModel.DataAnnotations;

using Kentico.Xperience.Admin.Base.FormAnnotations;
using Kentico.Xperience.Admin.Base.Forms;
using Kentico.Xperience.Lucene.Admin.Providers;
using Kentico.Xperience.Lucene.Core.Indexing;

namespace Kentico.Xperience.Lucene.Admin;

public class LuceneConfigurationModel
{
public int Id { get; set; }

[TextInputComponent(
Label = "Index Name",
ExplanationText = "Changing this value on an existing index without changing application code will cause the search experience to stop working.",
Order = 1)]
[Required]
[MinLength(1)]
public string IndexName { get; set; } = "";

[GeneralSelectorComponent(dataProviderType: typeof(LanguageOptionsProvider), Label = "Indexed Languages", Order = 2)]
public IEnumerable<string> LanguageNames { get; set; } = Enumerable.Empty<string>();

[DropDownComponent(Label = "Channel Name", DataProviderType = typeof(ChannelOptionsProvider), Order = 3)]
public string ChannelName { get; set; } = "";

[DropDownComponent(Label = "Indexing Strategy", DataProviderType = typeof(IndexingStrategyOptionsProvider), Order = 4)]
public string StrategyName { get; set; } = "";

[DropDownComponent(Label = "Lucene Analyzer", DataProviderType = typeof(AnalyzerOptionsProvider), Order = 5)]
public string AnalyzerName { get; set; } = "";

[TextInputComponent(Label = "Rebuild Hook")]
public string RebuildHook { get; set; } = "";

[LuceneIndexConfigurationComponent(Label = "Included Paths")]
public IEnumerable<LuceneIndexIncludedPath> Paths { get; set; } = Enumerable.Empty<LuceneIndexIncludedPath>();

public LuceneConfigurationModel() { }

public LuceneConfigurationModel(
LuceneIndexModel luceneModel
)
{
Id = luceneModel.Id;
IndexName = luceneModel.IndexName;
LanguageNames = luceneModel.LanguageNames;
ChannelName = luceneModel.ChannelName;
StrategyName = luceneModel.StrategyName;
AnalyzerName = luceneModel.AnalyzerName;
RebuildHook = luceneModel.RebuildHook;
Paths = luceneModel.Paths;
}

public LuceneIndexModel ToLuceneModel() =>
new()
{
Id = Id,
IndexName = IndexName,
LanguageNames = LanguageNames,
ChannelName = ChannelName,
AnalyzerName = AnalyzerName,
StrategyName = StrategyName,
RebuildHook = RebuildHook,
Paths = Paths
};
}
150 changes: 75 additions & 75 deletions src/Kentico.Xperience.Lucene.Admin/UIPages/BaseIndexEditPage.cs
Original file line number Diff line number Diff line change
@@ -1,75 +1,75 @@
using System.Text;

using Kentico.Xperience.Admin.Base;
using Kentico.Xperience.Admin.Base.Forms;
using Kentico.Xperience.Lucene.Core.Indexing;

using IFormItemCollectionProvider = Kentico.Xperience.Admin.Base.Forms.Internal.IFormItemCollectionProvider;

namespace Kentico.Xperience.Lucene.Admin;

internal abstract class BaseIndexEditPage : ModelEditPage<LuceneConfigurationModel>
{
protected readonly ILuceneConfigurationStorageService StorageService;

private readonly ILuceneIndexManager indexManager;

protected BaseIndexEditPage(
IFormItemCollectionProvider formItemCollectionProvider,
IFormDataBinder formDataBinder,
ILuceneConfigurationStorageService storageService,
ILuceneIndexManager indexManager)
: base(formItemCollectionProvider, formDataBinder)
{
this.indexManager = indexManager;
StorageService = storageService;
}

protected async Task<IndexModificationResult> ValidateAndProcess(LuceneConfigurationModel configuration)
{
configuration.IndexName = RemoveWhitespacesUsingStringBuilder(configuration.IndexName ?? "");

if (StorageService.GetIndexIds().Exists(x => x == configuration.Id))
{
bool edited = await StorageService.TryEditIndexAsync(configuration.ToLuceneModel());

if (edited)
{
return IndexModificationResult.Success;
}

return IndexModificationResult.Failure;
}
else
{
if (!string.IsNullOrWhiteSpace(configuration.IndexName))
{
indexManager.AddIndex(configuration.ToLuceneModel());

return IndexModificationResult.Success;
}

return IndexModificationResult.Failure;
}
}

protected static string RemoveWhitespacesUsingStringBuilder(string source)
{
var builder = new StringBuilder(source.Length);
for (int i = 0; i < source.Length; i++)
{
char c = source[i];
if (!char.IsWhiteSpace(c))
{
builder.Append(c);
}
}
return source.Length == builder.Length ? source : builder.ToString();
}
}

internal enum IndexModificationResult
{
Success,
Failure
}
using System.Text;

using Kentico.Xperience.Admin.Base;
using Kentico.Xperience.Admin.Base.Forms;
using Kentico.Xperience.Lucene.Core.Indexing;

using IFormItemCollectionProvider = Kentico.Xperience.Admin.Base.Forms.Internal.IFormItemCollectionProvider;

namespace Kentico.Xperience.Lucene.Admin;

internal abstract class BaseIndexEditPage : ModelEditPage<LuceneConfigurationModel>
{
protected readonly ILuceneConfigurationStorageService StorageService;

private readonly ILuceneIndexManager indexManager;

protected BaseIndexEditPage(
IFormItemCollectionProvider formItemCollectionProvider,
IFormDataBinder formDataBinder,
ILuceneConfigurationStorageService storageService,
ILuceneIndexManager indexManager)
: base(formItemCollectionProvider, formDataBinder)
{
this.indexManager = indexManager;
StorageService = storageService;
}

protected async Task<IndexModificationResult> ValidateAndProcess(LuceneConfigurationModel configuration)
{
configuration.IndexName = RemoveWhitespacesUsingStringBuilder(configuration.IndexName ?? "");

if (StorageService.GetIndexIds().Exists(x => x == configuration.Id))
{
bool edited = await StorageService.TryEditIndexAsync(configuration.ToLuceneModel());

if (edited)
{
return IndexModificationResult.Success;
}

return IndexModificationResult.Failure;
}
else
{
if (!string.IsNullOrWhiteSpace(configuration.IndexName))
{
indexManager.AddIndex(configuration.ToLuceneModel());

return IndexModificationResult.Success;
}

return IndexModificationResult.Failure;
}
}

protected static string RemoveWhitespacesUsingStringBuilder(string source)
{
var builder = new StringBuilder(source.Length);
for (int i = 0; i < source.Length; i++)
{
char c = source[i];
if (!char.IsWhiteSpace(c))
{
builder.Append(c);
}
}
return source.Length == builder.Length ? source : builder.ToString();
}
}

internal enum IndexModificationResult
{
Success,
Failure
}
Loading

0 comments on commit 90133e3

Please sign in to comment.