Commit 83035e50 authored by ics's avatar ics

New code to manage files moved from client to server side (scans, xbu,

pal, settings)
parent 9e77bd4a
...@@ -61,28 +61,6 @@ public class ResourceManager { ...@@ -61,28 +61,6 @@ public class ResourceManager {
public String getFileContent(String controllerType, String fileName) throws ResourceNotFoundException { public String getFileContent(String controllerType, String fileName) throws ResourceNotFoundException {
return ServantManagerAccessor.getInstance(serverId).readResourceFile(controllerType, fileName); return ServantManagerAccessor.getInstance(serverId).readResourceFile(controllerType, fileName);
/*
String fullFilePath = "/home/dpt/ortizh/tmp/" + fileName;
if (new File(fullFilePath).exists()) {
try {
String content = "";
String line;
BufferedReader in = new BufferedReader(new FileReader(fullFilePath));
while ((line = in.readLine()) != null) {
content = content + line + "\n";
}
in.close();
return content;
} catch (IOException e) {
System.err.println("IOException while getting content of file " + fullFilePath);
e.printStackTrace();
}
} else {
throw new ResourceNotFoundException(fileName);
}
return null;
*/
} }
public void setFileContent(String controllerType, String fileName, String content) { public void setFileContent(String controllerType, String fileName, String content) {
...@@ -107,6 +85,22 @@ public class ResourceManager { ...@@ -107,6 +85,22 @@ public class ResourceManager {
*/ */
} }
public void saveFile(String fileName, String content) {
ServantManagerAccessor.getInstance(serverId).saveFile(fileName, content);
}
public String getFileContent(String fileName) throws ResourceNotFoundException {
return ServantManagerAccessor.getInstance(serverId).getFileContent(fileName);
}
public String getTree(String rootDirectory) {
return ServantManagerAccessor.getInstance(serverId).getTree(rootDirectory);
}
public HashMap<String, String> getFamilyImageKeys() { public HashMap<String, String> getFamilyImageKeys() {
return ServantManagerAccessor.getInstance(serverId).getFamilyImageKeys(); return ServantManagerAccessor.getInstance(serverId).getFamilyImageKeys();
} }
......
...@@ -1027,4 +1027,82 @@ public class ServantManagerAccessor { ...@@ -1027,4 +1027,82 @@ public class ServantManagerAccessor {
} }
} }
public void saveFile(String fileName, String content) {
// Create the message type.
ServantManagerRequest.Message type = ServantManagerRequest.Message.newBuilder()
.setType(ServantManagerRequest.Message.Type.SaveFile)
.build();
// Create the request.
ServantManagerRequest.SaveFileRequest request = ServantManagerRequest.SaveFileRequest.newBuilder()
.setFileName(fileName)
.setContent(content)
.build();
servantManagerRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse.parseFrom(servantManagerRequester.receive());
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "saveFile", "error in parsing response");
}
}
public String getFileContent(String fileName) throws ResourceNotFoundException {
// Create the message type.
ServantManagerRequest.Message type = ServantManagerRequest.Message.newBuilder()
.setType(ServantManagerRequest.Message.Type.GetFileContent)
.build();
// Create the request.
ServantManagerRequest.GetFileContentRequest request = ServantManagerRequest.GetFileContentRequest.newBuilder()
.setFileName(fileName)
.build();
servantManagerRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.StringResponse response = Common.StringResponse.parseFrom(servantManagerRequester.receive());
if (response.hasError()) {
throw new ResourceNotFoundException(fileName);
}
return response.getValue();
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "getFileContent", "error in parsing response");
}
throw new ResourceNotFoundException(fileName);
}
public String getTree(String rootDirectory) {
// Create the message type.
ServantManagerRequest.Message type = ServantManagerRequest.Message.newBuilder()
.setType(ServantManagerRequest.Message.Type.GetTree)
.build();
// Create the request.
ServantManagerRequest.GetTreeRequest request = ServantManagerRequest.GetTreeRequest.newBuilder()
.setRootDirectory(rootDirectory)
.build();
servantManagerRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.StringResponse response = Common.StringResponse.parseFrom(servantManagerRequester.receive());
return response.getValue();
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "getTree", "error in parsing response");
}
return "";
}
} }
\ No newline at end of file
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