Commit 424ae8a5 authored by Pedro Rocha's avatar Pedro Rocha
Browse files

Incluiío método de remoção de arquivos e ajustando log.

- Incluído o método de remoção de arquivos ao FileExplorer.
- Ajustando o JobServices para usar o Logger para gerar as mensagens de
log no método de pulling de jobs.

[CSBASE-4919]
[INFOGRD-3127]
parent 6d0fa78b
......@@ -14,6 +14,7 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
public class JobServices {
......@@ -82,14 +83,14 @@ public class JobServices {
JobPullInfo info = getJobPullInfo(host, token, jobId, currDate);
if (info!=null && info.getJob(jobId)!=null)
{
JobInfo.StatusType state = info.getJob(jobId).getState();
System.out.println ("Job state (" + currDate + "): " + state);
if (state.equals(JobInfo.StatusType.FINISHED)) {
System.out.println("Job " + jobId + " terminou");
break;
} else {
currDate = info.getDate();
}
JobInfo.StatusType state = info.getJob(jobId).getState();
Logger.getGlobal().fine("Job state (" + currDate + "): " + state);
if (state.equals(JobInfo.StatusType.FINISHED)) {
Logger.getGlobal().fine("Job " + jobId + " terminou");
break;
} else {
currDate = info.getDate();
}
}
}
}
......
......@@ -178,4 +178,28 @@ public class FileExplorer {
else if (status == Response.Status.NOT_FOUND.getStatusCode())
throw new ProjectOrFileNotFoundException();
}
public static void removeFile(String host, Token token, Project project, String projectFolderPath, String fileName)
throws ProjectOrFileNotFoundException, PermissionException, InvalidLoginOrPasswordException {
Client client = ClientBuilder.newClient();
WebTarget webTarget = client.target(host);
String fileId = Base64.getEncoder().encodeToString(projectFolderPath.equals("root") ? fileName.getBytes()
: (projectFolderPath + (fileName == null ? "" : "/" + fileName)).getBytes());
WebTarget uploadTarget = webTarget.path("projects").path(project.getId()).path("files").path(fileId);
Invocation.Builder invocationBuilder = uploadTarget.request();
Response response = invocationBuilder
.header(HttpHeaders.AUTHORIZATION, token.getTokenType() + token.getAccessToken()).delete();
int status = response.getStatus();
if (status == Response.Status.BAD_REQUEST.getStatusCode())
throw new InvalidLoginOrPasswordException();
else if (status == Response.Status.FORBIDDEN.getStatusCode())
throw new PermissionException();
else if (status == Response.Status.NOT_FOUND.getStatusCode())
throw new ProjectOrFileNotFoundException();
client.close();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment