Commit 85a82694 authored by Aaron Gutierrez's avatar Aaron Gutierrez

Modelo de agentes

parent d3d98737
package com.bytesw.bytebot.model;
import com.bytesw.bytebot.model.converters.AgentStatusConverter;
import com.bytesw.bytebot.model.converters.AgentTypeConverter;
import com.bytesw.bytebot.model.enums.AgentStatusEnum;
import com.bytesw.bytebot.model.enums.AgentTypeEnum;
import com.bytesw.bytebot.model.enums.LanguageEnum;
import lombok.*;
import javax.persistence.*;
import java.io.Serializable;
@Entity
@Getter @Setter @ToString @EqualsAndHashCode(of = "id")
@NoArgsConstructor
@Table(name = "BBOT_AGENT")
@NamedQuery(name = "Agent.findByPK", query = "Select u from Agent u where u.id = ?1")
public class Agent implements Serializable {
@Id
@TableGenerator(name = "BBOT_AGENT_GENERATOR", table = "SEQUENCE_TABLE", pkColumnName = "SEQ_NAME",
valueColumnName = "SEQ_COUNT", pkColumnValue = "BBOT_AGENT_SEQ", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.TABLE, generator = "BBOT_AGENT_GENERATOR")
@Column(name = "AGEN_ID")
private Long id;
@Column(name = "AGEN_IDEN", nullable = false)
private String identifier;
@Column(name = "AGEN_DESCR", nullable = false)
private String description;
@Column(name = "AGEN_VERS", nullable = false)
private String version;
@Column(name = "AGEN_LANG", nullable = false)
@Convert(converter = AgentTypeConverter.class)
private LanguageEnum language;
@Column(name = "AGEN_TZONE", nullable = false)
private String timeZone;
@Column(name = "AGEN_TZONE", nullable = false)
private Country country;
@Column(name = "AGEN_STATE", nullable = false)
@Convert(converter = AgentStatusConverter.class)
private AgentStatusEnum state;
@Column(name = "AGEN_TYPE", nullable = false)
@Convert(converter = AgentTypeConverter.class)
private AgentTypeEnum type;
}
package com.bytesw.bytebot.model;
import lombok.*;
import javax.persistence.*;
@Entity
@Getter @Setter @ToString @EqualsAndHashCode(of = "id")
@NoArgsConstructor
@Table(name = "BBOT_COUNTRY")
@NamedQuery(name = "Country.findByPK", query = "Select u from Country u where u.id = ?1")
public class Country {
@Id
@TableGenerator(name = "BBOT_COUNTRY_GENERATOR", table = "SEQUENCE_TABLE", pkColumnName = "SEQ_NAME",
valueColumnName = "SEQ_COUNT", pkColumnValue = "BBOT_COUNTRY_SEQ", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.TABLE, generator = "BBOT_COUNTRY_GENERATOR")
@Column(name = "COUN_ID")
private Long id;
@Column(name = "COUN_IDEN", nullable = false)
private String identifier;
}
package com.bytesw.bytebot.model.converters;
import com.bytesw.bytebot.model.enums.AgentStatusEnum;
import org.apache.camel.Converter;
import javax.persistence.AttributeConverter;
@Converter
public class AgentStatusConverter implements AttributeConverter<AgentStatusEnum, String> {
@Override
public String convertToDatabaseColumn(AgentStatusEnum agentStatusEnum) {
if (agentStatusEnum == null) return null;
return agentStatusEnum.getName();
}
@Override
public AgentStatusEnum convertToEntityAttribute(String s) {
return AgentStatusEnum.fromString(s);
}
}
package com.bytesw.bytebot.model.converters;
import com.bytesw.bytebot.model.enums.AgentTypeEnum;
import org.apache.camel.Converter;
import javax.persistence.AttributeConverter;
@Converter
public class AgentTypeConverter implements AttributeConverter<AgentTypeEnum, String> {
@Override
public String convertToDatabaseColumn(AgentTypeEnum agentTypeEnum) {
if (agentTypeEnum == null) return null;
return agentTypeEnum.getName();
}
@Override
public AgentTypeEnum convertToEntityAttribute(String s) {
return AgentTypeEnum.fromString(s);
}
}
package com.bytesw.bytebot.model.enums;
import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;
public enum AgentStatusEnum {
CREATE("C"), DEPLOYMENT("I");
private final String name;
private static final Map<String, AgentStatusEnum> map = new HashMap<>();
static {
for (AgentStatusEnum type : AgentStatusEnum.values()) {
map.put(type.name, type);
}
}
AgentStatusEnum(String name) {
this.name = name;
}
public String getName() {
return name;
}
public static AgentStatusEnum fromString(String name) {
if (map.containsKey(name)) {
return map.get(name);
}
throw new NoSuchElementException(name + " not found");
}
}
package com.bytesw.bytebot.model.enums;
import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;
public enum AgentTypeEnum {
FREQUENT_QUESTION("F");
private final String name;
private static final Map<String, AgentTypeEnum> map = new HashMap<>();
static {
for (AgentTypeEnum type : AgentTypeEnum.values()) {
map.put(type.name, type);
}
}
AgentTypeEnum(String name) {
this.name = name;
}
public String getName() {
return name;
}
public static AgentTypeEnum fromString(String name) {
if (map.containsKey(name)) {
return map.get(name);
}
throw new NoSuchElementException(name + " not found");
}
}
package com.bytesw.bytebot.model.enums;
import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;
public enum LanguageEnum {
SPANISH("S");
private final String name;
private static final Map<String, LanguageEnum> map = new HashMap<>();
static {
for (LanguageEnum type : LanguageEnum.values()) {
map.put(type.name, type);
}
}
LanguageEnum(String name) {
this.name = name;
}
public String getName() {
return name;
}
public static LanguageEnum fromString(String name) {
if (map.containsKey(name)) {
return map.get(name);
}
throw new NoSuchElementException(name + " not found");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment