From a61d5a407e9d1d8d1addebd8ac110aa454def282 Mon Sep 17 00:00:00 2001 From: Krystian Dabrowski <98942253+krdabrowski@users.noreply.github.com> Date: Thu, 12 Oct 2023 12:01:28 +0200 Subject: [PATCH] ACS-6070: Support for highlighting prefix and postfix (#2245) * ACS-6070: Support for highlighting prefix and postfix - added prefix and postfix to field model --- .../rest/search/RestRequestFieldsModel.java | 113 +++++++++++++----- .../search/RestRequestHighlightModel.java | 9 +- 2 files changed, 92 insertions(+), 30 deletions(-) diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestFieldsModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestFieldsModel.java index 7252e9d4ad..aa86042124 100644 --- a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestFieldsModel.java +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestFieldsModel.java @@ -2,7 +2,7 @@ * #%L * 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. * If the software was purchased under a paid Alfresco license, the terms of @@ -23,24 +23,6 @@ * along with Alfresco. If not, see . * #L% */ -/* - * Copyright (C) 2017 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * 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 - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - */ package org.alfresco.rest.search; import com.fasterxml.jackson.annotation.JsonProperty; @@ -55,23 +37,40 @@ import org.alfresco.utility.model.TestModel; */ public class RestRequestFieldsModel extends TestModel implements IRestModel { - public RestRequestFieldsModel(){} - - public RestRequestFieldsModel(String fieldValue) - { - this.field = fieldValue; - } @JsonProperty(value = "entry") RestRequestFieldsModel model; + @JsonProperty(required = true) + private String field; + private String prefix; + private String postfix; + + public RestRequestFieldsModel() { + super(); + } + + public static RestRequestFieldsModel of(String field) + { + RestRequestFieldsModel fieldModel = new RestRequestFieldsModel(); + fieldModel.setField(field); + return fieldModel; + } + + public static RestRequestFieldsModel of(String field, String prefix, String postfix) + { + RestRequestFieldsModel fieldModel = new RestRequestFieldsModel(); + fieldModel.setField(field); + fieldModel.setPrefix(prefix); + fieldModel.setPostfix(postfix); + return fieldModel; + } + @Override public RestRequestFieldsModel onModel() { return model; } - @JsonProperty(required = true) - private String field; public String getField() { @@ -82,8 +81,64 @@ public class RestRequestFieldsModel extends TestModel implements IRestModel fields) { - this.fields = fields.stream().map(field -> new RestRequestFieldsModel(field)).toList(); + this.fields = fields.stream().map(RestRequestFieldsModel::of).toList(); + return this; + } + + public RestRequestHighlightModelBuilder fields(RestRequestFieldsModel... fields) + { + this.fields = Arrays.stream(fields).toList(); return this; }