labelingsystem-server  Version 0.1.0.0
DumpResource Class Reference
Collaboration diagram for DumpResource:

Public Member Functions

Response getList ()
 
Response getDump (@PathParam("repo") String repo)
 
Response getStatus (@QueryParam("mode") String mode)
 
Response startDumping ()
 
Response stopDumping ()
 
void start () throws InterruptedException, IOException
 
void status () throws InterruptedException, IOException
 
void stop ()
 
void listFilesForFolder ()
 

Static Public Member Functions

static void listDumpFilesDeleteForMax () throws IOException
 
static int getNumberOfStatements () throws MalformedURLException, IOException
 

Static Public Attributes

static String mode = "start"
 
static String out
 
static long startTime = System.currentTimeMillis()
 
static boolean dumping = false
 
static String fileDir = ""
 
static String filePath = ""
 
static String tmpDirString = "tmpDir_1"
 
static String tmpDirString2 = "tmpDir_2"
 
static String tmpDirPath = ""
 
static String tmpDirPath2 = ""
 
static String downloadLink = ""
 
static String size_url = ""
 
static long sleepTimeInMills = 43200000
 
static String lastDump = ""
 
static String lastDumpTime = ""
 
static String numberOfTriples = ""
 
static int dumbNo = -1
 

Static Private Attributes

static final List< String > fileList = new ArrayList<String>()
 
static int maxDumps = 100
 

Member Function Documentation

◆ getDump()

Response getDump ( @PathParam("repo") String  repo)
89  {
90  try {
91  String dumpFile = Dump.writeFile(repo);
92  JSONObject out = new JSONObject();
93  out.put("file", dumpFile);
94  return Response.ok(out).header("Content-Type", "application/json;charset=UTF-8").build();
95  } catch (Exception e) {
96  return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(Logging.getMessageJSON(e, "v1.rest.DumpResource"))
97  .header("Content-Type", "application/json;charset=UTF-8").build();
98  }
99  }

References Logging.getMessageJSON(), and Dump.writeFile().

◆ getList()

Response getList ( )
56  {
57  try {
58  fileDir = ConfigProperties.getPropertyParam("dump_server");
59  String html_header = "<html>";
60  html_header += "<head>";
61  html_header += "</head>";
62  html_header += "<body>";
63  String html_footer = "</body>";
64  html_footer += "</html>";
66  out = "<h1>Index of Labeling System Dumps</h1>";
67  if (fileList.size() > 0) {
68  out += "<table style=\"width:75%\" border='1'>";
69  out += "<tr><th>Name</th><th>Last modified</th><th>Size</th></tr>";
70  for (String file : fileList) {
71  out += "<tr>"
72  + "<td width='25%'><a href='" + ConfigProperties.getPropertyParam("dump_web") + file.split("#")[0] + "'>" + file.split("#")[0] + "</a></td>"
73  + "<td width='25%'>" + file.split("#")[2] + "</td>"
74  + "<td width='25%'>" + file.split("#")[1] + " KB</td>"
75  + "</tr>";
76  }
77  out += "</table>";
78  }
79  return Response.ok(html_header + out + html_footer).header("Content-Type", "text/html;charset=UTF-8").build();
80  } catch (Exception e) {
81  return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(Logging.getMessageJSON(e, "v1.rest.DumpResource"))
82  .header("Content-Type", "application/json;charset=UTF-8").build();
83  }
84  }

References Logging.getMessageJSON(), and ConfigProperties.getPropertyParam().

◆ getNumberOfStatements()

static int getNumberOfStatements ( ) throws MalformedURLException, IOException
static
225  {
226  try {
227  URL obj = new URL(size_url);
228  HttpURLConnection con = (HttpURLConnection) obj.openConnection();
229  con.setRequestMethod("GET");
230  BufferedReader in = new BufferedReader(
231  new InputStreamReader(con.getInputStream()));
232  String inputLine;
233  StringBuilder response = new StringBuilder();
234  while ((inputLine = in.readLine()) != null) {
235  response.append(inputLine);
236  }
237  in.close();
238  int size = Integer.parseInt(response.toString());
239  return size;
240  } catch (Exception e) {
241  throw new NullPointerException();
242  }
243  }

Referenced by LSDump.writeFile().

◆ getStatus()

Response getStatus ( @QueryParam("mode") String  mode)
103  {
104  try {
105  status();
106  JSONObject outObject = new JSONObject();
107  outObject.put("message", out);
108  return Response.ok(outObject).header("Content-Type", "application/json;charset=UTF-8").build();
109  } catch (Exception e) {
110  return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(Logging.getMessageJSON(e, "v1.rest.DumpResource"))
111  .header("Content-Type", "application/json;charset=UTF-8").build();
112  }
113  }

References Logging.getMessageJSON().

◆ listDumpFilesDeleteForMax()

static void listDumpFilesDeleteForMax ( ) throws IOException
static
202  {
203  fileList.clear();
204  File directory = new File(fileDir);
205  File[] files = directory.listFiles((FileFilter) FileFileFilter.FILE);
206  Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_REVERSE);
207  for (File file : files) {
208  if (!file.getName().contains("labelingsystem-latest")) {
209  fileList.add(file.getName());
210  }
211  }
212  boolean tmp = true;
213  while (tmp) {
214  if (fileList.size() >= maxDumps) {
215  File fileDelete = new File(fileDir + fileList.get(fileList.size() - 1));
216  Files.deleteIfExists(fileDelete.toPath());
217  fileList.remove(fileList.size() - 1);
218  } else {
219  tmp = false;
220  break;
221  }
222  }
223  }

Referenced by LSDump.writeFile().

◆ listFilesForFolder()

void listFilesForFolder ( )
190  {
191  fileList.clear();
192  // http://www.avajava.com/tutorials/lessons/how-do-i-sort-an-array-of-files-according-to-their-last-modified-dates.html
193  File directory = new File(fileDir);
194  File[] files = directory.listFiles((FileFilter) FileFileFilter.FILE);
195  Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_REVERSE);
196  for (File file : files) {
197  double filesize = (file.length() / 1024);
198  fileList.add(file.getName() + "#" + filesize + "#" + new Date(file.lastModified()));
199  }
200  }

◆ start()

void start ( ) throws InterruptedException, IOException
154  {
155  (new Thread(new LSDump())).start();
156  long currentTime = System.currentTimeMillis();
157  SimpleDateFormat sdf = new SimpleDateFormat("MMM dd yyyy HH:mm:ss");
158  Date resultdate = new Date(currentTime);
159  System.out.println("started at: " + sdf.format(resultdate));
160  status();
161  }

◆ startDumping()

Response startDumping ( )
117  {
118  try {
119  fileDir = ConfigProperties.getPropertyParam("dump_server");
120  filePath = ConfigProperties.getPropertyParam("dump_web");
121  downloadLink = ConfigProperties.getPropertyParam("ts_server") + "/repositories/" + ConfigProperties.getPropertyParam("repository") + "/statements?Accept=text/plain";
122  size_url = ConfigProperties.getPropertyParam("ts_server") + "/repositories/" + ConfigProperties.getPropertyParam("repository") + "/size";
123  tmpDirPath = fileDir + "tmpDir_1" + "/";
124  tmpDirPath2 = fileDir + "tmpDir_2" + "/";
125  dumping = true;
126  start();
127  JSONObject outObject = new JSONObject();
128  outObject.put("message", out);
129  return Response.ok(outObject).header("Content-Type", "application/json;charset=UTF-8").build();
130  } catch (Exception e) {
131  stop();
132  dumping = false;
133  return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(Logging.getMessageJSON(e, "v1.rest.DumpResource"))
134  .header("Content-Type", "application/json;charset=UTF-8").build();
135  }
136  }

References Logging.getMessageJSON(), and ConfigProperties.getPropertyParam().

◆ status()

void status ( ) throws InterruptedException, IOException
163  {
164  if (dumping) {
165  SimpleDateFormat sdf = new SimpleDateFormat("MMM dd yyyy HH:mm:ss");
166  Date resultdate = new Date(startTime);
167  if (lastDumpTime.equals("") || lastDump.equals("")) {
168  out = "started at: " + sdf.format(resultdate);
169  } else {
170  out = "started at: " + sdf.format(resultdate) + ", last dump at: " + lastDumpTime + ", last dump: " + lastDump;
171  }
172  } else {
173  out = "dumping not started";
174  }
175  }

◆ stop()

void stop ( )
177  {
178  if (dumping) {
179  long currentTime = System.currentTimeMillis();
180  SimpleDateFormat sdf = new SimpleDateFormat("MMM dd yyyy HH:mm:ss");
181  Date resultdate = new Date(currentTime);
182  System.out.println("stopped at: " + sdf.format(resultdate));
183  dumping = false;
184  out = "stopped at: " + sdf.format(resultdate);
185  } else {
186  out = "dumping not started";
187  }
188  }

◆ stopDumping()

Response stopDumping ( )
140  {
141  try {
142  stop();
143  JSONObject outObject = new JSONObject();
144  outObject.put("message", out);
145  return Response.ok(outObject).header("Content-Type", "application/json;charset=UTF-8").build();
146  } catch (Exception e) {
147  stop();
148  dumping = false;
149  return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(Logging.getMessageJSON(e, "v1.rest.DumpResource"))
150  .header("Content-Type", "application/json;charset=UTF-8").build();
151  }
152  }

References Logging.getMessageJSON().

Member Data Documentation

◆ downloadLink

String downloadLink = ""
static

Referenced by LSDump.writeFile().

◆ dumbNo

int dumbNo = -1
static

Referenced by LSDump.writeFile().

◆ dumping

boolean dumping = false
static

Referenced by LSDump.run(), and LSDump.writeFile().

◆ fileDir

String fileDir = ""
static

Referenced by LSDump.writeFile().

◆ fileList

final List<String> fileList = new ArrayList<String>()
staticprivate

◆ filePath

String filePath = ""
static

Referenced by LSDump.writeFile().

◆ lastDump

String lastDump = ""
static

Referenced by LSDump.writeFile().

◆ lastDumpTime

String lastDumpTime = ""
static

Referenced by LSDump.writeFile().

◆ maxDumps

int maxDumps = 100
staticprivate

◆ mode

String mode = "start"
static

◆ numberOfTriples

String numberOfTriples = ""
static

◆ out

String out
static

◆ size_url

String size_url = ""
static

◆ sleepTimeInMills

long sleepTimeInMills = 43200000
static

Referenced by LSDump.writeFile().

◆ startTime

long startTime = System.currentTimeMillis()
static

◆ tmpDirPath

String tmpDirPath = ""
static

Referenced by LSDump.writeFile().

◆ tmpDirPath2

String tmpDirPath2 = ""
static

Referenced by LSDump.writeFile().

◆ tmpDirString

String tmpDirString = "tmpDir_1"
static

Referenced by LSDump.writeFile().

◆ tmpDirString2

String tmpDirString2 = "tmpDir_2"
static

Referenced by LSDump.writeFile().

v1.rest.DumpResource.maxDumps
static int maxDumps
Definition: DumpResource.java:51
v1.rest.DumpResource.lastDumpTime
static String lastDumpTime
Definition: DumpResource.java:49
v1.rest.DumpResource.fileDir
static String fileDir
Definition: DumpResource.java:39
v1.rest.DumpResource.lastDump
static String lastDump
Definition: DumpResource.java:48
v1.rest.DumpResource.size_url
static String size_url
Definition: DumpResource.java:46
v1.rest.DumpResource.downloadLink
static String downloadLink
Definition: DumpResource.java:45
v1.rest.DumpResource.stop
void stop()
Definition: DumpResource.java:177
v1.rest.DumpResource.listFilesForFolder
void listFilesForFolder()
Definition: DumpResource.java:190
Exception
v1.rest.DumpResource.startTime
static long startTime
Definition: DumpResource.java:37
v1.rest.DumpResource.tmpDirPath
static String tmpDirPath
Definition: DumpResource.java:43
v1.rest.DumpResource.out
static String out
Definition: DumpResource.java:36
v1.rest.DumpResource.dumping
static boolean dumping
Definition: DumpResource.java:38
v1.rest.DumpResource.filePath
static String filePath
Definition: DumpResource.java:40
v1.rest.DumpResource.status
void status()
Definition: DumpResource.java:163
v1.rest.DumpResource.tmpDirPath2
static String tmpDirPath2
Definition: DumpResource.java:44
v1.rest.DumpResource.start
void start()
Definition: DumpResource.java:154
v1.rest.DumpResource.fileList
static final List< String > fileList
Definition: DumpResource.java:50