StatusDTO.java

/*
 * Copyright (C) 2000 - 2025 Silverpeas
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * As a special exception to the terms and conditions of version 3.0 of
 * the GPL, you may redistribute this Program in connection with Free/Libre
 * Open Source Software ("FLOSS") applications as described in Silverpeas's
 * FLOSS exception.  You should have received a copy of the text describing
 * the FLOSS exception, and it is also available here:
 * "https://www.silverpeas.org/legal/floss_exception.html"
 *
 * This program 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.silverpeas.mobile.shared.dto;

import jsinterop.base.JsPropertyMap;

import java.io.Serializable;
import java.util.Date;

public class StatusDTO implements Serializable, Comparable<StatusDTO> {

	private static final long serialVersionUID = 2921606984249560882L;
	
	 private int id;
	 private int userId;
	 private Date creationDate;
	 private String description = "";

    public static StatusDTO fromJSON(JsPropertyMap<Object> json) {
		StatusDTO dto = new StatusDTO();

		Object id = json.get("id");
		if (id != null) {
			dto.setId(((Number) id).intValue());
		}

		Object userId = json.get("userId");
		if (userId != null) {
			dto.setUserId(((Number) userId).intValue());
		}

		Object creationDate = json.get("creationDate");
		if (creationDate != null) {
			dto.setCreationDate(new Date(((Number) creationDate).longValue()));
		}

		dto.setDescription(
				json.get("description") != null
						? json.get("description").toString()
						: null
		);

		return dto;
    }

    public int compareTo(StatusDTO o) {
		return getCreationDate().compareTo(o.getCreationDate()) * -1;
	}

	public int getId() {
		return id;
	}
	
	public void setId(int id) {
		this.id = id;
	}
	public int getUserId() {
		return userId;
	}
	public void setUserId(int userId) {
		this.userId = userId;
	}
	public Date getCreationDate() {
		return creationDate;
	}
	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	
	@Override
	public boolean equals(Object obj) {		
		return ((StatusDTO) obj).getId() == id; 
	}
}