BrightSide Workbench Full Report + Source Code
SpaceUsageSelfSummary.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2018 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.elephant.configuration;
20 
21 import java.io.BufferedReader;
22 import java.io.File;
23 import java.io.FileReader;
24 import java.io.IOException;
25 import java.util.logging.Level;
26 import java.util.logging.Logger;
27 import org.turro.action.Plugins;
28 import org.turro.annotation.ElephantPlugin;
29 import org.turro.elephant.context.Application;
30 import org.turro.elephant.context.ElephantContext;
31 import org.turro.elephant.impl.util.Files;
32 import org.turro.elephant.util.Images;
33 import org.turro.plugin.command.SelfSummaryPlugin;
34 import org.turro.zkoss.label.LabelTypes;
35 import org.turro.zkoss.layout.GroupboxArrow;
36 import org.zkoss.zk.ui.util.Clients;
37 import org.zkoss.zul.Hlayout;
38 import org.zkoss.zul.Image;
39 import org.zkoss.zul.Label;
40 
45 @ElephantPlugin
47 
48  @Override
49  protected void executePlugin() {
51  if(app.isInRole("contact:all")) {
52  Clients.showBusy("Calculating usage...");
53  Plugins.execute("SpaceUsage", null);
54  Clients.clearBusy();
55  final File file = Files.file("/WEB-INF/space-usage.txt");
56  if(file.exists()) {
57  GroupboxArrow gba = new GroupboxArrow() {
58  @Override
59  protected void doFillContent() {
60  Label label = new Label(getFileContent(file));
61  label.setPre(true);
62  appendChild(label);
63  }
64  };
65  Hlayout hbox = new Hlayout();
66  gba.setCaption(hbox);
67  hbox.setSclass("z-valign-middle");
68  hbox.setValign("middle");
69  hbox.appendChild(new Image(Images.getImage("info")));
70  hbox.appendChild(LabelTypes.getSoftLabel("BaaS"));
71  gba.setOpen(false);
72  addResult("BaaS", gba);
73  }
74  }
75  }
76 
77  private String getFileContent(File file) {
78  String content = "";
79  try (BufferedReader br = new BufferedReader(new FileReader(file))) {
80  String line;
81  while ((line = br.readLine()) != null) {
82  content += line + "\n";
83  }
84  } catch (IOException ex) {
85  Logger.getLogger(SpaceUsageSelfSummary.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
86  }
87  return content;
88  }
89 
90 }
Object addResult(String key, Object value)
static Map< String, Object > execute(String name, Map params)
Definition: Plugins.java:44
static File file(IConstructor constructor, String file)
Definition: Files.java:71
static String getImage(String image)
Definition: Images.java:36
static Label getSoftLabel(String value)
Definition: LabelTypes.java:28