SmartAPI
Open Source .NET RQL library for RedDot CMS / OpenText WSM Management Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
IPageSearchFilter.cs
Go to the documentation of this file.
1 ï»¿// SmartAPI - .Net programmatic access to RedDot servers
2 //
3 // Copyright (C) 2013 erminas GbR
4 //
5 // This program is free software: you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License as published by the Free Software Foundation,
7 // either version 3 of the License, or (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 // See the GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License along with this program.
14 // If not, see <http://www.gnu.org/licenses/>.
15 
16 using System;
17 using erminas.SmartAPI.CMS.Project.ContentClasses;
18 using erminas.SmartAPI.CMS.Project.Workflows;
19 using erminas.SmartAPI.Utils;
20 
21 namespace erminas.SmartAPI.CMS.Project.Pages
22 {
23  public interface IPageSearchFilter
24  {
25  string ToSearchItemString();
26  }
27 
29  {
30  #region EqualityOperatorType enum
31 
33  {
34  Equal,
35  NotEqual
36  }
37 
38  #endregion
39 
40  #region IPageSearchPredicate Members
41 
42  public abstract string ToSearchItemString();
43 
44  #endregion
45 
46  protected static string EqualityOperatorToString(EqualityOperatorType type)
47  {
48  return type == EqualityOperatorType.Equal ? "eq" : "ne";
49  }
50 
51  protected static string ToSearchItemStringInternal(string key, string value, string @operator)
52  {
53  const string BASIC_SEARCH_ITEM = @"<SEARCHITEM key=""{0}"" value=""{1}"" operator=""{2}""/>";
54  return string.Format(BASIC_SEARCH_ITEM, key, value, @operator);
55  }
56  }
57 
59  {
60  #region OperatorType enum
61 
62  public enum OperatorType
63  {
64  IsLike,
65  Contains
66  }
67 
68  #endregion
69 
70  public readonly OperatorType Operator;
71  public readonly string Value;
72 
73  public HeadlineFilter(OperatorType op, string value)
74  {
75  Operator = op;
76  Value = value;
77  }
78 
79  public override string ToSearchItemString()
80  {
81  return ToSearchItemStringInternal("headline", Value, Operator == OperatorType.IsLike ? "like" : "contains");
82  }
83  }
84 
86  {
87  public readonly EqualityOperatorType Operator;
88  public readonly string Value;
89 
90  public HeadlineAndContentFilter(EqualityOperatorType @operator, string value)
91  {
92  Operator = @operator;
93  Value = value;
94  }
95 
96  public override string ToSearchItemString()
97  {
98  return ToSearchItemStringInternal("keyword", Value, EqualityOperatorToString(Operator));
99  }
100  }
101 
103  {
104  public readonly EqualityOperatorType Operator;
105  public readonly IWorkflow Workflow;
106 
107  public WorkflowFilter(EqualityOperatorType @operator, IWorkflow workflow)
108  {
109  Operator = @operator;
110  Workflow = workflow;
111  }
112 
113  public override string ToSearchItemString()
114  {
115  return ToSearchItemStringInternal("workflow", Workflow.Guid.ToRQLString(),
116  EqualityOperatorToString(Operator));
117  }
118  }
119 
121  {
122  #region PageCategoryType enum
123 
124  public enum PageCategoryType
125  {
126  Linked,
127  Unlinked,
128  RecycleBin,
129  Active,
130  All
131  }
132 
133  #endregion
134 
136 
137  public SpecialPageFilter(PageCategoryType pageCategory)
138  {
139  PageCategory = pageCategory;
140  }
141 
142  public override string ToSearchItemString()
143  {
144  return ToSearchItemStringInternal("specialpages", PageCategory.ToString().ToLowerInvariant(), "eq");
145  }
146  }
147 
149  {
150  private readonly IContentClass _contentClass;
151 
152  public ContentClassFilter(IContentClass contentClass)
153  {
154  _contentClass = contentClass;
155  }
156 
157  public override string ToSearchItemString()
158  {
159  return ToSearchItemStringInternal("contentclassguid", _contentClass.Guid.ToRQLString(), "eq");
160  }
161  }
162 
164  {
165  private readonly IContentClass _contentClass;
166 
168  {
169  _contentClass = contentClass;
170  }
171 
172  public override string ToSearchItemString()
173  {
174  return ToSearchItemStringInternal("contentclassguid", _contentClass.Guid.ToRQLString(), "ne");
175  }
176  }
177 
179  {
180  #region PageStatusType enum
181 
182  public enum PageStatusType
183  {
184  SavedAsDraft,
185  WaitingForRelease,
186  WaitingForCorrection,
187  InWorkflow,
188  Resubmitted,
189  Released
190  }
191 
192  #endregion
193 
194  #region UserType enum
195 
196  public enum UserType
197  {
198  CurrentUser,
199  AllUsers
200  }
201 
202  #endregion
203 
204  public readonly PageStatusType PageStatus;
205 
206  public readonly UserType User;
207 
208  public PageStatusFilter(PageStatusType pageStatus, UserType user)
209  {
210  PageStatus = pageStatus;
211  User = user;
212  }
213 
214  public override string ToSearchItemString()
215  {
216  const string STATUS_ITEM = @"<SEARCHITEM key=""pagestate"" value=""{0}"" users=""{1}"" />";
217  return string.Format(STATUS_ITEM, PageStatusTypeToString(PageStatus),
218  User == UserType.CurrentUser ? "myself" : "all");
219  }
220 
221  private static string PageStatusTypeToString(PageStatusType pageStatus)
222  {
223  switch (pageStatus)
224  {
225  case PageStatusType.WaitingForCorrection:
226  return "waitingforcorrection";
227  case PageStatusType.WaitingForRelease:
228  return "waitingforrelease";
229  case PageStatusType.SavedAsDraft:
230  return "checkedout";
231  case PageStatusType.Released:
232  return "released";
233  case PageStatusType.Resubmitted:
234  return "resubmitted";
235  case PageStatusType.InWorkflow:
236  return "pagesinworkflow";
237 
238  default:
239  throw new ArgumentException(String.Format("Unknown page status {0}", pageStatus));
240  }
241  }
242  }
243 }