Java tutorial
package fr.ortolang.diffusion.api.message; /* * #%L * ORTOLANG * A online network structure for hosting language resources and tools. * * Jean-Marie Pierrel / ATILF UMR 7118 - CNRS / Universit de Lorraine * Etienne Petitjean / ATILF UMR 7118 - CNRS * Jrme Blanchard / ATILF UMR 7118 - CNRS * Bertrand Gaiffe / ATILF UMR 7118 - CNRS * Cyril Pestel / ATILF UMR 7118 - CNRS * Marie Tonnelier / ATILF UMR 7118 - CNRS * Ulrike Fleury / ATILF UMR 7118 - CNRS * Frdric Pierre / ATILF UMR 7118 - CNRS * Cline Moro / ATILF UMR 7118 - CNRS * * This work is based on work done in the equipex ORTOLANG (http://www.ortolang.fr/), by several Ortolang contributors (mainly CNRTL and SLDR) * ORTOLANG is funded by the French State program "Investissements d'Avenir" ANR-11-EQPX-0032 * %% * Copyright (C) 2013 - 2016 Ortolang Team * %% * This program 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 3 of the * License, or (at your option) any later version. * * 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 General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. * #L% */ import java.util.Collections; import java.util.Date; import java.util.Set; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlRootElement; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import fr.ortolang.diffusion.OrtolangObjectInfos; import fr.ortolang.diffusion.message.entity.Message; import fr.ortolang.diffusion.message.entity.MessageAttachment; @XmlRootElement(name = "message") @JsonIgnoreProperties(ignoreUnknown = true) public class MessageRepresentation { @XmlAttribute(name = "key") private String key; private String body; private Date date; private Date edit; private String thread; private String parent; private String author; private boolean question; private boolean answer; private Set<MessageAttachment> attachments; public MessageRepresentation() { attachments = Collections.emptySet(); question = false; answer = false; } public String getKey() { return key; } public void setKey(String key) { this.key = key; } public String getBody() { return body; } public void setBody(String body) { this.body = body; } public Date getDate() { return date; } public void setDate(Date date) { this.date = date; } public Date getEdit() { return edit; } public void setEdit(Date edit) { this.edit = edit; } public String getThread() { return thread; } public void setThread(String thread) { this.thread = thread; } public String getParent() { return parent; } public void setParent(String parent) { this.parent = parent; } public String getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } public Set<MessageAttachment> getAttachments() { return attachments; } public void setAttachments(Set<MessageAttachment> attachments) { this.attachments = attachments; } public boolean isQuestion() { return question; } public void setQuestion(boolean question) { this.question = question; } public boolean isAnswer() { return answer; } public void setAnswer(boolean answer) { this.answer = answer; } public static MessageRepresentation fromMessage(Message message) { MessageRepresentation representation = new MessageRepresentation(); representation.setKey(message.getKey()); representation.setThread(message.getThread()); representation.setBody(message.getBody()); representation.setDate(message.getDate()); representation.setEdit(message.getEdit()); representation.setParent(message.getParent()); representation.setAttachments(message.getAttachments()); return representation; } public static MessageRepresentation fromMessageAndInfos(Message message, OrtolangObjectInfos infos) { MessageRepresentation representation = fromMessage(message); representation.setAuthor(infos.getAuthor()); return representation; } }