BrightSide Workbench Full Report + Source Code
CommonsCleanup.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 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.cleanup;
20 
21 import java.util.Collections;
22 import java.util.Set;
23 import org.turro.assistant.ParticipationInfo;
24 import org.turro.log.SystemLogModel;
25 import org.turro.log.SystemLogger;
26 import org.turro.related.Relateds;
27 import org.turro.skills.Skills;
28 import org.turro.tags.Tags;
29 
34 @ElephantCleanup
35 public class CommonsCleanup extends AbstractCleanup {
36 
37  @Override
38  public boolean isMine(Object entity) {
39  return false;
40  }
41 
42  @Override
43  public void cleanEntity(Object entity, CleanupMode mode) {
44 
45  }
46 
47  @Override
48  public void cleanFromCommons(String entityPath, CleanupMode mode, Set<Commons> commons) {
49  if(commons.contains(Commons.TAGS)) {
50  CleanupAction.from("Removing tags...",
51  () -> Tags.removeTags(entityPath))
52  .execute(getConsole(), mode);
53  }
54  if(commons.contains(Commons.SKILLS)) {
55  CleanupAction.from("Removing skills...",
56  () -> Skills.removeSkills(entityPath))
57  .execute(getConsole(), mode);
58  }
59  if(commons.contains(Commons.PARTICIPATIONS)) {
60  CleanupAction.from("Removing participations...",
61  () -> ParticipationInfo.cleanup(entityPath))
62  .execute(getConsole(), mode);
63  }
64  if(commons.contains(Commons.RELATED)) {
65  CleanupAction.from("Removing related...",
66  () -> Relateds.empty().removeAny(entityPath))
67  .execute(getConsole(), mode);
68  }
69  if(commons.contains(Commons.LOGS)) {
70  CleanupAction.from("Removing log information...",
71  () -> SystemLogger.cleanup(entityPath))
72  .execute(getConsole(), mode);
73  }
74  }
75 
76  @Override
77  public Set<String> pathsForRoot(String root, Commons common) {
78  return switch (common) {
79  case TAGS -> Tags.getAllPaths(root);
80  case SKILLS -> Skills.getAllPaths(root);
81  case PARTICIPATIONS -> ParticipationInfo.getAllPaths(root);
82  case RELATED -> Relateds.getAllPaths(root);
83  case LOGS -> SystemLogModel.getAllPaths(root);
84  default -> Collections.EMPTY_SET;
85  };
86  }
87 
88 }
static void cleanup(String entityPath)
static Set< String > getAllPaths(String root)
static CleanupAction from(String message, Runnable action)
void execute(ICleanupConsole console, CleanupMode mode)
void cleanFromCommons(String entityPath, CleanupMode mode, Set< Commons > commons)
Set< String > pathsForRoot(String root, Commons common)
void cleanEntity(Object entity, CleanupMode mode)
boolean isMine(Object entity)
static Set< String > getAllPaths(String root)
static void cleanup(String entityPath)
static Set< String > getAllPaths(String root)
Definition: Relateds.java:125
Relateds removeAny(String removePath)
Definition: Relateds.java:100
static Relateds empty()
Definition: Relateds.java:149
static Set< String > getAllPaths(String root)
Definition: Skills.java:125
static void removeSkills(String entityPath)
Definition: Skills.java:114
static void removeTags(Object entity)
Definition: Tags.java:366
static Set< String > getAllPaths(String root)
Definition: Tags.java:434