BrightSide Workbench Full Report + Source Code
AttachmentCleanup.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.attach.search.Attachments;
24 import org.turro.file.util.AttachFiles;
25 
30 @ElephantCleanup
31 public class AttachmentCleanup extends AbstractCleanup {
32 
33  @Override
34  public boolean isMine(Object entity) {
35  return false;
36  }
37 
38  @Override
39  public void cleanEntity(Object entity, CleanupMode mode) {
40 
41  }
42 
43  @Override
44  public void cleanFromCommons(String entityPath, CleanupMode mode, Set<Commons> commons) {
45  if(commons.contains(Commons.ATTACHMENTS)) {
46  CleanupAction.from("Deleting attachments...",
47  () -> Attachments.from(entityPath).remove())
48  .execute(getConsole(), mode);
49  }
50  if(commons.contains(Commons.PUBLISHABLEFILES)) {
51  CleanupAction.from("Deleting publishable files...",
52  () -> AttachFiles.from(entityPath).removePublishable())
53  .execute(getConsole(), mode);
54  }
55  if(commons.contains(Commons.PRIVATEFILES)) {
56  CleanupAction.from("Deleting private files...",
57  () -> AttachFiles.from(entityPath).removePrivate())
58  .execute(getConsole(), mode);
59  }
60  }
61 
62  @Override
63  public Set<String> pathsForRoot(String root, Commons common) {
64  return switch (common) {
65  case ATTACHMENTS -> Attachments.getAllPaths(root);
66  case PUBLISHABLEFILES -> AttachFiles.getAllPublishablePaths(root);
67  case PRIVATEFILES -> AttachFiles.getAllPrivatePaths(root);
68  default -> Collections.EMPTY_SET;
69  };
70  }
71 
72 }
static Attachments from(String path)
static Set< String > getAllPaths(String root)
void cleanEntity(Object entity, CleanupMode mode)
Set< String > pathsForRoot(String root, Commons common)
void cleanFromCommons(String entityPath, CleanupMode mode, Set< Commons > commons)
static CleanupAction from(String message, Runnable action)
void execute(ICleanupConsole console, CleanupMode mode)
static Set< String > getAllPublishablePaths(String root)
static AttachFiles from(String path)
static Set< String > getAllPrivatePaths(String root)