BrightSide Workbench Full Report + Source Code
OldLogEntry.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2021 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.log;
20 
21 import java.util.Date;
22 import org.turro.string.Strings;
23 import org.turro.elephant.entities.db.SystemLog;
24 import org.turro.entities.EmptyController;
25 import org.turro.entities.Entities;
26 import org.turro.entities.IElephantEntity;
27 import org.turro.jpa.Dao;
28 
33 public class OldLogEntry {
34 
35  private final String path, idUser, name, comment;
36  private final int type;
37  private final Date dateLog;
38  private final byte[] data;
39 
40  public OldLogEntry(int type, String path, String idUser, String name, Date dateLog, String comment, byte[] data) {
41  this.type = type;
42  this.path = path;
43  this.idUser = idUser;
44  this.name = name;
45  this.dateLog = dateLog;
46  this.comment = comment;
47  this.data = data;
48  }
49 
50  public int getType() {
51  return type;
52  }
53 
54  public String getPath() {
55  return path;
56  }
57 
58  public String getIdUser() {
59  return idUser;
60  }
61 
62  public String getName() {
63  return name;
64  }
65 
66  public Date getDateLog() {
67  return dateLog;
68  }
69 
70  public String getComment() {
71  return comment;
72  }
73 
74  public byte[] getData() {
75  return data;
76  }
77 
78  public void migrate(Dao dao) {
79  SystemLog entry = new SystemLog();
80  entry.setDateLog(dateLog);
81  if(Strings.isBlank(idUser) || idUser.length() < 20) {
82  entry.setGeneratorPath(Strings.isBlank(idUser, "#"));
83  entry.setGeneratorName("Unknown");
84  } else {
85  entry.setGeneratorPath("/contact/" + idUser);
86  entry.setGeneratorName(name);
87  }
88  IElephantEntity entity = Entities.getController(path);
89  if((entity == null) || (entity instanceof EmptyController)) {
90  entry.setEntityPath(path);
91  entry.setEntityName("Unknown");
92  } else {
93  entry.setEntityPath(entity.getPath());
94  entry.setEntityName(entity.getName());
95  }
96  entry.setComment(comment);
97  entry.setData(data);
98  switch(type) {
99  case 1:
101  break;
102  case 2:
104  break;
105  default:
107  break;
108  }
109  dao.saveObject(entry);
110  }
111 
112 }
void setEntityName(String entityName)
Definition: SystemLog.java:108
void setLogType(SystemLogType logType)
Definition: SystemLog.java:76
void setGeneratorPath(String generatorPath)
Definition: SystemLog.java:84
void setGeneratorName(String generatorName)
Definition: SystemLog.java:100
void setEntityPath(String entityPath)
Definition: SystemLog.java:92
static IElephantEntity getController(String path)
Definition: Entities.java:78
OldLogEntry(int type, String path, String idUser, String name, Date dateLog, String comment, byte[] data)