/*
 * Copyright 2016 EPAM Systems
 * 
 * 
 * This file is part of EPAM Report Portal.
 * https://github.com/reportportal/commons-dao
 * 
 * Report Portal 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 3 of the License, or
 * (at your option) any later version.
 * 
 * Report Portal 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 Report Portal.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.epam.ta.reportportal.database.entity.filter;

import java.io.Serializable;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.CompoundIndex;
import org.springframework.data.mongodb.core.index.CompoundIndexes;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.hateoas.Identifiable;

import com.epam.ta.reportportal.database.entity.sharing.Shareable;
import com.epam.ta.reportportal.database.search.Filter;
import com.epam.ta.reportportal.database.search.FilterCriteria;

/**
 * Filter DAO layer object. Represent stored filter from ui.
 * 
 * @author Aliaksei_Makayed
 * 
 */

@Document
@CompoundIndexes({ @CompoundIndex(name = "project_name_name", def = "{'projectName': 1,'name': 1}") })
public class UserFilter extends Shareable implements Serializable, Identifiable<String> {

	private static final long serialVersionUID = 2746422761895104850L;

	public static final String PROJECT_NAME = "projectName";
	public static final String NAME = "name";
	public static final String IS_LINK = "is_link";

	@Id
	private String id;

	@FilterCriteria("name")
	private String name;

	private Filter filter;

	private SelectionOptions selectionOptions;

	@FilterCriteria("projectName")
	private String projectName;

	@FilterCriteria(IS_LINK)
	private boolean isLink;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setFilter(Filter filter) {
		this.filter = filter;
	}

	public Filter getFilter() {
		return filter;
	}

	public void setId(String id) {
		this.id = id;
	}

	public boolean isLink() {
		return isLink;
	}

	public void setIsLink(boolean isLink) {
		this.isLink = isLink;
	}

	@Override
	public String getId() {
		return id;
	}

	public SelectionOptions getSelectionOptions() {
		return selectionOptions;
	}

	public void setSelectionOptions(SelectionOptions selectionOptions) {
		this.selectionOptions = selectionOptions;
	}

	public String getProjectName() {
		return projectName;
	}

	public void setProjectName(String projectName) {
		this.projectName = projectName;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;

		UserFilter that = (UserFilter) o;

		if (isLink != that.isLink)
			return false;
		if (id != null ? !id.equals(that.id) : that.id != null)
			return false;
		if (name != null ? !name.equals(that.name) : that.name != null)
			return false;
		if (filter != null ? !filter.equals(that.filter) : that.filter != null)
			return false;
		if (selectionOptions != null ? !selectionOptions.equals(that.selectionOptions) : that.selectionOptions != null)
			return false;
		return (projectName != null ? !projectName.equals(that.projectName) : that.projectName != null);

	}

	@Override
	public int hashCode() {
		int result = id != null ? id.hashCode() : 0;
		result = 31 * result + (name != null ? name.hashCode() : 0);
		result = 31 * result + (filter != null ? filter.hashCode() : 0);
		result = 31 * result + (selectionOptions != null ? selectionOptions.hashCode() : 0);
		result = 31 * result + (projectName != null ? projectName.hashCode() : 0);
		result = 31 * result + (isLink ? 1 : 0);
		return result;
	}
}
@@ -868,24 +868,50 @@
 erializable;
+%0Aimport java.util.Objects;
 %0A%0Aimport org
@@ -3105,17 +3105,16 @@
  false;%0A
-%0A
 %09%09UserFi
@@ -3145,23 +3145,25 @@
  o;%0A
-%0A
 %09%09
-if (
+return 
 isLink 
-!
+=
 = th
@@ -3175,136 +3175,66 @@
 Link
-)
+ &&
 %0A%09%09%09
-return false;%0A%09%09if (id != null ? !id.equals(that.id) : that.id != null)%0A%09%09%09return false;%0A%09%09if (name != null ? !name
+%09Objects.equals(id, that.id) &&%0A%09%09%09%09Objects
 .equals(
 that
@@ -3233,20 +3233,13 @@
 als(
-that.
 name
-) :
+,
  tha
@@ -3248,73 +3248,32 @@
 name
- != null)%0A%09%09%09return false;%0A%09%09if (filter != null ? !filter
+) &&%0A%09%09%09%09Objects
 .equals(
 that
@@ -3272,22 +3272,15 @@
 als(
-that.
 filter
-) :
+,
  tha
@@ -3291,84 +3291,23 @@
 lter
- != null)%0A%09%09%09return false;%0A%09%09if (selectionOptions != null ? !selectionOption
+) &&%0A%09%09%09%09Object
 s.eq
@@ -3311,21 +3311,16 @@
 .equals(
-that.
 selectio
@@ -3327,19 +3327,17 @@
 nOptions
-) :
+,
  that.se
@@ -3354,87 +3354,32 @@
 ions
- != null)%0A%09%09%09return false;%0A%09%09return (projectName != null ? !projectName
+) &&%0A%09%09%09%09Objects
 .equals(
 that
@@ -3374,21 +3374,16 @@
 .equals(
-that.
 projectN
@@ -3385,19 +3385,17 @@
 jectName
-) :
+,
  that.pr
@@ -3407,20 +3407,11 @@
 Name
- != null
 );%0A
-%0A
 %09%7D%0A%0A
@@ -3452,407 +3452,87 @@
 %7B%0A%09%09
-int result = id != null ? id.hashCode() : 0;%0A%09%09result = 31 * result + (name != null ? name.hashCode() : 0);%0A%09%09result = 31 * result + (filter != null ? filter.hashCode() : 0);%0A%09%09result = 31 * result + (selectionOptions != null ? selectionOptions.hashCode() : 0);%0A%09%09result = 31 * result + (projectName != null ? projectName.hashCode() : 0);%0A%09%09result = 31 * result + (isLink ? 1 : 0);%0A%09%09return result
+return Objects.hash(id, name, filter, selectionOptions, projectName, isLink)
 ;%0A%09%7D%0A%7D
+%0A

fix equals in user filter