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

com.memority.citadel.shared.api.services.PatchBuilder Maven / Gradle / Ivy

Go to download

This artifact provides the API classes that are necessary to implement general 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 Citadel 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.citadel.shared.api.services;

import com.memority.citadel.shared.api.im.operation.AttributeOperation;
import com.memority.citadel.shared.api.im.operation.AttributePatch;
import com.memority.citadel.shared.api.im.operation.ObjectPatch;

import java.util.List;

/**
 * Builds an {@link ObjectPatch}
 */
public interface PatchBuilder> {
    /**
     * Delete the specified attribute, removing all its values.
     *
     * @param attribute the attribute to delete.
     * @return this builder.
     */
    B delete(String attribute);

    /**
     * Sets the given attribute to a specified value(s). Usage:
     * 
     *     objectManager.patch(obj)
     *        .set("monoValuedAttr").value("foo")
     *        .set("multivaluedAttr").values("bar", "baz")
     *        ...
     * 
* @param attribute the attribute to set. * @return a {@link SetAttributePatchBuilder}, to specify the new attribute values. * @see SetAttributePatchBuilder */ SetAttributePatchBuilder set(String attribute); /** * Adds the specified values to the given attribute, either at the end or at the specified index. Usage:
*
     *     objectManager.patch(obj)
     *         .add("multivaluedAttr1").values("foo", "bar").atEnd()
     *         .add("multivaluedAttr2").values("baz").atIndex(42)
     *         ...
     * 
* @param attribute the attribut to which the values will be added * @return an {@link AddAttributePatchBuilder}, to specify which values to add and where. * @see AddAttributePatchBuilder */ AddAttributePatchBuilder add(String attribute); /** * Removes the specified values from the given attribute. Usage:
*
     *     objectManager.patch(obj)
     *         .remove("multivaluedAttr").values("foo", "bar")
     * 
* @param attribute the attribute to remove the values from. * @return a {@link RemoveAttributePatchBuilder}, to specify which values to remove. * @see RemoveAttributePatchBuilder */ RemoveAttributePatchBuilder remove(String attribute); /** * Replaces old values with new ones for the given attribute; this is equivalent to calling * {@link #remove(String)} then {@link #add(String)}. Usage: *
     *     objectManager.patch(obj)
     *         .replace("multivaluedAttr1").oldValues("foo", "bar").with("baz").atEnd()
     *         .replace("multivaluedAttr2").oldValues("foo", "bar").with("baz").atIndex(42)
     * 
* @param attribute the attribute to replace the values from. * @param the attribute values type. * @return a {@link ReplacePatchOldValuesBuilder}, to specify what to remove, what to add and where. * @see ReplacePatchOldValuesBuilder */ ReplacePatchOldValuesBuilder replace(String attribute); /** * Creates an {@link AttributeOperation#ADD ADD} * {@link AttributePatch} for the given attribute. * * @see PatchBuilder#add(String) */ interface AddAttributePatchBuilder> { /** * Specifies the values to add. * * @param values the values to add * @param the type of the values to add * @return an {@link PatchBuilder.IndexedPatchBuilder}, to specify where to add the values. * @see PatchBuilder.IndexedPatchBuilder */ IndexedPatchBuilder values(List values); /** * Specifies the values to add. * * @param values the values to add * @param the type of the values to add * @return an {@link PatchBuilder.IndexedPatchBuilder}, to specify where to add the values. * @see #values(List) */ @SuppressWarnings("unchecked") IndexedPatchBuilder values(T... values); } /** * Creates a {@link AttributeOperation#REPLACE REPLACE} * {@link AttributePatch} for the given attribute. This builder is responsible for setting setting the values to * remove. * * @see PatchBuilder#replace(String) */ interface ReplacePatchOldValuesBuilder, T> { /** * Specifies the values to remove. * * @param oldValues the values to remove. * @return a {@link PatchBuilder.ReplacePatchNewValuesBuilder}, to specify the values to add. */ ReplacePatchNewValuesBuilder oldValues(List oldValues); /** * Specifies the values to remove. * * @param oldValues the values to remove. * @return a {@link PatchBuilder.ReplacePatchNewValuesBuilder}, to specify the values to add. * @see #oldValues(List) */ @SuppressWarnings("unchecked") ReplacePatchNewValuesBuilder oldValues(T... oldValues); } /** * Creates a {@link AttributeOperation#REPLACE REPLACE} * {@link AttributePatch} for the given attribute. This builder is responsible for setting setting the values to * add. * * @see PatchBuilder#replace(String) */ interface ReplacePatchNewValuesBuilder, T> { /** * Specifies the values to add. * * @param newValues the values to add. * @return an {@link PatchBuilder.IndexedPatchBuilder}, to specify where the values should be added */ IndexedPatchBuilder with(List newValues); /** * Specifies the values to add. * * @param newValues the values to add. * @return an {@link PatchBuilder.IndexedPatchBuilder}, to specify where the values should be added * @see #with(List) */ @SuppressWarnings("unchecked") IndexedPatchBuilder with(T... newValues); } /** * Helper builder for {@link PatchBuilder.AddAttributePatchBuilder} and {@link PatchBuilder.ReplacePatchNewValuesBuilder} to specify where to * add the new values. */ interface IndexedPatchBuilder> { /** * Specifies to add the new values at the given index and finalizes the {@link AttributePatch} being built. * @param index where new values are inserted (0 is the first index) * @return the parent {@link PatchBuilder}.; */ B atIndex(int index); /** * Specifies to append the new values to the current attribute values and finalizes the {@link AttributePatch} * being built. * @return the parent {@link PatchBuilder}.; */ B atEnd(); } /** * Creates a {@link AttributeOperation#REMOVE REMOVE} * {@link AttributePatch} for the given attribute. * * @see PatchBuilder#remove(String) */ interface RemoveAttributePatchBuilder> { /** * Specifies the values to remove and finalizes the attribute patch being built. * * @param values the values to remove. * @param the type of the attribute values. * @return the parent {@link PatchBuilder} */ B values(List values); /** * Specifies the values to remove and finalizes the attribute patch being built. * * @param values the values to remove. * @param the type of the attribute values. * @return the parent {@link PatchBuilder} * @see #values(List) */ @SuppressWarnings("unchecked") B values(T... values); } /** * Creates a {@link AttributeOperation#SET SET} * {@link AttributePatch} for the given attribute. * * @see PatchBuilder#set(String) */ interface SetAttributePatchBuilder> { /** * Specifies the new values of the attribute, and finalizes the {@link AttributePatch} being built. * * @param values the new values of the attribute * @param the values' type * @return the parent patch builder */ B values(List values); /** * Specifies the new values of the attribute, and finalizes the {@link AttributePatch} being built. * * @param values the new values of the attribute * @param the values' type * @return the parent patch builder * @see #values(List) */ @SuppressWarnings("unchecked") B values(T... values); /** * Specifies the new values of the attribute, and finalizes the {@link AttributePatch} being built. * @param value the new value of the attribute * @param the value type * @return the parent patch builder */ B value(T value); } }