Skip to content
Snippets Groups Projects
Commit 6b1cce13 authored by Michal Schejbal's avatar Michal Schejbal
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 1452 additions and 0 deletions
##########################
## Java
##########################
*.class
.mtj.tmp/
*.jar
*.war
*.ear
hs_err_pid*
##########################
## Maven
##########################
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
##########################
## IntelliJ
##########################
*.iml
.idea/
*.ipr
*.iws
out/
.idea_modules/
##########################
## Eclipse
##########################
.metadata
.classpath
.project
.settings/
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.loadpath
##########################
## NetBeans
##########################
nbproject/private/
build/
nbbuild/
dist/
nbdist/
nbactions.xml
nb-configuration.xml
##########################
## OS X
##########################
.DS_Store
##########################
## Project specific
##########################
ocr/
img/
/data/output
convertor
/persistence.local.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="persistence-server">
<description>
Hibernate Persistence - Server
</description>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://irtis.fi.muni.cz:5432/jpa_test" />
<property name="javax.persistence.jdbc.user" value="test_user" />
<property name="javax.persistence.jdbc.password" value="password" />
</properties>
</persistence-unit>
</persistence>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="persistence">
<description>
Hibernate Persistence
</description>
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<!-- <mapping-file>file:///etc/opt/app/mappings/orm.xml</mapping-file> -->
<properties>
<!--@todo specify PostgreSQL server version-->
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL9Dialect" />
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
<!-- <property name="hibernate.connection.driver_class" value="org.postgresql.jdbc" />-->
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<!--Use local & server files to configure access -->
<!-- <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/irtis" />-->
<!-- <property name="javax.persistence.jdbc.user" value="postgres" />-->
<!-- <property name="javax.persistence.jdbc.password" value="root" />-->
</properties>
</persistence-unit>
</persistence>
\ No newline at end of file
pom.xml 0 → 100644
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cz.muni.irtis</groupId>
<artifactId>irtis-repository</artifactId>
<version>1</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api -->
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.14.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.14</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.10</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package cz.muni.irtis.repository;
import cz.muni.irtis.repository.database.PersistenceConfigLoader;
import cz.muni.irtis.repository.database.PersistenceHandler;
import cz.muni.irtis.repository.model.RepositoryFilter;
import cz.muni.irtis.repository.model.RepositoryLimit;
import cz.muni.irtis.repository.model.RepositoryOrder;
import cz.muni.irtis.repository.model.messages.Message;
import cz.muni.irtis.repository.model.messages.MessagesRepository;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
/**
* Repository
*
* Testing point for the Repository API
*/
public class Repository {
public static void main(String[] args) {
System.out.println("Repository started");
// Session session = PersistenceHandler.build().getSession();
// Message item = Message.build(1L);
// item.setText("Ahoj jsme native");
// MessagesRepository messages = new MessagesRepository();
// item = messages.getItem(item);
// item.setCreated(System.currentTimeMillis());
// messages.store(item);
//
// item = Message.build();
// item.setText("Novinka");
// messages.store(item);
// List<Message> items = messages.getItems(RepositoryFilter.build().add("created IS NULL"), RepositoryOrder.build().add("id"), RepositoryLimit.build(3));
// if(items!=null) {
// Iterator<Message> iMessages = items.iterator();
// while (iMessages.hasNext()) {
// Message message = iMessages.next();
// System.out.println(message.getId().toString());
// }
// }
}
}
package cz.muni.irtis.repository.database;
import com.google.gson.GsonBuilder;
import cz.muni.irtis.repository.model.RepositoryInstanceBase;
abstract public class EntityBase {
static public <Entity extends EntityBase, Instance extends RepositoryInstanceBase> Entity build(Instance item) {
return null;
}
abstract public Long getId();
public String toString() {
return new GsonBuilder().create().toJson(this);
}
}
package cz.muni.irtis.repository.database;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
/**
* PersistenceConfigLoader
*
*/
public class PersistenceConfigLoader {
static public PersistenceConfigLoader build() {
return new PersistenceConfigLoader();
}
public Properties getConfig() {
Properties config = getBase();
if(isLocal()) {
config.putAll(getLocal());
} else if(isServer()) {
config.putAll(getServer());
}
return config;
}
private Properties getBase() {
Properties config = new Properties();
try {
File file = new File("persistence.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = dbFactory.newDocumentBuilder();
Document document = builder.parse(file);
document.getDocumentElement().normalize(); // See this http://stackoverflow.com/questions/13786607/normalization-in-dom-parsing-with-java-how-does-it-work
// System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
NodeList ePropertiesItems = document.getElementsByTagName("properties");
for (int iPropertiesItems = 0; iPropertiesItems < ePropertiesItems.getLength(); iPropertiesItems++) {
Node nNode = ePropertiesItems.item(iPropertiesItems);
// System.out.println("\nCurrent Element :" + nNode.getNodeName());
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element ePropertiesElement = (Element) nNode;
NodeList ePropertyItems = ePropertiesElement.getElementsByTagName("property");
for (int iPropertyItems = 0; iPropertyItems < ePropertyItems.getLength(); iPropertyItems++) {
Element ePropertyElement = (Element) ePropertyItems.item(iPropertyItems);
if (ePropertyElement.getNodeType() == Node.ELEMENT_NODE) {
String name = ePropertyElement.getAttribute("name");
String value = ePropertyElement.getAttribute("value");
config.put(name, value);
// System.out.println("Name: "+name+"; Value: "+value);
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return config;
}
private Properties getServer() {
Properties config = new Properties();
try {
File file = new File("persistence.server.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = dbFactory.newDocumentBuilder();
Document document = builder.parse(file);
document.getDocumentElement().normalize(); // See this http://stackoverflow.com/questions/13786607/normalization-in-dom-parsing-with-java-how-does-it-work
NodeList ePropertiesItems = document.getElementsByTagName("properties");
for (int iPropertiesItems = 0; iPropertiesItems < ePropertiesItems.getLength(); iPropertiesItems++) {
Node nNode = ePropertiesItems.item(iPropertiesItems);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element ePropertiesElement = (Element) nNode;
NodeList ePropertyItems = ePropertiesElement.getElementsByTagName("property");
for (int iPropertyItems = 0; iPropertyItems < ePropertyItems.getLength(); iPropertyItems++) {
Element ePropertyElement = (Element) ePropertyItems.item(iPropertyItems);
if (ePropertyElement.getNodeType() == Node.ELEMENT_NODE) {
String name = ePropertyElement.getAttribute("name");
String value = ePropertyElement.getAttribute("value");
config.put(name, value);
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return config;
}
private Properties getLocal() {
Properties config = new Properties();
try {
File file = new File("persistence.local.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = dbFactory.newDocumentBuilder();
Document document = builder.parse(file);
document.getDocumentElement().normalize(); // See this http://stackoverflow.com/questions/13786607/normalization-in-dom-parsing-with-java-how-does-it-work
NodeList ePropertiesItems = document.getElementsByTagName("properties");
for (int iPropertiesItems = 0; iPropertiesItems < ePropertiesItems.getLength(); iPropertiesItems++) {
Node nNode = ePropertiesItems.item(iPropertiesItems);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element ePropertiesElement = (Element) nNode;
NodeList ePropertyItems = ePropertiesElement.getElementsByTagName("property");
for (int iPropertyItems = 0; iPropertyItems < ePropertyItems.getLength(); iPropertyItems++) {
Element ePropertyElement = (Element) ePropertyItems.item(iPropertyItems);
if (ePropertyElement.getNodeType() == Node.ELEMENT_NODE) {
String name = ePropertyElement.getAttribute("name");
String value = ePropertyElement.getAttribute("value");
config.put(name, value);
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return config;
}
private boolean isLocal() {
return new File("persistence.local.xml").exists();
}
private boolean isServer() {
return new File("persistence.server.xml").exists();
}
}
package cz.muni.irtis.repository.database;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import javax.persistence.Entity;
import javax.tools.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Properties;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
public class PersistenceHandler {
private static StandardServiceRegistry registry;
private static SessionFactory factory;
static public PersistenceHandler build() {
PersistenceHandler instance = new PersistenceHandler();
if(factory == null) {
instance.load();
}
return instance;
}
private SessionFactory load() {
if (factory == null) {
try {
Properties config = PersistenceConfigLoader.build()
.getConfig();
Configuration configuration = new Configuration();
// configuration.configure(new File("persistence.xml"));
Properties properties = configuration.getProperties();
StandardServiceRegistryBuilder registryBuilder =
new StandardServiceRegistryBuilder();
properties.put("hibernate.dialect", config.get("hibernate.dialect"));
properties.put("javax.persistence.jdbc.driver", config.get("javax.persistence.jdbc.driver"));
properties.put("hibernate.show_sql", config.get("hibernate.show_sql"));
properties.put("hibernate.hbm2ddl.auto", config.get("hibernate.hbm2ddl.auto"));
properties.put("hibernate.connection.url", config.get("javax.persistence.jdbc.url"));
properties.put("hibernate.connection.username", config.get("javax.persistence.jdbc.user"));
properties.put("hibernate.connection.password", config.get("javax.persistence.jdbc.password"));
registryBuilder.applySettings(properties);
registry = registryBuilder.build();
MetadataSources sources = new MetadataSources(registry);
getEntities("cz.muni.irtis.repository.database")
.stream()
.forEach(sources::addAnnotatedClass);
factory = sources.buildMetadata().buildSessionFactory();
} catch (Exception e) {
System.out.println("SessionFactory creation failed");
if (registry != null) {
StandardServiceRegistryBuilder.destroy(registry);
}
}
}
return factory;
}
public Session getSession() throws HibernateException {
Session session = null;
try {
session = factory.openSession();
} catch(Throwable t){
System.err.println("Exception while getting session.. ");
t.printStackTrace();
}
if(session == null) {
System.err.println("session is discovered null");
}
return session;
}
public void shutdown() {
if (registry != null) {
StandardServiceRegistryBuilder.destroy(registry);
}
}
private Collection<Class> getEntities(final String pack) {
final StandardJavaFileManager fileManager = ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null);
try {
return StreamSupport.stream(fileManager.list(StandardLocation.CLASS_PATH, pack, Collections.singleton(JavaFileObject.Kind.CLASS), true).spliterator(), false)
.map(FileObject::getName)
.map(name -> {
try {
final String[] parts = name
.replace(".class", "")
.replace(")", "")
.split(Pattern.quote(File.separator));
String className = parts[parts.length - 1];
String subpack = name
.substring(name.replace(File.separator, ".").indexOf(pack) + pack.length(), name.indexOf(className))
.replaceAll("^"+Pattern.quote(File.separator), "")
.replaceAll(Pattern.quote(File.separator)+"$", "")
.replace(File.separator, ".");
String fullClassName = pack + "." + (!subpack.isEmpty() ? subpack + "." : "") + className;
return Class.forName(fullClassName);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
})
.filter(aClass -> aClass.isAnnotationPresent(Entity.class))
.collect(Collectors.toCollection(ArrayList::new));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
package cz.muni.irtis.repository.database.access;
import cz.muni.irtis.repository.database.EntityBase;
import cz.muni.irtis.repository.database.identity.PersonEntity;
import cz.muni.irtis.repository.database.identity.PersonGroupEntity;
import cz.muni.irtis.repository.model.access.Access;
import cz.muni.irtis.repository.model.persons.Person;
import javax.persistence.*;
@Entity
@Table(name = "access")
public class AccessEntity extends EntityBase {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(fetch = FetchType.LAZY, optional = true)
@JoinColumn(name = "person_id", nullable = true)
private PersonEntity person;
@ManyToOne(fetch = FetchType.LAZY, optional = true)
@JoinColumn(name = "api_id", nullable = true)
private ApiEntity api;
private String ip;
private String link;
private String application;
private String language;
private Long time;
public AccessEntity() {
}
static public AccessEntity build(Access item) {
AccessEntity entity = new AccessEntity();
entity.setId(item.getId());
if(item.getPerson()!=null) {
entity.setPerson(PersonEntity.build(item.getPerson()));
}
if(item.getApi()!=null) {
entity.setApi(ApiEntity.build(item.getApi()));
}
entity.setIp(item.getIp());
entity.setLink(item.getLink());
entity.setApplication(item.getApplication());
entity.setLanguage(item.getLanguage());
entity.setTime(item.getTime());
return entity;
}
@Override
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public PersonEntity getPerson() {
return person;
}
public void setPerson(PersonEntity person) {
this.person = person;
}
public ApiEntity getApi() {
return api;
}
public void setApi(ApiEntity api) {
this.api = api;
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
public String getApplication() {
return application;
}
public void setApplication(String application) {
this.application = application;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public Long getTime() {
return time;
}
public void setTime(Long time) {
this.time = time;
}
}
package cz.muni.irtis.repository.database.access;
import cz.muni.irtis.repository.database.EntityBase;
import cz.muni.irtis.repository.model.access.Api;
import javax.persistence.*;
@Entity
@Table(
name = "apis",
indexes = {
@Index(name = "index_identification", columnList="identifier, key", unique = true)
}
)
public class ApiEntity extends EntityBase {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private String identifier;
private String key;
private Boolean active;
public ApiEntity() {
}
static public ApiEntity build(Api item) {
ApiEntity entity = new ApiEntity();
entity.setId(item.getId());
entity.setName(item.getName());
entity.setIdentifier(item.getIdentifier());
entity.setKey(item.getKey());
entity.setActive(item.getActive());
return entity;
}
@Override
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getIdentifier() {
return identifier;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public Boolean getActive() {
return active;
}
public void setActive(Boolean active) {
this.active = active;
}
}
package cz.muni.irtis.repository.database.identity;
import cz.muni.irtis.repository.database.EntityBase;
import cz.muni.irtis.repository.database.messages.MessageEntity;
import cz.muni.irtis.repository.model.messages.Message;
import cz.muni.irtis.repository.model.persons.Burst;
import javax.persistence.*;
@Entity
@Table(name = "people_bursts")
public class BurstEntity extends EntityBase {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "person_id", nullable = false)
private PersonEntity person;
private String identifier; // Name, identifier of a burst
private Long starting;
private Long ending;
public BurstEntity() {
}
static public BurstEntity build(Burst item) {
BurstEntity entity = new BurstEntity();
entity.setId(item.getId());
entity.setPerson(PersonEntity.build(item.getPerson()));
entity.setIdentifier(item.getIdentifier());
entity.setStarting(item.getStarting());
entity.setEnding(item.getEnding());
return entity;
}
@Override
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public PersonEntity getPerson() {
return person;
}
public void setPerson(PersonEntity person) {
this.person = person;
}
public String getIdentifier() {
return identifier;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
public Long getStarting() {
return starting;
}
public void setStarting(Long starting) {
this.starting = starting;
}
public Long getEnding() {
return ending;
}
public void setEnding(Long ending) {
this.ending = ending;
}
}
\ No newline at end of file
package cz.muni.irtis.repository.database.identity;
import cz.muni.irtis.repository.database.EntityBase;
import cz.muni.irtis.repository.model.persons.Person;
import javax.persistence.*;
@Entity
@Table(
name = "people",
indexes = {
@Index(name = "index_token", columnList="token", unique = true),
@Index(name = "index_login", columnList="id, password", unique = true)
}
)
public class PersonEntity extends EntityBase {
@Id
@GeneratedValue(generator = "person_generator")
@SequenceGenerator(
name = "person_generator",
sequenceName = "person_sequence",
initialValue = 1000
)
private Long id;
@ManyToOne(fetch = FetchType.LAZY, optional = true)
@JoinColumn(name = "group_id", nullable = true)
private PersonGroupEntity group;
private String password;
private String name;
private String email;
private String phone;
private String token;
private String device;
private String api;
public PersonEntity() {
}
static public PersonEntity build(Person item) {
PersonEntity entity = new PersonEntity();
entity.setId(item.getId());
if(item.getGroup()!=null) {
entity.setGroup(PersonGroupEntity.build(item.getGroup()));
}
entity.setPassword(item.getPassword());
entity.setName(item.getName());
entity.setEmail(item.getEmail());
entity.setPhone(item.getPhone());
entity.setToken(item.getToken());
entity.setDevice(item.getDevice());
entity.setApi(item.getApi());
return entity;
}
@Override
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public PersonGroupEntity getGroup() {
return group;
}
public void setGroup(PersonGroupEntity group) {
this.group = group;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public String getDevice() {
return device;
}
public void setDevice(String device) {
this.device = device;
}
public String getApi() {
return api;
}
public void setApi(String api) {
this.api = api;
}
}
package cz.muni.irtis.repository.database.identity;
import cz.muni.irtis.repository.database.EntityBase;
import cz.muni.irtis.repository.model.persons.Group;
import cz.muni.irtis.repository.model.persons.Person;
import javax.persistence.*;
@Entity
@Table(
name = "people_groups"
)
public class PersonGroupEntity extends EntityBase {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String title;
public PersonGroupEntity() {
}
static public PersonGroupEntity build(Group item) {
PersonGroupEntity entity = new PersonGroupEntity();
entity.setId(item.getId());
entity.setTitle(item.getTitle());
return entity;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
package cz.muni.irtis.repository.database.messages;
import cz.muni.irtis.repository.database.EntityBase;
import cz.muni.irtis.repository.database.identity.PersonEntity;
import cz.muni.irtis.repository.model.messages.Message;
import javax.persistence.*;
@Entity
@Table(name = "messages")
public class MessageEntity extends EntityBase {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(fetch = FetchType.LAZY, optional = true)
@JoinColumn(name = "person_id", nullable = true)
private PersonEntity person;
@ManyToOne(fetch = FetchType.LAZY, optional = true)
@JoinColumn(name = "creator_id", nullable = true)
private PersonEntity creator;
private Integer type;
@Column(name="text", length=1024)
private String text;
@Column(name="response", length=1024)
private String response;
private Long created;
private Long updated;
@Column(name="valid_from")
private Long validFrom;
@Column(name="valid_to")
private Long validTo;
private Long downloaded;
private Long notified;
private Long opened;
private Long read;
private Long uploaded;
public MessageEntity() {
}
static public MessageEntity build(Message item) {
MessageEntity entity = new MessageEntity();
entity.setId(item.getId());
if(item.getPerson()!=null) {
entity.setPerson(PersonEntity.build(item.getPerson()));
}
if(item.getCreator()!=null) {
entity.setCreator(PersonEntity.build(item.getCreator()));
}
entity.setType(item.getType());
entity.setText(item.getText());
entity.setResponse(item.getResponse());
entity.setCreated(item.getCreated());
entity.setUpdated(item.getUpdated());
entity.setValidFrom(item.getValidFrom());
entity.setValidTo(item.getValidTo());
entity.setDownloaded(item.getDownloaded());
entity.setNotified(item.getNotified());
entity.setOpened(item.getOpened());
entity.setRead(item.getRead());
entity.setUploaded(item.getUploaded());
return entity;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public PersonEntity getPerson() {
return person;
}
public void setPerson(PersonEntity person) {
this.person = person;
}
public PersonEntity getCreator() {
return creator;
}
public void setCreator(PersonEntity creator) {
this.creator = creator;
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public String getResponse() {
return response;
}
public void setResponse(String response) {
this.response = response;
}
public Long getCreated() {
return created;
}
public void setCreated(Long created) {
this.created = created;
}
public Long getUpdated() {
return updated;
}
public void setUpdated(Long updated) {
this.updated = updated;
}
public Long getValidFrom() {
return validFrom;
}
public void setValidFrom(Long validFrom) {
this.validFrom = validFrom;
}
public Long getValidTo() {
return validTo;
}
public void setValidTo(Long validTo) {
this.validTo = validTo;
}
public Long getDownloaded() {
return downloaded;
}
public void setDownloaded(Long downloaded) {
this.downloaded = downloaded;
}
public Long getNotified() {
return notified;
}
public void setNotified(Long notified) {
this.notified = notified;
}
public Long getOpened() {
return opened;
}
public void setOpened(Long opened) {
this.opened = opened;
}
public Long getRead() {
return read;
}
public void setRead(Long read) {
this.read = read;
}
public Long getUploaded() {
return uploaded;
}
public void setUploaded(Long uploaded) {
this.uploaded = uploaded;
}
}
package cz.muni.irtis.repository.database.metrics;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Table;
@Entity
@Table(name = "metrics_activities")
public class ActivityEntity {
@EmbeddedId
private MetricIdentityEntity metricIdentity;
private String activity;
private int confidence;
public ActivityEntity() {
}
public ActivityEntity(MetricIdentityEntity metricIdentity, String activity, int confidence) {
this.metricIdentity = metricIdentity;
this.activity = activity;
this.confidence = confidence;
}
public MetricIdentityEntity getMetricIdentity() {
return metricIdentity;
}
public void setMetricIdentity(MetricIdentityEntity metricIdentity) {
this.metricIdentity = metricIdentity;
}
public String getActivity() {
return activity;
}
public void setActivity(String activity) {
this.activity = activity;
}
public int getConfidence() {
return confidence;
}
public void setConfidence(int confidence) {
this.confidence = confidence;
}
}
package cz.muni.irtis.repository.database.metrics;
import javax.persistence.*;
@Entity
@Table(name = "metrics_battery")
public class BatteryEntity {
@EmbeddedId
private MetricIdentityEntity metricIdentity;
@Column(name = "state_percent")
private int statePercent;
public BatteryEntity() {
}
public BatteryEntity(MetricIdentityEntity metricIdentity, int statePercent) {
this.metricIdentity = metricIdentity;
this.statePercent = statePercent;
}
public int getStatePercent() {
return statePercent;
}
public void setStatePercent(int statePercent) {
this.statePercent = statePercent;
}
public MetricIdentityEntity getMetricIdentity() {
return metricIdentity;
}
public void setMetricIdentity(MetricIdentityEntity metricIdentity) {
this.metricIdentity = metricIdentity;
}
}
package cz.muni.irtis.repository.database.metrics;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Table;
@Entity
@Table(name = "metrics_headphones")
public class HeadphonesEntity {
@EmbeddedId
private MetricIdentityEntity metricIdentity;
private Boolean connected;
public HeadphonesEntity() {
}
public HeadphonesEntity(MetricIdentityEntity metricIdentity, Boolean connected) {
this.metricIdentity = metricIdentity;
this.connected = connected;
}
public void setMetricIdentity(MetricIdentityEntity metricIdentity) {
this.metricIdentity = metricIdentity;
}
public MetricIdentityEntity getMetricIdentity() {
return metricIdentity;
}
public Boolean getConnected() {
return connected;
}
public void setConnected(Boolean connected) {
this.connected = connected;
}
}
package cz.muni.irtis.repository.database.metrics;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Table;
@Entity
@Table(name = "metrics_locations")
public class LocationEntity {
@EmbeddedId
private MetricIdentityEntity metricIdentity;
private Double latitude;
private Double longitude;
public LocationEntity() {
}
public LocationEntity(MetricIdentityEntity metricIdentity, Double latitude, Double longitude) {
this.metricIdentity = metricIdentity;
this.latitude = latitude;
this.longitude = longitude;
}
public void setMetricIdentity(MetricIdentityEntity metricIdentity) {
this.metricIdentity = metricIdentity;
}
public void setLatitude(Double latitude) {
this.latitude = latitude;
}
public void setLongitude(Double longitude) {
this.longitude = longitude;
}
public MetricIdentityEntity getMetricIdentity() {
return metricIdentity;
}
public Double getLatitude() {
return latitude;
}
public Double getLongitude() {
return longitude;
}
}
package cz.muni.irtis.repository.database.metrics;
import javax.persistence.Embeddable;
import java.io.Serializable;
@Embeddable
public class MetricIdentityEntity implements Serializable {
// @NonNull
private Long personId;
// @NonNull
private Long datetimeId;
public MetricIdentityEntity() {
}
public MetricIdentityEntity(Long personId, Long datetimeId) {
this.personId = personId;
this.datetimeId = datetimeId;
}
public Long getPersonId() {
return personId;
}
public void setPersonId(Long personId) {
this.personId = personId;
}
public Long getDatetimeId() {
return datetimeId;
}
public void setDatetimeId(Long datetimeId) {
this.datetimeId = datetimeId;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MetricIdentityEntity that = (MetricIdentityEntity) o;
if (!personId.equals(that.personId)) return false;
return datetimeId.equals(that.datetimeId);
}
@Override
public int hashCode() {
int result = personId.hashCode();
result = 31 * result + datetimeId.hashCode();
return result;
}
}
package cz.muni.irtis.repository.database.metrics;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Table;
@Entity
@Table(name = "metrics_notifications")
public class NotificationEntity {
@EmbeddedId
private MetricIdentityEntity metricIdentity;
@Column(name = "package")
private String packagage;
@Column(name = "posted")
private Long posted;
@Column(name = "removed")
private Long removed;
@Column(name = "title")
private String title;
@Column(name = "text")
private String text;
public NotificationEntity() {
}
public MetricIdentityEntity getMetricIdentity() {
return metricIdentity;
}
public void setMetricIdentity(MetricIdentityEntity metricIdentity) {
this.metricIdentity = metricIdentity;
}
public String getPackagage() {
return packagage;
}
public void setPackagage(String packagage) {
this.packagage = packagage;
}
public Long getPosted() {
return posted;
}
public void setPosted(Long posted) {
this.posted = posted;
}
public Long getRemoved() {
return removed;
}
public void setRemoved(Long removed) {
this.removed = removed;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment