001package com.box.sdk; 002 003import com.eclipsesource.json.JsonObject; 004/** 005 * <p>BoxMetadataFilter is used to help organize the request for when making metadata filter request 006 * in conjuction with search. The translation will look something like this: 007 * [{"templateKey":"marketingCollateral", "scope":"enterprise", "filters":{"documentType": "datasheet"}}]</p> 008 * 009 * 010 */ 011public class BoxMetadataFilter { 012 private String templateKey; 013 private String scope = "enterprise"; 014 private JsonObject filtersList; 015 016 /** 017 * Constructor for BoxMetadataFilter that initizlizes the JSON Object. 018 */ 019 public BoxMetadataFilter() { 020 this.filtersList = new JsonObject(); 021 } 022 /** 023 * Returns the template key that currently set. 024 * @return this.String template key. 025 */ 026 public String getTemplateKey() { 027 return this.templateKey; 028 } 029 /** 030 * Set the current template key for the search filter. 031 * @param templateKey must be a metadata template key. 032 */ 033 public void setTemplateKey(String templateKey) { 034 this.templateKey = templateKey; 035 } 036 /** 037 * return this.a list of the current filters that are being set. 038 * @return this.JsonObject filterList. 039 */ 040 public JsonObject getFiltersList() { 041 return this.filtersList; 042 } 043 /** 044 * Set a filter to the filterList, example: key=documentType, value=special. 045 * @param key the key that the filter should be looking for. 046 * @param value the specific value that corresponds to the key. 047 */ 048 public void addFilter(String key, String value) { 049 this.filtersList.add(key, value); 050 } 051 /** 052 * Set a NumberRanger filter to the filter numbers, example: key=documentNumber, lt : 20, gt : 5. 053 * @param key the key that the filter should be looking for. 054 * @param sizeRange the specific value that corresponds to the key. 055 */ 056 public void addNumberRangeFilter(String key, SizeRange sizeRange) { 057 JsonObject opObj = new JsonObject(); 058 059 if (sizeRange.getLowerBoundBytes() != 0) { 060 opObj.add("gt", sizeRange.getLowerBoundBytes()); 061 } 062 if (sizeRange.getUpperBoundBytes() != 0) { 063 opObj.add("lt", sizeRange.getUpperBoundBytes()); 064 } 065 066 this.filtersList.add(key, opObj); 067 } 068 /** 069 * Set a filter to the filterList, example: key=documentNumber, gt : "", lt : "". 070 * @param key the key that the filter should be looking for. 071 * @param dateRange the date range that is start and end dates 072 */ 073 public void addDateRangeFilter(String key, DateRange dateRange) { 074 075 JsonObject opObj = new JsonObject(); 076 077 if (dateRange.getFromDate() != null) { 078 String dateGtString = BoxDateFormat.format(dateRange.getFromDate()); 079 //workaround replacing + and - 000 at the end with 'Z' 080 dateGtString = dateGtString.replaceAll("(\\+|-)(?!-\\|?!\\+)\\d+$", "Z"); 081 opObj.add("gt", dateGtString); 082 } 083 if (dateRange.getToDate() != null) { 084 String dateLtString = BoxDateFormat.format(dateRange.getToDate()); 085 //workaround replacing + and - 000 at the end with 'Z' 086 dateLtString = dateLtString.replaceAll("(\\+|-)(?!-\\|?!\\+)\\d+$", "Z"); 087 opObj.add("lt", dateLtString); 088 } 089 090 this.filtersList.add(key, opObj); 091 } 092 /** 093 * return this.the current scope being used. 094 * @return this.String scope. 095 */ 096 public String getScope() { 097 return this.scope; 098 } 099 /** 100 * Set the scope for the key, currently only "enterprise" and "global" are allowed. 101 * @param scope the scope on which to find the template. 102 */ 103 public void setScope(String scope) { 104 this.scope = scope; 105 } 106}