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

io.imunity.upman.front.views.members.MemberModel Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2018 Bixbit - Krzysztof Benedyczak. All rights reserved.
 * See LICENCE.txt file for licensing information.
 */

package io.imunity.upman.front.views.members;

import com.vaadin.flow.component.icon.VaadinIcon;
import io.imunity.upman.front.model.EmailModel;
import org.apache.commons.lang3.tuple.Pair;

import pl.edu.icm.unity.base.verifiable.VerifiableElementBase;
import pl.edu.icm.unity.engine.api.project.GroupAuthorizationRole;

import java.util.Map;
import java.util.Objects;

public class MemberModel
{
	public final long entityId;
	public final String name;
	public final Map attributes;
	public final Pair role;
	public final EmailModel email;

	private MemberModel(long entityId, String name, Map attributes, Pair role, EmailModel email)
	{
		this.entityId = entityId;
		this.name = name;
		this.attributes = attributes;
		this.role = role;
		this.email = email;
	}

	@Override
	public boolean equals(Object o)
	{
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;
		MemberModel that = (MemberModel) o;
		return entityId == that.entityId && Objects.equals(name, that.name) && Objects.equals(attributes, that.attributes) && Objects.equals(role, that.role) && Objects.equals(email, that.email);
	}

	public boolean anyFieldContains(String value)
	{
		String lowerCaseValue = value.toLowerCase();
		return value.isEmpty()
				|| (name != null && name.toLowerCase().contains(lowerCaseValue))
				|| (role.getKey() != null && role.getKey().toLowerCase().contains(lowerCaseValue))
				|| (email.value != null && email.value.toLowerCase().contains(lowerCaseValue))
				|| (attributes != null && attributes.values().stream().anyMatch(attrValue -> attrValue.toLowerCase().contains(lowerCaseValue)));
	}

	@Override
	public int hashCode()
	{
		return Objects.hash(entityId, name, attributes, role, email);
	}

	public static MembersGridModelBuilder builder()
	{
		return new MembersGridModelBuilder();
	}

	public static final class MembersGridModelBuilder
	{
		public long entityId;
		public String name;
		public Map attributes;
		public Pair role;
		public EmailModel email;

		private MembersGridModelBuilder()
		{
		}

		public MembersGridModelBuilder entityId(long entityId)
		{
			this.entityId = entityId;
			return this;
		}

		public MembersGridModelBuilder name(String name)
		{
			this.name = name;
			return this;
		}

		public MembersGridModelBuilder attributes(Map attributes)
		{
			this.attributes = attributes;
			return this;
		}

		public MembersGridModelBuilder role(GroupAuthorizationRole role)
		{
			VaadinIcon icon = null;
			if (role.equals(GroupAuthorizationRole.manager))
				icon = VaadinIcon.STAR_O;
			if (role.equals(GroupAuthorizationRole.projectsAdmin))
				icon = VaadinIcon.STAR;

			this.role = Pair.of(role.name(), icon);
			return this;
		}

		public MembersGridModelBuilder email(VerifiableElementBase email)
		{
			this.email = EmailModel.of(email);
			return this;
		}

		public MemberModel build()
		{
			return new MemberModel(entityId, name, attributes, role, email);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy