This repository has been archived by the owner on Jun 27, 2018. It is now read-only.
forked from RefreshCache/arena-hdc-webservice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProfileAPI.cs
242 lines (208 loc) · 10.9 KB
/
ProfileAPI.cs
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.ServiceModel.Web;
using Arena.Core;
using Arena.DataLayer.Core;
using Arena.Security;
namespace Arena.Custom.HDC.WebService
{
class ProfileAPI
{
/// <summary>
/// Retrieve a list of profiles under the identified profile ID or
/// at the root level of the identified profile type.
/// </summary>
/// <param name="profileID">The parent profile to find all child profiles of.</param>
/// <param name="profileType">Retrieve a list of root profiles of this type.</param>
/// <param name="start">The number at which to start retrieving records.</param>
/// <param name="max">The number of records to return.</param>
/// <param name="fields">If supplied, the result is an array of Profile contracts with only the supplied fields.</param>
/// <returns>GenericListResult that contains either GenericReference objects or Profile objects.</returns>
[WebGet(UriTemplate = "profile/list?profileID={profileID}&profileType={profileType}&start={start}&max={max}&fields={fields}")]
public Object GetProfileList(String profileID, String profileType, int start, int max, String fields)
{
ProfileCollection profiles = null;
Contracts.ProfileMapper mapper = null;
Contracts.GenericListResult<Contracts.Profile> listP = new Contracts.GenericListResult<Contracts.Profile>();
Contracts.GenericListResult<Contracts.GenericReference> listR = new Contracts.GenericListResult<Contracts.GenericReference>();
int i;
if (profileType != null)
{
profiles = new ProfileCollection();
profiles.LoadChildProfiles(-1, RestApi.DefaultOrganizationID(), (Arena.Enums.ProfileType)Convert.ToInt32(profileType), ArenaContext.Current.Person.PersonID);
}
else if (profileID != null)
{
Profile profile;
if (RestApi.ProfileOperationAllowed(ArenaContext.Current.Person.PersonID, Convert.ToInt32(profileID), OperationType.View) == false)
throw new Exception("Access denied.");
profile = new Profile(Convert.ToInt32(profileID));
profiles = profile.ChildProfiles;
}
else
throw new Exception("Required parameters not provided.");
//
// Sort the list of profiles and determine if we are going to
// be returning references or full objects.
//
profiles.Sort(delegate(Profile p1, Profile p2) { return p1.Name.CompareTo(p2.Name); });
mapper = (string.IsNullOrEmpty(fields) ? null : new Contracts.ProfileMapper(new List<string>(fields.Split(','))));
//
// Prepare the appropraite list object.
//
if (mapper != null)
{
listP.Start = start;
listP.Max = max;
listP.Total = 0;
listP.Items = new List<Contracts.Profile>();
}
else
{
listR.Start = start;
listR.Max = max;
listR.Total = 0;
listR.Items = new List<Contracts.GenericReference>();
}
for (i = 0; i < profiles.Count; i++)
{
if (RestApi.ProfileOperationAllowed(ArenaContext.Current.Person.PersonID, profiles[i].ProfileID, OperationType.View) == false)
continue;
if (mapper != null)
{
if (listP.Total >= start && (max <= 0 ? true : listP.Items.Count < max))
listP.Items.Add(mapper.FromArena(profiles[i]));
listP.Total += 1;
}
else
{
if (listR.Total >= start && (max <= 0 ? true : listR.Items.Count < max))
listR.Items.Add(new Contracts.GenericReference(profiles[i]));
listR.Total += 1;
}
}
return (mapper != null ? (Object)listP : (Object)listR);
}
/// <summary>
/// Retrieve the information about a profile. If the profile
/// is not found, or no access is permitted to the profile, then
/// an exception is thrown to the client.
/// </summary>
/// <param name="profileID">The ID number of the profile to look up.</param>
/// <returns>Basic information about the profile.</returns>
[WebGet(UriTemplate = "profile/{profileID}")]
public Contracts.Profile GetProfileInformation(int profileID)
{
Contracts.ProfileMapper mapper = new Contracts.ProfileMapper();
Profile profile = new Profile(profileID);
if (profile.ProfileID == -1)
throw new Arena.Services.Exceptions.ResourceNotFoundException("Invalid profile ID");
if (RestApi.ProfileOperationAllowed(ArenaContext.Current.Person.PersonID, profile.ProfileID, OperationType.View) == false)
throw new Exception("Access denied.");
return mapper.FromArena(profile);
}
/// <summary>
/// Find all people who are members of the profile and return their
/// person IDs. All members are returned including in-active members. If the
/// profile has no members then an empty array is returned.
/// </summary>
/// <param name="profileID">The profile to find members of.</param>
/// <param name="start">The 0-based index to start retrieving at.</param>
/// <param name="max">The maximum number of members to retrieve.</param>
/// <returns>GenericListResult of ProfileMember objects.</returns>
[WebGet(UriTemplate = "profile/{profileID}/members/list?statusID={statusID}&start={start}&max={max}")]
public Contracts.GenericListResult<Contracts.ProfileMember>
GetProfileMembers(int profileID, String statusID, int start, int max)
{
Contracts.GenericListResult<Contracts.ProfileMember> list = new Contracts.GenericListResult<Contracts.ProfileMember>();
Profile profile = new Profile(profileID);
int i, nStatusID;
if (RestApi.ProfileOperationAllowed(ArenaContext.Current.Person.PersonID, profile.ProfileID, OperationType.View) == false)
throw new Exception("Access denied.");
try
{
nStatusID = Convert.ToInt32(statusID);
}
catch
{
nStatusID = -1;
}
profile.LoadMemberArray();
list.Start = start;
list.Max = max;
list.Total = 0;
list.Items = new List<Contracts.ProfileMember>();
for (i = 0; i < profile.Members.Count; i++)
{
if (nStatusID != -1 && profile.Members[i].Status.LookupID != nStatusID)
continue;
if (list.Total >= start && (max <= 0 ? true : list.Items.Count < max))
list.Items.Add(new Contracts.ProfileMember(profile.Members[i]));
list.Total += 1;
}
return list;
}
/// <summary>
/// Retrieve a single member of a profile. If the profile is not
/// found, or no access is permitted to the profile, then
/// an exception is thrown to the client.
/// </summary>
/// <param name="profileID">The ID number of the profile to look up.</param>
/// <returns>Basic information about the profile.</returns>
[WebGet(UriTemplate = "profile/{profileID}/members/{personID}")]
public Contracts.ProfileMember GetProfileMember(int profileID, int personID)
{
ProfileMember member = new ProfileMember(profileID, personID);
if (member.ProfileID == -1)
throw new Arena.Services.Exceptions.ResourceNotFoundException("Invalid profile ID");
if (RestApi.ProfileOperationAllowed(ArenaContext.Current.Person.PersonID, member.ProfileID, OperationType.View) == false)
throw new Exception("Access denied.");
return new Contracts.ProfileMember(member);
}
/// <summary>
/// Retrieves the activity for the person in the given profile. Optionally
/// the list can be limited to a specified number of records to support
/// pagination while loading.
/// </summary>
/// <param name="profileID">The profile ID to load the primary activity for.</param>
/// <param name="personID">The person to load the activity of.</param>
/// <param name="start">Optional starting index to begin loading at.</param>
/// <param name="max">Maximum number of records to load in this call.</param>
/// <returns></returns>
[WebGet(UriTemplate = "profile/{profileID}/members/{personID}/activity/list?start={start}&max={max}")]
public Contracts.GenericListResult<Contracts.ProfileMemberActivity>
GetProfileMemberActivity(int profileID, int personID, int start, int max)
{
Contracts.GenericListResult<Contracts.ProfileMemberActivity> list = new Contracts.GenericListResult<Contracts.ProfileMemberActivity>();
Profile profile = new Profile(profileID);
DataTable dt;
int i;
//
// Check if the profile exists.
//
if (profile.ProfileID == -1)
throw new Arena.Services.Exceptions.ResourceNotFoundException("Invalid profile ID");
//
// Check if the user has access to work with the profile.
//
if (RestApi.ProfileOperationAllowed(ArenaContext.Current.Person.PersonID, profile.ProfileID, OperationType.View) == false)
throw new Exception("Access denied.");
dt = new ProfileMemberActivityData().GetProfileMemberActivityDetails_DT(RestApi.DefaultOrganizationID(), profile.ProfileType, profile.Owner.PersonID, personID);
list.Start = start;
list.Max = max;
list.Items = new List<Contracts.ProfileMemberActivity>();
for (i = 0; i < dt.Rows.Count; i++)
{
if (RestApi.ProfileOperationAllowed(ArenaContext.Current.Person.PersonID, Convert.ToInt32(dt.Rows[i]["profile_id"]), OperationType.View) == false)
continue;
if (list.Total >= start && (max <= 0 ? true : list.Items.Count < max))
list.Items.Add(new Contracts.ProfileMemberActivity(dt.Rows[i]));
list.Total += 1;
}
return list;
}
}
}