-
Notifications
You must be signed in to change notification settings - Fork 106
/
CommentAddLiferayConnector.swift
87 lines (67 loc) · 2.12 KB
/
CommentAddLiferayConnector.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
import UIKit
open class CommentAddLiferayConnector: ServerConnector {
public let className: String
public let classPK: Int64
public let body: String
open var resultComment: Comment?
// MARK: Initializers
public init(className: String, classPK: Int64, body: String) {
self.className = className
self.classPK = classPK
self.body = body
super.init()
}
// MARK: ServerConnector
override open func validateData() -> ValidationError? {
let error = super.validateData()
if error == nil {
if className.isEmpty {
return ValidationError("comment-add-screenlet", "undefined-className")
}
if classPK <= 0 {
return ValidationError("comment-add-screenlet", "undefined-classPK")
}
if body.isEmpty {
return ValidationError("comment-add-screenlet", "empty-body")
}
}
return error
}
}
open class Liferay70CommentAddConnector: CommentAddLiferayConnector {
// MARK: ServerConnector
override open func doRun(session: LRSession) {
let service = LRScreenscommentService_v70(session: session)
do {
let result = try service.addComment(withClassName: className,
classPK: classPK,
body: Comment.plainBodyToHtml(body))
if let result = result as? [String: AnyObject] {
resultComment = Comment(attributes: result)
lastError = nil
}
else {
lastError = NSError.errorWithCause(.invalidServerResponse,
message: "Could not add comment.")
resultComment = nil
}
}
catch let error as NSError {
lastError = error
resultComment = nil
}
}
}