BrightSide Workbench Full Report + Source Code
CommonsInitializer.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.entities;
20 
21 import org.turro.string.Strings;
22 import org.turro.action.IElephantInitializer;
23 import org.turro.annotation.ElephantInitializer;
24 import org.turro.cleanup.Cleanup;
25 import org.turro.elephant.context.ElephantContext;
26 import org.turro.elephant.context.IConstructor;
27 import org.turro.elephant.db.ElephantPU;
28 import org.turro.elephant.entities.db.SystemLog;
29 import org.turro.jpa.Dao;
30 import org.turro.log.SystemLogAccumulator;
31 import org.turro.log.SystemLogMigration;
32 import org.turro.log.WebLoggers;
33 import org.turro.path.Path;
34 import org.turro.related.RelatedMigration;
35 import org.turro.sql.SqlClause;
36 import org.turro.tags.TagMigration;
37 
42 @ElephantInitializer
43 public class CommonsInitializer implements IElephantInitializer {
44 
45  @Override
46  public void initialize(IConstructor constructor) {
47  WebLoggers.info(this).message("SystemLogMigration started").log();
49  WebLoggers.info(this).message("TagMigration started").log();
51  WebLoggers.info(this).message("TagMigration.clean started").log();
53  WebLoggers.info(this).message("RelatedMigration started").log();
55  WebLoggers.info(this).message("repairDownloadedFiles started").log();
56  repairDownloadedFiles();
57  WebLoggers.info(this).message("SystemLogAccumulator started").log();
59  WebLoggers.info(this).message("Cleanup.orphans started").log();
60  Cleanup.orphans();
61  }
62 
63  private void repairDownloadedFiles() {
64  Dao dao = new ElephantPU();
65  SqlClause.select("l").from("SystemLog l")
66  .where().like("l.comment", "% downloaded")
67  .dao(dao)
68  .resultList(SystemLog.class).forEach(sl -> {
69  dao.deleteObject(sl);
70  String fullPath = sl.getComment().substring(0, sl.getComment().length() - " downloaded".length());
71  sl.setEntityPath("/file" + Strings.isBlank(ElephantContext.getRelativePath(fullPath), fullPath));
72  sl.setEntityName(Path.pathFrom(fullPath).getLastNode());
73  sl.setComment("downloaded");
74  dao.saveObject(sl);
75  });
76  }
77 
78 }
static void orphans()
Definition: Cleanup.java:61
void initialize(IConstructor constructor)
void deleteObject(Object obj)
Definition: Dao.java:162
WebLoggers message(String text, Object... parameters)
Definition: WebLoggers.java:34
static WebLoggers info(Object entity)
Definition: WebLoggers.java:43