io.imunity.furms.unity.common.AttributeValueMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of furms-unity-client Show documentation
Show all versions of furms-unity-client Show documentation
FURMS Unity DAO/Client module
/*
* 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();
}
}