
com.hecloud.runtime.common.model.License Maven / Gradle / Ivy
package com.hecloud.runtime.common.model;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.hecloud.runtime.common.encryptor.Encryptor;
import com.hecloud.runtime.common.encryptor.MD5Encryptor;
import com.hecloud.runtime.common.enums.LicenseAction;
import com.hecloud.runtime.common.enums.LicenseCatalog;
import com.hecloud.runtime.common.generator.IDFactory;
import com.hecloud.runtime.common.serializer.DateDeserializer;
import com.hecloud.runtime.common.serializer.DateSerializer;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* License对象
*
* @author LoveInBJ
*/
@Data
public class License {
private static Encryptor encryptor = new MD5Encryptor();
/**
* 节点数
*/
private Integer node;
/**
* 可用月数
*/
private Integer month;
/**
* mac地址数组
*/
private List address;
/**
* 允许服务模块
*/
private List service;
/**
* 当前项目
*/
private String project = "Test";
private String md5;
/**
* 证书操作
*/
private LicenseAction action = LicenseAction.New;
/**
* 证书类型
*/
private LicenseCatalog catalog;
/**
* 创建时间
*/
private Date createDate;
/**
* 过期时间
*/
@JsonSerialize(using = DateSerializer.class)
@JsonDeserialize(using = DateDeserializer.class)
private Date expireDate;
public License() {
}
public License(Integer node, Integer month, List address, List service, String project, LicenseAction action, LicenseCatalog catalog) {
this.node = node;
this.month = month;
this.address = address;
this.service = service;
Optional.ofNullable(project).ifPresent(data -> this.project = data);
Optional.ofNullable(action).ifPresent(data -> this.action = data);
this.catalog = catalog;
this.createDate = new Date();
try {
this.md5 = encryptor.encrypt(this.project, "BeyondCMP");
} catch (Exception e) {
this.md5 = IDFactory.instance().uuid();
}
}
public Integer getNode() {
return Optional.ofNullable(node).orElse(24);
}
public void setNode(Integer node) {
this.node = node;
}
public List getAddress() {
final List servers = Optional.ofNullable(address).orElse(new ArrayList<>());
return servers.stream().filter(StringUtils::isNotBlank).collect(Collectors.toList());
}
public void setProject(String project) {
Optional.ofNullable(project).ifPresent(p -> this.project = p);
}
public void setAction(LicenseAction action) {
Optional.ofNullable(action).ifPresent(data -> this.action = data);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy