All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.wallride.model.ArticleSearchRequest Maven / Gradle / Ivy

There is a newer version: 1.0.0.M18
Show newest version
/*
 * Copyright 2014 Tagbangers, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.wallride.model;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.wallride.domain.CustomField;
import org.wallride.domain.Post;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

public class ArticleSearchRequest implements Serializable {

	private String keyword;
	private LocalDateTime dateFrom;
	private LocalDateTime dateTo;
	private Collection categoryIds;
	private Collection categoryCodes;
	private Collection tagIds;
	private Collection tagNames;
	private Map customFields;
	private Long authorId;
	private Post.Status status;
	private String language;

	public ArticleSearchRequest() {
		this.language = LocaleContextHolder.getLocale().getLanguage();
	}

	public ArticleSearchRequest(String language) {
		this.language = language;
	}

	public String getKeyword() {
		return keyword;
	}

	public void setKeyword(String keyword) {
		this.keyword = keyword;
	}

	public ArticleSearchRequest withKeyword(String keyword) {
		this.keyword = keyword;
		return this;
	}

	public LocalDateTime getDateFrom() {
		return dateFrom;
	}

	public void setDateFrom(LocalDateTime dateFrom) {
		this.dateFrom = dateFrom;
	}

	public ArticleSearchRequest withDateFrom(LocalDateTime dateFrom) {
		this.dateFrom = dateFrom;
		return this;
	}

	public LocalDateTime getDateTo() {
		return dateTo;
	}

	public void setDateTo(LocalDateTime dateTo) {
		this.dateTo = dateTo;
	}

	public ArticleSearchRequest withDateTo(LocalDateTime dateTo) {
		this.dateTo = dateTo;
		return this;
	}

	public Collection getCategoryIds() {
		return categoryIds;
	}

	public void setCategoryIds(Collection categoryIds) {
		this.categoryIds = categoryIds;
	}

	public ArticleSearchRequest withCategoryIds(Long... categoryIds) {
		if (getCategoryIds() == null) {
			setCategoryIds(new ArrayList(categoryIds.length));
		}
		for (Long value : categoryIds) {
			getCategoryIds().add(value);
		}
		return this;
	}

	public ArticleSearchRequest withCategoryIds(Collection categoryIds) {
		if (categoryIds == null) {
			this.categoryIds = null;
		} else {
			this.categoryIds = new ArrayList<>(categoryIds);
		}
		return this;
	}

	public Collection getCategoryCodes() {
		return categoryCodes;
	}

	public void setCategoryCodes(Collection categoryCodes) {
		this.categoryCodes = categoryCodes;
	}

	public ArticleSearchRequest withCategoryCodes(String... categoryCodes) {
		if (getCategoryCodes() == null) {
			setCategoryCodes(new ArrayList(categoryCodes.length));
		}
		for (String value : categoryCodes) {
			getCategoryCodes().add(value);
		}
		return this;
	}

	public ArticleSearchRequest withCategoryCodes(Collection categoryCodes) {
		if (categoryCodes == null) {
			this.categoryCodes = null;
		} else {
			this.categoryCodes = new ArrayList<>(categoryCodes);
		}
		return this;
	}

	public Collection getTagIds() {
		return tagIds;
	}

	public void setTagIds(Collection tagIds) {
		this.tagIds = tagIds;
	}

	public ArticleSearchRequest withTagIds(Long... tags) {
		if (getTagIds() == null) {
			setTagIds(new ArrayList(tags.length));
		}
		for (Long value : tags) {
			getTagIds().add(value);
		}
		return this;
	}

	public ArticleSearchRequest withTagIds(Collection tags) {
		if (tags == null) {
			this.tagIds = null;
		} else {
			this.tagIds = new ArrayList<>(tags);
		}
		return this;
	}

	public Collection getTagNames() {
		return tagNames;
	}

	public void setTagNames(Collection tagNames) {
		this.tagNames = tagNames;
	}

	public ArticleSearchRequest withTagNames(String... tags) {
		if (getTagNames() == null) {
			setTagNames(new ArrayList(tags.length));
		}
		for (String value : tags) {
			getTagNames().add(value);
		}
		return this;
	}

	public ArticleSearchRequest withTagNames(Collection tags) {
		if (tags == null) {
			this.tagNames = null;
		} else {
			this.tagNames = new ArrayList<>(tags);
		}
		return this;
	}

	public Map getCustomFields() {
		return customFields;
	}

	public void setCustomFields(Map customFields) {
		this.customFields = customFields;
	}

	public  ArticleSearchRequest withCustomFields(Map customFields) {
		this.customFields = customFields;
		return this;
	}

	public Long getAuthorId() {
		return authorId;
	}

	public void setAuthorId(Long authorId) {
		this.authorId = authorId;
	}

	public ArticleSearchRequest withAuthorId(Long authorId) {
		this.authorId = authorId;
		return this;
	}

	public Post.Status getStatus() {
		return status;
	}

	public void setStatus(Post.Status status) {
		this.status = status;
	}

	public ArticleSearchRequest withStatus(Post.Status status) {
		this.status = status;
		return this;
	}

	public String getLanguage() {
		return language;
	}

	public void setLanguage(String language) {
		this.language = language;
	}

	public ArticleSearchRequest withLanguage(String language) {
		this.language = language;
		return this;
	}

	public boolean isEmpty() {
		if (StringUtils.hasText(getKeyword())) {
			return false;
		}
		if (getDateFrom() != null) {
			return false;
		}
		if (getDateTo() != null) {
			return false;
		}
		if (!CollectionUtils.isEmpty(getCategoryIds())) {
			return false;
		}
		if (!CollectionUtils.isEmpty(getTagNames())) {
			return false;
		}
		if (!CollectionUtils.isEmpty(getCustomFields())) {
			return false;
		}
		if (getAuthorId() != null) {
			return false;
		}
		if (getStatus() != null) {
			return false;
		}
		if (StringUtils.hasText(getLanguage())) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy