001/* 002 * Copyright 2026 Revetware LLC. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package com.revetsec.scim; 018 019import com.google.errorprone.annotations.CheckReturnValue; 020import org.jspecify.annotations.NonNull; 021import javax.annotation.concurrent.Immutable; 022import java.util.Collections; 023import java.util.LinkedHashSet; 024import java.util.Set; 025import static java.util.Objects.requireNonNull; 026 027/** A bounded create or replacement candidate; success is not authorization or persistence. 028 * 029 * @since 1.0.0 030 */ 031@Immutable 032public sealed interface ScimResourceParseResult permits ScimResourceParseResult.Succeeded, ScimResourceParseResult.Rejected { 033 /** A normalized candidate and the canonical paths actually supplied by the accepted request. 034 * 035 * @since 1.0.0 036 */ 037 @Immutable final class Succeeded implements ScimResourceParseResult { 038 private final @NonNull ScimResource resource; 039 private final @NonNull Set<@NonNull ScimAttributePath> suppliedAttributePaths; 040 private final @NonNull Object semanticContext; 041 Succeeded(@NonNull ScimResource resource, @NonNull Set<@NonNull ScimAttributePath> paths, @NonNull Object context) { 042 this.resource = requireNonNull(resource); 043 this.suppliedAttributePaths = Collections.unmodifiableSet(new LinkedHashSet<>(paths)); 044 this.semanticContext = requireNonNull(context); 045 } 046 /** Returns the candidate resource. 047 * @return the resource 048 * @since 1.0.0 */ 049 @CheckReturnValue public @NonNull ScimResource getResource() { return resource; } 050 /** Returns canonical nested leaf paths actually supplied, distinct from the final resource contents. 051 * 052 * @return the immutable paths 053 * @since 1.0.0 054 */ 055 @CheckReturnValue public @NonNull Set<@NonNull ScimAttributePath> getSuppliedAttributePaths() { return suppliedAttributePaths; } 056 @NonNull Object getSemanticContext() { return semanticContext; } 057 /** Returns a fixed redacted description. 058 * @return the description 059 * @since 1.0.0 */ 060 @Override public @NonNull String toString() { return "ScimResourceParseResult.Succeeded{resource=<redacted>, paths=<redacted>}"; } 061 } 062 /** A fixed rejection with no partial candidate. 063 * @since 1.0.0 */ 064 @Immutable final class Rejected implements ScimResourceParseResult { 065 private final @NonNull ScimError error; 066 Rejected(@NonNull ScimError error) { this.error = requireNonNull(error); } 067 /** Returns the fixed error. 068 * @return the error 069 * @since 1.0.0 */ 070 @CheckReturnValue public @NonNull ScimError getError() { return error; } 071 /** Returns a fixed redacted description. 072 * @return the description 073 * @since 1.0.0 */ 074 @Override public @NonNull String toString() { return "ScimResourceParseResult.Rejected{error=<redacted>}"; } 075 } 076}