
com.centurylink.mdw.model.user.UserList Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mdw-common Show documentation
Show all versions of mdw-common Show documentation
MDW is a microservices based workflow framework
/*
* Copyright (C) 2017 CenturyLink, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.centurylink.mdw.model.user;
import com.centurylink.mdw.model.InstanceList;
import com.centurylink.mdw.model.JsonObject;
import com.centurylink.mdw.model.Jsonable;
import com.centurylink.mdw.util.DateHelper;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class UserList implements Jsonable, InstanceList {
public UserList(List users) {
this.users = users;
this.count = users.size();
}
public UserList(String json) throws JSONException {
JSONObject jsonObj = new JsonObject(json);
if (jsonObj.has("retrieveDate"))
retrieveDate = DateHelper.serviceStringToDate(jsonObj.getString("retrieveDate"));
if (jsonObj.has("count"))
count = jsonObj.getInt("count");
if (jsonObj.has("total"))
total = jsonObj.getLong("total");
if (jsonObj.has("users")) {
JSONArray userList = jsonObj.getJSONArray("users");
for (int i = 0; i < userList.length(); i++)
users.add(new User((JSONObject)userList.get(i)));
}
}
private Date retrieveDate;
public Date getRetrieveDate() { return retrieveDate; }
public void setRetrieveDate(Date d) { this.retrieveDate = d; }
private int count;
public int getCount() { return count; }
public void setCount(int ct) { this.count = ct; }
private long total = -1;
public long getTotal() { return total; }
public void setTotal(long total) { this.total = total; }
private List users = new ArrayList();
public List getUsers() { return users; }
public void setUsers(List users) { this.users = users; }
public List getItems() {
return users;
}
public int getIndex(String id) {
for (int i = 0; i < users.size(); i++) {
if (users.get(i).getId().equals(id))
return i;
}
return -1;
}
public User get(String cuid) {
for (User user : users) {
if (user.getCuid().equals(cuid))
return user;
}
return null;
}
public JSONObject getJson() throws JSONException {
JSONObject json = create();
json.put("retrieveDate", DateHelper.serviceDateToString(getRetrieveDate()));
json.put("count", count);
if (total != -1)
json.put("total", total);
JSONArray array = new JSONArray();
if (users != null) {
for (User user : users)
array.put(user.getJson());
}
json.put("users", array);
return json;
}
public String getJsonName() {
return "Users";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy