|
@@ -5,6 +5,7 @@ import com.aip.gateway.api.aip.ConsentDelegateImpl;
|
|
|
import com.aip.gateway.api.aip.model.*;
|
|
|
import com.aip.gateway.api.aip.utils.Utilities;
|
|
|
import com.aip.gateway.api.aip.utils.AipFileUtils;
|
|
|
+import com.aip.gateway.api.utils.Elapsed;
|
|
|
import com.microsoft.informationprotection.*;
|
|
|
import com.microsoft.informationprotection.file.*;
|
|
|
import com.microsoft.informationprotection.internal.callback.FileHandlerObserver;
|
|
@@ -21,6 +22,7 @@ import java.util.Objects;
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
import java.util.concurrent.Future;
|
|
|
|
|
|
+@SuppressWarnings("DeclareNewLocal")
|
|
|
@Slf4j
|
|
|
public class FileManager extends AbstractManager {
|
|
|
private IFileProfile _profile = null;
|
|
@@ -148,6 +150,7 @@ public class FileManager extends AbstractManager {
|
|
|
return getFileInfo(fileName, fileName);
|
|
|
}
|
|
|
public AipFileInfo getFileInfo(String fileName, String actualFileName) {
|
|
|
+ Elapsed elapsed = new Elapsed();
|
|
|
IFileHandler handler = createFileHandler(fileName, actualFileName);
|
|
|
if (handler == null) {
|
|
|
return null;
|
|
@@ -156,6 +159,7 @@ public class FileManager extends AbstractManager {
|
|
|
if (result != null) {
|
|
|
result.setFileSize(getFileSize(fileName));
|
|
|
}
|
|
|
+ log.info("getFileInfo(File): {}, {} ms.", fileName, elapsed.milliSeconds());
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -164,7 +168,7 @@ public class FileManager extends AbstractManager {
|
|
|
log.error("FileManager.getFileInfo: FileHandler is null");
|
|
|
return null;
|
|
|
}
|
|
|
-
|
|
|
+ Elapsed elapsed = new Elapsed();
|
|
|
AipFileInfo fileInfo = new AipFileInfo(0, "");
|
|
|
|
|
|
fileInfo.setOutputFileName(handler.getOutputFileName());
|
|
@@ -218,6 +222,7 @@ public class FileManager extends AbstractManager {
|
|
|
fileInfo.getProtection().setProtectionDescriptor(descriptor);
|
|
|
}
|
|
|
}
|
|
|
+ log.info("getFileInfo(Handler): {}, {} ms.", fileInfo.getOutputFileName(), elapsed.milliSeconds());
|
|
|
return fileInfo;
|
|
|
}
|
|
|
|
|
@@ -271,6 +276,10 @@ public class FileManager extends AbstractManager {
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ private String getNewActualFileName(IFileHandler handler, String actualFileName) {
|
|
|
+ return AipFileUtils.getDirectoryName(actualFileName) + File.separator + AipFileUtils.getFileNameWithoutExtension(actualFileName) + AipFileUtils.getExtension(handler.getOutputFileName());
|
|
|
+ }
|
|
|
public SetFileInfo setLabel(String fileName, String actualFileName, String email, String labelId, String templateId, String comments) {
|
|
|
IFileHandler handler = createFileHandler(fileName, actualFileName);
|
|
|
return setLabel(handler, actualFileName, email, labelId, templateId, comments, getFileSize(fileName));
|
|
@@ -280,6 +289,7 @@ public class FileManager extends AbstractManager {
|
|
|
return setLabel(handler, actualFileName, email, labelId, templateId, comments, fileStream.size());
|
|
|
}
|
|
|
private SetFileInfo setLabel(IFileHandler handler, String actualFileName, String email, String labelId, String templateId, String comments, long fileSize) {
|
|
|
+ Elapsed elapsed = new Elapsed();
|
|
|
SetFileInfo result = new SetFileInfo();
|
|
|
if (handler == null) {
|
|
|
result.errorNo = 201;
|
|
@@ -300,7 +310,7 @@ public class FileManager extends AbstractManager {
|
|
|
String ownerEmail = getOrgFileInfo(handler, email, result);
|
|
|
|
|
|
ProtectionSettings protectionSettings = new ProtectionSettings();
|
|
|
- protectionSettings.setPFileExtensionBehavior(PFileExtensionBehavior.Default);
|
|
|
+ protectionSettings.setPFileExtensionBehavior(PFileExtensionBehavior.PPrefix);
|
|
|
if (!Objects.equals(ownerEmail, "")) {
|
|
|
protectionSettings.setDelegatedUserEmail(ownerEmail);
|
|
|
}
|
|
@@ -319,7 +329,9 @@ public class FileManager extends AbstractManager {
|
|
|
setError(53, "FileManager::SetLabel Failed.", ex.getMessage());
|
|
|
return result;
|
|
|
}
|
|
|
+ log.info("setLabel1: {}, {} ms.", actualFileName, elapsed.milliSeconds());
|
|
|
|
|
|
+ actualFileName = getNewActualFileName(handler, actualFileName);
|
|
|
boolean isCommitted = commitAsync(handler, actualFileName, result);
|
|
|
if (isCommitted) {
|
|
|
//handler.NotifyCommitSuccessful(fileName);
|
|
@@ -334,8 +346,8 @@ public class FileManager extends AbstractManager {
|
|
|
result.errorMsg = "AIP File CommitAsync(setLabel) Failed.";
|
|
|
setError(53, "FileManager::SetLabel Failed.", "Label Id: " + labelId + ", SetLabel Failed.");
|
|
|
}
|
|
|
-
|
|
|
getActionFileInfo(actualFileName, result);
|
|
|
+ log.info("setLabel2: {}, {} ms.", actualFileName, elapsed.milliSeconds());
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -362,7 +374,7 @@ public class FileManager extends AbstractManager {
|
|
|
String ownerEmail = getOrgFileInfo(handler, email, result);
|
|
|
|
|
|
ProtectionSettings protectionSettings = new ProtectionSettings();
|
|
|
- protectionSettings.setPFileExtensionBehavior(PFileExtensionBehavior.Default);
|
|
|
+ protectionSettings.setPFileExtensionBehavior(PFileExtensionBehavior.PPrefix);
|
|
|
if (!Objects.equals(ownerEmail, "")) {
|
|
|
protectionSettings.setDelegatedUserEmail(ownerEmail);
|
|
|
}
|
|
@@ -382,6 +394,7 @@ public class FileManager extends AbstractManager {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ actualFileName = getNewActualFileName(handler, actualFileName);
|
|
|
boolean isCommited = commitAsync(handler, actualFileName, result);
|
|
|
if (isCommited) {
|
|
|
//handler.NotifyCommitSuccessful(fileName);
|
|
@@ -422,7 +435,7 @@ public class FileManager extends AbstractManager {
|
|
|
try {
|
|
|
ProtectionDescriptor protectionDescriptor = new ProtectionDescriptor(templateId);
|
|
|
ProtectionSettings protectionSettings = new ProtectionSettings();
|
|
|
- protectionSettings.setPFileExtensionBehavior(PFileExtensionBehavior.Default);
|
|
|
+ protectionSettings.setPFileExtensionBehavior(PFileExtensionBehavior.PPrefix);
|
|
|
if (!Objects.equals(ownerEmail, "")) {
|
|
|
protectionSettings.setDelegatedUserEmail(ownerEmail);
|
|
|
}
|
|
@@ -435,6 +448,7 @@ public class FileManager extends AbstractManager {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ actualFileName = getNewActualFileName(handler, actualFileName);
|
|
|
boolean isCommited = commitAsync(handler, actualFileName, result);
|
|
|
if (isCommited) {
|
|
|
//handler.NotifyCommitSuccessful(fileName);
|
|
@@ -472,7 +486,7 @@ public class FileManager extends AbstractManager {
|
|
|
String ownerEmail = getOrgFileInfo(handler, email, result);
|
|
|
|
|
|
ProtectionSettings protectionSettings = new ProtectionSettings();
|
|
|
- protectionSettings.setPFileExtensionBehavior(PFileExtensionBehavior.Default);
|
|
|
+ protectionSettings.setPFileExtensionBehavior(PFileExtensionBehavior.PPrefix);
|
|
|
if (!Objects.equals(ownerEmail, "")) {
|
|
|
protectionSettings.setDelegatedUserEmail(ownerEmail);
|
|
|
}
|
|
@@ -499,6 +513,7 @@ public class FileManager extends AbstractManager {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ actualFileName = getNewActualFileName(handler, actualFileName);
|
|
|
boolean isCommited = commitAsync(handler, actualFileName, result);
|
|
|
if (isCommited) {
|
|
|
//handler.NotifyCommitSuccessful(fileName);
|
|
@@ -556,6 +571,7 @@ public class FileManager extends AbstractManager {
|
|
|
}
|
|
|
|
|
|
private boolean commitAsync(IFileHandler handler, String actualFileName, SetFileInfo result) {
|
|
|
+ Elapsed elapsed = new Elapsed();
|
|
|
boolean isCommitted = false;
|
|
|
if (handler.isModified()) {
|
|
|
Future<Boolean> future = handler.commitAsync(actualFileName);
|
|
@@ -564,14 +580,15 @@ public class FileManager extends AbstractManager {
|
|
|
} catch (InterruptedException e) {
|
|
|
result.errorNo = 301;
|
|
|
result.errorMsg = "AIP File CommitAsync InterruptedException Exception.";
|
|
|
- setError(61, "FileManager::commitAsync Failed.", e.getMessage());
|
|
|
+ setError(61, "FileManager::commitAsync Failed: " + actualFileName, e.getMessage());
|
|
|
Thread.currentThread().interrupt();
|
|
|
} catch (ExecutionException e) {
|
|
|
result.errorNo = 302;
|
|
|
result.errorMsg = "AIP File CommitAsync ExecutionException Exception.";
|
|
|
- setError(62, "FileManager::commitAsync Failed.", e.getMessage());
|
|
|
+ setError(62, "FileManager::commitAsync Failed: " + actualFileName, e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
+ log.info("commitAsync: {}, {} ms.", actualFileName, elapsed.milliSeconds());
|
|
|
return isCommitted;
|
|
|
}
|
|
|
|