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

com.memority.domino.shared.api.context.ShadowContext Maven / Gradle / Ivy

Go to download

This artifact provides the API classes that are necessary to implement synchronization configuration Rules on the Memority IM platform.

There is a newer version: 3.43.1
Show newest version
/*
 * Copyright (c) 2016-2023 Memority. All Rights Reserved.
 *
 * This file is part of Memority Domino API , a Memority project.
 *
 * This file is released under the Memority Public Artifacts End-User License Agreement,
 * see 
 * Unauthorized copying of this file, via any medium is strictly prohibited.
 */
package com.memority.domino.shared.api.context;

import com.memority.citadel.shared.api.context.SimpleAttributeValues;
import com.memority.citadel.shared.api.im.AttributeValue;
import com.memority.citadel.shared.api.im.HasAttributeValues;
import com.memority.domino.shared.api.AttributeValueConverterUtils;
import com.memority.domino.shared.api.sync.ShadowKind;
import com.memority.domino.shared.api.sync.SyncSituation;
import com.memority.toolkit.core.api.groovy.ReadOnlyMapLikeGroovyObject;
import com.memority.toolkit.rule.api.context.ContextConfigurer;

import org.apache.commons.lang3.Validate;

import java.util.List;
import java.util.stream.Collectors;

/**
 * This context provides information about an operation performed on a Shadow. It holds
 * all of the current shadow attributes, potentially being worked on, as well as the original
 * attributes (if available).
 *
 * 

Note: this context is immutable.

*/ public class ShadowContext implements ReadOnlyMapLikeGroovyObject { private ShadowKind kind; private String type; private String id; private HasAttributeValues attributes; private SyncSituation situation; public ShadowContext(ShadowKind shadowKind) { Validate.notNull(shadowKind); this.kind = shadowKind; } /** * @return the current Shadow attributes */ public HasAttributeValues getAttributes() { return attributes; } /** * @return the kind of Shadow being worked on, never null */ public ShadowKind getKind() { return kind; } /** * @return the shadow's identifier within the remote Application, e.g. an LDAP uuid or DN (never null) */ public String getId() { return id; } /** * @return the value of the IDM {@code ObjectType}, such as "employee" or "partner" (never null) */ public String getType() { return type; } /** * @return the shadow's synchronization situation */ public SyncSituation getSituation() { return situation; } /** * This make the Groovy static compiler check consider this object as potentially having any property, making * code such as myObj.prop pass the compiler check. */ @Override public Object getProperty(String propertyName) { return HasAttributeValueHelperTodoDuplicateClass.doGet(getAttributes(), propertyName); } /** * @param returningContext the parent, returning context * @param the type of returning context * @return a configurer of this context with the given parent */ public ShadowContextConfigurer configureFrom(C returningContext) { return new ShadowContextConfigurerImpl<>(returningContext); } public interface ShadowContextConfigurer extends ContextConfigurer { ShadowContextConfigurer identifiedAs(String type, String id); ShadowContextConfigurer withAttributes(List> attributes); ShadowContextConfigurer withSituation(SyncSituation situation); default C end() { return and(); } } class ShadowContextConfigurerImpl implements ShadowContextConfigurer { private final C returningContext; public ShadowContextConfigurerImpl(C returningContext) { this.returningContext = returningContext; } @Override public ShadowContextConfigurer identifiedAs(String type, String id) { ShadowContext.this.type = type; ShadowContext.this.id = id; return this; } @Override public ShadowContextConfigurer withAttributes(List> attributes) { ShadowContext.this.attributes = new SimpleAttributeValues( attributes.stream() .map(AttributeValueConverterUtils::convertFromJavaToApi) .collect(Collectors.toList()) ); return this; } @Override public ShadowContextConfigurer withSituation(SyncSituation situation) { ShadowContext.this.situation = situation; return this; } @Override public C and() { return this.returningContext; } } }