diff --git a/solidify-index-controller/src/main/java/ch/unige/solidify/service/rest/abstractservice/IndexFielAliasRemoteResourceService.java b/solidify-index-controller/src/main/java/ch/unige/solidify/service/rest/abstractservice/IndexFielAliasRemoteResourceService.java index bc5fc085d99c5d762a6844ceb56980e5d350a95d..fb16cae50eb8ba39427bd81d4df1626fcc897186 100644 --- a/solidify-index-controller/src/main/java/ch/unige/solidify/service/rest/abstractservice/IndexFielAliasRemoteResourceService.java +++ b/solidify-index-controller/src/main/java/ch/unige/solidify/service/rest/abstractservice/IndexFielAliasRemoteResourceService.java @@ -32,9 +32,9 @@ import org.springframework.data.domain.Sort; import ch.unige.solidify.IndexConstants; import ch.unige.solidify.SolidifyConstants; import ch.unige.solidify.dto.LabelDTO; +import ch.unige.solidify.model.Label; import ch.unige.solidify.model.index.FacetProperties; import ch.unige.solidify.model.index.IndexFieldAlias; -import ch.unige.solidify.model.index.IndexFieldAliasLabel; import ch.unige.solidify.rest.RestCollectionPage; import ch.unige.solidify.service.RemoteResourceService; import ch.unige.solidify.service.SolidifyRestClientService; @@ -67,7 +67,7 @@ public abstract class IndexFielAliasRemoteResourceService extends RemoteResource FacetProperties facetProperties = new FacetProperties(); facetProperties.setName(field.getAlias()); facetProperties.setDefaultVisibleValues(field.getFacetDefaultVisibleValues()); - for (IndexFieldAliasLabel label : field.getLabels()) { + for (Label label : field.getLabels()) { String text = label.getText(); if (StringTool.isNullOrEmpty(text)) { text = field.getAlias(); diff --git a/solidify-index-model/src/main/java/ch/unige/solidify/model/index/IndexFieldAlias.java b/solidify-index-model/src/main/java/ch/unige/solidify/model/index/IndexFieldAlias.java index 217301f0b4748342a163f9847d66bf9cf7a946c0..3154d8dd5ce7089b1e9aab75a6349ddebf3e916c 100644 --- a/solidify-index-model/src/main/java/ch/unige/solidify/model/index/IndexFieldAlias.java +++ b/solidify-index-model/src/main/java/ch/unige/solidify/model/index/IndexFieldAlias.java @@ -25,6 +25,7 @@ package ch.unige.solidify.model.index; import java.util.ArrayList; import java.util.List; + import javax.persistence.CollectionTable; import javax.persistence.Column; import javax.persistence.ElementCollection; @@ -38,6 +39,7 @@ import javax.validation.constraints.Size; import ch.unige.solidify.IndexConstants; import ch.unige.solidify.SolidifyConstants; +import ch.unige.solidify.model.Label; import ch.unige.solidify.rest.ResourceNormalized; @Entity @@ -103,8 +105,8 @@ public class IndexFieldAlias extends ResourceNormalized { @Column(name = IndexConstants.DB_INDEX_FIELD_ALIAS_ID) @CollectionTable(joinColumns = { @JoinColumn(name = IndexConstants.DB_INDEX_FIELD_ALIAS_ID) }, uniqueConstraints = @UniqueConstraint(columnNames = { - IndexConstants.DB_INDEX_FIELD_ALIAS_ID, SolidifyConstants.DB_LANGUAGE_ID })) - private List<IndexFieldAliasLabel> labels = new ArrayList<>(); + IndexConstants.DB_INDEX_FIELD_ALIAS_ID, SolidifyConstants.DB_LANGUAGE_ID })) + private List<Label> labels = new ArrayList<>(); public String getIndexName() { return this.indexName; @@ -178,11 +180,11 @@ public class IndexFieldAlias extends ResourceNormalized { this.facetDefaultVisibleValues = facetDefaultVisibleValues; } - public List<IndexFieldAliasLabel> getLabels() { + public List<Label> getLabels() { return this.labels; } - public void setLabels(List<IndexFieldAliasLabel> labels) { + public void setLabels(List<Label> labels) { this.labels = labels; } diff --git a/solidify-index/src/main/java/ch/unige/solidify/business/IndexFieldAliasService.java b/solidify-index/src/main/java/ch/unige/solidify/business/IndexFieldAliasService.java index 65019fa3ebfc3191287416b67cdad78a1cd2a1cf..7dd391fd705844fad58802bf12f0e2a1c2ec4b27 100644 --- a/solidify-index/src/main/java/ch/unige/solidify/business/IndexFieldAliasService.java +++ b/solidify-index/src/main/java/ch/unige/solidify/business/IndexFieldAliasService.java @@ -43,10 +43,10 @@ import ch.unige.solidify.IndexConstants; import ch.unige.solidify.SolidifyConstants; import ch.unige.solidify.controller.IndexController; import ch.unige.solidify.dto.LabelDTO; +import ch.unige.solidify.model.Label; import ch.unige.solidify.model.dto.FacetSortDTO; import ch.unige.solidify.model.index.FacetProperties; import ch.unige.solidify.model.index.IndexFieldAlias; -import ch.unige.solidify.model.index.IndexFieldAliasLabel; import ch.unige.solidify.model.specification.IndexFieldAliasSpecification; import ch.unige.solidify.repository.IndexFieldAliasRepository; import ch.unige.solidify.rest.FacetRequest; @@ -136,7 +136,7 @@ public class IndexFieldAliasService extends ResourceService<IndexFieldAlias> { FacetProperties facetProperties = new FacetProperties(); facetProperties.setName(field.getAlias()); facetProperties.setDefaultVisibleValues(field.getFacetDefaultVisibleValues()); - for (IndexFieldAliasLabel label : field.getLabels()) { + for (Label label : field.getLabels()) { String text = label.getText(); if (StringTool.isNullOrEmpty(text)) { text = field.getAlias(); @@ -235,7 +235,8 @@ public class IndexFieldAliasService extends ResourceService<IndexFieldAlias> { return new IndexFieldAliasSpecification(resource); } - public void createIfNotExists(String indexName, Integer facetPosition, String alias, String field, boolean isFacet, boolean isSystem, Integer facetMinCount, + public void createIfNotExists(String indexName, Integer facetPosition, String alias, String field, boolean isFacet, boolean isSystem, + Integer facetMinCount, Integer facetLimit) { IndexFieldAlias indexFieldAlias = new IndexFieldAlias(); indexFieldAlias.setIndexName(indexName); diff --git a/solidify-model/src/main/java/ch/unige/solidify/model/GlobalBanner.java b/solidify-model/src/main/java/ch/unige/solidify/model/GlobalBanner.java new file mode 100644 index 0000000000000000000000000000000000000000..5d07cbd2dc04113cf750806b59b0b50323bbee0f --- /dev/null +++ b/solidify-model/src/main/java/ch/unige/solidify/model/GlobalBanner.java @@ -0,0 +1,192 @@ +/*- + * %%---------------------------------------------------------------------------------------------- + * Solidify Framework - Solidify Model - GlobalBanner.java + * SPDX-License-Identifier: GPL-2.0-or-later + * %----------------------------------------------------------------------------------------------% + * Copyright (C) 2017 - 2022 University of Geneva + * %----------------------------------------------------------------------------------------------% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 2 of the + * License, or (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-2.0.html>. + * ----------------------------------------------------------------------------------------------%% + */ + +package ch.unige.solidify.model; + +import java.time.OffsetDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import javax.persistence.CollectionTable; +import javax.persistence.Column; +import javax.persistence.ElementCollection; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.JoinColumn; +import javax.persistence.UniqueConstraint; +import javax.validation.constraints.NotNull; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; + +import ch.unige.solidify.SolidifyConstants; +import ch.unige.solidify.rest.ResourceNormalized; +import ch.unige.solidify.util.StringTool; + +/** + * Global Banner + */ +@Entity +public class GlobalBanner extends ResourceNormalized { + + public enum GlobalBannerType { + CRITICAL, WARNING, INFO + } + + @NotNull + @Column(unique = true) + private String name; + + @Enumerated(EnumType.STRING) + @NotNull + private GlobalBanner.GlobalBannerType type; + + @ElementCollection + @Column(name = SolidifyConstants.DB_GLOBAL_BANNER_ID) + @CollectionTable(joinColumns = { + @JoinColumn(name = SolidifyConstants.DB_GLOBAL_BANNER_ID) }, uniqueConstraints = @UniqueConstraint(columnNames = { + SolidifyConstants.DB_GLOBAL_BANNER_ID, SolidifyConstants.DB_LANGUAGE_ID })) + private List<Label> titleLabels = new ArrayList<>(); + + @ElementCollection + @Column(name = SolidifyConstants.DB_GLOBAL_BANNER_ID) + @CollectionTable(joinColumns = { + @JoinColumn(name = SolidifyConstants.DB_GLOBAL_BANNER_ID) }, uniqueConstraints = @UniqueConstraint(columnNames = { + SolidifyConstants.DB_GLOBAL_BANNER_ID, SolidifyConstants.DB_LANGUAGE_ID })) + private List<LargeLabel> descriptionLabels = new ArrayList<>(); + + @Column(nullable = false) + private Boolean enabled; + + @NotNull + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = StringTool.DATE_TIME_FORMAT) + @Column(length = SolidifyConstants.DB_DATE_LENGTH) + private OffsetDateTime startDate; + + @NotNull + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = StringTool.DATE_TIME_FORMAT) + @Column(length = SolidifyConstants.DB_DATE_LENGTH) + private OffsetDateTime endDate; + + /***********************************************************/ + + public String getName() { + return this.name; + } + + @JsonProperty(access = JsonProperty.Access.READ_ONLY) + public Boolean isWithDescription() { + return !this.getDescriptionLabels().isEmpty(); + } + + public GlobalBanner.GlobalBannerType getType() { + return this.type; + } + + public List<Label> getTitleLabels() { + return this.titleLabels; + } + + public List<LargeLabel> getDescriptionLabels() { + return this.descriptionLabels; + } + + public Boolean getEnabled() { + return this.enabled; + } + + public OffsetDateTime getStartDate() { + return this.startDate; + } + + public OffsetDateTime getEndDate() { + return this.endDate; + } + + /***********************************************************/ + + public void setName(String name) { + this.name = name; + } + + public void setType(GlobalBanner.GlobalBannerType type) { + this.type = type; + } + + public void setTitleLabels(List<Label> titleLabels) { + this.titleLabels = titleLabels; + } + + public void setDescriptionLabels(List<LargeLabel> descriptionLabels) { + this.descriptionLabels = descriptionLabels; + } + + public void setEnabled(Boolean enabled) { + this.enabled = enabled; + } + + public void setStartDate(OffsetDateTime startDate) { + this.startDate = startDate; + } + + public void setEndDate(OffsetDateTime endDate) { + this.endDate = endDate; + } + + @Override + public void init() { + if (this.enabled == null) { + this.enabled = true; + } + } + + @Override + public String managedBy() { + return SolidifyConstants.ADMIN_MODULE; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + Objects.hash(descriptionLabels, enabled, endDate, name, startDate, titleLabels, type); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + GlobalBanner other = (GlobalBanner) obj; + return Objects.equals(this.descriptionLabels, other.descriptionLabels) && Objects.equals(this.enabled, other.enabled) + && Objects.equals(this.endDate, other.endDate) && Objects.equals(this.name, other.name) + && Objects.equals(this.startDate, other.startDate) && Objects.equals(this.titleLabels, other.titleLabels) && this.type == other.type; + } + +} diff --git a/solidify-model/src/main/java/ch/unige/solidify/model/Label.java b/solidify-model/src/main/java/ch/unige/solidify/model/Label.java index 1583e0d6e85a86aeee7c64670c41062605df4564..4238905e8d982d527d980003a75f54df2795b901 100644 --- a/solidify-model/src/main/java/ch/unige/solidify/model/Label.java +++ b/solidify-model/src/main/java/ch/unige/solidify/model/Label.java @@ -23,6 +23,7 @@ package ch.unige.solidify.model; +import javax.persistence.Column; import javax.persistence.Embeddable; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; @@ -35,10 +36,11 @@ import ch.unige.solidify.rest.EmbeddableEntity; @Embeddable @MappedSuperclass -public abstract class Label<T> implements EmbeddableEntity<T> { +public class Label implements EmbeddableEntity { @NotNull @Size(max = SolidifyConstants.DB_LONG_STRING_LENGTH) + @Column(length = SolidifyConstants.DB_LONG_STRING_LENGTH) private String text; @NotNull diff --git a/solidify-index-model/src/main/java/ch/unige/solidify/model/index/IndexFieldAliasLabel.java b/solidify-model/src/main/java/ch/unige/solidify/model/LargeLabel.java similarity index 71% rename from solidify-index-model/src/main/java/ch/unige/solidify/model/index/IndexFieldAliasLabel.java rename to solidify-model/src/main/java/ch/unige/solidify/model/LargeLabel.java index a981a5e15d6e1210994da96680cca601dc205169..911ec5adcc28acbb21d7435dd0e28d8c9afcd5df 100644 --- a/solidify-index-model/src/main/java/ch/unige/solidify/model/index/IndexFieldAliasLabel.java +++ b/solidify-model/src/main/java/ch/unige/solidify/model/LargeLabel.java @@ -1,6 +1,6 @@ /*- * %%---------------------------------------------------------------------------------------------- - * Solidify Framework - Solidify Index Model - IndexFieldAliasLabel.java + * Solidify Framework - Solidify Model - LargeLabel.java * SPDX-License-Identifier: GPL-2.0-or-later * %----------------------------------------------------------------------------------------------% * Copyright (C) 2017 - 2022 University of Geneva @@ -21,13 +21,31 @@ * ----------------------------------------------------------------------------------------------%% */ -package ch.unige.solidify.model.index; +package ch.unige.solidify.model; +import javax.persistence.Column; import javax.persistence.Embeddable; +import javax.persistence.Lob; +import javax.validation.constraints.NotNull; -import ch.unige.solidify.model.Label; +/* + * Large label > 1024 + */ @Embeddable -public class IndexFieldAliasLabel extends Label<IndexFieldAliasLabel> { +public class LargeLabel extends Label { + @NotNull + @Lob + @Column(nullable = false) + private String text; + + @Override + public String getText() { + return this.text; + } + @Override + public void setText(String text) { + this.text = text; + } } diff --git a/solidify-model/src/main/java/ch/unige/solidify/rest/EmbeddableEntity.java b/solidify-model/src/main/java/ch/unige/solidify/rest/EmbeddableEntity.java index 682f6ebfc566b8650fdadf6b3c35c6814876a2b5..72a093e0b1e95537bd887a5f15819fa9e8f5d44f 100644 --- a/solidify-model/src/main/java/ch/unige/solidify/rest/EmbeddableEntity.java +++ b/solidify-model/src/main/java/ch/unige/solidify/rest/EmbeddableEntity.java @@ -31,7 +31,7 @@ import java.util.List; import com.fasterxml.jackson.annotation.JsonIgnore; -public interface EmbeddableEntity<T> { +public interface EmbeddableEntity { @JsonIgnore @Transient diff --git a/solidify-model/src/main/java/ch/unige/solidify/specification/GlobalBannerSpecification.java b/solidify-model/src/main/java/ch/unige/solidify/specification/GlobalBannerSpecification.java new file mode 100644 index 0000000000000000000000000000000000000000..e880d1fc57f6c15ea90ae8717381d8f2ae598964 --- /dev/null +++ b/solidify-model/src/main/java/ch/unige/solidify/specification/GlobalBannerSpecification.java @@ -0,0 +1,57 @@ +/*- + * %%---------------------------------------------------------------------------------------------- + * Solidify Framework - Solidify Model - GlobalBannerSpecification.java + * SPDX-License-Identifier: GPL-2.0-or-later + * %----------------------------------------------------------------------------------------------% + * Copyright (C) 2017 - 2022 University of Geneva + * %----------------------------------------------------------------------------------------------% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 2 of the + * License, or (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-2.0.html>. + * ----------------------------------------------------------------------------------------------%% + */ + +package ch.unige.solidify.specification; + +import java.util.List; + +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Predicate; +import javax.persistence.criteria.Root; + +import ch.unige.solidify.model.GlobalBanner; + +public class GlobalBannerSpecification extends SolidifySpecification<GlobalBanner> { + + private static final long serialVersionUID = 5005447432831295808L; + + public GlobalBannerSpecification(GlobalBanner globalBanner) { + super(globalBanner); + } + + @Override + protected void completePredicatesList(Root<GlobalBanner> root, CriteriaQuery<?> query, CriteriaBuilder builder, + List<Predicate> predicatesList) { + + if (this.criteria.getName() != null) { + predicatesList.add(builder.like(root.get("name"), "%" + this.criteria.getName() + "%")); + } + if (this.criteria.getType() != null) { + predicatesList.add(builder.equal(root.get("type"), this.criteria.getType())); + } + if (this.criteria.getEnabled() != null) { + predicatesList.add(builder.equal(root.get("enabled"), this.criteria.getEnabled())); + } + } +} diff --git a/solidify-model/src/main/java/ch/unige/solidify/util/BasicEntityMapper.java b/solidify-model/src/main/java/ch/unige/solidify/util/BasicEntityMapper.java index 58b1d09ae7e7205650fa2442c76e805914316e3e..de1c78609ac0582dee6a5009e86cfc5a4f8107aa 100644 --- a/solidify-model/src/main/java/ch/unige/solidify/util/BasicEntityMapper.java +++ b/solidify-model/src/main/java/ch/unige/solidify/util/BasicEntityMapper.java @@ -64,7 +64,7 @@ public class BasicEntityMapper { } } - public void patchResource(EmbeddableEntity<?> embeddableEntity, Map<String, Object> properties) { + public void patchResource(EmbeddableEntity embeddableEntity, Map<String, Object> properties) { if (embeddableEntity != null && properties != null) { this.patchObject(embeddableEntity, properties, embeddableEntity.getNonUpdatableFields()); } @@ -146,7 +146,8 @@ public class BasicEntityMapper { } /** - * Set the object value by using its setter if it exists, otherwise set the field's value directly with reflection + * Set the object value by using its setter if it exists, otherwise set the field's value directly + * with reflection * * @param objectToUpdate * @param field @@ -228,8 +229,9 @@ public class BasicEntityMapper { } /** - * Return true if the property is a List of Resources or if both lists (current and new value) are null or empty. - * Note: lists of Resources must be managed by using relation controllers and are ignored during patch. + * Return true if the property is a List of Resources or if both lists (current and new value) are + * null or empty. Note: lists of Resources must be managed by using relation controllers and are + * ignored during patch. * * @param field * @param objectToUpdate diff --git a/solidify-model/src/test/java/ch/unige/solidify/test/util/BasicEntityMapperTest.java b/solidify-model/src/test/java/ch/unige/solidify/test/util/BasicEntityMapperTest.java index 618b13bf47f9a8370cd6e4fc302fc47c5eb022c6..9ec8ef9e74464bb309c66c918d7c8e8a064af4d3 100644 --- a/solidify-model/src/test/java/ch/unige/solidify/test/util/BasicEntityMapperTest.java +++ b/solidify-model/src/test/java/ch/unige/solidify/test/util/BasicEntityMapperTest.java @@ -61,7 +61,7 @@ class BasicEntityMapperTest { private static final BasicEntityMapper basicEntityMapper = new BasicEntityMapper(); - public static class EmbeddedEntity implements EmbeddableEntity<EmbeddedEntity> { + public static class EmbeddedEntity implements EmbeddableEntity { private String embeddedName = ORIGINAL_EMBEDDED_NAME; private DayOfWeek embeddedDayOfWeek = DayOfWeek.TUESDAY; @@ -194,7 +194,7 @@ class BasicEntityMapperTest { @Test void nullResourceTest() { assertDoesNotThrow(() -> this.basicEntityMapper.patchResource((Resource) null, Map.of())); - assertDoesNotThrow(() -> this.basicEntityMapper.patchResource((EmbeddableEntity<?>) null, Map.of())); + assertDoesNotThrow(() -> this.basicEntityMapper.patchResource((EmbeddableEntity) null, Map.of())); } @Test @@ -555,7 +555,7 @@ class BasicEntityMapperTest { Map updateMap = new HashMap(); updateMap.put("keywords", null); assertDoesNotThrow(() -> this.basicEntityMapper.patchResource(resourceTest, updateMap)); - //Note: as both list are null or empty, patchResource ignore the field --> it doesn't get null + // Note: as both list are null or empty, patchResource ignore the field --> it doesn't get null assertTrue(resourceTest.getKeywords().isEmpty()); } diff --git a/solidify-util/src/main/java/ch/unige/solidify/SolidifyConstants.java b/solidify-util/src/main/java/ch/unige/solidify/SolidifyConstants.java index b70744321dd961268236f1ece7ca01e52fbdb298..26b57739642d4fa7283d25175b601c8fa66e5b1c 100644 --- a/solidify-util/src/main/java/ch/unige/solidify/SolidifyConstants.java +++ b/solidify-util/src/main/java/ch/unige/solidify/SolidifyConstants.java @@ -107,6 +107,7 @@ public class SolidifyConstants { // Database column name public static final String DB_RES_ID = "resId"; public static final String DB_LANGUAGE_ID = "languageId"; + public static final String DB_GLOBAL_BANNER_ID = "bannerId"; // Test data public static final String TEST_RES_ID = "test";