ACS-4953 Add builder to TAS highlight POJO. (#2214)

* ACS-4953 Add builder to TAS highlight POJO.

Also rename ResponseHighLightModel to ResponseHighlightModel.
This commit is contained in:
Tom Page
2023-09-27 12:13:11 +01:00
committed by GitHub
parent d3498f4bc4
commit 248fecd030
3 changed files with 151 additions and 70 deletions

View File

@@ -44,6 +44,7 @@
package org.alfresco.rest.search; package org.alfresco.rest.search;
import java.util.List; import java.util.List;
import java.util.Objects;
import org.alfresco.rest.core.IRestModel; import org.alfresco.rest.core.IRestModel;
import org.alfresco.utility.model.TestModel; import org.alfresco.utility.model.TestModel;
@@ -52,11 +53,11 @@ import org.alfresco.utility.model.TestModel;
* @author Michael Suzuki * @author Michael Suzuki
* *
*/ */
public class ResponseHighLightModel extends TestModel implements IRestModel<ResponseHighLightModel> public class ResponseHighlightModel extends TestModel implements IRestModel<ResponseHighlightModel>
{ {
private ResponseHighLightModel model; private ResponseHighlightModel model;
private String field; private String field;
private List<Object> snippets; private List<String> snippets;
public String getField() public String getField()
{ {
@@ -66,19 +67,44 @@ public class ResponseHighLightModel extends TestModel implements IRestModel<Resp
{ {
this.field = field; this.field = field;
} }
public List<Object> getSnippets() public List<String> getSnippets()
{ {
return snippets; return snippets;
} }
public void setSnippets(List<Object> snippets) public void setSnippets(List<String> snippets)
{ {
this.snippets = snippets; this.snippets = snippets;
} }
@Override @Override
public ResponseHighLightModel onModel() public ResponseHighlightModel onModel()
{ {
return model; return model;
} }
@Override
public boolean equals(Object o)
{
if (this == o)
{
return true;
}
if (o == null || getClass() != o.getClass())
{
return false;
}
ResponseHighlightModel that = (ResponseHighlightModel) o;
return Objects.equals(model, that.model) && Objects.equals(field, that.field) && Objects.equals(snippets, that.snippets);
}
@Override
public int hashCode()
{
return Objects.hash(model, field, snippets);
}
@Override
public String toString()
{
return "ResponseHighlightModel{model=%s, field=%s, snippets=%s}".formatted(model, field, snippets);
}
} }

View File

@@ -2,23 +2,23 @@
* #%L * #%L
* alfresco-tas-restapi * alfresco-tas-restapi
* %% * %%
* Copyright (C) 2005 - 2022 Alfresco Software Limited * Copyright (C) 2005 - 2023 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is * the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms: * provided under the following open source license terms:
* *
* Alfresco is free software: you can redistribute it and/or modify * Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by * it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Alfresco is distributed in the hope that it will be useful, * Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
@@ -33,62 +33,38 @@ import org.alfresco.rest.core.IRestModel;
import org.alfresco.utility.model.TestModel; import org.alfresco.utility.model.TestModel;
/** /**
* Generated by 'msuzuki' on '2017-02-23 13:41' from 'Alfresco Search REST API' swagger file * Generated by 'msuzuki' on '2017-02-23 13:41' from 'Alfresco Search REST API' swagger file
* Generated from 'Alfresco Search REST API' swagger file * Generated from 'Alfresco Search REST API' swagger file
* Base Path {@linkplain /alfresco/api/-default-/public/search/versions/1} * Base Path {@linkplain /alfresco/api/-default-/public/search/versions/1}
*/ */
public class RestRequestHighlightModel extends TestModel implements IRestModel<RestRequestHighlightModel> public class RestRequestHighlightModel extends TestModel implements IRestModel<RestRequestHighlightModel>
{ {
@JsonProperty(value = "entry") @JsonProperty("entry")
RestRequestHighlightModel model; RestRequestHighlightModel model;
/** The string used to mark the start of a highlight in a fragment. */
private String prefix;
/** The string used to mark the end of a highlight in a fragment. */
private String postfix;
/** The maximum number of distinct highlight snippets to return for each highlight field. */
private int snippetCount;
/** The character length of each snippet. */
private int fragmentSize;
/** The number of characters to be considered for highlighting. Matches after this count will not be shown. */
private int maxAnalyzedChars;
/** If fragments overlap they can be merged into one larger fragment */
private boolean mergeContiguous;
/** Should phrases be identified. */
private boolean usePhraseHighlighter;
/** The fields to highlight and field specific configuration properties for each field */
private List<RestRequestFieldsModel> fields;
@Override @Override
public RestRequestHighlightModel onModel() public RestRequestHighlightModel onModel()
{ {
return model; return model;
} }
/**
The string used to mark the start of a highlight in a fragment.
*/
private String prefix;
/**
The string used to mark the end of a highlight in a fragment.
*/
private String postfix;
/**
The maximum number of distinct highlight snippets to return for each highlight field.
*/
private int snippetCount;
/**
The character length of each snippet.
*/
private int fragmentSize;
/**
The number of characters to be considered for highlighting. Matches after this count will not be shown.
*/
private int maxAnalyzedChars;
/**
If fragments over lap they can be merged into one larger fragment
*/
private boolean mergeContiguous;
/**
Should phrases be identified.
*/
private boolean usePhraseHighlighter;
/**
The fields to highlight and field specific configuration properties for each field
*/
private List<RestRequestFieldsModel> fields;
public String getPrefix() public String getPrefix()
{ {
return this.prefix; return this.prefix;
@@ -97,7 +73,7 @@ public class RestRequestHighlightModel extends TestModel implements IRestModel<R
public void setPrefix(String prefix) public void setPrefix(String prefix)
{ {
this.prefix = prefix; this.prefix = prefix;
} }
public String getPostfix() public String getPostfix()
{ {
@@ -107,7 +83,7 @@ public class RestRequestHighlightModel extends TestModel implements IRestModel<R
public void setPostfix(String postfix) public void setPostfix(String postfix)
{ {
this.postfix = postfix; this.postfix = postfix;
} }
public int getSnippetCount() public int getSnippetCount()
{ {
@@ -117,7 +93,7 @@ public class RestRequestHighlightModel extends TestModel implements IRestModel<R
public void setSnippetCount(int snippetCount) public void setSnippetCount(int snippetCount)
{ {
this.snippetCount = snippetCount; this.snippetCount = snippetCount;
} }
public int getFragmentSize() public int getFragmentSize()
{ {
@@ -127,7 +103,7 @@ public class RestRequestHighlightModel extends TestModel implements IRestModel<R
public void setFragmentSize(int fragmentSize) public void setFragmentSize(int fragmentSize)
{ {
this.fragmentSize = fragmentSize; this.fragmentSize = fragmentSize;
} }
public int getMaxAnalyzedChars() public int getMaxAnalyzedChars()
{ {
@@ -137,9 +113,9 @@ public class RestRequestHighlightModel extends TestModel implements IRestModel<R
public void setMaxAnalyzedChars(int maxAnalyzedChars) public void setMaxAnalyzedChars(int maxAnalyzedChars)
{ {
this.maxAnalyzedChars = maxAnalyzedChars; this.maxAnalyzedChars = maxAnalyzedChars;
} }
public boolean getMergeContiguous() public boolean isMergeContiguous()
{ {
return this.mergeContiguous; return this.mergeContiguous;
} }
@@ -147,9 +123,9 @@ public class RestRequestHighlightModel extends TestModel implements IRestModel<R
public void setMergeContiguous(boolean mergeContiguous) public void setMergeContiguous(boolean mergeContiguous)
{ {
this.mergeContiguous = mergeContiguous; this.mergeContiguous = mergeContiguous;
} }
public boolean getUsePhraseHighlighter() public boolean isUsePhraseHighlighter()
{ {
return this.usePhraseHighlighter; return this.usePhraseHighlighter;
} }
@@ -157,7 +133,7 @@ public class RestRequestHighlightModel extends TestModel implements IRestModel<R
public void setUsePhraseHighlighter(boolean usePhraseHighlighter) public void setUsePhraseHighlighter(boolean usePhraseHighlighter)
{ {
this.usePhraseHighlighter = usePhraseHighlighter; this.usePhraseHighlighter = usePhraseHighlighter;
} }
public List<RestRequestFieldsModel> getFields() public List<RestRequestFieldsModel> getFields()
{ {
@@ -167,6 +143,85 @@ public class RestRequestHighlightModel extends TestModel implements IRestModel<R
public void setFields(List<RestRequestFieldsModel> fields) public void setFields(List<RestRequestFieldsModel> fields)
{ {
this.fields = fields; this.fields = fields;
} }
public static RestRequestHighlightModelBuilder builder()
{
return new RestRequestHighlightModelBuilder();
}
public static class RestRequestHighlightModelBuilder
{
private String prefix;
private String postfix;
private int snippetCount;
private int fragmentSize;
private int maxAnalyzedChars;
private boolean mergeContiguous;
private boolean usePhraseHighlighter;
private List<RestRequestFieldsModel> fields;
public RestRequestHighlightModelBuilder prefix(String prefix)
{
this.prefix = prefix;
return this;
}
public RestRequestHighlightModelBuilder postfix(String postfix)
{
this.postfix = postfix;
return this;
}
public RestRequestHighlightModelBuilder snippetCount(int snippetCount)
{
this.snippetCount = snippetCount;
return this;
}
public RestRequestHighlightModelBuilder fragmentSize(int fragmentSize)
{
this.fragmentSize = fragmentSize;
return this;
}
public RestRequestHighlightModelBuilder maxAnalyzedChars(int maxAnalyzedChars)
{
this.maxAnalyzedChars = maxAnalyzedChars;
return this;
}
public RestRequestHighlightModelBuilder mergeContinuous(boolean mergeContiguous)
{
this.mergeContiguous = mergeContiguous;
return this;
}
public RestRequestHighlightModelBuilder usePhraseHighlighter(boolean usePhraseHighlighter)
{
this.usePhraseHighlighter = usePhraseHighlighter;
return this;
}
public RestRequestHighlightModelBuilder fields(List<String> fields)
{
this.fields = fields.stream().map(field -> new RestRequestFieldsModel(field)).toList();
return this;
}
public RestRequestHighlightModel build()
{
RestRequestHighlightModel highlightModel = new RestRequestHighlightModel();
highlightModel.setPrefix(prefix);
highlightModel.setPostfix(postfix);
highlightModel.setSnippetCount(snippetCount);
highlightModel.setFragmentSize(fragmentSize);
highlightModel.setMaxAnalyzedChars(maxAnalyzedChars);
highlightModel.setMergeContiguous(mergeContiguous);
highlightModel.setUsePhraseHighlighter(usePhraseHighlighter);
highlightModel.setFields(fields);
return highlightModel;
}
}
} }

View File

@@ -60,7 +60,7 @@ public class SearchScoreModel extends TestModel implements IRestModel<SearchScor
@JsonProperty(required = true) @JsonProperty(required = true)
private float score; private float score;
private List<ResponseHighLightModel> highlight; private List<ResponseHighlightModel> highlight;
public float getScore() public float getScore()
{ {
@@ -78,12 +78,12 @@ public class SearchScoreModel extends TestModel implements IRestModel<SearchScor
return this; return this;
} }
public List<ResponseHighLightModel> getHighlight() public List<ResponseHighlightModel> getHighlight()
{ {
return highlight; return highlight;
} }
public void setHighlight(List<ResponseHighLightModel> highlight) public void setHighlight(List<ResponseHighlightModel> highlight)
{ {
this.highlight = highlight; this.highlight = highlight;
} }