diff --git a/src/main/java/org/traccar/web/shared/model/Device.java b/src/main/java/org/traccar/web/shared/model/Device.java index b317678f..64caef98 100644 --- a/src/main/java/org/traccar/web/shared/model/Device.java +++ b/src/main/java/org/traccar/web/shared/model/Device.java @@ -170,6 +170,42 @@ public void setIconType(DeviceIconType iconType) { this.iconType = iconType; } + @ManyToOne + @JoinColumn(foreignKey = @ForeignKey(name = "devices_fkey_def_icon_id")) + private Picture defaultIcon; + + public Picture getDefaultIcon() { + return defaultIcon; + } + + public void setDefaultIcon(Picture defaultIcon) { + this.defaultIcon = defaultIcon; + } + + @ManyToOne + @JoinColumn(foreignKey = @ForeignKey(name = "devices_fkey_sel_icon_id")) + private Picture selectedIcon; + + public Picture getSelectedIcon() { + return selectedIcon; + } + + public void setSelectedIcon(Picture selectedIcon) { + this.selectedIcon = selectedIcon; + } + + @ManyToOne + @JoinColumn(foreignKey = @ForeignKey(name = "devices_fkey_off_icon_id")) + private Picture offlineIcon; + + public Picture getOfflineIcon() { + return offlineIcon; + } + + public void setOfflineIcon(Picture offlineIcon) { + this.offlineIcon = offlineIcon; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/src/main/java/org/traccar/web/shared/model/NotificationTemplate.java b/src/main/java/org/traccar/web/shared/model/NotificationTemplate.java index 1df4c5e4..9aa33972 100644 --- a/src/main/java/org/traccar/web/shared/model/NotificationTemplate.java +++ b/src/main/java/org/traccar/web/shared/model/NotificationTemplate.java @@ -74,7 +74,6 @@ public boolean equals(Object o) { if (!getSettings().equals(that.getSettings())) return false; return getType() == that.getType(); - } @Override diff --git a/src/main/java/org/traccar/web/shared/model/Picture.java b/src/main/java/org/traccar/web/shared/model/Picture.java new file mode 100644 index 00000000..381ce200 --- /dev/null +++ b/src/main/java/org/traccar/web/shared/model/Picture.java @@ -0,0 +1,77 @@ +/* + * Copyright 2015 Vitaly Litvak (vitavaque@gmail.com) + * + * 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.traccar.web.shared.model; + +import com.google.gwt.user.client.rpc.GwtTransient; +import com.google.gwt.user.client.rpc.IsSerializable; + +import javax.persistence.*; + +@Entity +@Table(name = "pictures") +public class Picture implements IsSerializable { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", nullable = false, updatable = false, unique = true) + private long id; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + @Enumerated(EnumType.STRING) + private PictureType type; + + public PictureType getType() { + return type; + } + + public void setType(PictureType type) { + this.type = type; + } + + @Lob + @Basic(fetch = FetchType.LAZY) + @Column(length = 1024 * 1024) // max 1 MB + @GwtTransient + private byte[] data; + + public byte[] getData() { + return data; + } + + public void setData(byte[] data) { + this.data = data; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Picture)) return false; + + Picture that = (Picture) o; + return that.getId() == getId(); + } + + @Override + public int hashCode() { + return (int)(getId() ^ (getId() >>> 32)); + } +} diff --git a/src/main/java/org/traccar/web/shared/model/PictureType.java b/src/main/java/org/traccar/web/shared/model/PictureType.java new file mode 100644 index 00000000..f11b6a27 --- /dev/null +++ b/src/main/java/org/traccar/web/shared/model/PictureType.java @@ -0,0 +1,26 @@ +/* + * Copyright 2015 Vitaly Litvak (vitavaque@gmail.com) + * + * 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.traccar.web.shared.model; + +public enum PictureType { + MARKER(20 * 1024), DEVICE_PHOTO(300 * 1024); + + final int maxLength; + + PictureType(int maxLength) { + this.maxLength = maxLength; + } +}