PageRenderTime 31ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/servers/sip-presence/presence/server/subscription-sbb/src/main/java/org/mobicents/slee/sippresence/server/subscription/rules/PresRule.java

http://mobicents.googlecode.com/
Java | 553 lines | 410 code | 73 blank | 70 comment | 107 complexity | 75e4c964afc66ae97ca724f35254433f MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0, LGPL-2.1, GPL-2.0, CC-BY-SA-3.0, CC0-1.0, Apache-2.0, BSD-3-Clause
  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2011, Red Hat, Inc. and individual contributors
  4. * by the @authors tag. See the copyright.txt in the distribution for a
  5. * full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.mobicents.slee.sippresence.server.subscription.rules;
  23. import java.io.Serializable;
  24. import java.util.HashSet;
  25. import java.util.Set;
  26. import javax.xml.bind.JAXBElement;
  27. import org.openxdm.xcap.client.appusage.presrules.jaxb.ProvideDevicePermission;
  28. import org.openxdm.xcap.client.appusage.presrules.jaxb.ProvidePersonPermission;
  29. import org.openxdm.xcap.client.appusage.presrules.jaxb.ProvideServicePermission;
  30. import org.openxdm.xcap.common.uri.DocumentSelector;
  31. /**
  32. * Pres-rules object for applying transformations.
  33. *
  34. * @author emmartins
  35. *
  36. */
  37. public class PresRule implements Serializable {
  38. /**
  39. *
  40. */
  41. private static final long serialVersionUID = -2821668554015646242L;
  42. private final DocumentSelector documentSelector;
  43. private SubHandlingAction subHandling = SubHandlingAction.confirm;
  44. // ------------ provide all devices, if true override all values in
  45. // "provide devices"
  46. private boolean provideAllDevices;
  47. // ------------ provide devices
  48. private Set<String> provideDeviceClasses;
  49. private Set<String> provideDeviceOccurenceIds;
  50. private Set<String> provideDeviceDeviceIDs;
  51. // ------------ provide all persons, if true override all values in
  52. // "provide persons"
  53. private boolean provideAllPersons;
  54. // ------------ provide persons
  55. private Set<String> providePersonClasses;
  56. private Set<String> providePersonOccurenceIds;
  57. // ------------ provide all services, if true override all values in
  58. // "provide services"
  59. private boolean provideAllServices;
  60. // ------------ provide services
  61. private Set<String> provideServiceClasses;
  62. private Set<String> provideServiceOccurenceIds;
  63. private Set<String> provideServiceServiceURIs;
  64. private Set<String> provideServiceServiceURISchemes;
  65. // ----------- provide all attributes, if true overrides all
  66. // "provide attributes"
  67. private boolean provideAllAttributes;
  68. // ----------- provide attributes
  69. private boolean provideActivities;
  70. private boolean provideClass;
  71. private boolean provideDeviceID;
  72. private boolean provideMood;
  73. private boolean providePlaceIs;
  74. private boolean providePlaceType;
  75. private boolean providePrivacy;
  76. private boolean provideRelationship;
  77. private boolean provideSphere;
  78. private boolean provideStatusIcon;
  79. private boolean provideTimeOffset;
  80. private UserInputTransformation provideUserInput = UserInputTransformation.FALSE;
  81. private boolean provideNote;
  82. private Set<UnknownBooleanAttributeTransformation> unknownBooleanAttributes;
  83. public PresRule(DocumentSelector documentSelector) {
  84. this.documentSelector = documentSelector;
  85. }
  86. public DocumentSelector getDocumentSelector() {
  87. return documentSelector;
  88. }
  89. /**
  90. * Combine another rule with this rule.
  91. */
  92. public void combine(PresRule other) {
  93. /*
  94. * If a particular permission type has no value in a rule, it assumes
  95. * the lowest possible value for that permission for the purpose of
  96. * computing the combined permission. That value is given by the data
  97. * type for booleans (FALSE) and sets (empty set), and MUST be defined
  98. * by any extension to the Common Policy for other data types.
  99. *
  100. * For boolean permissions, the resulting permission is TRUE if and only
  101. * if at least one permission in the matching rule set has a value of
  102. * TRUE and FALSE otherwise. For integer, real-valued and date-time
  103. * permissions, the resulting permission is the maximum value across the
  104. * permission values in the matching set of rules. For sets, it is the
  105. * union of values across the permissions in the matching rule set.
  106. */
  107. // here we go, booleans are combined with OR, UNION for strings lists,
  108. // MAX for ints
  109. if (this.subHandling.getValue() < other.subHandling.getValue()) {
  110. this.subHandling = other.subHandling;
  111. }
  112. this.provideAllDevices = this.provideAllDevices
  113. || other.provideAllDevices;
  114. if (!this.provideAllDevices) {
  115. // only combine "provide devices if "provide all" is not true
  116. if (other.provideDeviceClasses != null) {
  117. if (this.provideDeviceClasses == null) {
  118. this.provideDeviceClasses = new HashSet<String>();
  119. }
  120. this.provideDeviceClasses.addAll(other.provideDeviceClasses);
  121. }
  122. if (other.provideDeviceOccurenceIds != null) {
  123. if (this.provideDeviceOccurenceIds == null) {
  124. this.provideDeviceOccurenceIds = new HashSet<String>();
  125. }
  126. this.provideDeviceOccurenceIds
  127. .addAll(other.provideDeviceOccurenceIds);
  128. }
  129. if (other.provideDeviceDeviceIDs != null) {
  130. if (this.provideDeviceDeviceIDs == null) {
  131. this.provideDeviceDeviceIDs = new HashSet<String>();
  132. }
  133. this.provideDeviceDeviceIDs
  134. .addAll(other.provideDeviceDeviceIDs);
  135. }
  136. }
  137. this.provideAllPersons = this.provideAllPersons
  138. || other.provideAllPersons;
  139. if (!this.provideAllPersons) {
  140. // only combine "provide persons if "provide all" is not true
  141. if (other.providePersonClasses != null) {
  142. if (this.providePersonClasses == null) {
  143. this.providePersonClasses = new HashSet<String>();
  144. }
  145. this.providePersonClasses.addAll(other.providePersonClasses);
  146. }
  147. if (other.providePersonOccurenceIds != null) {
  148. if (this.providePersonOccurenceIds == null) {
  149. this.providePersonOccurenceIds = new HashSet<String>();
  150. }
  151. this.providePersonOccurenceIds
  152. .addAll(other.providePersonOccurenceIds);
  153. }
  154. }
  155. this.provideAllServices = this.provideAllServices
  156. || other.provideAllServices;
  157. if (!this.provideAllServices) {
  158. // only combine "provide services if "provide all" is not true
  159. if (other.provideServiceClasses != null) {
  160. if (this.provideServiceClasses == null) {
  161. this.provideServiceClasses = new HashSet<String>();
  162. }
  163. this.provideServiceClasses.addAll(other.provideServiceClasses);
  164. }
  165. if (other.provideServiceOccurenceIds != null) {
  166. if (this.provideServiceOccurenceIds == null) {
  167. this.provideServiceOccurenceIds = new HashSet<String>();
  168. }
  169. this.provideServiceOccurenceIds
  170. .addAll(other.provideServiceOccurenceIds);
  171. }
  172. if (other.provideServiceServiceURIs != null) {
  173. if (this.provideServiceServiceURIs == null) {
  174. this.provideServiceServiceURIs = new HashSet<String>();
  175. }
  176. this.provideServiceServiceURIs
  177. .addAll(other.provideServiceServiceURIs);
  178. }
  179. if (other.provideServiceServiceURISchemes != null) {
  180. if (this.provideServiceServiceURISchemes == null) {
  181. this.provideServiceServiceURISchemes = new HashSet<String>();
  182. }
  183. this.provideServiceServiceURISchemes
  184. .addAll(other.provideServiceServiceURISchemes);
  185. }
  186. }
  187. this.provideAllAttributes = this.provideAllAttributes
  188. || other.provideAllAttributes;
  189. if (!this.provideAllAttributes) {
  190. // only combine "provide attributes if "provide all" is not true
  191. this.provideActivities = this.provideActivities
  192. || other.provideActivities;
  193. this.provideClass = this.provideClass || other.provideClass;
  194. this.provideDeviceID = this.provideDeviceID
  195. || other.provideDeviceID;
  196. this.provideMood = this.provideMood || other.provideMood;
  197. this.providePlaceIs = this.providePlaceIs || other.providePlaceIs;
  198. this.providePlaceType = this.providePlaceType
  199. || other.providePlaceType;
  200. this.providePrivacy = this.providePrivacy || other.providePrivacy;
  201. this.provideRelationship = this.provideRelationship
  202. || other.provideRelationship;
  203. this.provideSphere = this.provideSphere || other.provideSphere;
  204. this.provideStatusIcon = this.provideStatusIcon
  205. || other.provideStatusIcon;
  206. this.provideTimeOffset = this.provideTimeOffset
  207. || other.provideTimeOffset;
  208. if (this.provideUserInput.getValue() < other.provideUserInput
  209. .getValue()) {
  210. this.provideUserInput = other.provideUserInput;
  211. }
  212. this.provideNote = this.provideNote || other.provideNote;
  213. if (other.unknownBooleanAttributes != null) {
  214. if (this.unknownBooleanAttributes == null) {
  215. this.unknownBooleanAttributes = new HashSet<UnknownBooleanAttributeTransformation>();
  216. }
  217. this.unknownBooleanAttributes
  218. .addAll(other.unknownBooleanAttributes);
  219. }
  220. }
  221. }
  222. // ---- GETTERS AND SETTERS
  223. public SubHandlingAction getSubHandling() {
  224. return subHandling;
  225. }
  226. public void setSubHandling(SubHandlingAction subHandling) {
  227. this.subHandling = subHandling;
  228. }
  229. public boolean isProvideAllDevices() {
  230. return provideAllDevices;
  231. }
  232. public void setProvideAllDevices(boolean provideAllDevices) {
  233. this.provideAllDevices = provideAllDevices;
  234. }
  235. public Set<String> getProvideDeviceClasses() {
  236. return provideDeviceClasses;
  237. }
  238. public Set<String> getProvideDeviceOccurenceIds() {
  239. return provideDeviceOccurenceIds;
  240. }
  241. public Set<String> getProvideDeviceDeviceIDs() {
  242. return provideDeviceDeviceIDs;
  243. }
  244. public boolean isProvideAllPersons() {
  245. return provideAllPersons;
  246. }
  247. public void setProvideAllPersons(boolean provideAllPersons) {
  248. this.provideAllPersons = provideAllPersons;
  249. }
  250. public Set<String> getProvidePersonClasses() {
  251. return providePersonClasses;
  252. }
  253. public Set<String> getProvidePersonOccurenceIds() {
  254. return providePersonOccurenceIds;
  255. }
  256. public boolean isProvideAllServices() {
  257. return provideAllServices;
  258. }
  259. public void setProvideAllServices(boolean provideAllServices) {
  260. this.provideAllServices = provideAllServices;
  261. }
  262. public Set<String> getProvideServiceClasses() {
  263. return provideServiceClasses;
  264. }
  265. public Set<String> getProvideServiceOccurenceIds() {
  266. return provideServiceOccurenceIds;
  267. }
  268. public Set<String> getProvideServiceServiceURIs() {
  269. return provideServiceServiceURIs;
  270. }
  271. public Set<String> getProvideServiceServiceURISchemes() {
  272. return provideServiceServiceURISchemes;
  273. }
  274. public boolean isProvideAllAttributes() {
  275. return provideAllAttributes;
  276. }
  277. public void setProvideAllAttributes(boolean provideAllAttributes) {
  278. this.provideAllAttributes = provideAllAttributes;
  279. }
  280. public boolean isProvideActivities() {
  281. return provideActivities;
  282. }
  283. public void setProvideActivities(boolean provideActivities) {
  284. this.provideActivities = provideActivities;
  285. }
  286. public boolean isProvideClass() {
  287. return provideClass;
  288. }
  289. public void setProvideClass(boolean provideClass) {
  290. this.provideClass = provideClass;
  291. }
  292. public boolean isProvideDeviceID() {
  293. return provideDeviceID;
  294. }
  295. public void setProvideDeviceID(boolean provideDeviceID) {
  296. this.provideDeviceID = provideDeviceID;
  297. }
  298. public boolean isProvideMood() {
  299. return provideMood;
  300. }
  301. public void setProvideMood(boolean provideMood) {
  302. this.provideMood = provideMood;
  303. }
  304. public boolean isProvidePlaceIs() {
  305. return providePlaceIs;
  306. }
  307. public void setProvidePlaceIs(boolean providePlaceIs) {
  308. this.providePlaceIs = providePlaceIs;
  309. }
  310. public boolean isProvidePlaceType() {
  311. return providePlaceType;
  312. }
  313. public void setProvidePlaceType(boolean providePlaceType) {
  314. this.providePlaceType = providePlaceType;
  315. }
  316. public boolean isProvidePrivacy() {
  317. return providePrivacy;
  318. }
  319. public void setProvidePrivacy(boolean providePrivacy) {
  320. this.providePrivacy = providePrivacy;
  321. }
  322. public boolean isProvideRelationship() {
  323. return provideRelationship;
  324. }
  325. public void setProvideRelationship(boolean provideRelationship) {
  326. this.provideRelationship = provideRelationship;
  327. }
  328. public boolean isProvideSphere() {
  329. return provideSphere;
  330. }
  331. public void setProvideSphere(boolean provideSphere) {
  332. this.provideSphere = provideSphere;
  333. }
  334. public boolean isProvideStatusIcon() {
  335. return provideStatusIcon;
  336. }
  337. public void setProvideStatusIcon(boolean provideStatusIcon) {
  338. this.provideStatusIcon = provideStatusIcon;
  339. }
  340. public boolean isProvideTimeOffset() {
  341. return provideTimeOffset;
  342. }
  343. public void setProvideTimeOffset(boolean provideTimeOffset) {
  344. this.provideTimeOffset = provideTimeOffset;
  345. }
  346. public UserInputTransformation getProvideUserInput() {
  347. return provideUserInput;
  348. }
  349. public void setProvideUserInput(UserInputTransformation provideUserInput) {
  350. this.provideUserInput = provideUserInput;
  351. }
  352. public boolean isProvideNote() {
  353. return provideNote;
  354. }
  355. public void setProvideNote(boolean provideNote) {
  356. this.provideNote = provideNote;
  357. }
  358. public Set<UnknownBooleanAttributeTransformation> getUnknownBooleanAttributes() {
  359. return unknownBooleanAttributes;
  360. }
  361. public void setUnknownBooleanAttributes(
  362. Set<UnknownBooleanAttributeTransformation> unknownBooleanAttributes) {
  363. this.unknownBooleanAttributes = unknownBooleanAttributes;
  364. }
  365. public boolean hasTransformations() {
  366. return !isProvideAllAttributes() || !isProvideAllDevices() || !isProvideAllPersons() || !isProvideAllServices();
  367. }
  368. // ------------------- processors
  369. @SuppressWarnings("rawtypes")
  370. public void processDevicePermission(
  371. ProvideDevicePermission provideDevicePermission) {
  372. provideAllDevices = provideDevicePermission.getAllDevices() != null;
  373. if (!provideAllDevices) {
  374. for (Object deviceTransformationObject : provideDevicePermission
  375. .getDeviceIDOrOccurrenceIdOrClazz()) {
  376. JAXBElement deviceTransformationElement = (JAXBElement) deviceTransformationObject;
  377. if (deviceTransformationElement.getName().getLocalPart()
  378. .equals("class")) {
  379. if (provideDeviceClasses == null) {
  380. provideDeviceClasses = new HashSet<String>();
  381. }
  382. provideDeviceClasses
  383. .add((String) deviceTransformationElement
  384. .getValue());
  385. } else if (deviceTransformationElement.getName().getLocalPart()
  386. .equals("occurrence-id")) {
  387. if (provideDeviceOccurenceIds == null) {
  388. provideDeviceOccurenceIds = new HashSet<String>();
  389. }
  390. provideDeviceOccurenceIds
  391. .add((String) deviceTransformationElement
  392. .getValue());
  393. } else if (deviceTransformationElement.getName().getLocalPart()
  394. .equals("deviceID")) {
  395. if (provideDeviceDeviceIDs == null) {
  396. provideDeviceDeviceIDs = new HashSet<String>();
  397. }
  398. provideDeviceDeviceIDs
  399. .add((String) deviceTransformationElement
  400. .getValue());
  401. }
  402. // unexpected value, ignore
  403. }
  404. }
  405. }
  406. @SuppressWarnings("rawtypes")
  407. public void processPersonPermission(
  408. ProvidePersonPermission providePersonPermission) {
  409. provideAllPersons = providePersonPermission.getAllPersons() != null;
  410. if (!provideAllPersons) {
  411. for (Object personTransformationObject : providePersonPermission
  412. .getOccurrenceIdOrClazzOrAny()) {
  413. JAXBElement personTransformationElement = (JAXBElement) personTransformationObject;
  414. if (personTransformationElement.getName().getLocalPart()
  415. .equals("class")) {
  416. if (providePersonClasses == null) {
  417. providePersonClasses = new HashSet<String>();
  418. }
  419. providePersonClasses
  420. .add((String) personTransformationElement
  421. .getValue());
  422. } else if (personTransformationElement.getName().getLocalPart()
  423. .equals("occurrence-id")) {
  424. if (providePersonOccurenceIds == null) {
  425. providePersonOccurenceIds = new HashSet<String>();
  426. }
  427. providePersonOccurenceIds
  428. .add((String) personTransformationElement
  429. .getValue());
  430. }
  431. // unexpected value, ignore
  432. }
  433. }
  434. }
  435. @SuppressWarnings("rawtypes")
  436. public void processServicePermission(
  437. ProvideServicePermission provideServicePermission) {
  438. provideAllServices = provideServicePermission.getAllServices() != null;
  439. if (!provideAllServices) {
  440. for (Object serviceTransformationObject : provideServicePermission
  441. .getServiceUriOrServiceUriSchemeOrOccurrenceId()) {
  442. JAXBElement serviceTransformationElement = (JAXBElement) serviceTransformationObject;
  443. if (serviceTransformationElement.getName().getLocalPart()
  444. .equals("class")) {
  445. if (provideServiceClasses == null) {
  446. provideServiceClasses = new HashSet<String>();
  447. }
  448. provideServiceClasses
  449. .add((String) serviceTransformationElement
  450. .getValue());
  451. } else if (serviceTransformationElement.getName()
  452. .getLocalPart().equals("occurrence-id")) {
  453. if (provideServiceOccurenceIds == null) {
  454. provideServiceOccurenceIds = new HashSet<String>();
  455. }
  456. provideServiceOccurenceIds
  457. .add((String) serviceTransformationElement
  458. .getValue());
  459. } else if (serviceTransformationElement.getName()
  460. .getLocalPart().equals("service-uri")) {
  461. if (provideServiceServiceURIs == null) {
  462. provideServiceServiceURIs = new HashSet<String>();
  463. }
  464. provideServiceServiceURIs
  465. .add((String) serviceTransformationElement
  466. .getValue());
  467. } else if (serviceTransformationElement.getName()
  468. .getLocalPart().equals("service-uri-scheme")) {
  469. if (provideServiceServiceURISchemes == null) {
  470. provideServiceServiceURISchemes = new HashSet<String>();
  471. }
  472. provideServiceServiceURISchemes
  473. .add((String) serviceTransformationElement
  474. .getValue());
  475. }
  476. // unexpected value, ignore
  477. }
  478. }
  479. }
  480. }