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

cdm.event.position.functions.IsValidPartyRole Maven / Gradle / Ivy

There is a newer version: 6.0.0-dev.89
Show newest version
package cdm.event.position.functions;

import cdm.base.staticdata.party.PartyRole;
import cdm.base.staticdata.party.PartyRoleEnum;
import com.google.inject.ImplementedBy;
import com.rosetta.model.lib.expression.CardinalityOperator;
import com.rosetta.model.lib.functions.RosettaFunction;
import com.rosetta.model.lib.mapper.MapperC;
import com.rosetta.model.lib.mapper.MapperS;
import java.util.Collections;
import java.util.List;

import static com.rosetta.model.lib.expression.ExpressionOperators.*;

@ImplementedBy(IsValidPartyRole.IsValidPartyRoleDefault.class)
public abstract class IsValidPartyRole implements RosettaFunction {

	/**
	* @param partyRoles 
	* @param validRoles 
	* @return isValid 
	*/
	public Boolean evaluate(List partyRoles, List validRoles) {
		Boolean isValid = doEvaluate(partyRoles, validRoles);
		
		return isValid;
	}

	protected abstract Boolean doEvaluate(List partyRoles, List validRoles);

	public static class IsValidPartyRoleDefault extends IsValidPartyRole {
		@Override
		protected Boolean doEvaluate(List partyRoles, List validRoles) {
			if (partyRoles == null) {
				partyRoles = Collections.emptyList();
			}
			if (validRoles == null) {
				validRoles = Collections.emptyList();
			}
			Boolean isValid = null;
			return assignOutput(isValid, partyRoles, validRoles);
		}
		
		protected Boolean assignOutput(Boolean isValid, List partyRoles, List validRoles) {
			final MapperC thenResult = MapperC.of(partyRoles)
				.mapItem(item -> contains(MapperC.of(validRoles), item.map("getRole", partyRole -> partyRole.getRole())).asMapper());
			isValid = areEqual(thenResult, MapperS.of(true), CardinalityOperator.All).asMapper().get();
			
			return isValid;
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy