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

io.imunity.scim.config.ReferenceAttributeMapping Maven / Gradle / Ivy

There is a newer version: 4.0.3
Show newest version
/*
 * Copyright (c) 2021 Bixbit - Krzysztof Benedyczak. All rights reserved.
 * See LICENCE.txt file for licensing information.
 */

package io.imunity.scim.config;

import java.util.Objects;
import java.util.Optional;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

import io.imunity.scim.console.mapping.AttributeMappingBean;
import io.imunity.scim.console.mapping.DataArrayBean;
import io.imunity.scim.console.mapping.ReferenceDataBean;

@JsonDeserialize(builder = ReferenceAttributeMapping.Builder.class)
public class ReferenceAttributeMapping implements AttributeMapping
{
	public static final String id = "Reference";

	public enum ReferenceType
	{
		USER, GROUP, GENERIC
	}

	public final Optional dataArray;
	public final ReferenceType type;
	public final String expression;

	private ReferenceAttributeMapping(Builder builder)
	{
		this.dataArray = builder.dataArray;
		this.type = builder.type;
		this.expression = builder.expression;
	}

	@Override
	public Optional getDataArray()
	{
		return dataArray;
	}

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

	@Override
	public AttributeMappingBean toBean()
	{
		AttributeMappingBean bean = new AttributeMappingBean();
		bean.setDataArray(dataArray.isEmpty() ? new DataArrayBean()
				: new DataArrayBean(dataArray.get().type, dataArray.get().value));
		bean.setDataReference(new ReferenceDataBean(type, expression));
		return bean;
	}

	@Override
	public int hashCode()
	{
		return Objects.hash(dataArray, expression, type);
	}

	@Override
	public boolean equals(Object obj)
	{
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ReferenceAttributeMapping other = (ReferenceAttributeMapping) obj;
		return Objects.equals(dataArray, other.dataArray) && Objects.equals(expression, other.expression)
				&& type == other.type;
	}

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

	@JsonIgnoreProperties(ignoreUnknown = true)
	public static final class Builder
	{
		private Optional dataArray = Optional.empty();
		private ReferenceType type;
		private String expression;

		private Builder()
		{
		}

		public Builder withDataArray(Optional dataArray)
		{
			this.dataArray = dataArray;
			return this;
		}

		public Builder withType(ReferenceType type)
		{
			this.type = type;
			return this;
		}

		public Builder withExpression(String expression)
		{
			this.expression = expression;
			return this;
		}

		public ReferenceAttributeMapping build()
		{
			return new ReferenceAttributeMapping(this);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy