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

io.imunity.furms.unity.common.AttributeValueMapper Maven / Gradle / Ivy

There is a newer version: 4.3.1
Show newest version
/*
 * Copyright (c) 2021 Bixbit - Krzysztof Benedyczak. All rights reserved.
 * See LICENCE.txt file for licensing information.
 */
package io.imunity.furms.unity.common;

import io.imunity.rest.api.RestAttributeExt;
import pl.edu.icm.unity.types.basic.Attribute;
import pl.edu.icm.unity.types.basic.VerifiableEmail;

import java.util.Map;
import java.util.function.Function;

public class AttributeValueMapper {
	private static final Function DEFAULT_VALUE_MAPPER = value -> value;
	private static final Map> mappersByAttributeType = Map.of(
				"verifiableEmail", AttributeValueMapper::convertEmail
			);
	
	public static String toFurmsAttributeValue(Attribute attribute, String value) {
		return mappersByAttributeType.getOrDefault(attribute.getValueSyntax(), DEFAULT_VALUE_MAPPER)
				.apply(value);
	}

	public static String toFurmsAttributeValue(RestAttributeExt attribute, String value) {
		return mappersByAttributeType.getOrDefault(attribute.getValueSyntax(), DEFAULT_VALUE_MAPPER)
			.apply(value);
	}
	
	private static String convertEmail(String encodedEmail) {
		return VerifiableEmail.fromJsonString(encodedEmail).getValue();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy