/* * Copyright 2011 Future Systems * * 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 org.krakenapps.ipmanager.model; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.Map; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; import org.krakenapps.msgbus.Marshalable; @Entity @Table(name = "ipm_denied_macs") public class DeniedMac implements Marshalable { @Id @GeneratedValue(strategy = GenerationType.AUTO) private int id; @ManyToOne @JoinColumn(name = "agent_id", nullable = false) private Agent agent; @Column(length = 20, nullable = false) private String mac; @Column(name = "begin_at") private Date beginDateTime; @Column(name = "end_at") private Date endDateTime; @Column(name = "created_at", nullable = false) private Date createDateTime; public int getId() { return id; } public void setId(int id) { this.id = id; } public Agent getAgent() { return agent; } public void setAgent(Agent agent) { this.agent = agent; } public String getMac() { return mac; } public void setMac(String mac) { this.mac = mac; } public Date getBeginDateTime() { return beginDateTime; } public void setBeginDateTime(Date beginDateTime) { this.beginDateTime = beginDateTime; } public Date getEndDateTime() { return endDateTime; } public void setEndDateTime(Date endDateTime) { this.endDateTime = endDateTime; } public Date getCreateDateTime() { return createDateTime; } public void setCreateDateTime(Date createDateTime) { this.createDateTime = createDateTime; } @Override public Map<String, Object> marshal() { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Map<String, Object> m = new HashMap<String, Object>(); m.put("id", id); m.put("agent_id", agent.getId()); m.put("mac", mac); m.put("begin", dateFormat.format(beginDateTime)); m.put("end", dateFormat.format(endDateTime)); m.put("created", dateFormat.format(createDateTime)); return m; } }