001/* 002 * Copyright 2015-2021 Ping Identity Corporation 003 * 004 * This program is free software; you can redistribute it and/or modify 005 * it under the terms of the GNU General Public License (GPLv2 only) 006 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 007 * as published by the Free Software Foundation. 008 * 009 * This program is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 * GNU General Public License for more details. 013 * 014 * You should have received a copy of the GNU General Public License 015 * along with this program; if not, see <http://www.gnu.org/licenses>. 016 */ 017 018package com.unboundid.scim2.client.requests; 019 020import com.unboundid.scim2.common.utils.ApiConstants; 021import com.unboundid.scim2.common.utils.StaticUtils; 022 023import javax.ws.rs.client.WebTarget; 024import java.util.Set; 025 026/** 027 * Abstract SCIM request builder for resource returning requests. 028 */ 029public abstract class ResourceReturningRequestBuilder 030 <T extends ResourceReturningRequestBuilder> extends RequestBuilder<T> 031{ 032 /** 033 * Whether the attribute list is for excluded attributes. 034 */ 035 protected boolean excluded; 036 037 /** 038 * The attribute list of include or exclude. 039 */ 040 protected Set<String> attributes; 041 042 /** 043 * Create a new SCIM request builder. 044 * 045 * @param target The WebTarget to send the request. 046 */ 047 ResourceReturningRequestBuilder(final WebTarget target) 048 { 049 super(target); 050 } 051 052 /** 053 * Build the WebTarget for the request. 054 * 055 * @return The WebTarget for the request. 056 */ 057 WebTarget buildTarget() 058 { 059 if(attributes != null && attributes.size() > 0) 060 { 061 if(!excluded) 062 { 063 return super.buildTarget().queryParam( 064 ApiConstants.QUERY_PARAMETER_ATTRIBUTES, 065 StaticUtils.collectionToString(attributes, ",")); 066 } 067 else 068 { 069 return super.buildTarget().queryParam( 070 ApiConstants.QUERY_PARAMETER_EXCLUDED_ATTRIBUTES, 071 StaticUtils.collectionToString(attributes, ",")); 072 } 073 } 074 return super.buildTarget(); 075 } 076 077 /** 078 * Specifies a multi-valued list of strings indicating the names of 079 * resource attributes to return in the response overriding the set 080 * of attributes that would be returned by default. Any existing excluded 081 * attributes will be removed. 082 * 083 * @param attributes the names of resource attributes to return 084 * @return This builder. 085 */ 086 @SuppressWarnings("unchecked") 087 public T attributes(final String... attributes) 088 { 089 this.attributes = StaticUtils.arrayToSet(attributes); 090 return (T) this; 091 } 092 093 /** 094 * Specifies a multi-valued list of strings indicating the names of resource 095 * attributes to be removed from the default set of attributes to return. Any 096 * existing attributes to return will be removed. 097 * 098 * @param excludedAttributes names of resource attributes to be removed from 099 * the default set of attributes to return. 100 * @return This builder. 101 */ 102 @SuppressWarnings("unchecked") 103 public T excludedAttributes(final String... excludedAttributes) 104 { 105 this.attributes = StaticUtils.arrayToSet(excludedAttributes); 106 this.excluded = true; 107 return (T) this; 108 } 109 110}