feat: complete reverse engineering, standard Maven structure, detailed code annotations and IoT-M platform architecture
This commit is contained in:
1 parent
e8dc09fb3c
commit
cd6a4c70e7
3045 files changed
+566733
-1
No files matched your search
@@ -0,0 +1,241 @@
|
||||
package com.midm.model;
|
||||
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import com.mitac.cell.utils.McBooleanUtils;
|
||||
import com.mitac.cell.utils.McDateTimeUtils;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import org.bson.Document;
|
||||
import org.joda.time.DateTime;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.index.Indexed;
|
||||
|
||||
public class GeneralProfile {
|
||||
@Id
|
||||
protected UUID uuid;
|
||||
protected DbObject profile;
|
||||
protected DbObject settings;
|
||||
protected Date created;
|
||||
@Indexed
|
||||
protected Date updated;
|
||||
protected Boolean enabled;
|
||||
|
||||
public void init() {
|
||||
this.generateId();
|
||||
this.created = new Date();
|
||||
this.updated = this.created;
|
||||
}
|
||||
|
||||
public void generateId() {
|
||||
this.uuid = UUID.randomUUID();
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
public void setUuid(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public DbObject getProfile() {
|
||||
if (this.profile == null) {
|
||||
this.profile = new DbObject();
|
||||
}
|
||||
|
||||
return this.profile;
|
||||
}
|
||||
|
||||
public void setProfile(DbObject profile) {
|
||||
this.profile = profile;
|
||||
}
|
||||
|
||||
public DbObject getSettings() {
|
||||
if (this.settings == null) {
|
||||
this.settings = new DbObject();
|
||||
}
|
||||
|
||||
return this.settings;
|
||||
}
|
||||
|
||||
public void setSettings(DbObject settings) {
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
public Date getCreated() {
|
||||
return this.created;
|
||||
}
|
||||
|
||||
public void setCreated(Date created) {
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
public Date getUpdated() {
|
||||
return this.updated;
|
||||
}
|
||||
|
||||
public void setUpdated(Date updated) {
|
||||
this.updated = updated;
|
||||
}
|
||||
|
||||
public void setUpdated() {
|
||||
this.setUpdated(new Date());
|
||||
}
|
||||
|
||||
public boolean getEnabled() {
|
||||
return this.enabled != null && this.enabled;
|
||||
}
|
||||
|
||||
public boolean isEnded() {
|
||||
if ("ends".equals(this.getProfile("endsOption"))) {
|
||||
DateTime dateTime = McDateTimeUtils.parseDate((String)this.getProfile("ends"), "yyyy-MM-dd").plusDays(1);
|
||||
return dateTime.isBeforeNow();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void setEnabled(Boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public Object getProfile(String key) {
|
||||
return this.getProfile(key, (Object)null);
|
||||
}
|
||||
|
||||
public Object getProfile(String key, Object defaultValue) {
|
||||
if (this.getProfile().containsKey(key)) {
|
||||
try {
|
||||
return this.getProfile().get(key);
|
||||
} catch (Exception var4) {
|
||||
}
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public boolean getProfileAsBoolean(String category, String key, String subCategory, String item, boolean def) {
|
||||
Boolean value = McBooleanUtils.isTrue(this.getProfile(category, key, subCategory, item));
|
||||
return value == null ? def : value;
|
||||
}
|
||||
|
||||
public Object getProfile(String category, String key, String subCategory, String item) {
|
||||
return this.getProfileCategory(category, key, subCategory).get(item);
|
||||
}
|
||||
|
||||
public DbObject getProfileCategory(String... categoryNames) {
|
||||
return this.getProfile().getDbObject(categoryNames);
|
||||
}
|
||||
|
||||
public Object getCategoryProfile(String category, String key) {
|
||||
return this.getProfileCategory(category) == null ? null : this.getProfileCategory(category).get(key);
|
||||
}
|
||||
|
||||
public void setProfile(String key, Object value) {
|
||||
this.getProfile().put(key, value);
|
||||
}
|
||||
|
||||
public void setProfile(String category, String key, Object value) {
|
||||
this.getProfileCategory(category).put(key, value);
|
||||
}
|
||||
|
||||
public void setProfile(String category, String subCategory, String item, String key, Object value) {
|
||||
this.getProfileCategory(category, subCategory, item).put(key, value);
|
||||
}
|
||||
|
||||
public void removeProfile(String key) {
|
||||
if (this.profile != null) {
|
||||
this.profile.remove(key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Object getSetting(String key) {
|
||||
return this.getSettings().get(key);
|
||||
}
|
||||
|
||||
public String getSettingAsString(String key) {
|
||||
return this.getSettings().getString(key, (String)null);
|
||||
}
|
||||
|
||||
public int getSettingAsInt(String key, int def) {
|
||||
return this.getSettings().getInteger(key, def);
|
||||
}
|
||||
|
||||
public float getSettingAsFloat(String key, float def) {
|
||||
return this.getSettings().getFloat(key, def);
|
||||
}
|
||||
|
||||
public boolean getSettingAsBoolean(String key) {
|
||||
return this.getSettingAsBoolean(key, false);
|
||||
}
|
||||
|
||||
public boolean getSettingAsBoolean(String key, boolean def) {
|
||||
return this.getSettings().containsKey(key) ? McBooleanUtils.isTrue(this.getSetting(key)) : def;
|
||||
}
|
||||
|
||||
public boolean getSettingAsBoolean(String category, String key, boolean def) {
|
||||
Boolean value = McBooleanUtils.isTrue(this.getSetting(category, key));
|
||||
return value == null ? def : value;
|
||||
}
|
||||
|
||||
public UUID getSettingAsUuid(String key) {
|
||||
return this.getSettings().getUuid(key);
|
||||
}
|
||||
|
||||
public DbObject getSettingsCategory(String... categoryNames) {
|
||||
return this.getSettings().getDbObject(categoryNames);
|
||||
}
|
||||
|
||||
public Object getSetting(String category, String key) {
|
||||
return this.getSettingsCategory(category).get(key);
|
||||
}
|
||||
|
||||
public void setSetting(String key, UUID value) {
|
||||
if (value != null) {
|
||||
this.getSettings().put(key, value.toString());
|
||||
} else {
|
||||
this.getSettings().remove(key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setSetting(String key, Object value) {
|
||||
this.getSettings().put(key, value);
|
||||
}
|
||||
|
||||
public void setSetting(String categoryName, String key, Object value) {
|
||||
Document dbObject = this.getSettingsCategory(categoryName);
|
||||
if (value != null) {
|
||||
dbObject.put(key, value);
|
||||
} else {
|
||||
dbObject.remove(key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void removeOption(String key) {
|
||||
this.getSettings().remove(key);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
Object value = this.getProfile("name");
|
||||
return value == null ? null : (String)value;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.setProfile("name", name);
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return (String)this.getProfile("desc");
|
||||
}
|
||||
|
||||
public void setDescription(String desc) {
|
||||
this.setProfile("desc", desc);
|
||||
}
|
||||
|
||||
public void minify() {
|
||||
this.created = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.midm.model;
|
||||
|
||||
public class GroupByResult {
|
||||
private String[] groups;
|
||||
private int count;
|
||||
|
||||
public int getCount() {
|
||||
return this.count;
|
||||
}
|
||||
|
||||
public void setCount(int count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return this.groups.length > 0 ? this.groups[0] : null;
|
||||
}
|
||||
|
||||
public String[] getGroups() {
|
||||
return this.groups;
|
||||
}
|
||||
|
||||
public void setGroups(String[] groups) {
|
||||
this.groups = groups;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.midm.model;
|
||||
|
||||
import com.google.common.base.CharMatcher;
|
||||
|
||||
public enum IF_EXISTS_OPTION {
|
||||
ignore(0),
|
||||
skip(0),
|
||||
replace(1),
|
||||
overwrite(1),
|
||||
update(2),
|
||||
modify(2),
|
||||
remove(3);
|
||||
|
||||
public int option;
|
||||
|
||||
private IF_EXISTS_OPTION(int option) {
|
||||
this.option = option;
|
||||
}
|
||||
|
||||
public static IF_EXISTS_OPTION get(String key) {
|
||||
try {
|
||||
return valueOf(CharMatcher.whitespace().removeFrom(key).toLowerCase());
|
||||
} catch (Exception var2) {
|
||||
return skip;
|
||||
}
|
||||
}
|
||||
|
||||
public static int getOption(String option) {
|
||||
return get(option).option;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package com.midm.model.battery;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.midm.model.GeneralProfile;
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import com.mitac.cell.utils.McJsonUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
import org.springframework.data.mongodb.core.index.CompoundIndex;
|
||||
import org.springframework.data.mongodb.core.index.CompoundIndexes;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
@CompoundIndexes({@CompoundIndex(
|
||||
def = "{'profile.hardware_info.batterySerial':1}",
|
||||
unique = true
|
||||
)})
|
||||
public class Battery extends GeneralProfile {
|
||||
private UUID siteUuid;
|
||||
private DbObject states;
|
||||
@Transient
|
||||
private String deviceGroupPath;
|
||||
|
||||
public Battery() {
|
||||
this.init();
|
||||
}
|
||||
|
||||
public void setSiteUuid(UUID siteUuid) {
|
||||
this.siteUuid = siteUuid;
|
||||
}
|
||||
|
||||
public UUID getSiteUuid() {
|
||||
return this.siteUuid;
|
||||
}
|
||||
|
||||
public String getBatterySerial() {
|
||||
return (String)this.getCategoryProfile("hardware_info", "batterySerial");
|
||||
}
|
||||
|
||||
public String getDeviceSerial() {
|
||||
return (String)this.getCategoryProfile("hardware_info", "deviceSerial");
|
||||
}
|
||||
|
||||
public void setDeviceSerial(String deviceSerial) {
|
||||
this.setProfile("hardware_info", "deviceSerial", deviceSerial.trim());
|
||||
}
|
||||
|
||||
public String getModel() {
|
||||
return (String)this.getCategoryProfile("hardware_info", "model");
|
||||
}
|
||||
|
||||
public String getDeviceId() {
|
||||
return (String)this.getCategoryProfile("hardware_info", "device_id");
|
||||
}
|
||||
|
||||
public void setRegisterState(String state) {
|
||||
this.getStates().put("state", state);
|
||||
}
|
||||
|
||||
public String getRegisterState() {
|
||||
return this.getStates().getString("state");
|
||||
}
|
||||
|
||||
public Integer getBatteryCondition() {
|
||||
return this.getStates().getInteger("batteryCondition", -1);
|
||||
}
|
||||
|
||||
public DbObject getStates() {
|
||||
if (this.states == null) {
|
||||
this.states = new DbObject();
|
||||
}
|
||||
|
||||
return this.states;
|
||||
}
|
||||
|
||||
public String getDeviceGroupPath() {
|
||||
return this.deviceGroupPath;
|
||||
}
|
||||
|
||||
public void setDeviceGroupPath(String deviceGroupPath) {
|
||||
this.deviceGroupPath = deviceGroupPath;
|
||||
}
|
||||
|
||||
public ValueWithTime getLastTemp() {
|
||||
List<ValueWithTime> dbTempList = (List)McJsonUtils.toObject(McJsonUtils.toJson(this.getStates().get("temperature")), (new TypeToken() {
|
||||
}).getType());
|
||||
return dbTempList.isEmpty() ? null : (ValueWithTime)dbTempList.get(0);
|
||||
}
|
||||
|
||||
public void setLastTemp(ValueWithTime t) {
|
||||
DbObject obj = new DbObject();
|
||||
obj.append("reportedAt", t.getReportedAt()).append("value", t.getValue());
|
||||
List<DbObject> list = new ArrayList();
|
||||
list.add(obj);
|
||||
this.getStates().put("temperature", list);
|
||||
}
|
||||
|
||||
public static enum BATTERY_CONDITION {
|
||||
UNKNOWN(-1),
|
||||
GOOD(0),
|
||||
AVERAGE(1),
|
||||
SERVICE_SOON(2);
|
||||
|
||||
private int value;
|
||||
|
||||
private BATTERY_CONDITION(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public static BATTERY_CONDITION forValue(int value) {
|
||||
for(BATTERY_CONDITION e : values()) {
|
||||
if (e.value == value) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
|
||||
return UNKNOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.midm.model.battery;
|
||||
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.index.CompoundIndex;
|
||||
import org.springframework.data.mongodb.core.index.Indexed;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
@CompoundIndex(
|
||||
def = "{batterySerial: 1, reportedAt: 1}"
|
||||
)
|
||||
public class BatteryLog {
|
||||
@Id
|
||||
private UUID uuid = UUID.randomUUID();
|
||||
@Indexed
|
||||
private String batterySerial;
|
||||
@Indexed
|
||||
private String category;
|
||||
private String log;
|
||||
@Indexed
|
||||
private Date reportedAt;
|
||||
private DbObject states;
|
||||
private Date recordedAt = new Date();
|
||||
|
||||
public UUID getUuid() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
public String getBatterySerial() {
|
||||
return this.batterySerial;
|
||||
}
|
||||
|
||||
public void setCategory(String category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public DbObject getStates() {
|
||||
if (this.states == null) {
|
||||
this.states = new DbObject();
|
||||
}
|
||||
|
||||
return this.states;
|
||||
}
|
||||
|
||||
public Date getReportedAt() {
|
||||
return this.reportedAt;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.midm.model.battery;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class ValueWithTime {
|
||||
private Date reportedAt;
|
||||
private double value;
|
||||
|
||||
public ValueWithTime(Date reportedAt, double value) {
|
||||
this.reportedAt = reportedAt;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Date getReportedAt() {
|
||||
return this.reportedAt;
|
||||
}
|
||||
|
||||
public void setReportedAt(Date reportedAt) {
|
||||
this.reportedAt = reportedAt;
|
||||
}
|
||||
|
||||
public double getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(double value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.midm.model.device;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
public class AppInfo {
|
||||
private String packageName;
|
||||
private String label;
|
||||
private String versionName;
|
||||
private Integer versionCode;
|
||||
private Integer minSdkVersion;
|
||||
private Long appSize;
|
||||
private Long dataSize;
|
||||
private Long firstInstalled;
|
||||
private Long lastUpdated;
|
||||
|
||||
public String getPackageName() {
|
||||
return this.packageName;
|
||||
}
|
||||
|
||||
public void setPackageName(String packageName) {
|
||||
this.packageName = packageName;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return Strings.isNullOrEmpty(this.label) ? this.packageName : this.label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public String getVersionName() {
|
||||
return this.versionName;
|
||||
}
|
||||
|
||||
public void setVersionName(String versionName) {
|
||||
this.versionName = versionName;
|
||||
}
|
||||
|
||||
public int getVersionCode() {
|
||||
return this.versionCode;
|
||||
}
|
||||
|
||||
public void setVersionCode(int versionCode) {
|
||||
this.versionCode = versionCode;
|
||||
}
|
||||
|
||||
public int minSdkVersion() {
|
||||
return this.minSdkVersion;
|
||||
}
|
||||
|
||||
public void setMinSdkVersion(int version) {
|
||||
this.minSdkVersion = version;
|
||||
}
|
||||
|
||||
public long getAppSize() {
|
||||
return this.appSize;
|
||||
}
|
||||
|
||||
public void setAppSize(long appSize) {
|
||||
this.appSize = appSize;
|
||||
}
|
||||
|
||||
public long getDataSize() {
|
||||
return this.dataSize;
|
||||
}
|
||||
|
||||
public void setDataSize(long dataSize) {
|
||||
this.dataSize = dataSize;
|
||||
}
|
||||
|
||||
public long getFirstInstalled() {
|
||||
return this.firstInstalled;
|
||||
}
|
||||
|
||||
public void setFirstInstalled(long firstInstalled) {
|
||||
this.firstInstalled = firstInstalled;
|
||||
}
|
||||
|
||||
public long getLastUpdated() {
|
||||
return this.lastUpdated;
|
||||
}
|
||||
|
||||
public void setLastUpdated(long lastUpdated) {
|
||||
this.lastUpdated = lastUpdated;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.format("%s %s(%s)", this.label, this.versionName, this.packageName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.midm.model.device;
|
||||
|
||||
import com.google.common.base.CharMatcher;
|
||||
|
||||
public enum DEVICE_PROPERTY {
|
||||
serialno,
|
||||
serial_no,
|
||||
serialnumber,
|
||||
serial_number,
|
||||
productsn,
|
||||
product_sn,
|
||||
partno,
|
||||
partnumber,
|
||||
part_no,
|
||||
palletno,
|
||||
pallet_no,
|
||||
cartonsn,
|
||||
carton_sn,
|
||||
wifimac,
|
||||
wifi_mac,
|
||||
device_group,
|
||||
devicegroup,
|
||||
group,
|
||||
owner,
|
||||
owner_name,
|
||||
owner_email,
|
||||
owner_phone,
|
||||
owner_mobile,
|
||||
email,
|
||||
description,
|
||||
desc,
|
||||
comment,
|
||||
memo,
|
||||
exists,
|
||||
ifexists,
|
||||
if_exists,
|
||||
license,
|
||||
renew,
|
||||
renewtosamemodel,
|
||||
renew_to_same_model,
|
||||
rsa,
|
||||
unknown;
|
||||
|
||||
public static DEVICE_PROPERTY get(String key) {
|
||||
try {
|
||||
return valueOf(CharMatcher.whitespace().removeFrom(key).toLowerCase());
|
||||
} catch (Exception var2) {
|
||||
return unknown;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
package com.midm.model.device;
|
||||
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.index.CompoundIndex;
|
||||
import org.springframework.data.mongodb.core.index.Indexed;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
@CompoundIndex(
|
||||
def = "{deviceUuid: 1, siteUuid: 1}"
|
||||
)
|
||||
public class DataUsage {
|
||||
@Id
|
||||
private UUID uuid;
|
||||
private UUID deviceUuid;
|
||||
private UUID siteUuid;
|
||||
@Indexed
|
||||
private Date from;
|
||||
@Indexed
|
||||
private Date to;
|
||||
private DbObject usage;
|
||||
@Indexed(
|
||||
expireAfterSeconds = 15552000
|
||||
)
|
||||
private Date recordedAt;
|
||||
|
||||
public DataUsage() {
|
||||
this.uuid = UUID.randomUUID();
|
||||
this.recordedAt = new Date();
|
||||
}
|
||||
|
||||
public DataUsage(Device device, DbObject report) {
|
||||
this();
|
||||
this.setSiteUuid(device.getSiteUuid());
|
||||
this.setDeviceUuid(device.getUuid());
|
||||
this.usage = report;
|
||||
DbObject wifiProperty = report.getDbObject(new String[]{"wifi"});
|
||||
DbObject mobileProperty = report.getDbObject(new String[]{"mobile"});
|
||||
long from = mobileProperty.getLong("from", wifiProperty.getLong("from"));
|
||||
this.from = new Date(from);
|
||||
long to = mobileProperty.getLong("to", wifiProperty.getLong("to"));
|
||||
this.to = new Date(to);
|
||||
if (wifiProperty.isEmpty()) {
|
||||
report.remove("wifi");
|
||||
} else if (wifiProperty.getLong("tx", 0L) + wifiProperty.getLong("rx", 0L) == 0L) {
|
||||
report.remove("wifi");
|
||||
} else {
|
||||
wifiProperty.remove("from");
|
||||
wifiProperty.remove("to");
|
||||
}
|
||||
|
||||
if (mobileProperty.isEmpty()) {
|
||||
report.remove("mobile");
|
||||
} else if (mobileProperty.getLong("tx", 0L) + mobileProperty.getLong("rx", 0L) == 0L) {
|
||||
report.remove("mobile");
|
||||
} else {
|
||||
mobileProperty.remove("from");
|
||||
mobileProperty.remove("to");
|
||||
}
|
||||
|
||||
if (this.usage.isEmpty()) {
|
||||
this.usage = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
public void setUuid(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public UUID getDeviceUuid() {
|
||||
return this.deviceUuid;
|
||||
}
|
||||
|
||||
public void setDeviceUuid(UUID deviceUuid) {
|
||||
this.deviceUuid = deviceUuid;
|
||||
}
|
||||
|
||||
public UUID getSiteUuid() {
|
||||
return this.siteUuid;
|
||||
}
|
||||
|
||||
public void setSiteUuid(UUID siteUuid) {
|
||||
this.siteUuid = siteUuid;
|
||||
}
|
||||
|
||||
public Date getFrom() {
|
||||
return this.from;
|
||||
}
|
||||
|
||||
public void setFrom(Date from) {
|
||||
this.from = from;
|
||||
}
|
||||
|
||||
public Date getTo() {
|
||||
return this.to;
|
||||
}
|
||||
|
||||
public void setTo(Date to) {
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
public DbObject getUsage() {
|
||||
return this.usage;
|
||||
}
|
||||
|
||||
public long getUsage(String category, String key) {
|
||||
return this.getUsage().getDbObject(new String[]{category}).getLong(key, 0L);
|
||||
}
|
||||
|
||||
public void setUsage(DbObject usage) {
|
||||
this.usage = usage;
|
||||
}
|
||||
|
||||
public Date getRecordedAt() {
|
||||
return this.recordedAt;
|
||||
}
|
||||
|
||||
public void setRecordedAt(Date recordedAt) {
|
||||
this.recordedAt = recordedAt;
|
||||
}
|
||||
|
||||
public boolean isLaterThan(DataUsage usage) {
|
||||
return usage.getTo().getTime() < this.getFrom().getTime();
|
||||
}
|
||||
|
||||
public boolean isOverlapped(DataUsage usage) {
|
||||
return usage.getFrom().getTime() >= this.getTo().getTime() && usage.getTo().getTime() <= this.getTo().getTime();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,495 @@
|
||||
package com.midm.model.device;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.midm.model.GeneralProfile;
|
||||
import com.midm.model.battery.Battery;
|
||||
import com.midm.model.file.OtaFile;
|
||||
import com.midm.model.org.User;
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import com.mitac.cell.utils.McJsonUtils;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import org.bson.Document;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
import org.springframework.data.mongodb.core.index.CompoundIndex;
|
||||
import org.springframework.data.mongodb.core.index.CompoundIndexes;
|
||||
import org.springframework.data.mongodb.core.index.Indexed;
|
||||
import org.springframework.data.mongodb.core.mapping.DBRef;
|
||||
|
||||
/**
|
||||
* ======================================================================================
|
||||
* 核心实体模型:受控终端设备档案 (Device Entity)
|
||||
* ======================================================================================
|
||||
*
|
||||
* <p>【数据建模与 MongoDB 索引架构】
|
||||
* 1. 业务地位:
|
||||
* - 作为整个 MDM / IoT 系统的核心资产抽象,代表一台具体的受控智能硬件(PDA / 移动平板 / 车载终端)。
|
||||
* 2. 【生产级复合索引设计】:
|
||||
* - `{'profile.hardware_info.serial_no': 1}` (unique = true):
|
||||
* 以出厂序列号构建唯一业务主键索引,杜绝重复设备接入,提供 O(1) 复杂度的极速检索。
|
||||
* - `{'deviceGroup.$id': 1}`:
|
||||
* 按部门/仓库/车辆编队等组织分组高效检索关联设备。
|
||||
* - `{'owner.$id': 1, 'deviceGroup.$id': 1}`:
|
||||
* 加速管理员按员工责任人与所属部门进行组合过滤统计。
|
||||
* 3. 关联映射({@link DBRef}):
|
||||
* - 关联所属企业员工 (User owner)、商业授权凭据 (DeviceLicense license)、组织分组 (DeviceGroup deviceGroup)。
|
||||
* 4. 动态属性集(DbObject):
|
||||
* - `profile`:静态硬件特征(IMEI、MAC、CPU型号、屏幕分辨率、出厂镜像版本);
|
||||
* - `states`:动态运行快照(当前电量、实时网络类型、内存剩余空间、活跃IP);
|
||||
* - `installedApps`:端侧已安装的应用清单快照(用于合规检测与版本审计)。
|
||||
*
|
||||
* @author MiDM Core Platform Team
|
||||
*/
|
||||
@org.springframework.data.mongodb.core.mapping.Document
|
||||
@CompoundIndexes({@CompoundIndex(
|
||||
def = "{'deviceGroup.$id':1}"
|
||||
), @CompoundIndex(
|
||||
def = "{'profile.hardware_info.serial_no':1}",
|
||||
unique = true
|
||||
), @CompoundIndex(
|
||||
def = "{'owner.$id':1, 'deviceGroup.$id':1}"
|
||||
)})
|
||||
public class Device extends GeneralProfile {
|
||||
/** 所属企业租户主键 UUID(实现多租户严格逻辑隔离) */
|
||||
private UUID siteUuid;
|
||||
|
||||
/** 临时字段:前端传递的目标分组 UUID,不持久化到 MongoDB */
|
||||
@Transient
|
||||
private UUID groupUuid;
|
||||
|
||||
/** 临时字段:展示给前端的分组全路径(如 "总公司/华东大区/智能物流一号仓") */
|
||||
@Transient
|
||||
private String groupPath;
|
||||
|
||||
/** 临时字段:归属负责人主键 UUID */
|
||||
@Transient
|
||||
private UUID ownerUuid;
|
||||
|
||||
/** MongoDB 跨集合引用:设备领用人档案 */
|
||||
@DBRef
|
||||
private User owner;
|
||||
|
||||
/** MongoDB 跨集合引用:设备绑定的商业 License 授权凭据 */
|
||||
@DBRef
|
||||
private DeviceLicense license;
|
||||
|
||||
/** MongoDB 跨集合引用:所属层级组织分组 */
|
||||
@DBRef
|
||||
private DeviceGroup deviceGroup;
|
||||
|
||||
/** 临时字段:设备当前生效的策略清单缓存 */
|
||||
@Transient
|
||||
private List deviceProfiles;
|
||||
|
||||
/** 许可激活时间点索引 */
|
||||
@Indexed
|
||||
private Date licensed;
|
||||
|
||||
/** 许可到期时间点索引(用于定时扫描批量过期告警与自动续约) */
|
||||
@Indexed
|
||||
private Date licenseExpiry;
|
||||
|
||||
/** 临时字段:RSA 鉴权私钥字符串 */
|
||||
@Transient
|
||||
private String rsa;
|
||||
|
||||
/** 终端动态遥测快照数据字典(电池状态、网络、存储剩余空间等) */
|
||||
protected DbObject states;
|
||||
|
||||
/** 首次入网注册时间戳 */
|
||||
private Date enrolled;
|
||||
|
||||
/** 最近一次活跃心跳上报时间(Check-in,用于离线判定) */
|
||||
private Date lastCheckedIn;
|
||||
|
||||
/** 最近一次 TCP / WebSocket 连接断开时间点 */
|
||||
private Date lastDisconnected;
|
||||
|
||||
/** 终端已安装的应用程序包信息清单快照 */
|
||||
private List installedApps;
|
||||
|
||||
public String getRsa() {
|
||||
return this.rsa;
|
||||
}
|
||||
|
||||
public void setRsa(String rsa) {
|
||||
this.rsa = rsa;
|
||||
}
|
||||
|
||||
public UUID getSiteUuid() {
|
||||
return this.siteUuid;
|
||||
}
|
||||
|
||||
public void setSiteUuid(UUID siteUuid) {
|
||||
this.siteUuid = siteUuid;
|
||||
}
|
||||
|
||||
public UUID getGroupUuid() {
|
||||
return this.groupUuid;
|
||||
}
|
||||
|
||||
public String getGroupPath() {
|
||||
return this.groupPath;
|
||||
}
|
||||
|
||||
public void setGroupPath(String groupPath) {
|
||||
this.groupPath = groupPath;
|
||||
}
|
||||
|
||||
public User getOwner() {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
public void setOwner(User owner) {
|
||||
this.owner = owner;
|
||||
if (owner != null) {
|
||||
this.removeProfile("owner");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public UUID getOwnerUuid() {
|
||||
return this.ownerUuid;
|
||||
}
|
||||
|
||||
public void setOwnerUuid(UUID ownerUuid) {
|
||||
this.ownerUuid = ownerUuid;
|
||||
}
|
||||
|
||||
public boolean hasOwner() {
|
||||
return this.getOwner() != null;
|
||||
}
|
||||
|
||||
public String getOwnerInfo(String key, String defaultValue) {
|
||||
if (this.owner == null) {
|
||||
DbObject owner = this.getProfileCategory(new String[]{"owner"});
|
||||
return (String)owner.get(key, defaultValue);
|
||||
} else {
|
||||
return key.equals("email") ? this.owner.getEmail() : (String)this.owner.getProfile(key, defaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAssociated() {
|
||||
return this.getDeviceGroup() != null;
|
||||
}
|
||||
|
||||
public boolean canRegister() {
|
||||
return !Strings.isNullOrEmpty(this.getSerialNo());
|
||||
}
|
||||
|
||||
public DeviceGroup getDeviceGroup() {
|
||||
return this.deviceGroup;
|
||||
}
|
||||
|
||||
public void setDeviceGroup(DeviceGroup deviceGroup) {
|
||||
if (deviceGroup != null && deviceGroup.getSiteUuid().equals(this.getSiteUuid())) {
|
||||
this.deviceGroup = deviceGroup;
|
||||
} else {
|
||||
this.groupUuid = null;
|
||||
this.deviceGroup = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public DbObject getStates() {
|
||||
if (this.states == null) {
|
||||
this.states = new DbObject();
|
||||
}
|
||||
|
||||
return this.states;
|
||||
}
|
||||
|
||||
public void setStates(DbObject states) {
|
||||
this.states = states;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return this.getStates().getString("state", "unknown");
|
||||
}
|
||||
|
||||
public void setState(String state) {
|
||||
this.setState("state", state);
|
||||
}
|
||||
|
||||
public boolean isOnline() {
|
||||
return this.getStates().getBoolean("isOnline", false);
|
||||
}
|
||||
|
||||
public void setOnline(boolean online) {
|
||||
this.setState("isOnline", online);
|
||||
}
|
||||
|
||||
public boolean isBlocked() {
|
||||
return this.getStates().containsKey("blocked");
|
||||
}
|
||||
|
||||
public void setState(String key, Object value) {
|
||||
this.getStates().append(key, value);
|
||||
}
|
||||
|
||||
public void setClientVersion(int version) {
|
||||
this.getStates().put("clientVersion", version);
|
||||
}
|
||||
|
||||
public int getClientVersion() {
|
||||
return this.getStates().getInteger("clientVersion", -1);
|
||||
}
|
||||
|
||||
public Battery.BATTERY_CONDITION getBatteryCondition() {
|
||||
return Battery.BATTERY_CONDITION.forValue(this.getStates().getInteger("batteryCondition", -1));
|
||||
}
|
||||
|
||||
public boolean hasOldClient() {
|
||||
return this.getClientVersion() < 0;
|
||||
}
|
||||
|
||||
public Date getEnrolled() {
|
||||
return this.enrolled;
|
||||
}
|
||||
|
||||
public boolean isEnrolled() {
|
||||
return this.enrolled != null;
|
||||
}
|
||||
|
||||
public void setEnrolled(Date enrolled) {
|
||||
this.enrolled = enrolled;
|
||||
this.setState("enrolled");
|
||||
this.setLicenseExpiry();
|
||||
}
|
||||
|
||||
public boolean isRetired() {
|
||||
return this.getState().equals("retired");
|
||||
}
|
||||
|
||||
public Date getLastCheckedIn() {
|
||||
return this.lastCheckedIn;
|
||||
}
|
||||
|
||||
public void setLastCheckedIn() {
|
||||
this.setLastCheckedIn(new Date());
|
||||
}
|
||||
|
||||
public void setLastCheckedIn(Date lastCheckedIn) {
|
||||
this.lastCheckedIn = lastCheckedIn;
|
||||
}
|
||||
|
||||
public Date getLastDisconnected() {
|
||||
return this.lastDisconnected;
|
||||
}
|
||||
|
||||
public void setLastDisconnected() {
|
||||
this.lastDisconnected = new Date();
|
||||
}
|
||||
|
||||
public void setLastDisconnected(Date disconnected) {
|
||||
this.lastDisconnected = disconnected;
|
||||
}
|
||||
|
||||
public List getInstalledApps() {
|
||||
return this.installedApps;
|
||||
}
|
||||
|
||||
public void setInstalledApps(List installedApps) {
|
||||
this.installedApps = installedApps;
|
||||
}
|
||||
|
||||
public void setDeviceProfiles(List deviceProfiles) {
|
||||
this.deviceProfiles = deviceProfiles;
|
||||
}
|
||||
|
||||
public String getSerialNo() {
|
||||
return (String)this.getCategoryProfile("hardware_info", "serial_no");
|
||||
}
|
||||
|
||||
public void setSerialNo(String serialNo) {
|
||||
this.setProfile("hardware_info", "serial_no", serialNo.trim());
|
||||
}
|
||||
|
||||
public String getModelId() {
|
||||
return (String)this.getCategoryProfile("hardware_info", "product_id");
|
||||
}
|
||||
|
||||
public String getBuildNo() {
|
||||
return this.getProfileCategory(new String[]{"software_info"}).getString("build_no");
|
||||
}
|
||||
|
||||
public String getDisplayId() {
|
||||
return this.getProfileCategory(new String[]{"software_info"}).getString("display_id");
|
||||
}
|
||||
|
||||
public String getProductDisplayId() {
|
||||
return this.getProfileCategory(new String[]{"software_info"}).getString("product_display_id");
|
||||
}
|
||||
|
||||
public long getBuildDate() {
|
||||
return this.getProfileCategory(new String[]{"software_info"}).getLong("build_date", -1L);
|
||||
}
|
||||
|
||||
public int getSdkVersion() {
|
||||
if (this.isEnrolled()) {
|
||||
int version = this.getProfileCategory(new String[]{"software_info"}).getInteger("sdk_version", -1);
|
||||
if (version < 0) {
|
||||
String osVersion = this.getProfileCategory(new String[]{"software_info"}).getString("os_version");
|
||||
if (!Strings.isNullOrEmpty(osVersion)) {
|
||||
if (osVersion.startsWith("5.")) {
|
||||
version = 22;
|
||||
} else if (osVersion.startsWith("6.")) {
|
||||
version = 23;
|
||||
} else if (osVersion.startsWith("7.")) {
|
||||
version = 25;
|
||||
} else if (osVersion.startsWith("8.")) {
|
||||
version = 27;
|
||||
} else if (osVersion.equals("9")) {
|
||||
version = 28;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return version;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public String getCustomerId() {
|
||||
return (String)this.getCategoryProfile("software_info", "customer_id");
|
||||
}
|
||||
|
||||
public String getRegionImgVersion() {
|
||||
return this.getProfile().getDbObject(new String[]{"software_info"}).getString("region_version");
|
||||
}
|
||||
|
||||
public String getScriptVersion() {
|
||||
return (String)this.getCategoryProfile("software_info", "script_version");
|
||||
}
|
||||
|
||||
public long getRegionBuildDate() {
|
||||
return this.getProfile().getDbObject(new String[]{"software_info"}).getLong("region_build_date");
|
||||
}
|
||||
|
||||
public boolean isGmsAvailable() {
|
||||
return this.getProfile().getDbObject(new String[]{"software_info"}).getBoolean("gms_available");
|
||||
}
|
||||
|
||||
public String getSkuId() {
|
||||
String skuId = (String)this.getCategoryProfile("hardware_info", "sku_id");
|
||||
if (skuId == null) {
|
||||
if (this.isGmsAvailable()) {
|
||||
String buildNo = this.getBuildNo();
|
||||
if (buildNo == null) {
|
||||
buildNo = this.getDisplayId();
|
||||
}
|
||||
|
||||
if (buildNo != null) {
|
||||
skuId = buildNo.substring(0, buildNo.indexOf("."));
|
||||
}
|
||||
} else {
|
||||
skuId = OtaFile.parseSkuId(this.getDisplayId());
|
||||
}
|
||||
|
||||
if (skuId == null) {
|
||||
skuId = OtaFile.parseSkuId(this.getProductDisplayId());
|
||||
}
|
||||
|
||||
if (skuId == null) {
|
||||
skuId = OtaFile.parseSkuId(this.getBuildNo());
|
||||
}
|
||||
|
||||
if (skuId != null) {
|
||||
this.setProfile("hardware_info", "sku_id", skuId);
|
||||
}
|
||||
}
|
||||
|
||||
return skuId;
|
||||
}
|
||||
|
||||
public String getDeviceId() {
|
||||
return (String)this.getCategoryProfile("hardware_info", "device_id");
|
||||
}
|
||||
|
||||
public String getBuildFingerPrint() {
|
||||
return (String)this.getCategoryProfile("software_info", "build_fingerprint");
|
||||
}
|
||||
|
||||
public boolean isMobileConnected() {
|
||||
String type = this.getProfileCategory(new String[]{"network", "active"}).getString("type");
|
||||
return "MOBILE".equalsIgnoreCase(type);
|
||||
}
|
||||
|
||||
public String getWifiMacAddr() {
|
||||
return this.getProfileCategory(new String[]{"network", "wifi"}).getString("mac_address");
|
||||
}
|
||||
|
||||
public DeviceLicense getLicense() {
|
||||
return this.license;
|
||||
}
|
||||
|
||||
public void setLicense(DeviceLicense license) {
|
||||
this.license = license;
|
||||
if (license != null) {
|
||||
this.licensed = new Date();
|
||||
this.setLicenseExpiry();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Date getLicensed() {
|
||||
return this.licensed;
|
||||
}
|
||||
|
||||
public void setLicensed(Date licensed) {
|
||||
this.licensed = licensed;
|
||||
}
|
||||
|
||||
private void setLicenseExpiry() {
|
||||
if (this.hasLicense()) {
|
||||
if (!this.license.isActivated() && this.isEnrolled()) {
|
||||
this.license.activate();
|
||||
}
|
||||
|
||||
this.setLicenseExpiry(this.license.getExpiry());
|
||||
}
|
||||
}
|
||||
|
||||
public Date getLicenseExpiry() {
|
||||
if (this.licenseExpiry == null && this.hasLicense()) {
|
||||
this.licenseExpiry = this.license.getExpiry();
|
||||
}
|
||||
|
||||
return this.licenseExpiry;
|
||||
}
|
||||
|
||||
public boolean isLicenseExpired() {
|
||||
return this.license != null && !this.license.isPerpetual() && this.license.isExpired();
|
||||
}
|
||||
|
||||
public void setLicenseExpiry(Date expiry) {
|
||||
this.licenseExpiry = expiry;
|
||||
}
|
||||
|
||||
public boolean hasLicense() {
|
||||
return this.license != null;
|
||||
}
|
||||
|
||||
public boolean isTrial() {
|
||||
return !this.hasLicense() || this.license.isTrial();
|
||||
}
|
||||
|
||||
public void removeLicense() {
|
||||
this.setLicense((DeviceLicense)null);
|
||||
}
|
||||
|
||||
public String getPlan() {
|
||||
return this.license.getPlan();
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.setEnrolled((Date)null);
|
||||
this.getStates().clear();
|
||||
}
|
||||
|
||||
public Device clone() {
|
||||
return (Device)McJsonUtils.clone(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
package com.midm.model.device;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class DeviceApps {
|
||||
@Id
|
||||
private UUID deviceUuid;
|
||||
@Transient
|
||||
private String serialNo;
|
||||
private String category = "installed";
|
||||
private List apps;
|
||||
private Date reported = new Date();
|
||||
|
||||
public UUID getDeviceUuid() {
|
||||
return this.deviceUuid;
|
||||
}
|
||||
|
||||
public void setDeviceUuid(UUID deviceUuid) {
|
||||
this.deviceUuid = deviceUuid;
|
||||
}
|
||||
|
||||
public String getSerialNo() {
|
||||
return this.serialNo;
|
||||
}
|
||||
|
||||
public void setSerialNo(String serialNo) {
|
||||
this.serialNo = serialNo;
|
||||
}
|
||||
|
||||
public String getCategory() {
|
||||
return this.category;
|
||||
}
|
||||
|
||||
public void setCategory(String category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public List getApps() {
|
||||
return this.apps;
|
||||
}
|
||||
|
||||
public void setApps(List apps) {
|
||||
this.apps = apps;
|
||||
}
|
||||
|
||||
public AppInfo getClientService() {
|
||||
return this.getApp("com.mitac.midm.client");
|
||||
}
|
||||
|
||||
public void setClientService(AppInfo appInfo) {
|
||||
this.setApp(appInfo);
|
||||
}
|
||||
|
||||
public AppInfo getSystemService() {
|
||||
return this.getApp("com.mitac.midm.system");
|
||||
}
|
||||
|
||||
public void setSystemService(AppInfo appInfo) {
|
||||
this.setApp(appInfo);
|
||||
}
|
||||
|
||||
public AppInfo getApp(String packageName) {
|
||||
if (this.apps != null) {
|
||||
for(AppInfo app : this.apps) {
|
||||
String appPackage = app.getPackageName();
|
||||
if (packageName.equals(appPackage)) {
|
||||
return app;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setApp(AppInfo newApp) {
|
||||
if (newApp != null && !Strings.isNullOrEmpty(newApp.getPackageName())) {
|
||||
if (this.apps == null) {
|
||||
this.apps = new ArrayList();
|
||||
}
|
||||
|
||||
this.apps.add(newApp);
|
||||
}
|
||||
}
|
||||
|
||||
public void fixAbnormal() {
|
||||
Iterator<AppInfo> it = this.apps.iterator();
|
||||
|
||||
while(it.hasNext()) {
|
||||
AppInfo info = (AppInfo)it.next();
|
||||
String packageName = info.getPackageName();
|
||||
String label = info.getLabel();
|
||||
if (Strings.isNullOrEmpty(packageName)) {
|
||||
it.remove();
|
||||
} else if (Strings.isNullOrEmpty(label)) {
|
||||
info.setLabel(packageName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Date getReported() {
|
||||
return this.reported;
|
||||
}
|
||||
|
||||
public void setReported(Date reported) {
|
||||
this.reported = reported;
|
||||
}
|
||||
|
||||
public boolean isAppInstalled(int deviceSdk, String packageName, long versionCode, int minSdk) {
|
||||
if (minSdk != -1 && deviceSdk < minSdk) {
|
||||
return true;
|
||||
} else {
|
||||
AppInfo appInfo = this.getApp(packageName);
|
||||
return appInfo != null ? (long)appInfo.getVersionCode() >= versionCode : false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
List<AppInfo> newApps = null;
|
||||
if (obj instanceof DeviceApps) {
|
||||
DeviceApps deviceApps = (DeviceApps)obj;
|
||||
newApps = deviceApps.getApps();
|
||||
if (this.apps != null && newApps != null && this.apps.size() == newApps.size()) {
|
||||
if (this.apps.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for(AppInfo newAppInfo : newApps) {
|
||||
AppInfo curInfo = this.getApp(newAppInfo.getPackageName());
|
||||
if (curInfo == null || newAppInfo.getVersionCode() != curInfo.getVersionCode()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.midm.model.device;
|
||||
|
||||
import com.midm.model.GeneralProfile;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class DeviceGroup extends GeneralProfile implements Comparable {
|
||||
private UUID siteUuid;
|
||||
private UUID parentUuid;
|
||||
private Integer order;
|
||||
@Transient
|
||||
private Integer deviceNumbers;
|
||||
private List children;
|
||||
|
||||
public DeviceGroup() {
|
||||
this.deviceNumbers = 0;
|
||||
}
|
||||
|
||||
public DeviceGroup(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public DeviceGroup(UUID siteUuid, UUID parentUuid, String name) {
|
||||
this.init();
|
||||
this.siteUuid = siteUuid;
|
||||
this.parentUuid = parentUuid;
|
||||
this.setName(name);
|
||||
}
|
||||
|
||||
public UUID getSiteUuid() {
|
||||
return this.siteUuid;
|
||||
}
|
||||
|
||||
public void setSiteUuid(UUID siteUuid) {
|
||||
this.siteUuid = siteUuid;
|
||||
}
|
||||
|
||||
public UUID getParentUuid() {
|
||||
return this.parentUuid;
|
||||
}
|
||||
|
||||
public void setParentUuid(UUID parentUuid) {
|
||||
this.parentUuid = parentUuid;
|
||||
}
|
||||
|
||||
public Integer getOrder() {
|
||||
return this.order;
|
||||
}
|
||||
|
||||
public void setOrder(Integer order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public Integer getDeviceNumbers() {
|
||||
return this.deviceNumbers;
|
||||
}
|
||||
|
||||
public void setDeviceNumbers(Integer numbers) {
|
||||
this.deviceNumbers = numbers == null ? 0 : numbers;
|
||||
}
|
||||
|
||||
public List getChildren() {
|
||||
return this.children;
|
||||
}
|
||||
|
||||
public void setChildren(List children) {
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
public boolean equals(UUID uuid) {
|
||||
return this.uuid != null && this.uuid.equals(uuid);
|
||||
}
|
||||
|
||||
public int compareTo(Object target) {
|
||||
UUID targetUuid = null;
|
||||
if (target instanceof UUID) {
|
||||
targetUuid = (UUID)target;
|
||||
} else if (target instanceof DeviceGroup) {
|
||||
targetUuid = ((DeviceGroup)target).getUuid();
|
||||
}
|
||||
|
||||
if (targetUuid == null) {
|
||||
return this.uuid == null ? 0 : 1;
|
||||
} else {
|
||||
return this.uuid == null ? -1 : this.uuid.compareTo(targetUuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.midm.model.device;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.index.Indexed;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class DeviceKey {
|
||||
@Id
|
||||
private UUID uuid;
|
||||
@Indexed
|
||||
private String deviceSerial;
|
||||
private String rsa;
|
||||
private Date created;
|
||||
|
||||
public DeviceKey() {
|
||||
this((String)null, (String)null);
|
||||
}
|
||||
|
||||
public DeviceKey(String deviceSerial, String rsa) {
|
||||
this.uuid = UUID.randomUUID();
|
||||
this.created = new Date();
|
||||
this.deviceSerial = deviceSerial;
|
||||
this.rsa = rsa;
|
||||
}
|
||||
|
||||
public String getDeviceSerial() {
|
||||
return this.deviceSerial;
|
||||
}
|
||||
|
||||
public void setDeviceSerial(String deviceSerial) {
|
||||
this.deviceSerial = deviceSerial;
|
||||
}
|
||||
|
||||
public String getRsa() {
|
||||
return this.rsa;
|
||||
}
|
||||
|
||||
public void setRsa(String rsa) {
|
||||
this.rsa = rsa;
|
||||
}
|
||||
|
||||
public Date getCreated() {
|
||||
return this.created;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,427 @@
|
||||
package com.midm.model.device;
|
||||
|
||||
import com.midm.model.org.Site;
|
||||
import com.midm.model.org.SiteLicense;
|
||||
import com.midm.model.system.LicenseModel;
|
||||
import com.mitac.cell.utils.McDateTimeUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.index.CompoundIndex;
|
||||
import org.springframework.data.mongodb.core.index.CompoundIndexes;
|
||||
import org.springframework.data.mongodb.core.index.Indexed;
|
||||
import org.springframework.data.mongodb.core.mapping.DBRef;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
@CompoundIndexes({@CompoundIndex(
|
||||
def = "{'site.$id': 1}"
|
||||
), @CompoundIndex(
|
||||
def = "{'siteLicense.$id': 1}"
|
||||
), @CompoundIndex(
|
||||
def = "{'licenseModel.$id': 1}"
|
||||
), @CompoundIndex(
|
||||
def = "{'plan': 1, 'site.$id': 1, 'expiry': 1}"
|
||||
), @CompoundIndex(
|
||||
def = "{'plan': 1, 'licenseModel.$id': 1, 'site.$id': 1, 'expiry': 1}"
|
||||
), @CompoundIndex(
|
||||
def = "{'plan': 1, 'childSite.$id': 1, 'licenseModel.$id': 1, 'site.$id': 1, 'expiry': 1}"
|
||||
), @CompoundIndex(
|
||||
def = "{'plan': 1,\t'childSite.$id': 1, 'site.$id': 1, 'expiry': 1}"
|
||||
), @CompoundIndex(
|
||||
def = "{'childSite.$id': 1, 'site.$id': 1, 'expiry': 1}"
|
||||
)})
|
||||
public class DeviceLicense {
|
||||
@Id
|
||||
private UUID uuid;
|
||||
@Indexed
|
||||
private UUID deviceUuid;
|
||||
@Indexed
|
||||
private String deviceSerial;
|
||||
@DBRef
|
||||
private SiteLicense siteLicense;
|
||||
@DBRef
|
||||
private SiteLicense childSiteLicense;
|
||||
@DBRef
|
||||
private Site site;
|
||||
@DBRef
|
||||
private Site childSite;
|
||||
@DBRef
|
||||
private LicenseModel licenseModel;
|
||||
private String plan;
|
||||
private boolean autoRenew;
|
||||
private boolean renewToSameModel;
|
||||
private int activationCount;
|
||||
@Indexed
|
||||
private Date activatedAt;
|
||||
@Indexed
|
||||
private Date expiry;
|
||||
private List reactivated;
|
||||
private Date created;
|
||||
|
||||
public DeviceLicense() {
|
||||
this.plan = "standard";
|
||||
this.autoRenew = false;
|
||||
this.renewToSameModel = false;
|
||||
this.uuid = UUID.randomUUID();
|
||||
this.created = new Date();
|
||||
}
|
||||
|
||||
public DeviceLicense(SiteLicense license) {
|
||||
this((Device)null, (SiteLicense)license);
|
||||
}
|
||||
|
||||
public DeviceLicense(SiteLicense license, String plan) {
|
||||
this((Device)null, (SiteLicense)license);
|
||||
this.setPlan(plan);
|
||||
}
|
||||
|
||||
public DeviceLicense(Device device) {
|
||||
this();
|
||||
this.setDevice(device);
|
||||
}
|
||||
|
||||
public DeviceLicense(Device device, SiteLicense license) {
|
||||
this();
|
||||
this.setSiteLicense(license);
|
||||
this.setDevice(device);
|
||||
}
|
||||
|
||||
public DeviceLicense(Device device, LicenseModel licenseModel) {
|
||||
this();
|
||||
this.setLicenseModel(licenseModel);
|
||||
this.setDevice(device);
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
public void setUuid(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public SiteLicense getSiteLicense() {
|
||||
return this.siteLicense;
|
||||
}
|
||||
|
||||
public void setSiteLicense(SiteLicense license) {
|
||||
this.siteLicense = license;
|
||||
if (license != null) {
|
||||
this.setSite(license.getSite());
|
||||
this.setLicenseModel(license.getLicenseModel());
|
||||
} else {
|
||||
this.setLicenseModel((LicenseModel)null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public SiteLicense getChildSiteLicense() {
|
||||
return this.childSiteLicense;
|
||||
}
|
||||
|
||||
public void setChildSiteLicense(SiteLicense license) {
|
||||
this.childSiteLicense = license;
|
||||
}
|
||||
|
||||
public boolean isLite() {
|
||||
return this.site.isLite() || this.plan.equals("lite");
|
||||
}
|
||||
|
||||
public Site getSite() {
|
||||
return this.site;
|
||||
}
|
||||
|
||||
public void setSite(Site site) {
|
||||
if (site == null) {
|
||||
this.site = this.childSite = null;
|
||||
} else if (site.isChild()) {
|
||||
this.setSite(site.getReseller());
|
||||
this.setChildSite(site);
|
||||
} else {
|
||||
this.site = site;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Site getChildSite() {
|
||||
return this.childSite;
|
||||
}
|
||||
|
||||
public void setChildSite(Site child) {
|
||||
this.childSite = child;
|
||||
}
|
||||
|
||||
public boolean hasLicenseModel() {
|
||||
return this.getLicenseModel() != null;
|
||||
}
|
||||
|
||||
public LicenseModel getLicenseModel() {
|
||||
return this.licenseModel;
|
||||
}
|
||||
|
||||
public void setLicenseModel(LicenseModel licenseModel) {
|
||||
this.setLicenseModel(licenseModel, true);
|
||||
}
|
||||
|
||||
public void setLicenseModel(LicenseModel licenseModel, boolean setExpiry) {
|
||||
this.licenseModel = licenseModel;
|
||||
if (licenseModel != null && setExpiry) {
|
||||
this.expiry = this.licenseModel.getFreshExpiry(new Date());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public UUID getDeviceUuid() {
|
||||
return this.deviceUuid;
|
||||
}
|
||||
|
||||
public void setDeviceUuid(UUID deviceUuid) {
|
||||
this.deviceUuid = deviceUuid;
|
||||
}
|
||||
|
||||
public boolean setDevice(Device device) {
|
||||
if (this.isExceedActivationCount() && this.beforeExpiry()) {
|
||||
return false;
|
||||
} else if (device == null) {
|
||||
if (this.isTrial()) {
|
||||
this.expire();
|
||||
} else {
|
||||
this.setDeviceUuid((UUID)null);
|
||||
this.setDeviceSerial((String)null);
|
||||
this.setAutoRenew(false);
|
||||
this.setRenewToSameModel(false);
|
||||
if (this.isExceedActivationCount()) {
|
||||
this.expire();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
this.setDeviceSerial(device.getSerialNo());
|
||||
this.setDeviceUuid(device.getUuid());
|
||||
if (device.isEnrolled()) {
|
||||
if (this.isActivated()) {
|
||||
++this.activationCount;
|
||||
if (this.isPerpetual()) {
|
||||
Date nextExpiry = this.licenseModel.getNextExpiry(new Date());
|
||||
if (this.expiry.before(nextExpiry)) {
|
||||
this.expiry = nextExpiry;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.activate();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public String getDeviceSerial() {
|
||||
return this.deviceSerial;
|
||||
}
|
||||
|
||||
public void setDeviceSerial(String serialNo) {
|
||||
this.deviceSerial = serialNo;
|
||||
}
|
||||
|
||||
public String getPlan() {
|
||||
return this.plan;
|
||||
}
|
||||
|
||||
public void setPlan(String plan) {
|
||||
this.plan = plan;
|
||||
}
|
||||
|
||||
public boolean isAutoRenew() {
|
||||
return this.autoRenew;
|
||||
}
|
||||
|
||||
public void setAutoRenew(boolean autoRenew) {
|
||||
this.autoRenew = autoRenew;
|
||||
}
|
||||
|
||||
public boolean isRenewToSameModel() {
|
||||
return this.renewToSameModel;
|
||||
}
|
||||
|
||||
public void setRenewToSameModel(boolean renewToSameModel) {
|
||||
this.renewToSameModel = renewToSameModel;
|
||||
}
|
||||
|
||||
public int getActivationCount() {
|
||||
return this.activationCount;
|
||||
}
|
||||
|
||||
public void setActivationCount(int count) {
|
||||
if (count < 0) {
|
||||
count = 0;
|
||||
}
|
||||
|
||||
this.activationCount = count;
|
||||
if (this.activationCount == 0) {
|
||||
this.setActivatedAt((Date)null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void resetActivationCount() {
|
||||
if (this.isTrial()) {
|
||||
this.setActivationCount(0);
|
||||
this.setActivatedAt((Date)null);
|
||||
} else {
|
||||
this.setActivationCount(--this.activationCount);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean exceedActivationCount(int maxActivationCount) {
|
||||
return this.activationCount > maxActivationCount;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return this.activatedAt == null;
|
||||
}
|
||||
|
||||
public boolean isActivated() {
|
||||
return this.activatedAt != null;
|
||||
}
|
||||
|
||||
public boolean isExpired() {
|
||||
return !this.beforeExpiry();
|
||||
}
|
||||
|
||||
public boolean canExtend() {
|
||||
if (!this.isPerpetual()) {
|
||||
return false;
|
||||
} else {
|
||||
List<Date> reactivated = this.getReactivated();
|
||||
if ((reactivated == null || reactivated.size() != 2) && (!this.isExceedActivationCount() || this.getDeviceUuid() != null)) {
|
||||
DateTime expiry = new DateTime(this.getExpiry());
|
||||
DateTime now = DateTime.now();
|
||||
return now.plusDays(45).isAfter(expiry) && expiry.plusDays(14).isAfter(now);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Date getActivatedAt() {
|
||||
return this.activatedAt;
|
||||
}
|
||||
|
||||
public Boolean activate() {
|
||||
return this.isActivated() ? true : this.setActivatedAt(new Date());
|
||||
}
|
||||
|
||||
public Boolean setActivatedAt(Date activatedAt) {
|
||||
if (!this.isActivated()) {
|
||||
this.activatedAt = activatedAt;
|
||||
this.expiry = this.licenseModel.getActivatedExpiry(activatedAt);
|
||||
if (activatedAt != null) {
|
||||
++this.activationCount;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (this.isActivated() && this.activationCount < this.licenseModel.getMaxActivation()) {
|
||||
if (activatedAt != null) {
|
||||
++this.activationCount;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.setDevice((Device)null);
|
||||
}
|
||||
|
||||
public Date getExpiry() {
|
||||
return this.expiry;
|
||||
}
|
||||
|
||||
public boolean beforeExpiry() {
|
||||
return this.expiry != null && this.expiry.after(new Date());
|
||||
}
|
||||
|
||||
public void setExpiry(Date expiryDate) {
|
||||
this.expiry = expiryDate;
|
||||
}
|
||||
|
||||
public void extendExpiryDays(int days) {
|
||||
this.setExpiry((new DateTime()).plusDays(days).toDate());
|
||||
}
|
||||
|
||||
public void expire() {
|
||||
this.setExpiry(new Date());
|
||||
}
|
||||
|
||||
public Date getCreated() {
|
||||
return this.created;
|
||||
}
|
||||
|
||||
public void setCreated(Date created) {
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
public boolean isPerpetual() {
|
||||
return this.licenseModel != null && this.licenseModel.isPerpetual();
|
||||
}
|
||||
|
||||
public boolean isTrial() {
|
||||
return this.siteLicense == null || this.licenseModel == null || this.licenseModel.isTrial();
|
||||
}
|
||||
|
||||
public boolean isExceedActivationCount() {
|
||||
int maxCount = this.licenseModel == null ? 2 : this.licenseModel.getMaxActivation();
|
||||
return maxCount > 0 && maxCount <= this.activationCount;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return this.isPerpetual() ? true : (new Date()).before(this.expiry);
|
||||
}
|
||||
|
||||
public boolean isSameLicenseModel(UUID licenseModelUuid) {
|
||||
return this.licenseModel != null && this.licenseModel.getUuid().equals(licenseModelUuid);
|
||||
}
|
||||
|
||||
public int getRemainingDays() {
|
||||
return this.expiry.before(new Date()) ? 0 : McDateTimeUtils.daysBetween(new DateTime(this.expiry), DateTime.now());
|
||||
}
|
||||
|
||||
public List getReactivated() {
|
||||
return this.reactivated;
|
||||
}
|
||||
|
||||
public void setReactivated(List reactivated) {
|
||||
this.reactivated = reactivated;
|
||||
}
|
||||
|
||||
public boolean reactivate() {
|
||||
if (this.isPerpetual()) {
|
||||
if (this.reactivated == null) {
|
||||
this.reactivated = new ArrayList();
|
||||
}
|
||||
|
||||
if (this.reactivated.size() < 2) {
|
||||
LocalDate today = LocalDate.now();
|
||||
this.reactivated.add(today.toDate());
|
||||
this.setExpiry((new DateTime(this.getExpiry())).plusYears(1).toDate());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getPo() {
|
||||
return this.childSiteLicense != null ? this.childSiteLicense.getPo() : (this.siteLicense != null ? this.siteLicense.getPo() : null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.midm.model.device;
|
||||
|
||||
import com.midm.model.org.User;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class DeviceNote {
|
||||
@Id
|
||||
private UUID uuid;
|
||||
private UUID deviceUuid;
|
||||
private UUID writerUuid;
|
||||
@Transient
|
||||
private User writer;
|
||||
private String note;
|
||||
private Date registeredAt;
|
||||
|
||||
public void init() {
|
||||
this.setUuid(UUID.randomUUID());
|
||||
this.setRegisteredAt(new Date());
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
public void setUuid(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public UUID getDeviceUuid() {
|
||||
return this.deviceUuid;
|
||||
}
|
||||
|
||||
public void setDeviceUuid(UUID deviceUuid) {
|
||||
this.deviceUuid = deviceUuid;
|
||||
}
|
||||
|
||||
public UUID getWriterUuid() {
|
||||
return this.writerUuid;
|
||||
}
|
||||
|
||||
public void setWriterUuid(UUID writerUuid) {
|
||||
this.writerUuid = writerUuid;
|
||||
}
|
||||
|
||||
public User getWriter() {
|
||||
return this.writer;
|
||||
}
|
||||
|
||||
public void setWriter(User writer) {
|
||||
this.writer = writer;
|
||||
}
|
||||
|
||||
public String getNote() {
|
||||
return this.note;
|
||||
}
|
||||
|
||||
public void setNote(String note) {
|
||||
this.note = note;
|
||||
}
|
||||
|
||||
public Date getRegisteredAt() {
|
||||
return this.registeredAt;
|
||||
}
|
||||
|
||||
public void setRegisteredAt(Date registeredAt) {
|
||||
this.registeredAt = registeredAt;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,349 @@
|
||||
package com.midm.model.device;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.midm.model.GeneralProfile;
|
||||
import com.midm.model.org.User;
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import com.mitac.cell.utils.McJsonUtils;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
import org.springframework.data.mongodb.core.index.CompoundIndex;
|
||||
import org.springframework.data.mongodb.core.index.Indexed;
|
||||
import org.springframework.data.mongodb.core.mapping.DBRef;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
@CompoundIndex(
|
||||
def = "{'deviceProfileGroup.uuid': 1}"
|
||||
)
|
||||
public class DeviceProfile extends GeneralProfile {
|
||||
@Indexed
|
||||
private UUID siteUuid;
|
||||
@DBRef
|
||||
private DeviceProfileGroup deviceProfileGroup;
|
||||
private UUID writerUuid;
|
||||
private boolean isGlobal;
|
||||
private DbObject status;
|
||||
private ProfileApps apps;
|
||||
private List otas;
|
||||
private DbObject files;
|
||||
private ProfileScope scope;
|
||||
private List sequence;
|
||||
@Transient
|
||||
private DbObject progress;
|
||||
@Transient
|
||||
private DbObject reference;
|
||||
@Transient
|
||||
private UUID groupUuid;
|
||||
@Transient
|
||||
private User writer;
|
||||
@Expose(
|
||||
serialize = false
|
||||
)
|
||||
@Transient
|
||||
private boolean needOldFormat = false;
|
||||
|
||||
public UUID getSiteUuid() {
|
||||
return this.siteUuid;
|
||||
}
|
||||
|
||||
public boolean isGlobal() {
|
||||
return this.isGlobal;
|
||||
}
|
||||
|
||||
public void setIsGlobal(boolean isGlobal) {
|
||||
this.isGlobal = isGlobal;
|
||||
}
|
||||
|
||||
public UUID getGroupUuid() {
|
||||
return this.groupUuid;
|
||||
}
|
||||
|
||||
public void setGroupUuid(UUID groupUuid) {
|
||||
this.groupUuid = groupUuid;
|
||||
}
|
||||
|
||||
public DeviceProfileGroup getDeviceProfileGroup() {
|
||||
return this.deviceProfileGroup;
|
||||
}
|
||||
|
||||
public void setDeviceProfileGroup(DeviceProfileGroup deviceProfileGroup) {
|
||||
this.deviceProfileGroup = deviceProfileGroup;
|
||||
if (deviceProfileGroup == null) {
|
||||
this.groupUuid = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Set getFileUUids() {
|
||||
Set<UUID> pushUuids = new HashSet();
|
||||
if (this.files != null && !this.files.isEmpty() && this.files.containsKey("push")) {
|
||||
List<DbObject> pushes = this.files.getList("push", DbObject.class);
|
||||
pushes.forEach((pushItem) -> {
|
||||
List<Object> sources = pushItem.getList("sources", Object.class);
|
||||
sources.forEach((source) -> {
|
||||
if (source instanceof UUID) {
|
||||
pushUuids.add((UUID)source);
|
||||
} else if (source instanceof String) {
|
||||
pushUuids.add(UUID.fromString((String)source));
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return pushUuids;
|
||||
}
|
||||
|
||||
public String applyOrder() {
|
||||
return this.getProfile().getString("applyOrder", "none");
|
||||
}
|
||||
|
||||
public List getSequence() {
|
||||
return this.sequence;
|
||||
}
|
||||
|
||||
public boolean hasSequence() {
|
||||
return this.sequence != null && !this.sequence.isEmpty();
|
||||
}
|
||||
|
||||
public void setSequence(List sequence) {
|
||||
this.sequence = sequence;
|
||||
}
|
||||
|
||||
public void setSiteUuid(UUID siteUuid) {
|
||||
this.siteUuid = siteUuid;
|
||||
}
|
||||
|
||||
public UUID getWriterUuid() {
|
||||
return this.writerUuid;
|
||||
}
|
||||
|
||||
public void setWriterUuid(UUID writerUuid) {
|
||||
this.writerUuid = writerUuid;
|
||||
}
|
||||
|
||||
public DbObject getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
public void setStatus(DbObject status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public ProfileScope getScope() {
|
||||
return this.scope;
|
||||
}
|
||||
|
||||
public boolean hasScope() {
|
||||
return this.scope != null && this.scope.hasScoped();
|
||||
}
|
||||
|
||||
public boolean hasScopeDeviceGroups() {
|
||||
return this.scope != null && this.scope.getGroup() != null && !this.scope.getGroup().isEmpty();
|
||||
}
|
||||
|
||||
public Set getScopedDeviceGroups() {
|
||||
return this.scope == null ? null : this.scope.getGroup();
|
||||
}
|
||||
|
||||
public Set getScopedDevice() {
|
||||
return this.scope == null ? null : this.scope.getDevice();
|
||||
}
|
||||
|
||||
public void setScope(ProfileScope scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
public User getWriter() {
|
||||
return this.writer;
|
||||
}
|
||||
|
||||
public void setWriter(User writer) {
|
||||
this.writer = writer;
|
||||
}
|
||||
|
||||
public void initApps() {
|
||||
if (this.apps != null) {
|
||||
this.apps.initInstallApp();
|
||||
this.apps.setInstall(this.apps.getInstallApp());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public ProfileApps getApps() {
|
||||
return this.apps;
|
||||
}
|
||||
|
||||
public List getInstallApps() {
|
||||
if (this.apps == null) {
|
||||
this.initApps();
|
||||
}
|
||||
|
||||
return this.apps == null ? null : this.apps.getInstallApp();
|
||||
}
|
||||
|
||||
public List getInstallUuids() {
|
||||
if (this.apps == null) {
|
||||
this.initApps();
|
||||
}
|
||||
|
||||
return this.apps != null ? this.apps.getInstallUuids() : null;
|
||||
}
|
||||
|
||||
public ProfileApps.InstallApp getInstallApp(String packageName) {
|
||||
if (this.apps == null) {
|
||||
this.initApps();
|
||||
}
|
||||
|
||||
return this.apps != null ? this.apps.getInstallApp(packageName) : null;
|
||||
}
|
||||
|
||||
public void setApps(ProfileApps apps) {
|
||||
this.apps = apps;
|
||||
}
|
||||
|
||||
public boolean needOldFormat() {
|
||||
return this.needOldFormat;
|
||||
}
|
||||
|
||||
public void setNeedOldFormat(boolean need) {
|
||||
this.needOldFormat = need;
|
||||
}
|
||||
|
||||
public void setToOldFormat() {
|
||||
if (this.apps != null) {
|
||||
this.apps.setToOldFormat();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public List getWhiteListPackages() {
|
||||
return this.apps != null ? this.apps.getPackageList(this.apps.getWhiteList()) : null;
|
||||
}
|
||||
|
||||
public List getBlackListPackages() {
|
||||
return this.apps != null ? this.apps.getPackageList(this.apps.getWhiteList()) : null;
|
||||
}
|
||||
|
||||
public List getOtas() {
|
||||
return this.otas;
|
||||
}
|
||||
|
||||
public void setOtas(List otas) {
|
||||
this.otas = otas;
|
||||
}
|
||||
|
||||
public boolean checkBuildDate() {
|
||||
return this.getSettingAsBoolean("otas", "checkBuildDate", false);
|
||||
}
|
||||
|
||||
public DbObject getFiles() {
|
||||
return this.files;
|
||||
}
|
||||
|
||||
public void setFiles(DbObject files) {
|
||||
this.files = files;
|
||||
}
|
||||
|
||||
public DbObject getProgress() {
|
||||
return this.progress;
|
||||
}
|
||||
|
||||
public void setProgress(DbObject progress) {
|
||||
this.progress = progress;
|
||||
}
|
||||
|
||||
public DbObject getReference() {
|
||||
return this.reference;
|
||||
}
|
||||
|
||||
public void setReference(DbObject reference) {
|
||||
this.reference = reference;
|
||||
}
|
||||
|
||||
public void setReference(String key, Object data) {
|
||||
if (data == null) {
|
||||
if (this.reference != null) {
|
||||
this.reference.remove(key);
|
||||
}
|
||||
} else if (this.reference == null) {
|
||||
this.reference = new DbObject(key, data);
|
||||
} else {
|
||||
this.reference.put(key, data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void unsetDateTimeSettings() {
|
||||
DbObject settings = this.getSettingsCategory(new String[]{"system", "dateTime"});
|
||||
if (settings != null) {
|
||||
if (settings.containsKey("hourFormat")) {
|
||||
settings.remove("hourFormat");
|
||||
}
|
||||
|
||||
if (settings.size() > 0) {
|
||||
this.setSetting("system", "dateTime", settings);
|
||||
} else {
|
||||
this.setSetting("system", "dateTime", (Object)null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void convertCustomSettingsForDevice() {
|
||||
String[] categories = new String[]{"systemProperties", "globalSettings", "systemSettings", "secureSettings"};
|
||||
|
||||
for(String category : categories) {
|
||||
Object settingValue = this.getSetting(category);
|
||||
if (settingValue instanceof List) {
|
||||
List<? extends Map<String, ?>> settings = (List)this.getSetting(category);
|
||||
if (settings != null && !settings.isEmpty()) {
|
||||
DbObject newSettings = new DbObject();
|
||||
settings.forEach((item) -> newSettings.append((String)item.get("key"), item.get("value")));
|
||||
this.setSetting(category, newSettings);
|
||||
}
|
||||
} else if (settingValue instanceof DbObject) {
|
||||
this.setSetting(category, (UUID)null);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.getSettings().containsKey("midm")) {
|
||||
boolean reboot = this.getSettingsCategory(new String[]{"midm"}).getBoolean("reboot", true);
|
||||
DbObject systemSettings = this.getSettingsCategory(new String[]{"systemSettings"});
|
||||
if (systemSettings == null) {
|
||||
systemSettings = new DbObject();
|
||||
}
|
||||
|
||||
systemSettings.put("midmclient.reboot", Character.valueOf((char)(reboot ? '1' : '0')));
|
||||
} else if (this.settings.containsKey("otas") && (this.otas == null || this.otas.isEmpty())) {
|
||||
this.settings.remove("otas");
|
||||
this.otas = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean removeIfNoScope() {
|
||||
return this.getProfile().getBoolean("removeIfNoScope", false);
|
||||
}
|
||||
|
||||
public boolean unscopeIfApplied() {
|
||||
return this.getProfile().getBoolean("unscopeIfApplied", false);
|
||||
}
|
||||
|
||||
public void minify() {
|
||||
super.minify();
|
||||
this.deviceProfileGroup = null;
|
||||
this.scope = null;
|
||||
this.writerUuid = null;
|
||||
this.writer = null;
|
||||
}
|
||||
|
||||
public DeviceProfile clone() {
|
||||
return (DeviceProfile)McJsonUtils.clone(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.midm.model.device;
|
||||
|
||||
import com.midm.model.GeneralProfile;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class DeviceProfileGroup extends GeneralProfile {
|
||||
private UUID siteUuid;
|
||||
private UUID parentUuid;
|
||||
private Integer order;
|
||||
@Transient
|
||||
private Long deviceProfileNumbers;
|
||||
private List children;
|
||||
|
||||
public UUID getSiteUuid() {
|
||||
return this.siteUuid;
|
||||
}
|
||||
|
||||
public void setSiteUuid(UUID siteUuid) {
|
||||
this.siteUuid = siteUuid;
|
||||
}
|
||||
|
||||
public UUID getParentUuid() {
|
||||
return this.parentUuid;
|
||||
}
|
||||
|
||||
public void setParentUuid(UUID parentUuid) {
|
||||
this.parentUuid = parentUuid;
|
||||
}
|
||||
|
||||
public Integer getOrder() {
|
||||
return this.order;
|
||||
}
|
||||
|
||||
public void setOrder(Integer order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public Long getDeviceProfileNumbers() {
|
||||
return this.deviceProfileNumbers;
|
||||
}
|
||||
|
||||
public void setDeviceProfileNumbers(Long numbers) {
|
||||
this.deviceProfileNumbers = numbers;
|
||||
}
|
||||
|
||||
public List getChildren() {
|
||||
return this.children;
|
||||
}
|
||||
|
||||
public void setChildren(List children) {
|
||||
this.children = children;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
package com.midm.model.device;
|
||||
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
import org.springframework.data.mongodb.core.index.CompoundIndex;
|
||||
import org.springframework.data.mongodb.core.index.CompoundIndexes;
|
||||
import org.springframework.data.mongodb.core.index.Indexed;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
@CompoundIndexes({@CompoundIndex(
|
||||
def = "{'_id.deviceUuid': 1}"
|
||||
), @CompoundIndex(
|
||||
def = "{'_id.profileUuid': 1}"
|
||||
)})
|
||||
public class DeviceProfileState {
|
||||
public static final String STATE_IN_PROGRESS = "in_progress";
|
||||
public static final String STATE_DONE = "done";
|
||||
public static final String STATE_UNKNWON = "unknown";
|
||||
@Id
|
||||
private Scoped scoped;
|
||||
private long updated = -1L;
|
||||
@Indexed
|
||||
private String state = "unknown";
|
||||
private String applyFirstState = "unknown";
|
||||
@Indexed
|
||||
private long applied;
|
||||
@Transient
|
||||
private DeviceReport report;
|
||||
|
||||
public DeviceProfileState() {
|
||||
}
|
||||
|
||||
public DeviceProfileState(Device device, DeviceProfile profile) {
|
||||
this.scoped = new Scoped(profile.getUuid(), device.getUuid());
|
||||
this.updated = profile.getUpdated().getTime();
|
||||
this.applied = (new Date()).getTime();
|
||||
}
|
||||
|
||||
public DeviceProfileState(DeviceReport report) {
|
||||
this.setReport(report);
|
||||
}
|
||||
|
||||
public Scoped getScoped() {
|
||||
return this.scoped;
|
||||
}
|
||||
|
||||
public void setScoped(Scoped scoped) {
|
||||
this.scoped = scoped;
|
||||
}
|
||||
|
||||
public UUID getProfileUuid() {
|
||||
return this.getScoped().getProfileUuid();
|
||||
}
|
||||
|
||||
public UUID getDeviceUuid() {
|
||||
return this.getScoped().getDeviceUuid();
|
||||
}
|
||||
|
||||
public long getUpdated() {
|
||||
return this.updated;
|
||||
}
|
||||
|
||||
public void setUpdated(long updated) {
|
||||
this.updated = updated;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return this.state;
|
||||
}
|
||||
|
||||
public boolean isDone() {
|
||||
return this.state == null || this.state.equals("done");
|
||||
}
|
||||
|
||||
public void setState(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public String getApplyFirstState() {
|
||||
return this.applyFirstState;
|
||||
}
|
||||
|
||||
public boolean isApplyFirstDone() {
|
||||
return this.applyFirstState != null && this.applyFirstState.equals("done");
|
||||
}
|
||||
|
||||
public void setApplyFirstState(String applyFirstState) {
|
||||
this.applyFirstState = applyFirstState;
|
||||
}
|
||||
|
||||
public long getApplied() {
|
||||
return this.applied;
|
||||
}
|
||||
|
||||
public void setApplied(long applied) {
|
||||
this.applied = applied;
|
||||
this.setState("done");
|
||||
}
|
||||
|
||||
public void setApplied(long applied, String state) {
|
||||
this.state = state;
|
||||
this.applied = applied;
|
||||
}
|
||||
|
||||
public void setApplied() {
|
||||
this.applied = (new Date()).getTime();
|
||||
}
|
||||
|
||||
public DeviceReport getReport() {
|
||||
return this.report;
|
||||
}
|
||||
|
||||
public void setReport(DeviceReport report) {
|
||||
this.report = report;
|
||||
DbObject profile = report.getProperties().getDbObject(new String[]{"deviceProfile"});
|
||||
this.scoped = new Scoped(profile.getUuid("uuid"), report.getDeviceUuid());
|
||||
this.updated = profile.getLong("updated", -1L);
|
||||
this.applied = profile.getLong("applied", -1L);
|
||||
this.setState("done");
|
||||
}
|
||||
|
||||
public static class Scoped implements Serializable {
|
||||
private UUID profileUuid;
|
||||
private UUID deviceUuid;
|
||||
|
||||
public Scoped() {
|
||||
}
|
||||
|
||||
public Scoped(UUID profileUuid, UUID deviceUuid) {
|
||||
this.profileUuid = profileUuid;
|
||||
this.deviceUuid = deviceUuid;
|
||||
}
|
||||
|
||||
public UUID getProfileUuid() {
|
||||
return this.profileUuid;
|
||||
}
|
||||
|
||||
public void setProfileUuid(UUID profileUuid) {
|
||||
this.profileUuid = profileUuid;
|
||||
}
|
||||
|
||||
public UUID getDeviceUuid() {
|
||||
return this.deviceUuid;
|
||||
}
|
||||
|
||||
public void setDeviceUuid(UUID deviceUuid) {
|
||||
this.deviceUuid = deviceUuid;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
package com.midm.model.device;
|
||||
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import com.mitac.cell.utils.McJsonUtils;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
import org.springframework.data.mongodb.core.index.CompoundIndex;
|
||||
import org.springframework.data.mongodb.core.index.CompoundIndexes;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
/**
|
||||
* ======================================================================================
|
||||
* IoT 设备时序遥测上报数据模型 (DeviceReport)
|
||||
* ======================================================================================
|
||||
*
|
||||
* <p>【时序遥测存储与复合索引优化】
|
||||
* 1. 业务场景:
|
||||
* - 采集移动受控设备的动态遥测快照(GPS地理坐标、传感器数值、网络质量、策略生效版本等)。
|
||||
* 2. 【高并发时序复合索引】:
|
||||
* - `{'deviceUuid': 1, 'properties.location.time': -1}`:
|
||||
* 按设备维度按时间倒序快速检索设备的历史运动轨迹,支撑地理围栏(Geo-fencing)与电子地图回放;
|
||||
* - `{'properties.deviceProfile.uuid': 1, 'properties.deviceProfile.updated': 1}`:
|
||||
* 用于统计各策略配置(DeviceProfile)在设备上的下发与部署成功率。
|
||||
*
|
||||
* @author MiDM Core Platform Team
|
||||
*/
|
||||
@Document
|
||||
@CompoundIndexes({@CompoundIndex(
|
||||
def = "{'properties.deviceProfile.uuid':1, 'properties.deviceProfile.updated':1}"
|
||||
), @CompoundIndex(
|
||||
def = "{'deviceUuid':1, 'properties.location.time': -1}"
|
||||
)})
|
||||
public class DeviceReport {
|
||||
/** 报告记录全局主键 UUID */
|
||||
@Id
|
||||
private UUID uuid;
|
||||
|
||||
/** 关联的目标受控硬件主键 UUID */
|
||||
private UUID deviceUuid;
|
||||
|
||||
/** 临时字段:设备序列号 */
|
||||
@Transient
|
||||
private String serialNo;
|
||||
|
||||
/** 动态遥测属性字典(包含 GPS 坐标:properties.location.latitude / longitude 等) */
|
||||
private DbObject properties;
|
||||
|
||||
/** 终端边缘侧本地采样并生成该报文的时间戳 */
|
||||
private Date reportedAt;
|
||||
|
||||
/** 云端服务端持久化写入数据库的系统时间戳 */
|
||||
private Date recordedAt;
|
||||
|
||||
public DeviceReport() {
|
||||
this.setRecordedAt();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
this.setUuid(UUID.randomUUID());
|
||||
this.setReportedAt(new Date());
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
public void setUuid(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public UUID getDeviceUuid() {
|
||||
return this.deviceUuid;
|
||||
}
|
||||
|
||||
public void setDeviceUuid(UUID deviceUuid) {
|
||||
this.deviceUuid = deviceUuid;
|
||||
}
|
||||
|
||||
public String getSerialNo() {
|
||||
return this.serialNo;
|
||||
}
|
||||
|
||||
public void setSerialNo(String serialNo) {
|
||||
this.serialNo = serialNo;
|
||||
}
|
||||
|
||||
public boolean hasProperties() {
|
||||
return this.properties != null && !this.properties.isEmpty();
|
||||
}
|
||||
|
||||
public DbObject getProperties() {
|
||||
if (this.properties == null) {
|
||||
this.properties = new DbObject();
|
||||
}
|
||||
|
||||
return this.properties;
|
||||
}
|
||||
|
||||
public void setProperties(DbObject properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public Date getReportedAt() {
|
||||
return this.reportedAt;
|
||||
}
|
||||
|
||||
public void setReportedAt(Date reportedAt) {
|
||||
this.reportedAt = reportedAt;
|
||||
}
|
||||
|
||||
public Date getRecordedAt() {
|
||||
return this.recordedAt;
|
||||
}
|
||||
|
||||
public void setRecordedAt(Date recordedAt) {
|
||||
this.recordedAt = recordedAt;
|
||||
}
|
||||
|
||||
public void setRecordedAt() {
|
||||
this.recordedAt = new Date();
|
||||
}
|
||||
|
||||
public void setProperty(String key, Object val) {
|
||||
this.getProperties().append(key, val);
|
||||
}
|
||||
|
||||
public Object getProperty(String key) {
|
||||
return this.getProperties().get(key);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return McJsonUtils.toJson(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,289 @@
|
||||
package com.midm.model.device;
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.midm.model.file.AppFile;
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import com.mitac.cell.utils.McJsonUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
import org.springframework.data.mongodb.core.mapping.Field;
|
||||
|
||||
public class ProfileApps {
|
||||
private List install;
|
||||
@Transient
|
||||
@Expose(
|
||||
serialize = false
|
||||
)
|
||||
private List installApp;
|
||||
private List uninstall;
|
||||
@SerializedName("add_appwidget")
|
||||
@Field("add_appwidget")
|
||||
private List appWidget;
|
||||
private List widget;
|
||||
@SerializedName("grant_all")
|
||||
@Field("grant_all")
|
||||
private List grantAll;
|
||||
private List disabled;
|
||||
@SerializedName("wifi_only")
|
||||
@Field("wifi_only")
|
||||
private List wifiOnly;
|
||||
@SerializedName("white_list")
|
||||
@Field("white_list")
|
||||
private List whiteList;
|
||||
@SerializedName("black_list")
|
||||
@Field("black_list")
|
||||
private List blackList;
|
||||
|
||||
public List getInstall() {
|
||||
return this.install;
|
||||
}
|
||||
|
||||
public void setInstall(List install) {
|
||||
this.install = install;
|
||||
}
|
||||
|
||||
public void setToOldFormat() {
|
||||
this.install = this.getInstallUuids();
|
||||
}
|
||||
|
||||
public List getInstallApp() {
|
||||
if (this.installApp == null && this.install != null) {
|
||||
this.initInstallApp();
|
||||
}
|
||||
|
||||
return this.installApp;
|
||||
}
|
||||
|
||||
public void initInstallApp() {
|
||||
if (this.install != null && !this.install.isEmpty()) {
|
||||
if (this.install.get(0) instanceof InstallApp) {
|
||||
this.installApp = this.install;
|
||||
} else {
|
||||
this.installApp = (List)McJsonUtils.toObject(McJsonUtils.toJsonElement(this.install), (new TypeToken() {
|
||||
}).getType());
|
||||
this.install = this.installApp;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setInstallApp(List installApp) {
|
||||
this.installApp = installApp;
|
||||
}
|
||||
|
||||
public boolean hasInstallApps() {
|
||||
this.getInstallApp();
|
||||
return this.installApp != null && !this.installApp.isEmpty();
|
||||
}
|
||||
|
||||
public InstallApp getInstallApp(String packageName) {
|
||||
if (!this.hasInstallApps()) {
|
||||
return null;
|
||||
} else {
|
||||
for(InstallApp app : this.installApp) {
|
||||
if (packageName.equals(app.getPackageName())) {
|
||||
return app;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean removeInstallApp(UUID appUuid) {
|
||||
if (this.hasInstallApps()) {
|
||||
Iterator<InstallApp> it = this.installApp.iterator();
|
||||
|
||||
while(it.hasNext()) {
|
||||
if (((InstallApp)it.next()).uuid.equals(appUuid)) {
|
||||
it.remove();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public List getInstallUuids() {
|
||||
return this.installApp != null ? (List)this.installApp.stream().map((app) -> app.getUuid()).collect(Collectors.toList()) : null;
|
||||
}
|
||||
|
||||
public List getUninstall() {
|
||||
return this.toDbList(this.uninstall);
|
||||
}
|
||||
|
||||
public void setUninstall(List uninstall) {
|
||||
this.uninstall = uninstall;
|
||||
}
|
||||
|
||||
public List getAppWidget() {
|
||||
return this.appWidget;
|
||||
}
|
||||
|
||||
public void setAppWidget(List addAppWidget) {
|
||||
this.appWidget = addAppWidget;
|
||||
}
|
||||
|
||||
public List getWidget() {
|
||||
return this.widget;
|
||||
}
|
||||
|
||||
public void setWidget(List widget) {
|
||||
this.widget = widget;
|
||||
}
|
||||
|
||||
public List getGrantAll() {
|
||||
return this.toDbList(this.grantAll);
|
||||
}
|
||||
|
||||
public void setGrantAll(List grantAll) {
|
||||
this.grantAll = grantAll;
|
||||
}
|
||||
|
||||
public List getDisabled() {
|
||||
return this.toDbList(this.disabled);
|
||||
}
|
||||
|
||||
public void setDisabled(List disabled) {
|
||||
this.disabled = disabled;
|
||||
}
|
||||
|
||||
public List getWifiOnly() {
|
||||
return this.toDbList(this.wifiOnly);
|
||||
}
|
||||
|
||||
public void setWifiOnly(List wifiOnly) {
|
||||
this.wifiOnly = wifiOnly;
|
||||
}
|
||||
|
||||
public List getWhiteList() {
|
||||
return this.toDbList(this.whiteList);
|
||||
}
|
||||
|
||||
public void setWhiteList(List whiteList) {
|
||||
this.whiteList = whiteList;
|
||||
}
|
||||
|
||||
public List getBlackList() {
|
||||
return this.toDbList(this.blackList);
|
||||
}
|
||||
|
||||
public void setBlackList(List blackList) {
|
||||
this.blackList = blackList;
|
||||
}
|
||||
|
||||
public List getPackageList(List apps) {
|
||||
return apps != null ? (List)apps.stream().map((app) -> app.getString("package")).collect(Collectors.toList()) : null;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return (this.install == null || this.install.isEmpty()) && (this.uninstall == null || this.uninstall.isEmpty()) && (this.appWidget == null || this.appWidget.isEmpty()) && (this.widget == null || this.widget.isEmpty()) && (this.grantAll == null || this.grantAll.isEmpty()) && (this.disabled == null || this.disabled.isEmpty()) && (this.wifiOnly == null || this.wifiOnly.isEmpty()) && (this.whiteList == null || this.whiteList.isEmpty()) && (this.blackList == null || this.blackList.isEmpty());
|
||||
}
|
||||
|
||||
private List toDbList(List list) {
|
||||
if (list != null && !list.isEmpty()) {
|
||||
List<DbObject> dbList = new ArrayList();
|
||||
list.forEach((item) -> {
|
||||
if (item instanceof DbObject) {
|
||||
dbList.add((DbObject)item);
|
||||
} else if (item instanceof Map) {
|
||||
dbList.add(new DbObject((Map)item));
|
||||
}
|
||||
|
||||
});
|
||||
return dbList;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class InstallApp {
|
||||
private UUID uuid;
|
||||
private String packageName;
|
||||
@SerializedName("silent_install")
|
||||
@Field("silent_install")
|
||||
private Boolean silentInstall = true;
|
||||
@SerializedName("grant_all")
|
||||
@Field("grant_all")
|
||||
private Boolean grantAll = false;
|
||||
@SerializedName("starts_on_update")
|
||||
@Field("starts_on_update")
|
||||
private Boolean startsOnUpdate = false;
|
||||
@SerializedName("reboots_on_update")
|
||||
@Field("reboots_on_update")
|
||||
private Boolean rebootsOnUpdate = false;
|
||||
|
||||
public InstallApp() {
|
||||
}
|
||||
|
||||
public InstallApp(AppFile appFile) {
|
||||
this.uuid = appFile.getFileUuid();
|
||||
this.packageName = appFile.getPackageName();
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
public void setUuid(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public String getPackageName() {
|
||||
return this.packageName;
|
||||
}
|
||||
|
||||
public void setPackageName(String packageName) {
|
||||
this.packageName = packageName;
|
||||
}
|
||||
|
||||
public Boolean getSilentInstall() {
|
||||
return this.silentInstall;
|
||||
}
|
||||
|
||||
public void setSilentInstall(Boolean silentInstall) {
|
||||
this.silentInstall = silentInstall;
|
||||
}
|
||||
|
||||
public Boolean getGrantAll() {
|
||||
return this.grantAll;
|
||||
}
|
||||
|
||||
public void setGrantAll(Boolean grantAll) {
|
||||
this.grantAll = grantAll;
|
||||
}
|
||||
|
||||
public Boolean getStartsOnUpdate() {
|
||||
return this.startsOnUpdate;
|
||||
}
|
||||
|
||||
public void setStartsOnUpdate(Boolean startsOnUpdate) {
|
||||
this.startsOnUpdate = startsOnUpdate;
|
||||
}
|
||||
|
||||
public Boolean getRebootsOnUpdate() {
|
||||
return this.rebootsOnUpdate;
|
||||
}
|
||||
|
||||
public void setRebootsOnUpdate(Boolean rebootsOnUpdate) {
|
||||
this.rebootsOnUpdate = rebootsOnUpdate;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof InstallApp)) {
|
||||
return false;
|
||||
} else {
|
||||
InstallApp installApp = (InstallApp)obj;
|
||||
return this.uuid.equals(installApp.uuid) && this.packageName.equals(installApp.packageName) && this.silentInstall == installApp.silentInstall && this.grantAll == installApp.grantAll && this.startsOnUpdate == installApp.startsOnUpdate && this.rebootsOnUpdate == installApp.rebootsOnUpdate;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.midm.model.device;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ProfileScope {
|
||||
Set group;
|
||||
Set device;
|
||||
Set userGroup;
|
||||
|
||||
public Set getGroup() {
|
||||
return this.group;
|
||||
}
|
||||
|
||||
public void setGroup(Set group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
public void addGroup(UUID groupUuid) {
|
||||
if (this.group == null) {
|
||||
this.group = new HashSet();
|
||||
this.group.add(groupUuid);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void removeGroup(UUID groupUuid) {
|
||||
if (this.group != null) {
|
||||
this.group.remove(groupUuid);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Set getDevice() {
|
||||
return this.device;
|
||||
}
|
||||
|
||||
public void setDevice(Set device) {
|
||||
this.device = device;
|
||||
}
|
||||
|
||||
public void addDevice(String serialNo) {
|
||||
if (this.device == null) {
|
||||
this.device = new HashSet();
|
||||
this.device.add(serialNo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void removeDevice(String serialNo) {
|
||||
if (this.device != null) {
|
||||
this.device.remove(serialNo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Set getUserGroup() {
|
||||
return this.userGroup;
|
||||
}
|
||||
|
||||
public void setUserGroup(Set userGroup) {
|
||||
this.userGroup = userGroup;
|
||||
}
|
||||
|
||||
public boolean hasScoped() {
|
||||
return this.group != null && !this.group.isEmpty() || this.device != null && !this.device.isEmpty() || this.userGroup != null && !this.userGroup.isEmpty();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
package com.midm.model.device;
|
||||
|
||||
import com.midm.model.org.User;
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import java.util.Date;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
import org.joda.time.LocalDateTime;
|
||||
|
||||
public class ReconnectMonitor {
|
||||
private static final int BLOCKING_HOURS = 12;
|
||||
private static final int RECONNECT_FOR = 10;
|
||||
private Device device;
|
||||
private Date startedAt;
|
||||
private long prevMins;
|
||||
private int count;
|
||||
private int total;
|
||||
private Date blockedAt;
|
||||
private Date unblockAt;
|
||||
private Timer unblockTimer;
|
||||
private OnAbusedListener listener;
|
||||
|
||||
public ReconnectMonitor(Device device, OnAbusedListener listener) {
|
||||
this.device = device;
|
||||
this.listener = listener;
|
||||
this.init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
this.startedAt = new Date();
|
||||
this.blockedAt = null;
|
||||
this.unblockAt = null;
|
||||
this.prevMins = this.getCurMins();
|
||||
this.total = this.count = 1;
|
||||
}
|
||||
|
||||
public Device getDevice() {
|
||||
return this.device;
|
||||
}
|
||||
|
||||
public UUID getDeviceUuid() {
|
||||
return this.device.getUuid();
|
||||
}
|
||||
|
||||
public Date getStartedAt() {
|
||||
return this.startedAt;
|
||||
}
|
||||
|
||||
public Date getBlockedAt() {
|
||||
return this.blockedAt;
|
||||
}
|
||||
|
||||
public Date getUnblockAt() {
|
||||
return this.unblockAt;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return this.count;
|
||||
}
|
||||
|
||||
public int getTotal() {
|
||||
return this.total;
|
||||
}
|
||||
|
||||
public void connected() {
|
||||
long curMins = this.getCurMins();
|
||||
long gap = curMins - this.prevMins;
|
||||
if (gap <= 1L) {
|
||||
++this.total;
|
||||
if (gap == 1L) {
|
||||
++this.count;
|
||||
this.prevMins = curMins;
|
||||
if (this.count >= 10) {
|
||||
this.blockedAt = new Date();
|
||||
this.onAbused();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.init();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean isBlocked() {
|
||||
return this.blockedAt != null;
|
||||
}
|
||||
|
||||
public void block() {
|
||||
this.blockedAt = new Date();
|
||||
this.unblockAt = (new LocalDateTime(this.blockedAt)).plusHours(12).withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0).toDate();
|
||||
this.startUnblockTimer();
|
||||
}
|
||||
|
||||
public void block(Device device) {
|
||||
if (device.isBlocked()) {
|
||||
DbObject blockedState = device.getStates().getDbObject(new String[]{"blocked"});
|
||||
this.blockedAt = blockedState.getDate("from");
|
||||
this.unblockAt = blockedState.getDate("to");
|
||||
if (this.unblockAt.getTime() < (new Date()).getTime()) {
|
||||
this.unblock((User)null);
|
||||
} else {
|
||||
this.startUnblockTimer();
|
||||
}
|
||||
} else {
|
||||
this.block();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void startUnblockTimer() {
|
||||
this.stopUnblockTimer();
|
||||
String var10003 = this.device.getUuid().toString();
|
||||
this.unblockTimer = new Timer(var10003 + (new Date()).getTime());
|
||||
this.unblockTimer.schedule(new TimerTask() {
|
||||
public void run() {
|
||||
ReconnectMonitor.this.unblock((User)null);
|
||||
}
|
||||
}, this.unblockAt);
|
||||
}
|
||||
|
||||
private void stopUnblockTimer() {
|
||||
if (this.unblockTimer != null) {
|
||||
try {
|
||||
this.unblockTimer.cancel();
|
||||
this.unblockTimer.purge();
|
||||
this.unblockTimer = null;
|
||||
} catch (Exception var2) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void unblock(User user) {
|
||||
this.stopUnblockTimer();
|
||||
this.startedAt = null;
|
||||
this.blockedAt = null;
|
||||
this.unblockAt = null;
|
||||
this.prevMins = 0L;
|
||||
this.total = this.count = 0;
|
||||
if (this.listener != null) {
|
||||
this.listener.onUnblocked(this, user);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void onAbused() {
|
||||
this.block();
|
||||
if (this.listener != null) {
|
||||
this.listener.onAbused(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private long getCurMins() {
|
||||
return (new Date()).getTime() / 60000L;
|
||||
}
|
||||
|
||||
public interface OnAbusedListener {
|
||||
void onAbused(ReconnectMonitor monitor);
|
||||
|
||||
void onUnblocked(ReconnectMonitor monitor, User user);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
package com.midm.model.file;
|
||||
|
||||
import com.google.api.client.util.Strings;
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.midm.model.org.User;
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import com.mitac.cell.io.McApkFile;
|
||||
import com.mitac.cell.io.McFile;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import net.dongliu.apk.parser.bean.ApkMeta;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class AppFile extends BaseFile {
|
||||
private DbObject appInfo;
|
||||
private DbObject updateOptions;
|
||||
@Transient
|
||||
@Expose(
|
||||
serialize = false
|
||||
)
|
||||
private boolean generateIcon;
|
||||
|
||||
public AppFile() {
|
||||
this.generateIcon = true;
|
||||
}
|
||||
|
||||
public AppFile(User user, UUID fileUuid, McFile file) {
|
||||
this(user, fileUuid, file, true);
|
||||
}
|
||||
|
||||
public AppFile(User user, UUID fileUuid, McFile file, boolean generateIcon) {
|
||||
super(user, fileUuid, file);
|
||||
this.generateIcon = true;
|
||||
this.generateIcon = generateIcon;
|
||||
this.setAppInfo(file);
|
||||
}
|
||||
|
||||
public boolean isApk() {
|
||||
return !Strings.isNullOrEmpty(this.getPackageName());
|
||||
}
|
||||
|
||||
public boolean hasSystemPermission() {
|
||||
return "android.uid.system".equals(this.getSharedUserId());
|
||||
}
|
||||
|
||||
public DbObject getAppInfo() {
|
||||
if (this.appInfo == null) {
|
||||
this.appInfo = new DbObject();
|
||||
}
|
||||
|
||||
return this.appInfo;
|
||||
}
|
||||
|
||||
public void setAppInfo(DbObject appInfo) {
|
||||
this.appInfo = appInfo;
|
||||
}
|
||||
|
||||
public void setAppInfo(String key, Object value) {
|
||||
this.getAppInfo().append(key, value);
|
||||
}
|
||||
|
||||
public DbObject getUpdateOptions() {
|
||||
if (this.updateOptions == null) {
|
||||
this.updateOptions = new DbObject();
|
||||
}
|
||||
|
||||
return this.updateOptions;
|
||||
}
|
||||
|
||||
public void setUpdateOptions(DbObject updateOptions) {
|
||||
this.updateOptions = updateOptions;
|
||||
}
|
||||
|
||||
public void setUpdateOptions(String key, Object value) {
|
||||
this.getUpdateOptions().append(key, value);
|
||||
}
|
||||
|
||||
public boolean isMitacApp() {
|
||||
return this.getPackageName().toLowerCase().contains("mitac");
|
||||
}
|
||||
|
||||
public String getPackageName() {
|
||||
return this.getAppInfo().getString("packageName");
|
||||
}
|
||||
|
||||
public void setPackageName(String packageName) {
|
||||
this.setAppInfo("packageName", packageName);
|
||||
}
|
||||
|
||||
public String getSharedUserId() {
|
||||
return this.getAppInfo().getString("sharedUid");
|
||||
}
|
||||
|
||||
public void setSharedUserId(String sharedUid) {
|
||||
if (!Strings.isNullOrEmpty(sharedUid)) {
|
||||
this.setAppInfo("sharedUid", sharedUid);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return this.getAppInfo().getString("label");
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.setAppInfo("label", label);
|
||||
}
|
||||
|
||||
public String getIconName() {
|
||||
return this.getAppInfo().getString("iconName");
|
||||
}
|
||||
|
||||
public void setIconName(String iconName) {
|
||||
this.setAppInfo("iconName", iconName);
|
||||
}
|
||||
|
||||
public long getVersionCode() {
|
||||
return this.getAppInfo().getLong("versionCode");
|
||||
}
|
||||
|
||||
public void setVersionCode(long versionCode) {
|
||||
this.setAppInfo("versionCode", versionCode);
|
||||
}
|
||||
|
||||
public String getVersionName() {
|
||||
return this.getAppInfo().getString("versionName");
|
||||
}
|
||||
|
||||
public void setVersionName(String versionName) {
|
||||
this.setAppInfo("versionName", versionName);
|
||||
}
|
||||
|
||||
public int getMinSdkVersion() {
|
||||
return this.getAppInfo().getInteger("minSdkVersion", -1);
|
||||
}
|
||||
|
||||
public void setMinSdkVersion(String minSdkVersion) {
|
||||
if (!Strings.isNullOrEmpty(minSdkVersion)) {
|
||||
this.setMinSdkVersion(Integer.parseInt(minSdkVersion));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setMinSdkVersion(int minSdkVersion) {
|
||||
this.setAppInfo("minSdkVersion", minSdkVersion);
|
||||
}
|
||||
|
||||
public int getMaxSdkVersion() {
|
||||
return this.getAppInfo().getInteger("maxSdkVersion", -1);
|
||||
}
|
||||
|
||||
public void setMaxSdkVersion(String maxSdkVersion) {
|
||||
if (!Strings.isNullOrEmpty(maxSdkVersion)) {
|
||||
this.setAppInfo("maxSdkVersion", Integer.parseInt(maxSdkVersion));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int getTargetSdkVersion() {
|
||||
return this.getAppInfo().getInteger("targetSdkVersion", -1);
|
||||
}
|
||||
|
||||
public void setTargetSdkVersion(String targetSdkVersion) {
|
||||
if (Strings.isNullOrEmpty(targetSdkVersion)) {
|
||||
this.getAppInfo().remove("targetSdkVersion");
|
||||
} else {
|
||||
this.setAppInfo("targetSdkVersion", Integer.parseInt(targetSdkVersion));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public List getUserPermission() {
|
||||
return this.getAppInfo().getList("userPermission", String.class);
|
||||
}
|
||||
|
||||
public void setUserPermission(List userPermission) {
|
||||
this.setAppInfo("userPermission", userPermission);
|
||||
}
|
||||
|
||||
public String getCertMd5() {
|
||||
return this.getAppInfo().getString("certMd5");
|
||||
}
|
||||
|
||||
public void setCertMd5(String certMd5) {
|
||||
if (!Strings.isNullOrEmpty(certMd5)) {
|
||||
this.setAppInfo("certMd5", certMd5);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setAppInfo(McFile file) {
|
||||
try {
|
||||
McApkFile apkFile = new McApkFile(file);
|
||||
ApkMeta meta = apkFile.getApkMeta();
|
||||
this.setSharedUserId(meta.getSharedUserId());
|
||||
this.setPackageName(meta.getPackageName());
|
||||
String label = meta.getLabel();
|
||||
if (Strings.isNullOrEmpty(label)) {
|
||||
label = meta.getPackageName();
|
||||
}
|
||||
|
||||
this.setLabel(label);
|
||||
this.setVersionCode(meta.getVersionCode());
|
||||
this.setVersionName(meta.getVersionName());
|
||||
this.setUserPermission(meta.getUsesPermissions());
|
||||
this.setMinSdkVersion(meta.getMinSdkVersion());
|
||||
this.setMaxSdkVersion(meta.getMaxSdkVersion());
|
||||
this.setTargetSdkVersion(meta.getTargetSdkVersion());
|
||||
this.setCertMd5(apkFile.getCertMd5());
|
||||
this.setName(this.getLabel());
|
||||
if (this.generateIcon) {
|
||||
apkFile.saveIcon(file.getPath() + ".png");
|
||||
}
|
||||
|
||||
apkFile.close();
|
||||
} catch (Exception var5) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void minify() {
|
||||
super.minify();
|
||||
this.setUserPermission((List)null);
|
||||
this.setTargetSdkVersion((String)null);
|
||||
this.setVersionName((String)null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,279 @@
|
||||
package com.midm.model.file;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.midm.model.org.User;
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import com.mitac.cell.io.McFile;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import org.apache.tika.Tika;
|
||||
import org.joda.time.LocalDateTime;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.index.Indexed;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class BaseFile {
|
||||
@Id
|
||||
protected UUID fileUuid;
|
||||
protected UUID userUuid;
|
||||
@Indexed
|
||||
protected UUID siteUuid;
|
||||
protected DbObject fileInfo;
|
||||
protected DbObject extra;
|
||||
protected String name;
|
||||
protected boolean enabled = true;
|
||||
protected Date lastUpdated;
|
||||
protected Date registeredAt;
|
||||
|
||||
public BaseFile() {
|
||||
}
|
||||
|
||||
public BaseFile(User user, UUID fileUuid, McFile file) {
|
||||
this.setUserUuid(user);
|
||||
this.setFileUuid(fileUuid);
|
||||
this.setFileInfo(file);
|
||||
this.initRegisteredAt();
|
||||
}
|
||||
|
||||
public UUID getSiteUuid() {
|
||||
return this.siteUuid;
|
||||
}
|
||||
|
||||
public void setSiteUuid(UUID siteUuid) {
|
||||
this.siteUuid = siteUuid;
|
||||
}
|
||||
|
||||
public UUID getFileUuid() {
|
||||
return this.fileUuid;
|
||||
}
|
||||
|
||||
public void setFileUuid(UUID uid) {
|
||||
this.fileUuid = uid;
|
||||
}
|
||||
|
||||
public UUID getUserUuid() {
|
||||
return this.userUuid;
|
||||
}
|
||||
|
||||
public void setUserUuid(UUID uid) {
|
||||
this.userUuid = uid;
|
||||
}
|
||||
|
||||
public void setUserUuid(User user) {
|
||||
if (user != null) {
|
||||
this.userUuid = user.getUuid();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public DbObject getFileInfo() {
|
||||
if (this.fileInfo == null) {
|
||||
this.fileInfo = new DbObject();
|
||||
}
|
||||
|
||||
return this.fileInfo;
|
||||
}
|
||||
|
||||
public String getFileInfoAsString(String key) {
|
||||
if (this.fileInfo == null) {
|
||||
this.fileInfo = new DbObject();
|
||||
}
|
||||
|
||||
return this.fileInfo.getString(key);
|
||||
}
|
||||
|
||||
public void removeFileInfo() {
|
||||
this.fileInfo = null;
|
||||
}
|
||||
|
||||
public void setFileInfo(DbObject fileInfo) {
|
||||
this.fileInfo = fileInfo;
|
||||
}
|
||||
|
||||
public void setFileInfo(McFile file) {
|
||||
if (file.exists()) {
|
||||
this.setLength(file.length());
|
||||
this.setChecksum(file.getCrcChecksum());
|
||||
this.setLastModified(file.lastModified());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public DbObject getExtra() {
|
||||
return this.extra;
|
||||
}
|
||||
|
||||
public void setExtra(DbObject extra) {
|
||||
this.extra = extra;
|
||||
}
|
||||
|
||||
public void setExtra(Map parameters) {
|
||||
if (parameters != null) {
|
||||
if (this.extra == null) {
|
||||
this.extra = new DbObject();
|
||||
}
|
||||
|
||||
parameters.forEach((key, value) -> {
|
||||
if (value.length > 0 && key.startsWith("extra.")) {
|
||||
this.extra.put(key.substring(6), value.length == 1 ? value[0] : Arrays.asList(value));
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean getEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return this.getFileInfo().getString("fileName");
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.setFileInfo("fileName", fileName);
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
String contentType = this.getFileInfo().getString("contentType");
|
||||
if (Strings.isNullOrEmpty(contentType)) {
|
||||
contentType = (new Tika()).detect(this.getFileName());
|
||||
this.setType(contentType);
|
||||
}
|
||||
|
||||
return contentType;
|
||||
}
|
||||
|
||||
public void setType(String contentType) {
|
||||
this.setFileInfo("contentType", contentType);
|
||||
}
|
||||
|
||||
public long getLength() {
|
||||
return this.getFileInfo().getLong("length");
|
||||
}
|
||||
|
||||
public void setLength(long length) {
|
||||
this.setFileInfo("length", length);
|
||||
}
|
||||
|
||||
public long getChecksum() {
|
||||
return this.getFileInfo().getLong("checksum");
|
||||
}
|
||||
|
||||
public void setChecksum(long checksum) {
|
||||
this.setFileInfo("checksum", checksum);
|
||||
}
|
||||
|
||||
public long getLastModified() {
|
||||
return this.getFileInfo().getLong("lastModified");
|
||||
}
|
||||
|
||||
public void setLastModified(long lastModified) {
|
||||
if (lastModified <= 0L) {
|
||||
lastModified = (new Date()).getTime();
|
||||
}
|
||||
|
||||
this.setFileInfo("lastModified", lastModified);
|
||||
}
|
||||
|
||||
public void setFileInfo(String key, Object value) {
|
||||
this.getFileInfo().append(key, value);
|
||||
}
|
||||
|
||||
public void setFileUrl(String url) {
|
||||
this.setFileInfo("fileUrl", url);
|
||||
}
|
||||
|
||||
public long getUrlExpiry() {
|
||||
Date expiry = this.getFileInfo().getDate("urlExpiry");
|
||||
return expiry == null ? -1L : expiry.getTime();
|
||||
}
|
||||
|
||||
public void setCloudUrl(String url) {
|
||||
this.setFileInfo("fileUrl", url);
|
||||
Date expiry = LocalDateTime.now().plusDays(6).toDate();
|
||||
this.setFileInfo("urlExpiry", expiry);
|
||||
}
|
||||
|
||||
public boolean hasFileUrl() {
|
||||
boolean hasUrl = this.getFileInfo().containsKey("fileUrl");
|
||||
if (hasUrl && this.getFileInfo().containsKey("urlExpiry")) {
|
||||
hasUrl = this.getFileInfo().getDate("urlExpiry").after(new Date());
|
||||
if (!hasUrl) {
|
||||
this.getFileInfo().remove("fileUrl");
|
||||
this.getFileInfo().remove("urlExpiry");
|
||||
}
|
||||
}
|
||||
|
||||
return hasUrl;
|
||||
}
|
||||
|
||||
public String getFileUrl() {
|
||||
return this.getFileInfoAsString("fileUrl");
|
||||
}
|
||||
|
||||
public boolean hasIconUrl() {
|
||||
boolean hasUrl = this.getFileInfo().containsKey("iconUrl");
|
||||
if (hasUrl && this.getFileInfo().containsKey("iconExpiry")) {
|
||||
hasUrl = this.getFileInfo().getDate("iconExpiry").after(new Date());
|
||||
if (!hasUrl) {
|
||||
this.getFileInfo().remove("iconUrl");
|
||||
this.getFileInfo().remove("iconExpiry");
|
||||
}
|
||||
}
|
||||
|
||||
return hasUrl;
|
||||
}
|
||||
|
||||
public void setIconUrl(String url) {
|
||||
this.setFileInfo("iconUrl", url);
|
||||
Date expiry = LocalDateTime.now().plusDays(6).toDate();
|
||||
this.setFileInfo("iconExpiry", expiry);
|
||||
}
|
||||
|
||||
public String getIconUrl() {
|
||||
return this.getFileInfoAsString("iconUrl");
|
||||
}
|
||||
|
||||
public Date getLastUpdated() {
|
||||
return this.lastUpdated;
|
||||
}
|
||||
|
||||
public void setLastUpdated(Date lastUpdated) {
|
||||
this.lastUpdated = lastUpdated;
|
||||
}
|
||||
|
||||
public Date getRegisteredAt() {
|
||||
return this.registeredAt;
|
||||
}
|
||||
|
||||
public void setRegisteredAt(Date registeredAt) {
|
||||
this.registeredAt = registeredAt;
|
||||
}
|
||||
|
||||
public void initRegisteredAt() {
|
||||
this.setRegisteredAt(new Date());
|
||||
this.setLastUpdated(this.getRegisteredAt());
|
||||
}
|
||||
|
||||
public void minify() {
|
||||
this.userUuid = null;
|
||||
this.registeredAt = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.midm.model.file;
|
||||
|
||||
public class DeployOption {
|
||||
public static final String PROPERTY_DEFAULT = "default";
|
||||
public static final String PROPERTY_FORCE_TO_DOWNLOAD = "force_to_download";
|
||||
public static final String PROPERTY_FORCE_TO_INSTALL = "force_to_install";
|
||||
public static final String PROPERTY_SAVE_AS = "save_as";
|
||||
public static final String PROPERTY_KEEP_BACKUP = "keep_backgup";
|
||||
private boolean isDefault;
|
||||
private boolean uninstallFirst;
|
||||
private boolean keepData;
|
||||
private boolean forceToDownload;
|
||||
private boolean foreceToInstall;
|
||||
private String saveTo;
|
||||
private boolean keepBackup;
|
||||
private boolean isUserMode;
|
||||
|
||||
public boolean getIsDefault() {
|
||||
return this.isDefault;
|
||||
}
|
||||
|
||||
public void setIsDefault(boolean isDefault) {
|
||||
this.isDefault = isDefault;
|
||||
}
|
||||
|
||||
public boolean getUninstallFirst() {
|
||||
return this.uninstallFirst;
|
||||
}
|
||||
|
||||
public void setUninstallFirst(boolean uninstallFirst) {
|
||||
this.uninstallFirst = uninstallFirst;
|
||||
}
|
||||
|
||||
public boolean getKeepData() {
|
||||
return this.keepData;
|
||||
}
|
||||
|
||||
public void setKeepData(boolean keepData) {
|
||||
this.keepData = keepData;
|
||||
}
|
||||
|
||||
public boolean getForceToDownload() {
|
||||
return this.forceToDownload;
|
||||
}
|
||||
|
||||
public void setForceToDownload(boolean forceToDownload) {
|
||||
this.forceToDownload = forceToDownload;
|
||||
}
|
||||
|
||||
public boolean getForeceToInstall() {
|
||||
return this.foreceToInstall;
|
||||
}
|
||||
|
||||
public void setForeceToInstall(boolean foreceToInstall) {
|
||||
this.foreceToInstall = foreceToInstall;
|
||||
}
|
||||
|
||||
public String getSaveTo() {
|
||||
return this.saveTo;
|
||||
}
|
||||
|
||||
public void setSaveTo(String saveTo) {
|
||||
this.saveTo = saveTo;
|
||||
}
|
||||
|
||||
public boolean getKeepBackup() {
|
||||
return this.keepBackup;
|
||||
}
|
||||
|
||||
public void setKeepBackup(boolean keepBackup) {
|
||||
this.keepBackup = keepBackup;
|
||||
}
|
||||
|
||||
public boolean getIsUserMode() {
|
||||
return this.isUserMode;
|
||||
}
|
||||
|
||||
public void setIsUserMode(boolean isUserMode) {
|
||||
this.isUserMode = isUserMode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.midm.model.file;
|
||||
|
||||
public enum FILE_TYPE {
|
||||
OTA,
|
||||
REGION,
|
||||
APK,
|
||||
FILE,
|
||||
UNKNOWN;
|
||||
}
|
||||
@@ -0,0 +1,784 @@
|
||||
package com.midm.model.file;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.midm.model.org.User;
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import com.mitac.cell.io.McFile;
|
||||
import com.mitac.cell.security.McOtaCert;
|
||||
import com.mitac.cell.utils.McJsonUtils;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.UUID;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
/**
|
||||
* ======================================================================================
|
||||
* Android / 嵌入式系统 OTA 固件镜像模型 (OtaFile)
|
||||
* ======================================================================================
|
||||
*
|
||||
* <p>【IoT 固件空中升级 (FOTA) 核心实现】
|
||||
* 1. 业务功能:
|
||||
* - 管理受控终端的完整系统固件镜像(System Image / Full OTA)与区域增量镜像(Region Image / Incremental OTA)。
|
||||
* 2. 【固件安全与包结构解析】:
|
||||
* - 自动解包并解析 Android Recovery 规范的标准固件 ZIP 包结构:
|
||||
* - `META-INF/com/google/android/updater-script`: 固件升级执行脚本;
|
||||
* - `system/build.prop`: 提取目标硬件型号、Android 操作系统版本、编译日期(build_date)、基带版本等;
|
||||
* - `META-INF/com/android/otacert`: 嵌入式固件发布签名证书,校验固件是否由官方私钥签发;
|
||||
* - `META-INF/com/android/metadata`: 提取差分升级的前置版本与兼容约束。
|
||||
* 3. 硬件兼容性矩阵(SKU Matching):
|
||||
* - 严格匹配终端出厂 SKU,防止跨机型错刷固件导致设备“变砖”(Bricking)。
|
||||
*
|
||||
* @author MiDM Core Platform Team
|
||||
*/
|
||||
@Document
|
||||
public class OtaFile extends BaseFile implements Comparable {
|
||||
/** Android Recovery 固件升级脚本入口 */
|
||||
private static final String ENTRY_META_INF = "META-INF/com/";
|
||||
private static final String ENTRY_UPDATE_SCRIPT = "META-INF/com/google/android/updater-script";
|
||||
|
||||
/** Android 操作系统属性字典路径(包含型号、Build版本、指纹等关键参数) */
|
||||
private static final String ENTRY_BUILD_PROP = "system/build.prop";
|
||||
|
||||
/** 固件合法性验签 X.509 官方证书路径 */
|
||||
private static final String ENTRY_OTA_CERT = "META-INF/com/android/otacert";
|
||||
|
||||
/** OTA 元数据配置文件(版本区间、差分基线版本等) */
|
||||
private static final String ENTRY_METADATA = "META-INF/com/android/metadata";
|
||||
private static final String ENTRY_UPDATE_INFO = "META-INF/com/android/update_info";
|
||||
|
||||
/** 解析固件包后提取的硬件规格与构建元数据字典 */
|
||||
private DbObject otaInfo;
|
||||
|
||||
public OtaFile() {
|
||||
}
|
||||
|
||||
public OtaFile(User user, UUID fileUuid, McFile file) {
|
||||
super(user, fileUuid, file);
|
||||
this.setOtaInfo(file);
|
||||
}
|
||||
|
||||
public boolean isOtaImage() {
|
||||
if (Strings.isNullOrEmpty(this.getProductId()) && Strings.isNullOrEmpty(this.getDeviceId())) {
|
||||
return false;
|
||||
} else {
|
||||
return this.isRegionImage() ? true : !Strings.isNullOrEmpty(this.getSkuId());
|
||||
}
|
||||
}
|
||||
|
||||
public DbObject getOtaInfo() {
|
||||
if (this.otaInfo == null) {
|
||||
this.otaInfo = new DbObject();
|
||||
}
|
||||
|
||||
return this.otaInfo;
|
||||
}
|
||||
|
||||
public void setOtaInfo(DbObject otaInfo) {
|
||||
this.otaInfo = otaInfo;
|
||||
}
|
||||
|
||||
public void setOtaInfo(String key, Object value) {
|
||||
this.getOtaInfo().append(key, value);
|
||||
}
|
||||
|
||||
public void setOtaInfo(McFile file) {
|
||||
try {
|
||||
this.retrieveBuildInfo(new ZipFile(file));
|
||||
} catch (Exception var3) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return this.getOtaInfo().getString("type", "system");
|
||||
}
|
||||
|
||||
public boolean isSystemImage() {
|
||||
return this.getType().equals("system");
|
||||
}
|
||||
|
||||
public boolean isRegionImage() {
|
||||
return this.getType().equals("region");
|
||||
}
|
||||
|
||||
public boolean isModemImage() {
|
||||
return this.getType().equals("modem");
|
||||
}
|
||||
|
||||
public boolean isAbUpdate() {
|
||||
return this.getOtaInfo().getBoolean("abUpdate", false);
|
||||
}
|
||||
|
||||
public boolean isPartial() {
|
||||
return this.getOtaInfo().containsKey("preBuild");
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
if (type.toLowerCase().equals("base")) {
|
||||
type = "system";
|
||||
}
|
||||
|
||||
this.getOtaInfo().put("type", type);
|
||||
}
|
||||
|
||||
public void setAbUpdate(boolean abUpdate) {
|
||||
this.getOtaInfo().put("abUpdate", abUpdate);
|
||||
}
|
||||
|
||||
public long getBuildDate() {
|
||||
return this.getOtaInfo().getLong("buildDate", -1L);
|
||||
}
|
||||
|
||||
public void setBuildDate(long date) {
|
||||
this.setOtaInfo("buildDate", date);
|
||||
}
|
||||
|
||||
public int getSdkLevel() {
|
||||
return this.getOtaInfo().getInteger("sdk", -1);
|
||||
}
|
||||
|
||||
public void setSdkLevel(int level) {
|
||||
this.setOtaInfo("sdk", level);
|
||||
}
|
||||
|
||||
public long getPostBuildDate() {
|
||||
return this.getOtaInfo().getLong("postBuildDate", -1L);
|
||||
}
|
||||
|
||||
public void setPostBuildDate(long date) {
|
||||
this.setOtaInfo("postBuildDate", date);
|
||||
}
|
||||
|
||||
public String getProductId() {
|
||||
return this.getOtaInfo().getString("productId");
|
||||
}
|
||||
|
||||
public void setProductId(String productId) {
|
||||
this.setOtaInfo("productId", productId);
|
||||
}
|
||||
|
||||
public String getTargetProduct() {
|
||||
return this.getOtaInfo().getString("targetProduct");
|
||||
}
|
||||
|
||||
public void setTargetProduct(String productId) {
|
||||
this.setOtaInfo("targetProduct", productId);
|
||||
}
|
||||
|
||||
public String getSkuId() {
|
||||
return this.getOtaInfo().getString("skuId");
|
||||
}
|
||||
|
||||
public void setSkuId(String skuId) {
|
||||
this.setOtaInfo("skuId", skuId);
|
||||
}
|
||||
|
||||
public boolean hasCompatibleSkuIds() {
|
||||
List<String> ids = this.getOtaInfo().getList("compatibleSkuIds", String.class);
|
||||
return ids != null && ids.size() > 0;
|
||||
}
|
||||
|
||||
public List getCompatibleSkuIds() {
|
||||
return this.getOtaInfo().getList("compatibleSkuIds", String.class);
|
||||
}
|
||||
|
||||
public boolean isCompatibleSkuId(String skuId) {
|
||||
if (Strings.isNullOrEmpty(skuId)) {
|
||||
return false;
|
||||
} else {
|
||||
String curSkuId = this.getSkuId();
|
||||
if (skuId.equals(curSkuId)) {
|
||||
return true;
|
||||
} else {
|
||||
List<String> compatibleSkuIds = this.getCompatibleSkuIds();
|
||||
return compatibleSkuIds != null && compatibleSkuIds.contains(skuId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setCompatibleSkuIds(String skuIds) {
|
||||
if (!Strings.isNullOrEmpty(skuIds)) {
|
||||
String[] ids = skuIds.split("\\s*,\\s*");
|
||||
if (ids != null && ids.length > 0) {
|
||||
this.setOtaInfo("compatibleSkuIds", Arrays.asList(ids));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String getDeviceId() {
|
||||
return this.getOtaInfo().getString("deviceId");
|
||||
}
|
||||
|
||||
public void setDeviceId(String deviceId) {
|
||||
this.setOtaInfo("deviceId", deviceId);
|
||||
}
|
||||
|
||||
public String getDisplayId() {
|
||||
return this.getOtaInfo().getString("displayId");
|
||||
}
|
||||
|
||||
public void setDisplayId(String displayId) {
|
||||
this.setOtaInfo("displayId", displayId);
|
||||
}
|
||||
|
||||
public void setProductDisplayId(String displayId) {
|
||||
this.setOtaInfo("productDisplayId", displayId);
|
||||
}
|
||||
|
||||
public String getPreDisplayId() {
|
||||
return this.getOtaInfo().getString("preDisplayId");
|
||||
}
|
||||
|
||||
public void setPreDisplayId(String displayId) {
|
||||
this.setOtaInfo("preDisplayId", displayId);
|
||||
}
|
||||
|
||||
public static String parseSkuId(String displayId) {
|
||||
if (displayId != null) {
|
||||
int startIndex = displayId.indexOf(46);
|
||||
++startIndex;
|
||||
startIndex = displayId.indexOf(46, startIndex);
|
||||
if (startIndex > 0) {
|
||||
int endIndex = displayId.indexOf(46, startIndex + 1);
|
||||
if (endIndex > startIndex) {
|
||||
++startIndex;
|
||||
return displayId.substring(startIndex, endIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getBrand() {
|
||||
return this.getOtaInfo().getString("brand");
|
||||
}
|
||||
|
||||
public void setBrand(String brand) {
|
||||
this.setOtaInfo("brand", brand);
|
||||
}
|
||||
|
||||
public String getCustomer() {
|
||||
return this.getOtaInfo().getString("customer");
|
||||
}
|
||||
|
||||
public void setCustomer(String customer) {
|
||||
this.setOtaInfo("customer", customer);
|
||||
}
|
||||
|
||||
public String getCustomerId() {
|
||||
return this.getOtaInfo().getString("customerId");
|
||||
}
|
||||
|
||||
public void setCustomerId(String customerId) {
|
||||
this.setOtaInfo("customerId", customerId);
|
||||
}
|
||||
|
||||
public String getPartNo() {
|
||||
return this.getOtaInfo().getString("partNo");
|
||||
}
|
||||
|
||||
public void setPartNo(String partNo) {
|
||||
this.setOtaInfo("partNo", partNo);
|
||||
}
|
||||
|
||||
public String getOsVersion() {
|
||||
return this.getOtaInfo().getString("osVersion");
|
||||
}
|
||||
|
||||
public void setOsVersion(String version) {
|
||||
this.setOtaInfo("osVersion", version);
|
||||
}
|
||||
|
||||
public String getScriptVersion() {
|
||||
return this.getOtaInfo().getString("scriptVersion");
|
||||
}
|
||||
|
||||
public void setScriptVersion(String partNo) {
|
||||
this.setOtaInfo("scriptVersion", partNo);
|
||||
}
|
||||
|
||||
public String getReleaseVersion() {
|
||||
return this.getOtaInfo().getString("releaseVersion");
|
||||
}
|
||||
|
||||
public void setReleaseVersion(String partNo) {
|
||||
this.setOtaInfo("releaseVersion", partNo);
|
||||
}
|
||||
|
||||
public String getMarketName1() {
|
||||
return this.getOtaInfo().getString("marketName1");
|
||||
}
|
||||
|
||||
public void setMarketName1(String name) {
|
||||
this.setOtaInfo("marketName1", name);
|
||||
}
|
||||
|
||||
public String getMarketName2() {
|
||||
return this.getOtaInfo().getString("marketName2");
|
||||
}
|
||||
|
||||
public void setMarketName2(String name) {
|
||||
this.setOtaInfo("marketName2", name);
|
||||
}
|
||||
|
||||
public String getSecurityPatchLevel() {
|
||||
return this.getOtaInfo().getString("securityPatch");
|
||||
}
|
||||
|
||||
public void setSecurityPatchLevel(String level) {
|
||||
this.setOtaInfo("securityPatch", level);
|
||||
}
|
||||
|
||||
public String getBuildType() {
|
||||
return this.getOtaInfo().getString("buildType");
|
||||
}
|
||||
|
||||
public void setBuildType(String buildType) {
|
||||
this.setOtaInfo("buildType", buildType);
|
||||
}
|
||||
|
||||
public String getBuildTags() {
|
||||
return this.getOtaInfo().getString("buildTags");
|
||||
}
|
||||
|
||||
public void setBuildTags(String buildTags) {
|
||||
this.setOtaInfo("buildTags", buildTags);
|
||||
}
|
||||
|
||||
public String getPreBuild() {
|
||||
return this.getOtaInfo().getString("preBuild");
|
||||
}
|
||||
|
||||
public void setPreBuild(String value) {
|
||||
this.setOtaInfo("preBuild", value);
|
||||
}
|
||||
|
||||
public String getOtaCertHash() {
|
||||
return this.getOtaInfo().getString("otaCert");
|
||||
}
|
||||
|
||||
public void setOtaCertHash(String hash) {
|
||||
this.setOtaInfo("otaCert", hash);
|
||||
}
|
||||
|
||||
public String getModemSku() {
|
||||
return this.getOtaInfo().getString("modemSku");
|
||||
}
|
||||
|
||||
public void setModemSku(String hash) {
|
||||
this.setOtaInfo("modemSku", hash);
|
||||
}
|
||||
|
||||
public String getModemFirmwareVersion() {
|
||||
return this.getOtaInfo().getString("modemFirmwareVersion");
|
||||
}
|
||||
|
||||
public void setModemFirmwareVersion(String hash) {
|
||||
this.setOtaInfo("modemFirmwareVersion", hash);
|
||||
}
|
||||
|
||||
public String getModemFirmwareLongVersion() {
|
||||
return this.getOtaInfo().getString("modemFirmwareLongVersion");
|
||||
}
|
||||
|
||||
public void setModemFirmwareLongVersion(String hash) {
|
||||
this.setOtaInfo("modemFirmwareLongVersion", hash);
|
||||
}
|
||||
|
||||
private void retrieveBuildInfo(ZipFile zipFile) {
|
||||
try {
|
||||
Enumeration<? extends ZipEntry> entries = zipFile.entries();
|
||||
ZipEntry bodyEntry = null;
|
||||
boolean isAbImage = false;
|
||||
|
||||
while(entries.hasMoreElements()) {
|
||||
ZipEntry entry = (ZipEntry)entries.nextElement();
|
||||
if (entry.getName().endsWith(".zip")) {
|
||||
bodyEntry = entry;
|
||||
} else if (entry.getName().endsWith(".sh")) {
|
||||
isAbImage = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isAbImage && bodyEntry != null) {
|
||||
InputStream input = zipFile.getInputStream(bodyEntry);
|
||||
|
||||
ZipInputStream zipBody;
|
||||
ZipEntry entry;
|
||||
for(zipBody = new ZipInputStream(input); (entry = zipBody.getNextEntry()) != null; zipBody.closeEntry()) {
|
||||
String entryName = entry.getName();
|
||||
if (entryName.equals("META-INF/com/android/metadata")) {
|
||||
this.dispatchProp(zipBody);
|
||||
} else if (entryName.equals("META-INF/com/android/update_info")) {
|
||||
this.dispatchJson(zipBody);
|
||||
} else if (entryName.equals("META-INF/com/android/otacert")) {
|
||||
this.dispatchOtaCert(zipBody);
|
||||
}
|
||||
}
|
||||
|
||||
zipBody.close();
|
||||
input.close();
|
||||
} else {
|
||||
ZipEntry udpateInfoEntry = zipFile.getEntry("META-INF/com/android/update_info");
|
||||
if (udpateInfoEntry != null) {
|
||||
this.dispatchJson(zipFile.getInputStream(udpateInfoEntry));
|
||||
this.setType("region");
|
||||
}
|
||||
|
||||
ZipEntry metaDataEntry = zipFile.getEntry("META-INF/com/android/metadata");
|
||||
if (metaDataEntry != null) {
|
||||
this.dispatchProp(zipFile.getInputStream(metaDataEntry));
|
||||
}
|
||||
|
||||
ZipEntry updateScriptEntry = zipFile.getEntry("META-INF/com/google/android/updater-script");
|
||||
if (updateScriptEntry != null) {
|
||||
this.dispatchUpdaterScript(zipFile.getInputStream(updateScriptEntry));
|
||||
}
|
||||
|
||||
ZipEntry otaCertEntry = zipFile.getEntry("META-INF/com/android/otacert");
|
||||
if (otaCertEntry != null) {
|
||||
InputStream otaInput = zipFile.getInputStream(otaCertEntry);
|
||||
this.dispatchOtaCert(otaInput);
|
||||
otaInput.close();
|
||||
}
|
||||
|
||||
ZipEntry buildPropEntry = zipFile.getEntry("system/build.prop");
|
||||
if (buildPropEntry != null) {
|
||||
this.dispatchProp(zipFile.getInputStream(buildPropEntry));
|
||||
}
|
||||
|
||||
zipFile.close();
|
||||
if (!Strings.isNullOrEmpty(this.getDisplayId()) && this.isRegionImage()) {
|
||||
this.setDisplayId(String.format("%s_%s_%s", this.getReleaseVersion(), this.getPartNo(), this.getMarketName2()));
|
||||
}
|
||||
|
||||
if (Strings.isNullOrEmpty(this.getType())) {
|
||||
this.setType("system");
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void dispatchUpdaterScript(InputStream is) {
|
||||
try {
|
||||
String script = IOUtils.toString(is, "UTF-8");
|
||||
String key = "ro.build.date.utc";
|
||||
String buildDate = this.lastSubString(script, key, "(", ",");
|
||||
this.setOtaProperty(key, buildDate);
|
||||
key = "ro.product.device";
|
||||
String value = this.subString(script, key, "\"", "\"");
|
||||
if (!Strings.isNullOrEmpty(value)) {
|
||||
this.setOtaProperty(key, value);
|
||||
}
|
||||
|
||||
key = "ro.mitac.product";
|
||||
value = this.subString(script, key, "\"", "\"");
|
||||
if (!Strings.isNullOrEmpty(value)) {
|
||||
this.setOtaProperty(key, value);
|
||||
}
|
||||
|
||||
key = "ro.mitac.sku";
|
||||
value = this.subString(script, key, "\"", "\"");
|
||||
if (!Strings.isNullOrEmpty(value)) {
|
||||
this.setOtaProperty(key, value);
|
||||
}
|
||||
|
||||
if (Strings.isNullOrEmpty(this.getDeviceId())) {
|
||||
value = this.subString(script, "get_device_compatible", "\"", "\"");
|
||||
if (!Strings.isNullOrEmpty(value)) {
|
||||
this.setDeviceId(value);
|
||||
}
|
||||
}
|
||||
|
||||
if (Strings.isNullOrEmpty(this.getBuildTags())) {
|
||||
String fingerPrint = this.subString(script, "ui_print(\"Target", " ", "\"");
|
||||
if (!Strings.isNullOrEmpty(fingerPrint)) {
|
||||
String buildTags = fingerPrint.substring(fingerPrint.lastIndexOf(47) + 1);
|
||||
if (!Strings.isNullOrEmpty(buildTags)) {
|
||||
this.setBuildTags(buildTags);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException var8) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void dispatchProp(InputStream input) {
|
||||
try {
|
||||
Properties properties = new Properties();
|
||||
properties.load(input);
|
||||
|
||||
for(Map.Entry entry : properties.entrySet()) {
|
||||
this.setOtaProperty((String)entry.getKey(), (String)entry.getValue());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void dispatchJson(InputStream input) {
|
||||
if (input != null) {
|
||||
JsonElement json = McJsonUtils.toJsonElement(input);
|
||||
if (json != null && json.isJsonObject()) {
|
||||
JsonObject jProps = json.getAsJsonObject();
|
||||
|
||||
for(Map.Entry entry : jProps.entrySet()) {
|
||||
String key = (String)entry.getKey();
|
||||
JsonElement value = (JsonElement)entry.getValue();
|
||||
if (value.isJsonPrimitive()) {
|
||||
this.setOtaProperty(key, value.getAsString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void dispatchOtaCert(InputStream otaCertIs) {
|
||||
McOtaCert otaCert = new McOtaCert(otaCertIs);
|
||||
this.setOtaCertHash(otaCert.getBase64Hash());
|
||||
}
|
||||
|
||||
private void setOtaProperty(String key, String value) {
|
||||
switch (key) {
|
||||
case "ota-type":
|
||||
this.setAbUpdate(value.equals("AB"));
|
||||
break;
|
||||
case "persist.sys.rgimg.brand":
|
||||
if (Strings.isNullOrEmpty(this.getBrand())) {
|
||||
this.setBrand(value);
|
||||
}
|
||||
break;
|
||||
case "ro.build.date.utc":
|
||||
case "post-timestamp":
|
||||
case "persist.sys.rgimg.build_utc":
|
||||
if (this.getBuildDate() < 0L) {
|
||||
this.setBuildDate(Long.valueOf(value));
|
||||
}
|
||||
break;
|
||||
case "persist.sys.rgimg.customer":
|
||||
if (Strings.isNullOrEmpty(this.getCustomer())) {
|
||||
this.setCustomer(value);
|
||||
}
|
||||
break;
|
||||
case "persist.sys.rgimg.customer_id":
|
||||
if (Strings.isNullOrEmpty(this.getCustomerId())) {
|
||||
this.setCustomerId(value);
|
||||
}
|
||||
break;
|
||||
case "persist.sys.rgimg.mkt_name1":
|
||||
if (Strings.isNullOrEmpty(this.getMarketName1())) {
|
||||
this.setMarketName1(value);
|
||||
}
|
||||
break;
|
||||
case "persist.sys.rgimg.mkt_name2":
|
||||
if (Strings.isNullOrEmpty(this.getMarketName2())) {
|
||||
this.setMarketName2(value);
|
||||
}
|
||||
break;
|
||||
case "persist.sys.rgimg.part_num":
|
||||
if (Strings.isNullOrEmpty(this.getPartNo())) {
|
||||
this.setPartNo(value);
|
||||
}
|
||||
break;
|
||||
case "product-code":
|
||||
case "ro.mitac.product":
|
||||
case "persist.sys.rgimg.product":
|
||||
if (Strings.isNullOrEmpty(this.getProductId())) {
|
||||
this.setProductId(value);
|
||||
}
|
||||
break;
|
||||
case "persist.sys.rgimg.release_ver":
|
||||
if (Strings.isNullOrEmpty(this.getReleaseVersion())) {
|
||||
this.setReleaseVersion(value);
|
||||
}
|
||||
break;
|
||||
case "persist.sys.rgimg.script_ver":
|
||||
if (Strings.isNullOrEmpty(this.getScriptVersion())) {
|
||||
this.setScriptVersion(value);
|
||||
}
|
||||
break;
|
||||
case "persist.sys.rgimg.target_device":
|
||||
case "pre-device":
|
||||
if (Strings.isNullOrEmpty(this.getDeviceId())) {
|
||||
this.setDeviceId(value);
|
||||
}
|
||||
break;
|
||||
case "persist.sys.rgimg.target_product":
|
||||
if (Strings.isNullOrEmpty(this.getTargetProduct())) {
|
||||
this.setTargetProduct(value);
|
||||
}
|
||||
break;
|
||||
case "mitac-display-id":
|
||||
String curDisplayId = this.getDisplayId();
|
||||
this.setProductDisplayId(value);
|
||||
if (Strings.isNullOrEmpty(curDisplayId)) {
|
||||
this.setDisplayId(value);
|
||||
}
|
||||
|
||||
if (Strings.isNullOrEmpty(this.getSkuId())) {
|
||||
String skuId = parseSkuId(value);
|
||||
if (!Strings.isNullOrEmpty(skuId)) {
|
||||
this.setSkuId(skuId);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "display-id":
|
||||
case "ro.build.display.id":
|
||||
String curDisplayId = this.getDisplayId();
|
||||
if (Strings.isNullOrEmpty(curDisplayId) || !curDisplayId.equals(value)) {
|
||||
this.setDisplayId(value);
|
||||
}
|
||||
|
||||
if (Strings.isNullOrEmpty(this.getSkuId())) {
|
||||
String skuId = parseSkuId(value);
|
||||
if (!Strings.isNullOrEmpty(skuId)) {
|
||||
this.setSkuId(skuId);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "pre-display-id":
|
||||
this.setPreDisplayId(value);
|
||||
break;
|
||||
case "mitac-package-type":
|
||||
this.setType(value);
|
||||
case "post-build-incremental":
|
||||
default:
|
||||
break;
|
||||
case "post-sdk-level":
|
||||
if (this.getSdkLevel() < 0) {
|
||||
this.setSdkLevel(Integer.valueOf(value));
|
||||
}
|
||||
break;
|
||||
case "post-security-patch-level":
|
||||
if (Strings.isNullOrEmpty(this.getSecurityPatchLevel())) {
|
||||
this.setSecurityPatchLevel(value);
|
||||
}
|
||||
break;
|
||||
case "pre-build":
|
||||
this.setPreBuild(value);
|
||||
break;
|
||||
case "post-build":
|
||||
this.dispatchPostBuild(value);
|
||||
break;
|
||||
case "sku-id":
|
||||
case "ro.mitac.sku":
|
||||
this.setSkuId(value);
|
||||
break;
|
||||
case "base-sku-compatibility":
|
||||
if (!this.hasCompatibleSkuIds()) {
|
||||
this.setCompatibleSkuIds(value);
|
||||
}
|
||||
break;
|
||||
case "ro.build.tags":
|
||||
if (Strings.isNullOrEmpty(this.getBuildTags())) {
|
||||
this.setBuildTags(value);
|
||||
}
|
||||
break;
|
||||
case "modem-firmware-sku":
|
||||
if (Strings.isNullOrEmpty(this.getModemSku())) {
|
||||
this.setModemSku(value);
|
||||
}
|
||||
break;
|
||||
case "modem-firmware-version":
|
||||
if (Strings.isNullOrEmpty(this.getModemFirmwareVersion())) {
|
||||
this.setModemFirmwareVersion(value);
|
||||
}
|
||||
break;
|
||||
case "modem-firmware-long-version":
|
||||
if (Strings.isNullOrEmpty(this.getModemFirmwareLongVersion())) {
|
||||
this.setModemFirmwareLongVersion(value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String getPostBuild() {
|
||||
return this.getOtaInfo().getString("postBuild");
|
||||
}
|
||||
|
||||
private void dispatchPostBuild(String text) {
|
||||
this.setOtaInfo("postBuild", text);
|
||||
String[] tags = text.split(":");
|
||||
if (tags.length >= 3) {
|
||||
String[] tokens = tags[1].split("/");
|
||||
if (Strings.isNullOrEmpty(this.getOsVersion())) {
|
||||
this.setOsVersion(tokens[0]);
|
||||
}
|
||||
|
||||
tokens = tags[2].split("/");
|
||||
if (Strings.isNullOrEmpty(this.getBuildType())) {
|
||||
this.setBuildType(tokens[0]);
|
||||
}
|
||||
|
||||
if (Strings.isNullOrEmpty(this.getBuildTags())) {
|
||||
this.setBuildTags(tokens[1]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private String subString(String sb, String key, String prefix, String suffix) {
|
||||
int keyIndex = sb.indexOf(key);
|
||||
if (keyIndex < 0) {
|
||||
return null;
|
||||
} else {
|
||||
int startIndex = sb.indexOf(prefix, keyIndex + key.length() + 1) + 1;
|
||||
int endIndex = sb.indexOf(suffix, startIndex + 1);
|
||||
return startIndex < endIndex ? sb.substring(startIndex, endIndex) : "";
|
||||
}
|
||||
}
|
||||
|
||||
private String lastSubString(String sb, String key, String prefix, String suffix) {
|
||||
int keyIndex = sb.indexOf(key);
|
||||
int endIndex = sb.lastIndexOf(",", keyIndex);
|
||||
int startIndex = sb.lastIndexOf("(", endIndex) + 1;
|
||||
return startIndex < endIndex ? sb.substring(startIndex, endIndex) : "";
|
||||
}
|
||||
|
||||
public int compareTo(OtaFile other) {
|
||||
int result = this.getSkuId().compareTo(other.getSkuId());
|
||||
if (result == 0) {
|
||||
boolean isThisSystemImage = this.isSystemImage();
|
||||
boolean isOtherSystemImage = other.isSystemImage();
|
||||
if (isThisSystemImage != isOtherSystemImage) {
|
||||
if (isThisSystemImage) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
result = (int)(this.getBuildDate() - other.getBuildDate());
|
||||
if (result == 0) {
|
||||
if (this.isPartial() && !other.isPartial()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!this.isPartial() && other.isPartial()) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.midm.model.file;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public enum REPORT_ERROR {
|
||||
UNKNOWN(1000),
|
||||
FILE_ERROR(1001),
|
||||
UNHANDLED_HTTP_CODE(1002),
|
||||
HTTP_DATA_ERROR(1004),
|
||||
TOO_MANY_REDIRECTS(1005),
|
||||
INSUFFICIENT_SPACE(1006),
|
||||
DEVICE_NOT_FOUND(1007),
|
||||
CANNOT_RESUME(1008),
|
||||
FILE_ALREADY_EXISTS(1009),
|
||||
FILE_MISMATCHED(2001);
|
||||
|
||||
public static final List COLLECT_SSN = List.of(UNKNOWN, FILE_ERROR, INSUFFICIENT_SPACE, DEVICE_NOT_FOUND, CANNOT_RESUME, FILE_ALREADY_EXISTS);
|
||||
private int value;
|
||||
|
||||
private REPORT_ERROR(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public static REPORT_ERROR fromValue(int value) {
|
||||
for(REPORT_ERROR e : values()) {
|
||||
if (e.getValue() == value) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package com.midm.model.log;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.midm.model.org.User;
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import com.mitac.cell.internet.http.UserAgent;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.index.CompoundIndex;
|
||||
import org.springframework.data.mongodb.core.index.CompoundIndexes;
|
||||
import org.springframework.data.mongodb.core.mapping.DBRef;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
@CompoundIndexes({@CompoundIndex(
|
||||
def = "{'category':1, 'loggedAt':1}"
|
||||
), @CompoundIndex(
|
||||
def = "{'forWhat':1, 'loggedAt': -1}"
|
||||
), @CompoundIndex(
|
||||
def = "{'forWhat':1, 'log': 1}"
|
||||
)})
|
||||
public class MidmLog {
|
||||
@Id
|
||||
private UUID uuid;
|
||||
private UUID forWhat;
|
||||
private String category;
|
||||
private String log;
|
||||
private DbObject reference;
|
||||
private Date loggedAt;
|
||||
@DBRef
|
||||
private User logger;
|
||||
|
||||
public MidmLog() {
|
||||
this.setUuid(UUID.randomUUID());
|
||||
this.setLoggedAt(new Date());
|
||||
}
|
||||
|
||||
public MidmLog(User user, UUID forWhat, String category, String log) {
|
||||
this();
|
||||
if (user != null) {
|
||||
this.setLogger(user);
|
||||
}
|
||||
|
||||
this.setForWhat(forWhat);
|
||||
this.setCategory(category);
|
||||
this.setLog(log);
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
public void setUuid(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public UUID getForWhat() {
|
||||
return this.forWhat;
|
||||
}
|
||||
|
||||
public void setForWhat(UUID forWhat) {
|
||||
this.forWhat = forWhat;
|
||||
}
|
||||
|
||||
public String getCategory() {
|
||||
return this.category;
|
||||
}
|
||||
|
||||
public void setCategory(String category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public String getLog() {
|
||||
return this.log;
|
||||
}
|
||||
|
||||
public void setLog(String log) {
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
public DbObject getReference() {
|
||||
if (this.reference == null) {
|
||||
this.reference = new DbObject();
|
||||
}
|
||||
|
||||
return this.reference;
|
||||
}
|
||||
|
||||
public boolean hasReference() {
|
||||
return this.reference != null && this.reference.size() > 0;
|
||||
}
|
||||
|
||||
public void setReference(DbObject reference) {
|
||||
this.reference = reference;
|
||||
}
|
||||
|
||||
public void setReference(UserAgent agent, String sessionId, String remoteIp) {
|
||||
if (agent != null) {
|
||||
this.addReference("browser", agent.agentFamily());
|
||||
this.addReference("os", agent.osFamily());
|
||||
this.addReference("device", agent.deviceFamily());
|
||||
}
|
||||
|
||||
if (!Strings.isNullOrEmpty(sessionId)) {
|
||||
this.addReference("sessionId", sessionId);
|
||||
}
|
||||
|
||||
if (!Strings.isNullOrEmpty(remoteIp)) {
|
||||
this.addReference("remoteIp", remoteIp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void addReference(String key, Object value) {
|
||||
this.getReference().put(key, value);
|
||||
}
|
||||
|
||||
public UUID getLoggerUuid() {
|
||||
return this.logger != null ? this.logger.getUuid() : null;
|
||||
}
|
||||
|
||||
public Date getLoggedAt() {
|
||||
return this.loggedAt;
|
||||
}
|
||||
|
||||
public void setLoggedAt(Date loggedAt) {
|
||||
this.loggedAt = loggedAt;
|
||||
}
|
||||
|
||||
public void setLoggedAt(long loggedAt) {
|
||||
this.loggedAt = new Date(loggedAt);
|
||||
}
|
||||
|
||||
public User getLogger() {
|
||||
return this.logger;
|
||||
}
|
||||
|
||||
public void setLogger(User logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.midm.model.message;
|
||||
|
||||
public enum MIDM_REQUEST {
|
||||
PING(99, "ping"),
|
||||
CONNECT(100, "connect"),
|
||||
DISCONNECT(101, "disconnect"),
|
||||
CHECKIN(102, "checkin"),
|
||||
CHECKOUT(103, "checkout"),
|
||||
ENROLL(104, "enroll"),
|
||||
DEVICE_INFO(105, "update_device_info"),
|
||||
CLIENT_UPDATE(121, "client_update"),
|
||||
UPDATE_PROFILE(131, "profile_update"),
|
||||
UPDATE_ALL_PROFILES(132, "profile_update_all"),
|
||||
REMOVE_PROFILE(136, "profile_remove"),
|
||||
COMMAND(200, "command"),
|
||||
QUERY(210, "query"),
|
||||
EXEC(220, "exec"),
|
||||
DEVICE_STATE(300, "device_state"),
|
||||
USER_LOG(301, "userLog"),
|
||||
DEVICE_LOG(302, "deviceLog"),
|
||||
RTC(400, "rtc"),
|
||||
UNKNOWN(-1, "");
|
||||
|
||||
private int code;
|
||||
private String request;
|
||||
|
||||
private MIDM_REQUEST(int code, String request) {
|
||||
this.code = code;
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
public String getRequest() {
|
||||
return this.request;
|
||||
}
|
||||
|
||||
public static MIDM_REQUEST get(int code) {
|
||||
for(MIDM_REQUEST request : values()) {
|
||||
if (request.code == code) {
|
||||
return request;
|
||||
}
|
||||
}
|
||||
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
public static MIDM_REQUEST get(String requestText) {
|
||||
for(MIDM_REQUEST request : values()) {
|
||||
if (request.getRequest().equalsIgnoreCase(requestText.trim())) {
|
||||
return request;
|
||||
}
|
||||
}
|
||||
|
||||
return UNKNOWN;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
package com.midm.model.message;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.mitac.cell.data.McCompress;
|
||||
import com.mitac.cell.data.McDecompress;
|
||||
import com.mitac.cell.utils.McJsonUtils;
|
||||
import java.io.Serializable;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
import org.springframework.web.socket.BinaryMessage;
|
||||
import org.springframework.web.socket.TextMessage;
|
||||
|
||||
@Document
|
||||
public class MidmPacket implements Serializable {
|
||||
@Id
|
||||
private UUID uuid;
|
||||
private UUID recieverUuid;
|
||||
private UUID queryUuid;
|
||||
@Transient
|
||||
private MidmQuery query;
|
||||
private MidmResponse feedback;
|
||||
private Date readAt;
|
||||
|
||||
public MidmPacket() {
|
||||
this.setUuid(UUID.randomUUID());
|
||||
}
|
||||
|
||||
public MidmPacket(int code) {
|
||||
this.init();
|
||||
this.setQuery(new MidmQuery(code));
|
||||
}
|
||||
|
||||
public MidmPacket(MIDM_REQUEST request) {
|
||||
this(request.getCode());
|
||||
}
|
||||
|
||||
private void init() {
|
||||
this.setUuid(UUID.randomUUID());
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
public void setUuid(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public UUID getRecieverUuid() {
|
||||
return this.recieverUuid;
|
||||
}
|
||||
|
||||
public void setRecieverUuid(UUID recieverUuid) {
|
||||
this.recieverUuid = recieverUuid;
|
||||
}
|
||||
|
||||
public UUID getQueryUuid() {
|
||||
return this.queryUuid;
|
||||
}
|
||||
|
||||
public void setQueryUuid(UUID queryUuid) {
|
||||
this.queryUuid = queryUuid;
|
||||
}
|
||||
|
||||
public MidmQuery getQuery() {
|
||||
return this.query;
|
||||
}
|
||||
|
||||
public void setQuery(MidmQuery query) {
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
public Object getParam(String key) {
|
||||
return this.getQuery().getParam(key);
|
||||
}
|
||||
|
||||
public void setParam(String key, Object value) {
|
||||
this.getQuery().setParam(key, value);
|
||||
}
|
||||
|
||||
public MidmResponse getFeedback() {
|
||||
return this.feedback;
|
||||
}
|
||||
|
||||
public void setFeedback(MidmResponse feedback) {
|
||||
this.feedback = feedback;
|
||||
}
|
||||
|
||||
public void setFeedback(int code, String message) {
|
||||
this.feedback = new MidmResponse(code, message);
|
||||
}
|
||||
|
||||
public void setFeedback(int code, String message, Object data) {
|
||||
this.feedback = new MidmResponse(code, message, data);
|
||||
}
|
||||
|
||||
public Date getReadAt() {
|
||||
return this.readAt;
|
||||
}
|
||||
|
||||
public void setReadAt(Date readAt) {
|
||||
this.readAt = readAt;
|
||||
}
|
||||
|
||||
public TextMessage toMessage() {
|
||||
return new TextMessage(this.toString());
|
||||
}
|
||||
|
||||
public BinaryMessage toBinary() {
|
||||
byte[] bytes = McCompress.compress(this.toString());
|
||||
return new BinaryMessage(bytes);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return McJsonUtils.toJson(this);
|
||||
}
|
||||
|
||||
public static MidmPacket toPacket(TextMessage message) {
|
||||
return (MidmPacket)McJsonUtils.toObject((String)message.getPayload(), MidmPacket.class);
|
||||
}
|
||||
|
||||
public static MidmPacket topacket(BinaryMessage message) {
|
||||
ByteBuffer bytes = (ByteBuffer)message.getPayload();
|
||||
byte[] decompressed = McDecompress.decompress(bytes.array());
|
||||
return (MidmPacket)McJsonUtils.toObject(new String(decompressed, Charsets.UTF_8), MidmPacket.class);
|
||||
}
|
||||
|
||||
public static MidmPacket toPacket(String message) {
|
||||
return (MidmPacket)McJsonUtils.toObject(message, MidmPacket.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package com.midm.model.message;
|
||||
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class MidmQuery {
|
||||
private UUID uuid;
|
||||
private UUID senderUuid;
|
||||
private int code;
|
||||
private DbObject query;
|
||||
private boolean isInstant;
|
||||
private Date registeredAt;
|
||||
|
||||
public MidmQuery() {
|
||||
this.init();
|
||||
}
|
||||
|
||||
public MidmQuery(int code) {
|
||||
this();
|
||||
this.setCode(code);
|
||||
}
|
||||
|
||||
public void init() {
|
||||
this.setUuid(UUID.randomUUID());
|
||||
this.isInstant = true;
|
||||
this.setRegisteredAt(new Date());
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
public void setUuid(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public UUID getSenderUuid() {
|
||||
return this.senderUuid;
|
||||
}
|
||||
|
||||
public void setSenderUuid(UUID senderUuid) {
|
||||
this.senderUuid = senderUuid;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public DbObject getQuery() {
|
||||
if (this.query == null) {
|
||||
this.query = new DbObject();
|
||||
}
|
||||
|
||||
return this.query;
|
||||
}
|
||||
|
||||
public void setQuery(DbObject query) {
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
public String getRequest() {
|
||||
return (String)this.getQuery().get("request");
|
||||
}
|
||||
|
||||
public void setRequest(String request) {
|
||||
this.getQuery().put("request", request);
|
||||
}
|
||||
|
||||
public DbObject getParams() {
|
||||
DbObject params = this.getQuery().getDbObject(new String[]{"params"});
|
||||
if (params == null) {
|
||||
params = new DbObject();
|
||||
this.getQuery().put("params", params);
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
public Object getParam(String key) {
|
||||
return this.getParams().get(key);
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
return this.getParam("command").toString();
|
||||
}
|
||||
|
||||
public void setParam(String key, Object value) {
|
||||
this.getParams().put(key, value);
|
||||
}
|
||||
|
||||
public boolean isInstant() {
|
||||
return this.isInstant;
|
||||
}
|
||||
|
||||
public void setInstant(boolean isInstant) {
|
||||
this.isInstant = isInstant;
|
||||
}
|
||||
|
||||
public Date getRegisteredAt() {
|
||||
return this.registeredAt;
|
||||
}
|
||||
|
||||
public void setRegisteredAt(Date registeredAt) {
|
||||
this.registeredAt = registeredAt;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,268 @@
|
||||
package com.midm.model.message;
|
||||
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import com.mitac.cell.utils.McJsonUtils;
|
||||
import com.mongodb.client.result.UpdateResult;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.web.socket.TextMessage;
|
||||
|
||||
public class MidmResponse {
|
||||
public static final String MESSAGE_SUCCEED = "succeed";
|
||||
public static final String MESSAGE_FAILED = "failed";
|
||||
public static final int CODE_SERVICE_CONNECTED = 100;
|
||||
public static final int CODE_SUCCEED = 200;
|
||||
public static final int CODE_CHECKEDIN = 110;
|
||||
public static final int CODE_ENROLLED = 111;
|
||||
public static final int CODE_ENROLL_REJECTED = 112;
|
||||
public static final int CODE_DEVICE_REGISTERD = 113;
|
||||
public static final int CODE_DEVICE_UPDATED = 114;
|
||||
public static final int CODE_LICENSE_EXPIRED = 115;
|
||||
public static final int CODE_MESSAGE_NOTIFY = 116;
|
||||
public static final int CODE_REPORT_READY = 117;
|
||||
public static final int CODE_REPORT_GENERATE_FAIL = 118;
|
||||
public static final int CODE_HOST_LICENSE_READY = 119;
|
||||
public static final int CODE_SITE_LICENSE_READY = 109;
|
||||
public static final int CODE_SITE_LICENSE_REQUESTED = 108;
|
||||
public static final int CODE_SITE_UPGRADE_REQUESTED = 107;
|
||||
public static final int CODE_SITE_UPGRADE_SUCCESS = 106;
|
||||
public static final int CODE_UPDATE_CIENT_APPS = 121;
|
||||
public static final int CODE_ONLINE_STATE_CHANGED = 211;
|
||||
public static final int CODE_DEVICE_STATE_CHANGED = 300;
|
||||
public static final int FEEDBACK_APP_LIST = 120;
|
||||
public static final int FEEDBACK_APP_INSTALLED = 121;
|
||||
public static final int FEEDBACK_APP_UNINSTALLED = 122;
|
||||
public static final int FEEDBACK_APP_ENABLE = 123;
|
||||
public static final int FEEDBACK_APP_DISABLE = 124;
|
||||
public static final int FEEDBACK_APP_SHOW = 125;
|
||||
public static final int FEEDBACK_APP_HIDE = 126;
|
||||
public static final int FEEDBACK_APP_INFO = 127;
|
||||
public static final int FEEDBACK_FILE_LIST = 130;
|
||||
public static final int FEEDBACK_FILE_STORAGE = 131;
|
||||
public static final int FEEDBACK_FILE_COPY = 132;
|
||||
public static final int FEEDBACK_FILE_RENAME = 133;
|
||||
public static final int FEEDBACK_FILE_MOVE = 134;
|
||||
public static final int FEEDBACK_FILE_REMOVE = 135;
|
||||
public static final int FEEDBACK_FILE_MKDIR = 136;
|
||||
public static final int FEEDBACK_FILE_PUSH = 137;
|
||||
public static final int FEEDBACK_FILE_PULL = 138;
|
||||
public static final int FEEDBACK_FILE_LOGCAT = 139;
|
||||
public static final int FEEDBACK_EXEC = 140;
|
||||
public static final int FEEDBACK_EXEC_LOGCAT = 141;
|
||||
public static final int FEEDBACK_HARDWARE_INFO = 170;
|
||||
public static final int FEEDBACK_SOFTWARE_INFO = 180;
|
||||
public static final int FEEDBACK_MEMORY_USAGE = 190;
|
||||
public static final int FEEDBACK_BATTERY_INFO = 191;
|
||||
public static final int FEEDBACK_DATA_USAGE = 192;
|
||||
public static final int FEEDBACK_ACTIVE_NETWORK = 193;
|
||||
public static final int FEEDBACK_NETWORK = 194;
|
||||
public static final int FEEDBACK_LOCATION = 198;
|
||||
public static final int FEEDBACK_SCREEN_CAPTURED = 199;
|
||||
public static final int FEEDBACK_ONLINE_STATE = 211;
|
||||
public static final int FEEDBACK_CAMERA_STATE = 212;
|
||||
public static final int FEEDBACK_DEVICE_STATE = 300;
|
||||
public static final int CODE_FAILED = 400;
|
||||
public static final int CODE_NOT_FOUND = 404;
|
||||
public static final int CODE_FAIL_USER_NOT_FOUND = 410;
|
||||
public static final int CODE_FAIL_WRONG_PASSWROD = 411;
|
||||
public static final int CODE_FAIL_USER_NOT_AVAILABLE = 412;
|
||||
public static final int CODE_FAIL_INSUFFICIENT_INFO = 413;
|
||||
public static final int CODE_FAIL_USER_LOGGED_IN = 414;
|
||||
public static final int CODE_FAIL_NO_AUTH_INFO = 415;
|
||||
public static final int CODE_FAIL_REGISTERED_TO_OTHER = 416;
|
||||
public static final int CODE_FAIL_VERSION_DUPLICATE = 417;
|
||||
public static final int CODE_FAIL_USER_NOT_AGREED = 418;
|
||||
public static final int CODE_FAIL_SAME_NAME_NOT_ALLOW = 419;
|
||||
public static final int CODE_FAIL_HOST_EXPIRED = 420;
|
||||
public static final int CODE_FAIL_HOST_EXCEED_DEVICE_LIMIT = 421;
|
||||
public static final int CODE_FAIL_INVALID = 422;
|
||||
public static final int CODE_FAIL_EXISTING_USER = 423;
|
||||
public static final int CODE_FAIL_EXCEED_LOGIN_FAILURE = 424;
|
||||
public static final int CODE_FAIL_API_ONLY_USER = 425;
|
||||
public static final int CODE_FAIL_SITE_NOT_FOUND = 450;
|
||||
public static final int CODE_FAIL_NO_SITE_AVAILABLE = 451;
|
||||
public static final int CODE_FAIL_SITE_NO_USER = 452;
|
||||
public static final int CODE_FAIL_SITE_USER_DISABLED = 453;
|
||||
public static final int CODE_FAIL_SITE_SAME = 455;
|
||||
public static final int CODE_FAIL_DEVICE_NO_SERIAL = 461;
|
||||
public static final int CODE_FAIL_DEVICE_NO_SITE = 462;
|
||||
public static final int CODE_FAIL_NO_DEVICE_EXISTS = 463;
|
||||
public static final int CODE_FAIL_DEVICE_NO_LICENSE = 464;
|
||||
public static final int CODE_FAIL_CHILD_EXISTS = 466;
|
||||
public static final int CODE_FAIL_DEVICE_EXISTS = 467;
|
||||
public static final int CODE_FAIL_LICENSE_EXPIRED = 115;
|
||||
public static final int CODE_ERROR_NO_RECORD = 421;
|
||||
public static final int CODE_ERROR_TOKEN_NOT_DEFINED = 461;
|
||||
public static final int CODE_ERROR_EXPIRED_TOKEN = 462;
|
||||
public static final int CODE_ERROR_INVALID_TOKEN = 463;
|
||||
public static final int CODE_ERROR_URL_FORMAT = 431;
|
||||
public static final int CODE_ERROR_IO_EXEPTION = 432;
|
||||
public static final int CODE_ERROR_NO_PERMISSION = 433;
|
||||
public static final int CODE_ERROR_INVALID_SYSTEM_IMAGE = 441;
|
||||
public static final int CODE_UNKOWN = -1;
|
||||
public static final String MESSAGE_NOT_ALLOWED = "Not allowed.";
|
||||
public static final String MESSAGE_NOT_AUTHORIZED = "Not authorized.";
|
||||
public static final String MESSAGE_NO_PERMISSION = "No permission.";
|
||||
public static final String MESSAGE_NO_USER_EXISTS = "No user exists.";
|
||||
public static final String MESSAGE_NO_SITE_AVAILABLE = "No site available.";
|
||||
public static final String MESSAGE_NO_DEVICE_EXISTS = "No device exists.";
|
||||
public static final String MESSAGE_NO_SERIAL_DEFINED = "No serial no. defined.";
|
||||
public static final String MESSAGE_DEVICE_EXISTS = "Existing device.";
|
||||
public static final String MESSAGE_NO_GROUP_EXISTS = "No group exists.";
|
||||
public static final String MESSAGE_NO_GROUP = "No group: ";
|
||||
public static final String MESSAGE_NO_RECORDS = "No records.";
|
||||
public static final String MESSAGE_NO_REPORTS = "No reports.";
|
||||
public static final String MESSAGE_NO_LICENSE = "No license.";
|
||||
public static final String MESSAGE_NO_LOCATIONS = "No locations.";
|
||||
public static final String MESSAGE_NO_PROFILE_FOUND = "No profile found.";
|
||||
public static final String MESSAGE_NO_APP_FOUND = "No apps found.";
|
||||
public static final String MESSAGE_NO_USER_LOGGED_IN = "No user logged in.";
|
||||
private int code;
|
||||
private String message;
|
||||
private Object data;
|
||||
private Object reference;
|
||||
private Integer totalPage;
|
||||
private Long size;
|
||||
private Long totalSize;
|
||||
|
||||
public MidmResponse() {
|
||||
}
|
||||
|
||||
public MidmResponse(int code, String msg) {
|
||||
this.setCode(code);
|
||||
this.setMessage(msg);
|
||||
}
|
||||
|
||||
public MidmResponse(int code, String msg, Object data) {
|
||||
this.setCode(code);
|
||||
this.setMessage(msg);
|
||||
this.setData(data);
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public Object getData() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
public DbObject getDataAsDbObject() {
|
||||
Object data = this.getData();
|
||||
return data == null ? new DbObject() : new DbObject((Map)data);
|
||||
}
|
||||
|
||||
public void setData(Object data) {
|
||||
if (data instanceof UpdateResult) {
|
||||
UpdateResult result = (UpdateResult)data;
|
||||
this.data = (new DbObject("matched", result.getMatchedCount())).append("modified", result.getModifiedCount());
|
||||
} else {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Object getReference() {
|
||||
return this.reference;
|
||||
}
|
||||
|
||||
public DbObject getRefereceAsDbObject() {
|
||||
Object data = this.getReference();
|
||||
return data == null ? new DbObject() : new DbObject((Map)data);
|
||||
}
|
||||
|
||||
public void setReference(Object reference) {
|
||||
this.reference = reference;
|
||||
}
|
||||
|
||||
public int getTotalPage() {
|
||||
return this.totalPage;
|
||||
}
|
||||
|
||||
public void setTotalPages(int totalPage) {
|
||||
this.totalPage = totalPage;
|
||||
}
|
||||
|
||||
public long getSize() {
|
||||
return this.size;
|
||||
}
|
||||
|
||||
public void setSize(long size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public long getTotalSize() {
|
||||
return this.totalSize;
|
||||
}
|
||||
|
||||
public void setTotalSize(long totalSize) {
|
||||
this.totalSize = totalSize;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return McJsonUtils.toJson(this);
|
||||
}
|
||||
|
||||
public TextMessage toTextMessage() {
|
||||
return new TextMessage(this.toString());
|
||||
}
|
||||
|
||||
public static String getSucceedResponse() {
|
||||
return getResponse(200, "succeed");
|
||||
}
|
||||
|
||||
public static String getSucceedResponse(List list) {
|
||||
MidmResponse response = new MidmResponse(200, "succeed");
|
||||
if (list != null) {
|
||||
response.setData(list);
|
||||
response.setSize((long)list.size());
|
||||
}
|
||||
|
||||
return response.toString();
|
||||
}
|
||||
|
||||
public static String getSucceedResponse(Page page) {
|
||||
MidmResponse response = new MidmResponse(200, "succeed");
|
||||
if (page != null) {
|
||||
response.setData(page.getContent());
|
||||
response.setTotalPages(page.getTotalPages());
|
||||
response.setSize((long)page.getNumberOfElements());
|
||||
response.setTotalSize(page.getTotalElements());
|
||||
}
|
||||
|
||||
return response.toString();
|
||||
}
|
||||
|
||||
public static String getSucceedResponse(Object data) {
|
||||
return getResponse(200, "succeed", data);
|
||||
}
|
||||
|
||||
public static String getFailedResponse() {
|
||||
return getResponse(400, "failed");
|
||||
}
|
||||
|
||||
public static String getResponse(int code, String msg) {
|
||||
return (new MidmResponse(code, msg)).toString();
|
||||
}
|
||||
|
||||
public static String getResponse(int code, String msg, Object data) {
|
||||
return (new MidmResponse(code, msg, data)).toString();
|
||||
}
|
||||
|
||||
public static String getResponse(Object object) {
|
||||
return McJsonUtils.toJson(object);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
package com.midm.model.news;
|
||||
|
||||
import com.midm.model.org.User;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.index.Indexed;
|
||||
import org.springframework.data.mongodb.core.mapping.DBRef;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class MessageLog {
|
||||
@Id
|
||||
private UUID uuid;
|
||||
@DBRef
|
||||
private NewsMessage message;
|
||||
@DBRef
|
||||
private User reader;
|
||||
@Indexed
|
||||
private UUID siteUuid;
|
||||
@Indexed
|
||||
private Date readDate;
|
||||
@Indexed
|
||||
private boolean isCheck;
|
||||
@Indexed
|
||||
private boolean isRead;
|
||||
@Indexed
|
||||
private Date checkDate;
|
||||
@Indexed
|
||||
private Date notified;
|
||||
|
||||
public MessageLog() {
|
||||
}
|
||||
|
||||
public MessageLog(NewsMessage message, User reader, UUID siteUuid) {
|
||||
this.uuid = UUID.randomUUID();
|
||||
this.message = message;
|
||||
this.reader = reader;
|
||||
this.siteUuid = siteUuid;
|
||||
this.isCheck = false;
|
||||
this.notified = new Date();
|
||||
}
|
||||
|
||||
public MessageLog(NewsMessage message, UUID userUuid, UUID siteUuid) {
|
||||
this.uuid = UUID.randomUUID();
|
||||
this.message = message;
|
||||
this.reader = new User(userUuid);
|
||||
this.siteUuid = siteUuid;
|
||||
this.isCheck = false;
|
||||
this.notified = new Date();
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
public void setUuid(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public NewsMessage getMessage() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public void setMessage(NewsMessage message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public User getReader() {
|
||||
return this.reader;
|
||||
}
|
||||
|
||||
public void setReader(User reader) {
|
||||
this.reader = reader;
|
||||
}
|
||||
|
||||
public boolean isCheck() {
|
||||
return this.isCheck;
|
||||
}
|
||||
|
||||
public void setCheck(boolean isCheck) {
|
||||
this.isCheck = isCheck;
|
||||
}
|
||||
|
||||
public boolean isRead() {
|
||||
return this.isRead;
|
||||
}
|
||||
|
||||
public void setRead(boolean isRead) {
|
||||
this.isRead = isRead;
|
||||
}
|
||||
|
||||
public UUID getSiteUuid() {
|
||||
return this.siteUuid;
|
||||
}
|
||||
|
||||
public void setSiteUuid(UUID siteUuid) {
|
||||
this.siteUuid = siteUuid;
|
||||
}
|
||||
|
||||
public Date getNotified() {
|
||||
return this.notified;
|
||||
}
|
||||
|
||||
public void setNotified(Date notified) {
|
||||
this.notified = notified;
|
||||
}
|
||||
|
||||
public Date getReadDate() {
|
||||
return this.readDate;
|
||||
}
|
||||
|
||||
public void setReadDate(Date readDate) {
|
||||
this.readDate = readDate;
|
||||
}
|
||||
|
||||
public Date getCheckDate() {
|
||||
return this.checkDate;
|
||||
}
|
||||
|
||||
public void setCheckDate(Date checkDate) {
|
||||
this.checkDate = checkDate;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,306 @@
|
||||
package com.midm.model.news;
|
||||
|
||||
import com.google.gson.internal.LinkedTreeMap;
|
||||
import com.midm.model.device.Device;
|
||||
import com.midm.model.message.MidmPacket;
|
||||
import com.midm.model.message.MidmQuery;
|
||||
import com.midm.model.org.User;
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import com.mitac.cell.utils.McDateTimeUtils;
|
||||
import com.mitac.cell.utils.McEmailUtils;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import org.joda.time.DateTime;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
import org.springframework.data.mongodb.core.mapping.DBRef;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class NewsMessage {
|
||||
@Id
|
||||
private UUID uuid;
|
||||
@DBRef
|
||||
private User writer;
|
||||
private String category;
|
||||
private String forWhat;
|
||||
private DbObject reference;
|
||||
private DbObject message;
|
||||
private Boolean isUnremovable;
|
||||
private Boolean isEnabled;
|
||||
private Date sendSchedule;
|
||||
private Date expiry;
|
||||
@Transient
|
||||
private boolean sendNow;
|
||||
private Date created;
|
||||
private Date updated;
|
||||
|
||||
public NewsMessage(Device device, String category) {
|
||||
this.init();
|
||||
this.category = "device_" + category;
|
||||
this.reference.put("uuid", device.getUuid());
|
||||
}
|
||||
|
||||
public NewsMessage(Device device) {
|
||||
this.init();
|
||||
this.reference.put("uuid", device.getUuid());
|
||||
}
|
||||
|
||||
public NewsMessage(MidmPacket packet) {
|
||||
MidmQuery query = packet.getQuery();
|
||||
this.setUuid(query.getUuid());
|
||||
this.created = query.getRegisteredAt();
|
||||
this.updated = this.created;
|
||||
String request = query.getRequest();
|
||||
String command = query.getCommand();
|
||||
this.category = String.format("%s_%s", request, command);
|
||||
this.getReference().put("userUuid", query.getSenderUuid());
|
||||
this.getReference().put("deviceUuid", packet.getRecieverUuid());
|
||||
this.getReference().put("query", query.getQuery());
|
||||
}
|
||||
|
||||
public NewsMessage() {
|
||||
this.init();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
this.uuid = UUID.randomUUID();
|
||||
this.created = new Date();
|
||||
this.updated = this.created;
|
||||
}
|
||||
|
||||
public DbObject getMessage() {
|
||||
if (this.message == null) {
|
||||
this.message = new DbObject();
|
||||
}
|
||||
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public DbObject getMessage(Locale locale) {
|
||||
return this.getMessage(locale.toLanguageTag());
|
||||
}
|
||||
|
||||
public DbObject getMessage(String languageTag) {
|
||||
DbObject message = this.getMessage();
|
||||
DbObject localedMessage = new DbObject();
|
||||
if (message.get(languageTag) == null) {
|
||||
message.put(languageTag, localedMessage);
|
||||
} else if (message.get(languageTag) instanceof LinkedTreeMap) {
|
||||
for(Map.Entry entry : ((LinkedTreeMap)message.get(languageTag)).entrySet()) {
|
||||
localedMessage.append((String)entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
message.put(languageTag, localedMessage);
|
||||
} else if (message.get(languageTag) instanceof DbObject) {
|
||||
localedMessage = (DbObject)message.get(languageTag);
|
||||
message.put(languageTag, localedMessage);
|
||||
} else if (message.get(languageTag) instanceof org.bson.Document) {
|
||||
for(Map.Entry entry : ((org.bson.Document)message.get(languageTag)).entrySet()) {
|
||||
localedMessage.append((String)entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
message.put(languageTag, localedMessage);
|
||||
}
|
||||
|
||||
return localedMessage;
|
||||
}
|
||||
|
||||
public void setMessage(DbObject message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public void setMessage(String title, String content) {
|
||||
this.setTitle(title);
|
||||
this.setContent(content);
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return this.getMessage("en-US").getString("title");
|
||||
}
|
||||
|
||||
public String getSummary() {
|
||||
return this.getMessage().getString("summary");
|
||||
}
|
||||
|
||||
public boolean hasContent() {
|
||||
return this.getMessage().containsKey("content");
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return this.getMessage("en-US").getString("content");
|
||||
}
|
||||
|
||||
public String getTitle(String locale) {
|
||||
return this.getMessage(locale).getString("title");
|
||||
}
|
||||
|
||||
public String getSummary(String locale) {
|
||||
return this.getMessage(locale).getString("summary");
|
||||
}
|
||||
|
||||
public boolean hasContent(String locale) {
|
||||
return this.getMessage(locale).containsKey("content");
|
||||
}
|
||||
|
||||
public String getContent(String locale) {
|
||||
return this.getMessage(locale).getString("content");
|
||||
}
|
||||
|
||||
public List getMailsTo() {
|
||||
return McEmailUtils.parseMails(this.getMessage().getString("to"));
|
||||
}
|
||||
|
||||
public void setMessage(String title, String content, String summary) {
|
||||
this.setMessage(Locale.US.toLanguageTag(), title, content, summary);
|
||||
}
|
||||
|
||||
public void setMessage(String languageTag, String title, String content, String summary) {
|
||||
this.setTitle(languageTag, title);
|
||||
this.setContent(languageTag, content);
|
||||
this.setSummary(languageTag, summary);
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.setTitle(Locale.US.toLanguageTag(), title);
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.setContent(Locale.US.toLanguageTag(), content);
|
||||
}
|
||||
|
||||
public void setSummary(String summary) {
|
||||
this.setSummary(Locale.US.toLanguageTag(), summary);
|
||||
}
|
||||
|
||||
public void setTitle(String languageTag, String title) {
|
||||
DbObject message = this.getMessage(languageTag);
|
||||
message.put("title", title);
|
||||
}
|
||||
|
||||
public void setContent(String languageTag, String content) {
|
||||
DbObject message = this.getMessage(languageTag);
|
||||
message.put("content", content);
|
||||
}
|
||||
|
||||
public DbObject getReference() {
|
||||
if (this.reference == null) {
|
||||
this.reference = new DbObject();
|
||||
}
|
||||
|
||||
return this.reference;
|
||||
}
|
||||
|
||||
public void setReference(DbObject reference) {
|
||||
this.reference = reference;
|
||||
}
|
||||
|
||||
public void setSummary(String languageTag, String summary) {
|
||||
DbObject message = this.getMessage(languageTag);
|
||||
message.put("summary", summary);
|
||||
}
|
||||
|
||||
public Boolean isUnremovable() {
|
||||
return this.isUnremovable;
|
||||
}
|
||||
|
||||
public void setIsUnremovable(Boolean isUnremovable) {
|
||||
this.isUnremovable = isUnremovable;
|
||||
}
|
||||
|
||||
public String getForWhat() {
|
||||
return this.forWhat;
|
||||
}
|
||||
|
||||
public void setForWhat(String forWhat) {
|
||||
this.forWhat = forWhat;
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
public void setUuid(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public User getWriter() {
|
||||
return this.writer;
|
||||
}
|
||||
|
||||
public void setWriter(User writer) {
|
||||
this.writer = writer;
|
||||
}
|
||||
|
||||
public String getCategory() {
|
||||
return this.category;
|
||||
}
|
||||
|
||||
public void setCategory(String category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public Date getSendSchedule() {
|
||||
return this.sendSchedule;
|
||||
}
|
||||
|
||||
public void setSendSchedule(Date sendSchedule) {
|
||||
this.sendSchedule = sendSchedule;
|
||||
}
|
||||
|
||||
public boolean sendNow() {
|
||||
return this.sendNow || this.sendSchedule == null || McDateTimeUtils.isSameDate(new DateTime(this.sendSchedule), DateTime.now());
|
||||
}
|
||||
|
||||
public Date getExpiry() {
|
||||
return this.expiry;
|
||||
}
|
||||
|
||||
public void setExpiry(Date expiry) {
|
||||
this.expiry = expiry;
|
||||
}
|
||||
|
||||
public Date getCreated() {
|
||||
return this.created;
|
||||
}
|
||||
|
||||
public void setCreated(Date created) {
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
public Date getUpdated() {
|
||||
return this.updated;
|
||||
}
|
||||
|
||||
public void setUpdated(Date updated) {
|
||||
this.updated = updated;
|
||||
}
|
||||
|
||||
public Boolean getIsUnremovable() {
|
||||
return this.isUnremovable;
|
||||
}
|
||||
|
||||
public Boolean isEnabled() {
|
||||
return this.isEnabled;
|
||||
}
|
||||
|
||||
public void setIsEnabled(Boolean isEnabled) {
|
||||
this.isEnabled = isEnabled;
|
||||
}
|
||||
|
||||
public boolean isSendNow() {
|
||||
return this.sendNow;
|
||||
}
|
||||
|
||||
public void setSendNow(boolean sendNow) {
|
||||
this.sendNow = sendNow;
|
||||
}
|
||||
|
||||
public String toDateString(String dateString, String format) {
|
||||
DateTime dateTime = new DateTime(dateString);
|
||||
return McDateTimeUtils.toString(dateTime, format);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,383 @@
|
||||
package com.midm.model.org;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.midm.model.GeneralProfile;
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import com.mitac.cell.utils.McUuidUtils;
|
||||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
import java.util.UUID;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
import org.springframework.data.mongodb.core.index.Indexed;
|
||||
import org.springframework.data.mongodb.core.mapping.DBRef;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class Site extends GeneralProfile {
|
||||
public static final String MODEL_MIDM = "midm";
|
||||
public static final String MODEL_MUST = "must";
|
||||
@DBRef
|
||||
private Site reseller;
|
||||
@Indexed(
|
||||
unique = true
|
||||
)
|
||||
private String idName;
|
||||
@Transient
|
||||
private Date latestVisit;
|
||||
@Transient
|
||||
private DbObject report;
|
||||
|
||||
public Site() {
|
||||
this.setEnabled(false);
|
||||
}
|
||||
|
||||
public Site(String model) {
|
||||
this();
|
||||
this.setModel(model);
|
||||
}
|
||||
|
||||
public void init() {
|
||||
this.setUuid(UUID.randomUUID());
|
||||
DbObject notiSettings = new DbObject("sendEmail", true);
|
||||
DbObject notiRoles = new DbObject("enabled", true);
|
||||
notiRoles.append("roles", new DbObject("SUPERVISOR", true));
|
||||
DbObject supportSettings = new DbObject("general", notiRoles);
|
||||
supportSettings.append("maintenance", notiRoles).append("urgent", notiRoles);
|
||||
notiSettings.append("support", supportSettings);
|
||||
this.setSetting("noti", notiSettings);
|
||||
this.setCreated(new Date());
|
||||
}
|
||||
|
||||
public Site getReseller() {
|
||||
return this.reseller;
|
||||
}
|
||||
|
||||
public void setReseller(Site reseller) {
|
||||
this.reseller = reseller;
|
||||
}
|
||||
|
||||
public boolean isChild() {
|
||||
return this.reseller != null;
|
||||
}
|
||||
|
||||
public boolean canCustomize() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Object getDomainName() {
|
||||
return this.getSetting("domainName");
|
||||
}
|
||||
|
||||
public String getIdName() {
|
||||
return this.idName;
|
||||
}
|
||||
|
||||
public void setIdName(String idName) {
|
||||
this.idName = idName;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
String siteName = (String)this.getSetting("theme", "siteName");
|
||||
return Strings.isNullOrEmpty(siteName) ? this.getName() : siteName;
|
||||
}
|
||||
|
||||
public boolean hasLogo() {
|
||||
return this.getSettingAsBoolean("theme", "logo", false);
|
||||
}
|
||||
|
||||
public DbObject getPlan() {
|
||||
return this.getProfileCategory(new String[]{"plan"});
|
||||
}
|
||||
|
||||
public String getPlanName() {
|
||||
DbObject plan = this.getPlan();
|
||||
return plan.getString("plan", "standard");
|
||||
}
|
||||
|
||||
public String getShowPlanName() {
|
||||
String planName = this.getPlanName();
|
||||
return this.getShowPlanName(planName);
|
||||
}
|
||||
|
||||
public String getShowPlanName(String planName) {
|
||||
String name = "";
|
||||
if (planName.equals("lite")) {
|
||||
name = "Lite";
|
||||
} else if (planName.equals("standard")) {
|
||||
name = "Standard";
|
||||
} else if (planName.equals("standardWithBatteryPro")) {
|
||||
name = "Std + Batt Pro";
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setPlan(DbObject plan) {
|
||||
this.setProfile("plan", plan);
|
||||
}
|
||||
|
||||
public void setPlan(String plan) {
|
||||
if (!Strings.isNullOrEmpty(plan)) {
|
||||
this.setProfile("plan", "plan", plan);
|
||||
DbObject profilePlan = this.getProfile().getDbObject(new String[]{"plan"});
|
||||
if (plan.equals("standard")) {
|
||||
profilePlan.remove("features");
|
||||
}
|
||||
|
||||
profilePlan.remove("upgradeStatus");
|
||||
}
|
||||
}
|
||||
|
||||
public String getUpgradeStatus() {
|
||||
DbObject plan = this.getPlan();
|
||||
return plan.getString("upgradeStatus");
|
||||
}
|
||||
|
||||
public boolean isUpgradeRequested() {
|
||||
return "processing".equals(this.getUpgradeStatus());
|
||||
}
|
||||
|
||||
public String getUpgradeTargetPlan() {
|
||||
DbObject plan = this.getPlan();
|
||||
return plan.getString("targetPlan");
|
||||
}
|
||||
|
||||
public String getModel() {
|
||||
return (String)this.getProfile("model", "midm");
|
||||
}
|
||||
|
||||
public void setModel(String model) {
|
||||
this.setProfile("model", model);
|
||||
}
|
||||
|
||||
public String getPhone() {
|
||||
return (String)this.getProfile("phone");
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return (String)this.getProfile("address");
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
return (String)this.getProfile("country");
|
||||
}
|
||||
|
||||
public boolean isReseller() {
|
||||
return (Boolean)this.getProfile("isReseller", false);
|
||||
}
|
||||
|
||||
public void setIsReseller(boolean isReseller) {
|
||||
this.setProfile("isReseller", isReseller);
|
||||
}
|
||||
|
||||
public boolean limitRegisteredDeviceOnly() {
|
||||
return this.getSettingAsBoolean("enrollment", "registeredOnly", false);
|
||||
}
|
||||
|
||||
public Date getLatestVisit() {
|
||||
return this.latestVisit;
|
||||
}
|
||||
|
||||
public void setLatestVisit(Date latestVisit) {
|
||||
this.latestVisit = latestVisit;
|
||||
}
|
||||
|
||||
public DbObject getCredential() {
|
||||
return this.getSettings().getDbObject(new String[]{"credential"});
|
||||
}
|
||||
|
||||
public boolean isCredentialMatched(String credential) {
|
||||
if (Strings.isNullOrEmpty(credential)) {
|
||||
return false;
|
||||
} else {
|
||||
DbObject credentialSettings = this.getCredential();
|
||||
if (credentialSettings != null && !credentialSettings.isEmpty()) {
|
||||
String siteCredential = credentialSettings.getString("credential");
|
||||
long cridentialExpiry = credentialSettings.getLong("expiry");
|
||||
return (cridentialExpiry == -1L || cridentialExpiry > (new Date()).getTime()) && credential.equals(siteCredential);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setCredential(String credential) {
|
||||
if (!Strings.isNullOrEmpty(credential)) {
|
||||
DbObject value = new DbObject("credential", credential);
|
||||
value.append("expiry", -1);
|
||||
this.setSetting("credential", value);
|
||||
} else {
|
||||
this.getSettings().remove("credential");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void renewCredential() {
|
||||
String credential = McUuidUtils.toBase64String(UUID.randomUUID(), true);
|
||||
this.setCredential(credential);
|
||||
}
|
||||
|
||||
public DbObject getSettings() {
|
||||
DbObject settings = super.getSettings();
|
||||
if (settings.get("theme") == null) {
|
||||
DbObject themeSettings = new DbObject();
|
||||
themeSettings.put("skinColor", "steelblue");
|
||||
themeSettings.put("logo", false);
|
||||
settings.put("theme", themeSettings);
|
||||
}
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
public DbObject getReport() {
|
||||
if (this.report == null) {
|
||||
this.report = new DbObject();
|
||||
}
|
||||
|
||||
return this.report;
|
||||
}
|
||||
|
||||
public void setReport(DbObject report) {
|
||||
this.report = report;
|
||||
}
|
||||
|
||||
public void addReport(String key, Object value) {
|
||||
this.getReport().put(key, value);
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (obj.hashCode() == this.hashCode()) {
|
||||
return true;
|
||||
} else if (obj instanceof Site) {
|
||||
Site site = (Site)obj;
|
||||
return this.getUuid().equals(site.getUuid());
|
||||
} else if (obj instanceof SiteInfo) {
|
||||
SiteInfo siteInfo = (SiteInfo)obj;
|
||||
return this.getUuid().equals(siteInfo.getSiteUuid());
|
||||
} else {
|
||||
return obj instanceof UUID ? this.getUuid().equals((UUID)obj) : false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isLite() {
|
||||
return this.getPlanName().equals("lite");
|
||||
}
|
||||
|
||||
public boolean isStandard() {
|
||||
return this.getPlanName().equals("standard");
|
||||
}
|
||||
|
||||
public boolean isStandardWithBatteryPro() {
|
||||
return this.getPlanName().equals("standardWithBatteryPro");
|
||||
}
|
||||
|
||||
public boolean isMust() {
|
||||
return this.getModel().equals("must");
|
||||
}
|
||||
|
||||
public void setMust(boolean isMust) {
|
||||
this.setModel("must");
|
||||
}
|
||||
|
||||
public boolean isFeatureAllowed(String subCategory, String item) {
|
||||
return !this.isLite() ? true : this.getProfileAsBoolean("plan", "features", subCategory, item, false);
|
||||
}
|
||||
|
||||
public DbObject getNotificationSettings() {
|
||||
return this.getSettingsCategory(new String[]{"noti"});
|
||||
}
|
||||
|
||||
public boolean notifyViaMail() {
|
||||
return this.getNotificationSettings().getBoolean("sendEmail", false);
|
||||
}
|
||||
|
||||
public void setNotifyViaMail(boolean viaMail) {
|
||||
this.getNotificationSettings().put("sendEmail", viaMail);
|
||||
}
|
||||
|
||||
public boolean notifyDeviceErrorMail() {
|
||||
return this.getNotificationSettings().getBoolean("sendDeviceErrorEmail", false);
|
||||
}
|
||||
|
||||
public void setNotifyDeviceErrorMail(boolean enable) {
|
||||
this.getNotificationSettings().put("sendDeviceErrorEmail", enable);
|
||||
}
|
||||
|
||||
public boolean notifyBatteryConditionMail() {
|
||||
return this.getNotificationSettings().getBoolean("sendBatteryConditionEmail", false);
|
||||
}
|
||||
|
||||
public void setNotifyBatteryConditionMail(boolean enable) {
|
||||
this.getNotificationSettings().put("sendBatteryConditionEmail", enable);
|
||||
}
|
||||
|
||||
public void setNotificationSettings(String category, String forWhat, boolean isEnabled) {
|
||||
this.setNotificationSettings(category, forWhat, isEnabled, (Set)null);
|
||||
}
|
||||
|
||||
public void setNotificationSettings(String category, String forWhat, boolean isEnabled, Set roles) {
|
||||
DbObject settings = this.getSettingsCategory(new String[]{"noti", category, forWhat});
|
||||
settings.put("isEnabled", isEnabled);
|
||||
if (roles == null) {
|
||||
settings.remove("roles");
|
||||
} else {
|
||||
settings.put("roles", roles);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setNotificationSettings(String category, String forWhat, String key, String value) {
|
||||
DbObject settings = this.getSettingsCategory(new String[]{"noti", category, forWhat});
|
||||
settings.put(key, value);
|
||||
}
|
||||
|
||||
public String getDataUsage() {
|
||||
return this.getSettingsCategory(new String[]{"report"}).getString("dataUsage", "none");
|
||||
}
|
||||
|
||||
public boolean collectDataUsage() {
|
||||
return !this.getDataUsage().equals("none");
|
||||
}
|
||||
|
||||
public Set getMessageRoles(String category, String forWhat) {
|
||||
DbObject settings = this.getSettingsCategory(new String[]{"noti", category, forWhat});
|
||||
if (settings.getBoolean("enabled")) {
|
||||
Object value = settings.get("roles");
|
||||
if (value instanceof Set) {
|
||||
return (Set)value;
|
||||
} else {
|
||||
DbObject dt = (DbObject)value;
|
||||
return dt.keySet();
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasTimeZone() {
|
||||
return this.getSetting("general", "timeZone") != null;
|
||||
}
|
||||
|
||||
public void setTimeZone(TimeZone timeZone) {
|
||||
this.setSetting("general", "timeZone", timeZone.getID());
|
||||
}
|
||||
|
||||
public TimeZone getTimeZone() {
|
||||
Object timeZone = this.getSetting("general", "timeZone");
|
||||
return timeZone != null ? TimeZone.getTimeZone((String)timeZone) : TimeZone.getDefault();
|
||||
}
|
||||
|
||||
public String[] getIncludeApps() {
|
||||
String installApps = this.getSettingsCategory(new String[]{"report"}).getString("installApps");
|
||||
return Strings.isNullOrEmpty(installApps) ? null : installApps.split("[,;\\s]+");
|
||||
}
|
||||
|
||||
public DbObject getCallbackSetting() {
|
||||
return this.getSettingsCategory(new String[]{"callback"});
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.format("%s(%s):%s", this.getName(), this.getIdName(), this.getUuid());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.midm.model.org;
|
||||
|
||||
import com.midm.model.file.BaseFile;
|
||||
import com.mitac.cell.io.McFile;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import org.springframework.data.mongodb.core.mapping.DBRef;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class SiteFile extends BaseFile {
|
||||
private String category;
|
||||
private String forWhat;
|
||||
private Date requested;
|
||||
private Date expiry;
|
||||
private String siteName;
|
||||
@DBRef
|
||||
private User requestedFrom;
|
||||
|
||||
public SiteFile() {
|
||||
}
|
||||
|
||||
public SiteFile(User requestedFrom, UUID fileUuid, McFile file) {
|
||||
this.setUserUuid(requestedFrom);
|
||||
this.setFileUuid(fileUuid);
|
||||
this.setFileInfo(file);
|
||||
}
|
||||
|
||||
public String getCategory() {
|
||||
return this.category;
|
||||
}
|
||||
|
||||
public void setCategory(String category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public User getRequestedFrom() {
|
||||
return this.requestedFrom;
|
||||
}
|
||||
|
||||
public void setRequestedFrom(User requestedFrom) {
|
||||
this.requestedFrom = requestedFrom;
|
||||
}
|
||||
|
||||
public Date getRequested() {
|
||||
return this.requested;
|
||||
}
|
||||
|
||||
public void setRequested(Date requested) {
|
||||
this.requested = requested;
|
||||
}
|
||||
|
||||
public Date getExpiry() {
|
||||
return this.expiry;
|
||||
}
|
||||
|
||||
public void setExpiry(Date expiry) {
|
||||
this.expiry = expiry;
|
||||
}
|
||||
|
||||
public String getSiteName() {
|
||||
return this.siteName;
|
||||
}
|
||||
|
||||
public void setSiteName(String siteName) {
|
||||
this.siteName = siteName;
|
||||
}
|
||||
|
||||
public String getForWhat() {
|
||||
return this.forWhat;
|
||||
}
|
||||
|
||||
public void setForWhat(String forWhat) {
|
||||
this.forWhat = forWhat;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
package com.midm.model.org;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import org.springframework.data.mongodb.core.index.Indexed;
|
||||
|
||||
public class SiteInfo {
|
||||
@Indexed
|
||||
private UUID siteUuid;
|
||||
private Set roles;
|
||||
private UUID groupUuid;
|
||||
protected DbObject settings;
|
||||
private Boolean apiOnly;
|
||||
private Date created;
|
||||
private Date updated;
|
||||
private boolean enabled;
|
||||
|
||||
public SiteInfo() {
|
||||
this.setRoles(new HashSet());
|
||||
this.setCreated(new Date());
|
||||
this.setUpdated(new Date());
|
||||
this.setEnabled(false);
|
||||
}
|
||||
|
||||
public SiteInfo(UUID siteUuid) {
|
||||
this();
|
||||
this.setSiteUuid(siteUuid);
|
||||
}
|
||||
|
||||
public UUID getSiteUuid() {
|
||||
return this.siteUuid;
|
||||
}
|
||||
|
||||
public void setSiteUuid(UUID siteUuid) {
|
||||
this.siteUuid = siteUuid;
|
||||
}
|
||||
|
||||
public Set getRoles() {
|
||||
if (this.roles == null) {
|
||||
this.roles = new HashSet();
|
||||
}
|
||||
|
||||
return this.roles;
|
||||
}
|
||||
|
||||
public boolean hasRole(String role) {
|
||||
return this.isEnabled() && !this.getRoles().isEmpty() && this.getRoles().contains(role);
|
||||
}
|
||||
|
||||
public boolean hasRole(Collection roles) {
|
||||
if (this.isEnabled() && !this.getRoles().isEmpty()) {
|
||||
for(String role : roles) {
|
||||
if (this.getRoles().contains(role)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addRole(String role) {
|
||||
role = UserRole.toRole(role);
|
||||
if (!Strings.isNullOrEmpty(role)) {
|
||||
this.getRoles().add(role);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setRoles(Set roles) {
|
||||
if (roles != null && !roles.isEmpty()) {
|
||||
for(String role : roles) {
|
||||
role = UserRole.toRole(role);
|
||||
if (!Strings.isNullOrEmpty(role) && !this.hasRole("SUPERVISOR")) {
|
||||
if (role.equals("SUPERVISOR")) {
|
||||
this.getRoles().clear();
|
||||
this.getRoles().add(role);
|
||||
} else {
|
||||
this.getRoles().add(role);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.roles = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void clearRoles() {
|
||||
this.getRoles().clear();
|
||||
}
|
||||
|
||||
public UUID getGroupUuid() {
|
||||
return this.groupUuid;
|
||||
}
|
||||
|
||||
public void setGroupUuid(UUID groupUuid) {
|
||||
this.groupUuid = groupUuid;
|
||||
}
|
||||
|
||||
public boolean isApiOnly() {
|
||||
return this.apiOnly != null && this.apiOnly;
|
||||
}
|
||||
|
||||
public void setApiOnly(boolean apiOnly) {
|
||||
this.apiOnly = apiOnly;
|
||||
}
|
||||
|
||||
public DbObject getSettings() {
|
||||
if (this.settings == null) {
|
||||
this.settings = new DbObject();
|
||||
}
|
||||
|
||||
return this.settings;
|
||||
}
|
||||
|
||||
public void setSettings(DbObject settings) {
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
public void setSetting(String key, Object value) {
|
||||
this.getSettings().put(key, value);
|
||||
}
|
||||
|
||||
public Object getSetting(String key) {
|
||||
return this.getSettings().get(key);
|
||||
}
|
||||
|
||||
public String getSettingAsString(String key) {
|
||||
return this.getSettings().getString(key, (String)null);
|
||||
}
|
||||
|
||||
public DbObject getPageSetting(String url) {
|
||||
return this.getSettings().getDbObject(new String[]{"page", url});
|
||||
}
|
||||
|
||||
public void setPageSetting(String url, String key, Object value) {
|
||||
this.getPageSetting(url).put(key, value);
|
||||
}
|
||||
|
||||
public Date getCreated() {
|
||||
return this.created;
|
||||
}
|
||||
|
||||
public void setCreated(Date created) {
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
public Date getUpdated() {
|
||||
return this.updated;
|
||||
}
|
||||
|
||||
public void setUpdated(Date updated) {
|
||||
this.updated = updated;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,267 @@
|
||||
package com.midm.model.org;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.midm.model.system.LicenseModel;
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
import org.springframework.data.mongodb.core.mapping.DBRef;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class SiteLicense {
|
||||
@Id
|
||||
private UUID uuid;
|
||||
@DBRef
|
||||
private Site site;
|
||||
@DBRef
|
||||
private Site childSite;
|
||||
@Transient
|
||||
private User writer;
|
||||
@DBRef
|
||||
private LicenseModel licenseModel;
|
||||
private int amount;
|
||||
private DbObject reference;
|
||||
private String plan;
|
||||
@Transient
|
||||
private DbObject report;
|
||||
private STATUS status;
|
||||
private boolean enabled;
|
||||
private Date updated;
|
||||
private Date created;
|
||||
|
||||
public SiteLicense() {
|
||||
this.plan = "standard";
|
||||
this.status = SiteLicense.STATUS.UNKNOWN;
|
||||
this.uuid = UUID.randomUUID();
|
||||
this.enabled = true;
|
||||
this.setCreated(new Date());
|
||||
}
|
||||
|
||||
public SiteLicense(Site site) {
|
||||
this();
|
||||
this.setSite(site);
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
public void setUuid(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public Site getSite() {
|
||||
return this.site;
|
||||
}
|
||||
|
||||
public void setSite(Site site) {
|
||||
if (site.isChild()) {
|
||||
this.site = site.getReseller();
|
||||
this.childSite = site;
|
||||
} else {
|
||||
this.site = site;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Site getChildSite() {
|
||||
return this.childSite;
|
||||
}
|
||||
|
||||
public boolean isForChildSite() {
|
||||
return this.childSite != null;
|
||||
}
|
||||
|
||||
public void setChildSite(Site reseller) {
|
||||
this.childSite = reseller;
|
||||
}
|
||||
|
||||
public User getWriter() {
|
||||
return this.writer;
|
||||
}
|
||||
|
||||
public void setWriter(User user) {
|
||||
this.writer = user;
|
||||
}
|
||||
|
||||
public String getPlan() {
|
||||
return this.plan;
|
||||
}
|
||||
|
||||
public void setPlan(String plan) {
|
||||
this.plan = plan;
|
||||
}
|
||||
|
||||
public boolean isLite() {
|
||||
return "lite".equals(this.getPlan());
|
||||
}
|
||||
|
||||
public LicenseModel getLicenseModel() {
|
||||
return this.licenseModel;
|
||||
}
|
||||
|
||||
public void setLicenseModel(LicenseModel licenseModel) {
|
||||
if (this.isUpdated() && !this.licenseModel.getUuid().equals(licenseModel.getUuid())) {
|
||||
this.addNote("License model changed: " + licenseModel.getName());
|
||||
}
|
||||
|
||||
this.licenseModel = licenseModel;
|
||||
}
|
||||
|
||||
public Character getType() {
|
||||
return this.licenseModel.getType();
|
||||
}
|
||||
|
||||
public Integer getPeriod() {
|
||||
return this.licenseModel.getPeriod();
|
||||
}
|
||||
|
||||
public int getAmount() {
|
||||
return this.amount;
|
||||
}
|
||||
|
||||
public void setAmount(int amount) {
|
||||
if (this.isUpdated() && this.amount != amount) {
|
||||
this.addNote("Amount changed: " + amount);
|
||||
}
|
||||
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public DbObject getReference() {
|
||||
if (this.reference == null) {
|
||||
this.reference = new DbObject();
|
||||
}
|
||||
|
||||
return this.reference;
|
||||
}
|
||||
|
||||
public void setReference(DbObject reference) {
|
||||
this.reference = reference;
|
||||
}
|
||||
|
||||
public String getPo() {
|
||||
return this.getReference().getString("po", "");
|
||||
}
|
||||
|
||||
public void setPo(String po) {
|
||||
if (this.isUpdated() && !this.getPo().equals(po)) {
|
||||
this.addNote(Strings.isNullOrEmpty(po) ? "PO has unset" : "PO changed: " + po);
|
||||
}
|
||||
|
||||
this.getReference().put("po", po);
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return this.getReference().getString("desc", "");
|
||||
}
|
||||
|
||||
public void setDesc(String desc) {
|
||||
this.getReference().put("desc", desc);
|
||||
}
|
||||
|
||||
public List getNotes() {
|
||||
return this.getReference().getList("notes", DbObject.class);
|
||||
}
|
||||
|
||||
public void addNote(STATUS status) {
|
||||
if (this.isUpdated()) {
|
||||
this.addNote("Status changed: " + status);
|
||||
} else {
|
||||
this.addNote(String.format("%s: %s, %,d licenses", status, this.licenseModel.getName(), this.amount));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void addNote(String note) {
|
||||
DbObject noteObj = new DbObject("name", this.writer.getName());
|
||||
noteObj.append("email", this.writer.getEmail()).append("note", note).append("updated", this.updated);
|
||||
List<DbObject> notes = this.getNotes();
|
||||
if (notes == null) {
|
||||
notes = new ArrayList();
|
||||
this.getReference().append("notes", notes);
|
||||
}
|
||||
|
||||
notes.add(noteObj);
|
||||
}
|
||||
|
||||
public boolean getEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public Date getUpdated() {
|
||||
return this.updated;
|
||||
}
|
||||
|
||||
public void setUpdated(Date updated) {
|
||||
this.updated = updated;
|
||||
}
|
||||
|
||||
private boolean isUpdated() {
|
||||
return !this.created.equals(this.updated);
|
||||
}
|
||||
|
||||
public void updated() {
|
||||
this.updated = new Date();
|
||||
}
|
||||
|
||||
public Date getCreated() {
|
||||
return this.created;
|
||||
}
|
||||
|
||||
public void setCreated(Date created) {
|
||||
this.created = created;
|
||||
this.updated = created;
|
||||
}
|
||||
|
||||
public DbObject getReport() {
|
||||
if (this.report == null) {
|
||||
this.report = new DbObject();
|
||||
}
|
||||
|
||||
return this.report;
|
||||
}
|
||||
|
||||
public void setReport(DbObject report) {
|
||||
this.report = report;
|
||||
}
|
||||
|
||||
public void setReport(String key, Object value) {
|
||||
this.getReport().put(key, value);
|
||||
}
|
||||
|
||||
public boolean isTrial() {
|
||||
return this.getLicenseModel().isTrial();
|
||||
}
|
||||
|
||||
public boolean isPerpetual() {
|
||||
return this.getLicenseModel().isPerpetual();
|
||||
}
|
||||
|
||||
public STATUS getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
public void setStatus(STATUS status) {
|
||||
this.addNote(status);
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public static enum STATUS {
|
||||
ORDERED,
|
||||
PROCESSING,
|
||||
CONFIRMED,
|
||||
REJECTED,
|
||||
CANCELED,
|
||||
UNKNOWN;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.midm.model.org;
|
||||
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import java.util.UUID;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class SitePlan {
|
||||
@Id
|
||||
private UUID uuid;
|
||||
private String model = "midm";
|
||||
private DbObject plan;
|
||||
private boolean isReseller = false;
|
||||
|
||||
public UUID getUuid() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
public void setUuid(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public String getModel() {
|
||||
return this.model;
|
||||
}
|
||||
|
||||
public void setModel(String model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
public DbObject getPlan() {
|
||||
return this.plan;
|
||||
}
|
||||
|
||||
public void setPlan(DbObject plan) {
|
||||
this.plan = plan;
|
||||
}
|
||||
|
||||
public boolean isReseller() {
|
||||
return this.isReseller;
|
||||
}
|
||||
|
||||
public void setReseller(boolean isReseller) {
|
||||
this.isReseller = isReseller;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.midm.model.org;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class SiteRequest {
|
||||
@Id
|
||||
private UUID uuid;
|
||||
private String name;
|
||||
private String email;
|
||||
private String company;
|
||||
private String title;
|
||||
private String phone;
|
||||
private String country;
|
||||
private String industry;
|
||||
private Date requestedAt;
|
||||
|
||||
public UUID getUuid() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
public void setUuid(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return this.email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getCompany() {
|
||||
return this.company;
|
||||
}
|
||||
|
||||
public void setCompany(String company) {
|
||||
this.company = company;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getPhone() {
|
||||
return this.phone;
|
||||
}
|
||||
|
||||
public void setPhone(String phone) {
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
return this.country;
|
||||
}
|
||||
|
||||
public void setCountry(String country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
public String getIndustry() {
|
||||
return this.industry;
|
||||
}
|
||||
|
||||
public void setIndustry(String industry) {
|
||||
this.industry = industry;
|
||||
}
|
||||
|
||||
public Date getRequestedAt() {
|
||||
return this.requestedAt;
|
||||
}
|
||||
|
||||
public void setRequestedAt(Date requestedAt) {
|
||||
this.requestedAt = requestedAt;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.midm.model.org;
|
||||
|
||||
public enum USER_PROPERTY {
|
||||
email,
|
||||
email_addr,
|
||||
email_address,
|
||||
role,
|
||||
roles,
|
||||
mail,
|
||||
name,
|
||||
password,
|
||||
pwd,
|
||||
group,
|
||||
title,
|
||||
position,
|
||||
tel,
|
||||
phone,
|
||||
telephone,
|
||||
mobile,
|
||||
mobilephone,
|
||||
mobile_phone,
|
||||
unknown;
|
||||
|
||||
public static USER_PROPERTY get(String key) {
|
||||
try {
|
||||
return valueOf(key.trim().toLowerCase());
|
||||
} catch (Exception var2) {
|
||||
return unknown;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,687 @@
|
||||
package com.midm.model.org;
|
||||
|
||||
import com.google.api.client.util.Strings;
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.midm.constant.LocaleConst;
|
||||
import com.midm.model.GeneralProfile;
|
||||
import com.midm.model.system.PolicyAgreement;
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import com.mitac.cell.utils.McEmailUtils;
|
||||
import com.mitac.cell.utils.McStringUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
import org.springframework.data.mongodb.core.index.Indexed;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
||||
@Document
|
||||
public class User extends GeneralProfile {
|
||||
public static final int MAX_LOGIN_ATTEMPT = 5;
|
||||
public static final int LOGIN_AFTER_MINUTES = 10;
|
||||
@Indexed
|
||||
private UUID siteUuid;
|
||||
@Indexed
|
||||
private String email;
|
||||
@Expose(
|
||||
serialize = false
|
||||
)
|
||||
private String password;
|
||||
private List sites;
|
||||
@Transient
|
||||
private boolean isMultiSiteUser;
|
||||
@Transient
|
||||
private boolean isApiUser;
|
||||
@Transient
|
||||
private SiteInfo siteInfo;
|
||||
private Set systemRoles;
|
||||
@Transient
|
||||
private UUID groupUuid;
|
||||
protected Date activated;
|
||||
@Transient
|
||||
private Site site;
|
||||
@Transient
|
||||
private UserGroup userGroup;
|
||||
|
||||
public User() {
|
||||
}
|
||||
|
||||
public User(UUID userUuid) {
|
||||
this.setUuid(userUuid);
|
||||
}
|
||||
|
||||
public User(String email) {
|
||||
this();
|
||||
this.setEmail(email);
|
||||
}
|
||||
|
||||
public User(String email, String password) {
|
||||
this(email);
|
||||
this.setPassword(password);
|
||||
}
|
||||
|
||||
public void init() {
|
||||
super.init();
|
||||
if (this.hasRole("SUPERVISOR") || this.hasSystemRole("SYSTEM_ADMIN")) {
|
||||
this.setEnabled(true);
|
||||
}
|
||||
|
||||
this.setActivated();
|
||||
if (Strings.isNullOrEmpty(super.getName())) {
|
||||
this.setName(this.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public UUID getSiteUuid() {
|
||||
if (this.siteUuid == null && !this.hasSystemRole()) {
|
||||
List<SiteInfo> sites = this.getSites();
|
||||
if (!sites.isEmpty()) {
|
||||
this.setSiteUuid(((SiteInfo)sites.get(0)).getSiteUuid());
|
||||
}
|
||||
}
|
||||
|
||||
return this.siteUuid;
|
||||
}
|
||||
|
||||
public void setSiteUuid(UUID siteUuid) {
|
||||
this.siteUuid = siteUuid;
|
||||
SiteInfo siteInfo = this.getSiteInfo(siteUuid);
|
||||
if (siteInfo != null) {
|
||||
this.setRoles(siteInfo.getRoles());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Site getSite() {
|
||||
return this.site;
|
||||
}
|
||||
|
||||
public void setSite(Site site) {
|
||||
this.site = site;
|
||||
}
|
||||
|
||||
public boolean isReseller() {
|
||||
return this.site != null && this.site.isReseller();
|
||||
}
|
||||
|
||||
public boolean isLite() {
|
||||
return this.site != null && this.site.isLite();
|
||||
}
|
||||
|
||||
public boolean isStandard() {
|
||||
return this.site != null && this.site.isStandard();
|
||||
}
|
||||
|
||||
public boolean isStandardWithBatteryPro() {
|
||||
return this.site != null && this.site.isStandardWithBatteryPro();
|
||||
}
|
||||
|
||||
public boolean isFeatureAllowed(String subCategory, String item) {
|
||||
return this.isLite() ? this.site != null && this.site.isFeatureAllowed(subCategory, item) : true;
|
||||
}
|
||||
|
||||
public boolean isFilesFeatureAllowed(String category, String key) {
|
||||
return this.isFeatureAllowed(category, key) && (this.hasRole("SUPERVISOR") || this.hasRole("PROFILE_MANAGER"));
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return this.email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
if (!Strings.isNullOrEmpty(email)) {
|
||||
if (McEmailUtils.isValid(email)) {
|
||||
this.email = email.toLowerCase();
|
||||
}
|
||||
|
||||
if (Strings.isNullOrEmpty(super.getName())) {
|
||||
this.setName(this.getName());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return this.password;
|
||||
}
|
||||
|
||||
public boolean setPassword(String password) {
|
||||
this.password = password;
|
||||
return !Strings.isNullOrEmpty(password) && password.length() >= 8 ? McStringUtils.hasUpperLowerDigit(password) : false;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
String name = super.getName();
|
||||
if (Strings.isNullOrEmpty(name)) {
|
||||
name = this.getEmail().substring(0, this.getEmail().indexOf("@"));
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setSiteInfo(SiteInfo siteInfo) {
|
||||
this.siteInfo = siteInfo;
|
||||
}
|
||||
|
||||
public List getSites() {
|
||||
if (this.sites == null) {
|
||||
this.sites = new ArrayList();
|
||||
}
|
||||
|
||||
return this.sites;
|
||||
}
|
||||
|
||||
public List getSiteUuids() {
|
||||
return this.sites != null && !this.sites.isEmpty() ? (List)this.sites.stream().map((item) -> item.getSiteUuid()).collect(Collectors.toList()) : null;
|
||||
}
|
||||
|
||||
public boolean clearUndefinedSites() {
|
||||
boolean hasChanges = false;
|
||||
if (this.sites != null) {
|
||||
Iterator<SiteInfo> it = this.sites.iterator();
|
||||
|
||||
while(it.hasNext()) {
|
||||
SiteInfo site = (SiteInfo)it.next();
|
||||
if (site.getSiteUuid() == null) {
|
||||
it.remove();
|
||||
hasChanges = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return hasChanges;
|
||||
}
|
||||
|
||||
public void setSites(List sites) {
|
||||
this.sites = sites;
|
||||
}
|
||||
|
||||
public boolean isMultiSiteUser() {
|
||||
return this.isMultiSiteUser;
|
||||
}
|
||||
|
||||
public void setMultiSiteUser() {
|
||||
this.isMultiSiteUser = this.getSites().size() > 1;
|
||||
if (!this.isMultiSiteUser) {
|
||||
this.isApiUser = this.isApiUser();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public SiteInfo getSiteInfo() {
|
||||
return this.getSiteInfo(this.getSiteUuid());
|
||||
}
|
||||
|
||||
public SiteInfo getSiteInfo(Site site) {
|
||||
return this.getSiteInfo(site.getUuid());
|
||||
}
|
||||
|
||||
public SiteInfo getSiteInfo(UUID siteUuid) {
|
||||
if (siteUuid == null) {
|
||||
return null;
|
||||
} else {
|
||||
for(SiteInfo siteInfo : this.getSites()) {
|
||||
if (siteInfo.getSiteUuid() != null && siteInfo.getSiteUuid().equals(siteUuid)) {
|
||||
return siteInfo;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isBelongedToSite(Site site) {
|
||||
return this.isBelongedToSite(site.getUuid());
|
||||
}
|
||||
|
||||
public boolean isBelongedToSite(UUID siteUuid) {
|
||||
for(SiteInfo siteInfo : this.getSites()) {
|
||||
if (siteInfo.getSiteUuid() != null && siteInfo.getSiteUuid().equals(siteUuid)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean canHandle(UUID siteUuid, String... roles) {
|
||||
SiteInfo info = this.getSiteInfo(siteUuid);
|
||||
if (info != null) {
|
||||
if (info.hasRole("SUPERVISOR")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for(String role : roles) {
|
||||
if (info.hasRole(role)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public SiteInfo addSite(UUID siteUuid) {
|
||||
if (siteUuid == null) {
|
||||
return null;
|
||||
} else {
|
||||
if (!this.isBelongedToSite(siteUuid)) {
|
||||
this.getSites().add(new SiteInfo(siteUuid));
|
||||
}
|
||||
|
||||
if (this.getSiteUuid() == null) {
|
||||
this.setSiteUuid(siteUuid);
|
||||
}
|
||||
|
||||
SiteInfo siteInfo = this.getSiteInfo(siteUuid);
|
||||
siteInfo.setEnabled(true);
|
||||
return siteInfo;
|
||||
}
|
||||
}
|
||||
|
||||
public void removeSite(UUID siteUuid) {
|
||||
if (siteUuid != null) {
|
||||
SiteInfo existSite = null;
|
||||
|
||||
for(SiteInfo siteInfo : this.getSites()) {
|
||||
if (siteInfo.getSiteUuid().equals(siteUuid)) {
|
||||
existSite = siteInfo;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (existSite != null) {
|
||||
this.getSites().remove(existSite);
|
||||
}
|
||||
|
||||
if (this.getSites().isEmpty()) {
|
||||
this.setSiteUuid((UUID)null);
|
||||
this.setGroupUuid((UUID)null);
|
||||
this.setLastSite((UUID)null);
|
||||
} else {
|
||||
if (siteUuid.equals(this.getSiteUuid())) {
|
||||
this.setSiteUuid((UUID)null);
|
||||
this.setGroupUuid((UUID)null);
|
||||
}
|
||||
|
||||
if (siteUuid.equals(this.getLastSite())) {
|
||||
this.setLastSite((UUID)null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public Set getRoles() {
|
||||
return this.getRolesBySite(this.getSiteUuid());
|
||||
}
|
||||
|
||||
public Set getRoles(UUID siteUuid) {
|
||||
return this.getRolesBySite(siteUuid);
|
||||
}
|
||||
|
||||
public Set getRolesBySite(UUID siteUuid) {
|
||||
SiteInfo info = this.getSiteInfo(siteUuid);
|
||||
return (Set)(info != null ? this.getSiteInfo(siteUuid).getRoles() : new HashSet());
|
||||
}
|
||||
|
||||
public void setRoles(Set roles) {
|
||||
SiteInfo info = this.getSiteInfo(this.getSiteUuid());
|
||||
if (info != null) {
|
||||
this.getSiteInfo(this.getSiteUuid()).setRoles(roles);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void addRoleToSite(String role, UUID siteUuid) {
|
||||
role = UserRole.toRole(role);
|
||||
if (role != null) {
|
||||
if (role.equals("SUPERVISOR")) {
|
||||
this.getRoles(siteUuid).clear();
|
||||
}
|
||||
|
||||
this.getRolesBySite(siteUuid).add(role);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void removeRole(String role) {
|
||||
this.getRoles().remove(role);
|
||||
}
|
||||
|
||||
public void removeRole(UUID siteUuid, String role) {
|
||||
SiteInfo siteInfo = this.getSiteInfo(siteUuid);
|
||||
if (siteInfo != null) {
|
||||
siteInfo.getRoles().remove(role);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Set getSystemRoles() {
|
||||
if (this.systemRoles == null) {
|
||||
this.systemRoles = new HashSet();
|
||||
}
|
||||
|
||||
return this.systemRoles;
|
||||
}
|
||||
|
||||
public void setSystemRoles(Set systemRoles) {
|
||||
this.systemRoles = systemRoles;
|
||||
}
|
||||
|
||||
public void addSystemRole(String role) {
|
||||
this.getSystemRoles().add(role);
|
||||
}
|
||||
|
||||
public void removeSystemRole(String role) {
|
||||
this.getSystemRoles().remove(role);
|
||||
}
|
||||
|
||||
public boolean hasSystemRole() {
|
||||
return !this.getSystemRoles().isEmpty();
|
||||
}
|
||||
|
||||
public boolean hasSystemRole(String role) {
|
||||
return this.getSystemRoles().contains(role);
|
||||
}
|
||||
|
||||
public boolean hasRole(String role) {
|
||||
return this.hasRole(this.getSiteUuid(), role);
|
||||
}
|
||||
|
||||
public boolean hasRole(UUID siteUuid, String role) {
|
||||
SiteInfo site = this.getSiteInfo(siteUuid);
|
||||
return site != null ? site.hasRole(role) : false;
|
||||
}
|
||||
|
||||
public boolean isSupervisor() {
|
||||
return this.hasRole("SUPERVISOR");
|
||||
}
|
||||
|
||||
public boolean isSystemUser() {
|
||||
return !this.getSystemRoles().isEmpty();
|
||||
}
|
||||
|
||||
public boolean isSystemAdmin() {
|
||||
return this.getSystemRoles().contains("SYSTEM_ADMIN");
|
||||
}
|
||||
|
||||
public UUID getGroupUuid() {
|
||||
return this.groupUuid;
|
||||
}
|
||||
|
||||
public void setGroupUuid(UUID groupUuid) {
|
||||
this.groupUuid = groupUuid;
|
||||
}
|
||||
|
||||
public Date getActivated() {
|
||||
return this.activated;
|
||||
}
|
||||
|
||||
public void setActivated(Date activated) {
|
||||
this.activated = activated;
|
||||
}
|
||||
|
||||
public void setActivated() {
|
||||
this.activated = new Date();
|
||||
this.enabled = true;
|
||||
}
|
||||
|
||||
public boolean isActivated() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isAvailable() {
|
||||
return this.getEnabled() && this.isActivated();
|
||||
}
|
||||
|
||||
public String getEmailAddress() {
|
||||
String EMAIL_FORMAT = "%s<%s>";
|
||||
String name = this.getName();
|
||||
if (McStringUtils.isNullOrEmpty(this.email)) {
|
||||
return null;
|
||||
} else {
|
||||
return McStringUtils.isNullOrEmpty(name) ? this.email : String.format("%s<%s>", name, this.email);
|
||||
}
|
||||
}
|
||||
|
||||
public UserGroup getUserGroup() {
|
||||
return this.userGroup;
|
||||
}
|
||||
|
||||
public void setUserGroup(UserGroup userGroup) {
|
||||
this.userGroup = userGroup;
|
||||
if (userGroup != null) {
|
||||
SiteInfo siteInfo = this.getSiteInfo(userGroup.getSiteUuid());
|
||||
if (siteInfo != null) {
|
||||
siteInfo.setGroupUuid(userGroup.getUuid());
|
||||
} else {
|
||||
this.userGroup = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void encodePassword(PasswordEncoder encoder, String password) {
|
||||
this.password = encoder.encode(password);
|
||||
}
|
||||
|
||||
public void encodePassword(PasswordEncoder encoder) {
|
||||
this.password = encoder.encode(this.password);
|
||||
}
|
||||
|
||||
public boolean canRegister() {
|
||||
return !McStringUtils.isNullOrEmpty(this.getEmail()) && !McStringUtils.isNullOrEmpty(this.getPassword());
|
||||
}
|
||||
|
||||
public List getAuthorities() {
|
||||
return UserRole.getAuthorities(this.getRoles());
|
||||
}
|
||||
|
||||
public String getTheme() {
|
||||
String theme = "default";
|
||||
if (this.site != null) {
|
||||
String model = this.site.getModel();
|
||||
if (!Strings.isNullOrEmpty(model) && !model.equals("midm")) {
|
||||
theme = model;
|
||||
}
|
||||
}
|
||||
|
||||
return theme;
|
||||
}
|
||||
|
||||
public String getLocale() {
|
||||
String locale = this.getSettingAsString("language");
|
||||
return McStringUtils.isNullOrEmpty(locale) ? LocaleConst.DEFAULT_LOCALE.toLanguageTag() : locale;
|
||||
}
|
||||
|
||||
public void setLocale(Locale locale) {
|
||||
this.setLocale(locale.toLanguageTag());
|
||||
}
|
||||
|
||||
public void setLocale(String locale) {
|
||||
this.setSetting("language", locale);
|
||||
}
|
||||
|
||||
public boolean isSameLocale(Locale locale) {
|
||||
return this.isSameLocale(locale.toLanguageTag());
|
||||
}
|
||||
|
||||
public boolean isSameLocale(String localeTag) {
|
||||
return this.getLocale().equals(localeTag);
|
||||
}
|
||||
|
||||
public boolean keepSignIn() {
|
||||
return this.getSettingAsBoolean("keepSignIn");
|
||||
}
|
||||
|
||||
public UUID getLastSite() {
|
||||
UUID uuid = this.getSettingAsUuid("lastSite");
|
||||
if (uuid == null && this.sites != null && !this.sites.isEmpty() && !this.hasSystemRole()) {
|
||||
uuid = ((SiteInfo)this.sites.get(0)).getSiteUuid();
|
||||
this.setLastSite(uuid);
|
||||
}
|
||||
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public void setLastSite(UUID uuid) {
|
||||
this.setSetting("lastSite", uuid);
|
||||
}
|
||||
|
||||
public String getLastPage() {
|
||||
SiteInfo siteInfo = this.getSiteInfo(this.siteUuid);
|
||||
return siteInfo == null ? this.getSettingAsString("lastPage") : siteInfo.getSettingAsString("lastPage");
|
||||
}
|
||||
|
||||
public List getDashboardSettings() {
|
||||
SiteInfo siteInfo = this.getSiteInfo(this.siteUuid);
|
||||
if (siteInfo != null) {
|
||||
Object settings = siteInfo.getSetting("dashboard");
|
||||
if (settings != null && settings instanceof List) {
|
||||
return (List)settings;
|
||||
}
|
||||
}
|
||||
|
||||
return new ArrayList();
|
||||
}
|
||||
|
||||
public DbObject getReportSettings() {
|
||||
SiteInfo siteInfo = this.getSiteInfo(this.siteUuid);
|
||||
return siteInfo != null ? siteInfo.getSettings().getDbObject(new String[]{"report"}) : new DbObject();
|
||||
}
|
||||
|
||||
public void setDashboardSettings(List dashboard) {
|
||||
SiteInfo siteInfo = this.getSiteInfo(this.siteUuid);
|
||||
if (siteInfo != null) {
|
||||
siteInfo.setSetting("dashboard", dashboard);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setLastPage(String url) {
|
||||
SiteInfo siteInfo = this.getSiteInfo(this.siteUuid);
|
||||
if (siteInfo != null) {
|
||||
siteInfo.setSetting("lastPage", url);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public DbObject getPageSettings(String pageUrl) {
|
||||
Object settings = this.getSetting("page", pageUrl);
|
||||
DbObject var3;
|
||||
if (settings == null) {
|
||||
var3 = new DbObject();
|
||||
} else {
|
||||
if (settings instanceof DbObject) {
|
||||
return (DbObject)settings;
|
||||
}
|
||||
|
||||
if (settings instanceof Map) {
|
||||
var3 = new DbObject((Map)settings);
|
||||
} else {
|
||||
var3 = new DbObject();
|
||||
}
|
||||
}
|
||||
|
||||
this.setSetting("page", pageUrl, var3);
|
||||
return var3;
|
||||
}
|
||||
|
||||
public Object getPageSetting(String pageUrl, String key) {
|
||||
return this.getPageSettings(pageUrl).get(key);
|
||||
}
|
||||
|
||||
public void setPageSetting(String pageUrl, String key, Object value) {
|
||||
if (value == null) {
|
||||
this.getPageSettings(pageUrl).remove(key);
|
||||
} else {
|
||||
this.getPageSettings(pageUrl).put(key, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void updateProfile(DbObject newProfile) {
|
||||
DbObject profile = this.getProfile();
|
||||
newProfile.forEach((key, value) -> {
|
||||
if (!key.equals("eula") && !key.equals("ip")) {
|
||||
profile.put(key, value);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public void setEula(PolicyAgreement agreement) {
|
||||
this.setProfile("eula", (new DbObject("uuid", agreement.getUuid().toString())).append("version", agreement.getVersion()).append("acceptDate", new Date()));
|
||||
}
|
||||
|
||||
public void setEula(String value) {
|
||||
Object object = McStringUtils.isNullOrEmpty(value) ? new DbObject() : DbObject.parse(value);
|
||||
this.setProfile("eula", object);
|
||||
}
|
||||
|
||||
public String getMfaMethod() {
|
||||
return this.getSettingAsString("mfa");
|
||||
}
|
||||
|
||||
public boolean isEulaAgreed() {
|
||||
return this.isApiUser() || this.getCategoryProfile("eula", "acceptDate") != null;
|
||||
}
|
||||
|
||||
public boolean isApiUser() {
|
||||
SiteInfo siteInfo = this.getSiteInfo();
|
||||
return siteInfo != null && siteInfo.isApiOnly();
|
||||
}
|
||||
|
||||
public boolean equals(Object user) {
|
||||
if (user == null) {
|
||||
return false;
|
||||
} else if (user instanceof User) {
|
||||
return this.getEmail().equalsIgnoreCase(((User)user).getEmail());
|
||||
} else if (user instanceof String) {
|
||||
return this.getEmail().equals((String)user);
|
||||
} else {
|
||||
return user instanceof UUID ? user.equals(this.getUuid()) : super.equals(user);
|
||||
}
|
||||
}
|
||||
|
||||
public void setProfileOnly() {
|
||||
this.siteUuid = null;
|
||||
this.sites = null;
|
||||
this.systemRoles = null;
|
||||
this.activated = null;
|
||||
this.settings = null;
|
||||
this.created = null;
|
||||
this.updated = null;
|
||||
this.getProfile().remove("eula");
|
||||
}
|
||||
|
||||
public DbObject getLoginAttempt() {
|
||||
return this.getSettings().getDbObject(new String[]{"loginAttempt"});
|
||||
}
|
||||
|
||||
public void loginFailed() {
|
||||
DbObject loginAttempt = this.getLoginAttempt();
|
||||
loginAttempt.put("attemptAt", new Date());
|
||||
int count = loginAttempt.getInteger("count", 0) + 1;
|
||||
loginAttempt.put("count", count % 6);
|
||||
this.setSetting("loginAttempt", loginAttempt);
|
||||
}
|
||||
|
||||
public void resetLoginAttempt() {
|
||||
this.getSettings().remove("loginAttempt");
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.getEmail();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.midm.model.org;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
public class UserAccess {
|
||||
private String sessionId;
|
||||
private UUID userUuid;
|
||||
private String browser;
|
||||
private String os;
|
||||
private String device;
|
||||
private Date lastAccess;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.midm.model.org;
|
||||
|
||||
import com.midm.model.GeneralProfile;
|
||||
import java.util.UUID;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
|
||||
public class UserGroup extends GeneralProfile {
|
||||
private UUID siteUuid;
|
||||
private UUID parentUuid;
|
||||
private Integer order;
|
||||
@Transient
|
||||
private Long userNumbers;
|
||||
|
||||
public UserGroup() {
|
||||
}
|
||||
|
||||
public UserGroup(UUID siteUuid, UserGroup parentGroup, String name) {
|
||||
this.setSiteUuid(siteUuid);
|
||||
if (parentGroup != null) {
|
||||
this.setParentUuid(parentGroup.getUuid());
|
||||
}
|
||||
|
||||
this.setName(name);
|
||||
}
|
||||
|
||||
public UUID getSiteUuid() {
|
||||
return this.siteUuid;
|
||||
}
|
||||
|
||||
public void setSiteUuid(UUID siteUuid) {
|
||||
this.siteUuid = siteUuid;
|
||||
}
|
||||
|
||||
public UUID getParentUuid() {
|
||||
return this.parentUuid;
|
||||
}
|
||||
|
||||
public void setParentUuid(UUID parentUuid) {
|
||||
this.parentUuid = parentUuid;
|
||||
}
|
||||
|
||||
public Integer getOrder() {
|
||||
return this.order;
|
||||
}
|
||||
|
||||
public void setOrder(Integer order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public Long getUserNumbers() {
|
||||
return this.userNumbers;
|
||||
}
|
||||
|
||||
public void setUserNumbers(Long numbers) {
|
||||
this.userNumbers = numbers;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.midm.model.org;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
|
||||
public class UserRole {
|
||||
public static final String ROLES = "roles";
|
||||
public static final String SYSTEM_ROLES = "systemRoles";
|
||||
public static final String ROLE_SUPER_USER = "SUPER_USER";
|
||||
public static final String ROLE_SUPERVISOR = "SUPERVISOR";
|
||||
public static final String ROLE_SYSTEM_ADMIN = "SYSTEM_ADMIN";
|
||||
public static final String ROLE_SITE_MANAGER = "SITE_MANAGER";
|
||||
public static final String ROLE_SALES = "SALES";
|
||||
public static final String ROLE_RESELLER = "RESELLER";
|
||||
public static final String ROLE_FINANCE = "FINANCE";
|
||||
public static final String ROLE_USER = "USER";
|
||||
public static final String ROLE_USER_MANAGER = "USER_MANAGER";
|
||||
public static final String ROLE_DEVICE_MANAGER = "DEVICE_MANAGER";
|
||||
public static final String ROLE_PROFILE_MANAGER = "PROFILE_MANAGER";
|
||||
public static final String ROLE_DEVIE_OWNER = "DEVICE_OWNER";
|
||||
public static final String ROLE_GUEST = "ROLE_GUEST";
|
||||
public static final String[] USER_MANAGE_ROLES = new String[]{"SUPERVISOR", "USER_MANAGER"};
|
||||
public static final String[] DEVICE_MANAGE_ROLES = new String[]{"SUPERVISOR", "DEVICE_MANAGER"};
|
||||
public static final String[] PROFILE_MANAGE_ROLES = new String[]{"SUPERVISOR", "PROFILE_MANAGER"};
|
||||
|
||||
public static List getAuthorities(final String role) {
|
||||
return new ArrayList() {
|
||||
{
|
||||
this.add(new SimpleGrantedAuthority(role));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static List getAuthorities(final Set roles) {
|
||||
return new ArrayList() {
|
||||
{
|
||||
if (roles != null && !roles.isEmpty()) {
|
||||
for(String role : roles) {
|
||||
this.add(new SimpleGrantedAuthority(role));
|
||||
}
|
||||
} else {
|
||||
this.add(new SimpleGrantedAuthority("ROLE_GUEST"));
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static String toRole(String role) {
|
||||
if (Strings.isNullOrEmpty(role)) {
|
||||
return null;
|
||||
} else {
|
||||
switch (role.toLowerCase()) {
|
||||
case "supervisor":
|
||||
return "SUPERVISOR";
|
||||
case "user_manager":
|
||||
case "usermanager":
|
||||
return "USER_MANAGER";
|
||||
case "device_manager":
|
||||
case "devicemanager":
|
||||
return "DEVICE_MANAGER";
|
||||
case "profile_manager":
|
||||
case "profilemanager":
|
||||
return "PROFILE_MANAGER";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
package com.midm.model.org;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import com.mitac.cell.utils.McUrlUtils;
|
||||
import com.mitac.cell.utils.McUuidUtils;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.joda.time.DateTime;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class UserToken implements Serializable {
|
||||
public static final char TOKEN_CONFIRMATION = 'C';
|
||||
public static final char TOKEN_ACTIVATION = 'A';
|
||||
public static final char TOKEN_LOGIN = 'L';
|
||||
public static final char TOKEN_REMEMBER_LOGIN = 'R';
|
||||
public static final char TOKEN_RESET_PASSWORD = 'P';
|
||||
public static final char TOKEN_MFA_AUTH = 'M';
|
||||
public static final char TOKEN_DEVICE_ACCESS = 'D';
|
||||
@Id
|
||||
@Expose(
|
||||
serialize = false
|
||||
)
|
||||
private UUID tokenUuid;
|
||||
@Transient
|
||||
private String accessToken;
|
||||
@Expose(
|
||||
serialize = false
|
||||
)
|
||||
private UUID userUuid;
|
||||
@Expose(
|
||||
serialize = false
|
||||
)
|
||||
private char tokenType;
|
||||
@Expose(
|
||||
serialize = false
|
||||
)
|
||||
private Date created;
|
||||
@Expose(
|
||||
serialize = false
|
||||
)
|
||||
private Date expired;
|
||||
private DbObject reference;
|
||||
|
||||
public UserToken() {
|
||||
}
|
||||
|
||||
public UserToken(User user, char tokenType, long validPeriod) {
|
||||
this.tokenUuid = UUID.randomUUID();
|
||||
this.userUuid = user.getUuid();
|
||||
this.tokenType = tokenType;
|
||||
this.created = new Date();
|
||||
DateTime date = new DateTime(this.created);
|
||||
this.expired = date.plus(validPeriod).toDate();
|
||||
}
|
||||
|
||||
public void renew() {
|
||||
this.tokenUuid = UUID.randomUUID();
|
||||
this.encryptToken();
|
||||
this.created = new Date();
|
||||
long validPeriod = this.expired.getTime() - this.created.getTime();
|
||||
DateTime date = new DateTime(this.created);
|
||||
this.expired = date.plus(validPeriod).toDate();
|
||||
}
|
||||
|
||||
public void encryptToken() {
|
||||
this.accessToken = McUuidUtils.toBase64String(this.tokenUuid);
|
||||
}
|
||||
|
||||
public String getAccessToken() {
|
||||
if (Strings.isNullOrEmpty(this.accessToken)) {
|
||||
this.encryptToken();
|
||||
}
|
||||
|
||||
return this.accessToken;
|
||||
}
|
||||
|
||||
public UUID getTokenUuid() {
|
||||
return this.tokenUuid;
|
||||
}
|
||||
|
||||
public void setTokenUuid(UUID uid) {
|
||||
this.tokenUuid = uid;
|
||||
}
|
||||
|
||||
public UUID getUserUuid() {
|
||||
return this.userUuid;
|
||||
}
|
||||
|
||||
public void setUserUuid(UUID userUuid) {
|
||||
this.userUuid = userUuid;
|
||||
}
|
||||
|
||||
public char getTokenType() {
|
||||
return this.tokenType;
|
||||
}
|
||||
|
||||
public void setTokenType(char tokenType) {
|
||||
this.tokenType = tokenType;
|
||||
}
|
||||
|
||||
public String getMfaToken(int length) {
|
||||
return this.getMfaToken().substring(0, length);
|
||||
}
|
||||
|
||||
public String getMfaToken() {
|
||||
return String.valueOf(this.tokenUuid.getMostSignificantBits() * this.tokenUuid.getLeastSignificantBits());
|
||||
}
|
||||
|
||||
public DbObject getReference() {
|
||||
if (this.reference == null) {
|
||||
this.reference = new DbObject();
|
||||
}
|
||||
|
||||
return this.reference;
|
||||
}
|
||||
|
||||
public void setReference(DbObject reference) {
|
||||
this.reference = reference;
|
||||
}
|
||||
|
||||
public void setReference(String key, Object value) {
|
||||
if (value == null) {
|
||||
this.getReference().remove(key);
|
||||
} else {
|
||||
this.getReference().put(key, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public UUID getDeviceUuid() {
|
||||
return this.getReference().getUuid("deviceUuid");
|
||||
}
|
||||
|
||||
public Date getCreated() {
|
||||
return this.created;
|
||||
}
|
||||
|
||||
public void setCreated(Date registered) {
|
||||
this.created = registered;
|
||||
}
|
||||
|
||||
public Date getExpired() {
|
||||
return this.expired;
|
||||
}
|
||||
|
||||
public void setExpired(Date expired) {
|
||||
this.expired = expired;
|
||||
}
|
||||
|
||||
public void plusExpired(long time) {
|
||||
DateTime expiredDate = new DateTime(this.getExpired());
|
||||
expiredDate.plus(time);
|
||||
}
|
||||
|
||||
public boolean isExpired() {
|
||||
return this.getExpired().getTime() < (new Date()).getTime();
|
||||
}
|
||||
|
||||
public DbObject toDeviceAccess(HttpServletRequest request) {
|
||||
String var10000 = McUrlUtils.getHostUrl(request);
|
||||
String accessUrl = var10000 + "/device/" + McUuidUtils.toBase64String(this.tokenUuid, true);
|
||||
DbObject deviceAccess = new DbObject("accessUrl", accessUrl);
|
||||
deviceAccess.append("expiry", this.getExpired());
|
||||
return deviceAccess;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.midm.model.store;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class AppReleaseNote extends ReleaseNote {
|
||||
@Id
|
||||
private NoteId noteId;
|
||||
private String versionName;
|
||||
private int minSdkVersion;
|
||||
private List files;
|
||||
|
||||
public AppReleaseNote() {
|
||||
}
|
||||
|
||||
public AppReleaseNote(String packageName, int versionCode, String versionName, int minSdkVersion) {
|
||||
this.noteId = new NoteId(packageName, versionCode);
|
||||
this.versionName = versionName;
|
||||
this.setMinSdkVersion(minSdkVersion);
|
||||
}
|
||||
|
||||
public AppReleaseNote(StoreAppFile appFile) {
|
||||
this(appFile.getPackageName(), (int)appFile.getVersionCode(), appFile.getVersionName(), appFile.getMinSdkVersion());
|
||||
}
|
||||
|
||||
public int getVersionCode() {
|
||||
return this.noteId.getVersionCode();
|
||||
}
|
||||
|
||||
public String getVersionName() {
|
||||
return this.versionName;
|
||||
}
|
||||
|
||||
public void setVersionName(String versionName) {
|
||||
this.versionName = versionName;
|
||||
}
|
||||
|
||||
public List getFiles() {
|
||||
return this.files;
|
||||
}
|
||||
|
||||
public void setFiles(List files) {
|
||||
this.files = files;
|
||||
}
|
||||
|
||||
public int getMinSdkVersion() {
|
||||
return this.minSdkVersion;
|
||||
}
|
||||
|
||||
public void setMinSdkVersion(int minSdkVersion) {
|
||||
this.minSdkVersion = minSdkVersion;
|
||||
}
|
||||
|
||||
public static class NoteId implements Serializable {
|
||||
private String packageName;
|
||||
private int versionCode;
|
||||
|
||||
public NoteId() {
|
||||
}
|
||||
|
||||
public NoteId(String packageName, int versionCode) {
|
||||
this.packageName = packageName;
|
||||
this.versionCode = versionCode;
|
||||
}
|
||||
|
||||
public String getAppUuid() {
|
||||
return this.packageName;
|
||||
}
|
||||
|
||||
public void setAppUuid(String packageName) {
|
||||
this.packageName = packageName;
|
||||
}
|
||||
|
||||
public int getVersionCode() {
|
||||
return this.versionCode;
|
||||
}
|
||||
|
||||
public void setVersionCode(int versionCode) {
|
||||
this.versionCode = versionCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.midm.model.store;
|
||||
|
||||
import com.mitac.cell.io.McFile;
|
||||
import java.io.InputStream;
|
||||
import java.security.Key;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.cert.Certificate;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class KeyStore {
|
||||
@Id
|
||||
private String id;
|
||||
private String description;
|
||||
private String alias;
|
||||
private String keyPassword;
|
||||
private String storePassword;
|
||||
private String certMd5;
|
||||
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getAlias() {
|
||||
return this.alias;
|
||||
}
|
||||
|
||||
public void setAlias(String alias) {
|
||||
this.alias = alias;
|
||||
}
|
||||
|
||||
public String getKeyPassword() {
|
||||
return this.keyPassword;
|
||||
}
|
||||
|
||||
public void setKeyPassword(String keyPassword) {
|
||||
this.keyPassword = keyPassword;
|
||||
}
|
||||
|
||||
public String getStorePassword() {
|
||||
return this.storePassword;
|
||||
}
|
||||
|
||||
public void setStorePassword(String storePassword) {
|
||||
this.storePassword = storePassword;
|
||||
}
|
||||
|
||||
public String getCertMd5() {
|
||||
return this.certMd5;
|
||||
}
|
||||
|
||||
public void setCertMd5(String certMd5) {
|
||||
this.certMd5 = certMd5;
|
||||
}
|
||||
|
||||
public void setCertMd5(McFile storeFile) {
|
||||
try {
|
||||
InputStream input = storeFile.getInputStream();
|
||||
java.security.KeyStore keystore = java.security.KeyStore.getInstance(java.security.KeyStore.getDefaultType());
|
||||
keystore.load(input, this.storePassword.toCharArray());
|
||||
Key key = keystore.getKey(this.alias, this.keyPassword.toCharArray());
|
||||
if (key instanceof PrivateKey) {
|
||||
Certificate cert = keystore.getCertificate(this.alias);
|
||||
this.certMd5 = DigestUtils.md5Hex(cert.getEncoded());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.midm.model.store;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class OtaReleaseNote extends ReleaseNote {
|
||||
@Id
|
||||
private NoteId noteId;
|
||||
private String displayId;
|
||||
|
||||
public OtaReleaseNote() {
|
||||
}
|
||||
|
||||
public OtaReleaseNote(String productId, long buildDate) {
|
||||
this.noteId = new NoteId(productId, buildDate);
|
||||
}
|
||||
|
||||
public OtaReleaseNote(StoreOtaFile otaFile) {
|
||||
this(otaFile.getProductId(), otaFile.getBuildDate());
|
||||
this.setDisplayId(otaFile.getDisplayId());
|
||||
}
|
||||
|
||||
public String getDisplayId() {
|
||||
return this.displayId;
|
||||
}
|
||||
|
||||
public void setDisplayId(String versionName) {
|
||||
this.displayId = versionName;
|
||||
}
|
||||
|
||||
public class NoteId {
|
||||
private String productId;
|
||||
private long buildDate;
|
||||
|
||||
public NoteId() {
|
||||
}
|
||||
|
||||
public NoteId(String productId, long buildDate) {
|
||||
this.productId = productId;
|
||||
this.buildDate = buildDate;
|
||||
}
|
||||
|
||||
public String getProductId() {
|
||||
return this.productId;
|
||||
}
|
||||
|
||||
public void setProductId(String productId) {
|
||||
this.productId = productId;
|
||||
}
|
||||
|
||||
public long getBuildDate() {
|
||||
return this.buildDate;
|
||||
}
|
||||
|
||||
public void setBuildDate(long buildDate) {
|
||||
this.buildDate = buildDate;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.midm.model.store;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class ReleaseNote {
|
||||
private String[] note;
|
||||
private String[] noteNewFunction;
|
||||
private Boolean isFormal;
|
||||
private Date releasedAt = new Date();
|
||||
|
||||
public Date getReleasedAt() {
|
||||
return this.releasedAt;
|
||||
}
|
||||
|
||||
public void setReleasedAt(Date releasedAt) {
|
||||
this.releasedAt = releasedAt;
|
||||
}
|
||||
|
||||
public boolean hasNote() {
|
||||
return this.note != null && this.note.length > 0;
|
||||
}
|
||||
|
||||
public boolean hasNoteNewFunction() {
|
||||
return this.noteNewFunction != null && this.noteNewFunction.length > 0;
|
||||
}
|
||||
|
||||
public String[] getNote() {
|
||||
return this.note;
|
||||
}
|
||||
|
||||
public void setNotes(String[] note) {
|
||||
this.note = note;
|
||||
}
|
||||
|
||||
public String[] getNoteNewFunction() {
|
||||
return this.noteNewFunction;
|
||||
}
|
||||
|
||||
public void setNoteNewFunctions(String[] noteNewFunction) {
|
||||
this.noteNewFunction = noteNewFunction;
|
||||
}
|
||||
|
||||
public Boolean isFormal() {
|
||||
return this.isFormal;
|
||||
}
|
||||
|
||||
public void setIsFormal(Boolean isFormal) {
|
||||
this.isFormal = isFormal;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.midm.model.store;
|
||||
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class StoreApp extends StoreBase {
|
||||
@Id
|
||||
private String packageName;
|
||||
private Boolean isFormal;
|
||||
private DbObject appInfo;
|
||||
@Transient
|
||||
private Set sdkVersions;
|
||||
|
||||
public StoreApp(String packageName) {
|
||||
this.packageName = packageName;
|
||||
}
|
||||
|
||||
public Boolean isFormal() {
|
||||
return this.isFormal;
|
||||
}
|
||||
|
||||
public void setIsFormal(Boolean isFormal) {
|
||||
this.isFormal = isFormal;
|
||||
}
|
||||
|
||||
public String getPackageName() {
|
||||
return this.packageName;
|
||||
}
|
||||
|
||||
public void setPackageName(String packageName) {
|
||||
this.packageName = packageName;
|
||||
}
|
||||
|
||||
public DbObject getAppInfo() {
|
||||
if (this.appInfo == null) {
|
||||
this.appInfo = new DbObject();
|
||||
}
|
||||
|
||||
return this.appInfo;
|
||||
}
|
||||
|
||||
public void setAppInfo(DbObject appInfo) {
|
||||
this.appInfo = appInfo;
|
||||
}
|
||||
|
||||
public void setAppInfo(String key, Object value) {
|
||||
this.getAppInfo().append(key, value);
|
||||
}
|
||||
|
||||
public Set getSdkVersions() {
|
||||
return this.sdkVersions;
|
||||
}
|
||||
|
||||
public void setSdkVersions(Set sdkVersions) {
|
||||
this.sdkVersions = sdkVersions;
|
||||
}
|
||||
|
||||
public void setSdkVersions(List sdkVersions) {
|
||||
if (sdkVersions != null) {
|
||||
this.sdkVersions = new HashSet();
|
||||
this.sdkVersions.addAll(sdkVersions);
|
||||
} else {
|
||||
this.sdkVersions = null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.midm.model.store;
|
||||
|
||||
import com.midm.model.file.AppFile;
|
||||
import com.midm.model.org.User;
|
||||
import com.mitac.cell.io.McFile;
|
||||
import java.util.UUID;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class StoreAppFile extends AppFile {
|
||||
public StoreAppFile() {
|
||||
}
|
||||
|
||||
public StoreAppFile(User user, UUID fileUuid, McFile file, boolean generateIcon) {
|
||||
super(user, fileUuid, file, generateIcon);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.midm.model.store;
|
||||
|
||||
import com.midm.constant.LocaleConst;
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import java.util.Date;
|
||||
|
||||
public class StoreBase {
|
||||
private DbObject title;
|
||||
private DbObject summary;
|
||||
private DbObject desc;
|
||||
private Date createdAt = new Date();
|
||||
private Date lastUpdated = new Date();
|
||||
|
||||
public void init() {
|
||||
this.createdAt = new Date();
|
||||
this.lastUpdated = new Date();
|
||||
}
|
||||
|
||||
public DbObject getTitle() {
|
||||
if (this.title == null) {
|
||||
this.title = new DbObject();
|
||||
}
|
||||
|
||||
return this.title;
|
||||
}
|
||||
|
||||
public void setTitle(DbObject title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public void setTitle(String key, Object value) {
|
||||
this.getTitle().append(key, value);
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.setTitle(LocaleConst.DEFAULT_LOCALE.toLanguageTag(), title);
|
||||
}
|
||||
|
||||
public DbObject getSummary() {
|
||||
if (this.summary == null) {
|
||||
this.summary = new DbObject();
|
||||
}
|
||||
|
||||
return this.summary;
|
||||
}
|
||||
|
||||
public void setSummary(DbObject summary) {
|
||||
this.summary = summary;
|
||||
}
|
||||
|
||||
public void setSummary(String key, Object value) {
|
||||
this.getSummary().append(key, value);
|
||||
}
|
||||
|
||||
public DbObject getDesc() {
|
||||
if (this.desc == null) {
|
||||
this.desc = new DbObject();
|
||||
}
|
||||
|
||||
return this.desc;
|
||||
}
|
||||
|
||||
public void setDescription(DbObject desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public void setDescription(String key, Object value) {
|
||||
this.getDesc().append(key, value);
|
||||
}
|
||||
|
||||
public Date getCreatedAt() {
|
||||
return this.createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(Date createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public Date getLastUpdated() {
|
||||
return this.lastUpdated;
|
||||
}
|
||||
|
||||
public void setLastUpdated(Date lastUpdated) {
|
||||
this.lastUpdated = lastUpdated;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.midm.model.store;
|
||||
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import java.util.Date;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class StoreOta {
|
||||
@Id
|
||||
private String productId;
|
||||
private String deviceId;
|
||||
private DbObject otaInfo;
|
||||
private Boolean isFormal;
|
||||
private Date createdAt;
|
||||
private Date lastUpdated;
|
||||
|
||||
public StoreOta(String productId) {
|
||||
this.productId = productId;
|
||||
this.createdAt = new Date();
|
||||
this.lastUpdated = new Date();
|
||||
}
|
||||
|
||||
Boolean isFormal() {
|
||||
return this.isFormal;
|
||||
}
|
||||
|
||||
public void setIsFormal(Boolean isFormal) {
|
||||
this.isFormal = isFormal;
|
||||
}
|
||||
|
||||
public String getProductId() {
|
||||
return this.productId;
|
||||
}
|
||||
|
||||
public void setProductId(String productId) {
|
||||
this.productId = productId;
|
||||
}
|
||||
|
||||
public String getDeviceId() {
|
||||
return this.deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(String deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public Date getCreatedAt() {
|
||||
return this.createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(Date createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public Date getLastUpdated() {
|
||||
return this.lastUpdated;
|
||||
}
|
||||
|
||||
public void setLastUpdated(Date lastUpdated) {
|
||||
this.lastUpdated = lastUpdated;
|
||||
}
|
||||
|
||||
public DbObject getOtaInfo() {
|
||||
return this.otaInfo;
|
||||
}
|
||||
|
||||
public void setOtaInfo(DbObject otaInfo) {
|
||||
this.otaInfo = otaInfo;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.midm.model.store;
|
||||
|
||||
import com.midm.model.file.OtaFile;
|
||||
import com.midm.model.org.User;
|
||||
import com.mitac.cell.io.McFile;
|
||||
import java.util.UUID;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class StoreOtaFile extends OtaFile {
|
||||
private String[] note;
|
||||
|
||||
public StoreOtaFile() {
|
||||
}
|
||||
|
||||
public StoreOtaFile(User user, UUID fileUuid, McFile file) {
|
||||
super(user, fileUuid, file);
|
||||
}
|
||||
|
||||
public String[] getNote() {
|
||||
return this.note;
|
||||
}
|
||||
|
||||
public void setNotes(String[] note) {
|
||||
this.note = note;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.midm.model.store;
|
||||
|
||||
import com.midm.model.file.BaseFile;
|
||||
import com.midm.model.org.User;
|
||||
import com.mitac.cell.io.McFile;
|
||||
import java.util.UUID;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class StoreOtherFile extends BaseFile {
|
||||
private String alias;
|
||||
|
||||
public StoreOtherFile() {
|
||||
}
|
||||
|
||||
public StoreOtherFile(User user, UUID fileUuid, McFile file) {
|
||||
super(user, fileUuid, file);
|
||||
}
|
||||
|
||||
public String getAlias() {
|
||||
return this.alias;
|
||||
}
|
||||
|
||||
public void setAlias(String alias) {
|
||||
this.alias = alias;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
package com.midm.model.store;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.midm.model.file.BaseFile;
|
||||
import com.midm.model.org.User;
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import com.mitac.cell.io.McFile;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.UUID;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.zip.ZipEntry;
|
||||
import org.joda.time.DateTime;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class StoreWebApp extends BaseFile {
|
||||
private DbObject appInfo;
|
||||
private Boolean isFormal;
|
||||
private List releaseNote;
|
||||
private List releaseNoteNewFunction;
|
||||
|
||||
public StoreWebApp() {
|
||||
}
|
||||
|
||||
public StoreWebApp(User user, UUID fileUuid, McFile file) {
|
||||
super(user, fileUuid, file);
|
||||
this.setAppInfo((File)file);
|
||||
}
|
||||
|
||||
public StoreWebApp(McFile file) {
|
||||
super((User)null, (UUID)null, file);
|
||||
this.setAppInfo((File)file);
|
||||
}
|
||||
|
||||
public boolean isFormal() {
|
||||
return this.isFormal != null && this.isFormal;
|
||||
}
|
||||
|
||||
public void setIsFormal(boolean isFormal) {
|
||||
this.isFormal = isFormal;
|
||||
}
|
||||
|
||||
public DbObject getAppInfo() {
|
||||
if (this.appInfo == null) {
|
||||
this.appInfo = new DbObject();
|
||||
}
|
||||
|
||||
return this.appInfo;
|
||||
}
|
||||
|
||||
public void setAppInfo(DbObject appInfo) {
|
||||
this.appInfo = appInfo;
|
||||
}
|
||||
|
||||
public void setAppInfo(String key, Object value) {
|
||||
if (!this.getAppInfo().containsKey(key)) {
|
||||
this.getAppInfo().append(key, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setAppInfo(Properties properties) {
|
||||
properties.forEach((key, value) -> {
|
||||
String name = (String)key;
|
||||
if (name.startsWith("build")) {
|
||||
name = name.substring(6);
|
||||
}
|
||||
|
||||
switch (name) {
|
||||
case "build.group":
|
||||
case "group":
|
||||
case "groupId":
|
||||
this.setAppInfo("groupId", value);
|
||||
break;
|
||||
case "build.artifact":
|
||||
case "artifact":
|
||||
case "artifactId":
|
||||
this.setAppInfo("artifactId", value);
|
||||
break;
|
||||
case "build.name":
|
||||
case "name":
|
||||
case "m2e.projectName":
|
||||
this.setName((String)value);
|
||||
break;
|
||||
case "build.time":
|
||||
case "time":
|
||||
this.setAppInfo("buildTime", DateTime.parse((String)value).toDate());
|
||||
break;
|
||||
case "build.version":
|
||||
case "version":
|
||||
this.setAppInfo("version", value);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public String getGroupId() {
|
||||
return this.getAppInfo().getString("groupId");
|
||||
}
|
||||
|
||||
public String getArtifactId() {
|
||||
return this.getAppInfo().getString("artifactId");
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return this.getAppInfo().getString("version");
|
||||
}
|
||||
|
||||
public Date getBuildTime() {
|
||||
return this.getAppInfo().getDate("buildTime");
|
||||
}
|
||||
|
||||
public List getReleaseNote() {
|
||||
if (this.releaseNote == null) {
|
||||
this.releaseNote = new ArrayList();
|
||||
}
|
||||
|
||||
return this.releaseNote;
|
||||
}
|
||||
|
||||
public void setReleaseNote(List releaseNote) {
|
||||
this.releaseNote = releaseNote;
|
||||
}
|
||||
|
||||
public boolean hasReleaseNote() {
|
||||
return !this.getReleaseNote().isEmpty();
|
||||
}
|
||||
|
||||
public List getReleaseNoteNewFunction() {
|
||||
if (this.releaseNoteNewFunction == null) {
|
||||
this.releaseNoteNewFunction = new ArrayList();
|
||||
}
|
||||
|
||||
return this.releaseNoteNewFunction;
|
||||
}
|
||||
|
||||
public void setReleaseNoteNewFunction(List releaseNoteNewFunction) {
|
||||
this.releaseNoteNewFunction = releaseNoteNewFunction;
|
||||
}
|
||||
|
||||
public boolean hasReleaseNoteNewFunction() {
|
||||
return !this.getReleaseNoteNewFunction().isEmpty();
|
||||
}
|
||||
|
||||
public boolean isWebApp() {
|
||||
return !Strings.isNullOrEmpty(this.getGroupId()) && !Strings.isNullOrEmpty(this.getArtifactId());
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
String fileName = super.getFileName();
|
||||
if (Strings.isNullOrEmpty(fileName)) {
|
||||
fileName = String.format("%s.%s.war", this.getName(), this.getVersion());
|
||||
}
|
||||
|
||||
return fileName;
|
||||
}
|
||||
|
||||
private void setAppInfo(File file) {
|
||||
try {
|
||||
JarFile jarFile = new JarFile(file);
|
||||
|
||||
try {
|
||||
ZipEntry entry = this.findZipEntry(jarFile, "build-info.properties");
|
||||
if (entry != null) {
|
||||
Properties properties = new Properties();
|
||||
properties.load(jarFile.getInputStream(entry));
|
||||
this.setAppInfo(properties);
|
||||
}
|
||||
|
||||
entry = this.findZipEntry(jarFile, "pom.properties");
|
||||
if (entry != null) {
|
||||
Properties properties = new Properties();
|
||||
properties.load(jarFile.getInputStream(entry));
|
||||
this.setAppInfo(properties);
|
||||
}
|
||||
|
||||
entry = this.findZipEntry(jarFile, "project.properties");
|
||||
if (entry != null) {
|
||||
Properties properties = new Properties();
|
||||
properties.load(jarFile.getInputStream(entry));
|
||||
this.setAppInfo(properties);
|
||||
}
|
||||
} catch (Throwable var6) {
|
||||
try {
|
||||
jarFile.close();
|
||||
} catch (Throwable var5) {
|
||||
var6.addSuppressed(var5);
|
||||
}
|
||||
|
||||
throw var6;
|
||||
}
|
||||
|
||||
jarFile.close();
|
||||
} catch (Exception var7) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private ZipEntry findZipEntry(JarFile jarFile, String name) {
|
||||
Enumeration<? extends ZipEntry> entries = jarFile.entries();
|
||||
|
||||
while(entries.hasMoreElements()) {
|
||||
ZipEntry entry = (ZipEntry)entries.nextElement();
|
||||
if (entry.getName().endsWith(name)) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.midm.model.system;
|
||||
|
||||
import java.util.Locale;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class AltLocale {
|
||||
@Id
|
||||
private String locale;
|
||||
private String altLocale;
|
||||
|
||||
public String getLocale() {
|
||||
return this.locale;
|
||||
}
|
||||
|
||||
public void setLocale(String locale) {
|
||||
this.locale = locale;
|
||||
}
|
||||
|
||||
public String getAltLocale() {
|
||||
return this.altLocale;
|
||||
}
|
||||
|
||||
public void setAltLocale(String altLocale) {
|
||||
this.altLocale = altLocale;
|
||||
}
|
||||
|
||||
public Locale toLocale() {
|
||||
return Locale.forLanguageTag(this.getAltLocale());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.midm.model.system;
|
||||
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class Category {
|
||||
@Id
|
||||
public CategoryId id;
|
||||
public int order;
|
||||
public DbObject profile;
|
||||
public List features;
|
||||
|
||||
public Category() {
|
||||
}
|
||||
|
||||
public Category(String use, String categoryId) {
|
||||
this.id = new CategoryId(use, categoryId);
|
||||
}
|
||||
|
||||
public CategoryId getId() {
|
||||
if (this.id == null) {
|
||||
this.id = new CategoryId();
|
||||
}
|
||||
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(CategoryId id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUse() {
|
||||
return this.getId().getUse();
|
||||
}
|
||||
|
||||
public void setUse(String use) {
|
||||
this.getId().setUse(use);
|
||||
}
|
||||
|
||||
public String getCategoryId() {
|
||||
return this.getId().getId();
|
||||
}
|
||||
|
||||
public void setCategoryId(String id) {
|
||||
this.getId().setId(id);
|
||||
}
|
||||
|
||||
public void setCategory(String use, String categoryId) {
|
||||
this.getId().set(use, categoryId);
|
||||
}
|
||||
|
||||
public List getFeatures() {
|
||||
return this.features;
|
||||
}
|
||||
|
||||
public void setFeatures(List features) {
|
||||
this.features = features;
|
||||
}
|
||||
|
||||
public int getOrder() {
|
||||
return this.order;
|
||||
}
|
||||
|
||||
public void setOrder(int order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public DbObject getProfile() {
|
||||
if (this.profile == null) {
|
||||
this.profile = new DbObject();
|
||||
}
|
||||
|
||||
return this.profile;
|
||||
}
|
||||
|
||||
public void setProfile(DbObject profile) {
|
||||
this.profile = profile;
|
||||
}
|
||||
|
||||
public void setProfile(Locale locale, String name, String desc) {
|
||||
DbObject profile = new DbObject();
|
||||
profile.put("name", name);
|
||||
profile.put("desc", desc);
|
||||
this.getProfile().put(locale.toString(), profile);
|
||||
}
|
||||
|
||||
public DbObject getProfile(Locale locale) {
|
||||
return (DbObject)this.getProfile().get(locale.toString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.midm.model.system;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class CategoryId implements Serializable {
|
||||
private String use;
|
||||
private String id;
|
||||
|
||||
public CategoryId() {
|
||||
}
|
||||
|
||||
public CategoryId(String use, String id) {
|
||||
this.set(use, id);
|
||||
}
|
||||
|
||||
public String getUse() {
|
||||
return this.use;
|
||||
}
|
||||
|
||||
public void setUse(String use) {
|
||||
this.use = use;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void set(String use, String id) {
|
||||
this.setUse(use);
|
||||
this.setId(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.midm.model.system;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class DbTemplate {
|
||||
@Id
|
||||
private String code;
|
||||
private String name;
|
||||
private String content;
|
||||
private String comment;
|
||||
|
||||
public DbTemplate() {
|
||||
}
|
||||
|
||||
public DbTemplate(String code, String name, String content) {
|
||||
this.setCode(code);
|
||||
this.setName(name);
|
||||
this.setContent(content);
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return this.content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getComment() {
|
||||
return this.comment;
|
||||
}
|
||||
|
||||
public void setComment(String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package com.midm.model.system;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class HelpMessage {
|
||||
@Id
|
||||
private String code;
|
||||
private DbObject message;
|
||||
private DbObject options;
|
||||
private String comment;
|
||||
|
||||
public HelpMessage() {
|
||||
}
|
||||
|
||||
public HelpMessage(String code) {
|
||||
this.setCode(code);
|
||||
}
|
||||
|
||||
public HelpMessage(String code, String locale, String title, String desc, String comment) {
|
||||
this.setCode(code);
|
||||
this.setMessage(locale, title, desc);
|
||||
this.setComment(comment);
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public DbObject getMessage() {
|
||||
if (this.message == null) {
|
||||
this.message = new DbObject();
|
||||
}
|
||||
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public void setMessages(DbObject messages) {
|
||||
this.message = messages;
|
||||
}
|
||||
|
||||
public void setMessage(String locale, String title, String desc) {
|
||||
this.getMessage().append(locale, (new DbObject("title", title)).append("desc", this.message));
|
||||
}
|
||||
|
||||
public String getTitle(String locale) {
|
||||
return this.getMessage(locale).getString("title");
|
||||
}
|
||||
|
||||
public DbObject getMessage(String locale) {
|
||||
return this.getMessage().getDbObject(new String[]{Strings.isNullOrEmpty(locale) ? "en-US" : locale});
|
||||
}
|
||||
|
||||
public String getDescription(String locale) {
|
||||
return this.getMessage(locale).getString("desc");
|
||||
}
|
||||
|
||||
public DbObject getOptions() {
|
||||
if (this.options == null) {
|
||||
this.options = new DbObject();
|
||||
}
|
||||
|
||||
return this.options;
|
||||
}
|
||||
|
||||
public DbObject getOptions(String category) {
|
||||
Object categoryObject = this.getOptions().get(category);
|
||||
if (categoryObject == null) {
|
||||
categoryObject = new DbObject();
|
||||
this.getOptions().put(category, categoryObject);
|
||||
}
|
||||
|
||||
return (DbObject)categoryObject;
|
||||
}
|
||||
|
||||
public void setOptions(DbObject options) {
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
public void setOptions(String category, DbObject options) {
|
||||
this.getOptions().put(category, options);
|
||||
}
|
||||
|
||||
public void setOptions(String category, String key, String desc) {
|
||||
this.getOptions(category).put(key, desc);
|
||||
}
|
||||
|
||||
public String getComment() {
|
||||
return this.comment;
|
||||
}
|
||||
|
||||
public void setComment(String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,355 @@
|
||||
package com.midm.model.system;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import com.mitac.cell.net.McNetUtils;
|
||||
import com.mitac.cell.security.McTextEncryptor;
|
||||
import com.mitac.cell.system.McSystemInfo;
|
||||
import com.mitac.cell.utils.McJsonUtils;
|
||||
import com.mitac.cell.utils.McStringUtils;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import org.joda.time.DateTime;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class HostLicense {
|
||||
public static final Integer trialPeriod = 45;
|
||||
private static final Integer trialDeviceLimit = -1;
|
||||
private static final Integer trialSiteLimit = -1;
|
||||
@Transient
|
||||
private String hostId;
|
||||
@Transient
|
||||
private Integer siteLimit;
|
||||
@Transient
|
||||
private Integer deviceLimit;
|
||||
@Transient
|
||||
private Long validFrom;
|
||||
@Transient
|
||||
private Long validTo;
|
||||
@Transient
|
||||
private boolean isStandalone;
|
||||
@Transient
|
||||
private Boolean isValidKey;
|
||||
@Id
|
||||
private String systemHash;
|
||||
private String licenseKey;
|
||||
private DbObject properties;
|
||||
private boolean isPrimary;
|
||||
@Expose(
|
||||
serialize = false
|
||||
)
|
||||
private String validated;
|
||||
@Transient
|
||||
private Long validatedAt;
|
||||
@Transient
|
||||
@Expose(
|
||||
serialize = false
|
||||
)
|
||||
private McTextEncryptor encryptor;
|
||||
private static final String tokenPassword = "MiDM@MiTAC.com";
|
||||
private static final String tokenSalt = "171891893b5cef2f";
|
||||
public static final McTextEncryptor sourceEncryptor = new McTextEncryptor("MiDM@MiTAC.com", "171891893b5cef2f");
|
||||
|
||||
public HostLicense() {
|
||||
this.siteLimit = trialSiteLimit;
|
||||
this.deviceLimit = trialDeviceLimit;
|
||||
this.validFrom = -1L;
|
||||
this.validTo = -1L;
|
||||
this.isStandalone = false;
|
||||
this.isValidKey = false;
|
||||
}
|
||||
|
||||
public HostLicense(String hostId, String systemHash) {
|
||||
this(hostId, systemHash, (String)null);
|
||||
}
|
||||
|
||||
public HostLicense(String hostId, String systemHash, String licenseKey) {
|
||||
this.siteLimit = trialSiteLimit;
|
||||
this.deviceLimit = trialDeviceLimit;
|
||||
this.validFrom = -1L;
|
||||
this.validTo = -1L;
|
||||
this.isStandalone = false;
|
||||
this.isValidKey = false;
|
||||
this.hostId = hostId;
|
||||
this.setSystemHash(systemHash);
|
||||
this.setLicenseKey(licenseKey);
|
||||
this.dispatch();
|
||||
}
|
||||
|
||||
public String getSystemHash() {
|
||||
return this.systemHash;
|
||||
}
|
||||
|
||||
public void setSystemHash(String systemHash) {
|
||||
this.systemHash = systemHash;
|
||||
}
|
||||
|
||||
public String getHostId() {
|
||||
return this.hostId;
|
||||
}
|
||||
|
||||
public void setHostId(String hostId) {
|
||||
this.hostId = hostId;
|
||||
this.refreshEncryptor();
|
||||
}
|
||||
|
||||
private void refreshEncryptor() {
|
||||
if (!Strings.isNullOrEmpty(this.hostId) && !Strings.isNullOrEmpty(this.systemHash)) {
|
||||
try {
|
||||
this.encryptor = new McTextEncryptor(this.hostId, this.systemHash);
|
||||
} catch (Exception var2) {
|
||||
this.encryptor = null;
|
||||
}
|
||||
} else {
|
||||
this.encryptor = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String getLicenseKey() {
|
||||
return this.licenseKey;
|
||||
}
|
||||
|
||||
public boolean hasLicenseKey() {
|
||||
return !Strings.isNullOrEmpty(this.licenseKey);
|
||||
}
|
||||
|
||||
public void setLicenseKey(String licenseKey) {
|
||||
this.licenseKey = licenseKey;
|
||||
if (Strings.isNullOrEmpty(licenseKey)) {
|
||||
this.siteLimit = trialSiteLimit;
|
||||
this.deviceLimit = trialDeviceLimit;
|
||||
} else {
|
||||
this.dispatch(licenseKey);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean isValidKey() {
|
||||
return this.isValidKey;
|
||||
}
|
||||
|
||||
public int getSiteLimit() {
|
||||
return this.siteLimit;
|
||||
}
|
||||
|
||||
public void setSiteLimit(int siteLimit) {
|
||||
this.siteLimit = siteLimit;
|
||||
}
|
||||
|
||||
public int getDeviceLimit() {
|
||||
return this.deviceLimit;
|
||||
}
|
||||
|
||||
public void setDeviceLimit(int deviceLimit) {
|
||||
this.deviceLimit = deviceLimit;
|
||||
}
|
||||
|
||||
public Long getValidFrom() {
|
||||
return this.validFrom;
|
||||
}
|
||||
|
||||
public void setValidFrom(Long validFrom) {
|
||||
this.validFrom = validFrom;
|
||||
}
|
||||
|
||||
public Long getValidTo() {
|
||||
return this.validTo;
|
||||
}
|
||||
|
||||
public void setValidTo(Long validTo) {
|
||||
this.validTo = validTo;
|
||||
}
|
||||
|
||||
public boolean isStandalone() {
|
||||
return this.isStandalone;
|
||||
}
|
||||
|
||||
public void setIsStandalone(boolean isStandalone) {
|
||||
this.isStandalone = isStandalone;
|
||||
}
|
||||
|
||||
public void setAsTrial() {
|
||||
this.setIsStandalone(true);
|
||||
this.setDeviceLimit(trialDeviceLimit);
|
||||
if (this.validFrom == null) {
|
||||
this.validFrom = (new Date()).getTime();
|
||||
}
|
||||
|
||||
this.validTo = (new DateTime(this.validFrom)).plusDays(trialPeriod).getMillis();
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return !this.isExpired() && this.isValidated();
|
||||
}
|
||||
|
||||
private boolean isValidated() {
|
||||
return DateTime.now().isBefore((new DateTime(this.validatedDate())).plusDays(trialPeriod));
|
||||
}
|
||||
|
||||
private boolean isExpired() {
|
||||
return this.validTo != -1L && (new DateTime(this.validTo)).plusDays(1).isBeforeNow();
|
||||
}
|
||||
|
||||
public DbObject getProperties() {
|
||||
if (this.properties == null) {
|
||||
this.properties = new DbObject();
|
||||
}
|
||||
|
||||
return this.properties;
|
||||
}
|
||||
|
||||
public void setProperties(DbObject properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public void setProperty(String key, String value) {
|
||||
this.getProperties().append(key, value);
|
||||
}
|
||||
|
||||
public void dispatch() {
|
||||
if (!Strings.isNullOrEmpty(this.getLicenseKey())) {
|
||||
this.dispatch(this.getLicenseKey());
|
||||
}
|
||||
|
||||
this.validatedDate();
|
||||
}
|
||||
|
||||
public void validate() {
|
||||
this.setProperty("ip_addr", McNetUtils.getIpAddress());
|
||||
this.setProperty("host_name", McNetUtils.hostName());
|
||||
if (this.encryptor != null) {
|
||||
this.validated = this.encryptor.encrypt(String.valueOf((new Date()).getTime()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Long validatedDate() {
|
||||
this.validatedAt = null;
|
||||
if (!Strings.isNullOrEmpty(this.validated)) {
|
||||
String dateString = this.encryptor.decrypt(this.validated);
|
||||
if (!Strings.isNullOrEmpty(dateString)) {
|
||||
this.validatedAt = Long.parseLong(dateString);
|
||||
}
|
||||
}
|
||||
|
||||
return this.validatedAt;
|
||||
}
|
||||
|
||||
public boolean isPrimary() {
|
||||
return this.isPrimary;
|
||||
}
|
||||
|
||||
public void setPrimary(boolean isPrimary) {
|
||||
this.isPrimary = isPrimary;
|
||||
}
|
||||
|
||||
public void dispatch(String encryptedLicense) {
|
||||
if (this.encryptor == null) {
|
||||
this.refreshEncryptor();
|
||||
}
|
||||
|
||||
if (this.encryptor != null && !Strings.isNullOrEmpty(encryptedLicense)) {
|
||||
try {
|
||||
String license = this.encryptor.decrypt(encryptedLicense);
|
||||
if (!Strings.isNullOrEmpty(license)) {
|
||||
JsonObject jLicense = McJsonUtils.toJsonElement(license).getAsJsonObject();
|
||||
this.setDeviceLimit(McJsonUtils.getInt(jLicense, "deviceLimit", -1));
|
||||
this.setValidTo(McJsonUtils.getLong(jLicense, "validTo", -1L));
|
||||
this.setIsStandalone(McJsonUtils.getInt(jLicense, "isStandalone", -1) > 0);
|
||||
this.isValidKey = true;
|
||||
return;
|
||||
}
|
||||
} catch (Exception var4) {
|
||||
}
|
||||
|
||||
this.setAsTrial();
|
||||
this.isValidKey = false;
|
||||
} else {
|
||||
this.setAsTrial();
|
||||
}
|
||||
}
|
||||
|
||||
public static String generateSystemHash(String systemHash) {
|
||||
if (!Strings.isNullOrEmpty(systemHash)) {
|
||||
return systemHash;
|
||||
} else {
|
||||
McSystemInfo systemInfo = new McSystemInfo();
|
||||
List<byte[]> macAddresses = systemInfo.getMacAddresses();
|
||||
if (macAddresses != null && !macAddresses.isEmpty()) {
|
||||
ByteBuffer bb = ByteBuffer.allocate(macAddresses.size() * 6);
|
||||
|
||||
for(byte[] macAddr : macAddresses) {
|
||||
bb.put(macAddr);
|
||||
}
|
||||
|
||||
byte[] macBytes = bb.array();
|
||||
Arrays.sort(macBytes);
|
||||
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
return McStringUtils.toHexString(md.digest(macBytes));
|
||||
} catch (NoSuchAlgorithmException var6) {
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String encrypt(String value) {
|
||||
return sourceEncryptor.encrypt(value);
|
||||
}
|
||||
|
||||
public static String decrypt(String value) {
|
||||
return sourceEncryptor.decrypt(value);
|
||||
}
|
||||
|
||||
public String generateLicense() {
|
||||
String licenseKey = this.generateLicense(this.siteLimit, this.deviceLimit, this.validTo, false, this.isStandalone);
|
||||
this.setLicenseKey(licenseKey);
|
||||
return licenseKey;
|
||||
}
|
||||
|
||||
public String generateLicense(Integer siteLimit, Integer deviceLimit, Long validTo, Boolean isLicenseServer, Boolean isStandalone) {
|
||||
if (this.encryptor == null) {
|
||||
this.refreshEncryptor();
|
||||
}
|
||||
|
||||
if (this.encryptor == null) {
|
||||
return null;
|
||||
} else {
|
||||
JsonObject jLicense = new JsonObject();
|
||||
if (siteLimit != null && siteLimit > 0) {
|
||||
jLicense.addProperty("siteLimit", siteLimit);
|
||||
}
|
||||
|
||||
if (deviceLimit != null && deviceLimit > 0) {
|
||||
jLicense.addProperty("deviceLimit", deviceLimit);
|
||||
}
|
||||
|
||||
if (validTo != null && validTo > 0L) {
|
||||
jLicense.addProperty("validTo", validTo);
|
||||
}
|
||||
|
||||
if (isLicenseServer != null && isLicenseServer) {
|
||||
jLicense.addProperty("isLicenseServer", 1);
|
||||
}
|
||||
|
||||
if (isStandalone != null && isStandalone) {
|
||||
jLicense.addProperty("isStandalone", 1);
|
||||
}
|
||||
|
||||
return this.encryptor.encrypt(jLicense.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.midm.model.system;
|
||||
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import java.util.Locale;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class LicenseFeature {
|
||||
@Id
|
||||
String code;
|
||||
CategoryId categoryId;
|
||||
DbObject profile;
|
||||
|
||||
public String getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public CategoryId getCategoryId() {
|
||||
return this.categoryId;
|
||||
}
|
||||
|
||||
public void setCategoryId(CategoryId categoryId) {
|
||||
this.categoryId = categoryId;
|
||||
}
|
||||
|
||||
public DbObject getProfile() {
|
||||
if (this.profile == null) {
|
||||
this.profile = new DbObject();
|
||||
}
|
||||
|
||||
return this.profile;
|
||||
}
|
||||
|
||||
public void setProfile(DbObject profile) {
|
||||
this.profile = profile;
|
||||
}
|
||||
|
||||
public void setProfile(Locale locale, String name, String desc) {
|
||||
DbObject profile = new DbObject();
|
||||
profile.put("name", name);
|
||||
profile.put("desc", desc);
|
||||
this.getProfile().put(locale.toString(), profile);
|
||||
}
|
||||
|
||||
public DbObject getProfile(Locale locale) {
|
||||
return (DbObject)this.getProfile().get(locale.toString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,269 @@
|
||||
package com.midm.model.system;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class LicenseModel {
|
||||
public static final char TYPE_TRIAL = 't';
|
||||
public static final char TYPE_PERPETUAL = 'p';
|
||||
public static final char TYPE_YEARLY = 'y';
|
||||
public static final char TYPE_MONTHLY = 'm';
|
||||
public static final char TYPE_DAILY = 'd';
|
||||
public static final int DEFAULT_TRIAL_DAYS = 45;
|
||||
@Id
|
||||
private UUID uuid;
|
||||
private String name;
|
||||
private String idName;
|
||||
private DbObject profile;
|
||||
private Character type;
|
||||
private Integer period;
|
||||
private String freshExpiry;
|
||||
private String activatedExpiry;
|
||||
private String autoExtend;
|
||||
private Integer maxActivation = 2;
|
||||
private boolean isFormal;
|
||||
@Transient
|
||||
private DbObject report;
|
||||
|
||||
public LicenseModel() {
|
||||
}
|
||||
|
||||
public LicenseModel(String name, Character type, Integer period, Integer maxActivation) {
|
||||
this.initUuid();
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.period = period;
|
||||
this.maxActivation = maxActivation;
|
||||
}
|
||||
|
||||
public void initUuid() {
|
||||
this.setUuid(UUID.randomUUID());
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
public void setUuid(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getIdName() {
|
||||
return this.idName;
|
||||
}
|
||||
|
||||
public void setIdName(String idName) {
|
||||
this.idName = idName;
|
||||
}
|
||||
|
||||
public Integer getPeriod() {
|
||||
return this.period;
|
||||
}
|
||||
|
||||
public void setPeriod(int period) {
|
||||
this.period = period;
|
||||
}
|
||||
|
||||
public Character getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void setType(char type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public boolean isTrial() {
|
||||
return this.getType() == 't';
|
||||
}
|
||||
|
||||
public boolean isPerpetual() {
|
||||
return this.getType() == 'p';
|
||||
}
|
||||
|
||||
public Integer getMaxActivation() {
|
||||
return this.maxActivation;
|
||||
}
|
||||
|
||||
public void setMaxActivation(int maxCount) {
|
||||
this.maxActivation = maxCount;
|
||||
}
|
||||
|
||||
public DbObject getProfile() {
|
||||
return this.profile;
|
||||
}
|
||||
|
||||
public boolean isFormal() {
|
||||
return this.isFormal;
|
||||
}
|
||||
|
||||
public void setFormal(boolean isFormal) {
|
||||
this.isFormal = isFormal;
|
||||
}
|
||||
|
||||
public void setProfile(DbObject profile) {
|
||||
this.profile = profile;
|
||||
}
|
||||
|
||||
public DbObject getReport() {
|
||||
if (this.report == null) {
|
||||
this.report = new DbObject();
|
||||
}
|
||||
|
||||
return this.report;
|
||||
}
|
||||
|
||||
public long getReportAsLong(String key) {
|
||||
return this.getReport().getLong(key);
|
||||
}
|
||||
|
||||
public void setReport(DbObject report) {
|
||||
this.report = report;
|
||||
}
|
||||
|
||||
public void setReport(String key, Object data) {
|
||||
this.getReport().put(key, data);
|
||||
}
|
||||
|
||||
public String getFreshExpiry() {
|
||||
if (Strings.isNullOrEmpty(this.freshExpiry)) {
|
||||
switch (this.getType()) {
|
||||
case 'p':
|
||||
case 'y':
|
||||
this.freshExpiry = "6m";
|
||||
break;
|
||||
case 't':
|
||||
this.freshExpiry = "45d";
|
||||
break;
|
||||
default:
|
||||
String var10001 = String.valueOf(this.period);
|
||||
this.freshExpiry = var10001 + this.type;
|
||||
}
|
||||
}
|
||||
|
||||
return this.freshExpiry;
|
||||
}
|
||||
|
||||
public void setFreshExpiry(String expiry) {
|
||||
this.freshExpiry = expiry;
|
||||
}
|
||||
|
||||
public String getActivatedExpiry() {
|
||||
if (Strings.isNullOrEmpty(this.activatedExpiry)) {
|
||||
switch (this.getType()) {
|
||||
case 'p':
|
||||
this.activatedExpiry = "3y";
|
||||
break;
|
||||
case 't':
|
||||
this.activatedExpiry = "45d";
|
||||
break;
|
||||
default:
|
||||
String var10001 = String.valueOf(this.period);
|
||||
this.activatedExpiry = var10001 + this.type;
|
||||
}
|
||||
}
|
||||
|
||||
return this.activatedExpiry;
|
||||
}
|
||||
|
||||
public void setActivatedExpiry(String expiry) {
|
||||
this.activatedExpiry = expiry;
|
||||
}
|
||||
|
||||
public String getAutoExtend() {
|
||||
if (this.isPerpetual()) {
|
||||
this.autoExtend = "1y";
|
||||
}
|
||||
|
||||
return this.autoExtend;
|
||||
}
|
||||
|
||||
public void setAutoExtend(String extend) {
|
||||
this.autoExtend = extend;
|
||||
}
|
||||
|
||||
public Date getFreshExpiry(Date from) {
|
||||
return (new Period(this.getFreshExpiry())).from(from);
|
||||
}
|
||||
|
||||
public Date getActivatedExpiry(Date from) {
|
||||
return (new Period(this.getActivatedExpiry())).from(from);
|
||||
}
|
||||
|
||||
public Date getNextExpiry(Date from) {
|
||||
return (new Period(this.getAutoExtend())).from(from);
|
||||
}
|
||||
|
||||
public static LicenseModel defaultTrial() {
|
||||
return new LicenseModel("Trial", 't', 45, 45);
|
||||
}
|
||||
|
||||
public class Period {
|
||||
private int period = 0;
|
||||
private char unit = 'd';
|
||||
|
||||
public Period(int period, char unit) {
|
||||
this.period = period;
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
public Period(String expireBy) {
|
||||
if (!Strings.isNullOrEmpty(expireBy)) {
|
||||
String[] tokens = expireBy.split("(?<=\\D)(?=\\d)|(?<=\\d)(?=\\D)");
|
||||
this.period = Integer.parseInt(tokens[0]);
|
||||
this.unit = tokens[1].toLowerCase().charAt(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int getPeriod() {
|
||||
return this.period;
|
||||
}
|
||||
|
||||
public char getUnit() {
|
||||
return this.unit;
|
||||
}
|
||||
|
||||
public Date fromNow() {
|
||||
return this.from(new Date());
|
||||
}
|
||||
|
||||
public Date from(Date date) {
|
||||
if (this.period > 0) {
|
||||
LocalDate localDate = (new DateTime(date)).plusDays(1).toLocalDate();
|
||||
switch (this.unit) {
|
||||
case 'd':
|
||||
case 't':
|
||||
return localDate.plusDays(this.period).toDate();
|
||||
case 'm':
|
||||
return localDate.plusMonths(this.period).toDate();
|
||||
case 'y':
|
||||
return localDate.plusYears(this.period).toDate();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "" + this.period + this.unit;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.midm.model.system;
|
||||
|
||||
import com.midm.model.org.User;
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.DBRef;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class PolicyAgreement {
|
||||
@Id
|
||||
private UUID uuid;
|
||||
@DBRef
|
||||
private User writer;
|
||||
private String category;
|
||||
private String version;
|
||||
private DbObject message;
|
||||
private Date created;
|
||||
|
||||
public PolicyAgreement() {
|
||||
this.init();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
this.uuid = UUID.randomUUID();
|
||||
this.created = new Date();
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
public void setUuid(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public User getWriter() {
|
||||
return this.writer;
|
||||
}
|
||||
|
||||
public void setWriter(User writer) {
|
||||
this.writer = writer;
|
||||
}
|
||||
|
||||
public String getCategory() {
|
||||
return this.category;
|
||||
}
|
||||
|
||||
public void setCategory(String category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public Date getCreated() {
|
||||
return this.created;
|
||||
}
|
||||
|
||||
public void setCreated(Date created) {
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public DbObject getMessage() {
|
||||
if (this.message == null) {
|
||||
this.message = new DbObject();
|
||||
}
|
||||
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return this.message.getString("content");
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.setContent(Locale.US.toLanguageTag(), content);
|
||||
}
|
||||
|
||||
public void setContent(String languageTag, String content) {
|
||||
DbObject message = this.getMessage(languageTag);
|
||||
message.put("content", content);
|
||||
}
|
||||
|
||||
public DbObject getMessage(String languageTag) {
|
||||
DbObject message = this.getMessage();
|
||||
DbObject localedMessage = new DbObject();
|
||||
message.put(languageTag, localedMessage);
|
||||
return localedMessage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.midm.model.system;
|
||||
|
||||
import java.util.Locale;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class ResourceLocale {
|
||||
@Id
|
||||
private String locale;
|
||||
private String name;
|
||||
private Integer order;
|
||||
private Boolean enabled;
|
||||
|
||||
public ResourceLocale() {
|
||||
}
|
||||
|
||||
public ResourceLocale(String locale, String name) {
|
||||
this.init(locale, name, true);
|
||||
}
|
||||
|
||||
public ResourceLocale(String locale, String name, boolean enabled) {
|
||||
this.init(locale, name, enabled);
|
||||
}
|
||||
|
||||
public void init(String locale, String name, boolean enabled) {
|
||||
this.setLocale(locale);
|
||||
this.setName(name);
|
||||
this.setEnabled(enabled);
|
||||
this.setOrder(0);
|
||||
}
|
||||
|
||||
public String getLocale() {
|
||||
return this.locale;
|
||||
}
|
||||
|
||||
public void setLocale(String locale) {
|
||||
this.locale = locale;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(Boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public Integer getOrder() {
|
||||
return this.order;
|
||||
}
|
||||
|
||||
public void setOrder(Integer order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public Locale toLocale() {
|
||||
return Locale.forLanguageTag(this.getLocale());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.midm.model.system;
|
||||
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import com.mitac.cell.utils.McStringUtils;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class ResourceMessage {
|
||||
@Id
|
||||
private String code;
|
||||
private DbObject messages;
|
||||
private String comment;
|
||||
|
||||
public ResourceMessage() {
|
||||
}
|
||||
|
||||
public ResourceMessage(String code) {
|
||||
this.setCode(code);
|
||||
}
|
||||
|
||||
public ResourceMessage(String code, String locale, String message, String comment) {
|
||||
this.setCode(code);
|
||||
this.setMessage(locale, message);
|
||||
this.setComment(comment);
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public DbObject getMessages() {
|
||||
if (this.messages == null) {
|
||||
this.messages = new DbObject();
|
||||
}
|
||||
|
||||
return this.messages;
|
||||
}
|
||||
|
||||
public void setMessages(DbObject messages) {
|
||||
this.messages = messages;
|
||||
}
|
||||
|
||||
public void setMessage(String locale, String message) {
|
||||
this.getMessages().append(locale, message);
|
||||
}
|
||||
|
||||
public String getMessage(String locale) {
|
||||
String message = this.getMessages().getString(locale);
|
||||
return McStringUtils.isNullOrEmpty(message) ? getDefaultMessage(this.code) : message;
|
||||
}
|
||||
|
||||
public static String getDefaultMessage(String code) {
|
||||
return "#" + code;
|
||||
}
|
||||
|
||||
public String getComment() {
|
||||
return this.comment;
|
||||
}
|
||||
|
||||
public void setComment(String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
package com.midm.model.system;
|
||||
|
||||
import com.google.common.base.CharMatcher;
|
||||
import com.midm.model.org.Site;
|
||||
import com.midm.model.org.User;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.DBRef;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class StandaloneLicense {
|
||||
@Id
|
||||
private UUID uuid;
|
||||
@DBRef
|
||||
private Site site;
|
||||
private User writer;
|
||||
private String hostId;
|
||||
private String systemHash;
|
||||
private String licenseType;
|
||||
private String licenseKey;
|
||||
private String status;
|
||||
private Integer deviceLimit;
|
||||
private long validTo = -1L;
|
||||
private Integer period;
|
||||
private boolean isStandalone = true;
|
||||
private List notes;
|
||||
private Date updated;
|
||||
protected Date created;
|
||||
|
||||
public UUID getUuid() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
public void init(User user) {
|
||||
this.uuid = UUID.randomUUID();
|
||||
this.writer = user;
|
||||
this.created = new Date();
|
||||
this.updated = new Date();
|
||||
}
|
||||
|
||||
public void setUuid(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public String getHostId() {
|
||||
return this.hostId;
|
||||
}
|
||||
|
||||
public void setHostId(String hostId) {
|
||||
this.hostId = hostId;
|
||||
}
|
||||
|
||||
public String getSystemHash() {
|
||||
return this.systemHash;
|
||||
}
|
||||
|
||||
public void setSystemHash(String systemHash) {
|
||||
this.systemHash = systemHash;
|
||||
}
|
||||
|
||||
public String getLicenseKey() {
|
||||
return this.licenseKey;
|
||||
}
|
||||
|
||||
public void setLicenseKey(String licenseKey) {
|
||||
this.licenseKey = licenseKey;
|
||||
}
|
||||
|
||||
public Integer getDeviceLimit() {
|
||||
return this.deviceLimit;
|
||||
}
|
||||
|
||||
public void setDeviceLimit(Integer deviceLimit) {
|
||||
this.deviceLimit = deviceLimit;
|
||||
}
|
||||
|
||||
public long getValidTo() {
|
||||
return this.validTo;
|
||||
}
|
||||
|
||||
public void setValidTo(long validTo) {
|
||||
this.validTo = validTo;
|
||||
}
|
||||
|
||||
public boolean isStandalone() {
|
||||
return this.isStandalone;
|
||||
}
|
||||
|
||||
public void setStandalone(boolean isStandalone) {
|
||||
this.isStandalone = isStandalone;
|
||||
}
|
||||
|
||||
public Site getSite() {
|
||||
return this.site;
|
||||
}
|
||||
|
||||
public void setSite(Site site) {
|
||||
this.site = site;
|
||||
}
|
||||
|
||||
public String getLicenseType() {
|
||||
return this.licenseType;
|
||||
}
|
||||
|
||||
public void setLicenseType(String licenseType) {
|
||||
this.licenseType = licenseType;
|
||||
}
|
||||
|
||||
public Date getCreated() {
|
||||
return this.created;
|
||||
}
|
||||
|
||||
public void setCreated(Date created) {
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
public Date getUpdated() {
|
||||
return this.updated;
|
||||
}
|
||||
|
||||
public void setUpdated(Date updated) {
|
||||
this.updated = updated;
|
||||
}
|
||||
|
||||
public List getNotes() {
|
||||
if (this.notes == null) {
|
||||
this.notes = new ArrayList();
|
||||
}
|
||||
|
||||
return this.notes;
|
||||
}
|
||||
|
||||
public void setNotes(List notes) {
|
||||
this.notes = notes;
|
||||
}
|
||||
|
||||
public void addNote(String note) {
|
||||
this.getNotes().add(new Note(this.writer, note));
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Integer getPeriod() {
|
||||
return this.period;
|
||||
}
|
||||
|
||||
public void setPeriod(Integer period) {
|
||||
this.period = period;
|
||||
}
|
||||
|
||||
public static enum STATUS {
|
||||
REQUESTED,
|
||||
PROCESSING,
|
||||
CONFIRMED,
|
||||
CANCELED,
|
||||
REJECTED,
|
||||
EXPIRED,
|
||||
RENEWED,
|
||||
UNKNOWN;
|
||||
|
||||
public static STATUS get(String key) {
|
||||
try {
|
||||
return valueOf(CharMatcher.whitespace().removeFrom(key).toLowerCase());
|
||||
} catch (Exception var2) {
|
||||
return UNKNOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Note {
|
||||
private User recordedBy;
|
||||
private String note;
|
||||
private Date noted;
|
||||
|
||||
public Note() {
|
||||
}
|
||||
|
||||
public Note(User user, String note) {
|
||||
this.recordedBy = user;
|
||||
this.note = note;
|
||||
this.noted = new Date();
|
||||
}
|
||||
|
||||
public User getRecordedBy() {
|
||||
return this.recordedBy;
|
||||
}
|
||||
|
||||
public void setRecordedBy(User recordedBy) {
|
||||
this.recordedBy = recordedBy;
|
||||
}
|
||||
|
||||
public String getNote() {
|
||||
return this.note;
|
||||
}
|
||||
|
||||
public void setNote(String note) {
|
||||
this.note = note;
|
||||
}
|
||||
|
||||
public Date getNoted() {
|
||||
return this.noted;
|
||||
}
|
||||
|
||||
public void setNoted(Date noted) {
|
||||
this.noted = noted;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.midm.model.system;
|
||||
|
||||
import com.mitac.cell.utils.McNumberUtils;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class SystemSetting {
|
||||
@Id
|
||||
private String key;
|
||||
private String value;
|
||||
|
||||
public SystemSetting() {
|
||||
}
|
||||
|
||||
public SystemSetting(String key, Object value) {
|
||||
this.setKey(key);
|
||||
this.setValue(value != null ? String.valueOf(value) : null);
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Integer getAsInteger() {
|
||||
return McNumberUtils.toInt(this.getValue());
|
||||
}
|
||||
|
||||
public Long getAsLong() {
|
||||
return McNumberUtils.toLong(this.getValue());
|
||||
}
|
||||
|
||||
public Boolean getAsBoolean() {
|
||||
return this.value.equalsIgnoreCase("true");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.midm.model.template;
|
||||
|
||||
import com.midm.model.org.User;
|
||||
import com.mitac.cell.db.DbObject;
|
||||
import java.util.Date;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class MailTemplate {
|
||||
@Id
|
||||
private String idName;
|
||||
private String name;
|
||||
private String description;
|
||||
private DbObject template;
|
||||
private User writer;
|
||||
private Date created;
|
||||
private Date updated;
|
||||
|
||||
public void init() {
|
||||
this.created = new Date();
|
||||
this.updated = new Date();
|
||||
}
|
||||
|
||||
public String getIdName() {
|
||||
return this.idName;
|
||||
}
|
||||
|
||||
public void setIdName(String idName) {
|
||||
this.idName = idName;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public DbObject getTemplate() {
|
||||
return this.template;
|
||||
}
|
||||
|
||||
public void setTemplate(DbObject template) {
|
||||
this.template = template;
|
||||
}
|
||||
|
||||
public User getWriter() {
|
||||
return this.writer;
|
||||
}
|
||||
|
||||
public void setWriter(User writer) {
|
||||
this.writer = writer;
|
||||
}
|
||||
|
||||
public Date getCreated() {
|
||||
return this.created;
|
||||
}
|
||||
|
||||
public void setCreated(Date created) {
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
public Date getUpdated() {
|
||||
return this.updated;
|
||||
}
|
||||
|
||||
public void setUpdated(Date updated) {
|
||||
this.updated = updated;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user