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

de.captaingoldfish.scim.sdk.server.endpoints.bulkid.BulkIdReferencePatchNodeWrapper Maven / Gradle / Ivy

There is a newer version: 1.26.0
Show newest version
// Generated by delombok at Thu Nov 02 20:38:53 CET 2023
package de.captaingoldfish.scim.sdk.server.endpoints.bulkid;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import de.captaingoldfish.scim.sdk.common.constants.AttributeNames;
import de.captaingoldfish.scim.sdk.common.request.PatchRequestOperation;


/**
 * @author Pascal Knueppel
 * @since 22.08.2022
 */
public class BulkIdReferencePatchNodeWrapper implements BulkIdReferenceWrapper
{

  private static final Pattern GET_BULK_ID_PATTERN = Pattern.compile("^bulkId:(.*)|\"bulkId:(.*?)\"");

  private final PatchRequestOperation patchRequestOperation;

  private final String operationValue;

  private final int valueIndex;

  private final String bulkId;

  public BulkIdReferencePatchNodeWrapper(PatchRequestOperation patchRequestOperation,
                                         String operationValue,
                                         int valueIndex)
  {
    this.patchRequestOperation = patchRequestOperation;
    this.operationValue = operationValue;
    this.valueIndex = valueIndex;
    Matcher matcher = GET_BULK_ID_PATTERN.matcher(operationValue);
    matcher.find();
    this.bulkId = matcher.group(1) == null ? matcher.group(2) : matcher.group(1);
  }

  @Override
  public void replaceValueNode(String newValue)
  {
    List operations = patchRequestOperation.getValues();
    operations.remove(valueIndex);
    String newOperationValue = operationValue.replaceAll(String.format("%s:%s", AttributeNames.RFC7643.BULK_ID, bulkId),
                                                         newValue);
    operations.add(valueIndex, newOperationValue);
    patchRequestOperation.setValues(operations);
  }

  @java.lang.SuppressWarnings("all")
  public String getBulkId()
  {
    return this.bulkId;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy