- restore generic signatures, scoped variables and missing code from original bytecode - remove decompiler artifacts and document classes, methods, fields and packages - restore resources, add Batik/BouncyCastle dependencies and build/runtime docs
367 lines
9.2 KiB
Java
367 lines
9.2 KiB
Java
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;
|
||
|
||
/**
|
||
* 【MongoDB 文档实体】{@code DeviceProfileState}
|
||
*
|
||
* 类职责:
|
||
* <ul>
|
||
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
|
||
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
|
||
* </ul>
|
||
*
|
||
* 核心字段(按声明顺序):
|
||
* <ul>
|
||
* <li>{@code STATE_IN_PROGRESS}(String):字段 STATE_IN_PROGRESS</li>
|
||
* <li>{@code STATE_DONE}(String):字段 STATE_DONE</li>
|
||
* <li>{@code STATE_UNKNWON}(String):字段 STATE_UNKNWON</li>
|
||
* <li>{@code scoped}(Scoped):字段 scoped</li>
|
||
* <li>{@code updated}(long):最后更新时间</li>
|
||
* <li>{@code state}(String):状态</li>
|
||
* </ul>
|
||
*
|
||
* 协作对象:{@code Scoped、DeviceReport}。
|
||
*
|
||
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
|
||
*
|
||
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
|
||
*/
|
||
@Document
|
||
@CompoundIndexes({@CompoundIndex(
|
||
def = "{'_id.deviceUuid': 1}"
|
||
), @CompoundIndex(
|
||
def = "{'_id.profileUuid': 1}"
|
||
)})
|
||
public class DeviceProfileState {
|
||
/**
|
||
* 字段 STATE_IN_PROGRESS。
|
||
*/
|
||
public static final String STATE_IN_PROGRESS = "in_progress";
|
||
/**
|
||
* 字段 STATE_DONE。
|
||
*/
|
||
public static final String STATE_DONE = "done";
|
||
/**
|
||
* 字段 STATE_UNKNWON。
|
||
*/
|
||
public static final String STATE_UNKNWON = "unknown";
|
||
/**
|
||
* 字段 scoped;MongoDB 主键。
|
||
*
|
||
* 注解:{@code @Id}。
|
||
*/
|
||
@Id
|
||
private Scoped scoped;
|
||
/**
|
||
* 最后更新时间。
|
||
*/
|
||
private long updated = -1L;
|
||
/**
|
||
* 状态;建有索引,常用于查询条件。
|
||
*
|
||
* 注解:{@code @Indexed}。
|
||
*/
|
||
@Indexed
|
||
private String state = "unknown";
|
||
/**
|
||
* 应用第一状态。
|
||
*/
|
||
private String applyFirstState = "unknown";
|
||
/**
|
||
* 字段 applied;建有索引,常用于查询条件。
|
||
*
|
||
* 注解:{@code @Indexed}。
|
||
*/
|
||
@Indexed
|
||
private long applied;
|
||
/**
|
||
* 报表;不持久化到 MongoDB,仅运行时使用。
|
||
*
|
||
* 注解:{@code @Transient}。
|
||
*/
|
||
@Transient
|
||
private DeviceReport report;
|
||
|
||
/**
|
||
* 构造 {@code DeviceProfileState} 实例。
|
||
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
|
||
*/
|
||
public DeviceProfileState() {
|
||
}
|
||
|
||
/**
|
||
* 构造 {@code DeviceProfileState} 实例。
|
||
*
|
||
* 实现要点:主要调用:new Scoped、new Date。
|
||
*
|
||
* @param device 设备({@code Device})
|
||
* @param profile 设备配置档案({@code DeviceProfile})
|
||
*/
|
||
public DeviceProfileState(Device device, DeviceProfile profile) {
|
||
this.scoped = new Scoped(profile.getUuid(), device.getUuid());
|
||
this.updated = profile.getUpdated().getTime();
|
||
this.applied = (new Date()).getTime();
|
||
}
|
||
|
||
/**
|
||
* 构造 {@code DeviceProfileState} 实例。
|
||
*
|
||
* @param report 参数 {@code report}({@code DeviceReport})
|
||
*/
|
||
public DeviceProfileState(DeviceReport report) {
|
||
this.setReport(report);
|
||
}
|
||
|
||
/**
|
||
* 获取 {@code scoped}。
|
||
* @return 字段/派生属性 {@code scoped} 的值
|
||
*/
|
||
public Scoped getScoped() {
|
||
return this.scoped;
|
||
}
|
||
|
||
/**
|
||
* 设置 {@code scoped}。
|
||
*
|
||
* @param scoped 参数 {@code scoped}({@code Scoped})
|
||
*/
|
||
public void setScoped(Scoped scoped) {
|
||
this.scoped = scoped;
|
||
}
|
||
|
||
/**
|
||
* 获取 {@code profileUuid}。
|
||
* @return UUID
|
||
*/
|
||
public UUID getProfileUuid() {
|
||
return this.getScoped().getProfileUuid();
|
||
}
|
||
|
||
/**
|
||
* 获取 {@code deviceUuid}。
|
||
* @return UUID
|
||
*/
|
||
public UUID getDeviceUuid() {
|
||
return this.getScoped().getDeviceUuid();
|
||
}
|
||
|
||
/**
|
||
* 获取 {@code updated}。
|
||
* @return 数量/长度
|
||
*/
|
||
public long getUpdated() {
|
||
return this.updated;
|
||
}
|
||
|
||
/**
|
||
* 设置 {@code updated}。
|
||
*
|
||
* @param updated 参数 {@code updated}({@code long})
|
||
*/
|
||
public void setUpdated(long updated) {
|
||
this.updated = updated;
|
||
}
|
||
|
||
/**
|
||
* 获取 {@code state}。
|
||
* @return 字符串结果
|
||
*/
|
||
public String getState() {
|
||
return this.state;
|
||
}
|
||
|
||
/**
|
||
* 判断 {@code done}。
|
||
* @return 字段/派生属性 {@code done} 的值
|
||
*/
|
||
public boolean isDone() {
|
||
return this.state == null || this.state.equals("done");
|
||
}
|
||
|
||
/**
|
||
* 设置 {@code state}。
|
||
*
|
||
* @param state 参数 {@code state}({@code String})
|
||
*/
|
||
public void setState(String state) {
|
||
this.state = state;
|
||
}
|
||
|
||
/**
|
||
* 获取 {@code applyFirstState}。
|
||
* @return 字符串结果
|
||
*/
|
||
public String getApplyFirstState() {
|
||
return this.applyFirstState;
|
||
}
|
||
|
||
/**
|
||
* 判断 {@code applyFirstDone}。
|
||
* @return 字段/派生属性 {@code applyFirstDone} 的值
|
||
*/
|
||
public boolean isApplyFirstDone() {
|
||
return this.applyFirstState != null && this.applyFirstState.equals("done");
|
||
}
|
||
|
||
/**
|
||
* 设置 {@code applyFirstState}。
|
||
*
|
||
* @param applyFirstState 参数 {@code applyFirstState}({@code String})
|
||
*/
|
||
public void setApplyFirstState(String applyFirstState) {
|
||
this.applyFirstState = applyFirstState;
|
||
}
|
||
|
||
/**
|
||
* 获取 {@code applied}。
|
||
* @return 数量/长度
|
||
*/
|
||
public long getApplied() {
|
||
return this.applied;
|
||
}
|
||
|
||
/**
|
||
* 设置 {@code applied}。
|
||
*
|
||
* @param applied 参数 {@code applied}({@code long})
|
||
*/
|
||
public void setApplied(long applied) {
|
||
this.applied = applied;
|
||
this.setState("done");
|
||
}
|
||
|
||
/**
|
||
* 设置Applied。
|
||
*
|
||
* @param applied 参数 {@code applied}({@code long})
|
||
* @param state 参数 {@code state}({@code String})
|
||
*/
|
||
public void setApplied(long applied, String state) {
|
||
this.state = state;
|
||
this.applied = applied;
|
||
}
|
||
|
||
/**
|
||
* 设置Applied。
|
||
*
|
||
* 实现要点:主要调用:new Date。
|
||
*/
|
||
public void setApplied() {
|
||
this.applied = (new Date()).getTime();
|
||
}
|
||
|
||
/**
|
||
* 获取 {@code report}。
|
||
* @return 字段/派生属性 {@code report} 的值
|
||
*/
|
||
public DeviceReport getReport() {
|
||
return this.report;
|
||
}
|
||
|
||
/**
|
||
* 设置 {@code report}。
|
||
*
|
||
* 实现要点:主要调用:new Scoped。
|
||
*
|
||
* @param report 参数 {@code report}({@code DeviceReport})
|
||
*/
|
||
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");
|
||
}
|
||
|
||
/**
|
||
* 【领域模型】{@code Scoped}
|
||
*
|
||
* 类职责:
|
||
* <ul>
|
||
* <li>表达领域对象的数据结构、字段约束与派生属性。</li>
|
||
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
|
||
* </ul>
|
||
*
|
||
* 核心字段(按声明顺序):
|
||
* <ul>
|
||
* <li>{@code profileUuid}(UUID):配置档案UUID</li>
|
||
* <li>{@code deviceUuid}(UUID):设备UUID</li>
|
||
* </ul>
|
||
*
|
||
* 学习提示:先看类注释和 public 方法,再结合调用方理解它在整体流程中的位置。
|
||
*/
|
||
public static class Scoped implements Serializable {
|
||
/**
|
||
* 配置档案UUID。
|
||
*/
|
||
private UUID profileUuid;
|
||
/**
|
||
* 设备UUID。
|
||
*/
|
||
private UUID deviceUuid;
|
||
|
||
/**
|
||
* 构造 {@code Scoped} 实例。
|
||
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
|
||
*/
|
||
public Scoped() {
|
||
}
|
||
|
||
/**
|
||
* 构造 {@code Scoped} 实例。
|
||
*
|
||
* @param profileUuid 配置档案 UUID({@code UUID})
|
||
* @param deviceUuid 设备 UUID({@code UUID})
|
||
*/
|
||
public Scoped(UUID profileUuid, UUID deviceUuid) {
|
||
this.profileUuid = profileUuid;
|
||
this.deviceUuid = deviceUuid;
|
||
}
|
||
|
||
/**
|
||
* 获取 {@code profileUuid}。
|
||
* @return UUID
|
||
*/
|
||
public UUID getProfileUuid() {
|
||
return this.profileUuid;
|
||
}
|
||
|
||
/**
|
||
* 设置 {@code profileUuid}。
|
||
*
|
||
* @param profileUuid 配置档案 UUID({@code UUID})
|
||
*/
|
||
public void setProfileUuid(UUID profileUuid) {
|
||
this.profileUuid = profileUuid;
|
||
}
|
||
|
||
/**
|
||
* 获取 {@code deviceUuid}。
|
||
* @return UUID
|
||
*/
|
||
public UUID getDeviceUuid() {
|
||
return this.deviceUuid;
|
||
}
|
||
|
||
/**
|
||
* 设置 {@code deviceUuid}。
|
||
*
|
||
* @param deviceUuid 设备 UUID({@code UUID})
|
||
*/
|
||
public void setDeviceUuid(UUID deviceUuid) {
|
||
this.deviceUuid = deviceUuid;
|
||
}
|
||
}
|
||
}
|