001/*- 002 * #%L 003 * HAPI FHIR - Server Framework 004 * %% 005 * Copyright (C) 2014 - 2024 Smile CDR, Inc. 006 * %% 007 * Licensed under the Apache License, Version 2.0 (the "License"); 008 * you may not use this file except in compliance with the License. 009 * You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 * #L% 019 */ 020package ca.uhn.fhir.rest.server.interceptor.consent; 021 022import java.util.stream.Stream; 023 024public enum ConsentOperationStatusEnum implements IConsentVote { 025 026 /** 027 * The requested operation cannot proceed, and an operation outcome suitable for 028 * the user is available 029 */ 030 REJECT, 031 032 /** 033 * The requested operation is allowed to proceed, but the engine will review each 034 * resource before sending to the client 035 */ 036 PROCEED, 037 038 /** 039 * The engine has nothing to say about the operation (same as proceed, but the 040 * host application need not consult the engine - can use more efficient 041 * counting/caching methods) 042 */ 043 AUTHORIZED, 044 ; 045 046 /** 047 * Assigns ordinals to the verdicts by strength: 048 * REJECT > AUTHORIZED > PROCEED. 049 * @return 2/1/0 for REJECT/AUTHORIZED/PROCEED 050 */ 051 int getPrecedence() { 052 switch (this) { 053 case REJECT: 054 return 2; 055 case AUTHORIZED: 056 return 1; 057 case PROCEED: 058 default: 059 return 0; 060 } 061 } 062 063 /** 064 * Does this vote abstain from the verdict? 065 * I.e. this == PROCEED 066 * @return true if this vote can be ignored 067 */ 068 boolean isAbstain() { 069 return this == PROCEED; 070 } 071 072 /** 073 * Does this vote participate from the verdict? 074 * I.e. this != PROCEED 075 * @return false if this vote can be ignored 076 */ 077 boolean isActiveVote() { 078 return this != PROCEED; 079 } 080 081 @Override 082 public ConsentOperationStatusEnum getStatus() { 083 return this; 084 } 085 086 /** 087 * Evaluate verdicts in order, taking the first "decision" (i.e. first non-PROCEED) verdict. 088 * 089 * @return the first decisive verdict, or PROCEED when empty or all PROCEED. 090 */ 091 public static ConsentOperationStatusEnum serialReduce(Stream<ConsentOperationStatusEnum> theVoteStream) { 092 return IConsentVote.serialReduce(PROCEED, theVoteStream); 093 } 094 095 public static ConsentOperationStatusEnum parallelReduce(Stream<ConsentOperationStatusEnum> theVoteStream) { 096 return IConsentVote.parallelReduce(PROCEED, theVoteStream); 097 } 098 099 /** @deprecated for rename */ 100 @Deprecated(forRemoval = true) 101 public static ConsentOperationStatusEnum serialEvaluate(Stream<ConsentOperationStatusEnum> theVoteStream) { 102 return serialReduce(theVoteStream); 103 } 104 105 /** @deprecated for rename */ 106 @Deprecated(forRemoval = true) 107 public static ConsentOperationStatusEnum parallelEvaluate(Stream<ConsentOperationStatusEnum> theVoteStream) { 108 return parallelReduce(theVoteStream); 109 } 110}